BN_SET_FLAGS(3)
π BN_SET_FLAGS β bestie's guide to BIGNUM flags β¨
okay so this is from BN_SET_FLAGS(3), part of the Library Functions Manual β yes, the Library Functions Manual, we're being fancy today π β and it's literally all about turning flags on and peeking at them on BIGNUM objects. no cap.
β¨ NAME β¨
BN_set_flags, BN_get_flags β enable and inspect flags on BIGNUM objects π¦
πΈ SYNOPSIS πΈ
it's giving "library βlibcryptoβ" energy first, then:
#include <openssl/bn.h>
void
BN_set_flags(BIGNUM *b, int flags);
int
BN_get_flags(const BIGNUM *b, int flags);
π DESCRIPTION π
so BN_set_flags() enables the given flags on b. and the flags argument can contain zero or more of the following constants OR'ed together (yes, zero is allowed, she can be empty, we support her π):
BN_FLG_CONSTTIMEβ if this flag is set on the dividendaor the divisordinBN_div(3), on the exponentpinBN_mod_exp(3), or on the divisoraor the modulusninBN_mod_inverse(3), these functions pick algorithms whose execution time is independent of the respective numbers. which is the whole point: avoid exposing sensitive info to timing side-channel attacks π₯. this flag is off by default forBIGNUMobjects created withBN_new(3).BN_FLG_MALLOCEDβ if this flag is set,BN_free(3)andBN_clear_free(3)will not only clear and free the components ofb, but alsobitself, like, the whole girl π. this flag is set internally byBN_new(3). setting it manually on an existingBIGNUMobject is usually a bad idea and can cause calls tofree(3)with bogus arguments. soβ¦ don't π.BN_FLG_STATIC_DATAβ if this flag is set,BN_clear_free(3)will neither clear nor free the memory used for storing the number. consequently, setting it manually on an existingBIGNUMobject is usually a terrible idea that can cause both disclosure of secret data and memory leaks. two for one, but the bad kind π. this flag is automatically set on the constantBIGNUMobject returned byBN_value_one(3).
and BN_get_flags() interprets flags as a bitmask and returns those of the given flags that are set in b, OR'ed together β or 0 if none of the given flags is set. the flags argument has the same syntax as for BN_set_flags(). iykyk π
β RETURN VALUES β
BN_get_flags() returns zero or more of the above constants, OR'ed together. that's it, that's the return value π«Ά
π SEE ALSO π
BN_mod_exp(3), BN_mod_inverse(3), BN_new(3), BN_with_flags(3) β go read those too, be a well-read icon π
π§ HISTORY π§
BN_set_flags() and BN_get_flags() first appeared in SSLeay 0.9.1 and have been available since OpenBSD 2.6. ancient. iconic. still serving β
π CAVEATS π
no public interface exists to clear a flag once it is set. like, once it's on, it's ON, no take-backs. so think twice before using BN_set_flags(). fr fr.
π BUGS π
- even if the
BN_FLG_CONSTTIMEflag is set onaorb,BN_gcd()neither fails nor operates in constant time β potentially allowing timing side-channel attacks. not her finest moment π¬. - even if the
BN_FLG_CONSTTIMEflag is set onp, if the modulusmis even,BN_mod_exp(3)does not operate in constant time, potentially allowing timing side-channel attacks. the even modulus really said "not today" π. - if
BN_FLG_CONSTTIMEis set onp,BN_exp()fails instead of operating in constant time. at least she's honest about it π.
and that's the whole page, bestie π«Ά this one's from Debian, dated June 8, 2025 β slay, go set your flags responsibly, and remember: you can't unset them π β¨
π¦ 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) 2017 Ingo Schwarze <schwarze@openbsd.org>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms