Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 1 | /* Originally written by Bodo Moeller for the OpenSSL project. |
| 2 | * ==================================================================== |
| 3 | * Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * |
| 12 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * |
| 17 | * 3. All advertising materials mentioning features or use of this |
| 18 | * software must display the following acknowledgment: |
| 19 | * "This product includes software developed by the OpenSSL Project |
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" |
| 21 | * |
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
| 23 | * endorse or promote products derived from this software without |
| 24 | * prior written permission. For written permission, please contact |
| 25 | * openssl-core@openssl.org. |
| 26 | * |
| 27 | * 5. Products derived from this software may not be called "OpenSSL" |
| 28 | * nor may "OpenSSL" appear in their names without prior written |
| 29 | * permission of the OpenSSL Project. |
| 30 | * |
| 31 | * 6. Redistributions of any form whatsoever must retain the following |
| 32 | * acknowledgment: |
| 33 | * "This product includes software developed by the OpenSSL Project |
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" |
| 35 | * |
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY |
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR |
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED |
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. |
| 48 | * ==================================================================== |
| 49 | * |
| 50 | * This product includes cryptographic software written by Eric Young |
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim |
| 52 | * Hudson (tjh@cryptsoft.com). |
| 53 | * |
| 54 | */ |
| 55 | /* ==================================================================== |
| 56 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. |
| 57 | * |
| 58 | * Portions of the attached software ("Contribution") are developed by |
| 59 | * SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project. |
| 60 | * |
| 61 | * The Contribution is licensed pursuant to the OpenSSL open source |
| 62 | * license provided above. |
| 63 | * |
| 64 | * The elliptic curve binary polynomial software is originally written by |
| 65 | * Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems |
| 66 | * Laboratories. */ |
| 67 | |
| 68 | #ifndef OPENSSL_HEADER_EC_INTERNAL_H |
| 69 | #define OPENSSL_HEADER_EC_INTERNAL_H |
| 70 | |
| 71 | #include <openssl/base.h> |
| 72 | |
| 73 | #include <openssl/bn.h> |
| 74 | #include <openssl/ex_data.h> |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 75 | #include <openssl/thread.h> |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 76 | #include <openssl/type_check.h> |
| 77 | |
| 78 | #include "../bn/internal.h" |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 79 | |
| 80 | #if defined(__cplusplus) |
| 81 | extern "C" { |
| 82 | #endif |
| 83 | |
| 84 | |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 85 | // Cap the size of all field elements and scalars, including custom curves, to |
| 86 | // 66 bytes, large enough to fit secp521r1 and brainpoolP512r1, which appear to |
| 87 | // be the largest fields anyone plausibly uses. |
| 88 | #define EC_MAX_SCALAR_BYTES 66 |
| 89 | #define EC_MAX_SCALAR_WORDS ((66 + BN_BYTES - 1) / BN_BYTES) |
| 90 | |
| 91 | OPENSSL_COMPILE_ASSERT(EC_MAX_SCALAR_WORDS <= BN_SMALL_MAX_WORDS, |
| 92 | bn_small_functions_applicable); |
| 93 | |
Robert Sloan | cd79cde | 2017-12-11 09:06:12 -0800 | [diff] [blame] | 94 | // An EC_SCALAR is an integer fully reduced modulo the order. Only the first |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 95 | // |order->top| words are used. An |EC_SCALAR| is specific to an |EC_GROUP| and |
Robert Sloan | cd79cde | 2017-12-11 09:06:12 -0800 | [diff] [blame] | 96 | // must not be mixed between groups. |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 97 | typedef union { |
| 98 | // bytes is the representation of the scalar in little-endian order. |
| 99 | uint8_t bytes[EC_MAX_SCALAR_BYTES]; |
| 100 | BN_ULONG words[EC_MAX_SCALAR_WORDS]; |
| 101 | } EC_SCALAR; |
| 102 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 103 | struct ec_method_st { |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 104 | int (*group_init)(EC_GROUP *); |
| 105 | void (*group_finish)(EC_GROUP *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 106 | int (*group_set_curve)(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, |
| 107 | const BIGNUM *b, BN_CTX *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 108 | int (*point_get_affine_coordinates)(const EC_GROUP *, const EC_POINT *, |
| 109 | BIGNUM *x, BIGNUM *y, BN_CTX *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 110 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 111 | // Computes |r = g_scalar*generator + p_scalar*p| if |g_scalar| and |p_scalar| |
| 112 | // are both non-null. Computes |r = g_scalar*generator| if |p_scalar| is null. |
| 113 | // Computes |r = p_scalar*p| if g_scalar is null. At least one of |g_scalar| |
| 114 | // and |p_scalar| must be non-null, and |p| must be non-null if |p_scalar| is |
| 115 | // non-null. |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 116 | int (*mul)(const EC_GROUP *group, EC_POINT *r, const EC_SCALAR *g_scalar, |
| 117 | const EC_POINT *p, const EC_SCALAR *p_scalar, BN_CTX *ctx); |
Robert Sloan | 5581810 | 2017-12-18 11:26:17 -0800 | [diff] [blame] | 118 | // mul_public performs the same computation as mul. It further assumes that |
| 119 | // the inputs are public so there is no concern about leaking their values |
| 120 | // through timing. |
| 121 | int (*mul_public)(const EC_GROUP *group, EC_POINT *r, |
| 122 | const EC_SCALAR *g_scalar, const EC_POINT *p, |
| 123 | const EC_SCALAR *p_scalar, BN_CTX *ctx); |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 124 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 125 | // 'field_mul' and 'field_sqr' can be used by 'add' and 'dbl' so that the |
| 126 | // same implementations of point operations can be used with different |
| 127 | // optimized implementations of expensive field operations: |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 128 | int (*field_mul)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 129 | const BIGNUM *b, BN_CTX *); |
| 130 | int (*field_sqr)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 131 | |
| 132 | int (*field_encode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 133 | BN_CTX *); // e.g. to Montgomery |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 134 | int (*field_decode)(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 135 | BN_CTX *); // e.g. from Montgomery |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 136 | } /* EC_METHOD */; |
| 137 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 138 | const EC_METHOD *EC_GFp_mont_method(void); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 139 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 140 | struct ec_group_st { |
| 141 | const EC_METHOD *meth; |
| 142 | |
Robert Sloan | 29c1d2c | 2017-10-30 14:10:28 -0700 | [diff] [blame] | 143 | // Unlike all other |EC_POINT|s, |generator| does not own |generator->group| |
| 144 | // to avoid a reference cycle. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 145 | EC_POINT *generator; |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 146 | BIGNUM order; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 147 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 148 | int curve_name; // optional NID for named curve |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 149 | |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 150 | BN_MONT_CTX *order_mont; // data for ECDSA inverse |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 151 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 152 | // The following members are handled by the method functions, |
| 153 | // even if they appear generic |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 154 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 155 | BIGNUM field; // For curves over GF(p), this is the modulus. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 156 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 157 | BIGNUM a, b; // Curve coefficients. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 158 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 159 | int a_is_minus3; // enable optimized point arithmetics for special case |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 160 | |
Robert Sloan | 29c1d2c | 2017-10-30 14:10:28 -0700 | [diff] [blame] | 161 | CRYPTO_refcount_t references; |
| 162 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 163 | BN_MONT_CTX *mont; // Montgomery structure. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 164 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 165 | BIGNUM one; // The value one. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 166 | } /* EC_GROUP */; |
| 167 | |
| 168 | struct ec_point_st { |
Robert Sloan | 29c1d2c | 2017-10-30 14:10:28 -0700 | [diff] [blame] | 169 | // group is an owning reference to |group|, unless this is |
| 170 | // |group->generator|. |
| 171 | EC_GROUP *group; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 172 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 173 | BIGNUM X; |
| 174 | BIGNUM Y; |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 175 | BIGNUM Z; // Jacobian projective coordinates: |
| 176 | // (X, Y, Z) represents (X/Z^2, Y/Z^3) if Z != 0 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 177 | } /* EC_POINT */; |
| 178 | |
| 179 | EC_GROUP *ec_group_new(const EC_METHOD *meth); |
| 180 | |
Robert Sloan | cd79cde | 2017-12-11 09:06:12 -0800 | [diff] [blame] | 181 | // ec_bignum_to_scalar converts |in| to an |EC_SCALAR| and writes it to |
| 182 | // |*out|. It returns one on success and zero if |in| is out of range. |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 183 | int ec_bignum_to_scalar(const EC_GROUP *group, EC_SCALAR *out, |
| 184 | const BIGNUM *in); |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 185 | |
Robert Sloan | cd79cde | 2017-12-11 09:06:12 -0800 | [diff] [blame] | 186 | // ec_bignum_to_scalar_unchecked behaves like |ec_bignum_to_scalar| but does not |
| 187 | // check |in| is fully reduced. |
| 188 | int ec_bignum_to_scalar_unchecked(const EC_GROUP *group, EC_SCALAR *out, |
| 189 | const BIGNUM *in); |
| 190 | |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 191 | // ec_random_nonzero_scalar sets |out| to a uniformly selected random value from |
| 192 | // 1 to |group->order| - 1. It returns one on success and zero on error. |
| 193 | int ec_random_nonzero_scalar(const EC_GROUP *group, EC_SCALAR *out, |
| 194 | const uint8_t additional_data[32]); |
| 195 | |
| 196 | // ec_point_mul_scalar sets |r| to generator * |g_scalar| + |p| * |
| 197 | // |p_scalar|. Unlike other functions which take |EC_SCALAR|, |g_scalar| and |
| 198 | // |p_scalar| need not be fully reduced. They need only contain as many bits as |
| 199 | // the order. |
| 200 | int ec_point_mul_scalar(const EC_GROUP *group, EC_POINT *r, |
| 201 | const EC_SCALAR *g_scalar, const EC_POINT *p, |
| 202 | const EC_SCALAR *p_scalar, BN_CTX *ctx); |
| 203 | |
Robert Sloan | 5581810 | 2017-12-18 11:26:17 -0800 | [diff] [blame] | 204 | // ec_point_mul_scalar_public performs the same computation as |
| 205 | // ec_point_mul_scalar. It further assumes that the inputs are public so |
| 206 | // there is no concern about leaking their values through timing. |
| 207 | int ec_point_mul_scalar_public(const EC_GROUP *group, EC_POINT *r, |
| 208 | const EC_SCALAR *g_scalar, const EC_POINT *p, |
| 209 | const EC_SCALAR *p_scalar, BN_CTX *ctx); |
| 210 | |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 211 | int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const EC_SCALAR *g_scalar, |
| 212 | const EC_POINT *p, const EC_SCALAR *p_scalar, BN_CTX *ctx); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 213 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 214 | // method functions in simple.c |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 215 | int ec_GFp_simple_group_init(EC_GROUP *); |
| 216 | void ec_GFp_simple_group_finish(EC_GROUP *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 217 | int ec_GFp_simple_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, |
| 218 | const BIGNUM *b, BN_CTX *); |
| 219 | int ec_GFp_simple_group_get_curve(const EC_GROUP *, BIGNUM *p, BIGNUM *a, |
| 220 | BIGNUM *b, BN_CTX *); |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 221 | unsigned ec_GFp_simple_group_get_degree(const EC_GROUP *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 222 | int ec_GFp_simple_point_init(EC_POINT *); |
| 223 | void ec_GFp_simple_point_finish(EC_POINT *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 224 | int ec_GFp_simple_point_copy(EC_POINT *, const EC_POINT *); |
| 225 | int ec_GFp_simple_point_set_to_infinity(const EC_GROUP *, EC_POINT *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 226 | int ec_GFp_simple_point_set_affine_coordinates(const EC_GROUP *, EC_POINT *, |
| 227 | const BIGNUM *x, const BIGNUM *y, |
| 228 | BN_CTX *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 229 | int ec_GFp_simple_add(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
| 230 | const EC_POINT *b, BN_CTX *); |
| 231 | int ec_GFp_simple_dbl(const EC_GROUP *, EC_POINT *r, const EC_POINT *a, |
| 232 | BN_CTX *); |
| 233 | int ec_GFp_simple_invert(const EC_GROUP *, EC_POINT *, BN_CTX *); |
| 234 | int ec_GFp_simple_is_at_infinity(const EC_GROUP *, const EC_POINT *); |
| 235 | int ec_GFp_simple_is_on_curve(const EC_GROUP *, const EC_POINT *, BN_CTX *); |
| 236 | int ec_GFp_simple_cmp(const EC_GROUP *, const EC_POINT *a, const EC_POINT *b, |
| 237 | BN_CTX *); |
| 238 | int ec_GFp_simple_make_affine(const EC_GROUP *, EC_POINT *, BN_CTX *); |
| 239 | int ec_GFp_simple_points_make_affine(const EC_GROUP *, size_t num, |
| 240 | EC_POINT * [], BN_CTX *); |
| 241 | int ec_GFp_simple_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 242 | const BIGNUM *b, BN_CTX *); |
| 243 | int ec_GFp_simple_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 244 | BN_CTX *); |
| 245 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 246 | // method functions in montgomery.c |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 247 | int ec_GFp_mont_group_init(EC_GROUP *); |
| 248 | int ec_GFp_mont_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, |
| 249 | const BIGNUM *b, BN_CTX *); |
| 250 | void ec_GFp_mont_group_finish(EC_GROUP *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 251 | int ec_GFp_mont_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 252 | const BIGNUM *b, BN_CTX *); |
| 253 | int ec_GFp_mont_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 254 | BN_CTX *); |
| 255 | int ec_GFp_mont_field_encode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 256 | BN_CTX *); |
| 257 | int ec_GFp_mont_field_decode(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, |
| 258 | BN_CTX *); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 259 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 260 | void ec_GFp_nistp_recode_scalar_bits(uint8_t *sign, uint8_t *digit, uint8_t in); |
| 261 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 262 | const EC_METHOD *EC_GFp_nistp224_method(void); |
| 263 | const EC_METHOD *EC_GFp_nistp256_method(void); |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 264 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 265 | // EC_GFp_nistz256_method is a GFp method using montgomery multiplication, with |
| 266 | // x86-64 optimized P256. See http://eprint.iacr.org/2013/816. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 267 | const EC_METHOD *EC_GFp_nistz256_method(void); |
Adam Langley | fad6327 | 2015-11-12 12:15:39 -0800 | [diff] [blame] | 268 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 269 | struct ec_key_st { |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 270 | EC_GROUP *group; |
| 271 | |
| 272 | EC_POINT *pub_key; |
| 273 | BIGNUM *priv_key; |
| 274 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 275 | // fixed_k may contain a specific value of 'k', to be used in ECDSA signing. |
| 276 | // This is only for the FIPS power-on tests. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 277 | BIGNUM *fixed_k; |
| 278 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 279 | unsigned int enc_flag; |
| 280 | point_conversion_form_t conv_form; |
| 281 | |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 282 | CRYPTO_refcount_t references; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 283 | |
| 284 | ECDSA_METHOD *ecdsa_meth; |
| 285 | |
| 286 | CRYPTO_EX_DATA ex_data; |
| 287 | } /* EC_KEY */; |
| 288 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 289 | struct built_in_curve { |
| 290 | int nid; |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 291 | const uint8_t *oid; |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 292 | uint8_t oid_len; |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 293 | // comment is a human-readable string describing the curve. |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 294 | const char *comment; |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 295 | // param_len is the number of bytes needed to store a field element. |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 296 | uint8_t param_len; |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 297 | // params points to an array of 6*|param_len| bytes which hold the field |
| 298 | // elements of the following (in big-endian order): prime, a, b, generator x, |
| 299 | // generator y, order. |
Robert Sloan | e56da3e | 2017-06-26 08:26:42 -0700 | [diff] [blame] | 300 | const uint8_t *params; |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 301 | const EC_METHOD *method; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 302 | }; |
| 303 | |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 304 | #define OPENSSL_NUM_BUILT_IN_CURVES 4 |
| 305 | |
| 306 | struct built_in_curves { |
| 307 | struct built_in_curve curves[OPENSSL_NUM_BUILT_IN_CURVES]; |
| 308 | }; |
| 309 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 310 | // OPENSSL_built_in_curves returns a pointer to static information about |
| 311 | // standard curves. The array is terminated with an entry where |nid| is |
| 312 | // |NID_undef|. |
Robert Sloan | 8ff0355 | 2017-06-14 12:40:58 -0700 | [diff] [blame] | 313 | const struct built_in_curves *OPENSSL_built_in_curves(void); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 314 | |
| 315 | #if defined(__cplusplus) |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 316 | } // extern C |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 317 | #endif |
| 318 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 319 | #endif // OPENSSL_HEADER_EC_INTERNAL_H |