BN_SET_BIT(3SSL)
π BN_SET_BIT(3SSL) β bit ops on BIGNUMs, bestie edition
okay so you've found yourself in the OpenSSL manual, section 3SSL, staring at a page all about poking individual bits inside a BIGNUM. genuinely iconic behavior. let's get into it β¨
π NAME
BN_set_bit, BN_clear_bit, BN_is_bit_set, BN_mask_bits, BN_lshift, BN_lshift1, BN_rshift, BN_rshift1 β bit operations on BIGNUMs π¦
β¨ SYNOPSIS
#include <openssl/bn.h>
int BN_set_bit(BIGNUM *a, int n);
int BN_clear_bit(BIGNUM *a, int n);
int BN_is_bit_set(const BIGNUM *a, int n);
int BN_mask_bits(BIGNUM *a, int n);
int BN_lshift(BIGNUM *r, const BIGNUM *a, int n);
int BN_lshift1(BIGNUM *r, BIGNUM *a);
int BN_rshift(BIGNUM *r, BIGNUM *a, int n);
int BN_rshift1(BIGNUM *r, BIGNUM *a);
look at all those little guys. each one is a whole personality, fr fr π
πΈ DESCRIPTION
BN_set_bit() β flips bit n in a to 1, which is literally just a|=(1<<n) if you wanna think about it that way. and if the number needs to grow to hold that bit? it just grows. no drama, she expands π«Ά
BN_clear_bit() β flips bit n in a to 0, aka a&=~(1<<n). β οΈ but heads up bestie: if a is shorter than n bits, that's an error. she can't clear a bit that isn't there π
BN_is_bit_set() β the vibe check π asks the question: is bit n in a actually set? that's it, that's the whole job.
BN_mask_bits() β truncates a down to an n bit number, mathematically a&=~((~0)<<n). βοΈ two ways to fail here: an error happens if n is negative, and an error is also returned if the internal representation of a is already shorter than n bits. and now the tea β β that internal representation depends on the platform's word size, so that particular error can be safely ignored. if you actually need the exact number of bits, go use BN_num_bits(3). iykyk π
BN_lshift() β shifts a left by n bits and drops the result into r, i.e. r=a*2^n. note that n must be nonnegative π¨
BN_lshift1() β shifts a left by exactly one and puts the result in r, i.e. r=2*a. one bit. tiny move. ate π
BN_rshift() β shifts a right by n bits and places the result in r, i.e. r=a/2^n. and again, note that n must be nonnegative π¨
BN_rshift1() β shifts a right by one and places the result in r, i.e. r=a/2. π
β¨ cute lil bonus fact for the shift functions:randamay be the same variable. in-place era, no cap π
π RETURN VALUES
BN_is_bit_set()returns1if the bit is set,0otherwise.- everything else returns
1for success and0on error. π - need the actual error codes? grab them with
ERR_get_error(3). periodt.
π SEE ALSO
go read those too, they're giving main character energy π§
π COPYRIGHT
Copyright 2000-2024 The OpenSSL Project Authors. All Rights Reserved. β
Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.
and that's the whole page, bestie!! π this was BN_SET_BIT(3SSL) from OpenSSL 4.0.3 and the page is dated 2026-09-29 β so go set some bits, clear some bits, shift things around, and stay slay πβ¨π¦
π¦ where this page comes from
- ubuntu stonking: libssl-doc 4.0.3-1ubuntu1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms