summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikos Mavrogiannopoulos <nmav@redhat.com>2017-04-24 13:06:45 +0200
committerNikos Mavrogiannopoulos <nmav@gnutls.org>2017-04-25 08:06:44 +0200
commitb23ac8712ffa874247368aaeadd02971857e98a3 (patch)
tree94ea2279da5dd47509452b0be5a57450cdccd4d6
parent0ff2e657fcfa53f0bb6324599802ef1f083460d7 (diff)
downloadgnutls-b23ac8712ffa874247368aaeadd02971857e98a3.tar.gz
fips140-2: enhanced check of generated parameters
That is, replaced all assert() calls with if statements to allow gracefull fail. Signed-off-by: Nikos Mavrogiannopoulos <nmav@redhat.com>
-rw-r--r--lib/nettle/int/rsa-keygen-fips186.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/lib/nettle/int/rsa-keygen-fips186.c b/lib/nettle/int/rsa-keygen-fips186.c
index 624aa36535..8ea4f7daa9 100644
--- a/lib/nettle/int/rsa-keygen-fips186.c
+++ b/lib/nettle/int/rsa-keygen-fips186.c
@@ -27,7 +27,6 @@
#include "config.h"
#endif
-#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@@ -337,10 +336,16 @@ _rsa_generate_fips186_4_keypair(struct rsa_public_key *pub,
mpz_mul(pub->n, key->p, key->q);
- assert(mpz_sizeinbase(pub->n, 2) == n_size);
+ if (mpz_sizeinbase(pub->n, 2) != n_size) {
+ ret = 0;
+ goto cleanup;
+ }
/* c = q^{-1} (mod p) */
- assert(mpz_invert(key->c, key->q, key->p) != 0);
+ if (mpz_invert(key->c, key->q, key->p) == 0) {
+ ret = 0;
+ goto cleanup;
+ }
mpz_sub_ui(p1, key->p, 1);
mpz_sub_ui(q1, key->q, 1);
@@ -362,7 +367,10 @@ _rsa_generate_fips186_4_keypair(struct rsa_public_key *pub,
/* c was computed earlier */
pub->size = key->size = (n_size + 7) / 8;
- assert(pub->size >= RSA_MINIMUM_N_OCTETS);
+ if (pub->size < RSA_MINIMUM_N_OCTETS) {
+ ret = 0;
+ goto cleanup;
+ }
ret = 1;
cleanup: