OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "crypto/ghash.h" | 5 #include "crypto/ghash.h" |
6 | 6 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace crypto { | 9 namespace crypto { |
10 | 10 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 GaloisHash hash(test.key); | 110 GaloisHash hash(test.key); |
111 if (test.additional_length) | 111 if (test.additional_length) |
112 hash.UpdateAdditional(test.additional, test.additional_length); | 112 hash.UpdateAdditional(test.additional, test.additional_length); |
113 if (test.ciphertext_length) | 113 if (test.ciphertext_length) |
114 hash.UpdateCiphertext(test.ciphertext, test.ciphertext_length); | 114 hash.UpdateCiphertext(test.ciphertext, test.ciphertext_length); |
115 hash.Finish(out, sizeof(out)); | 115 hash.Finish(out, sizeof(out)); |
116 EXPECT_TRUE(0 == memcmp(out, test.expected, 16)); | 116 EXPECT_TRUE(0 == memcmp(out, test.expected, 16)); |
117 } | 117 } |
118 } | 118 } |
119 | 119 |
120 TEST(GaloisHash, TestCasesByteAtATime) { | 120 TEST(GaloisHash, VaryLengths) { |
121 uint8 out[16]; | 121 uint8 out[16]; |
122 | 122 |
123 for (size_t i = 0; i < arraysize(kTestCases); ++i) { | 123 for (size_t chunk_size = 1; chunk_size < 16; chunk_size++) { |
124 const TestCase& test = kTestCases[i]; | 124 for (size_t i = 0; i < arraysize(kTestCases); ++i) { |
| 125 const TestCase& test = kTestCases[i]; |
125 | 126 |
126 GaloisHash hash(test.key); | 127 GaloisHash hash(test.key); |
127 for (size_t i = 0; i < test.additional_length; ++i) | 128 for (size_t i = 0; i < test.additional_length;) { |
128 hash.UpdateAdditional(test.additional + i, 1); | 129 size_t n = std::min(test.additional_length - i, chunk_size); |
129 for (size_t i = 0; i < test.ciphertext_length; ++i) | 130 hash.UpdateAdditional(test.additional + i, n); |
130 hash.UpdateCiphertext(test.ciphertext + i, 1); | 131 i += n; |
131 hash.Finish(out, sizeof(out)); | 132 } |
132 EXPECT_TRUE(0 == memcmp(out, test.expected, 16)); | 133 for (size_t i = 0; i < test.ciphertext_length;) { |
| 134 size_t n = std::min(test.ciphertext_length - i, chunk_size); |
| 135 hash.UpdateCiphertext(test.ciphertext + i, n); |
| 136 i += n; |
| 137 } |
| 138 hash.Finish(out, sizeof(out)); |
| 139 EXPECT_TRUE(0 == memcmp(out, test.expected, 16)); |
| 140 } |
133 } | 141 } |
134 } | 142 } |
135 | 143 |
136 } // namespace | 144 } // namespace |
137 | 145 |
138 } // namespace crypto | 146 } // namespace crypto |
OLD | NEW |