Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(413)

Unified Diff: content/renderer/webcrypto_impl_unittest.cc

Issue 24616003: Implement verify() for HMAC using NSS (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_build_sh
Patch Set: Rebase. Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/renderer/webcrypto_impl_openssl.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/renderer/webcrypto_impl_unittest.cc
diff --git a/content/renderer/webcrypto_impl_unittest.cc b/content/renderer/webcrypto_impl_unittest.cc
index 170c39d11e5230dcaf144d8930ba45e735ae418e..696d88745dcd0f9481628b0925019fdef81c0b6d 100644
--- a/content/renderer/webcrypto_impl_unittest.cc
+++ b/content/renderer/webcrypto_impl_unittest.cc
@@ -105,6 +105,23 @@ class WebCryptoImplTest : public testing::Test {
return crypto_.SignInternal(algorithm, key, data, data_size, buffer);
}
+ bool VerifySignatureInternal(
+ const WebKit::WebCryptoAlgorithm& algorithm,
+ const WebKit::WebCryptoKey& key,
+ const unsigned char* signature,
+ unsigned signature_size,
+ const unsigned char* data,
+ unsigned data_size,
+ bool* signature_match) {
+ return crypto_.VerifySignatureInternal(algorithm,
+ key,
+ signature,
+ signature_size,
+ data,
+ data_size,
+ signature_match);
+ }
+
private:
WebCryptoImpl crypto_;
};
@@ -296,6 +313,40 @@ TEST_F(WebCryptoImplTest, HMACSampleSets) {
algorithm, key, message_raw.data(), message_raw.size(), &output));
ExpectArrayBufferMatchesHex(test.mac, output);
+
+ bool signature_match = false;
+ EXPECT_TRUE(VerifySignatureInternal(
+ algorithm,
+ key,
+ static_cast<const unsigned char*>(output.data()),
+ output.byteLength(),
+ message_raw.data(),
+ message_raw.size(),
+ &signature_match));
+ EXPECT_TRUE(signature_match);
+
+ // Ensure truncated signature does not verify by passing one less byte.
+ EXPECT_TRUE(VerifySignatureInternal(
+ algorithm,
+ key,
+ static_cast<const unsigned char*>(output.data()),
+ output.byteLength() - 1,
+ message_raw.data(),
+ message_raw.size(),
+ &signature_match));
+ EXPECT_FALSE(signature_match);
+
+ // Ensure extra long signature does not cause issues and fails.
+ const unsigned char kLongSignature[1024] = { 0 };
+ EXPECT_TRUE(VerifySignatureInternal(
+ algorithm,
+ key,
+ kLongSignature,
+ sizeof(kLongSignature),
+ message_raw.data(),
+ message_raw.size(),
+ &signature_match));
+ EXPECT_FALSE(signature_match);
}
}
« no previous file with comments | « content/renderer/webcrypto_impl_openssl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698