openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libxcrypt/4.4.6-r0/git/lib/crypt-yescrypt.c
void gensalt_yescrypt_rn(unsigned long count, const uint8_t* rbytes,
                         size_t nrbytes, uint8_t* output, size_t o_size)
{
    if (o_size < 3 + 8 * 6 + BASE64_LEN(nrbytes) + 1 ||
        CRYPT_GENSALT_OUTPUT_SIZE < 3 + 8 * 6 + BASE64_LEN(nrbytes) + 1)
    {
        errno = ERANGE;
        return;
    }

    if (count > 11 || nrbytes < 16)
    {
        errno = EINVAL;
        return;
    }

    /* Temporary buffer for operation.  The buffer is guaranteed to be
       large enough to hold the maximum size of the generated salt.  */
    uint8_t outbuf[CRYPT_GENSALT_OUTPUT_SIZE];

    yescrypt_params_t params = {
        .flags = YESCRYPT_DEFAULTS,
        .p = 1,
    };

    /* Valid cost parameters are from 1 to 11.  The default is 5.
       These are used to set yescrypt's 'N' and 'r' parameters as
       follows:
       N (block count) is specified in units of r (block size,
       adjustable in steps of 128 bytes).

       128 bytes * r = size of each memory block

       128 bytes * r * N = total amount of memory used for hashing
                           in N blocks of r * 128 bytes.

       The author of yescrypt recommends in the documentation to use
       r=8 (a block size of 1 KiB) for total sizes of 2 MiB and less,
       and r=32 (a block size of 4KiB) above that.
       This has to do with the typical per-core last-level cache sizes
       of current CPUs.  */

    if (count == 0)
        count = 5;

    if (count < 3)
    {
        params.r = 8;                   // N in 1KiB
        params.N = 1ULL << (count + 9); // 1 -> 1024, 2 -> 2048
    }
    else
    {
        params.r = 32; // N in 4KiB
        params.N =
            1ULL << (count + 7); // 3 -> 1024, 4 -> 2048, ... 11 -> 262144
    }

    if (!yescrypt_encode_params_r(&params, rbytes, nrbytes, outbuf, o_size))
    {
        errno = ERANGE;
        return;
    }

    XCRYPT_STRCPY_OR_ABORT(output, o_size, outbuf);
    return;
}
/*
 * As OUTPUT is initialized with a failure token before gensalt_yescrypt_rn
 * is called, in case of an error we could just set an appropriate errno
 * and return.
 * Since O_SIZE is guaranteed to be greater than 2, we may fill OUTPUT
 * with a short failure token when need.
 */
As OUTPUT is initialized with a failure token before gensalt_yescrypt_rn
is called, in case of an error we could just set an appropriate errno
and return.
Since O_SIZE is guaranteed to be greater than 2, we may fill OUTPUT
with a short failure token when need.
As OUTPUT is initialized with a failure token before gensalt_yescrypt_rn is called in case of an error we could just set an appropriate errno and return . Since O_SIZE is guaranteed to be greater than 2 we may fill OUTPUT with a short failure token when need .
void gensalt_yescrypt_rn(unsigned long count, const uint8_t* rbytes,
                         size_t nrbytes, uint8_t* output, size_t o_size)
{
    if (o_size < 3 + 8 * 6 + BASE64_LEN(nrbytes) + 1 ||
        CRYPT_GENSALT_OUTPUT_SIZE < 3 + 8 * 6 + BASE64_LEN(nrbytes) + 1)
    {
        errno = ERANGE;
        return;
    }
    if (count > 11 || nrbytes < 16)
    {
        errno = EINVAL;
        return;
    }
    uint8_t outbuf[CRYPT_GENSALT_OUTPUT_SIZE];
    yescrypt_params_t params = {
        .flags = YESCRYPT_DEFAULTS,
        .p = 1,
    };
    if (count == 0)
        count = 5;
    if (count < 3)
    {
        params.r = 8;                   
        params.N = 1ULL << (count + 9); 
    }
    else
    {
        params.r = 32; 
        params.N =
            1ULL << (count + 7); 
    }
    if (!yescrypt_encode_params_r(&params, rbytes, nrbytes, outbuf, o_size))
    {
        errno = ERANGE;
        return;
    }
    XCRYPT_STRCPY_OR_ABORT(output, o_size, outbuf);
    return;
}
void gensalt_yescrypt_rn ( unsigned long count , const uint8_t * rbytes , size_t nrbytes , uint8_t * output , size_t o_size ) { if ( o_size < 3 + 8 * 6 + BASE64_LEN ( nrbytes ) + 1 || CRYPT_GENSALT_OUTPUT_SIZE < 3 + 8 * 6 + BASE64_LEN ( nrbytes ) + 1 ) { errno = ERANGE ; return ; } if ( count > 11 || nrbytes < 16 ) { errno = EINVAL ; return ; } uint8_t outbuf [ CRYPT_GENSALT_OUTPUT_SIZE ] ; yescrypt_params_t params = { . flags = YESCRYPT_DEFAULTS , . p = 1 , } ; if ( count == 0 ) count = 5 ; if ( count < 3 ) { params . r = 8 ; params . N = 1ULL << ( count + 9 ) ; } else { params . r = 32 ; params . N = 1ULL << ( count + 7 ) ; } if ( ! yescrypt_encode_params_r ( & params , rbytes , nrbytes , outbuf , o_size ) ) { errno = ERANGE ; return ; } XCRYPT_STRCPY_OR_ABORT ( output , o_size , outbuf ) ; return ; }
As OUTPUT is initialized with a failure token before gensalt_yescrypt_rn
 is called, in case of an error we could just set an appropriate errno
 and return.
As OUTPUT is initialized with a failure token before gensalt_yescrypt_rn is called in case of an error we could just set an appropriate errno and return .
/* Temporary buffer for operation.  The buffer is guaranteed to be
       large enough to hold the maximum size of the generated salt.  */ /* Valid cost parameters are from 1 to 11.  The default is 5.
       These are used to set yescrypt's 'N' and 'r' parameters as
       follows:
       N (block count) is specified in units of r (block size,
       adjustable in steps of 128 bytes).

       128 bytes * r = size of each memory block

       128 bytes * r * N = total amount of memory used for hashing
                           in N blocks of r * 128 bytes.

       The author of yescrypt recommends in the documentation to use
       r=8 (a block size of 1 KiB) for total sizes of 2 MiB and less,
       and r=32 (a block size of 4KiB) above that.
       This has to do with the typical per-core last-level cache sizes
       of current CPUs.  */ // N in 1KiB // 1 -> 1024, 2 -> 2048 // N in 4KiB // 3 -> 1024, 4 -> 2048, ... 11 -> 262144