OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/child/webcrypto/shared_crypto.h" | 5 #include "content/child/webcrypto/shared_crypto.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
709 std::vector<uint8> test_input = GetBytesFromHexString(test, "input"); | 709 std::vector<uint8> test_input = GetBytesFromHexString(test, "input"); |
710 std::vector<uint8> test_output = GetBytesFromHexString(test, "output"); | 710 std::vector<uint8> test_output = GetBytesFromHexString(test, "output"); |
711 | 711 |
712 blink::WebArrayBuffer output; | 712 blink::WebArrayBuffer output; |
713 ASSERT_STATUS_SUCCESS( | 713 ASSERT_STATUS_SUCCESS( |
714 Digest(test_algorithm, CryptoData(test_input), &output)); | 714 Digest(test_algorithm, CryptoData(test_input), &output)); |
715 EXPECT_TRUE(ArrayBufferMatches(test_output, output)); | 715 EXPECT_TRUE(ArrayBufferMatches(test_output, output)); |
716 } | 716 } |
717 } | 717 } |
718 | 718 |
| 719 TEST_F(SharedCryptoTest, DigestSampleSetsInChunks) { |
| 720 scoped_ptr<base::ListValue> tests; |
| 721 ASSERT_TRUE(ReadJsonTestFileToList("digest.json", &tests)); |
| 722 |
| 723 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { |
| 724 SCOPED_TRACE(test_index); |
| 725 base::DictionaryValue* test; |
| 726 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); |
| 727 |
| 728 blink::WebCryptoAlgorithm test_algorithm = |
| 729 GetDigestAlgorithm(test, "algorithm"); |
| 730 std::vector<uint8> test_input = GetBytesFromHexString(test, "input"); |
| 731 std::vector<uint8> test_output = GetBytesFromHexString(test, "output"); |
| 732 |
| 733 // Test the chunk version of the digest functions. Test with 129 byte chunks |
| 734 // because the SHA-512 chunk size is 128 bytes. |
| 735 unsigned char* output; |
| 736 unsigned int output_length; |
| 737 static const size_t kChunkSizeBytes = 129; |
| 738 size_t length = test_input.size(); |
| 739 scoped_ptr<blink::WebCryptoDigestor> digestor( |
| 740 CreateDigestor(test_algorithm.id())); |
| 741 std::vector<uint8>::iterator begin = test_input.begin(); |
| 742 size_t chunk_index = 0; |
| 743 while (begin != test_input.end()) { |
| 744 size_t chunk_length = std::min(kChunkSizeBytes, length - chunk_index); |
| 745 std::vector<uint8> chunk(begin, begin + chunk_length); |
| 746 ASSERT_TRUE(chunk.size() > 0); |
| 747 EXPECT_TRUE(digestor->consume(&chunk.front(), chunk.size())); |
| 748 chunk_index = chunk_index + chunk_length; |
| 749 begin = begin + chunk_length; |
| 750 } |
| 751 EXPECT_TRUE(digestor->finish(output, output_length)); |
| 752 ExpectVectorMatches(test_output, |
| 753 std::vector<uint8>(output, output + output_length)); |
| 754 } |
| 755 } |
| 756 |
719 TEST_F(SharedCryptoTest, HMACSampleSets) { | 757 TEST_F(SharedCryptoTest, HMACSampleSets) { |
720 scoped_ptr<base::ListValue> tests; | 758 scoped_ptr<base::ListValue> tests; |
721 ASSERT_TRUE(ReadJsonTestFileToList("hmac.json", &tests)); | 759 ASSERT_TRUE(ReadJsonTestFileToList("hmac.json", &tests)); |
722 // TODO(padolph): Missing known answer tests for HMAC SHA384, and SHA512. | 760 // TODO(padolph): Missing known answer tests for HMAC SHA384, and SHA512. |
723 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { | 761 for (size_t test_index = 0; test_index < tests->GetSize(); ++test_index) { |
724 SCOPED_TRACE(test_index); | 762 SCOPED_TRACE(test_index); |
725 base::DictionaryValue* test; | 763 base::DictionaryValue* test; |
726 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); | 764 ASSERT_TRUE(tests->GetDictionary(test_index, &test)); |
727 | 765 |
728 blink::WebCryptoAlgorithm test_hash = GetDigestAlgorithm(test, "hash"); | 766 blink::WebCryptoAlgorithm test_hash = GetDigestAlgorithm(test, "hash"); |
(...skipping 2493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3222 algorithm, | 3260 algorithm, |
3223 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), | 3261 CreateAesCbcAlgorithm(std::vector<uint8>(0, 16)), |
3224 true, | 3262 true, |
3225 blink::WebCryptoKeyUsageEncrypt, | 3263 blink::WebCryptoKeyUsageEncrypt, |
3226 &unwrapped_key)); | 3264 &unwrapped_key)); |
3227 } | 3265 } |
3228 | 3266 |
3229 } // namespace webcrypto | 3267 } // namespace webcrypto |
3230 | 3268 |
3231 } // namespace content | 3269 } // namespace content |
OLD | NEW |