1.Dd $Mdocdate: July 25 2015 $ 2.Dt BN_RAND 3 3.Os 4.Sh NAME 5.Nm BN_rand , 6.Nm BN_pseudo_rand , 7.Nm BN_rand_range , 8.Nm BN_pseudo_rand_range 9.Nd generate pseudo-random number 10.Sh SYNOPSIS 11.In openssl/bn.h 12.Ft int 13.Fo BN_rand 14.Fa "BIGNUM *rnd" 15.Fa "int bits" 16.Fa "int top" 17.Fa "int bottom" 18.Fc 19.Ft int 20.Fo BN_pseudo_rand 21.Fa "BIGNUM *rnd" 22.Fa "int bits" 23.Fa "int top" 24.Fa "int bottom" 25.Fc 26.Ft int 27.Fo BN_rand_range 28.Fa "BIGNUM *rnd" 29.Fa "BIGNUM *range" 30.Fc 31.Ft int 32.Fo BN_pseudo_rand_range 33.Fa "BIGNUM *rnd" 34.Fa "BIGNUM *range" 35.Fc 36.Sh DESCRIPTION 37.Fn BN_rand 38generates a cryptographically strong pseudo-random number of 39.Fa bits 40in length and stores it in 41.Fa rnd . 42If 43.Fa top 44is -1, the most significant bit of the random number can be zero. 45If 46.Fa top 47is 0, it is set to 1, and if 48.Fa top 49is 1, the two most significant bits of the number will be set to 1, so 50that the product of two such random numbers will always have 51.Pf 2* Fa bits 52length. 53If 54.Fa bottom 55is true, the number will be odd. 56.Pp 57.Fn BN_pseudo_rand 58does the same, but pseudo-random numbers generated by this function are 59not necessarily unpredictable. 60They can be used for non-cryptographic purposes and for certain purposes 61in cryptographic protocols, but usually not for key generation etc. 62.Pp 63.Fn BN_rand_range 64generates a cryptographically strong pseudo-random number 65.Fa rnd 66in the range 0 <= 67.Fa rnd No < Fa range . 68.Fn BN_pseudo_rand_range 69does the same, but is based on 70.Fn BN_pseudo_rand , 71and hence numbers generated by it are not necessarily unpredictable. 72.Sh RETURN VALUES 73The functions return 1 on success, 0 on error. 74The error codes can be obtained by 75.Xr ERR_get_error 3 . 76.Sh SEE ALSO 77.Xr bn 3 , 78.Xr ERR_get_error 3 , 79.Xr rand 3 , 80.Xr RAND_add 3 , 81.Xr RAND_bytes 3 82.Sh HISTORY 83.Fn BN_rand 84is available in all versions of SSLeay and OpenSSL. 85.Fn BN_pseudo_rand 86was added in OpenSSL 0.9.5. 87The 88.Fa top 89== -1 case and the function 90.Fn BN_rand_range 91were added in OpenSSL 0.9.6a. 92.Fn BN_pseudo_rand_range 93was added in OpenSSL 0.9.6c. 94