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/symmetric_key.h" | 5 #include "crypto/symmetric_key.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 unsigned int key_size_in_bits; | 73 unsigned int key_size_in_bits; |
| 74 const char* expected; // ASCII encoded hex bytes | 74 const char* expected; // ASCII encoded hex bytes |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 class SymmetricKeyDeriveKeyFromPasswordTest | 77 class SymmetricKeyDeriveKeyFromPasswordTest |
| 78 : public testing::TestWithParam<PBKDF2TestVector> { | 78 : public testing::TestWithParam<PBKDF2TestVector> { |
| 79 }; | 79 }; |
| 80 | 80 |
| 81 TEST_P(SymmetricKeyDeriveKeyFromPasswordTest, DeriveKeyFromPassword) { | 81 TEST_P(SymmetricKeyDeriveKeyFromPasswordTest, DeriveKeyFromPassword) { |
| 82 PBKDF2TestVector test_data(GetParam()); | 82 PBKDF2TestVector test_data(GetParam()); |
| 83 #if defined(OS_MACOSX) && !defined(OS_IOS) | |
| 84 // The OS X crypto libraries have minimum salt and iteration requirements | |
|
svaldez
2016/06/07 13:56:41
Seems to be separate from the NSS change? Add a no
Ryan Sleevi
2016/06/07 14:58:18
There already was one. The second paragraph.
| |
| 85 // so some of the tests below will cause them to barf. Skip these. | |
| 86 if (strlen(test_data.salt) < 8 || test_data.rounds < 1000) { | |
| 87 VLOG(1) << "Skipped test vector for " << test_data.expected; | |
| 88 return; | |
| 89 } | |
| 90 #endif // OS_MACOSX | |
| 91 | |
| 92 std::unique_ptr<crypto::SymmetricKey> key( | 83 std::unique_ptr<crypto::SymmetricKey> key( |
| 93 crypto::SymmetricKey::DeriveKeyFromPassword( | 84 crypto::SymmetricKey::DeriveKeyFromPassword( |
| 94 test_data.algorithm, test_data.password, test_data.salt, | 85 test_data.algorithm, test_data.password, test_data.salt, |
| 95 test_data.rounds, test_data.key_size_in_bits)); | 86 test_data.rounds, test_data.key_size_in_bits)); |
| 96 ASSERT_TRUE(NULL != key.get()); | 87 ASSERT_TRUE(NULL != key.get()); |
| 97 | 88 |
| 98 std::string raw_key; | 89 std::string raw_key; |
| 99 key->GetRawKey(&raw_key); | 90 key->GetRawKey(&raw_key); |
| 100 EXPECT_EQ(test_data.key_size_in_bits / 8, raw_key.size()); | 91 EXPECT_EQ(test_data.key_size_in_bits / 8, raw_key.size()); |
| 101 EXPECT_EQ(test_data.expected, | 92 EXPECT_EQ(test_data.expected, |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", | 206 "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", |
| 216 "pass phrase exceeds block size", | 207 "pass phrase exceeds block size", |
| 217 20, | 208 20, |
| 218 256, | 209 256, |
| 219 "e0739745dc28b8721ba402e05214d2ac1eab54cf72bee1fba388297a09eb493c", | 210 "e0739745dc28b8721ba402e05214d2ac1eab54cf72bee1fba388297a09eb493c", |
| 220 }, | 211 }, |
| 221 }; | 212 }; |
| 222 | 213 |
| 223 INSTANTIATE_TEST_CASE_P(, SymmetricKeyDeriveKeyFromPasswordTest, | 214 INSTANTIATE_TEST_CASE_P(, SymmetricKeyDeriveKeyFromPasswordTest, |
| 224 testing::ValuesIn(kTestVectors)); | 215 testing::ValuesIn(kTestVectors)); |
| OLD | NEW |