---
name: "libressl-BN_mod_inverse"
section: "3"
platform: "linux"
package: "libressl"
version: "4.4.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/libressl-BN_mod_inverse"
---

# libressl-BN\_mod\_inverse(3)

compute inverse modulo m

## NAME

**BN\_mod\_inverse** – compute inverse modulo m

## SYNOPSIS

Crypto Library (libcrypto, -lcrypto)

**#include \<openssl/bn.h\>**

*BIGNUM* *\**\

**BN\_mod\_inverse**(*BIGNUM \*r*, *const BIGNUM \*a*, *const BIGNUM \*m*, *BN\_CTX \*ctx*);

## DESCRIPTION

**BN\_mod\_inverse**() computes the inverse of *a* modulo *m* and places the result in *r*, so that *r* satisfies a \* r == 1 (mod m). If *r* is NULL, a new *BIGNUM* is allocated.

If the flag BN\_FLG\_CONSTTIME is set on *a* or *m*, it operates in constant time.

*ctx* is a previously allocated *BN\_CTX* used for temporary variables. *r* may be the same *BIGNUM* as *a* or *m*.

## RETURN VALUES

**BN\_mod\_inverse**() returns the *BIGNUM* containing the inverse, or NULL on error. The error codes can be obtained by ERR\_get\_error(3).

## SEE ALSO

BN\_add(3), BN\_new(3), BN\_set\_flags(3)

## HISTORY

**BN\_mod\_inverse**() first appeared in SSLeay 0.5.1 and has been available since OpenBSD 2.4.

The *r* argument was added in SSLeay 0.9.1 and OpenBSD 2.6.
