ge_operations.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* ge_operations.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. /* Based On Daniel J Bernstein's ed25519 Public Domain ref10 work. */
  22. #ifndef WOLF_CRYPT_GE_OPERATIONS_H
  23. #define WOLF_CRYPT_GE_OPERATIONS_H
  24. #include <wolfssl/wolfcrypt/settings.h>
  25. #ifdef HAVE_ED25519
  26. #include <wolfssl/wolfcrypt/fe_operations.h>
  27. /*
  28. ge means group element.
  29. Here the group is the set of pairs (x,y) of field elements (see fe.h)
  30. satisfying -x^2 + y^2 = 1 + d x^2y^2
  31. where d = -121665/121666.
  32. Representations:
  33. ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
  34. ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
  35. ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
  36. ge_precomp (Duif): (y+x,y-x,2dxy)
  37. */
  38. #ifdef ED25519_SMALL
  39. typedef byte ge[F25519_SIZE];
  40. #elif defined(CURVED25519_ASM_64BIT)
  41. typedef sword64 ge[4];
  42. #elif defined(CURVED25519_ASM_32BIT)
  43. typedef sword32 ge[8];
  44. #elif defined(CURVED25519_128BIT)
  45. typedef sword64 ge[5];
  46. #else
  47. typedef sword32 ge[10];
  48. #endif
  49. typedef struct {
  50. ge X;
  51. ge Y;
  52. ge Z;
  53. } ge_p2;
  54. typedef struct {
  55. ge X;
  56. ge Y;
  57. ge Z;
  58. ge T;
  59. } ge_p3;
  60. WOLFSSL_LOCAL int ge_compress_key(byte* out, const byte* xIn, const byte* yIn,
  61. word32 keySz);
  62. WOLFSSL_LOCAL int ge_frombytes_negate_vartime(ge_p3 *h,const unsigned char *s);
  63. WOLFSSL_LOCAL int ge_double_scalarmult_vartime(ge_p2 *r, const unsigned char *a,
  64. const ge_p3 *A, const unsigned char *b);
  65. WOLFSSL_LOCAL void ge_scalarmult_base(ge_p3 *h,const unsigned char *a);
  66. WOLFSSL_LOCAL void sc_reduce(byte* s);
  67. WOLFSSL_LOCAL void sc_muladd(byte* s, const byte* a, const byte* b,
  68. const byte* c);
  69. WOLFSSL_LOCAL void ge_tobytes(unsigned char *s,const ge_p2 *h);
  70. WOLFSSL_LOCAL void ge_p3_tobytes(unsigned char *s,const ge_p3 *h);
  71. #ifndef ED25519_SMALL
  72. typedef struct {
  73. ge X;
  74. ge Y;
  75. ge Z;
  76. ge T;
  77. } ge_p1p1;
  78. typedef struct {
  79. ge yplusx;
  80. ge yminusx;
  81. ge xy2d;
  82. } ge_precomp;
  83. typedef struct {
  84. ge YplusX;
  85. ge YminusX;
  86. ge Z;
  87. ge T2d;
  88. } ge_cached;
  89. #endif /* !ED25519_SMALL */
  90. #endif /* HAVE_ED25519 */
  91. #endif /* WOLF_CRYPT_GE_OPERATIONS_H */