BN_RAND(3)
π BN_RAND(3) π
okay so bestie, this is a page from the Library Functions Manual β yes, that's the manual name β and it's all about libcrypto making pseudo-random numbers. buckle up, it's giving crypto girlie π
.
πΈ NAME πΈ
BN_rand, BN_rand_range, BN_pseudo_rand, BN_pseudo_rand_range β generate pseudo-random number
β¨ SYNOPSIS β¨
The page says it's from libcrypto and prints this exact synopsis:
library βlibcryptoβ #include <openssl/bn.h>
int
BN_rand(BIGNUM *rnd, int bits, int top, int bottom);
int
BN_rand_range(BIGNUM *rnd, const BIGNUM *range);
π¦ DESCRIPTION π¦
BN_rand() is the main character: it generates a cryptographically strong pseudo-random number of bits in length and stores it in rnd. The top parameter has three moods:
- If
topisBN_RAND_TOP_ANY, the most significant bit of the random number can be zero. - If
topisBN_RAND_TOP_ONE, the most significant bit is set to1. - If
topisBN_RAND_TOP_TWO, the two most significant bits of the number will be set to1, so that the product of two such random numbers will always have2*bitslength.
Then there's bottom, which is its own little vibe check:
- If
bottomisBN_RAND_BOTTOM_ODD, the number will be odd. - If it is
BN_RAND_BOTTOM_ANY, it can be odd or even.
Real talk: the value of bits must be zero or greater. If bits is +1 then top cannot be BN_RAND_TOP_TWO. periodt.
BN_rand_range() generates a cryptographically strong pseudo-random number rnd in the range 0 <= rnd < range.
Also heads up: BN_pseudo_rand() is a deprecated alias for BN_rand(), and BN_pseudo_rand_range() for BN_rand_range(). yes, deprecated β the manual says so, so treat those as the old names.
π RETURN VALUES π
The functions return 1 on success, 0 on error. The error codes can be obtained by ERR_get_error(3).
π«Ά SEE ALSO π«Ά
π HISTORY π
BN_rand() first appeared in SSLeay 0.5.1 and has been available since OpenBSD 2.4.
The top == -1 case and the function BN_rand_range() first appeared in OpenSSL 0.9.6a and have been available since OpenBSD 3.0.
π from Debian, dated June 8, 2025 β this page is BN_RAND(3) β byeee, bestie π«Ά
π¦ where this page comes from
- alpine 3.24: libressl-doc 4.3.1-r0 Β· custom
- arch rolling: libressl 4.4.0-1 Β· ISC AND custom:OpenSSL
- Copyright (c) 2000, 2001, 2002, 2013, 2015 The OpenSSL Project
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms