Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

110 рядки
3.2 KiB

  1. /* Copyright (c) 2015, Google Inc.
  2. *
  3. * Permission to use, copy, modify, and/or distribute this software for any
  4. * purpose with or without fee is hereby granted, provided that the above
  5. * copyright notice and this permission notice appear in all copies.
  6. *
  7. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  8. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  9. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  10. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  11. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  12. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  13. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
  14. #ifndef OPENSSL_HEADER_CURVE25519_INTERNAL_H
  15. #define OPENSSL_HEADER_CURVE25519_INTERNAL_H
  16. #if defined(__cplusplus)
  17. extern "C" {
  18. #endif
  19. #if defined(OPENSSL_X86_64) && !defined(OPENSSL_SMALL) && \
  20. !defined(OPENSSL_WINDOWS) && !defined(OPENSSL_NO_ASM)
  21. #define BORINGSSL_X25519_X86_64
  22. void x25519_x86_64(uint8_t out[32], const uint8_t scalar[32],
  23. const uint8_t point[32]);
  24. #endif
  25. #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM)
  26. #define BORINGSSL_X25519_NEON
  27. /* x25519_NEON is defined in asm/x25519-arm.S. */
  28. void x25519_NEON(uint8_t out[32], const uint8_t scalar[32],
  29. const uint8_t point[32]);
  30. #endif
  31. /* fe means field element. Here the field is \Z/(2^255-19). An element t,
  32. * entries t[0]...t[9], represents the integer t[0]+2^26 t[1]+2^51 t[2]+2^77
  33. * t[3]+2^102 t[4]+...+2^230 t[9]. Bounds on each t[i] vary depending on
  34. * context. */
  35. typedef int32_t fe[10];
  36. /* ge means group element.
  37. * Here the group is the set of pairs (x,y) of field elements (see fe.h)
  38. * satisfying -x^2 + y^2 = 1 + d x^2y^2
  39. * where d = -121665/121666.
  40. *
  41. * Representations:
  42. * ge_p2 (projective): (X:Y:Z) satisfying x=X/Z, y=Y/Z
  43. * ge_p3 (extended): (X:Y:Z:T) satisfying x=X/Z, y=Y/Z, XY=ZT
  44. * ge_p1p1 (completed): ((X:Z),(Y:T)) satisfying x=X/Z, y=Y/T
  45. * ge_precomp (Duif): (y+x,y-x,2dxy) */
  46. typedef struct {
  47. fe X;
  48. fe Y;
  49. fe Z;
  50. } ge_p2;
  51. typedef struct {
  52. fe X;
  53. fe Y;
  54. fe Z;
  55. fe T;
  56. } ge_p3;
  57. typedef struct {
  58. fe X;
  59. fe Y;
  60. fe Z;
  61. fe T;
  62. } ge_p1p1;
  63. typedef struct {
  64. fe yplusx;
  65. fe yminusx;
  66. fe xy2d;
  67. } ge_precomp;
  68. typedef struct {
  69. fe YplusX;
  70. fe YminusX;
  71. fe Z;
  72. fe T2d;
  73. } ge_cached;
  74. void x25519_ge_tobytes(uint8_t *s, const ge_p2 *h);
  75. int x25519_ge_frombytes_vartime(ge_p3 *h, const uint8_t *s);
  76. void x25519_ge_p3_to_cached(ge_cached *r, const ge_p3 *p);
  77. void x25519_ge_p1p1_to_p2(ge_p2 *r, const ge_p1p1 *p);
  78. void x25519_ge_p1p1_to_p3(ge_p3 *r, const ge_p1p1 *p);
  79. void x25519_ge_add(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
  80. void x25519_ge_sub(ge_p1p1 *r, const ge_p3 *p, const ge_cached *q);
  81. void x25519_ge_scalarmult_small_precomp(
  82. ge_p3 *h, const uint8_t a[32], const uint8_t precomp_table[15 * 2 * 32]);
  83. void x25519_ge_scalarmult_base(ge_p3 *h, const uint8_t a[32]);
  84. void x25519_ge_scalarmult(ge_p2 *r, const uint8_t *scalar, const ge_p3 *A);
  85. void x25519_sc_reduce(uint8_t *s);
  86. #if defined(__cplusplus)
  87. } /* extern C */
  88. #endif
  89. #endif /* OPENSSL_HEADER_CURVE25519_INTERNAL_H */