2014-07-14 23:28:14 +01:00
|
|
|
/* Originally written by Bodo Moeller for the OpenSSL project.
|
|
|
|
* ====================================================================
|
|
|
|
* Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
*
|
|
|
|
* 3. All advertising materials mentioning features or use of this
|
|
|
|
* software must display the following acknowledgment:
|
|
|
|
* "This product includes software developed by the OpenSSL Project
|
|
|
|
* for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
|
|
|
|
*
|
|
|
|
* 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
|
|
|
|
* endorse or promote products derived from this software without
|
|
|
|
* prior written permission. For written permission, please contact
|
|
|
|
* openssl-core@openssl.org.
|
|
|
|
*
|
|
|
|
* 5. Products derived from this software may not be called "OpenSSL"
|
|
|
|
* nor may "OpenSSL" appear in their names without prior written
|
|
|
|
* permission of the OpenSSL Project.
|
|
|
|
*
|
|
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
|
|
|
* acknowledgment:
|
|
|
|
* "This product includes software developed by the OpenSSL Project
|
|
|
|
* for use in the OpenSSL Toolkit (http://www.openssl.org/)"
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
|
|
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
|
|
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* ====================================================================
|
|
|
|
*
|
|
|
|
* This product includes cryptographic software written by Eric Young
|
|
|
|
* (eay@cryptsoft.com). This product includes software written by Tim
|
|
|
|
* Hudson (tjh@cryptsoft.com).
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
/* ====================================================================
|
|
|
|
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
|
|
|
|
*
|
|
|
|
* Portions of the attached software ("Contribution") are developed by
|
|
|
|
* SUN MICROSYSTEMS, INC., and are contributed to the OpenSSL project.
|
|
|
|
*
|
|
|
|
* The Contribution is licensed pursuant to the OpenSSL open source
|
|
|
|
* license provided above.
|
|
|
|
*
|
|
|
|
* The elliptic curve binary polynomial software is originally written by
|
|
|
|
* Sheueling Chang Shantz and Douglas Stebila of Sun Microsystems
|
|
|
|
* Laboratories. */
|
|
|
|
|
|
|
|
#ifndef OPENSSL_HEADER_EC_H
|
|
|
|
#define OPENSSL_HEADER_EC_H
|
|
|
|
|
|
|
|
#include <openssl/base.h>
|
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Low-level operations on elliptic curves.
|
2014-12-26 05:54:52 +00:00
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// point_conversion_form_t enumerates forms, as defined in X9.62 (ECDSA), for
|
|
|
|
// the encoding of a elliptic curve point (x,y)
|
2014-07-14 23:28:14 +01:00
|
|
|
typedef enum {
|
2017-08-19 00:21:50 +01:00
|
|
|
// POINT_CONVERSION_COMPRESSED indicates that the point is encoded as z||x,
|
|
|
|
// where the octet z specifies which solution of the quadratic equation y
|
|
|
|
// is.
|
2016-01-24 23:58:39 +00:00
|
|
|
POINT_CONVERSION_COMPRESSED = 2,
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// POINT_CONVERSION_UNCOMPRESSED indicates that the point is encoded as
|
|
|
|
// z||x||y, where z is the octet 0x04.
|
2016-01-24 23:58:39 +00:00
|
|
|
POINT_CONVERSION_UNCOMPRESSED = 4,
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// POINT_CONVERSION_HYBRID indicates that the point is encoded as z||x||y,
|
|
|
|
// where z specifies which solution of the quadratic equation y is. This is
|
|
|
|
// not supported by the code and has never been observed in use.
|
|
|
|
//
|
|
|
|
// TODO(agl): remove once node.js no longer references this.
|
2016-01-24 23:58:39 +00:00
|
|
|
POINT_CONVERSION_HYBRID = 6,
|
2014-07-14 23:28:14 +01:00
|
|
|
} point_conversion_form_t;
|
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Elliptic curve groups.
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_new_by_curve_name returns a fresh EC_GROUP object for the elliptic
|
|
|
|
// curve specified by |nid|, or NULL on error.
|
|
|
|
//
|
|
|
|
// The supported NIDs are:
|
2018-03-20 19:56:17 +00:00
|
|
|
// NID_secp224r1 (P-224),
|
|
|
|
// NID_X9_62_prime256v1 (P-256),
|
|
|
|
// NID_secp384r1 (P-384),
|
|
|
|
// NID_secp521r1 (P-521)
|
|
|
|
//
|
|
|
|
// If in doubt, use |NID_X9_62_prime256v1|, or see the curve25519.h header for
|
|
|
|
// more modern primitives.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_by_curve_name(int nid);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2018-04-24 03:55:35 +01:00
|
|
|
// EC_GROUP_free releases a reference to |group|.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT void EC_GROUP_free(EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2018-04-24 03:55:35 +01:00
|
|
|
// EC_GROUP_dup takes a reference to |a| and returns it.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT EC_GROUP *EC_GROUP_dup(const EC_GROUP *a);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_cmp returns zero if |a| and |b| are the same group and non-zero
|
|
|
|
// otherwise.
|
2015-02-13 18:47:56 +00:00
|
|
|
OPENSSL_EXPORT int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b,
|
|
|
|
BN_CTX *ignored);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get0_generator returns a pointer to the internal |EC_POINT| object
|
|
|
|
// in |group| that specifies the generator for the group.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT const EC_POINT *EC_GROUP_get0_generator(const EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get0_order returns a pointer to the internal |BIGNUM| object in
|
|
|
|
// |group| that specifies the order of the group.
|
2015-11-19 03:07:14 +00:00
|
|
|
OPENSSL_EXPORT const BIGNUM *EC_GROUP_get0_order(const EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get_cofactor sets |*cofactor| to the cofactor of |group| using
|
|
|
|
// |ctx|, if it's not NULL. It returns one on success and zero otherwise.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_GROUP_get_cofactor(const EC_GROUP *group,
|
|
|
|
BIGNUM *cofactor, BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get_curve_GFp gets various parameters about a group. It sets
|
|
|
|
// |*out_p| to the order of the coordinate field and |*out_a| and |*out_b| to
|
|
|
|
// the parameters of the curve when expressed as y² = x³ + ax + b. Any of the
|
|
|
|
// output parameters can be NULL. It returns one on success and zero on
|
|
|
|
// error.
|
2014-08-22 20:24:16 +01:00
|
|
|
OPENSSL_EXPORT int EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *out_p,
|
|
|
|
BIGNUM *out_a, BIGNUM *out_b,
|
|
|
|
BN_CTX *ctx);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get_curve_name returns a NID that identifies |group|.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_GROUP_get_curve_name(const EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get_degree returns the number of bits needed to represent an
|
|
|
|
// element of the field underlying |group|.
|
2015-10-09 04:10:15 +01:00
|
|
|
OPENSSL_EXPORT unsigned EC_GROUP_get_degree(const EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Points on elliptic curves.
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_new returns a fresh |EC_POINT| object in the given group, or NULL
|
|
|
|
// on error.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT EC_POINT *EC_POINT_new(const EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_free frees |point| and the data that it points to.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT void EC_POINT_free(EC_POINT *point);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_copy sets |*dest| equal to |*src|. It returns one on success and
|
|
|
|
// zero otherwise.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_dup returns a fresh |EC_POINT| that contains the same values as
|
|
|
|
// |src|, or NULL on error.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT EC_POINT *EC_POINT_dup(const EC_POINT *src,
|
|
|
|
const EC_GROUP *group);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_set_to_infinity sets |point| to be the "point at infinity" for the
|
|
|
|
// given group.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_set_to_infinity(const EC_GROUP *group,
|
|
|
|
EC_POINT *point);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_is_at_infinity returns one iff |point| is the point at infinity and
|
|
|
|
// zero otherwise.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_is_at_infinity(const EC_GROUP *group,
|
|
|
|
const EC_POINT *point);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_is_on_curve returns one if |point| is an element of |group| and
|
|
|
|
// and zero otherwise or when an error occurs. This is different from OpenSSL,
|
|
|
|
// which returns -1 on error. If |ctx| is non-NULL, it may be used.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_is_on_curve(const EC_GROUP *group,
|
|
|
|
const EC_POINT *point, BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_cmp returns zero if |a| is equal to |b|, greater than zero if
|
|
|
|
// not equal and -1 on error. If |ctx| is not NULL, it may be used.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_cmp(const EC_GROUP *group, const EC_POINT *a,
|
|
|
|
const EC_POINT *b, BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Point conversion.
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_get_affine_coordinates_GFp sets |x| and |y| to the affine value of
|
|
|
|
// |point| using |ctx|, if it's not NULL. It returns one on success and zero
|
|
|
|
// otherwise.
|
2018-03-05 18:53:54 +00:00
|
|
|
//
|
|
|
|
// Either |x| or |y| may be NULL to skip computing that coordinate. This is
|
|
|
|
// slightly faster in the common case where only the x-coordinate is needed.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group,
|
|
|
|
const EC_POINT *point,
|
|
|
|
BIGNUM *x, BIGNUM *y,
|
|
|
|
BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_set_affine_coordinates_GFp sets the value of |point| to be
|
|
|
|
// (|x|, |y|). The |ctx| argument may be used if not NULL. It returns one
|
|
|
|
// on success or zero on error. Note that, unlike with OpenSSL, it's
|
|
|
|
// considered an error if the point is not on the curve.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group,
|
|
|
|
EC_POINT *point,
|
|
|
|
const BIGNUM *x,
|
|
|
|
const BIGNUM *y,
|
|
|
|
BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_point2oct serialises |point| into the X9.62 form given by |form|
|
|
|
|
// into, at most, |len| bytes at |buf|. It returns the number of bytes written
|
|
|
|
// or zero on error if |buf| is non-NULL, else the number of bytes needed. The
|
|
|
|
// |ctx| argument may be used if not NULL.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT size_t EC_POINT_point2oct(const EC_GROUP *group,
|
|
|
|
const EC_POINT *point,
|
|
|
|
point_conversion_form_t form,
|
|
|
|
uint8_t *buf, size_t len, BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_point2cbb behaves like |EC_POINT_point2oct| but appends the
|
|
|
|
// serialised point to |cbb|. It returns one on success and zero on error.
|
2015-12-31 02:39:34 +00:00
|
|
|
OPENSSL_EXPORT int EC_POINT_point2cbb(CBB *out, const EC_GROUP *group,
|
|
|
|
const EC_POINT *point,
|
|
|
|
point_conversion_form_t form,
|
|
|
|
BN_CTX *ctx);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_oct2point sets |point| from |len| bytes of X9.62 format
|
|
|
|
// serialisation in |buf|. It returns one on success and zero otherwise. The
|
|
|
|
// |ctx| argument may be used if not NULL.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
|
|
|
|
const uint8_t *buf, size_t len,
|
|
|
|
BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_set_compressed_coordinates_GFp sets |point| to equal the point with
|
|
|
|
// the given |x| coordinate and the y coordinate specified by |y_bit| (see
|
|
|
|
// X9.62). It returns one on success and zero otherwise.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_set_compressed_coordinates_GFp(
|
|
|
|
const EC_GROUP *group, EC_POINT *point, const BIGNUM *x, int y_bit,
|
|
|
|
BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Group operations.
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_add sets |r| equal to |a| plus |b|. It returns one on success and
|
|
|
|
// zero otherwise. If |ctx| is not NULL, it may be used.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_add(const EC_GROUP *group, EC_POINT *r,
|
|
|
|
const EC_POINT *a, const EC_POINT *b,
|
|
|
|
BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_dbl sets |r| equal to |a| plus |a|. It returns one on success and
|
|
|
|
// zero otherwise. If |ctx| is not NULL, it may be used.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_dbl(const EC_GROUP *group, EC_POINT *r,
|
|
|
|
const EC_POINT *a, BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_invert sets |a| equal to minus |a|. It returns one on success and
|
|
|
|
// zero otherwise. If |ctx| is not NULL, it may be used.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_invert(const EC_GROUP *group, EC_POINT *a,
|
|
|
|
BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_POINT_mul sets r = generator*n + q*m. It returns one on success and zero
|
|
|
|
// otherwise. If |ctx| is not NULL, it may be used.
|
2014-07-31 00:02:14 +01:00
|
|
|
OPENSSL_EXPORT int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r,
|
|
|
|
const BIGNUM *n, const EC_POINT *q,
|
|
|
|
const BIGNUM *m, BN_CTX *ctx);
|
2014-07-14 23:28:14 +01:00
|
|
|
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Deprecated functions.
|
|
|
|
|
|
|
|
// EC_GROUP_new_curve_GFp creates a new, arbitrary elliptic curve group based
|
|
|
|
// on the equation y² = x³ + a·x + b. It returns the new group or NULL on
|
|
|
|
// error.
|
|
|
|
//
|
|
|
|
// This new group has no generator. It is an error to use a generator-less group
|
|
|
|
// with any functions except for |EC_GROUP_free|, |EC_POINT_new|,
|
|
|
|
// |EC_POINT_set_affine_coordinates_GFp|, and |EC_GROUP_set_generator|.
|
|
|
|
//
|
|
|
|
// |EC_GROUP|s returned by this function will always compare as unequal via
|
|
|
|
// |EC_GROUP_cmp| (even to themselves). |EC_GROUP_get_curve_name| will always
|
|
|
|
// return |NID_undef|.
|
|
|
|
//
|
|
|
|
// Avoid using arbitrary curves and use |EC_GROUP_new_by_curve_name| instead.
|
2016-03-11 21:08:39 +00:00
|
|
|
OPENSSL_EXPORT EC_GROUP *EC_GROUP_new_curve_GFp(const BIGNUM *p,
|
|
|
|
const BIGNUM *a,
|
|
|
|
const BIGNUM *b, BN_CTX *ctx);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_set_generator sets the generator for |group| to |generator|, which
|
|
|
|
// must have the given order and cofactor. It may only be used with |EC_GROUP|
|
|
|
|
// objects returned by |EC_GROUP_new_curve_GFp| and may only be used once on
|
2017-10-26 20:48:18 +01:00
|
|
|
// each group. |generator| must have been created using |group|.
|
2016-03-11 21:08:39 +00:00
|
|
|
OPENSSL_EXPORT int EC_GROUP_set_generator(EC_GROUP *group,
|
|
|
|
const EC_POINT *generator,
|
|
|
|
const BIGNUM *order,
|
|
|
|
const BIGNUM *cofactor);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_get_order sets |*order| to the order of |group|, if it's not
|
|
|
|
// NULL. It returns one on success and zero otherwise. |ctx| is ignored. Use
|
|
|
|
// |EC_GROUP_get0_order| instead.
|
2015-11-19 03:07:14 +00:00
|
|
|
OPENSSL_EXPORT int EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order,
|
|
|
|
BN_CTX *ctx);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_set_asn1_flag does nothing.
|
2015-04-13 22:34:17 +01:00
|
|
|
OPENSSL_EXPORT void EC_GROUP_set_asn1_flag(EC_GROUP *group, int flag);
|
|
|
|
|
|
|
|
#define OPENSSL_EC_NAMED_CURVE 0
|
|
|
|
|
|
|
|
typedef struct ec_method_st EC_METHOD;
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_method_of returns NULL.
|
2015-04-13 22:34:17 +01:00
|
|
|
OPENSSL_EXPORT const EC_METHOD *EC_GROUP_method_of(const EC_GROUP *group);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_METHOD_get_field_type returns NID_X9_62_prime_field.
|
2015-04-13 22:34:17 +01:00
|
|
|
OPENSSL_EXPORT int EC_METHOD_get_field_type(const EC_METHOD *meth);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_GROUP_set_point_conversion_form aborts the process if |form| is not
|
|
|
|
// |POINT_CONVERSION_UNCOMPRESSED| and otherwise does nothing.
|
2015-05-05 01:43:00 +01:00
|
|
|
OPENSSL_EXPORT void EC_GROUP_set_point_conversion_form(
|
|
|
|
EC_GROUP *group, point_conversion_form_t form);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_builtin_curve describes a supported elliptic curve.
|
2016-01-24 23:58:39 +00:00
|
|
|
typedef struct {
|
|
|
|
int nid;
|
|
|
|
const char *comment;
|
|
|
|
} EC_builtin_curve;
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// EC_get_builtin_curves writes at most |max_num_curves| elements to
|
|
|
|
// |out_curves| and returns the total number that it would have written, had
|
|
|
|
// |max_num_curves| been large enough.
|
|
|
|
//
|
|
|
|
// The |EC_builtin_curve| items describe the supported elliptic curves.
|
2016-01-24 23:58:39 +00:00
|
|
|
OPENSSL_EXPORT size_t EC_get_builtin_curves(EC_builtin_curve *out_curves,
|
|
|
|
size_t max_num_curves);
|
2015-04-13 22:34:17 +01:00
|
|
|
|
2017-10-27 02:13:16 +01:00
|
|
|
// EC_POINT_clear_free calls |EC_POINT_free|.
|
|
|
|
OPENSSL_EXPORT void EC_POINT_clear_free(EC_POINT *point);
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
// Old code expects to get EC_KEY from ec.h.
|
2016-07-12 16:03:59 +01:00
|
|
|
#include <openssl/ec_key.h>
|
|
|
|
|
2014-07-14 23:28:14 +01:00
|
|
|
|
|
|
|
#if defined(__cplusplus)
|
2017-08-19 00:21:50 +01:00
|
|
|
} // extern C
|
2016-08-18 04:10:28 +01:00
|
|
|
|
|
|
|
extern "C++" {
|
|
|
|
|
|
|
|
namespace bssl {
|
|
|
|
|
|
|
|
BORINGSSL_MAKE_DELETER(EC_POINT, EC_POINT_free)
|
|
|
|
BORINGSSL_MAKE_DELETER(EC_GROUP, EC_GROUP_free)
|
|
|
|
|
|
|
|
} // namespace bssl
|
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
} // extern C++
|
2016-08-18 04:10:28 +01:00
|
|
|
|
2014-07-14 23:28:14 +01:00
|
|
|
#endif
|
|
|
|
|
2015-02-11 20:55:26 +00:00
|
|
|
#define EC_R_BUFFER_TOO_SMALL 100
|
|
|
|
#define EC_R_COORDINATES_OUT_OF_RANGE 101
|
|
|
|
#define EC_R_D2I_ECPKPARAMETERS_FAILURE 102
|
|
|
|
#define EC_R_EC_GROUP_NEW_BY_NAME_FAILURE 103
|
|
|
|
#define EC_R_GROUP2PKPARAMETERS_FAILURE 104
|
|
|
|
#define EC_R_I2D_ECPKPARAMETERS_FAILURE 105
|
|
|
|
#define EC_R_INCOMPATIBLE_OBJECTS 106
|
|
|
|
#define EC_R_INVALID_COMPRESSED_POINT 107
|
|
|
|
#define EC_R_INVALID_COMPRESSION_BIT 108
|
|
|
|
#define EC_R_INVALID_ENCODING 109
|
|
|
|
#define EC_R_INVALID_FIELD 110
|
|
|
|
#define EC_R_INVALID_FORM 111
|
|
|
|
#define EC_R_INVALID_GROUP_ORDER 112
|
|
|
|
#define EC_R_INVALID_PRIVATE_KEY 113
|
|
|
|
#define EC_R_MISSING_PARAMETERS 114
|
|
|
|
#define EC_R_MISSING_PRIVATE_KEY 115
|
|
|
|
#define EC_R_NON_NAMED_CURVE 116
|
|
|
|
#define EC_R_NOT_INITIALIZED 117
|
|
|
|
#define EC_R_PKPARAMETERS2GROUP_FAILURE 118
|
|
|
|
#define EC_R_POINT_AT_INFINITY 119
|
|
|
|
#define EC_R_POINT_IS_NOT_ON_CURVE 120
|
|
|
|
#define EC_R_SLOT_FULL 121
|
|
|
|
#define EC_R_UNDEFINED_GENERATOR 122
|
|
|
|
#define EC_R_UNKNOWN_GROUP 123
|
|
|
|
#define EC_R_UNKNOWN_ORDER 124
|
|
|
|
#define EC_R_WRONG_ORDER 125
|
2015-04-14 20:07:44 +01:00
|
|
|
#define EC_R_BIGNUM_OUT_OF_RANGE 126
|
|
|
|
#define EC_R_WRONG_CURVE_PARAMETERS 127
|
2016-01-03 08:57:37 +00:00
|
|
|
#define EC_R_DECODE_ERROR 128
|
|
|
|
#define EC_R_ENCODE_ERROR 129
|
|
|
|
#define EC_R_GROUP_MISMATCH 130
|
2016-06-16 19:58:36 +01:00
|
|
|
#define EC_R_INVALID_COFACTOR 131
|
2017-04-13 18:14:12 +01:00
|
|
|
#define EC_R_PUBLIC_KEY_VALIDATION_FAILED 132
|
Make ECDSA signing 10% faster and plug some timing leaks.
None of the asymmetric crypto we inherented from OpenSSL is
constant-time because of BIGNUM. BIGNUM chops leading zeros off the
front of everything, so we end up leaking information about the first
word, in theory. BIGNUM functions additionally tend to take the full
range of inputs and then call into BN_nnmod at various points.
All our secret values should be acted on in constant-time, but k in
ECDSA is a particularly sensitive value. So, ecdsa_sign_setup, in an
attempt to mitigate the BIGNUM leaks, would add a couple copies of the
order.
This does not work at all. k is used to compute two values: k^-1 and kG.
The first operation when computing k^-1 is to call BN_nnmod if k is out
of range. The entry point to our tuned constant-time curve
implementations is to call BN_nnmod if the scalar has too many bits,
which this causes. The result is both corrections are immediately undone
but cause us to do more variable-time work in the meantime.
Replace all these computations around k with the word-based functions
added in the various preceding CLs. In doing so, replace the BN_mod_mul
calls (which internally call BN_nnmod) with Montgomery reduction. We can
avoid taking k^-1 out of Montgomery form, which combines nicely with
Brian Smith's trick in 3426d1011946b26ff1bb2fd98a081ba4753c9cc8. Along
the way, we avoid some unnecessary mallocs.
BIGNUM still affects the private key itself, as well as the EC_POINTs.
But this should hopefully be much better now. Also it's 10% faster:
Before:
Did 15000 ECDSA P-224 signing operations in 1069117us (14030.3 ops/sec)
Did 18000 ECDSA P-256 signing operations in 1053908us (17079.3 ops/sec)
Did 1078 ECDSA P-384 signing operations in 1087853us (990.9 ops/sec)
Did 473 ECDSA P-521 signing operations in 1069835us (442.1 ops/sec)
After:
Did 16000 ECDSA P-224 signing operations in 1064799us (15026.3 ops/sec)
Did 19000 ECDSA P-256 signing operations in 1007839us (18852.2 ops/sec)
Did 1078 ECDSA P-384 signing operations in 1079413us (998.7 ops/sec)
Did 484 ECDSA P-521 signing operations in 1083616us (446.7 ops/sec)
Change-Id: I2a25e90fc99dac13c0616d0ea45e125a4bd8cca1
Reviewed-on: https://boringssl-review.googlesource.com/23075
Reviewed-by: Adam Langley <agl@google.com>
2017-11-13 03:58:00 +00:00
|
|
|
#define EC_R_INVALID_SCALAR 133
|
2014-07-14 23:28:14 +01:00
|
|
|
|
2017-08-19 00:21:50 +01:00
|
|
|
#endif // OPENSSL_HEADER_EC_H
|