summaryrefslogtreecommitdiff
path: root/test/lib/test_crypt.c
diff options
context:
space:
mode:
authorTom Rini <trini@konsulko.com>2021-07-23 14:50:43 -0400
committerTom Rini <trini@konsulko.com>2021-07-23 14:50:43 -0400
commitedecc15eb9593b94dcd6a5f4f5ea5f134125b6a0 (patch)
tree1c8f414dc7ae2d0e914a706e3dd8aaebb945c946 /test/lib/test_crypt.c
parentf534d93cbf34f1d1762b04eb5680e84bef5e1fe1 (diff)
parent25c8b9f298e46ea6048b5308f7ee207c6461c36a (diff)
Merge branch '2021-07-23-reboot-mode-and-cryptfs-passwd-support'
- A new driver uclass is created to handle the reboot mode control. - Add support for libcrypt-style passwords for autoboot
Diffstat (limited to 'test/lib/test_crypt.c')
-rw-r--r--test/lib/test_crypt.c64
1 files changed, 64 insertions, 0 deletions
diff --git a/test/lib/test_crypt.c b/test/lib/test_crypt.c
new file mode 100644
index 00000000000..fb21edf9748
--- /dev/null
+++ b/test/lib/test_crypt.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2021 Steffen Jaeckel
+ *
+ * Unit test for crypt-style password hashing
+ */
+
+#include <common.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+#include <crypt.h>
+
+/**
+ * lib_crypt() - unit test for crypt-style password hashing
+ *
+ * @uts: unit test state
+ * Return: 0 = success, 1 = failure
+ */
+static int lib_crypt(struct unit_test_state *uts)
+{
+ int equals = 0;
+ int err;
+
+ err = crypt_compare("", "password", &equals);
+ ut_assertf(err != 0, "crypt_compare successful but should not\n");
+ ut_assertf(equals != 1,
+ "crypt_compare password hash matched but should not\n");
+
+ if (IS_ENABLED(CONFIG_CRYPT_PW_SHA256)) {
+ err = crypt_compare("$5$", "password", &equals);
+ ut_assertf(err == 0, "crypt-sha256 not successful\n");
+ ut_assertf(
+ equals != 1,
+ "crypt-sha256 password hash matched but should not\n");
+
+ err = crypt_compare(
+ "$5$rounds=640000$TM4lL4zXDG7F4aRX$JM7a9wmvodnA0WasjTztj6mxg.KVuk6doQ/eBhdcapB",
+ "password", &equals);
+ ut_assertf(err == 0, "crypt-sha256 failed: %d\n", err);
+ ut_assertf(equals == 1,
+ "crypt-sha256 password hash didn't match\n");
+ }
+ equals = 0;
+ if (IS_ENABLED(CONFIG_CRYPT_PW_SHA512)) {
+ err = crypt_compare("$6$", "password", &equals);
+ ut_assertf(err == 0, "crypt-sha512 not successful\n");
+ ut_assertf(
+ equals != 1,
+ "crypt-sha512 password hash matched but should not\n");
+
+ err = crypt_compare(
+ "$6$rounds=640000$fCTP1F0N5JLq2eND$z5EzK5KZJA9JnOaj5d1Gg/2v6VqFOQJ3bVekWuCPauabutBt/8qzV1exJnytUyhbq3H0bSBXtodwNbtGEi/Tm/",
+ "password", &equals);
+ ut_assertf(err == 0, "crypt-sha512 failed: %d\n", err);
+ ut_assertf(equals == 1,
+ "crypt-sha512 password hash didn't match\n");
+ }
+
+ return CMD_RET_SUCCESS;
+}
+
+LIB_TEST(lib_crypt, 0);