summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2021-01-30 09:25:06 +0100
committerDaiki Ueno <ueno@gnu.org>2021-02-17 18:09:46 +0100
commit99aee55141b761d61a2f77046b04c63709a185f1 (patch)
tree32c5ecf0e131d55ac61e0f8095d6323e2833dc54
parent6a9689358fa9fe10effc453e5eba385fde4a988b (diff)
downloadgnutls-99aee55141b761d61a2f77046b04c63709a185f1.tar.gz
nettle: check lib state early to cope with synthesized error
tests/x509sign-verify-error.c calls _gnutls_lib_simulate_error before the actual private key operations. That previously resulted in infloop / conditional jump depending on uninitialized data, because the random function (gnutls_rnd) was not able to feed sufficient randomness in that case. Signed-off-by: Daiki Ueno <ueno@gnu.org>
-rw-r--r--lib/nettle/pk.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/lib/nettle/pk.c b/lib/nettle/pk.c
index 432bcdd59d..ff8e3d15b4 100644
--- a/lib/nettle/pk.c
+++ b/lib/nettle/pk.c
@@ -548,6 +548,8 @@ _wrap_nettle_pk_encrypt(gnutls_pk_algorithm_t algo,
int ret;
mpz_t p;
+ FAIL_IF_LIB_ERROR;
+
mpz_init(p);
switch (algo) {
@@ -610,6 +612,8 @@ _wrap_nettle_pk_decrypt(gnutls_pk_algorithm_t algo,
{
int ret;
+ FAIL_IF_LIB_ERROR;
+
plaintext->data = NULL;
/* make a sexp from pkey */
@@ -704,6 +708,8 @@ _wrap_nettle_pk_decrypt2(gnutls_pk_algorithm_t algo,
int ret;
nettle_random_func *random_func;
+ FAIL_IF_LIB_ERROR;
+
if (algo != GNUTLS_PK_RSA || plaintext == NULL) {
gnutls_assert();
return GNUTLS_E_INTERNAL_ERROR;
@@ -863,6 +869,8 @@ _wrap_nettle_pk_sign(gnutls_pk_algorithm_t algo,
unsigned int hash_len;
const mac_entry_st *me;
+ FAIL_IF_LIB_ERROR;
+
if (IS_EC(algo)) {
/* check if the curve relates to the algorithm used */
if (gnutls_ecc_curve_get_pk(pk_params->curve) != algo)
@@ -1282,6 +1290,8 @@ _wrap_nettle_pk_verify(gnutls_pk_algorithm_t algo,
unsigned int hash_len;
bigint_t tmp[2] = { NULL, NULL };
+ FAIL_IF_LIB_ERROR;
+
if (IS_EC(algo)) {
/* check if the curve relates to the algorithm used */
if (gnutls_ecc_curve_get_pk(pk_params->curve) != algo)
@@ -1664,6 +1674,8 @@ wrap_nettle_pk_generate_params(gnutls_pk_algorithm_t algo,
int ret;
unsigned int i, q_bits;
+ FAIL_IF_LIB_ERROR;
+
params->algo = algo;
switch (algo) {
@@ -2267,6 +2279,8 @@ wrap_nettle_pk_generate_keys(gnutls_pk_algorithm_t algo,
unsigned rnd_level;
nettle_random_func *rnd_func;
+ FAIL_IF_LIB_ERROR;
+
if (IS_EC(algo)) {
/* check if the curve relates to the algorithm used */
if (gnutls_ecc_curve_get_pk(level) != algo)