mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-10 21:23:58 +01:00
Bug #5170 - test crypto_pk_get_all_digests
This commit is contained in:
parent
68be3469c5
commit
e4f51682bc
@ -14,6 +14,10 @@
|
||||
#include "crypto_curve25519.h"
|
||||
#endif
|
||||
|
||||
extern const char AUTHORITY_SIGNKEY_1[];
|
||||
extern const char AUTHORITY_SIGNKEY_1_DIGEST[];
|
||||
extern const char AUTHORITY_SIGNKEY_1_DIGEST256[];
|
||||
|
||||
/** Run unit tests for Diffie-Hellman functionality. */
|
||||
static void
|
||||
test_crypto_dh(void)
|
||||
@ -505,6 +509,35 @@ test_crypto_pk(void)
|
||||
tor_free(encoded);
|
||||
}
|
||||
|
||||
/** Sanity check for crypto pk digests */
|
||||
static void
|
||||
test_crypto_digests(void)
|
||||
{
|
||||
crypto_pk_t *k = NULL;
|
||||
ssize_t r;
|
||||
digests_t pkey_digests;
|
||||
char digest[DIGEST_LEN];
|
||||
|
||||
k = crypto_pk_new();
|
||||
test_assert(k);
|
||||
r = crypto_pk_read_private_key_from_string(k, AUTHORITY_SIGNKEY_1, -1);
|
||||
test_assert(!r);
|
||||
|
||||
r = crypto_pk_get_digest(k, digest);
|
||||
test_assert(r == 0);
|
||||
test_memeq(hex_str(digest, DIGEST_LEN),
|
||||
AUTHORITY_SIGNKEY_1_DIGEST, HEX_DIGEST_LEN);
|
||||
|
||||
r = crypto_pk_get_all_digests(k, &pkey_digests);
|
||||
|
||||
test_memeq(hex_str(pkey_digests.d[DIGEST_SHA1], DIGEST_LEN),
|
||||
AUTHORITY_SIGNKEY_1_DIGEST, HEX_DIGEST_LEN);
|
||||
test_memeq(hex_str(pkey_digests.d[DIGEST_SHA256], DIGEST256_LEN),
|
||||
AUTHORITY_SIGNKEY_1_DIGEST256, HEX_DIGEST256_LEN);
|
||||
done:
|
||||
crypto_pk_free(k);
|
||||
}
|
||||
|
||||
/** Run unit tests for misc crypto formatting functionality (base64, base32,
|
||||
* fingerprints, etc) */
|
||||
static void
|
||||
@ -1103,6 +1136,7 @@ struct testcase_t crypto_tests[] = {
|
||||
{ "aes_EVP", test_crypto_aes, TT_FORK, &pass_data, (void*)"evp" },
|
||||
CRYPTO_LEGACY(sha),
|
||||
CRYPTO_LEGACY(pk),
|
||||
CRYPTO_LEGACY(digests),
|
||||
CRYPTO_LEGACY(dh),
|
||||
CRYPTO_LEGACY(s2k),
|
||||
{ "aes_iv_AES", test_crypto_aes_iv, TT_FORK, &pass_data, (void*)"aes" },
|
||||
|
@ -63,6 +63,11 @@ const char AUTHORITY_SIGNKEY_1[] =
|
||||
"Yx4lqK0ca5IkTp3HevwnlWaJgbaOTUspCVshzJBhDA==\n"
|
||||
"-----END RSA PRIVATE KEY-----\n";
|
||||
|
||||
const char AUTHORITY_SIGNKEY_1_DIGEST[] =
|
||||
"CBF56A83368A5150F1A9AAADAFB4D77F8C4170E2";
|
||||
const char AUTHORITY_SIGNKEY_1_DIGEST256[] =
|
||||
"AF7C5468DBE3BA54A052726038D7F15F3C4CA511B1952645B3D96D83A8DFB51C";
|
||||
|
||||
/** Second of 3 example authority certificates for unit testing. */
|
||||
const char AUTHORITY_CERT_2[] =
|
||||
"dir-key-certificate-version 3\n"
|
||||
|
Loading…
Reference in New Issue
Block a user