
#use wml::openssl-macros area=docs page=BN_mod_inverse

<title>Documents, BN_mod_inverse(3)</title>

<h1>BN_mod_inverse(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
BN_mod_inverse - compute inverse modulo n

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/bn.h&gt;
</PRE>
<PRE> BIGNUM *BN_mod_inverse(BIGNUM *r, BIGNUM *a, const BIGNUM *n,
           BN_CTX *ctx);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>BN_mod_inverse()</CODE> computes the inverse of <STRONG>a</STRONG> modulo <STRONG>n</STRONG>
places the result in <STRONG>r</STRONG> (<CODE>(a*r)%n==1</CODE>). If <STRONG>r</STRONG> is NULL, a new <STRONG>BIGNUM</STRONG> is created.

</P>
<P>
<STRONG>ctx</STRONG> is a previously allocated <STRONG>BN_CTX</STRONG> used for temporary variables. <STRONG>r</STRONG> may be the same <STRONG>BIGNUM</STRONG> as <STRONG>a</STRONG> or <STRONG>n</STRONG>.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>BN_mod_inverse()</CODE> returns the <STRONG>BIGNUM</STRONG> containing the inverse, and NULL on error. The error codes can be obtained
by <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/bn.html#">bn(3)</A>, <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>, <A HREF="../crypto/BN_add.html#">BN_add(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>BN_mod_inverse()</CODE> is available in all versions of SSLeay and
OpenSSL.

</P>
:}

