Chromium Code Reviews| 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 "crypto/sha2.h" | 5 #include "crypto/sha2.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 | 9 |
| 10 TEST(Sha256Test, Test1) { | 10 TEST(Sha256Test, Test1) { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 38 int expected1[] = { 0xba, 0x78, 0x16, 0xbf, | 38 int expected1[] = { 0xba, 0x78, 0x16, 0xbf, |
| 39 0x8f, 0x01, 0xcf, 0xea, | 39 0x8f, 0x01, 0xcf, 0xea, |
| 40 0x41, 0x41, 0x40, 0xde, | 40 0x41, 0x41, 0x40, 0xde, |
| 41 0x5d, 0xae, 0x22, 0x23, | 41 0x5d, 0xae, 0x22, 0x23, |
| 42 0xb0, 0x03, 0x61, 0xa3, | 42 0xb0, 0x03, 0x61, 0xa3, |
| 43 0x96, 0x17, 0x7a, 0x9c, | 43 0x96, 0x17, 0x7a, 0x9c, |
| 44 0xb4, 0x10, 0xff, 0x61, | 44 0xb4, 0x10, 0xff, 0x61, |
| 45 0xf2, 0x00, 0x15, 0xad }; | 45 0xf2, 0x00, 0x15, 0xad }; |
| 46 | 46 |
| 47 std::string output1 = crypto::SHA256HashString(input1); | 47 std::string output1 = crypto::SHA256HashString(input1); |
| 48 ASSERT_EQ(crypto::SHA256_LENGTH, output1.size()); | 48 ASSERT_EQ(static_cast<size_t>(crypto::SHA256_LENGTH), output1.size()); |
|
Nico
2011/08/19 20:34:23
for msvc i assume. else revert
| |
| 49 for (size_t i = 0; i < crypto::SHA256_LENGTH; i++) | 49 for (size_t i = 0; i < crypto::SHA256_LENGTH; i++) |
| 50 EXPECT_EQ(expected1[i], static_cast<uint8>(output1[i])); | 50 EXPECT_EQ(expected1[i], static_cast<uint8>(output1[i])); |
| 51 } | 51 } |
| 52 | 52 |
| 53 TEST(Sha256Test, Test2) { | 53 TEST(Sha256Test, Test2) { |
| 54 // Example B.2 from FIPS 180-2: multi-block message. | 54 // Example B.2 from FIPS 180-2: multi-block message. |
| 55 std::string input2 = | 55 std::string input2 = |
| 56 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; | 56 "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"; |
| 57 int expected2[] = { 0x24, 0x8d, 0x6a, 0x61, | 57 int expected2[] = { 0x24, 0x8d, 0x6a, 0x61, |
| 58 0xd2, 0x06, 0x38, 0xb8, | 58 0xd2, 0x06, 0x38, 0xb8, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 crypto::SHA256HashString(input3, output3, sizeof(output3)); | 91 crypto::SHA256HashString(input3, output3, sizeof(output3)); |
| 92 for (size_t i = 0; i < crypto::SHA256_LENGTH; i++) | 92 for (size_t i = 0; i < crypto::SHA256_LENGTH; i++) |
| 93 EXPECT_EQ(expected3[i], static_cast<int>(output3[i])); | 93 EXPECT_EQ(expected3[i], static_cast<int>(output3[i])); |
| 94 | 94 |
| 95 uint8 output_truncated3[12]; | 95 uint8 output_truncated3[12]; |
| 96 crypto::SHA256HashString(input3, | 96 crypto::SHA256HashString(input3, |
| 97 output_truncated3, sizeof(output_truncated3)); | 97 output_truncated3, sizeof(output_truncated3)); |
| 98 for (size_t i = 0; i < sizeof(output_truncated3); i++) | 98 for (size_t i = 0; i < sizeof(output_truncated3); i++) |
| 99 EXPECT_EQ(expected3[i], static_cast<int>(output_truncated3[i])); | 99 EXPECT_EQ(expected3[i], static_cast<int>(output_truncated3[i])); |
| 100 } | 100 } |
| OLD | NEW |