1 // SPDX-License-Identifier: GPL-2.0+
6 #include "crypt-port.h"
8 typedef int (*crypt_fn)(const char *, size_t, const char *, size_t, uint8_t *,
9 size_t, void *, size_t);
11 const unsigned char ascii64[65] =
12 "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
14 static void equals_constant_time(const void *a_, const void *b_, size_t len,
18 const u8 *a = a_, *b = b_;
21 for (i = 0; i < len; i++)
32 int crypt_compare(const char *should, const char *passphrase, int *equal)
34 u8 output[CRYPT_OUTPUT_SIZE], scratch[ALG_SPECIFIC_SIZE];
41 #if defined(CONFIG_CRYPT_PW_SHA256)
42 { "$5$", crypt_sha256crypt_rn_wrapped },
44 #if defined(CONFIG_CRYPT_PW_SHA512)
45 { "$6$", crypt_sha512crypt_rn_wrapped },
52 for (n = 0; n < ARRAY_SIZE(crypt_algos); ++n) {
53 if (!crypt_algos[n].prefix)
55 if (strncmp(should, crypt_algos[n].prefix, 3) == 0)
59 if (n >= ARRAY_SIZE(crypt_algos))
62 err = crypt_algos[n].crypt(passphrase, strlen(passphrase), should, 0,
63 output, sizeof(output), scratch,
65 /* early return on error, nothing really happened inside the crypt() function */
69 equals_constant_time(should, output, strlen((const char *)output),
72 memset(scratch, 0, sizeof(scratch));
73 memset(output, 0, sizeof(output));