|
@@ -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" },
|