fe_448.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* fe448_448.h
  2. *
  3. * Copyright (C) 2006-2022 wolfSSL Inc.
  4. *
  5. * This file is part of wolfSSL.
  6. *
  7. * wolfSSL is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * wolfSSL is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
  20. */
  21. #ifndef WOLF_CRYPT_FE_448_H
  22. #define WOLF_CRYPT_FE_448_H
  23. #include <wolfssl/wolfcrypt/settings.h>
  24. #if defined(HAVE_CURVE448) || defined(HAVE_ED448)
  25. #include <wolfssl/wolfcrypt/types.h>
  26. #if defined(HAVE___UINT128_T) && !defined(NO_CURVED448_128BIT)
  27. #define CURVED448_128BIT
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* default to be faster but take more memory */
  33. #if !defined(CURVE448_SMALL) && !defined(ED448_SMALL)
  34. #if defined(CURVED448_128BIT)
  35. typedef sword64 fe448;
  36. #ifndef WOLFSSL_UINT128_T_DEFINED
  37. #ifdef __SIZEOF_INT128__
  38. typedef __uint128_t uint128_t;
  39. typedef __int128_t int128_t;
  40. typedef __uint128_t word128;
  41. typedef __int128_t sword128;
  42. #else
  43. typedef unsigned long uint128_t __attribute__ ((mode(TI)));
  44. typedef long int128_t __attribute__ ((mode(TI)));
  45. typedef uint128_t word128;
  46. typedef int128_t sword128;
  47. #endif
  48. #define WOLFSSL_UINT128_T_DEFINED
  49. #endif
  50. #else
  51. typedef sword32 fe448;
  52. #endif
  53. WOLFSSL_LOCAL void fe448_init(void);
  54. WOLFSSL_LOCAL int curve448(byte* r, const byte* n, const byte* a);
  55. #if !defined(CURVED448_128BIT)
  56. WOLFSSL_LOCAL void fe448_reduce(fe448*);
  57. #else
  58. #define fe448_reduce(a)
  59. #endif
  60. WOLFSSL_LOCAL void fe448_neg(fe448* r, const fe448* a);
  61. WOLFSSL_LOCAL void fe448_add(fe448* r, const fe448* a, const fe448* b);
  62. WOLFSSL_LOCAL void fe448_sub(fe448* r, const fe448* a, const fe448* b);
  63. WOLFSSL_LOCAL void fe448_mul(fe448* r, const fe448* a, const fe448* b);
  64. WOLFSSL_LOCAL void fe448_sqr(fe448* r, const fe448* a);
  65. WOLFSSL_LOCAL void fe448_mul39081(fe448* r, const fe448* a);
  66. WOLFSSL_LOCAL void fe448_invert(fe448* r, const fe448* a);
  67. WOLFSSL_LOCAL void fe448_0(fe448* a);
  68. WOLFSSL_LOCAL void fe448_1(fe448* a);
  69. WOLFSSL_LOCAL void fe448_copy(fe448* d, const fe448* a);
  70. WOLFSSL_LOCAL int fe448_isnonzero(const fe448* a);
  71. WOLFSSL_LOCAL int fe448_isnegative(const fe448* a);
  72. WOLFSSL_LOCAL void fe448_from_bytes(fe448* r, const unsigned char* b);
  73. WOLFSSL_LOCAL void fe448_to_bytes(unsigned char* b, const fe448* a);
  74. WOLFSSL_LOCAL void fe448_cmov(fe448* a, const fe448* b, int c);
  75. WOLFSSL_LOCAL void fe448_pow_2_446_222_1(fe448* r, const fe448* a);
  76. #else
  77. WOLFSSL_LOCAL void fe448_init(void);
  78. WOLFSSL_LOCAL int curve448(byte* r, const byte* n, const byte* a);
  79. #define fe448_reduce(a)
  80. WOLFSSL_LOCAL void fe448_neg(word8* r, const word8* a);
  81. WOLFSSL_LOCAL void fe448_add(word8* r, const word8* a, const word8* b);
  82. WOLFSSL_LOCAL void fe448_sub(word8* r, const word8* a, const word8* b);
  83. WOLFSSL_LOCAL void fe448_mul(word8* r, const word8* a, const word8* b);
  84. WOLFSSL_LOCAL void fe448_sqr(word8* r, const word8* a);
  85. WOLFSSL_LOCAL void fe448_mul39081(word8* r, const word8* a);
  86. WOLFSSL_LOCAL void fe448_invert(word8* r, const word8* a);
  87. WOLFSSL_LOCAL void fe448_norm(byte *a);
  88. WOLFSSL_LOCAL void fe448_copy(word8* d, const word8* a);
  89. WOLFSSL_LOCAL int fe448_isnonzero(const word8* a);
  90. WOLFSSL_LOCAL void fe448_cmov(word8* a, const word8* b, int c);
  91. WOLFSSL_LOCAL void fe448_pow_2_446_222_1(word8* r, const word8* a);
  92. #endif /* !CURVE448_SMALL || !ED448_SMALL */
  93. #ifdef __cplusplus
  94. } /* extern "C" */
  95. #endif
  96. #endif /* HAVE_CURVE448 || HAVE_ED448 */
  97. #endif /* WOLF_CRYPT_FE_448_H */