ge25519.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #ifndef GE25519_H
  2. #define GE25519_H
  3. #include "fe25519.h"
  4. #include "sc25519.h"
  5. #include "compat.h"
  6. #define ge25519 CRYPTO_NAMESPACE(ge25519)
  7. #define ge25519_base CRYPTO_NAMESPACE(ge25519_base)
  8. #define ge25519_unpackneg_vartime CRYPTO_NAMESPACE(unpackneg_vartime)
  9. #define ge25519_pack CRYPTO_NAMESPACE(pack)
  10. #define ge25519_isneutral_vartime CRYPTO_NAMESPACE(isneutral_vartime)
  11. #define ge25519_add CRYPTO_NAMESPACE(ge25519_add)
  12. #define ge25519_double CRYPTO_NAMESPACE(ge25519_double)
  13. #define ge25519_double_scalarmult_vartime CRYPTO_NAMESPACE(double_scalarmult_vartime)
  14. #define ge25519_multi_scalarmult_vartime CRYPTO_NAMESPACE(ge25519_multi_scalarmult_vartime)
  15. #define ge25519_scalarmult_base CRYPTO_NAMESPACE(scalarmult_base)
  16. #define ge25519_p1p1_to_p2 CRYPTO_NAMESPACE(ge25519_p1p1_to_p2)
  17. #define ge25519_p1p1_to_p3 CRYPTO_NAMESPACE(ge25519_p1p1_to_p3)
  18. #define ge25519_add_p1p1 CRYPTO_NAMESPACE(ge25519_add_p1p1)
  19. #define ge25519_dbl_p1p1 CRYPTO_NAMESPACE(ge25519_dbl_p1p1)
  20. #define choose_t CRYPTO_NAMESPACE(choose_t)
  21. #define ge25519_nielsadd2 CRYPTO_NAMESPACE(ge25519_nielsadd2)
  22. #define ge25519_nielsadd_p1p1 CRYPTO_NAMESPACE(ge25519_nielsadd_p1p1)
  23. #define ge25519_pnielsadd_p1p1 CRYPTO_NAMESPACE(ge25519_pnielsadd_p1p1)
  24. #define ge25519_p3 ge25519
  25. typedef struct
  26. {
  27. fe25519 x;
  28. fe25519 y;
  29. fe25519 z;
  30. fe25519 t;
  31. } ge25519;
  32. typedef struct
  33. {
  34. fe25519 x;
  35. fe25519 z;
  36. fe25519 y;
  37. fe25519 t;
  38. } ge25519_p1p1;
  39. typedef struct
  40. {
  41. fe25519 x;
  42. fe25519 y;
  43. fe25519 z;
  44. } ge25519_p2;
  45. typedef struct
  46. {
  47. fe25519 ysubx;
  48. fe25519 xaddy;
  49. fe25519 t2d;
  50. } ge25519_niels;
  51. typedef struct
  52. {
  53. fe25519 ysubx;
  54. fe25519 xaddy;
  55. fe25519 z;
  56. fe25519 t2d;
  57. } ge25519_pniels;
  58. typedef unsigned char bytes32[32];
  59. extern void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p) SYSVABI;
  60. extern void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p) SYSVABI;
  61. extern void ge25519_add_p1p1(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_p3 *q) SYSVABI;
  62. extern void ge25519_dbl_p1p1(ge25519_p1p1 *r, const ge25519_p2 *p) SYSVABI;
  63. extern void choose_t(ge25519_niels *t, unsigned long long pos, signed long long b, const ge25519_niels *base_multiples) SYSVABI;
  64. extern void ge25519_nielsadd2(ge25519_p3 *r, const ge25519_niels *q) SYSVABI;
  65. extern void ge25519_nielsadd_p1p1(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_niels *q) SYSVABI;
  66. extern void ge25519_pnielsadd_p1p1(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_pniels *q) SYSVABI;
  67. extern const ge25519 ge25519_base;
  68. extern int ge25519_unpackneg_vartime(ge25519 *r, const unsigned char p[32]);
  69. extern void ge25519_pack(unsigned char r[32], const ge25519 *p);
  70. extern void ge25519_batchpack_destructive_1(bytes32 *out, ge25519_p3 *in, fe25519 *tmp, size_t num);
  71. extern void ge25519_batchpack_destructive_finish(bytes32 out, ge25519_p3 *unf);
  72. extern int ge25519_isneutral_vartime(const ge25519 *p);
  73. extern void ge25519_add(ge25519 *r, const ge25519 *p, const ge25519 *q);
  74. extern void ge25519_double(ge25519 *r, const ge25519 *p);
  75. /* computes [s1]p1 + [s2]ge25519_base */
  76. extern void ge25519_double_scalarmult_vartime(ge25519 *r, const ge25519 *p1, const sc25519 *s1, const sc25519 *s2);
  77. extern void ge25519_multi_scalarmult_vartime(ge25519 *r, ge25519 *p, sc25519 *s, const unsigned long long npoints);
  78. extern void ge25519_scalarmult_base(ge25519 *r, const sc25519 *s);
  79. #endif