OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "base/crypto/secure_hash.h" | 5 #include "base/crypto/secure_hash.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/sha2.h" | 9 #include "base/sha2.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 TEST(SecureHashTest, TestUpdate) { | 12 TEST(SecureHashTest, TestUpdate) { |
13 // Example B.3 from FIPS 180-2: long message. | 13 // Example B.3 from FIPS 180-2: long message. |
14 std::string input3(500000, 'a'); // 'a' repeated half a million times | 14 std::string input3(500000, 'a'); // 'a' repeated half a million times |
15 int expected3[] = { 0xcd, 0xc7, 0x6e, 0x5c, | 15 int expected3[] = { 0xcd, 0xc7, 0x6e, 0x5c, |
16 0x99, 0x14, 0xfb, 0x92, | 16 0x99, 0x14, 0xfb, 0x92, |
17 0x81, 0xa1, 0xc7, 0xe2, | 17 0x81, 0xa1, 0xc7, 0xe2, |
18 0x84, 0xd7, 0x3e, 0x67, | 18 0x84, 0xd7, 0x3e, 0x67, |
19 0xf1, 0x80, 0x9a, 0x48, | 19 0xf1, 0x80, 0x9a, 0x48, |
20 0xa4, 0x97, 0x20, 0x0e, | 20 0xa4, 0x97, 0x20, 0x0e, |
21 0x04, 0x6d, 0x39, 0xcc, | 21 0x04, 0x6d, 0x39, 0xcc, |
22 0xc7, 0x11, 0x2c, 0xd0 }; | 22 0xc7, 0x11, 0x2c, 0xd0 }; |
23 | 23 |
24 uint8 output3[base::SHA256_LENGTH]; | 24 uint8 output3[base::SHA256_LENGTH]; |
25 | 25 |
26 scoped_ptr<base::SecureHash> ctx(base::SecureHash::Create( | 26 scoped_ptr<base::SecureHash> ctx(base::SecureHash::Create( |
27 base::SecureHash::SHA256)); | 27 base::SecureHash::SHA256)); |
28 ctx->Update(input3.data(), input3.size()); | 28 ctx->Update(input3.data(), input3.size()); |
29 ctx->Update(input3.data(), input3.size()); | 29 ctx->Update(input3.data(), input3.size()); |
30 | 30 |
31 ctx->Finish(output3, sizeof(output3)); | 31 ctx->Finish(output3, sizeof(output3)); |
32 for (size_t i = 0; i < base::SHA256_LENGTH; i++) | 32 for (size_t i = 0; i < base::SHA256_LENGTH; i++) |
33 EXPECT_EQ(expected3[i], static_cast<int>(output3[i])); | 33 EXPECT_EQ(expected3[i], static_cast<int>(output3[i])); |
34 } | 34 } |
OLD | NEW |