[Cryptech-Commits] [user/sra/libhal] 09/17: Debug RSA key generation.
git at cryptech.is
git at cryptech.is
Fri Jun 19 17:56:38 UTC 2015
This is an automated email from the git hooks/post-receive script.
sra at hactrn.net pushed a commit to branch master
in repository user/sra/libhal.
commit 35733aaf5f384f26a3a736f2ab54f638646bc086
Author: Rob Austein <sra at hactrn.net>
Date: Wed Jun 17 16:58:06 2015 -0400
Debug RSA key generation.
---
csprng.c | 2 +-
rsa.c | 8 ++++++--
tests/test-rsa.c | 4 ++--
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;
}
More information about the Commits
mailing list