Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 
 

155 rindas
4.7 KiB

  1. // The MIT License (MIT)
  2. //
  3. // Copyright (c) 2015-2016 the fiat-crypto authors (see the AUTHORS file).
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in all
  13. // copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. // SOFTWARE.
  22. #ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
  23. #define OPENSSL_HEADER_CURVE25519_INTERNAL_H
  24. #if defined(__cplusplus)
  25. extern "C" {
  26. #endif
  27. #include <openssl/base.h>
  28. #include "../../crypto/internal.h"
  29. #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
  30. #define BORINGSSL_X25519_NEON
  31. // x25519_NEON is defined in asm/x25519-arm.S.
  32. void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
  33. const uint8_t point[32]);
  34. #endif
  35. #if defined(BORINGSSL_HAS_UINT128)
  36. #define BORINGSSL_CURVE25519_64BIT
  37. #endif
  38. #if defined(BORINGSSL_CURVE25519_64BIT)
  39. // fe means field element. Here the field is \Z/(2^255-19). An element t,
  40. // entries t[0]...t[4], represents the integer t[0]+2^51 t[1]+2^102 t[2]+2^153
  41. // t[3]+2^204 t[4].
  42. // fe limbs are bounded by 1.125*2^51.
  43. // Multiplication and carrying produce fe from fe_loose.
  44. typedef struct fe { uint64_t v[5]; } fe;
  45. // fe_loose limbs are bounded by 3.375*2^51.
  46. // Addition and subtraction produce fe_loose from (fe, fe).
  47. typedef struct fe_loose { uint64_t v[5]; } fe_loose;
  48. #else
  49. // fe means field element. Here the field is \Z/(2^255-19). An element t,
  50. // entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
  51. // t[3]+2^102 t[4]+...+2^230 t[9].
  52. // fe limbs are bounded by 1.125*2^26,1.125*2^25,1.125*2^26,1.125*2^25,etc.
  53. // Multiplication and carrying produce fe from fe_loose.
  54. typedef struct fe { uint32_t v[10]; } fe;
  55. // fe_loose limbs are bounded by 3.375*2^26,3.375*2^25,3.375*2^26,3.375*2^25,etc.
  56. // Addition and subtraction produce fe_loose from (fe, fe).
  57. typedef struct fe_loose { uint32_t v[10]; } fe_loose;
  58. #endif
  59. // ge means group element.
  60. //
  61. // Here the group is the set of pairs (x,y) of field elements (see fe.h)
  62. // satisfying -x^2 + y^2 = 1 + d x^2y^2
  63. // where d = -121665/121666.
  64. //
  65. // Representations:
  66. // ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
  67. // ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
  68. // ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
  69. // ge_precomp (Duif): (y+x,y-x,2dxy)
  70. typedef struct {
  71. fe X;
  72. fe Y;
  73. fe Z;
  74. } ge_p2;
  75. typedef struct {
  76. fe X;
  77. fe Y;
  78. fe Z;
  79. fe T;
  80. } ge_p3;
  81. typedef struct {
  82. fe_loose X;
  83. fe_loose Y;
  84. fe_loose Z;
  85. fe_loose T;
  86. } ge_p1p1;
  87. typedef struct {
  88. fe_loose yplusx;
  89. fe_loose yminusx;
  90. fe_loose xy2d;
  91. } ge_precomp;
  92. typedef struct {
  93. fe_loose YplusX;
  94. fe_loose YminusX;
  95. fe_loose Z;
  96. fe_loose T2d;
  97. } ge_cached;
  98. void x25519_ge_tobytes(uint8_t s[32], const ge_p2 *h);
  99. int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
  100. void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
  101. void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
  102. void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
  103. void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
  104. void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
  105. void x25519_ge_scalarmult_small_precomp(
  106. ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
  107. void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
  108. void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
  109. void x25519_sc_reduce(uint8_t s[64]);
  110. enum spake2_state_t {
  111. spake2_state_init = 0,
  112. spake2_state_msg_generated,
  113. spake2_state_key_generated,
  114. };
  115. struct spake2_ctx_st {
  116. uint8_t private_key[32];
  117. uint8_t my_msg[32];
  118. uint8_t password_scalar[32];
  119. uint8_t password_hash[64];
  120. uint8_t *my_name;
  121. size_t my_name_len;
  122. uint8_t *their_name;
  123. size_t their_name_len;
  124. enum spake2_role_t my_role;
  125. enum spake2_state_t state;
  126. char disable_password_scalar_hack;
  127. };
  128. #if defined(__cplusplus)
  129. } // extern C
  130. #endif
  131. #endif // OPENSSL_HEADER_CURVE25519_INTERNAL_H