3 * Copyright (c) 2020 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 * @file - This file contains PBKDF2 SHA256 test vectors.
26 #include <core/CHIPError.h>
27 #include <core/CHIPSafeCasts.h>
29 struct pbkdf2_test_vector
31 const uint8_t * password;
42 static const uint8_t chiptest_key1[] = { 0x9a, 0x87, 0xd2, 0x5e, 0x37, 0x40, 0x8f, 0xd7, 0x2f, 0x42,
43 0x3d, 0x22, 0x85, 0xc7, 0x08, 0x6d, 0x3a, 0x64, 0x2a, 0x26 };
44 static const struct pbkdf2_test_vector chiptest_test_vector_1 = { .password = chip::Uint8::from_const_char("password"),
46 .salt = chip::Uint8::from_const_char("saltSALT"),
52 .result = CHIP_NO_ERROR };
54 static const uint8_t chiptest_key2[] = { 0xa0, 0xf3, 0x0e, 0x25, 0xe8, 0x65, 0x9c, 0x36, 0xa0, 0x95,
55 0x89, 0x49, 0x0d, 0x64, 0xa6, 0xb1, 0x2e, 0x0c, 0x38, 0x3c };
56 static const struct pbkdf2_test_vector chiptest_test_vector_2 = { .password = chip::Uint8::from_const_char("password"),
58 .salt = chip::Uint8::from_const_char("saltSALT"),
64 .result = CHIP_NO_ERROR };
66 static const uint8_t chiptest_key3[] = { 0x86, 0x16, 0x14, 0x28, 0x77, 0x14, 0xd4, 0x29, 0x75, 0x16,
67 0x5e, 0xb6, 0x3e, 0xa7, 0x8c, 0xce, 0x85, 0x50, 0x71, 0x3c };
68 static const struct pbkdf2_test_vector chiptest_test_vector_3 = { .password = chip::Uint8::from_const_char("password"),
70 .salt = chip::Uint8::from_const_char("saltSALT"),
76 .result = CHIP_NO_ERROR };
78 static const uint8_t chiptest_key4[] = { 0x3f, 0x12, 0x78, 0x37, 0x88, 0x9c, 0x4a, 0x62, 0x3d, 0x6e,
79 0x8d, 0xc8, 0x8c, 0xa3, 0x3c, 0x01, 0x23, 0xa2, 0x9f, 0x07 };
80 static const struct pbkdf2_test_vector chiptest_test_vector_4 = { .password = chip::Uint8::from_const_char("password"),
82 .salt = chip::Uint8::from_const_char("saltSALT"),
88 .result = CHIP_NO_ERROR };
90 static const uint8_t chiptest_key5[] = { 0x28, 0x1a, 0xef, 0x26, 0xfa, 0x2d, 0xdf, 0x5b, 0x76, 0x82, 0x01, 0xff, 0x3a,
91 0xdd, 0xfc, 0x68, 0x0a, 0xda, 0x07, 0x87, 0xc9, 0xb4, 0x76, 0x55, 0x42 };
92 static const struct pbkdf2_test_vector chiptest_test_vector_5 = { .password =
93 chip::Uint8::from_const_char("passwordPASSWORDpassword"),
95 .salt = chip::Uint8::from_const_char("saltSALTsaltSALT"),
101 .result = CHIP_NO_ERROR };
103 static const struct pbkdf2_test_vector chiptest_test_vector_6 = { .password = nullptr,
105 .salt = chip::Uint8::from_const_char("saltSALT"),
109 .key = chiptest_key4,
111 .result = CHIP_ERROR_INVALID_ARGUMENT };
113 static const struct pbkdf2_test_vector chiptest_test_vector_7 = { .password = chip::Uint8::from_const_char("password"),
115 .salt = chip::Uint8::from_const_char("saltSALT"),
119 .key = chiptest_key4,
121 .result = CHIP_ERROR_INVALID_ARGUMENT };
123 static const struct pbkdf2_test_vector chiptest_test_vector_8 = { .password = chip::Uint8::from_const_char("password"),
129 .key = chiptest_key4,
131 .result = CHIP_ERROR_INVALID_ARGUMENT };
133 static const struct pbkdf2_test_vector chiptest_test_vector_9 = { .password = chip::Uint8::from_const_char("password"),
135 .salt = chip::Uint8::from_const_char("saltSALT"),
139 .key = chiptest_key4,
141 .result = CHIP_ERROR_INVALID_ARGUMENT };
143 static const struct pbkdf2_test_vector chiptest_test_vector_10 = { .password = chip::Uint8::from_const_char("password"),
145 .salt = chip::Uint8::from_const_char("saltSALT"),
151 .result = CHIP_ERROR_INVALID_ARGUMENT };
153 static const struct pbkdf2_test_vector chiptest_test_vector_11 = { .password = chip::Uint8::from_const_char("password"),
159 .key = chiptest_key4,
161 .result = CHIP_ERROR_INVALID_ARGUMENT };
163 static const struct pbkdf2_test_vector chiptest_test_vector_12 = { .password = chip::Uint8::from_const_char("password"),
165 .salt = chip::Uint8::from_const_char("saltSAL"),
169 .key = chiptest_key4,
171 .result = CHIP_ERROR_INVALID_ARGUMENT };
173 static const struct pbkdf2_test_vector chiptest_test_vector_13 = { .password = chip::Uint8::from_const_char("password"),
175 .salt = chip::Uint8::from_const_char("saltSALTsaltSALTs"),
179 .key = chiptest_key4,
181 .result = CHIP_ERROR_INVALID_ARGUMENT };
183 static const struct pbkdf2_test_vector * pbkdf2_sha256_test_vectors[] = {
184 &chiptest_test_vector_1, &chiptest_test_vector_2, &chiptest_test_vector_3,
185 #if !CHIP_TARGET_STYLE_EMBEDDED
186 // The following test vector takes excessive time to run on an embedded target
187 &chiptest_test_vector_4,
189 &chiptest_test_vector_5, &chiptest_test_vector_6, &chiptest_test_vector_7, &chiptest_test_vector_8, &chiptest_test_vector_9,
190 &chiptest_test_vector_10, &chiptest_test_vector_11, &chiptest_test_vector_12, &chiptest_test_vector_13