From dff2c5b20e6c6e743881fc54c68e9910df19fe2b Mon Sep 17 00:00:00 2001 From: Colin Patrick McCabe Date: Wed, 23 Mar 2011 18:49:04 -0700 Subject: [PATCH] Use macro for digest size, part 2: tests Signed-off-by: Colin McCabe --- src/common/ceph_crypto.h | 1 - src/test/ceph_crypto.cc | 46 ++++++++++++++++------------------------ 2 files changed, 18 insertions(+), 29 deletions(-) diff --git a/src/common/ceph_crypto.h b/src/common/ceph_crypto.h index abaf95cfdec9b..ebe39b14e51c4 100644 --- a/src/common/ceph_crypto.h +++ b/src/common/ceph_crypto.h @@ -86,7 +86,6 @@ namespace ceph { PK11SymKey *symkey; PK11Context *ctx; public: - static const int DIGESTSIZE; HMACSHA1 (const byte *key, size_t length) { slot = PK11_GetBestSlot(CKM_SHA_1_HMAC, NULL); assert(slot); diff --git a/src/test/ceph_crypto.cc b/src/test/ceph_crypto.cc index 626e47337c8f9..772bdee5188f3 100644 --- a/src/test/ceph_crypto.cc +++ b/src/test/ceph_crypto.cc @@ -11,22 +11,17 @@ public: ::testing::Environment* const crypto_env = ::testing::AddGlobalTestEnvironment(new CryptoEnvironment); -TEST(MD5, DigestSize) { - int s = ceph::crypto::MD5::DIGESTSIZE; - ASSERT_EQ(16, s); -} - TEST(MD5, Simple) { ceph::crypto::MD5 h; h.Update((const byte*)"foo", 3); - unsigned char digest[ceph::crypto::MD5::DIGESTSIZE]; + unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); int err; - unsigned char want_digest[ceph::crypto::MD5::DIGESTSIZE] = { + unsigned char want_digest[CEPH_CRYPTO_MD5_DIGESTSIZE] = { 0xac, 0xbd, 0x18, 0xdb, 0x4c, 0xc2, 0xf8, 0x5c, 0xed, 0xef, 0x65, 0x4f, 0xcc, 0xc4, 0xa4, 0xd8, }; - err = memcmp(digest, want_digest, ceph::crypto::MD5::DIGESTSIZE); + err = memcmp(digest, want_digest, CEPH_CRYPTO_MD5_DIGESTSIZE); ASSERT_EQ(0, err); } @@ -37,14 +32,14 @@ TEST(MD5, MultiUpdate) { h.Update((const byte*)"", 0); h.Update((const byte*)"o", 1); h.Update((const byte*)"", 0); - unsigned char digest[ceph::crypto::MD5::DIGESTSIZE]; + unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); int err; - unsigned char want_digest[ceph::crypto::MD5::DIGESTSIZE] = { + unsigned char want_digest[CEPH_CRYPTO_MD5_DIGESTSIZE] = { 0xac, 0xbd, 0x18, 0xdb, 0x4c, 0xc2, 0xf8, 0x5c, 0xed, 0xef, 0x65, 0x4f, 0xcc, 0xc4, 0xa4, 0xd8, }; - err = memcmp(digest, want_digest, ceph::crypto::MD5::DIGESTSIZE); + err = memcmp(digest, want_digest, CEPH_CRYPTO_MD5_DIGESTSIZE); ASSERT_EQ(0, err); } @@ -53,33 +48,28 @@ TEST(MD5, Restart) { h.Update((const byte*)"bar", 3); h.Restart(); h.Update((const byte*)"foo", 3); - unsigned char digest[ceph::crypto::MD5::DIGESTSIZE]; + unsigned char digest[CEPH_CRYPTO_MD5_DIGESTSIZE]; h.Final(digest); int err; - unsigned char want_digest[ceph::crypto::MD5::DIGESTSIZE] = { + unsigned char want_digest[CEPH_CRYPTO_MD5_DIGESTSIZE] = { 0xac, 0xbd, 0x18, 0xdb, 0x4c, 0xc2, 0xf8, 0x5c, 0xed, 0xef, 0x65, 0x4f, 0xcc, 0xc4, 0xa4, 0xd8, }; - err = memcmp(digest, want_digest, ceph::crypto::MD5::DIGESTSIZE); + err = memcmp(digest, want_digest, CEPH_CRYPTO_MD5_DIGESTSIZE); ASSERT_EQ(0, err); } -TEST(HMACSHA1, DigestSize) { - int s = ceph::crypto::HMACSHA1::DIGESTSIZE; - ASSERT_EQ(20, s); -} - TEST(HMACSHA1, Simple) { ceph::crypto::HMACSHA1 h((const byte*)"sekrit", 6); h.Update((const byte*)"foo", 3); - unsigned char digest[ceph::crypto::HMACSHA1::DIGESTSIZE]; + unsigned char digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE]; h.Final(digest); int err; - unsigned char want_digest[ceph::crypto::HMACSHA1::DIGESTSIZE] = { + unsigned char want_digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE] = { 0x04, 0xbc, 0x52, 0x66, 0xb6, 0xff, 0xad, 0xad, 0x9d, 0x57, 0xce, 0x13, 0xea, 0x8c, 0xf5, 0x6b, 0xf9, 0x95, 0x2f, 0xd6, }; - err = memcmp(digest, want_digest, ceph::crypto::HMACSHA1::DIGESTSIZE); + err = memcmp(digest, want_digest, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE); ASSERT_EQ(0, err); } @@ -90,14 +80,14 @@ TEST(HMACSHA1, MultiUpdate) { h.Update((const byte*)"", 0); h.Update((const byte*)"o", 1); h.Update((const byte*)"", 0); - unsigned char digest[ceph::crypto::HMACSHA1::DIGESTSIZE]; + unsigned char digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE]; h.Final(digest); int err; - unsigned char want_digest[ceph::crypto::HMACSHA1::DIGESTSIZE] = { + unsigned char want_digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE] = { 0x04, 0xbc, 0x52, 0x66, 0xb6, 0xff, 0xad, 0xad, 0x9d, 0x57, 0xce, 0x13, 0xea, 0x8c, 0xf5, 0x6b, 0xf9, 0x95, 0x2f, 0xd6, }; - err = memcmp(digest, want_digest, ceph::crypto::HMACSHA1::DIGESTSIZE); + err = memcmp(digest, want_digest, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE); ASSERT_EQ(0, err); } @@ -106,13 +96,13 @@ TEST(HMACSHA1, Restart) { h.Update((const byte*)"bar", 3); h.Restart(); h.Update((const byte*)"foo", 3); - unsigned char digest[ceph::crypto::HMACSHA1::DIGESTSIZE]; + unsigned char digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE]; h.Final(digest); int err; - unsigned char want_digest[ceph::crypto::HMACSHA1::DIGESTSIZE] = { + unsigned char want_digest[CEPH_CRYPTO_HMACSHA1_DIGESTSIZE] = { 0x04, 0xbc, 0x52, 0x66, 0xb6, 0xff, 0xad, 0xad, 0x9d, 0x57, 0xce, 0x13, 0xea, 0x8c, 0xf5, 0x6b, 0xf9, 0x95, 0x2f, 0xd6, }; - err = memcmp(digest, want_digest, ceph::crypto::HMACSHA1::DIGESTSIZE); + err = memcmp(digest, want_digest, CEPH_CRYPTO_HMACSHA1_DIGESTSIZE); ASSERT_EQ(0, err); } -- 2.39.5