openbmc/build/tmp/deploy/sdk/witherspoon-2019-08-08/sysroots/armv6-openbmc-linux-gnueabi/usr/src/debug/rng-tools/6.7-r0/git/rngd_entsource.c
int init_entropy_source(struct rng* ent_src)
{
    struct sysfs_attribute* rngavail;
    char buf[16];

    ent_src->rng_fd = open(ent_src->rng_fname, O_RDONLY | O_NOCTTY);
    if (ent_src->rng_fd == -1)
    {
        message(LOG_DAEMON | LOG_DEBUG, "Unable to open file: %s",
                ent_src->rng_fname);
        return 1;
    }

    /* Try to read some data from the entropy source.  If it doesn't return
     * an error, assume its ok to use
     */
    if (ent_src->xread(buf, sizeof(buf), ent_src) == 0)
        goto source_valid;

    /* RHEL7: since /dev/hwrng will exist now even if there isn't an rng backing
     * it, check to see if rng_available is empty, and return error if it is.
     */
    rngavail = sysfs_open_attribute(RNG_AVAIL);
    if (!rngavail)
    {
        message(LOG_DAEMON | LOG_DEBUG, "Unable to open sysfs attribute: %s",
                RNG_AVAIL);
        return 1;
    }

    if (sysfs_read_attribute(rngavail))
    {
        message(LOG_DAEMON | LOG_DEBUG, "Error reading sysfs attribute: %s",
                RNG_AVAIL);
        sysfs_close_attribute(rngavail);
        return 1;
    }

    if (strncmp(rngavail->value, "\n", 1) == 0)
    {
        message(LOG_DAEMON | LOG_DEBUG, "hwrng: no available rng");
        sysfs_close_attribute(rngavail);
        return 1;
    }
    sysfs_close_attribute(rngavail);

source_valid:
    /* Bootstrap FIPS tests */
    ent_src->fipsctx = malloc(sizeof(fips_ctx_t));
    return 0;
}
/*
 * Open entropy source, and initialize it
 */
Open entropy source, and initialize it
Open entropy source and initialize it
int init_entropy_source(struct rng* ent_src)
{
    struct sysfs_attribute* rngavail;
    char buf[16];
    ent_src->rng_fd = open(ent_src->rng_fname, O_RDONLY | O_NOCTTY);
    if (ent_src->rng_fd == -1)
    {
        message(LOG_DAEMON | LOG_DEBUG, "Unable to open file: %s",
                ent_src->rng_fname);
        return 1;
    }
    if (ent_src->xread(buf, sizeof(buf), ent_src) == 0)
        goto source_valid;
    rngavail = sysfs_open_attribute(RNG_AVAIL);
    if (!rngavail)
    {
        message(LOG_DAEMON | LOG_DEBUG, "Unable to open sysfs attribute: %s",
                RNG_AVAIL);
        return 1;
    }
    if (sysfs_read_attribute(rngavail))
    {
        message(LOG_DAEMON | LOG_DEBUG, "Error reading sysfs attribute: %s",
                RNG_AVAIL);
        sysfs_close_attribute(rngavail);
        return 1;
    }
    if (strncmp(rngavail->value, "\n", 1) == 0)
    {
        message(LOG_DAEMON | LOG_DEBUG, "hwrng: no available rng");
        sysfs_close_attribute(rngavail);
        return 1;
    }
    sysfs_close_attribute(rngavail);
source_valid:
    ent_src->fipsctx = malloc(sizeof(fips_ctx_t));
    return 0;
}
int init_entropy_source ( struct rng * ent_src ) { struct sysfs_attribute * rngavail ; char buf [ 16 ] ; ent_src -> rng_fd = open ( ent_src -> rng_fname , O_RDONLY | O_NOCTTY ) ; if ( ent_src -> rng_fd == -1 ) { message ( LOG_DAEMON | LOG_DEBUG , " " , ent_src -> rng_fname ) ; return 1 ; } if ( ent_src -> xread ( buf , sizeof ( buf ) , ent_src ) == 0 ) goto source_valid ; rngavail = sysfs_open_attribute ( RNG_AVAIL ) ; if ( ! rngavail ) { message ( LOG_DAEMON | LOG_DEBUG , " " , RNG_AVAIL ) ; return 1 ; } if ( sysfs_read_attribute ( rngavail ) ) { message ( LOG_DAEMON | LOG_DEBUG , " " , RNG_AVAIL ) ; sysfs_close_attribute ( rngavail ) ; return 1 ; } if ( strncmp ( rngavail -> value , " \n " , 1 ) == 0 ) { message ( LOG_DAEMON | LOG_DEBUG , " " ) ; sysfs_close_attribute ( rngavail ) ; return 1 ; } sysfs_close_attribute ( rngavail ) ; source_valid : ent_src -> fipsctx = malloc ( sizeof ( fips_ctx_t ) ) ; return 0 ; }
Open entropy source, and initialize it
Open entropy source and initialize it
/* Try to read some data from the entropy source.  If it doesn't return
     * an error, assume its ok to use
     */ /* RHEL7: since /dev/hwrng will exist now even if there isn't an rng backing
     * it, check to see if rng_available is empty, and return error if it is.
     */ /* Bootstrap FIPS tests */