aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-06-17 16:58:06 -0400
committerRob Austein <sra@hactrn.net>2015-06-17 16:58:06 -0400
commit35733aaf5f384f26a3a736f2ab54f638646bc086 (patch)
treea4c0681bb224896724e424de2b4a2799834579a6
parentab5a8760becf4711afa68221a5610e5572686f1f (diff)
Debug RSA key generation.
-rw-r--r--csprng.c2
-rw-r--r--rsa.c8
-rw-r--r--tests/test-rsa.c4
3 files changed, 9 insertions, 5 deletions
diff --git a/csprng.c b/csprng.c
index 198534c..b5bf887 100644
--- a/csprng.c
+++ b/csprng.c
@@ -40,7 +40,7 @@
#include "cryptech.h"
#ifndef WAIT_FOR_CSPRNG_VALID
-#define WAIT_FOR_CSPRNG_VALID 1
+#define WAIT_FOR_CSPRNG_VALID 0
#endif
hal_error_t hal_get_random(void *buffer, const size_t length)
diff --git a/rsa.c b/rsa.c
index ad5cb16..9a42563 100644
--- a/rsa.c
+++ b/rsa.c
@@ -392,8 +392,8 @@ hal_error_t hal_rsa_key_gen(hal_rsa_key_t *key_,
* Calculate remaining key components.
*/
- fp_sub_d(&key->p, 1, &p_1);
- fp_sub_d(&key->q, 1, &q_1);
+ fp_init(&p_1); fp_sub_d(&key->p, 1, &p_1);
+ fp_init(&q_1); fp_sub_d(&key->q, 1, &q_1);
fp_mul(&key->p, &key->q, &key->n); /* n = p * q */
fp_lcm(&p_1, &q_1, &key->d);
FP_CHECK(fp_invmod(&key->e, &key->d, &key->d)); /* d = (1/e) % lcm(p-1, q-1) */
@@ -401,9 +401,13 @@ hal_error_t hal_rsa_key_gen(hal_rsa_key_t *key_,
FP_CHECK(fp_mod(&key->d, &q_1, &key->dQ)); /* dQ = d % (q-1) */
FP_CHECK(fp_invmod(&key->q, &key->p, &key->u)); /* u = (1/q) % p */
+ key_->key = key;
+
/* Fall through to cleanup */
fail:
+ if (err != HAL_OK)
+ memset(keybuf, 0, keybuf_len);
fp_zero(&p_1);
fp_zero(&q_1);
return err;
diff --git a/tests/test-rsa.c b/tests/test-rsa.c
index 814541c..08d22c5 100644
--- a/tests/test-rsa.c
+++ b/tests/test-rsa.c
@@ -160,7 +160,7 @@ static int test_gen(const char * const kind, const rsa_tc_t * const tc)
return 0;
}
- if (fwrite(der, der_len, 1, f) != der_len) {
+ if (fwrite(der, der_len, 1, f) != 1) {
printf("Length mismatch writing %s\n", fn);
return 0;
}
@@ -183,7 +183,7 @@ static int test_gen(const char * const kind, const rsa_tc_t * const tc)
return 0;
}
- if (fwrite(result, sizeof(result), 1, f) != sizeof(result)) {
+ if (fwrite(result, sizeof(result), 1, f) != 1) {
printf("Length mismatch writing %s key\n", fn);
return 0;
}