diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/GNUmakefile | 2 | ||||
-rw-r--r-- | tests/test-ecdsa.c | 3 | ||||
-rw-r--r-- | tests/test-rsa.c | 17 |
3 files changed, 17 insertions, 5 deletions
diff --git a/tests/GNUmakefile b/tests/GNUmakefile index 50b33a1..ba515f7 100644 --- a/tests/GNUmakefile +++ b/tests/GNUmakefile @@ -36,7 +36,7 @@ CFLAGS = -g3 -Wall -fPIC -std=c99 -I.. all: ${BIN} test: all - for i in ${BIN}; do ./$$i; done + for i in ${BIN}; do (set -x; ./$$i); done clean: rm -f *.o ${BIN} diff --git a/tests/test-ecdsa.c b/tests/test-ecdsa.c index bdcfca6..da2b367 100644 --- a/tests/test-ecdsa.c +++ b/tests/test-ecdsa.c @@ -231,6 +231,9 @@ static int test_against_static_vectors(const ecdsa_tc_t * const tc) if (err != HAL_OK) return printf("hal_ecdsa_public_key_to_der() failed: %s\n", hal_error_string(err)), 0; + if ((err = hal_ecdsa_public_key_from_der(&key2, keybuf2, sizeof(keybuf2), der, der_len)) != HAL_OK) + return printf("hal_ecdsa_public_key_from_der() failed: %s\n", hal_error_string(err)), 0; + if (memcmp(key1, key2, hal_ecdsa_key_t_size) != 0) return printf("Public key mismatch after second read/write cycle\n"), 0; 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 |