aboutsummaryrefslogtreecommitdiff
path: root/tests/test-rsa.c
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2015-06-16 19:17:24 -0400
committerRob Austein <sra@hactrn.net>2015-06-16 19:17:24 -0400
commit7a89eaa086fa534a6a0aac45fa2f5865ef7839ef (patch)
tree19e162a1fb2b49aaf5350531ab061ef269480066 /tests/test-rsa.c
parent8934e10e139d45e5bc9b6874b3c630461d55607c (diff)
Refactor key loading code.
Diffstat (limited to 'tests/test-rsa.c')
-rw-r--r--tests/test-rsa.c42
1 files changed, 26 insertions, 16 deletions
diff --git a/tests/test-rsa.c b/tests/test-rsa.c
index 6925261..b415955 100644
--- a/tests/test-rsa.c
+++ b/tests/test-rsa.c
@@ -83,28 +83,38 @@ static int test_modexp(const char * const kind,
static int test_crt(const char * const kind, const rsa_tc_t * const tc)
{
- uint8_t result[tc->n.len];
-
printf("%s test for %lu-bit RSA key\n", kind, (unsigned long) tc->size);
- if (hal_rsa_crt(tc->m.val, tc->m.len,
- tc->n.val, tc->n.len,
- tc->e.val, tc->e.len,
- tc->d.val, tc->d.len,
- tc->p.val, tc->p.len,
- tc->q.val, tc->q.len,
- tc->u.val, tc->u.len,
- result, sizeof(result)) != HAL_OK) {
- printf("RSA CRT failed\n");
+ uint8_t keybuf[hal_rsa_key_t_size];
+ hal_error_t err = HAL_OK;
+ hal_rsa_key_t key;
+
+ if ((err = hal_rsa_key_load(RSA_PRIVATE, &key, keybuf, sizeof(keybuf),
+ tc->n.val, tc->n.len,
+ tc->e.val, tc->e.len,
+ tc->d.val, tc->d.len,
+ tc->p.val, tc->p.len,
+ tc->q.val, tc->q.len,
+ tc->u.val, tc->u.len,
+ tc->dP.val, tc->dP.len,
+ tc->dQ.val, tc->dQ.len)) != HAL_OK) {
+ printf("RSA CRT key load failed: %s\n", hal_error_string(err));
return 0;
}
- if (memcmp(result, tc->s.val, tc->s.len)) {
- printf("MISMATCH\n");
- return 0;
- }
+ uint8_t result[tc->n.len];
- return 1;
+ if ((err = hal_rsa_crt(key, tc->m.val, tc->m.len, result, sizeof(result))) != HAL_OK)
+ printf("RSA CRT failed: %s\n", hal_error_string(err));
+
+ const int mismatch = (err == HAL_OK && memcmp(result, tc->s.val, tc->s.len) != 0);
+
+ if (mismatch)
+ printf("MISMATCH\n");
+
+ hal_rsa_key_clear(key);
+
+ return err == HAL_OK && !mismatch;
}
/*