From 29bbe71ccfef3440b4881259c6f8e39b6e7924c6 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Thu, 8 Jul 2021 15:57:34 +0200 Subject: lib: wrap crypt API to hide errno usage In order to prevent using the global errno, replace it with a static version and create a wrapper function which returns the error value. Signed-off-by: Steffen Jaeckel Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- test/lib/test_crypt.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'test/lib') diff --git a/test/lib/test_crypt.c b/test/lib/test_crypt.c index 277e4efed1..fb21edf974 100644 --- a/test/lib/test_crypt.c +++ b/test/lib/test_crypt.c @@ -21,19 +21,39 @@ 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)) { - crypt_compare( + 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)) { - crypt_compare( + 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"); } -- cgit v1.2.3