From 8c427a7b537a35d6685fb8a95e9b64732d6b4c49 Mon Sep 17 00:00:00 2001 From: Rob Austein Date: Wed, 23 Dec 2015 01:59:40 -0500 Subject: First round of fixes for new ASN.1 and test code. --- tests/test-rsa.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'tests/test-rsa.c') diff --git a/tests/test-rsa.c b/tests/test-rsa.c index 737387c..1fc516b 100644 --- a/tests/test-rsa.c +++ b/tests/test-rsa.c @@ -161,7 +161,7 @@ static int test_gen(const hal_core_t *core, return printf("Converting RSA key back from DER failed: %s\n", hal_error_string(err)), 0; if (memcmp(keybuf1, keybuf2, hal_rsa_key_t_size) != 0) - return printf("RSA key mismatch after conversion to and back from DER\n"), 0; + return printf("RSA private key mismatch after conversion to and back from DER\n"), 0; uint8_t result[tc->n.len]; @@ -175,7 +175,7 @@ static int test_gen(const hal_core_t *core, return printf("Couldn't open %s: %s\n", fn, strerror(errno)), 0; if (fwrite(result, sizeof(result), 1, f) != 1) - return printf("Length mismatch writing %s key\n", fn), 0; + return printf("Length mismatch writing %s\n", fn), 0; if (fclose(f) == EOF) return printf("Couldn't close %s: %s\n", fn, strerror(errno)), 0; @@ -194,6 +194,15 @@ static int test_gen(const hal_core_t *core, hal_rsa_key_clear(key2); key2 = NULL; + if ((f = fopen(fn, "rb")) == NULL) + return printf("Couldn't open %s: %s\n", fn, strerror(errno)), 0; + + if (fread(result, sizeof(result), 1, f) != 1) + return printf("Length mismatch reading %s\n", fn), 0; + + if (fclose(f) == EOF) + return printf("Couldn't close %s: %s\n", fn, strerror(errno)), 0; + err = hal_rsa_public_key_to_der(key1, der, &der_len, sizeof(der)); snprintf(fn, sizeof(fn), "test-rsa-public-key-%04lu.der", (unsigned long) tc->size); @@ -212,8 +221,8 @@ static int test_gen(const hal_core_t *core, if (err != HAL_OK) return printf("Converting RSA public key to DER failed: %s\n", hal_error_string(err)), 0; - if ((err = hal_rsa_private_key_from_der(&key2, keybuf2, sizeof(keybuf2), der, sizeof(der))) != HAL_OK) - return printf("Converting RSA key back from DER failed: %s\n", hal_error_string(err)), 0; + if ((err = hal_rsa_public_key_from_der(&key2, keybuf2, sizeof(keybuf2), der, der_len)) != HAL_OK) + return printf("Converting RSA public key back from DER failed: %s\n", hal_error_string(err)), 0; /* * Can't directly compare private key with public key. We could -- cgit v1.2.3