openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libxcrypt/4.4.6-r0/git/lib/alg-yescrypt-opt.c
int yescrypt_kdf(const yescrypt_shared_t* shared, yescrypt_local_t* local,
                 const uint8_t* passwd, size_t passwdlen, const uint8_t* salt,
                 size_t saltlen, const yescrypt_params_t* params, uint8_t* buf,
                 size_t buflen)
{
    yescrypt_flags_t flags = params->flags;
    uint64_t N = params->N;
    uint32_t r = params->r;
    uint32_t p = params->p;
    uint32_t t = params->t;
    uint32_t g = params->g;
    uint64_t NROM = params->NROM;
    uint8_t dk[32];
    int retval;

    /* Support for hash upgrades has been temporarily removed */
    if (g)
    {
        errno = EINVAL;
        return -1;
    }

    if ((flags & (YESCRYPT_RW | YESCRYPT_INIT_SHARED)) == YESCRYPT_RW &&
        p >= 1 && N / p >= 0x100 && N / p * r >= 0x20000)
    {
        if (yescrypt_kdf_body(shared, local, passwd, passwdlen, salt, saltlen,
                              flags | YESCRYPT_ALLOC_ONLY, N, r, p, t, NROM,
                              buf, buflen) != -3)
        {
            errno = EINVAL;
            return -1;
        }
        if ((retval = yescrypt_kdf_body(shared, local, passwd, passwdlen, salt,
                                        saltlen, flags | YESCRYPT_PREHASH,
                                        N >> 6, r, p, 0, NROM, dk, sizeof(dk))))
            return retval;
        passwd = dk;
        passwdlen = sizeof(dk);
    }

    retval = yescrypt_kdf_body(shared, local, passwd, passwdlen, salt, saltlen,
                               flags, N, r, p, t, NROM, buf, buflen);
#ifndef SKIP_MEMZERO
    if (passwd == dk)
        insecure_memzero(dk, sizeof(dk));
#endif
    return retval;
}
/**
 * yescrypt_kdf(shared, local, passwd, passwdlen, salt, saltlen, params,
 *     buf, buflen):
 * Compute scrypt or its revision as requested by the parameters.  The inputs
 * to this function are the same as those for yescrypt_kdf_body() above, with
 * the addition of g, which controls hash upgrades (0 for no upgrades so far).
 */
yescrypt_kdf(shared, local, passwd, passwdlen, salt, saltlen, params,
buf, buflen):
Compute scrypt or its revision as requested by the parameters.  The inputs
to this function are the same as those for yescrypt_kdf_body() above, with
the addition of g, which controls hash upgrades (0 for no upgrades so far).
yescrypt_kdf ( shared local passwd passwdlen salt saltlen params buf buflen ) : Compute scrypt or its revision as requested by the parameters . The inputs to this function are the same as those for yescrypt_kdf_body () above with the addition of g which controls hash upgrades ( 0 for no upgrades so far ) .
int yescrypt_kdf(const yescrypt_shared_t* shared, yescrypt_local_t* local,
                 const uint8_t* passwd, size_t passwdlen, const uint8_t* salt,
                 size_t saltlen, const yescrypt_params_t* params, uint8_t* buf,
                 size_t buflen)
{
    yescrypt_flags_t flags = params->flags;
    uint64_t N = params->N;
    uint32_t r = params->r;
    uint32_t p = params->p;
    uint32_t t = params->t;
    uint32_t g = params->g;
    uint64_t NROM = params->NROM;
    uint8_t dk[32];
    int retval;
    if (g)
    {
        errno = EINVAL;
        return -1;
    }
    if ((flags & (YESCRYPT_RW | YESCRYPT_INIT_SHARED)) == YESCRYPT_RW &&
        p >= 1 && N / p >= 0x100 && N / p * r >= 0x20000)
    {
        if (yescrypt_kdf_body(shared, local, passwd, passwdlen, salt, saltlen,
                              flags | YESCRYPT_ALLOC_ONLY, N, r, p, t, NROM,
                              buf, buflen) != -3)
        {
            errno = EINVAL;
            return -1;
        }
        if ((retval = yescrypt_kdf_body(shared, local, passwd, passwdlen, salt,
                                        saltlen, flags | YESCRYPT_PREHASH,
                                        N >> 6, r, p, 0, NROM, dk, sizeof(dk))))
            return retval;
        passwd = dk;
        passwdlen = sizeof(dk);
    }
    retval = yescrypt_kdf_body(shared, local, passwd, passwdlen, salt, saltlen,
                               flags, N, r, p, t, NROM, buf, buflen);
#ifndef SKIP_MEMZERO
    if (passwd == dk)
        insecure_memzero(dk, sizeof(dk));
#endif
    return retval;
}
int yescrypt_kdf ( const yescrypt_shared_t * shared , yescrypt_local_t * local , const uint8_t * passwd , size_t passwdlen , const uint8_t * salt , size_t saltlen , const yescrypt_params_t * params , uint8_t * buf , size_t buflen ) { yescrypt_flags_t flags = params -> flags ; uint64_t N = params -> N ; uint32_t r = params -> r ; uint32_t p = params -> p ; uint32_t t = params -> t ; uint32_t g = params -> g ; uint64_t NROM = params -> NROM ; uint8_t dk [ 32 ] ; int retval ; if ( g ) { errno = EINVAL ; return -1 ; } if ( ( flags & ( YESCRYPT_RW | YESCRYPT_INIT_SHARED ) ) == YESCRYPT_RW && p >= 1 && N / p >= 0x100 && N / p * r >= 0x20000 ) { if ( yescrypt_kdf_body ( shared , local , passwd , passwdlen , salt , saltlen , flags | YESCRYPT_ALLOC_ONLY , N , r , p , t , NROM , buf , buflen ) != -3 ) { errno = EINVAL ; return -1 ; } if ( ( retval = yescrypt_kdf_body ( shared , local , passwd , passwdlen , salt , saltlen , flags | YESCRYPT_PREHASH , N >> 6 , r , p , 0 , NROM , dk , sizeof ( dk ) ) ) ) return retval ; passwd = dk ; passwdlen = sizeof ( dk ) ; } retval = yescrypt_kdf_body ( shared , local , passwd , passwdlen , salt , saltlen , flags , N , r , p , t , NROM , buf , buflen ) ; #ifndef SKIP_MEMZERO if ( passwd == dk ) insecure_memzero ( dk , sizeof ( dk ) ) ; #endif return retval ; }
yescrypt_kdf(shared, local, passwd, passwdlen, salt, saltlen, params,
     buf, buflen):
 Compute scrypt or its revision as requested by the parameters.
yescrypt_kdf ( shared local passwd passwdlen salt saltlen params buf buflen ) : Compute scrypt or its revision as requested by the parameters .
/* Support for hash upgrades has been temporarily removed */