ed25519-donna.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. Public domain by Andrew M. <liquidsun@gmail.com>
  3. Modified from the amd64-51-30k implementation by
  4. Daniel J. Bernstein
  5. Niels Duif
  6. Tanja Lange
  7. Peter Schwabe
  8. Bo-Yin Yang
  9. */
  10. #include "ed25519-donna-portable.h"
  11. #if defined(ED25519_SSE2)
  12. #else
  13. #if defined(HAVE_UINT128) && !defined(ED25519_FORCE_32BIT)
  14. #define ED25519_64BIT
  15. #else
  16. #define ED25519_32BIT
  17. #endif
  18. #endif
  19. #if !defined(ED25519_NO_INLINE_ASM)
  20. /* detect extra features first so un-needed functions can be disabled throughout */
  21. #if defined(ED25519_SSE2)
  22. #if defined(COMPILER_GCC) && defined(CPU_X86)
  23. #define ED25519_GCC_32BIT_SSE_CHOOSE
  24. #elif defined(COMPILER_GCC) && defined(CPU_X86_64)
  25. #define ED25519_GCC_64BIT_SSE_CHOOSE
  26. #endif
  27. #else
  28. #if defined(CPU_X86_64)
  29. #if defined(COMPILER_GCC)
  30. #if defined(ED25519_64BIT)
  31. #define ED25519_GCC_64BIT_X86_CHOOSE
  32. #else
  33. #define ED25519_GCC_64BIT_32BIT_CHOOSE
  34. #endif
  35. #endif
  36. #endif
  37. #endif
  38. #endif
  39. #include "curve25519-donna-sse2.h"
  40. #include "curve25519-donna-64bit.h"
  41. #include "curve25519-donna-32bit.h"
  42. #include "curve25519-donna-helpers.h"
  43. #include "modm-donna-64bit.h"
  44. #include "modm-donna-32bit.h"
  45. typedef unsigned char hash_512bits[64];
  46. /*
  47. Timing safe memory compare
  48. */
  49. static int
  50. ed25519_verify(const unsigned char *x, const unsigned char *y, size_t len) {
  51. size_t differentbits = 0;
  52. while (len--)
  53. differentbits |= (*x++ ^ *y++);
  54. return (int) (1 & ((differentbits - 1) >> 8));
  55. }
  56. /*
  57. * Arithmetic on the twisted Edwards curve -x^2 + y^2 = 1 + dx^2y^2
  58. * with d = -(121665/121666) = 37095705934669439343138083508754565189542113879843219016388785533085940283555
  59. * Base point: (15112221349535400772501151409588531511454012693041857206046113283949847762202,46316835694926478169428394003475163141307993866256225615783033603165251855960);
  60. */
  61. typedef struct ge25519_t {
  62. bignum25519 x, y, z, t;
  63. } ge25519;
  64. typedef struct ge25519_p1p1_t {
  65. bignum25519 x, y, z, t;
  66. } ge25519_p1p1;
  67. typedef struct ge25519_niels_t {
  68. bignum25519 ysubx, xaddy, t2d;
  69. } ge25519_niels;
  70. typedef struct ge25519_pniels_t {
  71. bignum25519 ysubx, xaddy, z, t2d;
  72. } ge25519_pniels;
  73. typedef unsigned char bytes32[32];
  74. #include "ed25519-donna-basepoint-table.h"
  75. #include "ed25519-donna-64bit-tables.h"
  76. #include "ed25519-donna-64bit-x86.h"
  77. #include "ed25519-donna-32bit-tables.h"
  78. #include "ed25519-donna-64bit-x86-32bit.h"
  79. #include "ed25519-donna-32bit-sse2.h"
  80. #include "ed25519-donna-64bit-sse2.h"
  81. #include "ed25519-donna-impl-sse2.h"
  82. #include "ed25519-donna-impl-base.h"