]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
ceph_crypto: Add unittests for the HMAC-SHA1 compatibility shim.
authorTommi Virtanen <tommi.virtanen@dreamhost.com>
Thu, 10 Mar 2011 20:39:42 +0000 (12:39 -0800)
committerTommi Virtanen <tommi.virtanen@dreamhost.com>
Fri, 11 Mar 2011 21:13:40 +0000 (13:13 -0800)
Signed-off-by: Tommi Virtanen <tommi.virtanen@dreamhost.com>
src/test/ceph_crypto.cc

index ff2b87f9872a54e4b82d7fe154a3e16c86e31db2..626e47337c8f93a00d989d7fbf69c7888351a0a0 100644 (file)
@@ -63,3 +63,56 @@ TEST(MD5, Restart) {
   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];
+  h.Final(digest);
+  int err;
+  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);
+  ASSERT_EQ(0, err);
+}
+
+TEST(HMACSHA1, MultiUpdate) {
+  ceph::crypto::HMACSHA1 h((const byte*)"sekrit", 6);
+  h.Update((const byte*)"", 0);
+  h.Update((const byte*)"fo", 2);
+  h.Update((const byte*)"", 0);
+  h.Update((const byte*)"o", 1);
+  h.Update((const byte*)"", 0);
+  unsigned char digest[ceph::crypto::HMACSHA1::DIGESTSIZE];
+  h.Final(digest);
+  int err;
+  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);
+  ASSERT_EQ(0, err);
+}
+
+TEST(HMACSHA1, Restart) {
+  ceph::crypto::HMACSHA1 h((const byte*)"sekrit", 6);
+  h.Update((const byte*)"bar", 3);
+  h.Restart();
+  h.Update((const byte*)"foo", 3);
+  unsigned char digest[ceph::crypto::HMACSHA1::DIGESTSIZE];
+  h.Final(digest);
+  int err;
+  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);
+  ASSERT_EQ(0, err);
+}