RSA_check_key.pod 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. =pod
  2. =head1 NAME
  3. RSA_check_key_ex, RSA_check_key - validate private RSA keys
  4. =head1 SYNOPSIS
  5. #include <openssl/rsa.h>
  6. int RSA_check_key_ex(RSA *rsa, BN_GENCB *cb);
  7. int RSA_check_key(RSA *rsa);
  8. =head1 DESCRIPTION
  9. RSA_check_key_ex() function validates RSA keys.
  10. It checks that B<p> and B<q> are
  11. in fact prime, and that B<n = p*q>.
  12. It does not work on RSA public keys that have only the modulus
  13. and public exponent elements populated.
  14. It also checks that B<d*e = 1 mod (p-1*q-1)>,
  15. and that B<dmp1>, B<dmq1> and B<iqmp> are set correctly or are B<NULL>.
  16. It performs integrity checks on all
  17. the RSA key material, so the RSA key structure must contain all the private
  18. key data too.
  19. Therefore, it cannot be used with any arbitrary RSA key object,
  20. even if it is otherwise fit for regular RSA operation.
  21. The B<cb> parameter is a callback that will be invoked in the same
  22. manner as L<BN_is_prime_ex(3)>.
  23. RSA_check_key() is equivalent to RSA_check_key_ex() with a NULL B<cb>.
  24. =head1 RETURN VALUES
  25. RSA_check_key_ex() and RSA_check_key()
  26. return 1 if B<rsa> is a valid RSA key, and 0 otherwise.
  27. They return -1 if an error occurs while checking the key.
  28. If the key is invalid or an error occurred, the reason code can be
  29. obtained using L<ERR_get_error(3)>.
  30. =head1 NOTES
  31. Unlike most other RSA functions, this function does B<not> work
  32. transparently with any underlying ENGINE implementation because it uses the
  33. key data in the RSA structure directly. An ENGINE implementation can
  34. override the way key data is stored and handled, and can even provide
  35. support for HSM keys - in which case the RSA structure may contain B<no>
  36. key data at all! If the ENGINE in question is only being used for
  37. acceleration or analysis purposes, then in all likelihood the RSA key data
  38. is complete and untouched, but this can't be assumed in the general case.
  39. =head1 BUGS
  40. A method of verifying the RSA key using opaque RSA API functions might need
  41. to be considered. Right now RSA_check_key() simply uses the RSA structure
  42. elements directly, bypassing the RSA_METHOD table altogether (and
  43. completely violating encapsulation and object-orientation in the process).
  44. The best fix will probably be to introduce a "check_key()" handler to the
  45. RSA_METHOD function table so that alternative implementations can also
  46. provide their own verifiers.
  47. =head1 SEE ALSO
  48. L<BN_is_prime_ex(3)>,
  49. L<ERR_get_error(3)>
  50. =head1 HISTORY
  51. RSA_check_key_ex() appeared after OpenSSL 1.0.2.
  52. =head1 COPYRIGHT
  53. Copyright 2000-2018 The OpenSSL Project Authors. All Rights Reserved.
  54. Licensed under the Apache License 2.0 (the "License"). You may not use
  55. this file except in compliance with the License. You can obtain a copy
  56. in the file LICENSE in the source distribution or at
  57. L<https://www.openssl.org/source/license.html>.
  58. =cut