summaryrefslogtreecommitdiff
path: root/test/lib
diff options
context:
space:
mode:
authorSteffen Jaeckel <jaeckel-floss@eyet-services.de>2021-07-08 15:57:33 +0200
committerTom Rini <trini@konsulko.com>2021-07-23 13:36:14 -0400
commit26dd9936574864155b989b9f14319ca2779f0598 (patch)
tree41fe3ce1471a80916ea6cc91d8a6e7c956c8e2d9 /test/lib
parentc74675bd904b6ce9d5820a80f27793c0583fd54c (diff)
lib: add crypt subsystem
Add the basic functionality required to support the standard crypt format. The files crypt-sha256.c and crypt-sha512.c originate from libxcrypt and their formatting is therefor retained. The integration is done via a crypt_compare() function in crypt.c. ``` libxcrypt $ git describe --long --always --all tags/v4.4.17-0-g6b110bc ``` Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de> Reviewed-by: Simon Glass <sjg@chromium.org> Reviewed-by: Heiko Schocher <hs@denx.de>
Diffstat (limited to 'test/lib')
-rw-r--r--test/lib/Makefile1
-rw-r--r--test/lib/test_crypt.c44
2 files changed, 45 insertions, 0 deletions
diff --git a/test/lib/Makefile b/test/lib/Makefile
index aa2e66bc7f4..6fd05142510 100644
--- a/test/lib/Makefile
+++ b/test/lib/Makefile
@@ -17,3 +17,4 @@ obj-$(CONFIG_UT_LIB_ASN1) += asn1.o
obj-$(CONFIG_UT_LIB_RSA) += rsa.o
obj-$(CONFIG_AES) += test_aes.o
obj-$(CONFIG_GETOPT) += getopt.o
+obj-$(CONFIG_UT_LIB_CRYPT) += test_crypt.o
diff --git a/test/lib/test_crypt.c b/test/lib/test_crypt.c
new file mode 100644
index 00000000000..277e4efed16
--- /dev/null
+++ b/test/lib/test_crypt.c
@@ -0,0 +1,44 @@
+// 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;
+
+ if (IS_ENABLED(CONFIG_CRYPT_PW_SHA256)) {
+ crypt_compare(
+ "$5$rounds=640000$TM4lL4zXDG7F4aRX$JM7a9wmvodnA0WasjTztj6mxg.KVuk6doQ/eBhdcapB",
+ "password", &equals);
+ ut_assertf(equals == 1,
+ "crypt-sha256 password hash didn't match\n");
+ }
+ equals = 0;
+ if (IS_ENABLED(CONFIG_CRYPT_PW_SHA512)) {
+ crypt_compare(
+ "$6$rounds=640000$fCTP1F0N5JLq2eND$z5EzK5KZJA9JnOaj5d1Gg/2v6VqFOQJ3bVekWuCPauabutBt/8qzV1exJnytUyhbq3H0bSBXtodwNbtGEi/Tm/",
+ "password", &equals);
+ ut_assertf(equals == 1,
+ "crypt-sha512 password hash didn't match\n");
+ }
+
+ return CMD_RET_SUCCESS;
+}
+
+LIB_TEST(lib_crypt, 0);