blob: 277e4efed162d1cf2ab523c112c709dda6dae828 [file] [log] [blame]
Steffen Jaeckel229bd512021-07-08 15:57:33 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2021 Steffen Jaeckel
4 *
5 * Unit test for crypt-style password hashing
6 */
7
8#include <common.h>
9#include <test/lib.h>
10#include <test/test.h>
11#include <test/ut.h>
12
13#include <crypt.h>
14
15/**
16 * lib_crypt() - unit test for crypt-style password hashing
17 *
18 * @uts: unit test state
19 * Return: 0 = success, 1 = failure
20 */
21static int lib_crypt(struct unit_test_state *uts)
22{
23 int equals = 0;
24
25 if (IS_ENABLED(CONFIG_CRYPT_PW_SHA256)) {
26 crypt_compare(
27 "$5$rounds=640000$TM4lL4zXDG7F4aRX$JM7a9wmvodnA0WasjTztj6mxg.KVuk6doQ/eBhdcapB",
28 "password", &equals);
29 ut_assertf(equals == 1,
30 "crypt-sha256 password hash didn't match\n");
31 }
32 equals = 0;
33 if (IS_ENABLED(CONFIG_CRYPT_PW_SHA512)) {
34 crypt_compare(
35 "$6$rounds=640000$fCTP1F0N5JLq2eND$z5EzK5KZJA9JnOaj5d1Gg/2v6VqFOQJ3bVekWuCPauabutBt/8qzV1exJnytUyhbq3H0bSBXtodwNbtGEi/Tm/",
36 "password", &equals);
37 ut_assertf(equals == 1,
38 "crypt-sha512 password hash didn't match\n");
39 }
40
41 return CMD_RET_SUCCESS;
42}
43
44LIB_TEST(lib_crypt, 0);