keygen/src/ssl.c
/**
 * gen_rand_serial() - Returns a random serial number
 *
 * Returns a random 19-byte  serial number as an ASN1_INTEGER
 *
 * Return: A new ASN1_INTEGER on success or NULL on failure
 */
Returns a random serial number
Returns a random 19-byte  serial number as an ASN1_INTEGER

A new ASN1_INTEGER on success or NULL on failure
Returns a random serial number Returns a random 19 - byte serial number as an ASN1_INTEGER A new ASN1_INTEGER on success or NULL on failure
static ASN1_INTEGER *gen_rand_serial()
{
    unsigned char buffer[19];    
    BIGNUM *bignum;
    ASN1_INTEGER *ret = NULL;
    randombytes_buf(buffer, sizeof(buffer));
    bignum = BN_bin2bn(buffer, sizeof(buffer), NULL);
    if (!bignum) {
        ret = NULL;
        fprintf(stderr, "%s ERR: Could not generate serial number", __func__);
        goto out;
    }
    ret = BN_to_ASN1_INTEGER(bignum, NULL);
    if (!ret) {
        ret = 0;
        fprintf(stderr, "%s ERR: Could not convert BN to ASN1 (memory error)", __func__);
        goto cleanup;
    }
cleanup:
    BN_free(bignum);
out:
    return ret;
}
static ASN1_INTEGER * gen_rand_serial ( ) { unsigned char buffer [ 19 ] ; BIGNUM * bignum ; ASN1_INTEGER * ret = NULL ; randombytes_buf ( buffer , sizeof ( buffer ) ) ; bignum = BN_bin2bn ( buffer , sizeof ( buffer ) , NULL ) ; if ( ! bignum ) { ret = NULL ; fprintf ( stderr , " " , __func__ ) ; goto out ; } ret = BN_to_ASN1_INTEGER ( bignum , NULL ) ; if ( ! ret ) { ret = 0 ; fprintf ( stderr , " " , __func__ ) ; goto cleanup ; } cleanup : BN_free ( bignum ) ; out : return ret ; }
gen_rand_serial() - Returns a random serial number
 Returns a random 19-byte  serial number as an ASN1_INTEGER
gen_rand_serial () - Returns a random serial number Returns a random 19 - byte serial number as an ASN1_INTEGER
// to hold a random number up to 2**152