src/flb_random.c
int flb_random_bytes(unsigned char *buf, int len)
{
#ifdef FLB_SYSTEM_WINDOWS
    NTSTATUS ret;
    ret = BCryptGenRandom(NULL, buf, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
    if (!BCRYPT_SUCCESS(ret)) {
        return -1;
    }
    return 0;
#else
    int fd;
    int bytes;

    fd = open("/dev/urandom", O_RDONLY);
    if (fd == -1) {
        return -1;
    }

    while (len > 0) {
        bytes = read(fd, buf, len);
        if (bytes <= 0) {
            close(fd);
            return -1;
        }
        len -= bytes;
        buf += bytes;
    }
    close(fd);
    return 0;
#endif
}
/*
 * This module provides a random number generator for common use cases.
 *
 * On Windows, we use BCryptGenRandom() from CNG API. This function
 * is available since Windows Vista, and should be compliant to the
 * official recommendation.
 *
 * On Unix, we use /dev/urandom as a secure random source.
 */
This module provides a random number generator for common use cases.
On Windows, we use BCryptGenRandom() from CNG API. This function
is available since Windows Vista, and should be compliant to the
official recommendation.

On Unix, we use /dev/urandom as a secure random source.
This module provides a random number generator for common use cases . On Windows we use BCryptGenRandom () from CNG API . This function is available since Windows Vista and should be compliant to the official recommendation . On Unix we use / dev / urandom as a secure random source .
int flb_random_bytes(unsigned char *buf, int len)
{
#ifdef FLB_SYSTEM_WINDOWS
    NTSTATUS ret;
    ret = BCryptGenRandom(NULL, buf, len, BCRYPT_USE_SYSTEM_PREFERRED_RNG);
    if (!BCRYPT_SUCCESS(ret)) {
        return -1;
    }
    return 0;
#else
    int fd;
    int bytes;
    fd = open("/dev/urandom", O_RDONLY);
    if (fd == -1) {
        return -1;
    }
    while (len > 0) {
        bytes = read(fd, buf, len);
        if (bytes <= 0) {
            close(fd);
            return -1;
        }
        len -= bytes;
        buf += bytes;
    }
    close(fd);
    return 0;
#endif
}
int flb_random_bytes ( unsigned char * buf , int len ) { #ifdef FLB_SYSTEM_WINDOWS NTSTATUS ret ; ret = BCryptGenRandom ( NULL , buf , len , BCRYPT_USE_SYSTEM_PREFERRED_RNG ) ; if ( ! BCRYPT_SUCCESS ( ret ) ) { return -1 ; } return 0 ; #else int fd ; int bytes ; fd = open ( " " , O_RDONLY ) ; if ( fd == -1 ) { return -1 ; } while ( len > 0 ) { bytes = read ( fd , buf , len ) ; if ( bytes <= 0 ) { close ( fd ) ; return -1 ; } len -= bytes ; buf += bytes ; } close ( fd ) ; return 0 ; #endif }
This module provides a random number generator for common use cases.
This module provides a random number generator for common use cases .