BN_BLINDING_NEW(3ossl)

πŸ“¦
version 15.1 Β· 3 versions
, in freebsd 15.1

πŸ’… BN_BLINDING_NEW β€” the blinding glow-up for BIGNUM (3ossl) πŸ’…

okay bestie, welcome to the OpenSSL section of the group chat β€” this one's a 3ossl page and it's all about blinding, which is genuinely one of the most underrated hyped things in crypto. lowkey iconic. let's get into it 🫢


✨ NAME ✨

BN_BLINDING_new, BN_BLINDING_free, BN_BLINDING_update, BN_BLINDING_convert, BN_BLINDING_invert, BN_BLINDING_convert_ex, BN_BLINDING_invert_ex, BN_BLINDING_is_current_thread, BN_BLINDING_set_current_thread, BN_BLINDING_lock, BN_BLINDING_unlock, BN_BLINDING_get_flags, BN_BLINDING_set_flags, BN_BLINDING_create_param β€” the blinding-related BIGNUM functions, aka the whole squad πŸ’œ


🌸 SYNOPSIS 🌸

#include <openssl/bn.h>

BN_BLINDING *BN_BLINDING_new(const BIGNUM *A, const BIGNUM *Ai,
                             BIGNUM *mod);
void BN_BLINDING_free(BN_BLINDING *b);
int BN_BLINDING_update(BN_BLINDING *b, BN_CTX *ctx);
int BN_BLINDING_convert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
int BN_BLINDING_invert(BIGNUM *n, BN_BLINDING *b, BN_CTX *ctx);
int BN_BLINDING_convert_ex(BIGNUM *n, BIGNUM *r, BN_BLINDING *b,
                           BN_CTX *ctx);
int BN_BLINDING_invert_ex(BIGNUM *n, const BIGNUM *r, BN_BLINDING *b,
                          BN_CTX *ctx);
int BN_BLINDING_is_current_thread(BN_BLINDING *b);
void BN_BLINDING_set_current_thread(BN_BLINDING *b);
int BN_BLINDING_lock(BN_BLINDING *b);
int BN_BLINDING_unlock(BN_BLINDING *b);
unsigned long BN_BLINDING_get_flags(const BN_BLINDING *b);
void BN_BLINDING_set_flags(BN_BLINDING *b, unsigned long flags);
BN_BLINDING *BN_BLINDING_create_param(BN_BLINDING *b,
                                      const BIGNUM *e, BIGNUM *m, BN_CTX *ctx,
                                      int (*bn_mod_exp)(BIGNUM *r,
                                                        const BIGNUM *a,
                                                        const BIGNUM *p,
                                                        const BIGNUM *m,
                                                        BN_CTX *ctx,
                                                        BN_MONT_CTX *m_ctx),
                                      BN_MONT_CTX *m_ctx);

no cap, that last one is a whole paragraph of a function signature but we move πŸ’€


πŸ¦‹ DESCRIPTION πŸ¦‹

so. BN_BLINDING_new() is the main character here β€” it allocates a fresh BN_BLINDING structure and copies the A and Ai values right on into the newly created BN_BLINDING object. she's born ready ✨

BN_BLINDING_free() frees the BN_BLINDING structure. and if b is NULL? nothing happens. nothing. zero. she just vibes πŸ™ˆ

BN_BLINDING_update() updates the BN_BLINDING parameters by squaring the A and Ai β€” or, after a specific number of uses and if the necessary parameters are set, by re-creating the blinding parameters. glow-up either way πŸ’…

BN_BLINDING_convert_ex() multiplies n with the blinding factor A. and here's the cute part β€” if r is not NULL, a copy of the inverse blinding factor Ai gets returned in r. (this is lowkey useful if an RSA object is shared among several threads, iykyk 🧡). then BN_BLINDING_invert_ex() multiplies n with the inverse blinding factor Ai. and if r is not NULL, it gets used as the inverse blinding.

BN_BLINDING_convert() and BN_BLINDING_invert() are just wrapper functions for BN_BLINDING_convert_ex() and BN_BLINDING_invert_ex() with r set to NULL. short kings, still valid πŸ‘‘

BN_BLINDING_is_current_thread() returns whether the BN_BLINDING structure is owned by the current thread. why do we care? because it helps users provide proper locking if needed for multi-threaded use. bestie, if needed is doing a lot of work in that sentence, keep it in mind 🫢

BN_BLINDING_set_current_thread() sets the current thread as the owner of the BN_BLINDING structure. claim your territory πŸ’–

BN_BLINDING_lock() locks the BN_BLINDING structure.

BN_BLINDING_unlock() unlocks the BN_BLINDING structure. (they're a matching set, it's giving coordinated outfit 🌈)

BN_BLINDING_get_flags() returns the BN_BLINDING flags. currently there are two supported flags: BN_BLINDING_NO_UPDATE and BN_BLINDING_NO_RECREATE. let me spell it out:

  • BN_BLINDING_NO_UPDATE inhibits the automatic update of the BN_BLINDING parameters after each use
  • BN_BLINDING_NO_RECREATE inhibits the automatic re-creation of the BN_BLINDING parameters after a fixed number of uses (currently 32)

and in newly allocated BN_BLINDING objects, no flags are set β€” blank slate energy 🌸

BN_BLINDING_set_flags() sets the BN_BLINDING parameters flags. slay.

BN_BLINDING_create_param() creates new BN_BLINDING parameters using the exponent e and the modulus m. bn_mod_exp and m_ctx can be used to pass special functions for exponentiation (normally BN_mod_exp_mont() and BN_MONT_CTX).


πŸ”₯ RETURN VALUES πŸ”₯

okay so what do these actually hand back:

  • BN_BLINDING_new() returns the newly allocated BN_BLINDING structure, or NULL in case of an error 😭
  • BN_BLINDING_update(), BN_BLINDING_convert(), BN_BLINDING_invert(), BN_BLINDING_convert_ex() and BN_BLINDING_invert_ex() return 1 on success and 0 if an error occurred
  • BN_BLINDING_is_current_thread() returns 1 if the current thread owns the BN_BLINDING object, 0 otherwise
  • BN_BLINDING_set_current_thread() doesn't return anything. nothing. void. ghosted πŸ’€
  • BN_BLINDING_lock(), BN_BLINDING_unlock() return 1 if the operation succeeded or 0 on error
  • BN_BLINDING_get_flags() returns the currently set BN_BLINDING flags (an unsigned long value)
  • BN_BLINDING_create_param() returns the newly created BN_BLINDING parameters or NULL on error

πŸŽ€ HISTORY πŸŽ€

storytime: BN_BLINDING_thread_id() was first introduced in OpenSSL 1.0.0, and it deprecates BN_BLINDING_set_thread_id() and BN_BLINDING_get_thread_id(). out with the old, in with the new, periodt πŸ’…


Copyright 2005-2017 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 page bestie 🫢 this one's from OpenSSL 3.5.6, dated 2026-04-07 β€” go blind some BIGNUMs responsibly, mwah πŸ’–βœ¨

πŸ“¦ where this page comes from