Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_pbkdf2.c
Go to the documentation of this file.
1/*
2 * Copyright 2015-2018 Yubico AB
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include <stdint.h>
18#ifdef NDEBUG
19#undef NDEBUG
20#endif
21#include <assert.h>
22#include <string.h>
23
24#include "../../common/pkcs5.h"
25
26static void test_pbkdf2_vectors(void) {
27 struct vector {
28 const uint8_t *password;
29 size_t password_len;
30 const uint8_t *salt;
31 size_t salt_len;
32 uint64_t iterations;
33 hash_t hash;
34 const uint8_t *output;
35 size_t size;
36 } vectors[] = {
37 {(const uint8_t *) "password", 8, (const uint8_t *) "salt", 4, 1, _SHA1,
38 (const uint8_t *) "\x0c\x60\xc8\x0f\x96\x1f\x0e\x71\xf3\xa9\xb5\x24\xaf"
39 "\x60\x12\x06\x2f\xe0\x37\xa6",
40 20},
41 {(const uint8_t *) "password", 8, (const uint8_t *) "salt", 4, 2, _SHA1,
42 (const uint8_t *) "\xea\x6c\x01\x4d\xc7\x2d\x6f\x8c\xcd\x1e\xd9\x2a\xce"
43 "\x1d\x41\xf0\xd8\xde\x89\x57",
44 20},
45 {(const uint8_t *) "password", 8, (const uint8_t *) "salt", 4, 4096, _SHA1,
46 (const uint8_t *) "\x4b\x00\x79\x01\xb7\x65\x48\x9a\xbe\xad\x49\xd9\x26"
47 "\xf7\x21\xd0\x65\xa4\x29\xc1",
48 20},
49 //{(const uint8_t*)"password", 8, (const uint8_t*)"salt", 4, 16777216,
50 //_SHA1, (const
51 // uint8_t*)"\xee\xfe\x3d\x61\xcd\x4d\xa4\xe4\xe9\x94\x5b\x3d\x6b\xa2\x15\x8c\x26\x34\xe9\x84",
52 // 20},
53 {(const uint8_t *) "passwordPASSWORDpassword", 24,
54 (const uint8_t *) "saltSALTsaltSALTsaltSALTsaltSALTsalt", 36, 4096, _SHA1,
55 (const uint8_t *) "\x3d\x2e\xec\x4f\xe4\x1c\x84\x9b\x80\xc8\xd8\x36\x62"
56 "\xc0\xe4\x4a\x8b\x29\x1a\x96\x4c\xf2\xf0\x70\x38",
57 25},
58 {(const uint8_t *) "pass\0word", 9, (const uint8_t *) "sa\0lt", 5, 4096,
59 _SHA1,
60 (const uint8_t
61 *) "\x56\xfa\x6a\xa7\x55\x48\x09\x9d\xcc\x37\xd7\xf0\x34\x25\xe0\xc3",
62 16},
63 };
64
65 for (size_t i = 0; i < sizeof(vectors) / sizeof(vectors[0]); i++) {
66 uint8_t key[256];
67 bool res = pkcs5_pbkdf2_hmac(vectors[i].password, vectors[i].password_len,
68 vectors[i].salt, vectors[i].salt_len,
69 vectors[i].iterations, vectors[i].hash, key,
70 vectors[i].size);
71 assert(res == true);
72 assert(memcmp(key, vectors[i].output, vectors[i].size) == 0);
73 }
74}
75
76int main(void) { test_pbkdf2_vectors(); }
const uint8_t password[]
Definition attest.c:39
bool pkcs5_pbkdf2_hmac(const uint8_t *password, size_t cb_password, const uint8_t *salt, size_t cb_salt, uint64_t iterations, hash_t hash, uint8_t *key, size_t cb_key)
Definition pkcs5.c:27
unsigned char uint8_t
Definition stdint.h:124
unsigned __int64 uint64_t
Definition stdint.h:136
int main(void)
Definition test_pbkdf2.c:76
hash_t
Definition hash.h:33
@ _SHA1
Definition hash.h:35