test_crypt.c 1.0 KB

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