示例#1
0
KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_generate_random_block(void *buf, size_t len)
{
    static int rng_initialized = 0;

    HEIMDAL_MUTEX_lock(&crypto_mutex);
    if (!rng_initialized) {
	if (seed_something())
	    krb5_abortx(NULL, "Fatal: could not seed the "
			"random number generator");

	rng_initialized = 1;
    }
    HEIMDAL_MUTEX_unlock(&crypto_mutex);
    if (RAND_bytes(buf, len) <= 0)
	krb5_abortx(NULL, "Failed to generate random block");
}
示例#2
0
HEIMDAL_WARN_UNUSED_RESULT_ATTRIBUTE
KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_generate_random(void *buf, size_t len)
{
    static int rng_initialized = 0;
    int ret;

    HEIMDAL_MUTEX_lock(&crypto_mutex);
    if (!rng_initialized) {
	if (seed_something())
	    return HEIM_ERR_RANDOM_OFFLINE;
	rng_initialized = 1;
    }
    if (RAND_bytes(buf, len) <= 0)
	ret = HEIM_ERR_RANDOM_OFFLINE;
    else
	ret = 0;
    HEIMDAL_MUTEX_unlock(&crypto_mutex);

    return ret;
}