diff --git a/stratum/algos/yescrypt.c b/stratum/algos/yescrypt.c index 1501745..2959dfa 100644 --- a/stratum/algos/yescrypt.c +++ b/stratum/algos/yescrypt.c @@ -327,35 +327,25 @@ static int yescrypt_bsty(const uint8_t * passwd, size_t passwdlen, const uint8_t * salt, size_t saltlen, uint64_t N, uint32_t r, uint32_t p, uint8_t * buf, size_t buflen) { - static __thread int initialized = 0; - static __thread yescrypt_shared_t shared; - static __thread yescrypt_local_t local; + yescrypt_shared_t shared; + yescrypt_local_t local; int retval; - if (!initialized) { -/* "shared" could in fact be shared, but it's simpler to keep it private - * along with "local". It's dummy and tiny anyway. */ - if (yescrypt_init_shared(&shared, NULL, 0, + if (yescrypt_init_shared(&shared, NULL, 0, 0, 0, 0, YESCRYPT_SHARED_DEFAULTS, 0, NULL, 0)) return -1; - if (yescrypt_init_local(&local)) { + if (yescrypt_init_local(&local)) { yescrypt_free_shared(&shared); return -1; - } - initialized = 1; } + retval = yescrypt_kdf(&shared, &local, passwd, passwdlen, salt, saltlen, N, r, p, 0, YESCRYPT_FLAGS, buf, buflen); -#if 0 - if (yescrypt_free_local(&local)) { - yescrypt_free_shared(&shared); - return -1; - } - if (yescrypt_free_shared(&shared)) - return -1; - initialized = 0; -#endif + + yescrypt_free_local(&local); + yescrypt_free_shared(&shared); + return retval; } @@ -364,6 +354,7 @@ void yescrypt_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 2048, 8, 1, (uint8_t*)output, 32); } + void yescryptR16_hash(const char *input, char *output, uint32_t len) { yescrypt_bsty((uint8_t*)input, len, (uint8_t*)input, len, 4096, 16, 1, (uint8_t*)output, 32);