Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

111 wiersze
4.0 KiB

  1. /* Copyright (c) 2014, Intel Corporation.
  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_EC_P256_X86_64_H
  15. #define OPENSSL_HEADER_EC_P256_X86_64_H
  16. #include <openssl/base.h>
  17. #include <openssl/bn.h>
  18. #if defined(__cplusplus)
  19. extern "C" {
  20. #endif
  21. #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && \
  22. !defined(OPENSSL_SMALL)
  23. /* P-256 field operations.
  24. *
  25. * An element mod P in P-256 is represented as a little-endian array of
  26. * |P256_LIMBS| |BN_ULONG|s, spanning the full range of values.
  27. *
  28. * The following functions take fully-reduced inputs mod P and give
  29. * fully-reduced outputs. They may be used in-place. */
  30. #define P256_LIMBS (256 / BN_BITS2)
  31. /* ecp_nistz256_neg sets |res| to -|a| mod P. */
  32. void ecp_nistz256_neg(BN_ULONG res[P256_LIMBS], const BN_ULONG a[P256_LIMBS]);
  33. /* ecp_nistz256_mul_mont sets |res| to |a| * |b| * 2^-256 mod P. */
  34. void ecp_nistz256_mul_mont(BN_ULONG res[P256_LIMBS],
  35. const BN_ULONG a[P256_LIMBS],
  36. const BN_ULONG b[P256_LIMBS]);
  37. /* ecp_nistz256_sqr_mont sets |res| to |a| * |a| * 2^-256 mod P. */
  38. void ecp_nistz256_sqr_mont(BN_ULONG res[P256_LIMBS],
  39. const BN_ULONG a[P256_LIMBS]);
  40. /* ecp_nistz256_from_mont sets |res| to |in|, converted from Montgomery domain
  41. * by multiplying with 1. */
  42. void ecp_nistz256_from_mont(BN_ULONG res[P256_LIMBS],
  43. const BN_ULONG in[P256_LIMBS]);
  44. /* P-256 point operations.
  45. *
  46. * The following functions may be used in-place. All coordinates are in the
  47. * Montgomery domain. */
  48. /* A P256_POINT represents a P-256 point in Jacobian coordinates. */
  49. typedef struct {
  50. BN_ULONG X[P256_LIMBS];
  51. BN_ULONG Y[P256_LIMBS];
  52. BN_ULONG Z[P256_LIMBS];
  53. } P256_POINT;
  54. /* A P256_POINT_AFFINE represents a P-256 point in affine coordinates. Infinity
  55. * is encoded as (0, 0). */
  56. typedef struct {
  57. BN_ULONG X[P256_LIMBS];
  58. BN_ULONG Y[P256_LIMBS];
  59. } P256_POINT_AFFINE;
  60. /* ecp_nistz256_select_w5 sets |*val| to |in_t[index-1]| if 1 <= |index| <= 16
  61. * and all zeros (the point at infinity) if |index| is 0. This is done in
  62. * constant time. */
  63. void ecp_nistz256_select_w5(P256_POINT *val, const P256_POINT in_t[16],
  64. int index);
  65. /* ecp_nistz256_select_w7 sets |*val| to |in_t[index-1]| if 1 <= |index| <= 64
  66. * and all zeros (the point at infinity) if |index| is 0. This is done in
  67. * constant time. */
  68. void ecp_nistz256_select_w7(P256_POINT_AFFINE *val,
  69. const P256_POINT_AFFINE in_t[64], int index);
  70. /* ecp_nistz256_point_double sets |r| to |a| doubled. */
  71. void ecp_nistz256_point_double(P256_POINT *r, const P256_POINT *a);
  72. /* ecp_nistz256_point_add adds |a| to |b| and places the result in |r|. */
  73. void ecp_nistz256_point_add(P256_POINT *r, const P256_POINT *a,
  74. const P256_POINT *b);
  75. /* ecp_nistz256_point_add_affine adds |a| to |b| and places the result in
  76. * |r|. |a| and |b| must not represent the same point unless they are both
  77. * infinity. */
  78. void ecp_nistz256_point_add_affine(P256_POINT *r, const P256_POINT *a,
  79. const P256_POINT_AFFINE *b);
  80. #endif /* !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64) && \
  81. !defined(OPENSSL_SMALL) */
  82. #if defined(__cplusplus)
  83. } /* extern C++ */
  84. #endif
  85. #endif /* OPENSSL_HEADER_EC_P256_X86_64_H */