Latest update, add TLS 1.3 session time configuration.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2016-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -254,6 +254,7 @@ static void x25519_scalar_mulx(uint8_t out[32], const uint8_t scalar[32],
|
||||
#if defined(X25519_ASM) \
|
||||
|| ( (defined(__SIZEOF_INT128__) && __SIZEOF_INT128__ == 16) \
|
||||
&& !defined(__sparc__) \
|
||||
&& (!defined(__SIZEOF_LONG__) || (__SIZEOF_LONG__ == 8)) \
|
||||
&& !(defined(__ANDROID__) && !defined(__clang__)) )
|
||||
/*
|
||||
* Base 2^51 implementation. It's virtually no different from reference
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2017-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2015 Cryptography Research, Inc.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -24,7 +24,9 @@
|
||||
*/
|
||||
# ifndef C448_WORD_BITS
|
||||
# if (defined(__SIZEOF_INT128__) && (__SIZEOF_INT128__ == 16)) \
|
||||
&& !defined(__sparc__)
|
||||
&& !defined(__sparc__) \
|
||||
&& (!defined(__SIZEOF_LONG__) || (__SIZEOF_LONG__ == 8))
|
||||
|
||||
# define C448_WORD_BITS 64 /* The number of bits in a word */
|
||||
# else
|
||||
# define C448_WORD_BITS 32 /* The number of bits in a word */
|
||||
|
||||
+16
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
* this file except in compliance with the License. You can obtain a copy
|
||||
@@ -10,6 +10,16 @@
|
||||
#include "ec_lcl.h"
|
||||
#include <openssl/err.h>
|
||||
|
||||
int EC_GROUP_check_named_curve(const EC_GROUP *group, int nist_only)
|
||||
{
|
||||
int nid;
|
||||
|
||||
nid = ec_curve_nid_from_params(group);
|
||||
if (nid > 0 && nist_only && EC_curve_nid2nist(nid) == NULL)
|
||||
nid = NID_undef;
|
||||
return nid;
|
||||
}
|
||||
|
||||
int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -17,6 +27,11 @@ int EC_GROUP_check(const EC_GROUP *group, BN_CTX *ctx)
|
||||
BN_CTX *new_ctx = NULL;
|
||||
EC_POINT *point = NULL;
|
||||
|
||||
if (group == NULL || group->meth == NULL) {
|
||||
ECerr(EC_F_EC_GROUP_CHECK, ERR_R_PASSED_NULL_PARAMETER);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Custom curves assumed to be correct */
|
||||
if ((group->meth->flags & EC_FLAGS_CUSTOM_CURVE) != 0)
|
||||
return 1;
|
||||
|
||||
+122
-1
@@ -14,6 +14,7 @@
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/opensslconf.h>
|
||||
#include "internal/nelem.h"
|
||||
#include "internal/o_str.h"
|
||||
|
||||
typedef struct {
|
||||
int field_type, /* either NID_X9_62_prime_field or
|
||||
@@ -1136,6 +1137,7 @@ static const struct {
|
||||
},
|
||||
{
|
||||
/* no seed */
|
||||
/* p */
|
||||
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
@@ -1209,6 +1211,7 @@ static const struct {
|
||||
},
|
||||
{
|
||||
/* no seed */
|
||||
/* p */
|
||||
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
|
||||
@@ -1244,6 +1247,7 @@ static const struct {
|
||||
},
|
||||
{
|
||||
/* no seed */
|
||||
/* p */
|
||||
0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0xA1,
|
||||
@@ -1278,7 +1282,7 @@ static const struct {
|
||||
NID_X9_62_characteristic_two_field, 20, 36, 2
|
||||
},
|
||||
{
|
||||
/* no seed */
|
||||
/* seed */
|
||||
0x77, 0xE2, 0xB0, 0x73, 0x70, 0xEB, 0x0F, 0x83, 0x2A, 0x6D, 0xD5, 0xB6,
|
||||
0x2D, 0xFC, 0x88, 0xCD, 0x06, 0xBB, 0x84, 0xBE,
|
||||
/* p */
|
||||
@@ -3197,3 +3201,120 @@ int EC_curve_nist2nid(const char *name)
|
||||
}
|
||||
return NID_undef;
|
||||
}
|
||||
|
||||
#define NUM_BN_FIELDS 6
|
||||
/*
|
||||
* Validates EC domain parameter data for known named curves.
|
||||
* This can be used when a curve is loaded explicitly (without a curve
|
||||
* name) or to validate that domain parameters have not been modified.
|
||||
*
|
||||
* Returns: The nid associated with the found named curve, or NID_undef
|
||||
* if not found. If there was an error it returns -1.
|
||||
*/
|
||||
int ec_curve_nid_from_params(const EC_GROUP *group)
|
||||
{
|
||||
int ret = -1, nid, len, field_type, param_len;
|
||||
size_t i, seed_len;
|
||||
const unsigned char *seed, *params_seed, *params;
|
||||
unsigned char *param_bytes = NULL;
|
||||
const EC_CURVE_DATA *data;
|
||||
const EC_POINT *generator = NULL;
|
||||
const EC_METHOD *meth;
|
||||
const BIGNUM *cofactor = NULL;
|
||||
/* An array of BIGNUMs for (p, a, b, x, y, order) */
|
||||
BIGNUM *bn[NUM_BN_FIELDS] = {NULL, NULL, NULL, NULL, NULL, NULL};
|
||||
BN_CTX *ctx = NULL;
|
||||
|
||||
meth = EC_GROUP_method_of(group);
|
||||
if (meth == NULL)
|
||||
return -1;
|
||||
/* Use the optional named curve nid as a search field */
|
||||
nid = EC_GROUP_get_curve_name(group);
|
||||
field_type = EC_METHOD_get_field_type(meth);
|
||||
seed_len = EC_GROUP_get_seed_len(group);
|
||||
seed = EC_GROUP_get0_seed(group);
|
||||
cofactor = EC_GROUP_get0_cofactor(group);
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL)
|
||||
return -1;
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
/*
|
||||
* The built-in curves contains data fields (p, a, b, x, y, order) that are
|
||||
* all zero-padded to be the same size. The size of the padding is
|
||||
* determined by either the number of bytes in the field modulus (p) or the
|
||||
* EC group order, whichever is larger.
|
||||
*/
|
||||
param_len = BN_num_bytes(group->order);
|
||||
len = BN_num_bytes(group->field);
|
||||
if (len > param_len)
|
||||
param_len = len;
|
||||
|
||||
/* Allocate space to store the padded data for (p, a, b, x, y, order) */
|
||||
param_bytes = OPENSSL_malloc(param_len * NUM_BN_FIELDS);
|
||||
if (param_bytes == NULL)
|
||||
goto end;
|
||||
|
||||
/* Create the bignums */
|
||||
for (i = 0; i < NUM_BN_FIELDS; ++i) {
|
||||
if ((bn[i] = BN_CTX_get(ctx)) == NULL)
|
||||
goto end;
|
||||
}
|
||||
/*
|
||||
* Fill in the bn array with the same values as the internal curves
|
||||
* i.e. the values are p, a, b, x, y, order.
|
||||
*/
|
||||
/* Get p, a & b */
|
||||
if (!(EC_GROUP_get_curve(group, bn[0], bn[1], bn[2], ctx)
|
||||
&& ((generator = EC_GROUP_get0_generator(group)) != NULL)
|
||||
/* Get x & y */
|
||||
&& EC_POINT_get_affine_coordinates(group, generator, bn[3], bn[4], ctx)
|
||||
/* Get order */
|
||||
&& EC_GROUP_get_order(group, bn[5], ctx)))
|
||||
goto end;
|
||||
|
||||
/*
|
||||
* Convert the bignum array to bytes that are joined together to form
|
||||
* a single buffer that contains data for all fields.
|
||||
* (p, a, b, x, y, order) are all zero padded to be the same size.
|
||||
*/
|
||||
for (i = 0; i < NUM_BN_FIELDS; ++i) {
|
||||
if (BN_bn2binpad(bn[i], ¶m_bytes[i*param_len], param_len) <= 0)
|
||||
goto end;
|
||||
}
|
||||
|
||||
for (i = 0; i < curve_list_length; i++) {
|
||||
const ec_list_element curve = curve_list[i];
|
||||
|
||||
data = curve.data;
|
||||
/* Get the raw order byte data */
|
||||
params_seed = (const unsigned char *)(data + 1); /* skip header */
|
||||
params = params_seed + data->seed_len;
|
||||
|
||||
/* Look for unique fields in the fixed curve data */
|
||||
if (data->field_type == field_type
|
||||
&& param_len == data->param_len
|
||||
&& (nid <= 0 || nid == curve.nid)
|
||||
/* check the optional cofactor (ignore if its zero) */
|
||||
&& (BN_is_zero(cofactor)
|
||||
|| BN_is_word(cofactor, (const BN_ULONG)curve.data->cofactor))
|
||||
/* Check the optional seed (ignore if its not set) */
|
||||
&& (data->seed_len == 0 || seed_len == 0
|
||||
|| ((size_t)data->seed_len == seed_len
|
||||
&& OPENSSL_memcmp(params_seed, seed, seed_len) == 0))
|
||||
/* Check that the groups params match the built-in curve params */
|
||||
&& OPENSSL_memcmp(param_bytes, params, param_len * NUM_BN_FIELDS)
|
||||
== 0) {
|
||||
ret = curve.nid;
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
/* Gets here if the group was not found */
|
||||
ret = NID_undef;
|
||||
end:
|
||||
OPENSSL_free(param_bytes);
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
return ret;
|
||||
}
|
||||
+123
-27
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright 2002-2019 The OpenSSL Project Authors. All Rights Reserved.
|
||||
* Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved
|
||||
*
|
||||
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
||||
@@ -195,59 +195,90 @@ int ossl_ec_key_gen(EC_KEY *eckey)
|
||||
return eckey->group->meth->keygen(eckey);
|
||||
}
|
||||
|
||||
/*
|
||||
* ECC Key generation.
|
||||
* See SP800-56AR3 5.6.1.2.2 "Key Pair Generation by Testing Candidates"
|
||||
*
|
||||
* Params:
|
||||
* eckey An EC key object that contains domain params. The generated keypair
|
||||
* is stored in this object.
|
||||
* Returns 1 if the keypair was generated or 0 otherwise.
|
||||
*/
|
||||
int ec_key_simple_generate_key(EC_KEY *eckey)
|
||||
{
|
||||
int ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *priv_key = NULL;
|
||||
const BIGNUM *order = NULL;
|
||||
EC_POINT *pub_key = NULL;
|
||||
|
||||
if ((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
const EC_GROUP *group = eckey->group;
|
||||
|
||||
if (eckey->priv_key == NULL) {
|
||||
priv_key = BN_new();
|
||||
priv_key = BN_secure_new();
|
||||
if (priv_key == NULL)
|
||||
goto err;
|
||||
} else
|
||||
priv_key = eckey->priv_key;
|
||||
|
||||
order = EC_GROUP_get0_order(eckey->group);
|
||||
/*
|
||||
* Steps (1-2): Check domain parameters and security strength.
|
||||
* These steps must be done by the user. This would need to be
|
||||
* stated in the security policy.
|
||||
*/
|
||||
|
||||
order = EC_GROUP_get0_order(group);
|
||||
if (order == NULL)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Steps (3-7): priv_key = DRBG_RAND(order_n_bits) (range [1, n-1]).
|
||||
* Although this is slightly different from the standard, it is effectively
|
||||
* equivalent as it gives an unbiased result ranging from 1..n-1. It is also
|
||||
* faster as the standard needs to retry more often. Also doing
|
||||
* 1 + rand[0..n-2] would effect the way that tests feed dummy entropy into
|
||||
* rand so the simpler backward compatible method has been used here.
|
||||
*/
|
||||
do
|
||||
if (!BN_priv_rand_range(priv_key, order))
|
||||
goto err;
|
||||
while (BN_is_zero(priv_key)) ;
|
||||
|
||||
if (eckey->pub_key == NULL) {
|
||||
pub_key = EC_POINT_new(eckey->group);
|
||||
pub_key = EC_POINT_new(group);
|
||||
if (pub_key == NULL)
|
||||
goto err;
|
||||
} else
|
||||
pub_key = eckey->pub_key;
|
||||
|
||||
if (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))
|
||||
/* Step (8) : pub_key = priv_key * G (where G is a point on the curve) */
|
||||
if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, NULL))
|
||||
goto err;
|
||||
|
||||
eckey->priv_key = priv_key;
|
||||
eckey->pub_key = pub_key;
|
||||
priv_key = NULL;
|
||||
pub_key = NULL;
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
if (eckey->pub_key == NULL)
|
||||
EC_POINT_free(pub_key);
|
||||
if (eckey->priv_key != priv_key)
|
||||
BN_free(priv_key);
|
||||
BN_CTX_free(ctx);
|
||||
err:
|
||||
/* Step (9): If there is an error return an invalid keypair. */
|
||||
if (!ok) {
|
||||
BN_clear(eckey->priv_key);
|
||||
if (eckey->pub_key != NULL)
|
||||
EC_POINT_set_to_infinity(group, eckey->pub_key);
|
||||
}
|
||||
|
||||
EC_POINT_free(pub_key);
|
||||
BN_clear_free(priv_key);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int ec_key_simple_generate_public_key(EC_KEY *eckey)
|
||||
{
|
||||
/*
|
||||
* See SP800-56AR3 5.6.1.2.2: Step (8)
|
||||
* pub_key = priv_key * G (where G is a point on the curve)
|
||||
*/
|
||||
return EC_POINT_mul(eckey->group, eckey->pub_key, eckey->priv_key, NULL,
|
||||
NULL, NULL);
|
||||
}
|
||||
@@ -267,6 +298,58 @@ int EC_KEY_check_key(const EC_KEY *eckey)
|
||||
return eckey->group->meth->keycheck(eckey);
|
||||
}
|
||||
|
||||
/*
|
||||
* Check the range of the EC public key.
|
||||
* See SP800-56A R3 Section 5.6.2.3.3 (Part 2)
|
||||
* i.e.
|
||||
* - If q = odd prime p: Verify that xQ and yQ are integers in the
|
||||
* interval[0, p − 1], OR
|
||||
* - If q = 2m: Verify that xQ and yQ are bit strings of length m bits.
|
||||
* Returns 1 if the public key has a valid range, otherwise it returns 0.
|
||||
*/
|
||||
static int ec_key_public_range_check(BN_CTX *ctx, const EC_KEY *key)
|
||||
{
|
||||
int ret = 0;
|
||||
BIGNUM *x, *y;
|
||||
|
||||
BN_CTX_start(ctx);
|
||||
x = BN_CTX_get(ctx);
|
||||
y = BN_CTX_get(ctx);
|
||||
if (y == NULL)
|
||||
goto err;
|
||||
|
||||
if (!EC_POINT_get_affine_coordinates(key->group, key->pub_key, x, y, ctx))
|
||||
goto err;
|
||||
|
||||
if (EC_METHOD_get_field_type(key->group->meth) == NID_X9_62_prime_field) {
|
||||
if (BN_is_negative(x)
|
||||
|| BN_cmp(x, key->group->field) >= 0
|
||||
|| BN_is_negative(y)
|
||||
|| BN_cmp(y, key->group->field) >= 0) {
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
int m = EC_GROUP_get_degree(key->group);
|
||||
if (BN_num_bits(x) > m || BN_num_bits(y) > m) {
|
||||
goto err;
|
||||
}
|
||||
}
|
||||
ret = 1;
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
* ECC Key validation as specified in SP800-56A R3.
|
||||
* Section 5.6.2.3.3 ECC Full Public-Key Validation
|
||||
* Section 5.6.2.1.2 Owner Assurance of Private-Key Validity
|
||||
* Section 5.6.2.1.4 Owner Assurance of Pair-wise Consistency
|
||||
* NOTES:
|
||||
* Before calling this method in fips mode, there should be an assurance that
|
||||
* an approved elliptic-curve group is used.
|
||||
* Returns 1 if the key is valid, otherwise it returns 0.
|
||||
*/
|
||||
int ec_key_simple_check_key(const EC_KEY *eckey)
|
||||
{
|
||||
int ok = 0;
|
||||
@@ -279,6 +362,7 @@ int ec_key_simple_check_key(const EC_KEY *eckey)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* 5.6.2.3.3 (Step 1): Q != infinity */
|
||||
if (EC_POINT_is_at_infinity(eckey->group, eckey->pub_key)) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_POINT_AT_INFINITY);
|
||||
goto err;
|
||||
@@ -286,20 +370,28 @@ int ec_key_simple_check_key(const EC_KEY *eckey)
|
||||
|
||||
if ((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
|
||||
if ((point = EC_POINT_new(eckey->group)) == NULL)
|
||||
goto err;
|
||||
|
||||
/* testing whether the pub_key is on the elliptic curve */
|
||||
/* 5.6.2.3.3 (Step 2) Test if the public key is in range */
|
||||
if (!ec_key_public_range_check(ctx, eckey)) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_COORDINATES_OUT_OF_RANGE);
|
||||
goto err;
|
||||
}
|
||||
|
||||
/* 5.6.2.3.3 (Step 3) is the pub_key on the elliptic curve */
|
||||
if (EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx) <= 0) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE);
|
||||
goto err;
|
||||
}
|
||||
/* testing whether pub_key * order is the point at infinity */
|
||||
|
||||
order = eckey->group->order;
|
||||
if (BN_is_zero(order)) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);
|
||||
goto err;
|
||||
}
|
||||
/* 5.6.2.3.3 (Step 4) : pub_key * order is the point at infinity. */
|
||||
if (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx)) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, ERR_R_EC_LIB);
|
||||
goto err;
|
||||
@@ -308,15 +400,21 @@ int ec_key_simple_check_key(const EC_KEY *eckey)
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_WRONG_ORDER);
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
* in case the priv_key is present : check if generator * priv_key ==
|
||||
* pub_key
|
||||
*/
|
||||
|
||||
if (eckey->priv_key != NULL) {
|
||||
if (BN_cmp(eckey->priv_key, order) >= 0) {
|
||||
/*
|
||||
* 5.6.2.1.2 Owner Assurance of Private-Key Validity
|
||||
* The private key is in the range [1, order-1]
|
||||
*/
|
||||
if (BN_cmp(eckey->priv_key, BN_value_one()) < 0
|
||||
|| BN_cmp(eckey->priv_key, order) >= 0) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, EC_R_WRONG_ORDER);
|
||||
goto err;
|
||||
}
|
||||
/*
|
||||
* Section 5.6.2.1.4 Owner Assurance of Pair-wise Consistency (b)
|
||||
* Check if generator * priv_key = pub_key
|
||||
*/
|
||||
if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
|
||||
NULL, NULL, ctx)) {
|
||||
ECerr(EC_F_EC_KEY_SIMPLE_CHECK_KEY, ERR_R_EC_LIB);
|
||||
@@ -368,12 +466,10 @@ int EC_KEY_set_public_key_affine_coordinates(EC_KEY *key, BIGNUM *x,
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Check if retrieved coordinates match originals and are less than field
|
||||
* order: if not values are out of range.
|
||||
* Check if retrieved coordinates match originals. The range check is done
|
||||
* inside EC_KEY_check_key().
|
||||
*/
|
||||
if (BN_cmp(x, tx) || BN_cmp(y, ty)
|
||||
|| (BN_cmp(x, key->group->field) >= 0)
|
||||
|| (BN_cmp(y, key->group->field) >= 0)) {
|
||||
if (BN_cmp(x, tx) || BN_cmp(y, ty)) {
|
||||
ECerr(EC_F_EC_KEY_SET_PUBLIC_KEY_AFFINE_COORDINATES,
|
||||
EC_R_COORDINATES_OUT_OF_RANGE);
|
||||
goto err;
|
||||
|
||||
+6
-7
@@ -309,13 +309,10 @@ struct ec_point_st {
|
||||
static ossl_inline int ec_point_is_compat(const EC_POINT *point,
|
||||
const EC_GROUP *group)
|
||||
{
|
||||
if (group->meth != point->meth
|
||||
|| (group->curve_name != 0
|
||||
&& point->curve_name != 0
|
||||
&& group->curve_name != point->curve_name))
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
return group->meth == point->meth
|
||||
&& (group->curve_name == 0
|
||||
|| point->curve_name == 0
|
||||
|| group->curve_name == point->curve_name);
|
||||
}
|
||||
|
||||
NISTP224_PRE_COMP *EC_nistp224_pre_comp_dup(NISTP224_PRE_COMP *);
|
||||
@@ -595,6 +592,8 @@ int ec_key_simple_generate_key(EC_KEY *eckey);
|
||||
int ec_key_simple_generate_public_key(EC_KEY *eckey);
|
||||
int ec_key_simple_check_key(const EC_KEY *eckey);
|
||||
|
||||
int ec_curve_nid_from_params(const EC_GROUP *group);
|
||||
|
||||
/* EC_METHOD definitions */
|
||||
|
||||
struct ec_key_method_st {
|
||||
|
||||
+30
-15
@@ -284,15 +284,17 @@ int EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator,
|
||||
if (order != NULL) {
|
||||
if (!BN_copy(group->order, order))
|
||||
return 0;
|
||||
} else
|
||||
} else {
|
||||
BN_zero(group->order);
|
||||
}
|
||||
|
||||
/* The cofactor is an optional field, so it should be able to be NULL. */
|
||||
if (cofactor != NULL) {
|
||||
if (!BN_copy(group->cofactor, cofactor))
|
||||
return 0;
|
||||
} else
|
||||
} else {
|
||||
BN_zero(group->cofactor);
|
||||
|
||||
}
|
||||
/*
|
||||
* Some groups have an order with
|
||||
* factors of two, which makes the Montgomery setup fail.
|
||||
@@ -530,30 +532,43 @@ int EC_GROUP_cmp(const EC_GROUP *a, const EC_GROUP *b, BN_CTX *ctx)
|
||||
!b->meth->group_get_curve(b, b1, b2, b3, ctx))
|
||||
r = 1;
|
||||
|
||||
if (r || BN_cmp(a1, b1) || BN_cmp(a2, b2) || BN_cmp(a3, b3))
|
||||
/* return 1 if the curve parameters are different */
|
||||
if (r || BN_cmp(a1, b1) != 0 || BN_cmp(a2, b2) != 0 || BN_cmp(a3, b3) != 0)
|
||||
r = 1;
|
||||
|
||||
/* XXX EC_POINT_cmp() assumes that the methods are equal */
|
||||
/* return 1 if the generators are different */
|
||||
if (r || EC_POINT_cmp(a, EC_GROUP_get0_generator(a),
|
||||
EC_GROUP_get0_generator(b), ctx))
|
||||
EC_GROUP_get0_generator(b), ctx) != 0)
|
||||
r = 1;
|
||||
|
||||
if (!r) {
|
||||
const BIGNUM *ao, *bo, *ac, *bc;
|
||||
/* compare the order and cofactor */
|
||||
/* compare the orders */
|
||||
ao = EC_GROUP_get0_order(a);
|
||||
bo = EC_GROUP_get0_order(b);
|
||||
if (ao == NULL || bo == NULL) {
|
||||
/* return an error if either order is NULL */
|
||||
r = -1;
|
||||
goto end;
|
||||
}
|
||||
if (BN_cmp(ao, bo) != 0) {
|
||||
/* return 1 if orders are different */
|
||||
r = 1;
|
||||
goto end;
|
||||
}
|
||||
/*
|
||||
* It gets here if the curve parameters and generator matched.
|
||||
* Now check the optional cofactors (if both are present).
|
||||
*/
|
||||
ac = EC_GROUP_get0_cofactor(a);
|
||||
bc = EC_GROUP_get0_cofactor(b);
|
||||
if (ao == NULL || bo == NULL) {
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx_new);
|
||||
return -1;
|
||||
}
|
||||
if (BN_cmp(ao, bo) || BN_cmp(ac, bc))
|
||||
/* Returns 1 (mismatch) if both cofactors are specified and different */
|
||||
if (!BN_is_zero(ac) && !BN_is_zero(bc) && BN_cmp(ac, bc) != 0)
|
||||
r = 1;
|
||||
/* Returns 0 if the parameters matched */
|
||||
}
|
||||
|
||||
end:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx_new);
|
||||
|
||||
@@ -622,8 +637,8 @@ int EC_POINT_copy(EC_POINT *dest, const EC_POINT *src)
|
||||
}
|
||||
if (dest->meth != src->meth
|
||||
|| (dest->curve_name != src->curve_name
|
||||
&& dest->curve_name != 0
|
||||
&& src->curve_name != 0)) {
|
||||
&& dest->curve_name != 0
|
||||
&& src->curve_name != 0)) {
|
||||
ECerr(EC_F_EC_POINT_COPY, EC_R_INCOMPATIBLE_OBJECTS);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in,
|
||||
}
|
||||
}
|
||||
|
||||
k = BN_new(); /* this value is later returned in *kinvp */
|
||||
k = BN_secure_new(); /* this value is later returned in *kinvp */
|
||||
r = BN_new(); /* this value is later returned in *rp */
|
||||
X = BN_new();
|
||||
if (k == NULL || r == NULL || X == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user