RSA_check_key.pod 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. =pod
  2. =head1 NAME
  3. RSA_check_key - validate private RSA keys
  4. =head1 SYNOPSIS
  5. #include <openssl/rsa.h>
  6. int RSA_check_key(RSA *rsa);
  7. =head1 DESCRIPTION
  8. This function validates RSA keys. It checks that B<p> and B<q> are
  9. in fact prime, and that B<n = p*q>.
  10. It also checks that B<d*e = 1 mod (p-1*q-1)>,
  11. and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
  12. As such, this function can not be used with any arbitrary RSA key object,
  13. even if it is otherwise fit for regular RSA operation. See B<NOTES> for more
  14. information.
  15. =head1 RETURN VALUE
  16. RSA_check_key() returns 1 if B<rsa> is a valid RSA key, and 0 otherwise.
  17. -1 is returned if an error occurs while checking the key.
  18. If the key is invalid or an error occurred, the reason code can be
  19. obtained using L<ERR_get_error(3)|ERR_get_error(3)>.
  20. =head1 NOTES
  21. This function does not work on RSA public keys that have only the modulus
  22. and public exponent elements populated. It performs integrity checks on all
  23. the RSA key material, so the RSA key structure must contain all the private
  24. key data too.
  25. Unlike most other RSA functions, this function does B<not> work
  26. transparently with any underlying ENGINE implementation because it uses the
  27. key data in the RSA structure directly. An ENGINE implementation can
  28. override the way key data is stored and handled, and can even provide
  29. support for HSM keys - in which case the RSA structure may contain B<no>
  30. key data at all! If the ENGINE in question is only being used for
  31. acceleration or analysis purposes, then in all likelihood the RSA key data
  32. is complete and untouched, but this can't be assumed in the general case.
  33. =head1 BUGS
  34. A method of verifying the RSA key using opaque RSA API functions might need
  35. to be considered. Right now RSA_check_key() simply uses the RSA structure
  36. elements directly, bypassing the RSA_METHOD table altogether (and
  37. completely violating encapsulation and object-orientation in the process).
  38. The best fix will probably be to introduce a "check_key()" handler to the
  39. RSA_METHOD function table so that alternative implementations can also
  40. provide their own verifiers.
  41. =head1 SEE ALSO
  42. L<rsa(3)|rsa(3)>, L<ERR_get_error(3)|ERR_get_error(3)>
  43. =head1 HISTORY
  44. RSA_check_key() appeared in OpenSSL 0.9.4.
  45. =cut