[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Bug #5170 - test crypto_pk_get_all_digests



commit e4f51682bc6d15e5ba78dfe6dfe69e95c298954e
Author: Marek Majkowski <marek@xxxxxxxxxxxx>
Date:   Mon Jun 10 15:03:18 2013 +0100

    Bug #5170 - test crypto_pk_get_all_digests
---
 src/test/test_crypto.c |   34 ++++++++++++++++++++++++++++++++++
 src/test/test_data.c   |    5 +++++
 2 files changed, 39 insertions(+)

diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index 839de7d..e45fbb8 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -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" },
diff --git a/src/test/test_data.c b/src/test/test_data.c
index 5f0f7cb..3c68b12 100644
--- a/src/test/test_data.c
+++ b/src/test/test_data.c
@@ -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"



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits