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; 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, 0, 0, 0, YESCRYPT_SHARED_DEFAULTS, 0, NULL, 0)) return -1; 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 return retval; }
static #endif int PHS(void *out, size_t outlen, const void *in, size_t inlen, const void *salt, size_t saltlen, unsigned int t_cost, unsigned int m_cost) { yescrypt_shared_t shared; yescrypt_local_t local; int retval; if (yescrypt_init_shared(&shared, NULL, 0, 0, 0, 0, YESCRYPT_SHARED_DEFAULTS, 0, NULL, 0)) return -1; if (yescrypt_init_local(&local)) { yescrypt_free_shared(&shared); return -1; } retval = yescrypt_kdf(&shared, &local, in, inlen, salt, saltlen, (uint64_t)YESCRYPT_BASE_N << m_cost, YESCRYPT_R, YESCRYPT_P, t_cost, YESCRYPT_FLAGS, out, outlen); if (yescrypt_free_local(&local)) { yescrypt_free_shared(&shared); return -1; } if (yescrypt_free_shared(&shared)) return -1; return retval; }
uint8_t* yescrypt(const uint8_t* passwd, const uint8_t* setting) { static uint8_t buf[4 + 1 + 5 + 5 + BYTES2CHARS(32) + 1 + HASH_LEN + 1]; yescrypt_shared_t shared; yescrypt_local_t local; uint8_t * retval; if (yescrypt_init_shared(&shared, NULL, 0, 0, 0, 0, YESCRYPT_SHARED_DEFAULTS, 0, NULL, 0)) return NULL; if (yescrypt_init_local(&local)) { yescrypt_free_shared(&shared); return NULL; } retval = yescrypt_r(&shared, &local, passwd, 80, setting, buf, sizeof(buf)); //printf("hashse='%s'\n", (char *)retval); if (yescrypt_free_local(&local)) { yescrypt_free_shared(&shared); return NULL; } if (yescrypt_free_shared(&shared)) return NULL; return retval; }