diff options
author | Matt Caswell <matt@openssl.org> | 2017-12-01 18:57:42 +0100 |
---|---|---|
committer | Matt Caswell <matt@openssl.org> | 2018-03-15 13:47:27 +0100 |
commit | 4665244ce28add625d28c9ee9c52e39b42024705 (patch) | |
tree | 2350aa7ddf280394de45a551c40ba4bff9bf4507 /test/evp_test.c | |
parent | Add documentation for the newly added EVP_PKEY_new*() functions (diff) | |
download | openssl-4665244ce28add625d28c9ee9c52e39b42024705.tar.xz openssl-4665244ce28add625d28c9ee9c52e39b42024705.zip |
Add PrivateKeyRaw and PublicKeyRaw support to evp_test
Previously private and public keys had to be pem encoded to be read by
evp_test. This enables us to embed the raw private/public key values
in the test file. The algorithm has to support EVP_PKEY_new_private_key()
and EVP_PKEY_new_public_key() for this to work.
Reviewed-by: Richard Levitte <levitte@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/5520)
Diffstat (limited to 'test/evp_test.c')
-rw-r--r-- | test/evp_test.c | 47 |
1 files changed, 45 insertions, 2 deletions
diff --git a/test/evp_test.c b/test/evp_test.c index 860fcc878e..a804a9f73a 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -2444,8 +2444,7 @@ top: return 0; } klist = &private_keys; - } - else if (strcmp(pp->key, "PublicKey") == 0) { + } else if (strcmp(pp->key, "PublicKey") == 0) { pkey = PEM_read_bio_PUBKEY(t->s.key, NULL, 0, NULL); if (pkey == NULL && !key_unsupported()) { TEST_info("Can't read public key %s", pp->value); @@ -2453,6 +2452,50 @@ top: return 0; } klist = &public_keys; + } else if (strcmp(pp->key, "PrivateKeyRaw") == 0 + || strcmp(pp->key, "PublicKeyRaw") == 0 ) { + char *strnid = NULL, *keydata = NULL; + unsigned char *keybin; + size_t keylen; + int nid; + + if (strcmp(pp->key, "PrivateKeyRaw") == 0) + klist = &private_keys; + else + klist = &public_keys; + + strnid = strchr(pp->value, ':'); + if (strnid != NULL) { + *strnid++ = '\0'; + keydata = strchr(strnid, ':'); + if (keydata != NULL) + *keydata++ = '\0'; + } + if (keydata == NULL) { + TEST_info("Failed to parse %s value", pp->key); + return 0; + } + + nid = OBJ_txt2nid(strnid); + if (nid == NID_undef) { + TEST_info("Uncrecognised algorithm NID"); + return 0; + } + if (!parse_bin(keydata, &keybin, &keylen)) { + TEST_info("Failed to create binary key"); + return 0; + } + if (klist == &private_keys) + pkey = EVP_PKEY_new_private_key(nid, NULL, keybin, keylen); + else + pkey = EVP_PKEY_new_public_key(nid, NULL, keybin, keylen); + if (pkey == NULL) { + TEST_info("Can't read %s data", pp->key); + OPENSSL_free(keybin); + TEST_openssl_errors(); + return 0; + } + OPENSSL_free(keybin); } /* If we have a key add to list */ |