Chromium Code Reviews| Index: content/renderer/webcrypto/webcrypto_impl_unittest.cc |
| diff --git a/content/renderer/webcrypto/webcrypto_impl_unittest.cc b/content/renderer/webcrypto/webcrypto_impl_unittest.cc |
| index 8120dfab27e4afffa55d802f782e4cbe9da23df3..24ded89bbb2ded9e2c60d8d5c5fd846ba44a60ab 100644 |
| --- a/content/renderer/webcrypto/webcrypto_impl_unittest.cc |
| +++ b/content/renderer/webcrypto/webcrypto_impl_unittest.cc |
| @@ -9,10 +9,15 @@ |
| #include <vector> |
| #include "base/basictypes.h" |
| +#include "base/file_util.h" |
| +#include "base/json/json_reader.h" |
| #include "base/json/json_writer.h" |
| #include "base/logging.h" |
| #include "base/memory/ref_counted.h" |
| +#include "base/path_service.h" |
| #include "base/strings/string_number_conversions.h" |
| +#include "base/values.h" |
| +#include "content/public/common/content_paths.h" |
| #include "content/public/renderer/content_renderer_client.h" |
| #include "content/renderer/renderer_webkitplatformsupport_impl.h" |
| #include "content/renderer/webcrypto/webcrypto_util.h" |
| @@ -21,6 +26,7 @@ |
| #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" |
| #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h" |
| #include "third_party/WebKit/public/platform/WebCryptoKey.h" |
| +#include "third_party/re2/re2/re2.h" |
| // The OpenSSL implementation of WebCrypto is less complete, so don't run all of |
| // the tests: http://crbug.com/267888 |
| @@ -63,6 +69,13 @@ std::vector<uint8> HexStringToBytes(const std::string& hex) { |
| return bytes; |
| } |
| +void ExpectArrayBufferMatches(const std::vector<uint8>& expected, |
| + const blink::WebArrayBuffer& actual) { |
| + EXPECT_EQ( |
| + base::HexEncode(webcrypto::Uint8VectorStart(expected), expected.size()), |
| + base::HexEncode(actual.data(), actual.byteLength())); |
| +} |
| + |
| void ExpectArrayBufferMatchesHex(const std::string& expected_hex, |
| const blink::WebArrayBuffer& array_buffer) { |
| EXPECT_STRCASEEQ( |
| @@ -70,12 +83,11 @@ void ExpectArrayBufferMatchesHex(const std::string& expected_hex, |
| base::HexEncode(array_buffer.data(), array_buffer.byteLength()).c_str()); |
| } |
| -void ExpectVectorMatchesHex(const std::string& expected_hex, |
| - const std::vector<uint8>& bytes) { |
| - EXPECT_STRCASEEQ( |
| - expected_hex.c_str(), |
| - base::HexEncode(webcrypto::Uint8VectorStart(bytes), |
| - bytes.size()).c_str()); |
| +void ExpectVectorMatches(const std::vector<uint8>& expected, |
| + const std::vector<uint8>& actual) { |
| + EXPECT_EQ( |
| + base::HexEncode(webcrypto::Uint8VectorStart(expected), expected.size()), |
| + base::HexEncode(webcrypto::Uint8VectorStart(actual), actual.size())); |
| } |
| std::vector<uint8> MakeJsonVector(const std::string& json_string) { |
| @@ -88,6 +100,110 @@ std::vector<uint8> MakeJsonVector(const base::DictionaryValue& dict) { |
| return MakeJsonVector(json); |
| } |
| +// ---------------------------------------------------------------- |
| +// Helpers for working with JSON data files for test expectations. |
| +// ---------------------------------------------------------------- |
| + |
| +// Reads a file in "src/content/test/data/webcrypto" to a base::Value. |
| +// The file must be JSON, however it can also include C++ style comments. |
| +::testing::AssertionResult ReadJsonTestFile( |
| + const char* test_file_name, |
| + scoped_ptr<base::Value>* value) { |
| + base::FilePath test_data_dir; |
| + if (!PathService::Get(DIR_TEST_DATA, &test_data_dir)) |
| + return ::testing::AssertionFailure() << "Couldn't retrieve test dir"; |
| + |
| + base::FilePath file_path = |
| + test_data_dir.AppendASCII("webcrypto").AppendASCII(test_file_name); |
| + |
| + std::string file_contents; |
| + if (!base::ReadFileToString(file_path, &file_contents)) { |
| + return ::testing::AssertionFailure() << "Couldn't read test file: " |
| + << file_path.value(); |
| + } |
| + |
| + // Strip C++ style comments out of the "json" file, otherwise it cannot be |
| + // parsed. |
| + re2::RE2::GlobalReplace(&file_contents, re2::RE2("\\s*//.*"), ""); |
| + |
| + // Parse the JSON to a dictionary. |
| + value->reset(base::JSONReader::Read(file_contents)); |
| + if (!value->get()) { |
| + return ::testing::AssertionFailure() << "Couldn't parse test file JSON: " |
| + << file_path.value(); |
| + } |
| + |
| + return ::testing::AssertionSuccess(); |
| +} |
| + |
| +// Same as ReadJsonTestFile(), but return the value as a List. |
| +::testing::AssertionResult ReadJsonTestFileToList( |
| + const char* test_file_name, |
| + scoped_ptr<base::ListValue>* list) { |
| + // Read the JSON. |
| + scoped_ptr<base::Value> json; |
| + ::testing::AssertionResult result = ReadJsonTestFile(test_file_name, &json); |
| + if (!result) |
| + return result; |
| + |
| + // Cast to an ListValue. |
| + base::ListValue* list_value = NULL; |
| + if (!json->GetAsList(&list_value) || !list_value) |
| + return ::testing::AssertionFailure() << "The JSON was not a list"; |
| + |
| + list->reset(list_value); |
| + ignore_result(json.release()); |
| + |
| + return ::testing::AssertionSuccess(); |
| +} |
| + |
| +// Read a string property from the dictionary with path |property_name| |
| +// (which can include periods for nested dictionaries). Interprets the |
| +// string as a hex encoded string and converts it to a bytes list. |
| +// |
| +// Returns empty vector on failure. |
| +std::vector<uint8> GetBytesFromHexString( |
| + base::DictionaryValue* dict, |
| + const char* property_name) { |
| + std::string hex_string; |
| + if (!dict->GetString(property_name, &hex_string)) { |
| + EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; |
| + return std::vector<uint8>(); |
| + } |
| + |
| + return HexStringToBytes(hex_string); |
| +} |
| + |
| +// Reads a string property with path "property_name" and converts it to a |
| +// WebCryptoAlgorith. Returns null algorithm on failure. |
| +blink::WebCryptoAlgorithm GetDigestAlgorithm( |
| + base::DictionaryValue* dict, |
| + const char* property_name) { |
| + std::string algorithm_name; |
| + if (!dict->GetString(property_name, &algorithm_name)) { |
| + EXPECT_TRUE(false) << "Couldn't get string property: " << property_name; |
| + return blink::WebCryptoAlgorithm::createNull(); |
| + } |
| + |
| + struct { |
| + const char* name; |
| + blink::WebCryptoAlgorithmId id; |
| + } kDigestNameToId[] = { |
|
Ryan Sleevi
2014/01/31 20:53:36
make this struct const/static too?
|
| + {"sha-1", blink::WebCryptoAlgorithmIdSha1}, |
| + {"sha-224", blink::WebCryptoAlgorithmIdSha224}, |
| + {"sha-256", blink::WebCryptoAlgorithmIdSha256}, |
| + {"sha-384", blink::WebCryptoAlgorithmIdSha384}, |
| + {"sha-512", blink::WebCryptoAlgorithmIdSha512}, |
| + }; |
| + |
| + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(kDigestNameToId); ++i) { |
| + if (kDigestNameToId[i].name == algorithm_name) |
| + return webcrypto::CreateAlgorithm(kDigestNameToId[i].id); |
| + } |
| + |
| + return blink::WebCryptoAlgorithm::createNull(); |
| +} |
| + |
| // Helper for ImportJwkFailures and ImportJwkOctFailures. Restores the JWK JSON |
| // dictionary to a good state |
| void RestoreJwkOctDictionary(base::DictionaryValue* dict) { |
| @@ -223,12 +339,10 @@ const char* const kPrivateKeyPkcs8DerHex = |
| class WebCryptoImplTest : public testing::Test { |
| protected: |
| - blink::WebCryptoKey ImportSecretKeyFromRawHexString( |
| - const std::string& key_hex, |
| + blink::WebCryptoKey ImportSecretKeyFromRaw( |
| + const std::vector<uint8>& key_raw, |
| const blink::WebCryptoAlgorithm& algorithm, |
| blink::WebCryptoKeyUsageMask usage) { |
| - std::vector<uint8> key_raw = HexStringToBytes(key_hex); |
| - |
| blink::WebCryptoKey key = blink::WebCryptoKey::createNull(); |
| bool extractable = true; |
| EXPECT_STATUS_SUCCESS( |
| @@ -250,8 +364,8 @@ class WebCryptoImplTest : public testing::Test { |
| } |
| void ImportRsaKeyPair( |
| - const std::string& spki_der_hex, |
| - const std::string& pkcs8_der_hex, |
| + const std::vector<uint8>& spki_der, |
| + const std::vector<uint8>& pkcs8_der, |
| const blink::WebCryptoAlgorithm& algorithm, |
| bool extractable, |
| blink::WebCryptoKeyUsageMask usage_mask, |
| @@ -259,7 +373,7 @@ class WebCryptoImplTest : public testing::Test { |
| blink::WebCryptoKey* private_key) { |
| EXPECT_STATUS_SUCCESS(ImportKeyInternal( |
| blink::WebCryptoKeyFormatSpki, |
| - HexStringToBytes(spki_der_hex), |
| + spki_der, |
| algorithm, |
| true, |
| usage_mask, |
| @@ -273,7 +387,7 @@ class WebCryptoImplTest : public testing::Test { |
| EXPECT_STATUS_SUCCESS(ImportKeyInternal( |
| blink::WebCryptoKeyFormatPkcs8, |
| - HexStringToBytes(pkcs8_der_hex), |
| + pkcs8_der, |
| algorithm, |
| extractable, |
| usage_mask, |
| @@ -518,244 +632,57 @@ TEST_F(WebCryptoImplTest, StatusToString) { |
| } |
| TEST_F(WebCryptoImplTest, DigestSampleSets) { |
| - // The results are stored here in hex format for readability. |
| - // |
| - // TODO(bryaneyler): Eventually, all these sample test sets should be replaced |
| - // with the sets here: http://csrc.nist.gov/groups/STM/cavp/index.html#03 |
| - // |
| - // Results were generated using the command sha{1,224,256,384,512}sum. |
| - struct TestCase { |
| - blink::WebCryptoAlgorithmId algorithm; |
| - const std::string hex_input; |
| - const char* hex_result; |
| - }; |
| + scoped_ptr<base::ListValue> tests; |
| + ASSERT_TRUE(ReadJsonTestFileToList("digest.json", &tests)); |
| - const TestCase kTests[] = { |
| - { blink::WebCryptoAlgorithmIdSha1, "", |
| - "da39a3ee5e6b4b0d3255bfef95601890afd80709" |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha224, "", |
| - "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f" |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha256, "", |
| - "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha384, "", |
| - "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274e" |
| - "debfe76f65fbd51ad2f14898b95b" |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha512, "", |
| - "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0" |
| - "d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha1, "00", |
| - "5ba93c9db0cff93f52b521d7420e43f6eda2784f", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha224, "00", |
| - "fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha256, "00", |
| - "6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha384, "00", |
| - "bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d6636655933" |
| - "ec2b413465966817a9c208a11717", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha512, "00", |
| - "b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704a" |
| - "802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha1, "000102030405", |
| - "868460d98d09d8bbb93d7b6cdd15cc7fbec676b9", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha224, "000102030405", |
| - "7d92e7f1cad1818ed1d13ab41f04ebabfe1fef6bb4cbeebac34c29bc", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha256, "000102030405", |
| - "17e88db187afd62c16e5debf3e6527cd006bc012bc90b51a810cd80c2d511f43", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha384, "000102030405", |
| - "79f4738706fce9650ac60266675c3cd07298b09923850d525604d040e6e448adc7dc" |
| - "22780d7e1b95bfeaa86a678e4552", |
| - }, |
| - { blink::WebCryptoAlgorithmIdSha512, "000102030405", |
| - "2f3831bccc94cf061bcfa5f8c23c1429d26e3bc6b76edad93d9025cb91c903af6cf9" |
| - "c935dc37193c04c2c66e7d9de17c358284418218afea2160147aaa912f4c", |
| - }, |
| - }; |
| - |
| - for (size_t test_index = 0; test_index < ARRAYSIZE_UNSAFE(kTests); |
| - ++test_index) { |
| + for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { |
|
Ryan Sleevi
2014/01/31 20:53:36
So, this is valid code, so consider this a questio
eroman
2014/01/31 22:15:33
Not sure I understand this argument from a "perfor
|
| SCOPED_TRACE(test_index); |
| - const TestCase& test = kTests[test_index]; |
| + base::DictionaryValue* test; |
| + ASSERT_TRUE(tests->GetDictionary(test_index, &test)); |
| - blink::WebCryptoAlgorithm algorithm = |
| - webcrypto::CreateAlgorithm(test.algorithm); |
| - std::vector<uint8> input = HexStringToBytes(test.hex_input); |
| + blink::WebCryptoAlgorithm test_algorithm = |
| + GetDigestAlgorithm(test, "algorithm"); |
| + std::vector<uint8> test_input = GetBytesFromHexString(test, "input"); |
| + std::vector<uint8> test_output = GetBytesFromHexString(test, "output"); |
| blink::WebArrayBuffer output; |
| - ASSERT_STATUS_SUCCESS(DigestInternal(algorithm, input, &output)); |
| - ExpectArrayBufferMatchesHex(test.hex_result, output); |
| + ASSERT_STATUS_SUCCESS(DigestInternal(test_algorithm, test_input, &output)); |
| + ExpectArrayBufferMatches(test_output, output); |
| } |
| } |
| TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| - struct TestCase { |
| - blink::WebCryptoAlgorithmId algorithm; |
| - const char* key; |
| - const char* message; |
| - const char* mac; |
| - }; |
| + scoped_ptr<base::ListValue> tests; |
| + ASSERT_TRUE(ReadJsonTestFileToList("hmac.json", &tests)); |
| - const TestCase kTests[] = { |
| - // Empty sets. Result generated via OpenSSL commandline tool. These |
| - // particular results are also posted on the Wikipedia page examples: |
| - // http://en.wikipedia.org/wiki/Hash-based_message_authentication_code |
| - { |
| - blink::WebCryptoAlgorithmIdSha1, |
| - "", |
| - "", |
| - // openssl dgst -sha1 -hmac "" < /dev/null |
| - "fbdb1d1b18aa6c08324b7d64b71fb76370690e1d", |
| - }, |
| - { |
| - blink::WebCryptoAlgorithmIdSha256, |
| - "", |
| - "", |
| - // openssl dgst -sha256 -hmac "" < /dev/null |
| - "b613679a0814d9ec772f95d778c35fc5ff1697c493715653c6c712144292c5ad", |
| - }, |
| - // For this data, see http://csrc.nist.gov/groups/STM/cavp/index.html#07 |
| - // Download: |
| - // http://csrc.nist.gov/groups/STM/cavp/documents/mac/hmactestvectors.zip |
| - // L=20 set 45 |
| - { |
| - blink::WebCryptoAlgorithmIdSha1, |
| - // key |
| - "59785928d72516e31272", |
| - // message |
| - "a3ce8899df1022e8d2d539b47bf0e309c66f84095e21438ec355bf119ce5fdcb4e73a6" |
| - "19cdf36f25b369d8c38ff419997f0c59830108223606e31223483fd39edeaa4d3f0d21" |
| - "198862d239c9fd26074130ff6c86493f5227ab895c8f244bd42c7afce5d147a20a5907" |
| - "98c68e708e964902d124dadecdbda9dbd0051ed710e9bf", |
| - // mac |
| - "3c8162589aafaee024fc9a5ca50dd2336fe3eb28", |
| - }, |
| - // L=20 set 299 |
| - { |
| - blink::WebCryptoAlgorithmIdSha1, |
| - // key |
| - "ceb9aedf8d6efcf0ae52bea0fa99a9e26ae81bacea0cff4d5eecf201e3bca3c3577480" |
| - "621b818fd717ba99d6ff958ea3d59b2527b019c343bb199e648090225867d994607962" |
| - "f5866aa62930d75b58f6", |
| - // message |
| - "99958aa459604657c7bf6e4cdfcc8785f0abf06ffe636b5b64ecd931bd8a4563055924" |
| - "21fc28dbcccb8a82acea2be8e54161d7a78e0399a6067ebaca3f2510274dc9f92f2c8a" |
| - "e4265eec13d7d42e9f8612d7bc258f913ecb5a3a5c610339b49fb90e9037b02d684fc6" |
| - "0da835657cb24eab352750c8b463b1a8494660d36c3ab2", |
| - // mac |
| - "4ac41ab89f625c60125ed65ffa958c6b490ea670", |
| - }, |
| - // L=32, set 30 |
| - { |
| - blink::WebCryptoAlgorithmIdSha256, |
| - // key |
| - "9779d9120642797f1747025d5b22b7ac607cab08e1758f2f3a46c8be1e25c53b8c6a8f" |
| - "58ffefa176", |
| - // message |
| - "b1689c2591eaf3c9e66070f8a77954ffb81749f1b00346f9dfe0b2ee905dcc288baf4a" |
| - "92de3f4001dd9f44c468c3d07d6c6ee82faceafc97c2fc0fc0601719d2dcd0aa2aec92" |
| - "d1b0ae933c65eb06a03c9c935c2bad0459810241347ab87e9f11adb30415424c6c7f5f" |
| - "22a003b8ab8de54f6ded0e3ab9245fa79568451dfa258e", |
| - // mac |
| - "769f00d3e6a6cc1fb426a14a4f76c6462e6149726e0dee0ec0cf97a16605ac8b", |
| - }, |
| - // L=32, set 224 |
| - { |
| - blink::WebCryptoAlgorithmIdSha256, |
| - // key |
| - "4b7ab133efe99e02fc89a28409ee187d579e774f4cba6fc223e13504e3511bef8d4f63" |
| - "8b9aca55d4a43b8fbd64cf9d74dcc8c9e8d52034898c70264ea911a3fd70813fa73b08" |
| - "3371289b", |
| - // message |
| - "138efc832c64513d11b9873c6fd4d8a65dbf367092a826ddd587d141b401580b798c69" |
| - "025ad510cff05fcfbceb6cf0bb03201aaa32e423d5200925bddfadd418d8e30e18050e" |
| - "b4f0618eb9959d9f78c1157d4b3e02cd5961f138afd57459939917d9144c95d8e6a94c" |
| - "8f6d4eef3418c17b1ef0b46c2a7188305d9811dccb3d99", |
| - // mac |
| - "4f1ee7cb36c58803a8721d4ac8c4cf8cae5d8832392eed2a96dc59694252801b", |
| - }, |
| - // L=28, Count=71 |
| - { |
| - blink::WebCryptoAlgorithmIdSha224, |
| - // key |
| - "6c2539f4d0453efbbacc137794930413aeb392e029e0724715f9d943d6dcf7cdcc7fc19" |
| - "7333df4fc476d5737ac3940d40eae", |
| - // message |
| - "1f207b3fa6c905529c9f9f7894b8941b616974df2c0cc482c400f50734f293139b5bbf9" |
| - "7384adfafc56494ca0629ed0ca179daf03056e33295eb19ec8dcd4dff898281b4b9409c" |
| - "a369f662d49091a225a678b1ebb75818dcb6278a2d136319f78f9ba9df5031a4f6305ee" |
| - "fde5b761d2f196ee318e89bcc4acebc2e11ed3b5dc4", |
| - // mac |
| - "4a7d9d13705b0faba0db75356c8ee0635afff1544911c69c2fbb1ab2" |
| - }, |
| - // L=48, Count=50 |
| - { |
| - blink::WebCryptoAlgorithmIdSha384, |
| - // key |
| - "d137f3e6cc4af28554beb03ba7a97e60c9d3959cd3bb08068edbf68d402d0498c6ee0ae" |
| - "9e3a20dc7d8586e5c352f605cee19", |
| - // message |
| - "64a884670d1c1dff555483dcd3da305dfba54bdc4d817c33ccb8fe7eb2ebf6236241031" |
| - "09ec41644fa078491900c59a0f666f0356d9bc0b45bcc79e5fc9850f4543d96bc680090" |
| - "44add0838ac1260e80592fbc557b2ddaf5ed1b86d3ed8f09e622e567f1d39a340857f6a" |
| - "850cceef6060c48dac3dd0071fe68eb4ed2ed9aca01", |
| - // mac |
| - "c550fa53514da34f15e7f98ea87226ab6896cdfae25d3ec2335839f755cdc9a4992092e" |
| - "70b7e5bd422784380b6396cf5" |
| - }, |
| - // L=64, Count=65 |
| - { |
| - blink::WebCryptoAlgorithmIdSha512, |
| - // key |
| - "c367aeb5c02b727883ffe2a4ceebf911b01454beb328fb5d57fc7f11bf744576aba421e2" |
| - "a63426ea8109bd28ff21f53cd2bf1a11c6c989623d6ec27cdb0bbf458250857d819ff844" |
| - "08b4f3dce08b98b1587ee59683af8852a0a5f55bda3ab5e132b4010e", |
| - // message |
| - "1a7331c8ff1b748e3cee96952190fdbbe4ee2f79e5753bbb368255ee5b19c05a4ed9f1b2" |
| - "c72ff1e9b9cb0348205087befa501e7793770faf0606e9c901836a9bc8afa00d7db94ee2" |
| - "9eb191d5cf3fc3e8da95a0f9f4a2a7964289c3129b512bd890de8700a9205420f28a8965" |
| - "b6c67be28ba7fe278e5fcd16f0f22cf2b2eacbb9", |
| - // mac |
| - "4459066109cb11e6870fa9c6bfd251adfa304c0a2928ca915049704972edc560cc7c0bc3" |
| - "8249e9101aae2f7d4da62eaff83fb07134efc277de72b9e4ab360425" |
| - }, |
| - }; |
| - |
| - for (size_t test_index = 0; test_index < ARRAYSIZE_UNSAFE(kTests); |
| - ++test_index) { |
| + for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { |
| SCOPED_TRACE(test_index); |
| - const TestCase& test = kTests[test_index]; |
| + base::DictionaryValue* test; |
| + ASSERT_TRUE(tests->GetDictionary(test_index, &test)); |
| + |
| + blink::WebCryptoAlgorithm test_hash = GetDigestAlgorithm(test, "hash"); |
| + const std::vector<uint8> test_key = GetBytesFromHexString(test, "key"); |
| + const std::vector<uint8> test_message = |
| + GetBytesFromHexString(test, "message"); |
| + const std::vector<uint8> test_mac = GetBytesFromHexString(test, "mac"); |
| blink::WebCryptoAlgorithm algorithm = |
| - webcrypto::CreateHmacAlgorithmByHashId(test.algorithm); |
| + webcrypto::CreateHmacAlgorithmByHashId(test_hash.id()); |
| - blink::WebCryptoKey key = ImportSecretKeyFromRawHexString( |
| - test.key, algorithm, blink::WebCryptoKeyUsageSign); |
| + blink::WebCryptoKey key = ImportSecretKeyFromRaw( |
| + test_key, algorithm, blink::WebCryptoKeyUsageSign); |
| // Verify exported raw key is identical to the imported data |
| blink::WebArrayBuffer raw_key; |
| EXPECT_STATUS_SUCCESS( |
| ExportKeyInternal(blink::WebCryptoKeyFormatRaw, key, &raw_key)); |
| - ExpectArrayBufferMatchesHex(test.key, raw_key); |
| - |
| - std::vector<uint8> message_raw = HexStringToBytes(test.message); |
| + ExpectArrayBufferMatches(test_key, raw_key); |
| blink::WebArrayBuffer output; |
| - ASSERT_STATUS_SUCCESS(SignInternal(algorithm, key, message_raw, &output)); |
| + ASSERT_STATUS_SUCCESS(SignInternal(algorithm, key, test_message, &output)); |
| - ExpectArrayBufferMatchesHex(test.mac, output); |
| + ExpectArrayBufferMatches(test_mac, output); |
| bool signature_match = false; |
| EXPECT_STATUS_SUCCESS(VerifySignatureInternal( |
| @@ -763,7 +690,7 @@ TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| key, |
| static_cast<const unsigned char*>(output.data()), |
| output.byteLength(), |
| - message_raw, |
| + test_message, |
| &signature_match)); |
| EXPECT_TRUE(signature_match); |
| @@ -773,7 +700,7 @@ TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| key, |
| static_cast<const unsigned char*>(output.data()), |
| output.byteLength() - 1, |
| - message_raw, |
| + test_message, |
| &signature_match)); |
| EXPECT_FALSE(signature_match); |
| @@ -783,7 +710,7 @@ TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| key, |
| NULL, |
| 0, |
| - message_raw, |
| + test_message, |
| &signature_match)); |
| EXPECT_FALSE(signature_match); |
| @@ -794,7 +721,7 @@ TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| key, |
| kLongSignature, |
| sizeof(kLongSignature), |
| - message_raw, |
| + test_message, |
| &signature_match)); |
| EXPECT_FALSE(signature_match); |
| } |
| @@ -802,8 +729,8 @@ TEST_F(WebCryptoImplTest, HMACSampleSets) { |
| TEST_F(WebCryptoImplTest, AesCbcFailures) { |
| const std::string key_hex = "2b7e151628aed2a6abf7158809cf4f3c"; |
| - blink::WebCryptoKey key = ImportSecretKeyFromRawHexString( |
| - key_hex, |
| + blink::WebCryptoKey key = ImportSecretKeyFromRaw( |
| + HexStringToBytes(key_hex), |
| webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
| blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt); |
| @@ -880,89 +807,23 @@ TEST_F(WebCryptoImplTest, AesCbcFailures) { |
| } |
| TEST_F(WebCryptoImplTest, MAYBE(AesCbcSampleSets)) { |
| - struct TestCase { |
| - const char* key; |
| - const char* iv; |
| - const char* plain_text; |
| - const char* cipher_text; |
| - }; |
| + scoped_ptr<base::ListValue> tests; |
| + ASSERT_TRUE(ReadJsonTestFileToList("aescbc.json", &tests)); |
|
Ryan Sleevi
2014/01/31 20:53:36
aes_cbc?
|
| - TestCase kTests[] = { |
| - // F.2.1 (CBC-AES128.Encrypt) |
| - // http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf |
| - { |
| - // key |
| - "2b7e151628aed2a6abf7158809cf4f3c", |
| - |
| - // iv |
| - "000102030405060708090a0b0c0d0e0f", |
| - |
| - // plain_text |
| - "6bc1bee22e409f96e93d7e117393172a" |
| - "ae2d8a571e03ac9c9eb76fac45af8e51" |
| - "30c81c46a35ce411e5fbc1191a0a52ef" |
| - "f69f2445df4f9b17ad2b417be66c3710", |
| - |
| - // cipher_text |
| - "7649abac8119b246cee98e9b12e9197d" |
| - "5086cb9b507219ee95db113a917678b2" |
| - "73bed6b8e3c1743b7116e69e22229516" |
| - "3ff1caa1681fac09120eca307586e1a7" |
| - // Padding block: encryption of {0x10, 0x10, ... 0x10}) (not given by the |
| - // NIST test vector) |
| - "8cb82807230e1321d3fae00d18cc2012" |
| - }, |
| - |
| - // F.2.6 CBC-AES256.Decrypt [*] |
| - // http://csrc.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf |
| - // |
| - // [*] Truncated 3 bytes off the plain text, so block 4 differs from the |
| - // NIST vector. |
| - { |
| - // key |
| - "603deb1015ca71be2b73aef0857d7781" |
| - "1f352c073b6108d72d9810a30914dff4", |
| - |
| - // iv |
| - "000102030405060708090a0b0c0d0e0f", |
| - |
| - // plain_text |
| - "6bc1bee22e409f96e93d7e117393172a" |
| - "ae2d8a571e03ac9c9eb76fac45af8e51" |
| - "30c81c46a35ce411e5fbc1191a0a52ef" |
| - // Truncated this last block to make it more interesting. |
| - "f69f2445df4f9b17ad2b417be6", |
| - |
| - // cipher_text |
| - "f58c4c04d6e5f1ba779eabfb5f7bfbd6" |
| - "9cfc4e967edb808d679f777bc6702c7d" |
| - "39f23369a9d9bacfa530e26304231461" |
| - // This block differs from source vector (due to truncation) |
| - "c9aaf02a6a54e9e242ccbf48c59daca6" |
| - }, |
| - |
| - // Taken from encryptor_unittest.cc (EncryptorTest.EmptyEncrypt()) |
| - { |
| - // key |
| - "3132383d5369787465656e4279746573", |
| - |
| - // iv |
| - "5377656574205369787465656e204956", |
| - |
| - // plain_text |
| - "", |
| - |
| - // cipher_text |
| - "8518b8878d34e7185e300d0fcc426396" |
| - }, |
| - }; |
| - |
| - for (size_t index = 0; index < ARRAYSIZE_UNSAFE(kTests); index++) { |
| + for (size_t index = 0; index < tests->GetSize(); index++) { |
|
Ryan Sleevi
2014/01/31 20:53:36
++index
eroman
2014/01/31 22:55:11
Done.
|
| SCOPED_TRACE(index); |
| - const TestCase& test = kTests[index]; |
| - |
| - blink::WebCryptoKey key = ImportSecretKeyFromRawHexString( |
| - test.key, |
| + base::DictionaryValue* test; |
| + ASSERT_TRUE(tests->GetDictionary(index, &test)); |
| + |
| + std::vector<uint8> test_key = GetBytesFromHexString(test, "key"); |
| + std::vector<uint8> test_iv = GetBytesFromHexString(test, "iv"); |
| + std::vector<uint8> test_plain_text = |
| + GetBytesFromHexString(test, "plain_text"); |
| + std::vector<uint8> test_cipher_text = |
| + GetBytesFromHexString(test, "cipher_text"); |
| + |
| + blink::WebCryptoKey key = ImportSecretKeyFromRaw( |
| + test_key, |
| webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesCbc), |
| blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt); |
| @@ -970,55 +831,51 @@ TEST_F(WebCryptoImplTest, MAYBE(AesCbcSampleSets)) { |
| blink::WebArrayBuffer raw_key; |
| EXPECT_STATUS_SUCCESS(ExportKeyInternal( |
| blink::WebCryptoKeyFormatRaw, key, &raw_key)); |
| - ExpectArrayBufferMatchesHex(test.key, raw_key); |
| - |
| - std::vector<uint8> plain_text = HexStringToBytes(test.plain_text); |
| - std::vector<uint8> iv = HexStringToBytes(test.iv); |
| + ExpectArrayBufferMatches(test_key, raw_key); |
| blink::WebArrayBuffer output; |
| // Test encryption. |
| EXPECT_STATUS( |
| Status::Success(), |
| - EncryptInternal(webcrypto::CreateAesCbcAlgorithm(iv), |
| + EncryptInternal(webcrypto::CreateAesCbcAlgorithm(test_iv), |
| key, |
| - plain_text, |
| + test_plain_text, |
| &output)); |
| - ExpectArrayBufferMatchesHex(test.cipher_text, output); |
| + ExpectArrayBufferMatches(test_cipher_text, output); |
| // Test decryption. |
| - std::vector<uint8> cipher_text = HexStringToBytes(test.cipher_text); |
| EXPECT_STATUS( |
| Status::Success(), |
| - DecryptInternal(webcrypto::CreateAesCbcAlgorithm(iv), |
| + DecryptInternal(webcrypto::CreateAesCbcAlgorithm(test_iv), |
| key, |
| - cipher_text, |
| + test_cipher_text, |
| &output)); |
| - ExpectArrayBufferMatchesHex(test.plain_text, output); |
| + ExpectArrayBufferMatches(test_plain_text, output); |
| const unsigned int kAesCbcBlockSize = 16; |
| // Decrypt with a padding error by stripping the last block. This also ends |
| // up testing decryption over empty cipher text. |
| - if (cipher_text.size() >= kAesCbcBlockSize) { |
| + if (test_cipher_text.size() >= kAesCbcBlockSize) { |
| EXPECT_STATUS( |
| Status::Error(), |
| - DecryptInternal(webcrypto::CreateAesCbcAlgorithm(iv), |
| + DecryptInternal(webcrypto::CreateAesCbcAlgorithm(test_iv), |
| key, |
| - &cipher_text[0], |
| - cipher_text.size() - kAesCbcBlockSize, |
| + &test_cipher_text[0], |
| + test_cipher_text.size() - kAesCbcBlockSize, |
| &output)); |
| } |
| // Decrypt cipher text which is not a multiple of block size by stripping |
| // a few bytes off the cipher text. |
| - if (cipher_text.size() > 3) { |
| + if (test_cipher_text.size() > 3) { |
| EXPECT_STATUS( |
| Status::Error(), |
| - DecryptInternal(webcrypto::CreateAesCbcAlgorithm(iv), |
| + DecryptInternal(webcrypto::CreateAesCbcAlgorithm(test_iv), |
| key, |
| - &cipher_text[0], |
| - cipher_text.size() - 3, |
| + &test_cipher_text[0], |
| + test_cipher_text.size() - 3, |
| &output)); |
| } |
| } |
| @@ -1716,8 +1573,8 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaEsRoundTrip)) { |
| blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| ImportRsaKeyPair( |
| - kPublicKeySpkiDerHex, |
| - kPrivateKeyPkcs8DerHex, |
| + HexStringToBytes(kPublicKeySpkiDerHex), |
| + HexStringToBytes(kPrivateKeyPkcs8DerHex), |
| algorithm, |
| false, |
| blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, |
| @@ -1763,70 +1620,27 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaEsRoundTrip)) { |
| } |
| TEST_F(WebCryptoImplTest, MAYBE(RsaEsKnownAnswer)) { |
| + |
| + scoped_ptr<base::Value> json; |
| + ASSERT_TRUE(ReadJsonTestFile("rsaes.json", &json)); |
|
Ryan Sleevi
2014/01/31 20:53:36
rsa_es
|
| + base::DictionaryValue* test = NULL; |
| + ASSERT_TRUE(json->GetAsDictionary(&test)); |
| + |
| // Because the random data in PKCS1.5 padding makes the encryption output non- |
| // deterministic, we cannot easily do a typical known-answer test for RSA |
| // encryption / decryption. Instead we will take a known-good encrypted |
| // message, decrypt it, re-encrypt it, then decrypt again, verifying that the |
| // original known cleartext is the result. |
| - // The RSA public and private keys used for this test are produced by the |
| - // openssl command line: |
| - // % openssl genrsa -out pair.pem 1024 |
| - // % openssl rsa -in pair.pem -out spki.der -outform DER -pubout |
| - // % openssl pkcs8 -topk8 -inform PEM -outform DER -in pair.pem -out |
| - // pkcs8.der -nocrypt |
| - // % xxd -p spki.der |
| - // % xxd -p pkcs8.der |
| - const std::string rsa_spki_der_hex = |
| - "30819f300d06092a864886f70d010101050003818d0030818902818100a8" |
| - "d30894b93f376f7822229bfd2483e50da944c4ab803ca31979e0f47e70bf" |
| - "683c687c6b3e80f280a237cea3643fd1f7f10f7cc664dbc2ecd45be53e1c" |
| - "9b15a53c37dbdad846c0f8340c472abc7821e4aa7df185867bf38228ac3e" |
| - "cc1d97d3c8b57e21ea6ba57b2bc3814a436e910ee8ab64a0b7743a927e94" |
| - "4d3420401f7dd50203010001"; |
| - const std::string rsa_pkcs8_der_hex = |
| - "30820276020100300d06092a864886f70d0101010500048202603082025c" |
| - "02010002818100a8d30894b93f376f7822229bfd2483e50da944c4ab803c" |
| - "a31979e0f47e70bf683c687c6b3e80f280a237cea3643fd1f7f10f7cc664" |
| - "dbc2ecd45be53e1c9b15a53c37dbdad846c0f8340c472abc7821e4aa7df1" |
| - "85867bf38228ac3ecc1d97d3c8b57e21ea6ba57b2bc3814a436e910ee8ab" |
| - "64a0b7743a927e944d3420401f7dd5020301000102818100896cdffb50a0" |
| - "691bd00ad9696933243a7c5861a64684e8d74b91aed0d76c28234da9303e" |
| - "8c6ea2f89b141a9d5ea9a4ddd3d8eb9503dcf05ba0b1fd76060b281e3ae4" |
| - "b9d497fb5519bdf1127db8ad412d6a722686c78df3e3002acca960c6b2a2" |
| - "42a83ace5410693c03ce3d74cb9c9a7bacc8e271812920d1f53fee9312ef" |
| - "4eb1024100d09c14418ce92af7cc62f7cdc79836d8c6e3d0d33e7229cc11" |
| - "d732cbac75aa4c56c92e409a3ccbe75d4ce63ac5adca33080690782c6371" |
| - "e3628134c3534ca603024100cf2d3206f6deea2f39b70351c51f85436200" |
| - "5aa8f643e49e22486736d536e040dc30a2b4f9be3ab212a88d1891280874" |
| - "b9a170cdeb22eaf61c27c4b082c7d1470240638411a5b3b307ec6e744802" |
| - "c2d4ba556f8bfe72c7b76e790b89bd91ac13f5c9b51d04138d80b3450c1d" |
| - "4337865601bf96748b36c8f627be719f71ac3c70b441024065ce92cfe34e" |
| - "a58bf173a2b8f3024b4d5282540ac581957db3e11a7f528535ec098808dc" |
| - "a0013ffcb3b88a25716757c86c540e07d2ad8502cdd129118822c30f0240" |
| - "420a4983040e9db46eb29f1315a0d7b41cf60428f7460fce748e9a1a7d22" |
| - "d7390fa328948e7e9d1724401374e99d45eb41474781201378a4330e8e80" |
| - "8ce63551"; |
| - |
| - // Similarly, the cleartext and public key encrypted ciphertext for this test |
| - // are also produced by openssl. Note that since we are using a 1024-bit key, |
| - // the cleartext size must be less than or equal to 117 bytes (modulusLength / |
| - // 8 - 11). |
| - // % openssl rand -out cleartext.bin 64 |
| - // % openssl rsautl -encrypt -inkey spki.der -keyform DER -pubin -in |
| - // cleartext.bin -out ciphertext.bin |
| - // % xxd -p cleartext.bin |
| - // % xxd -p ciphertext.bin |
| - const std::string cleartext_hex = |
| - "ec358ed141c45d7e03d4c6338aebad718e8bcbbf8f8ee6f8d9f4b9ef06d8" |
| - "84739a398c6bcbc688418b2ff64761dc0ccd40e7d52bed03e06946d0957a" |
| - "eef9e822"; |
| - const std::string ciphertext_hex = |
| - "6106441c2b7a4b1a16260ed1ae4fe6135247345dc8e674754bbda6588c6c" |
| - "0d95a3d4d26bb34cdbcbe327723e80343bd7a15cd4c91c3a44e6cb9c6cd6" |
| - "7ad2e8bf41523188d9b36dc364a838642dcbc2c25e85dfb2106ba47578ca" |
| - "3bbf8915055aea4fa7c3cbfdfbcc163f04c234fb6d847f39bab9612ecbee" |
| - "04626e945c3ccf42"; |
| + const std::vector<uint8> rsa_spki_der = |
| + GetBytesFromHexString(test, "rsa_spki_der"); |
| + |
| + const std::vector<uint8> rsa_pkcs8_der = |
| + GetBytesFromHexString(test, "rsa_pkcs8_der"); |
| + const std::vector<uint8> ciphertext = |
| + GetBytesFromHexString(test, "ciphertext"); |
| + const std::vector<uint8> cleartext = |
| + GetBytesFromHexString(test, "cleartext"); |
| // Import the key pair. |
| blink::WebCryptoAlgorithm algorithm = |
| @@ -1834,8 +1648,8 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaEsKnownAnswer)) { |
| blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| ImportRsaKeyPair( |
| - rsa_spki_der_hex, |
| - rsa_pkcs8_der_hex, |
| + rsa_spki_der, |
| + rsa_pkcs8_der, |
| algorithm, |
| false, |
| blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, |
| @@ -1848,10 +1662,10 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaEsKnownAnswer)) { |
| ASSERT_STATUS_SUCCESS(DecryptInternal( |
| algorithm, |
| private_key, |
| - HexStringToBytes(ciphertext_hex), |
| + ciphertext, |
| &decrypted_data)); |
| EXPECT_FALSE(decrypted_data.isNull()); |
| - ExpectArrayBufferMatchesHex(cleartext_hex, decrypted_data); |
| + ExpectArrayBufferMatches(cleartext, decrypted_data); |
| // Encrypt this decrypted data with the public key. |
| blink::WebArrayBuffer encrypted_data; |
| @@ -1873,7 +1687,7 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaEsKnownAnswer)) { |
| encrypted_data.byteLength(), |
| &decrypted_data)); |
| EXPECT_FALSE(decrypted_data.isNull()); |
| - ExpectArrayBufferMatchesHex(cleartext_hex, decrypted_data); |
| + ExpectArrayBufferMatches(cleartext, decrypted_data); |
| } |
| TEST_F(WebCryptoImplTest, MAYBE(RsaEsFailures)) { |
| @@ -1883,8 +1697,8 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaEsFailures)) { |
| blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| ImportRsaKeyPair( |
| - kPublicKeySpkiDerHex, |
| - kPrivateKeyPkcs8DerHex, |
| + HexStringToBytes(kPublicKeySpkiDerHex), |
| + HexStringToBytes(kPrivateKeyPkcs8DerHex), |
| algorithm, |
| false, |
| blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt, |
| @@ -1954,8 +1768,8 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaSsaSignVerifyFailures)) { |
| blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| ImportRsaKeyPair( |
| - kPublicKeySpkiDerHex, |
| - kPrivateKeyPkcs8DerHex, |
| + HexStringToBytes(kPublicKeySpkiDerHex), |
| + HexStringToBytes(kPrivateKeyPkcs8DerHex), |
| algorithm, |
| false, |
| blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, |
| @@ -2078,202 +1892,8 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaSsaSignVerifyFailures)) { |
| } |
| TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) { |
| - // Use the NIST test vectors from Example 1 of |
| - // ftp://ftp.rsa.com/pub/rsalabs/tmp/pkcs1v15sign-vectors.txt |
| - // These vectors are known answers for RSA PKCS#1 v1.5 Signature with a SHA-1 |
| - // digest, using a predefined key pair. |
| - |
| - struct TestCase { |
| - const std::string message_hex; |
| - const std::string signature_hex; |
| - }; |
| - |
| - // The following data are the input messages and corresponding computed RSA |
| - // PKCS#1 v1.5 signatures from the NIST link above. |
| - const TestCase kTests[] = { |
| - // PKCS#1 v1.5 Signature Example 1.1 |
| - {"cdc87da223d786df3b45e0bbbc721326d1ee2af806cc315475cc6f0d9c66e1b6" |
| - "2371d45ce2392e1ac92844c310102f156a0d8d52c1f4c40ba3aa65095786cb76" |
| - "9757a6563ba958fed0bcc984e8b517a3d5f515b23b8a41e74aa867693f90dfb0" |
| - "61a6e86dfaaee64472c00e5f20945729cbebe77f06ce78e08f4098fba41f9d61" |
| - "93c0317e8b60d4b6084acb42d29e3808a3bc372d85e331170fcbf7cc72d0b71c" |
| - "296648b3a4d10f416295d0807aa625cab2744fd9ea8fd223c42537029828bd16" |
| - "be02546f130fd2e33b936d2676e08aed1b73318b750a0167d0", |
| - "6bc3a06656842930a247e30d5864b4d819236ba7c68965862ad7dbc4e24af28e" |
| - "86bb531f03358be5fb74777c6086f850caef893f0d6fcc2d0c91ec013693b4ea" |
| - "00b80cd49aac4ecb5f8911afe539ada4a8f3823d1d13e472d1490547c659c761" |
| - "7f3d24087ddb6f2b72096167fc097cab18e9a458fcb634cdce8ee35894c484d7"}, |
| - // PKCS#1 v1.5 Signature Example 1.2 |
| - {"851384cdfe819c22ed6c4ccb30daeb5cf059bc8e1166b7e3530c4c233e2b5f8f" |
| - "71a1cca582d43ecc72b1bca16dfc7013226b9e", |
| - "84fd2ce734ec1da828d0f15bf49a8707c15d05948136de537a3db421384167c8" |
| - "6fae022587ee9e137daee754738262932d271c744c6d3a189ad4311bdb020492" |
| - "e322fbddc40406ea860d4e8ea2a4084aa98b9622a446756fdb740ddb3d91db76" |
| - "70e211661bbf8709b11c08a70771422d1a12def29f0688a192aebd89e0f896f8"}, |
| - // PKCS#1 v1.5 Signature Example1.3 |
| - {"a4b159941761c40c6a82f2b80d1b94f5aa2654fd17e12d588864679b54cd04ef" |
| - "8bd03012be8dc37f4b83af7963faff0dfa225477437c48017ff2be8191cf3955" |
| - "fc07356eab3f322f7f620e21d254e5db4324279fe067e0910e2e81ca2cab31c7" |
| - "45e67a54058eb50d993cdb9ed0b4d029c06d21a94ca661c3ce27fae1d6cb20f4" |
| - "564d66ce4767583d0e5f060215b59017be85ea848939127bd8c9c4d47b51056c" |
| - "031cf336f17c9980f3b8f5b9b6878e8b797aa43b882684333e17893fe9caa6aa" |
| - "299f7ed1a18ee2c54864b7b2b99b72618fb02574d139ef50f019c9eef4169713" |
| - "38e7d470", |
| - "0b1f2e5180e5c7b4b5e672929f664c4896e50c35134b6de4d5a934252a3a245f" |
| - "f48340920e1034b7d5a5b524eb0e1cf12befef49b27b732d2c19e1c43217d6e1" |
| - "417381111a1d36de6375cf455b3c9812639dbc27600c751994fb61799ecf7da6" |
| - "bcf51540afd0174db4033188556675b1d763360af46feeca5b60f882829ee7b2"}, |
| - // PKCS#1 v1.5 Signature Example 1.4 |
| - {"bc656747fa9eafb3f0", |
| - "45607ad611cf5747a41ac94d0ffec878bdaf63f6b57a4b088bf36e34e109f840" |
| - "f24b742ada16102dabf951cbc44f8982e94ed4cd09448d20ec0efa73545f80b6" |
| - "5406bed6194a61c340b4ad1568cbb75851049f11af1734964076e02029aee200" |
| - "e40e80be0f4361f69841c4f92a4450a2286d43289b405554c54d25c6ecb584f4"}, |
| - // PKCS#1 v1.5 Signature Example 1.5 |
| - {"b45581547e5427770c768e8b82b75564e0ea4e9c32594d6bff706544de0a8776" |
| - "c7a80b4576550eee1b2acabc7e8b7d3ef7bb5b03e462c11047eadd00629ae575" |
| - "480ac1470fe046f13a2bf5af17921dc4b0aa8b02bee6334911651d7f8525d10f" |
| - "32b51d33be520d3ddf5a709955a3dfe78283b9e0ab54046d150c177f037fdccc" |
| - "5be4ea5f68b5e5a38c9d7edcccc4975f455a6909b4", |
| - "54be9d90877515f450279c15b5f61ad6f15ecc95f18cbed82b65b1667a575809" |
| - "587994668044f3bc2ae7f884501f64f0b43f588cfa205a6ab704328c2d4ab92a" |
| - "7ae13440614d3e085f401da9ad28e2105e4a0edb681a6424df047388ce051ee9" |
| - "df7bc2163fe347520ad51ccd518064383e741acad3cbdc2cb5a7c68e868464c2"}, |
| - // PKCS#1 v1.5 Signature Example 1.6 |
| - {"10aae9a0ab0b595d0841207b700d48d75faedde3b775cd6b4cc88ae06e4694ec" |
| - "74ba18f8520d4f5ea69cbbe7cc2beba43efdc10215ac4eb32dc302a1f53dc6c4" |
| - "352267e7936cfebf7c8d67035784a3909fa859c7b7b59b8e39c5c2349f1886b7" |
| - "05a30267d402f7486ab4f58cad5d69adb17ab8cd0ce1caf5025af4ae24b1fb87" |
| - "94c6070cc09a51e2f9911311e3877d0044c71c57a993395008806b723ac38373" |
| - "d395481818528c1e7053739282053529510e935cd0fa77b8fa53cc2d474bd4fb" |
| - "3cc5c672d6ffdc90a00f9848712c4bcfe46c60573659b11e6457e861f0f604b6" |
| - "138d144f8ce4e2da73", |
| - "0e6ff63a856b9cbd5dbe423183122047dd39d6f76d1b2310e546fe9ee73b33ef" |
| - "a7c78f9474455c9e5b88cb383aafc3698668e7b7a59a9cbb5b0897b6c5afb7f8" |
| - "bac4b924e98d760a15fc43d2814ab2d5187f79bed9915a93397ebc22a7677506" |
| - "a02e076d3ffdc0441dbd4db00453dc28d830e0573f77b817b505c38b4a4bb5d0"}, |
| - // PKCS#1 v1.5 Signature Example 1.7 |
| - {"efb5da1b4d1e6d9a5dff92d0184da7e31f877d1281ddda625664869e8379e67a" |
| - "d3b75eae74a580e9827abd6eb7a002cb5411f5266797768fb8e95ae40e3e8b34" |
| - "66f5ab15d69553952939ec23e61d58497fac76aa1c0bb5a3cb4a54383587c7bb" |
| - "78d13eefda205443e6ce4365802df55c64713497984e7ca96722b3edf84d56", |
| - "8385d58533a995f72df262b70f40b391ddf515f464b9d2cc2d66398fc05689d8" |
| - "11632946d62eabdca7a31fcf6cd6c981d28bbc29083e4a6d5b2b378ca4e540f0" |
| - "60b96d53ad2693f82178b94e2e2f86b9accfa02025107e062ab7080175684501" |
| - "028f676461d81c008fe4750671649970878fc175cf98e96b2ecbf6874d77dacb"}, |
| - // PKCS#1 v1.5 Signature Example 1.8 |
| - {"53bb58ce42f1984940552657233b14969af365c0a561a4132af18af39432280e" |
| - "3e437082434b19231837184f02cf2b2e726bebf74d7ae3256d8b72f3eafdb134" |
| - "d33de06f2991d299d59f5468d43b9958d6a968f5969edbbc6e7185cbc716c7c9" |
| - "45dafa9cc71ddfaaa01094a452ddf5e2407320400bf05ea9729cafbf0600e788" |
| - "07ef9462e3fde32ed7d981a56f4751ef64fb4549910ecc911d728053b3994300" |
| - "4740e6f5821fe8d75c0617bf2c6b24bbfc34013fc95f0dedf5ba297f504fb833" |
| - "da2a436d1d8ff1cc5193e2a64389fced918e7feb6716330f66801db9497549cf" |
| - "1d3bd97cf1bc6255", |
| - "8e1f3d26ec7c6bbb8c54c5d25f3120587803af6d3c2b99a37ced6a3657d4ae54" |
| - "266f63fffde660c866d65d0ab0589e1d12d9ce6054b05c8668ae127171ccaae7" |
| - "f1cd409677f52157b6123ab227f27a00966d1439b42a32169d1070394026fc8b" |
| - "c93545b1ac252d0f7da751c02e33a47831fbd71514c2bbbd3adb6740c0fd68ad"}, |
| - // PKCS#1 v1.5 Signature Example 1.9 |
| - {"27cadc698450945f204ec3cf8c6cbd8ceb4cc0cbe312274fa96b04deac855160" |
| - "c0e04e4ac5d38210c27c", |
| - "7b63f9223356f35f6117f68c8f8220034fc2384ab5dc6904141f139314d6ee89" |
| - "f54ec6ffd18c413a23c5931c7fbb13c555ccfd590e0eaa853c8c94d2520cd425" |
| - "0d9a05a193b65dc749b82478af0156ee1de55ddad33ec1f0099cad6c891a3617" |
| - "c7393d05fbfbbb00528a001df0b204ebdf1a341090dea89f870a877458427f7b"}, |
| - // PKCS#1 v1.5 Signature Example 1.10 |
| - {"716407e901b9ef92d761b013fd13eb7ad72aed", |
| - "2a22dbe3774d5b297201b55a0f17f42dce63b7845cb325cfe951d0badb5c5a14" |
| - "472143d896c86cc339f83671164215abc97862f2151654e75a3b357c37311b3d" |
| - "7268cab540202e23bee52736f2cd86cce0c7dbde95e1c600a47395dc5eb0a472" |
| - "153fbc4fb21b643e0c04ae14dd37e97e617a7567c89652219781001ba6f83298"}, |
| - // PKCS#1 v1.5 Signature Example 1.11 |
| - {"46c24e4103001629c712dd4ce8d747ee595d6c744ccc4f71347d9b8abf49d1b8" |
| - "fb2ef91b95dc899d4c0e3d2997e638f4cf3f68e0498de5aabd13f0dfe02ff26b" |
| - "a4379104e78ffa95ffbd15067ef8cbd7eb7860fecc71abe13d5c720a66851f2d" |
| - "efd4e795054d7bec024bb422a46a7368b56d95b47aebafbeadd612812593a70d" |
| - "b9f96d451ee15edb299308d777f4bb68ed3377c32156b41b7a9c92a14c8b8114" |
| - "4399c56a5a432f4f770aa97da8415d0bda2e813206031e70620031c881d616bf" |
| - "fd5f03bf147c1e73766c26246208", |
| - "12235b0b406126d9d260d447e923a11051fb243079f446fd73a70181d53634d7" |
| - "a0968e4ee27777eda63f6e4a3a91ad5985998a4848da59ce697b24bb332fa2ad" |
| - "9ce462ca4affdc21dab908e8ce15af6eb9105b1abcf39142aa17b34c4c092386" |
| - "a7abbfe028afdbebc14f2ce26fbee5edeca11502d39a6b7403154843d98a62a7"}, |
| - // PKCS#1 v1.5 Signature Example 1.12 |
| - {"bc99a932aa16d622bfff79c50b4c42358673261129e28d6a918ff1b0f1c4f46a" |
| - "d8afa98b0ca0f56f967975b0a29be882e93b6cd3fc33e1faef72e52b2ae0a3f1" |
| - "2024506e25690e902e782982145556532284cf505789738f4da31fa1333d3af8" |
| - "62b2ba6b6ce7ab4cce6aba", |
| - "872ec5ad4f1846256f17e9936ac50e43e9963ea8c1e76f15879b7874d77d122a" |
| - "609dc8c561145b94bf4ffdffdeb17e6e76ffc6c10c0747f5e37a9f434f5609e7" |
| - "9da5250215a457afdf12c6507cc1551f54a28010595826a2c9b97fa0aa851cc6" |
| - "8b705d7a06d720ba027e4a1c0b019500fb63b78071684dcfa9772700b982dc66"}, |
| - // PKCS#1 v1.5 Signature Example 1.13 |
| - {"731e172ac063992c5b11ba170dfb23bb000d47ba195329cf278061037381514c" |
| - "146064c5285db130dd5bae98b772225950eab05d3ea996f6fffb9a8c8622913f" |
| - "279914c89ada4f3dd77666a868bfcbff2b95b7daf453d4e2c9d75beee7f8e709" |
| - "05e4066a4f73aecc67f956aa5a3292b8488c917d317cfdc86253e690381e15ab", |
| - "76204eacc1d63ec1d6ad5bd0692e1a2f686df6e64ca945c77a824de212efa6d9" |
| - "782d81b4591403ff4020620298c07ebd3a8a61c5bf4dad62cbfc4ae6a03937be" |
| - "4b49a216d570fc6e81872937876e27bd19cf601effc30ddca573c9d56cd4569b" |
| - "db4851c450c42cb21e738cdd61027b8be5e9b410fc46aa3f29e4be9e64451346"}, |
| - // PKCS#1 v1.5 Signature Example 1.14 |
| - {"0211382683a74d8d2a2cb6a06550563be1c26ca62821e4ff163b720464fc3a28" |
| - "d91bedddc62749a5538eaf41fbe0c82a77e06ad99383c9e985ffb8a93fd4d7c5" |
| - "8db51ad91ba461d69a8fd7ddabe2496757a0c49122c1a79a85cc0553e8214d03" |
| - "6dfe0185efa0d05860c612fa0882c82d246e5830a67355dff18a2c36b732f988" |
| - "cfedc562264c6254b40fcabb97b760947568dcd6a17cda6ee8855bddbab93702" |
| - "471aa0cfb1bed2e13118eba1175b73c96253c108d0b2aba05ab8e17e84392e20" |
| - "085f47404d8365527dc3fb8f2bb48a50038e71361ccf973407", |
| - "525500918331f1042eae0c5c2054aa7f92deb26991b5796634f229daf9b49eb2" |
| - "054d87319f3cfa9b466bd075ef6699aea4bd4a195a1c52968b5e2b75e092d846" |
| - "ea1b5cc27905a8e1d5e5de0edfdb21391ebb951864ebd9f0b0ec35b654287136" |
| - "0a317b7ef13ae06af684e38e21b1e19bc7298e5d6fe0013a164bfa25d3e7313d"}, |
| - // PKCS#1 v1.5 Signature Example 1.15 |
| - {"fc6b700d22583388ab2f8dafcaf1a05620698020da4bae44dafbd0877b501250" |
| - "6dc3181d5c66bf023f348b41fd9f94795ab96452a4219f2d39d72af359cf1956" |
| - "51c7", |
| - "4452a6cc2626b01e95ab306df0d0cc7484fbab3c22e9703283567f66eadc248d" |
| - "bda58fce7dd0c70cce3f150fca4b369dff3b6237e2b16281ab55b53fb13089c8" |
| - "5cd265056b3d62a88bfc2135b16791f7fbcab9fd2dc33becb617be419d2c0461" |
| - "42a4d47b338314552edd4b6fe9ce1104ecec4a9958d7331e930fc09bf08a6e64"}, |
| - // PKCS#1 v1.5 Signature Example 1.16 |
| - {"13ba086d709cfa5fedaa557a89181a6140f2300ed6d7c3febb6cf68abebcbc67" |
| - "8f2bca3dc2330295eec45bb1c4075f3ada987eae88b39c51606cb80429e649d9" |
| - "8acc8441b1f8897db86c5a4ce0abf28b1b81dca3667697b850696b74a5ebd85d" |
| - "ec56c90f8abe513efa857853720be319607921bca947522cd8fac8cace5b827c" |
| - "3e5a129e7ee57f6b84932f14141ac4274e8cbb46e6912b0d3e2177d499d1840c" |
| - "d47d4d7ae0b4cdc4d3", |
| - "1f3b5a87db72a2c97bb3eff2a65a301268eacd89f42abc1098c1f2de77b0832a" |
| - "65d7815feb35070063f221bb3453bd434386c9a3fde18e3ca1687fb649e86c51" |
| - "d658619dde5debb86fe15491ff77ab748373f1be508880d66ea81e870e91cdf1" |
| - "704875c17f0b10103188bc64eef5a3551b414c733670215b1a22702562581ab1"}, |
| - // PKCS#1 v1.5 Signature Example 1.17 |
| - {"eb1e5935", |
| - "370cb9839ae6074f84b2acd6e6f6b7921b4b523463757f6446716140c4e6c0e7" |
| - "5bec6ad0197ebfa86bf46d094f5f6cd36dca3a5cc73c8bbb70e2c7c9ab5d964e" |
| - "c8e3dfde481b4a1beffd01b4ad15b31ae7aebb9b70344a9411083165fdf9c375" |
| - "4bbb8b94dd34bd4813dfada1f6937de4267d5597ca09a31e83d7f1a79dd19b5e"}, |
| - // PKCS#1 v1.5 Signature Example 1.18 |
| - {"6346b153e889c8228209630071c8a57783f368760b8eb908cfc2b276", |
| - "2479c975c5b1ae4c4e940f473a9045b8bf5b0bfca78ec29a38dfbedc8a749b7a" |
| - "2692f7c52d5bc7c831c7232372a00fed3b6b49e760ec99e074ff2eead5134e83" |
| - "05725dfa39212b84bd4b8d80bc8bc17a512823a3beb18fc08e45ed19c26c8177" |
| - "07d67fb05832ef1f12a33e90cd93b8a780319e2963ca25a2af7b09ad8f595c21"}, |
| - // PKCS#1 v1.5 Signature Example 1.19 |
| - {"64702db9f825a0f3abc361974659f5e9d30c3aa4f56feac69050c72905e77fe0" |
| - "c22f88a378c21fcf45fe8a5c717302093929", |
| - "152f3451c858d69594e6567dfb31291c1ee7860b9d15ebd5a5edd276ac3e6f7a" |
| - "8d1480e42b3381d2be023acf7ebbdb28de3d2163ae44259c6df98c335d045b61" |
| - "dac9dba9dbbb4e6ab4a083cd76b580cbe472206a1a9fd60680ceea1a570a29b0" |
| - "881c775eaef5525d6d2f344c28837d0aca422bbb0f1aba8f6861ae18bd73fe44"}, |
| - // PKCS#1 v1.5 Signature Example 1.20 |
| - {"941921de4a1c9c1618d6f3ca3c179f6e29bae6ddf9a6a564f929e3ce82cf3265" |
| - "d7837d5e692be8dcc9e86c", |
| - "7076c287fc6fff2b20537435e5a3107ce4da10716186d01539413e609d27d1da" |
| - "6fd952c61f4bab91c045fa4f8683ecc4f8dde74227f773cff3d96db84718c494" |
| - "4b06affeba94b725f1b07d3928b2490a85c2f1abf492a9177a7cd2ea0c966875" |
| - "6f825bbec900fa8ac3824e114387ef573780ca334882387b94e5aad7a27a28dc"}}; |
| + scoped_ptr<base::ListValue> tests; |
| + ASSERT_TRUE(ReadJsonTestFileToList("pkcs1v15_sign.json", &tests)); |
| // Import the key pair. |
| blink::WebCryptoAlgorithm algorithm = CreateRsaAlgorithmWithInnerHash( |
| @@ -2282,8 +1902,8 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) { |
| blink::WebCryptoKey public_key = blink::WebCryptoKey::createNull(); |
| blink::WebCryptoKey private_key = blink::WebCryptoKey::createNull(); |
| ImportRsaKeyPair( |
| - kPublicKeySpkiDerHex, |
| - kPrivateKeyPkcs8DerHex, |
| + HexStringToBytes(kPublicKeySpkiDerHex), |
| + HexStringToBytes(kPrivateKeyPkcs8DerHex), |
| algorithm, |
| false, |
| blink::WebCryptoKeyUsageSign | blink::WebCryptoKeyUsageVerify, |
| @@ -2292,22 +1912,28 @@ TEST_F(WebCryptoImplTest, MAYBE(RsaSignVerifyKnownAnswer)) { |
| // Validate the signatures are computed and verified as expected. |
| blink::WebArrayBuffer signature; |
| - for (size_t idx = 0; idx < ARRAYSIZE_UNSAFE(kTests); ++idx) { |
| + for (size_t idx = 0; idx < tests->GetSize(); ++idx) { |
|
Ryan Sleevi
2014/01/31 20:53:36
naming: idx -> index? matches consistency with the
eroman
2014/01/31 22:55:11
Done (test_index throughout)
|
| SCOPED_TRACE(idx); |
| - const TestCase& test = kTests[idx]; |
| - const std::vector<uint8> message = HexStringToBytes(test.message_hex); |
| + |
| + base::DictionaryValue* test; |
| + ASSERT_TRUE(tests->GetDictionary(idx, &test)); |
| + |
| + std::vector<uint8> test_message = |
| + GetBytesFromHexString(test, "message_hex"); |
| + std::vector<uint8> test_signature = |
| + GetBytesFromHexString(test, "signature_hex"); |
| signature.reset(); |
| ASSERT_STATUS_SUCCESS( |
| - SignInternal(algorithm, private_key, message, &signature)); |
| - ExpectArrayBufferMatchesHex(test.signature_hex, signature); |
| + SignInternal(algorithm, private_key, test_message, &signature)); |
| + ExpectArrayBufferMatches(test_signature, signature); |
| bool is_match = false; |
| ASSERT_STATUS_SUCCESS(VerifySignatureInternal( |
| algorithm, |
| public_key, |
| - HexStringToBytes(test.signature_hex), |
| - message, |
| + test_signature, |
| + test_message, |
| &is_match)); |
| EXPECT_TRUE(is_match); |
| } |
| @@ -2411,109 +2037,29 @@ TEST_F(WebCryptoImplTest, MAYBE(AesGcmSampleSets)) { |
| return; |
| } |
| - struct TestCase { |
| - const char* key; |
| - const char* iv; |
| - const char* plain_text; |
| - const char* cipher_text; |
| - const char* additional_data; |
| - const char* authentication_tag; |
| - }; |
| - |
| - // These tests come from the NIST GCM test vectors: |
| - // http://csrc.nist.gov/groups/STM/cavp/documents/mac/gcmtestvectors.zip |
| - // |
| - // Both encryption and decryption are expected to work. |
| - TestCase kTests[] = { |
| - // [Keylen = 128] |
| - // [IVlen = 96] |
| - // [PTlen = 0] |
| - // [AADlen = 0] |
| - // [Taglen = 128] |
| - { |
| - // key |
| - "cf063a34d4a9a76c2c86787d3f96db71", |
| - // iv |
| - "113b9785971864c83b01c787", |
| - // plain_text |
| - "", |
| - // cipher_text |
| - "", |
| - // additional_data |
| - "", |
| - // authentication_tag |
| - "72ac8493e3a5228b5d130a69d2510e42", |
| - }, |
| - |
| - // [Keylen = 128] |
| - // [IVlen = 96] |
| - // [PTlen = 0] |
| - // [AADlen = 128] |
| - // [Taglen = 120] |
| - { |
| - // key |
| - "6dfa1a07c14f978020ace450ad663d18", |
| - // iv |
| - "34edfa462a14c6969a680ec1", |
| - // plain_text |
| - "", |
| - // cipher_text |
| - "", |
| - // additional_data |
| - "2a35c7f5f8578e919a581c60500c04f6", |
| - // authentication_tag |
| - "751f3098d59cf4ea1d2fb0853bde1c" |
| - }, |
| - |
| - // [Keylen = 128] |
| - // [IVlen = 96] |
| - // [PTlen = 128] |
| - // [AADlen = 128] |
| - // [Taglen = 112] |
| - { |
| - // key |
| - "ed6cd876ceba555706674445c229c12d", |
| - // iv |
| - "92ecbf74b765bc486383ca2e", |
| - // plain_text |
| - "bfaaaea3880d72d4378561e2597a9b35", |
| - // cipher_text |
| - "bdd2ed6c66fa087dce617d7fd1ff6d93", |
| - // additional_data |
| - "95bd10d77dbe0e87fb34217f1a2e5efe", |
| - // authentication_tag |
| - "ba82e49c55a22ed02ca67da4ec6f" |
| - }, |
| - |
| - // [Keylen = 192] |
| - // [IVlen = 96] |
| - // [PTlen = 128] |
| - // [AADlen = 384] |
| - // [Taglen = 112] |
| - { |
| - // key |
| - "ae7972c025d7f2ca3dd37dcc3d41c506671765087c6b61b8", |
| - // iv |
| - "984c1379e6ba961c828d792d", |
| - // plain_text |
| - "d30b02c343487105219d6fa080acc743", |
| - // cipher_text |
| - "c4489fa64a6edf80e7e6a3b8855bc37c", |
| - // additional_data |
| - "edd8f630f9bbc31b0acf122998f15589d6e6e3e1a3ec89e0c6a6ece751610e" |
| - "bbf57fdfb9d82028ff1d9faebe37a268c1", |
| - // authentication_tag |
| - "772ee7de0f91a981c36c93a35c88" |
| - } |
| - }; |
| + scoped_ptr<base::ListValue> tests; |
| + ASSERT_TRUE(ReadJsonTestFileToList("aesgcm.json", &tests)); |
|
Ryan Sleevi
2014/01/31 20:53:36
aes_gcm
|
| // Note that WebCrypto appends the authentication tag to the ciphertext. |
| - for (size_t index = 0; index < ARRAYSIZE_UNSAFE(kTests); index++) { |
| + for (size_t index = 0; index < tests->GetSize(); index++) { |
|
Ryan Sleevi
2014/01/31 20:53:36
++index
eroman
2014/01/31 22:55:11
Done.
|
| SCOPED_TRACE(index); |
| - const TestCase& test = kTests[index]; |
| + base::DictionaryValue* test; |
| + ASSERT_TRUE(tests->GetDictionary(index, &test)); |
| + |
| + const std::vector<uint8> test_key = GetBytesFromHexString(test, "key"); |
| + const std::vector<uint8> test_iv = GetBytesFromHexString(test, "iv"); |
| + const std::vector<uint8> test_additional_data = |
| + GetBytesFromHexString(test, "additional_data"); |
| + const std::vector<uint8> test_plain_text = |
| + GetBytesFromHexString(test, "plain_text"); |
| + const std::vector<uint8> test_authentication_tag = |
| + GetBytesFromHexString(test, "authentication_tag"); |
| + const unsigned int test_tag_size_bits = test_authentication_tag.size() * 8; |
| + const std::vector<uint8> test_cipher_text = |
| + GetBytesFromHexString(test, "cipher_text"); |
| - blink::WebCryptoKey key = ImportSecretKeyFromRawHexString( |
| - test.key, |
| + blink::WebCryptoKey key = ImportSecretKeyFromRaw( |
| + test_key, |
| webcrypto::CreateAlgorithm(blink::WebCryptoAlgorithmIdAesGcm), |
| blink::WebCryptoKeyUsageEncrypt | blink::WebCryptoKeyUsageDecrypt); |
| @@ -2521,18 +2067,7 @@ TEST_F(WebCryptoImplTest, MAYBE(AesGcmSampleSets)) { |
| blink::WebArrayBuffer raw_key; |
| EXPECT_STATUS_SUCCESS(ExportKeyInternal( |
| blink::WebCryptoKeyFormatRaw, key, &raw_key)); |
| - ExpectArrayBufferMatchesHex(test.key, raw_key); |
| - |
| - const std::vector<uint8> test_iv = HexStringToBytes(test.iv); |
| - const std::vector<uint8> test_additional_data = |
| - HexStringToBytes(test.additional_data); |
| - const std::vector<uint8> test_plain_text = |
| - HexStringToBytes(test.plain_text); |
| - const std::vector<uint8> test_authentication_tag = |
| - HexStringToBytes(test.authentication_tag); |
| - const unsigned int test_tag_size_bits = test_authentication_tag.size() * 8; |
| - const std::vector<uint8> test_cipher_text = |
| - HexStringToBytes(test.cipher_text); |
| + ExpectArrayBufferMatches(test_key, raw_key); |
| // Test encryption. |
| std::vector<uint8> cipher_text; |
| @@ -2541,15 +2076,15 @@ TEST_F(WebCryptoImplTest, MAYBE(AesGcmSampleSets)) { |
| test_tag_size_bits, test_plain_text, |
| &cipher_text, &authentication_tag)); |
| - ExpectVectorMatchesHex(test.cipher_text, cipher_text); |
| - ExpectVectorMatchesHex(test.authentication_tag, authentication_tag); |
| + ExpectVectorMatches(test_cipher_text, cipher_text); |
| + ExpectVectorMatches(test_authentication_tag, authentication_tag); |
| // Test decryption. |
| blink::WebArrayBuffer plain_text; |
| EXPECT_STATUS_SUCCESS(AesGcmDecrypt(key, test_iv, test_additional_data, |
| test_tag_size_bits, test_cipher_text, |
| test_authentication_tag, &plain_text)); |
| - ExpectArrayBufferMatchesHex(test.plain_text, plain_text); |
| + ExpectArrayBufferMatches(test_plain_text, plain_text); |
| // Decryption should fail if any of the inputs are tampered with. |
| EXPECT_STATUS(Status::Error(), |