Changeset View
Changeset View
Standalone View
Standalone View
crypto/ec/ecdsa_ossl.c
/* | /* | ||||
* Copyright 2002-2021 The OpenSSL Project Authors. All Rights Reserved. | * Copyright 2002-2023 The OpenSSL Project Authors. All Rights Reserved. | ||||
* | * | ||||
* Licensed under the Apache License 2.0 (the "License"). You may not use | * 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 | * this file except in compliance with the License. You can obtain a copy | ||||
Context not available. | |||||
#include "crypto/bn.h" | #include "crypto/bn.h" | ||||
#include "ec_local.h" | #include "ec_local.h" | ||||
#define MIN_ECDSA_SIGN_ORDERBITS 64 | |||||
/* | |||||
* It is highly unlikely that a retry will happen, | |||||
* Multiple retries would indicate that something is wrong | |||||
* with the group parameters (which would normally only happen | |||||
* with a bad custom group). | |||||
*/ | |||||
#define MAX_ECDSA_SIGN_RETRIES 8 | |||||
int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, | ||||
BIGNUM **rp) | BIGNUM **rp) | ||||
{ | { | ||||
Context not available. | |||||
*siglen = 0; | *siglen = 0; | ||||
return 0; | return 0; | ||||
} | } | ||||
*siglen = i2d_ECDSA_SIG(s, &sig); | *siglen = i2d_ECDSA_SIG(s, sig != NULL ? &sig : NULL); | ||||
ECDSA_SIG_free(s); | ECDSA_SIG_free(s); | ||||
return 1; | return 1; | ||||
} | } | ||||
Context not available. | |||||
/* Preallocate space */ | /* Preallocate space */ | ||||
order_bits = BN_num_bits(order); | order_bits = BN_num_bits(order); | ||||
if (!BN_set_bit(k, order_bits) | /* Check the number of bits here so that an infinite loop is not possible */ | ||||
if (order_bits < MIN_ECDSA_SIGN_ORDERBITS | |||||
|| !BN_set_bit(k, order_bits) | |||||
|| !BN_set_bit(r, order_bits) | || !BN_set_bit(r, order_bits) | ||||
|| !BN_set_bit(X, order_bits)) | || !BN_set_bit(X, order_bits)) | ||||
goto err; | goto err; | ||||
Context not available. | |||||
EC_KEY *eckey) | EC_KEY *eckey) | ||||
{ | { | ||||
int ok = 0, i; | int ok = 0, i; | ||||
int retries = 0; | |||||
BIGNUM *kinv = NULL, *s, *m = NULL; | BIGNUM *kinv = NULL, *s, *m = NULL; | ||||
const BIGNUM *order, *ckinv; | const BIGNUM *order, *ckinv; | ||||
BN_CTX *ctx = NULL; | BN_CTX *ctx = NULL; | ||||
Context not available. | |||||
ERR_raise(ERR_LIB_EC, EC_R_NEED_NEW_SETUP_VALUES); | ERR_raise(ERR_LIB_EC, EC_R_NEED_NEW_SETUP_VALUES); | ||||
goto err; | goto err; | ||||
} | } | ||||
/* Avoid infinite loops cause by invalid group parameters */ | |||||
if (retries++ > MAX_ECDSA_SIGN_RETRIES) { | |||||
ERR_raise(ERR_LIB_EC, EC_R_TOO_MANY_RETRIES); | |||||
goto err; | |||||
} | |||||
} else { | } else { | ||||
/* s != 0 => we have a valid signature */ | /* s != 0 => we have a valid signature */ | ||||
break; | break; | ||||
Context not available. |