Sortix
Sortix Download Manual Development Source Code News Blog More
current nightly

Sortix nightly manual

This manual documents Sortix nightly, a development build that has not been officially released. You can instead view this document in the latest official manual.

NAME

BN_mod_inverse — compute inverse modulo m

SYNOPSIS

#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.
Copyright 2011-2025 Jonas 'Sortie' Termansen and contributors.
Sortix's source code is free software under the ISC license.
#sortix on irc.sortix.org
@sortix_org