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_H |
| 69 | #define OPENSSL_HEADER_EC_H |
| 70 | |
| 71 | #include <openssl/base.h> |
| 72 | |
| 73 | #if defined(__cplusplus) |
| 74 | extern "C" { |
| 75 | #endif |
| 76 | |
| 77 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 78 | // Low-level operations on elliptic curves. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 79 | |
| 80 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 81 | // point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for |
| 82 | // the encoding of a elliptic curve point (x,y) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 83 | typedef enum { |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 84 | // POINT_CONVERSION_COMPRESSED indicates that the point is encoded as z||x, |
| 85 | // where the octet z specifies which solution of the quadratic equation y |
| 86 | // is. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 87 | POINT_CONVERSION_COMPRESSED = 2, |
| 88 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 89 | // POINT_CONVERSION_UNCOMPRESSED indicates that the point is encoded as |
| 90 | // z||x||y, where z is the octet 0x04. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 91 | POINT_CONVERSION_UNCOMPRESSED = 4, |
| 92 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 93 | // POINT_CONVERSION_HYBRID indicates that the point is encoded as z||x||y, |
| 94 | // where z specifies which solution of the quadratic equation y is. This is |
| 95 | // not supported by the code and has never been observed in use. |
| 96 | // |
| 97 | // TODO(agl): remove once node.js no longer references this. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 98 | POINT_CONVERSION_HYBRID = 6, |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 99 | } point_conversion_form_t; |
| 100 | |
| 101 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 102 | // Elliptic curve groups. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 103 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 104 | // EC_GROUP_new_by_curve_name returns a fresh EC_GROUP object for the elliptic |
| 105 | // curve specified by |nid|, or NULL on error. |
| 106 | // |
| 107 | // The supported NIDs are: |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame^] | 108 | // NID_secp224r1 (P-224), |
| 109 | // NID_X9_62_prime256v1 (P-256), |
| 110 | // NID_secp384r1 (P-384), |
| 111 | // NID_secp521r1 (P-521) |
| 112 | // |
| 113 | // If in doubt, use |NID_X9_62_prime256v1|, or see the curve25519.h header for |
| 114 | // more modern primitives. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 115 | OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid); |
| 116 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 117 | // EC_GROUP_free frees |group| and the data that it points to. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 118 | OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group); |
| 119 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 120 | // EC_GROUP_dup returns a fresh |EC_GROUP| which is equal to |a| or NULL on |
| 121 | // error. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 122 | OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *a); |
| 123 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 124 | // EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero |
| 125 | // otherwise. |
Adam Langley | 4c6611d | 2015-02-25 11:15:39 -0800 | [diff] [blame] | 126 | OPENSSL_EXPORT int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, |
| 127 | BN_CTX *ignored); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 128 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 129 | // EC_GROUP_get0_generator returns a pointer to the internal |EC_POINT| object |
| 130 | // in |group| that specifies the generator for the group. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 131 | OPENSSL_EXPORT const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group); |
| 132 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 133 | // EC_GROUP_get0_order returns a pointer to the internal |BIGNUM| object in |
| 134 | // |group| that specifies the order of the group. |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 135 | OPENSSL_EXPORT const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 136 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 137 | // EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group| using |
| 138 | // |ctx|, if it's not NULL. It returns one on success and zero otherwise. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 139 | OPENSSL_EXPORT int EC_GROUP_get_cofactor(const EC_GROUP *group, |
| 140 | BIGNUM *cofactor, BN_CTX *ctx); |
| 141 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 142 | // EC_GROUP_get_curve_GFp gets various parameters about a group. It sets |
| 143 | // |*out_p| to the order of the coordinate field and |*out_a| and |*out_b| to |
| 144 | // the parameters of the curve when expressed as y² = x³ + ax + b. Any of the |
| 145 | // output parameters can be NULL. It returns one on success and zero on |
| 146 | // error. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 147 | OPENSSL_EXPORT int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p, |
| 148 | BIGNUM *out_a, BIGNUM *out_b, |
| 149 | BN_CTX *ctx); |
| 150 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 151 | // EC_GROUP_get_curve_name returns a NID that identifies |group|. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 152 | OPENSSL_EXPORT int EC_GROUP_get_curve_name(const EC_GROUP *group); |
| 153 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 154 | // EC_GROUP_get_degree returns the number of bits needed to represent an |
| 155 | // element of the field underlying |group|. |
Kenny Root | e99801b | 2015-11-06 15:31:15 -0800 | [diff] [blame] | 156 | OPENSSL_EXPORT unsigned EC_GROUP_get_degree(const EC_GROUP *group); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 157 | |
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 | // Points on elliptic curves. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 160 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 161 | // EC_POINT_new returns a fresh |EC_POINT| object in the given group, or NULL |
| 162 | // on error. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 163 | OPENSSL_EXPORT EC_POINT *EC_POINT_new(const EC_GROUP *group); |
| 164 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 165 | // EC_POINT_free frees |point| and the data that it points to. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 166 | OPENSSL_EXPORT void EC_POINT_free(EC_POINT *point); |
| 167 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 168 | // EC_POINT_copy sets |*dest| equal to |*src|. It returns one on success and |
| 169 | // zero otherwise. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 170 | OPENSSL_EXPORT int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src); |
| 171 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 172 | // EC_POINT_dup returns a fresh |EC_POINT| that contains the same values as |
| 173 | // |src|, or NULL on error. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 174 | OPENSSL_EXPORT EC_POINT *EC_POINT_dup(const EC_POINT *src, |
| 175 | const EC_GROUP *group); |
| 176 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 177 | // EC_POINT_set_to_infinity sets |point| to be the "point at infinity" for the |
| 178 | // given group. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 179 | OPENSSL_EXPORT int EC_POINT_set_to_infinity(const EC_GROUP *group, |
| 180 | EC_POINT *point); |
| 181 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 182 | // EC_POINT_is_at_infinity returns one iff |point| is the point at infinity and |
| 183 | // zero otherwise. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 184 | OPENSSL_EXPORT int EC_POINT_is_at_infinity(const EC_GROUP *group, |
| 185 | const EC_POINT *point); |
| 186 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 187 | // EC_POINT_is_on_curve returns one if |point| is an element of |group| and |
| 188 | // and zero otherwise or when an error occurs. This is different from OpenSSL, |
| 189 | // which returns -1 on error. If |ctx| is non-NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 190 | OPENSSL_EXPORT int EC_POINT_is_on_curve(const EC_GROUP *group, |
| 191 | const EC_POINT *point, BN_CTX *ctx); |
| 192 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 193 | // EC_POINT_cmp returns zero if |a| is equal to |b|, greater than zero if |
| 194 | // not equal and -1 on error. If |ctx| is not NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 195 | OPENSSL_EXPORT int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a, |
| 196 | const EC_POINT *b, BN_CTX *ctx); |
| 197 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 198 | // EC_POINT_make_affine converts |point| to affine form, internally. It returns |
| 199 | // one on success and zero otherwise. If |ctx| is not NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 200 | OPENSSL_EXPORT int EC_POINT_make_affine(const EC_GROUP *group, EC_POINT *point, |
| 201 | BN_CTX *ctx); |
| 202 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 203 | // EC_POINTs_make_affine converts |num| points from |points| to affine form, |
| 204 | // internally. It returns one on success and zero otherwise. If |ctx| is not |
| 205 | // NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 206 | OPENSSL_EXPORT int EC_POINTs_make_affine(const EC_GROUP *group, size_t num, |
| 207 | EC_POINT *points[], BN_CTX *ctx); |
| 208 | |
| 209 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 210 | // Point conversion. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 211 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 212 | // EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of |
| 213 | // |point| using |ctx|, if it's not NULL. It returns one on success and zero |
| 214 | // otherwise. |
Robert Sloan | ab8b888 | 2018-03-26 11:39:51 -0700 | [diff] [blame^] | 215 | // |
| 216 | // Either |x| or |y| may be NULL to skip computing that coordinate. This is |
| 217 | // slightly faster in the common case where only the x-coordinate is needed. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 218 | OPENSSL_EXPORT int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, |
| 219 | const EC_POINT *point, |
| 220 | BIGNUM *x, BIGNUM *y, |
| 221 | BN_CTX *ctx); |
| 222 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 223 | // EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be |
| 224 | // (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one |
| 225 | // on success or zero on error. Note that, unlike with OpenSSL, it's |
| 226 | // considered an error if the point is not on the curve. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 227 | OPENSSL_EXPORT int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, |
| 228 | EC_POINT *point, |
| 229 | const BIGNUM *x, |
| 230 | const BIGNUM *y, |
| 231 | BN_CTX *ctx); |
| 232 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 233 | // EC_POINT_point2oct serialises |point| into the X9.62 form given by |form| |
| 234 | // into, at most, |len| bytes at |buf|. It returns the number of bytes written |
| 235 | // or zero on error if |buf| is non-NULL, else the number of bytes needed. The |
| 236 | // |ctx| argument may be used if not NULL. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 237 | OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group, |
| 238 | const EC_POINT *point, |
| 239 | point_conversion_form_t form, |
| 240 | uint8_t *buf, size_t len, BN_CTX *ctx); |
| 241 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 242 | // EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the |
| 243 | // serialised point to |cbb|. It returns one on success and zero on error. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 244 | OPENSSL_EXPORT int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group, |
| 245 | const EC_POINT *point, |
| 246 | point_conversion_form_t form, |
| 247 | BN_CTX *ctx); |
| 248 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 249 | // EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format |
| 250 | // serialisation in |buf|. It returns one on success and zero otherwise. The |
| 251 | // |ctx| argument may be used if not NULL. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 252 | OPENSSL_EXPORT int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point, |
| 253 | const uint8_t *buf, size_t len, |
| 254 | BN_CTX *ctx); |
| 255 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 256 | // EC_POINT_set_compressed_coordinates_GFp sets |point| to equal the point with |
| 257 | // the given |x| coordinate and the y coordinate specified by |y_bit| (see |
| 258 | // X9.62). It returns one on success and zero otherwise. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 259 | OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp( |
| 260 | const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, int y_bit, |
| 261 | BN_CTX *ctx); |
| 262 | |
| 263 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 264 | // Group operations. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 265 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 266 | // EC_POINT_add sets |r| equal to |a| plus |b|. It returns one on success and |
| 267 | // zero otherwise. If |ctx| is not NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 268 | OPENSSL_EXPORT int EC_POINT_add(const EC_GROUP *group, EC_POINT *r, |
| 269 | const EC_POINT *a, const EC_POINT *b, |
| 270 | BN_CTX *ctx); |
| 271 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 272 | // EC_POINT_dbl sets |r| equal to |a| plus |a|. It returns one on success and |
| 273 | // zero otherwise. If |ctx| is not NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 274 | OPENSSL_EXPORT int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r, |
| 275 | const EC_POINT *a, BN_CTX *ctx); |
| 276 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 277 | // EC_POINT_invert sets |a| equal to minus |a|. It returns one on success and |
| 278 | // zero otherwise. If |ctx| is not NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 279 | OPENSSL_EXPORT int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a, |
| 280 | BN_CTX *ctx); |
| 281 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 282 | // EC_POINT_mul sets r = generator*n + q*m. It returns one on success and zero |
| 283 | // otherwise. If |ctx| is not NULL, it may be used. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 284 | OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, |
| 285 | const BIGNUM *n, const EC_POINT *q, |
| 286 | const BIGNUM *m, BN_CTX *ctx); |
| 287 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 288 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 289 | // Deprecated functions. |
Adam Langley | f7e890d | 2015-03-31 18:58:05 -0700 | [diff] [blame] | 290 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 291 | // EC_GROUP_new_curve_GFp creates a new, arbitrary elliptic curve group based |
| 292 | // on the equation y² = x³ + a·x + b. It returns the new group or NULL on |
| 293 | // error. |
| 294 | // |
| 295 | // This new group has no generator. It is an error to use a generator-less group |
| 296 | // with any functions except for |EC_GROUP_free|, |EC_POINT_new|, |
| 297 | // |EC_POINT_set_affine_coordinates_GFp|, and |EC_GROUP_set_generator|. |
| 298 | // |
| 299 | // |EC_GROUP|s returned by this function will always compare as unequal via |
| 300 | // |EC_GROUP_cmp| (even to themselves). |EC_GROUP_get_curve_name| will always |
| 301 | // return |NID_undef|. |
| 302 | // |
| 303 | // Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name| instead. |
Adam Langley | 430091c | 2015-05-12 19:09:47 -0700 | [diff] [blame] | 304 | OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p, |
| 305 | const BIGNUM *a, |
| 306 | const BIGNUM *b, BN_CTX *ctx); |
| 307 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 308 | // EC_GROUP_set_generator sets the generator for |group| to |generator|, which |
| 309 | // must have the given order and cofactor. It may only be used with |EC_GROUP| |
| 310 | // objects returned by |EC_GROUP_new_curve_GFp| and may only be used once on |
Robert Sloan | 29c1d2c | 2017-10-30 14:10:28 -0700 | [diff] [blame] | 311 | // each group. |generator| must have been created using |group|. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 312 | OPENSSL_EXPORT int EC_GROUP_set_generator(EC_GROUP *group, |
| 313 | const EC_POINT *generator, |
| 314 | const BIGNUM *order, |
| 315 | const BIGNUM *cofactor); |
| 316 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 317 | // EC_GROUP_get_order sets |*order| to the order of |group|, if it's not |
| 318 | // NULL. It returns one on success and zero otherwise. |ctx| is ignored. Use |
| 319 | // |EC_GROUP_get0_order| instead. |
Adam Langley | 4139edb | 2016-01-13 15:00:54 -0800 | [diff] [blame] | 320 | OPENSSL_EXPORT int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, |
| 321 | BN_CTX *ctx); |
| 322 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 323 | // EC_GROUP_set_asn1_flag does nothing. |
Adam Langley | f7e890d | 2015-03-31 18:58:05 -0700 | [diff] [blame] | 324 | OPENSSL_EXPORT void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag); |
| 325 | |
| 326 | #define OPENSSL_EC_NAMED_CURVE 0 |
| 327 | |
| 328 | typedef struct ec_method_st EC_METHOD; |
| 329 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 330 | // EC_GROUP_method_of returns NULL. |
Adam Langley | f7e890d | 2015-03-31 18:58:05 -0700 | [diff] [blame] | 331 | OPENSSL_EXPORT const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group); |
| 332 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 333 | // EC_METHOD_get_field_type returns NID_X9_62_prime_field. |
Adam Langley | f7e890d | 2015-03-31 18:58:05 -0700 | [diff] [blame] | 334 | OPENSSL_EXPORT int EC_METHOD_get_field_type(const EC_METHOD *meth); |
| 335 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 336 | // EC_GROUP_set_point_conversion_form aborts the process if |form| is not |
| 337 | // |POINT_CONVERSION_UNCOMPRESSED| and otherwise does nothing. |
Adam Langley | 217eaab | 2015-04-21 11:00:35 -0700 | [diff] [blame] | 338 | OPENSSL_EXPORT void EC_GROUP_set_point_conversion_form( |
| 339 | EC_GROUP *group, point_conversion_form_t form); |
Adam Langley | 830beae | 2015-04-20 10:49:33 -0700 | [diff] [blame] | 340 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 341 | // EC_builtin_curve describes a supported elliptic curve. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 342 | typedef struct { |
| 343 | int nid; |
| 344 | const char *comment; |
| 345 | } EC_builtin_curve; |
| 346 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 347 | // EC_get_builtin_curves writes at most |max_num_curves| elements to |
| 348 | // |out_curves| and returns the total number that it would have written, had |
| 349 | // |max_num_curves| been large enough. |
| 350 | // |
| 351 | // The |EC_builtin_curve| items describe the supported elliptic curves. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 352 | OPENSSL_EXPORT size_t EC_get_builtin_curves(EC_builtin_curve *out_curves, |
| 353 | size_t max_num_curves); |
Adam Langley | f7e890d | 2015-03-31 18:58:05 -0700 | [diff] [blame] | 354 | |
Robert Sloan | 29c1d2c | 2017-10-30 14:10:28 -0700 | [diff] [blame] | 355 | // EC_POINT_clear_free calls |EC_POINT_free|. |
| 356 | OPENSSL_EXPORT void EC_POINT_clear_free(EC_POINT *point); |
| 357 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 358 | // Old code expects to get EC_KEY from ec.h. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 359 | #include <openssl/ec_key.h> |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 360 | |
| 361 | |
| 362 | #if defined(__cplusplus) |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 363 | } // extern C |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 364 | |
| 365 | extern "C++" { |
| 366 | |
| 367 | namespace bssl { |
| 368 | |
| 369 | BORINGSSL_MAKE_DELETER(EC_POINT, EC_POINT_free) |
| 370 | BORINGSSL_MAKE_DELETER(EC_GROUP, EC_GROUP_free) |
| 371 | |
| 372 | } // namespace bssl |
| 373 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 374 | } // extern C++ |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 375 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 376 | #endif |
| 377 | |
Adam Langley | e9ada86 | 2015-05-11 17:20:37 -0700 | [diff] [blame] | 378 | #define EC_R_BUFFER_TOO_SMALL 100 |
| 379 | #define EC_R_COORDINATES_OUT_OF_RANGE 101 |
| 380 | #define EC_R_D2I_ECPKPARAMETERS_FAILURE 102 |
| 381 | #define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 103 |
| 382 | #define EC_R_GROUP2PKPARAMETERS_FAILURE 104 |
| 383 | #define EC_R_I2D_ECPKPARAMETERS_FAILURE 105 |
| 384 | #define EC_R_INCOMPATIBLE_OBJECTS 106 |
| 385 | #define EC_R_INVALID_COMPRESSED_POINT 107 |
| 386 | #define EC_R_INVALID_COMPRESSION_BIT 108 |
| 387 | #define EC_R_INVALID_ENCODING 109 |
| 388 | #define EC_R_INVALID_FIELD 110 |
| 389 | #define EC_R_INVALID_FORM 111 |
| 390 | #define EC_R_INVALID_GROUP_ORDER 112 |
| 391 | #define EC_R_INVALID_PRIVATE_KEY 113 |
| 392 | #define EC_R_MISSING_PARAMETERS 114 |
| 393 | #define EC_R_MISSING_PRIVATE_KEY 115 |
| 394 | #define EC_R_NON_NAMED_CURVE 116 |
| 395 | #define EC_R_NOT_INITIALIZED 117 |
| 396 | #define EC_R_PKPARAMETERS2GROUP_FAILURE 118 |
| 397 | #define EC_R_POINT_AT_INFINITY 119 |
| 398 | #define EC_R_POINT_IS_NOT_ON_CURVE 120 |
| 399 | #define EC_R_SLOT_FULL 121 |
| 400 | #define EC_R_UNDEFINED_GENERATOR 122 |
| 401 | #define EC_R_UNKNOWN_GROUP 123 |
| 402 | #define EC_R_UNKNOWN_ORDER 124 |
| 403 | #define EC_R_WRONG_ORDER 125 |
| 404 | #define EC_R_BIGNUM_OUT_OF_RANGE 126 |
| 405 | #define EC_R_WRONG_CURVE_PARAMETERS 127 |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 406 | #define EC_R_DECODE_ERROR 128 |
| 407 | #define EC_R_ENCODE_ERROR 129 |
| 408 | #define EC_R_GROUP_MISMATCH 130 |
David Benjamin | c895d6b | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 409 | #define EC_R_INVALID_COFACTOR 131 |
Robert Sloan | 572a4e2 | 2017-04-17 10:52:19 -0700 | [diff] [blame] | 410 | #define EC_R_PUBLIC_KEY_VALIDATION_FAILED 132 |
Robert Sloan | 99319a1 | 2017-11-27 10:32:46 -0800 | [diff] [blame] | 411 | #define EC_R_INVALID_SCALAR 133 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 412 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 413 | #endif // OPENSSL_HEADER_EC_H |