BN_MOD_INVERSE(3ossl)

πŸ“¦ version 3.5.0, in opensuse-leap 16.0

πŸ’… BN_MOD_INVERSE β€” compute inverse modulo n

okay so this page lives in the 3ossl manual section (that's the OpenSSL one, iykyk), and bestie, it's literally just one function that does one iconic little thing. let's get into it πŸŽ€


✨ SYNOPSIS ✨

#include <openssl/bn.h>

BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
                       BN_CTX *ctx);

🌸 DESCRIPTION 🌸

so BN_mod_inverse() computes the inverse of a modulo n and places the result in r. and the vibe it's going for is:

(a*r)%n==1

like that's the whole goal. that's the dream. 🫢

if r is NULL, a brand-new BIGNUM gets created for you β€” no cap, it just spawns one. main character energy fr.

ctx is a previously allocated BN_CTX used for temporary variables. think of it as the backstage dressing room where all the scratch work happens. ✨

and here's a fun little detail: r may be the same BIGNUM as a. yes bestie, they can share. it's fine. πŸ’…


πŸ’€ NOTES πŸ’€

it is an error to use the same BIGNUM as n. do not do this. i'm so serious. πŸ™ˆ

πŸ”₯ RETURN VALUES πŸ”₯

BN_mod_inverse() returns the BIGNUM containing the inverse, and NULL on error. slay when it works, NULL when it doesn't 😭

the error codes can be obtained by ERR_get_error(3) β€” go look 'em up if you need the tea. πŸ‘‘


πŸ¦‹ SEE ALSO πŸ¦‹


Copyright 2000-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 whole page, bestie 🌈 β€” brought to you by 3.5.0, dated 2026-09-25, from your fave BN_MOD_INVERSE(3ossl) girlies. periodt. πŸ’œ

πŸ“¦ where this page comes from