EVP_PKEY_is_a.pod 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_is_a, EVP_PKEY_can_sign, EVP_PKEY_type_names_do_all,
  4. EVP_PKEY_get0_type_name, EVP_PKEY_get0_description, EVP_PKEY_get0_provider
  5. - key type and capabilities functions
  6. =head1 SYNOPSIS
  7. #include <openssl/evp.h>
  8. int EVP_PKEY_is_a(const EVP_PKEY *pkey, const char *name);
  9. int EVP_PKEY_can_sign(const EVP_PKEY *pkey);
  10. int EVP_PKEY_type_names_do_all(const EVP_PKEY *pkey,
  11. void (*fn)(const char *name, void *data),
  12. void *data);
  13. const char *EVP_PKEY_get0_type_name(const EVP_PKEY *key);
  14. const char *EVP_PKEY_get0_description(const EVP_PKEY *key);
  15. const OSSL_PROVIDER *EVP_PKEY_get0_provider(const EVP_PKEY *key);
  16. =head1 DESCRIPTION
  17. EVP_PKEY_is_a() checks if the key type of I<pkey> is I<name>.
  18. EVP_PKEY_can_sign() checks if the functionality for the key type of
  19. I<pkey> supports signing. No other check is done, such as whether
  20. I<pkey> contains a private key.
  21. EVP_PKEY_type_names_do_all() traverses all names for I<pkey>'s key type, and
  22. calls I<fn> with each name and I<data>. For example, an RSA B<EVP_PKEY> may
  23. be named both C<RSA> and C<rsaEncryption>.
  24. The order of the names depends on the provider implementation that holds
  25. the key.
  26. EVP_PKEY_get0_type_name() returns the first key type name that is found
  27. for the given I<pkey>. Note that the I<pkey> may have multiple synonyms
  28. associated with it. In this case it depends on the provider implementation
  29. that holds the key which one will be returned.
  30. Ownership of the returned string is retained by the I<pkey> object and should
  31. not be freed by the caller.
  32. EVP_PKEY_get0_description() returns a description of the type of B<EVP_PKEY>,
  33. meant for display and human consumption. The description is at the
  34. discretion of the key type implementation.
  35. EVP_PKEY_get0_provider() returns the provider of the B<EVP_PKEY>'s
  36. L<EVP_KEYMGMT(3)>.
  37. =head1 RETURN VALUES
  38. EVP_PKEY_is_a() returns 1 if I<pkey> has the key type I<name>,
  39. otherwise 0.
  40. EVP_PKEY_can_sign() returns 1 if the I<pkey> key type functionality
  41. supports signing, otherwise 0.
  42. EVP_PKEY_get0_type_name() returns the name that is found or NULL on error.
  43. EVP_PKEY_get0_description() returns the description if found or NULL if not.
  44. EVP_PKEY_get0_provider() returns the provider if found or NULL if not.
  45. EVP_PKEY_type_names_do_all() returns 1 if the callback was called for all
  46. names. A return value of 0 means that the callback was not called for any
  47. names.
  48. =head1 EXAMPLES
  49. =head2 EVP_PKEY_is_a()
  50. The loaded providers and what key types they support will ultimately
  51. determine what I<name> is possible to use with EVP_PKEY_is_a(). We do know
  52. that the default provider supports RSA, DH, DSA and EC keys, so we can use
  53. this as an crude example:
  54. #include <openssl/evp.h>
  55. ...
  56. /* |pkey| is an EVP_PKEY* */
  57. if (EVP_PKEY_is_a(pkey, "RSA")) {
  58. BIGNUM *modulus = NULL;
  59. if (EVP_PKEY_get_bn_param(pkey, "n", &modulus))
  60. /* do whatever with the modulus */
  61. BN_free(modulus);
  62. }
  63. =head2 EVP_PKEY_can_sign()
  64. #include <openssl/evp.h>
  65. ...
  66. /* |pkey| is an EVP_PKEY* */
  67. if (!EVP_PKEY_can_sign(pkey)) {
  68. fprintf(stderr, "Not a signing key!");
  69. exit(1);
  70. }
  71. /* Sign something... */
  72. =head1 HISTORY
  73. The functions described here were added in OpenSSL 3.0.
  74. =head1 COPYRIGHT
  75. Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
  76. Licensed under the Apache License 2.0 (the "License"). You may not use
  77. this file except in compliance with the License. You can obtain a copy
  78. in the file LICENSE in the source distribution or at
  79. L<https://www.openssl.org/source/license.html>.
  80. =cut