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

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

<h1>RSA_check_key(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_VALUE">RETURN VALUE</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#BUGS">BUGS</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>
RSA_check_key - validate private RSA keys

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/rsa.h&gt;
</PRE>
<PRE> int RSA_check_key(RSA *rsa);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
This function validates RSA keys. It checks that <STRONG>p</STRONG> and <STRONG>q</STRONG> are in fact prime, and that <STRONG>n = p*q</STRONG>.

</P>
<P>
It also checks that <STRONG>d*e = 1 mod (p-1*q-1)</STRONG>, and that <STRONG>dmp1</STRONG>, <STRONG>dmq1</STRONG> and <STRONG>iqmp</STRONG> are set correctly or are <STRONG>NULL</STRONG>.

</P>
<P>
As such, this function can not be used with any arbitrary RSA key object,
even if it is otherwise fit for regular RSA operation. See <STRONG>NOTES</STRONG> for more information.

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUE">RETURN VALUE</A></H1>
<P>
<CODE>RSA_check_key()</CODE> returns 1 if <STRONG>rsa</STRONG> is a valid RSA key, and 0 otherwise. -1 is returned if an error occurs
while checking the key.

</P>
<P>
If the key is invalid or an error occurred, the reason code can be obtained
using <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
This function does not work on RSA public keys that have only the modulus
and public exponent elements populated. It performs integrity checks on all
the RSA key material, so the RSA key structure must contain all the private
key data too.

</P>
<P>
Unlike most other RSA functions, this function does <STRONG>not</STRONG> work transparently with any underlying ENGINE implementation because it
uses the key data in the RSA structure directly. An ENGINE implementation
can override the way key data is stored and handled, and can even provide
support for HSM keys - in which case the RSA structure may contain <STRONG>no</STRONG>
key data at all! If the ENGINE in question is only being used for
acceleration or analysis purposes, then in all likelihood the RSA key data
is complete and untouched, but this can't be assumed in the general case.

</P>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
A method of verifying the RSA key using opaque RSA API functions might need
to be considered. Right now <CODE>RSA_check_key()</CODE> simply uses the
RSA structure elements directly, bypassing the RSA_METHOD table altogether
(and completely violating encapsulation and object-orientation in the
process). The best fix will probably be to introduce a ``check_key()''
handler to the RSA_METHOD function table so that alternative
implementations can also provide their own verifiers.

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



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>RSA_check_key()</CODE> appeared in OpenSSL 0.9.4.

</P>
:}


