ed25519_ref10.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. #ifndef ed25519_ref10_H
  2. #define ed25519_ref10_H
  3. #include <stddef.h>
  4. #include <stdint.h>
  5. /*
  6. fe means field element.
  7. Here the field is \Z/(2^255-19).
  8. */
  9. #ifdef HAVE_TI_MODE
  10. typedef uint64_t fe25519[5];
  11. #else
  12. typedef int32_t fe25519[10];
  13. #endif
  14. void fe25519_invert(fe25519 out, const fe25519 z);
  15. void fe25519_frombytes(fe25519 h, const unsigned char *s);
  16. void fe25519_tobytes(unsigned char *s, const fe25519 h);
  17. #ifdef HAVE_TI_MODE
  18. # include "ed25519_ref10_fe_51.h"
  19. #else
  20. # include "ed25519_ref10_fe_25_5.h"
  21. #endif
  22. /*
  23. ge means group element.
  24. Here the group is the set of pairs (x,y) of field elements
  25. satisfying -x^2 + y^2 = 1 + d x^2y^2
  26. where d = -121665/121666.
  27. Representations:
  28. ge25519_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
  29. ge25519_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
  30. ge25519_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
  31. ge25519_precomp (Duif): (y+x,y-x,2dxy)
  32. */
  33. typedef struct {
  34. fe25519 X;
  35. fe25519 Y;
  36. fe25519 Z;
  37. } ge25519_p2;
  38. typedef struct {
  39. fe25519 X;
  40. fe25519 Y;
  41. fe25519 Z;
  42. fe25519 T;
  43. } ge25519_p3;
  44. typedef struct {
  45. fe25519 X;
  46. fe25519 Y;
  47. fe25519 Z;
  48. fe25519 T;
  49. } ge25519_p1p1;
  50. typedef struct {
  51. fe25519 yplusx;
  52. fe25519 yminusx;
  53. fe25519 xy2d;
  54. } ge25519_precomp;
  55. typedef struct {
  56. fe25519 YplusX;
  57. fe25519 YminusX;
  58. fe25519 Z;
  59. fe25519 T2d;
  60. } ge25519_cached;
  61. void ge25519_tobytes(unsigned char *s, const ge25519_p2 *h);
  62. void ge25519_p3_tobytes(unsigned char *s, const ge25519_p3 *h);
  63. int ge25519_frombytes(ge25519_p3 *h, const unsigned char *s);
  64. int ge25519_frombytes_negate_vartime(ge25519_p3 *h, const unsigned char *s);
  65. void ge25519_p3_to_cached(ge25519_cached *r, const ge25519_p3 *p);
  66. void ge25519_p1p1_to_p2(ge25519_p2 *r, const ge25519_p1p1 *p);
  67. void ge25519_p1p1_to_p3(ge25519_p3 *r, const ge25519_p1p1 *p);
  68. void ge25519_add(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q);
  69. void ge25519_sub(ge25519_p1p1 *r, const ge25519_p3 *p, const ge25519_cached *q);
  70. void ge25519_scalarmult_base(ge25519_p3 *h, const unsigned char *a);
  71. void ge25519_double_scalarmult_vartime(ge25519_p2 *r, const unsigned char *a,
  72. const ge25519_p3 *A,
  73. const unsigned char *b);
  74. void ge25519_scalarmult(ge25519_p3 *h, const unsigned char *a,
  75. const ge25519_p3 *p);
  76. int ge25519_is_canonical(const unsigned char *s);
  77. int ge25519_is_on_curve(const ge25519_p3 *p);
  78. int ge25519_is_on_main_subgroup(const ge25519_p3 *p);
  79. int ge25519_has_small_order(const unsigned char s[32]);
  80. void ge25519_from_uniform(unsigned char s[32], const unsigned char r[32]);
  81. void ge25519_from_hash(unsigned char s[32], const unsigned char h[64]);
  82. /*
  83. Ristretto group
  84. */
  85. int ristretto255_frombytes(ge25519_p3 *h, const unsigned char *s);
  86. void ristretto255_p3_tobytes(unsigned char *s, const ge25519_p3 *h);
  87. void ristretto255_from_hash(unsigned char s[32], const unsigned char h[64]);
  88. /*
  89. The set of scalars is \Z/l
  90. where l = 2^252 + 27742317777372353535851937790883648493.
  91. */
  92. void sc25519_invert(unsigned char recip[32], const unsigned char s[32]);
  93. void sc25519_reduce(unsigned char s[64]);
  94. void sc25519_mul(unsigned char s[32], const unsigned char a[32],
  95. const unsigned char b[32]);
  96. void sc25519_muladd(unsigned char s[32], const unsigned char a[32],
  97. const unsigned char b[32], const unsigned char c[32]);
  98. int sc25519_is_canonical(const unsigned char s[32]);
  99. #endif