openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/libgcrypt/1.8.4-r0/libgcrypt-1.8.4/random/rndjent.c
size_t _gcry_rndjent_poll(void (*add)(const void*, size_t, enum random_origins),
                          enum random_origins origin, size_t length)
{
    size_t nbytes = 0;

#ifdef USE_JENT
    if (is_rng_available())
    {
        lock_rng();

        if (!jent_rng_is_initialized)
        {
            /* Auto-initialize.  */
            jent_rng_is_initialized = 1;
            jent_entropy_collector_free(jent_rng_collector);
            jent_rng_collector = NULL;
            if (!(_gcry_random_read_conf() & RANDOM_CONF_DISABLE_JENT))
            {
                if (!jent_entropy_init())
                    jent_rng_collector = jent_entropy_collector_alloc(1, 0);
            }
        }

        if (jent_rng_collector && add)
        {
            /* We have a working JENT and it has not been disabled.  */
            char buffer[32];

            while (length)
            {
                int rc;
                size_t n = length < sizeof(buffer) ? length : sizeof(buffer);

                jent_rng_totalcalls++;
                rc = jent_read_entropy(jent_rng_collector, buffer, n);
                if (rc < 0)
                    break;
                /* We need to hash the output to conform to the BSI
                 * NTG.1 specs.  */
                _gcry_md_hash_buffer(GCRY_MD_SHA256, buffer, buffer, rc);
                n = rc < 32 ? rc : 32;
                (*add)(buffer, n, origin);
                length -= n;
                nbytes += n;
                jent_rng_totalbytes += n;
            }
            wipememory(buffer, sizeof buffer);
        }

        unlock_rng();
    }

#else

    (void)add;
    (void)origin;

#endif

    return nbytes;
}
/* Read up to LENGTH bytes from a jitter RNG and return the number of
 * bytes actually read.  */
Read up to LENGTH bytes from a jitter RNG and return the number of
bytes actually read.
Read up to LENGTH bytes from a jitter RNG and return the number of bytes actually read .
size_t _gcry_rndjent_poll(void (*add)(const void*, size_t, enum random_origins),
                          enum random_origins origin, size_t length)
{
    size_t nbytes = 0;
#ifdef USE_JENT
    if (is_rng_available())
    {
        lock_rng();
        if (!jent_rng_is_initialized)
        {
            jent_rng_is_initialized = 1;
            jent_entropy_collector_free(jent_rng_collector);
            jent_rng_collector = NULL;
            if (!(_gcry_random_read_conf() & RANDOM_CONF_DISABLE_JENT))
            {
                if (!jent_entropy_init())
                    jent_rng_collector = jent_entropy_collector_alloc(1, 0);
            }
        }
        if (jent_rng_collector && add)
        {
            char buffer[32];
            while (length)
            {
                int rc;
                size_t n = length < sizeof(buffer) ? length : sizeof(buffer);
                jent_rng_totalcalls++;
                rc = jent_read_entropy(jent_rng_collector, buffer, n);
                if (rc < 0)
                    break;
                _gcry_md_hash_buffer(GCRY_MD_SHA256, buffer, buffer, rc);
                n = rc < 32 ? rc : 32;
                (*add)(buffer, n, origin);
                length -= n;
                nbytes += n;
                jent_rng_totalbytes += n;
            }
            wipememory(buffer, sizeof buffer);
        }
        unlock_rng();
    }
#else
    (void)add;
    (void)origin;
#endif
    return nbytes;
}
size_t _gcry_rndjent_poll ( void ( * add ) ( const void * , size_t , enum random_origins ) , enum random_origins origin , size_t length ) { size_t nbytes = 0 ; #ifdef USE_JENT if ( is_rng_available ( ) ) { lock_rng ( ) ; if ( ! jent_rng_is_initialized ) { jent_rng_is_initialized = 1 ; jent_entropy_collector_free ( jent_rng_collector ) ; jent_rng_collector = NULL ; if ( ! ( _gcry_random_read_conf ( ) & RANDOM_CONF_DISABLE_JENT ) ) { if ( ! jent_entropy_init ( ) ) jent_rng_collector = jent_entropy_collector_alloc ( 1 , 0 ) ; } } if ( jent_rng_collector && add ) { char buffer [ 32 ] ; while ( length ) { int rc ; size_t n = length < sizeof ( buffer ) ? length : sizeof ( buffer ) ; jent_rng_totalcalls ++ ; rc = jent_read_entropy ( jent_rng_collector , buffer , n ) ; if ( rc < 0 ) break ; _gcry_md_hash_buffer ( GCRY_MD_SHA256 , buffer , buffer , rc ) ; n = rc < 32 ? rc : 32 ; ( * add ) ( buffer , n , origin ) ; length -= n ; nbytes += n ; jent_rng_totalbytes += n ; } wipememory ( buffer , sizeof buffer ) ; } unlock_rng ( ) ; } #else ( void ) add ; ( void ) origin ; #endif return nbytes ; }
Read up to LENGTH bytes from a jitter RNG and return the number of
 bytes actually read.
Read up to LENGTH bytes from a jitter RNG and return the number of bytes actually read .
/* Auto-initialize.  */ /* We have a working JENT and it has not been disabled.  */ /* We need to hash the output to conform to the BSI
                 * NTG.1 specs.  */