uint8_t* yescrypt_gensalt(uint32_t N_log2, uint32_t r, uint32_t p, yescrypt_flags_t flags, const uint8_t * src, size_t srclen) { static uint8_t buf[4 + 1 + 5 + 5 + BYTES2CHARS(32) + 1]; return yescrypt_gensalt_r(N_log2, r, p, flags, src, srclen, buf, sizeof(buf)); }
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; }
uint8_t* yescrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p, yescrypt_flags_t flags, const uint8_t* src, size_t srclen, uint8_t* buf, size_t buflen) { uint8_t * dst; size_t prefixlen = 3 + 1 + 5 + 5; size_t saltlen = BYTES2CHARS(srclen); size_t need; if (p == 1) flags &= ~YESCRYPT_PARALLEL_SMIX; if (flags) { if (flags & ~0x3f) return NULL; prefixlen++; if (flags != YESCRYPT_RW) prefixlen++; } need = prefixlen + saltlen + 1; if (need > buflen || need < saltlen || saltlen < srclen) return NULL; if (N_log2 > 63 || ((uint64_t)r * (uint64_t)p >= (1U << 30))) return NULL; dst = buf; *dst++ = '$'; *dst++ = '7'; if (flags) { *dst++ = 'X'; /* eXperimental, subject to change */ if (flags != YESCRYPT_RW) *dst++ = itoa64[flags]; } *dst++ = '$'; *dst++ = itoa64[N_log2]; dst = encode64_uint32(dst, buflen - (dst - buf), r, 30); if (!dst) /* Can't happen */ return NULL; dst = encode64_uint32(dst, buflen - (dst - buf), p, 30); if (!dst) /* Can't happen */ return NULL; dst = encode64(dst, buflen - (dst - buf), src, srclen); if (!dst || dst >= buf + buflen) /* Can't happen */ return NULL; *dst = 0; /* NUL termination */ return buf; }
uint8_t * escrypt(const uint8_t * passwd, const uint8_t * setting) { static uint8_t buf[4 + 1 + 5 + 5 + BYTES2CHARS(32) + 1 + HASH_LEN + 1]; escrypt_local_t local; uint8_t * retval; if (escrypt_init_local(&local)) return NULL; retval = escrypt_r(&local, passwd, strlen((char *)passwd), setting, buf, sizeof(buf)); if (escrypt_free_local(&local)) return NULL; return retval; }
uint8_t * escrypt_gensalt_r(uint32_t N_log2, uint32_t r, uint32_t p, const uint8_t * src, size_t srclen, uint8_t * buf, size_t buflen) { uint8_t *dst; size_t prefixlen = (sizeof "$7$" - 1U) + (1U /* N_log2 */) + (5U /* r */) + (5U /* p */); size_t saltlen = BYTES2CHARS(srclen); size_t need; need = prefixlen + saltlen + 1; if (need > buflen || need < saltlen || saltlen < srclen) { return NULL; } if (N_log2 > 63 || ((uint64_t)r * (uint64_t)p >= (1U << 30))) { return NULL; } dst = buf; *dst++ = '$'; *dst++ = '7'; *dst++ = '$'; *dst++ = itoa64[N_log2]; dst = encode64_uint32(dst, buflen - (dst - buf), r, 30); if (!dst) { /* Can't happen */ return NULL; } dst = encode64_uint32(dst, buflen - (dst - buf), p, 30); if (!dst) { /* Can't happen */ return NULL; } dst = encode64(dst, buflen - (dst - buf), src, srclen); if (!dst || dst >= buf + buflen) { /* Can't happen */ return NULL; } *dst = 0; /* NUL termination */ return buf; }