EVP_PKEY_gettable_params.pod 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_gettable_params, EVP_PKEY_get_params,
  4. EVP_PKEY_get_int_param, EVP_PKEY_get_size_t_param,
  5. EVP_PKEY_get_bn_param, EVP_PKEY_get_utf8_string_param,
  6. EVP_PKEY_get_octet_string_param
  7. - retrieve key parameters from a key
  8. =head1 SYNOPSIS
  9. #include <openssl/evp.h>
  10. const OSSL_PARAM *EVP_PKEY_gettable_params(EVP_PKEY *pkey);
  11. int EVP_PKEY_get_params(const EVP_PKEY *pkey, OSSL_PARAM params[]);
  12. int EVP_PKEY_get_int_param(const EVP_PKEY *pkey, const char *key_name,
  13. int *out);
  14. int EVP_PKEY_get_size_t_param(const EVP_PKEY *pkey, const char *key_name,
  15. size_t *out);
  16. int EVP_PKEY_get_bn_param(const EVP_PKEY *pkey, const char *key_name,
  17. BIGNUM **bn);
  18. int EVP_PKEY_get_utf8_string_param(const EVP_PKEY *pkey, const char *key_name,
  19. char *str, size_t max_buf_sz,
  20. size_t *out_len);
  21. int EVP_PKEY_get_octet_string_param(const EVP_PKEY *pkey, const char *key_name,
  22. unsigned char *buf, size_t max_buf_sz,
  23. size_t *out_len);
  24. =head1 DESCRIPTION
  25. EVP_PKEY_get_params() retrieves parameters from the key I<pkey>, according to
  26. the contents of I<params>.
  27. See L<OSSL_PARAM(3)> for information about parameters.
  28. EVP_PKEY_gettable_params() returns a constant list of I<params> indicating
  29. the names and types of key parameters that can be retrieved.
  30. See L<OSSL_PARAM(3)> for information about parameters.
  31. An B<OSSL_PARAM> of type B<OSSL_PARAM_INTEGER> or
  32. B<OSSL_PARAM_UNSIGNED_INTEGER> is of arbitrary length. Such a parameter can be
  33. obtained using any of the functions EVP_PKEY_get_int_param(),
  34. EVP_PKEY_get_size_t_param() or EVP_PKEY_get_bn_param(). Attempting to
  35. obtain an integer value that does not fit into a native C B<int> type will cause
  36. EVP_PKEY_get_int_param() to fail. Similarly attempting to obtain an integer
  37. value that is negative or does not fit into a native C B<size_t> type using
  38. EVP_PKEY_get_size_t_param() will also fail.
  39. EVP_PKEY_get_int_param() retrieves a key I<pkey> integer value I<*out>
  40. associated with a name of I<key_name> if it fits into C<int> type. For
  41. parameters that do not fit into C<int> use EVP_PKEY_get_bn_param().
  42. EVP_PKEY_get_size_t_param() retrieves a key I<pkey> size_t value I<*out>
  43. associated with a name of I<key_name> if it fits into C<size_t> type. For
  44. parameters that do not fit into C<size_t> use EVP_PKEY_get_bn_param().
  45. EVP_PKEY_get_bn_param() retrieves a key I<pkey> BIGNUM value I<**bn>
  46. associated with a name of I<key_name>. If I<*bn> is NULL then the BIGNUM
  47. is allocated by the method.
  48. EVP_PKEY_get_utf8_string_param() get a key I<pkey> UTF8 string value into a
  49. buffer I<str> of maximum size I<max_buf_sz> associated with a name of
  50. I<key_name>. The maximum size must be large enough to accommodate the string
  51. value including a terminating NUL byte, or this function will fail.
  52. If I<out_len> is not NULL, I<*out_len> is set to the length of the string
  53. not including the terminating NUL byte. The required buffer size not including
  54. the terminating NUL byte can be obtained from I<*out_len> by calling the
  55. function with I<str> set to NULL.
  56. EVP_PKEY_get_octet_string_param() get a key I<pkey>'s octet string value into a
  57. buffer I<buf> of maximum size I<max_buf_sz> associated with a name of I<key_name>.
  58. If I<out_len> is not NULL, I<*out_len> is set to the length of the contents.
  59. The required buffer size can be obtained from I<*out_len> by calling the
  60. function with I<buf> set to NULL.
  61. =head1 NOTES
  62. These functions only work for B<EVP_PKEY>s that contain a provider side key.
  63. =head1 RETURN VALUES
  64. EVP_PKEY_gettable_params() returns NULL on error or if it is not supported.
  65. All other methods return 1 if a value associated with the key's I<key_name> was
  66. successfully returned, or 0 if there was an error.
  67. An error may be returned by methods EVP_PKEY_get_utf8_string_param() and
  68. EVP_PKEY_get_octet_string_param() if I<max_buf_sz> is not big enough to hold the
  69. value. If I<out_len> is not NULL, I<*out_len> will be assigned the required
  70. buffer size to hold the value.
  71. =head1 EXAMPLES
  72. #include <openssl/evp.h>
  73. char curve_name[64];
  74. unsigned char pub[256];
  75. BIGNUM *bn_priv = NULL;
  76. /*
  77. * NB: assumes 'key' is set up before the next step. In this example the key
  78. * is an EC key.
  79. */
  80. if (!EVP_PKEY_get_utf8_string_param(key, OSSL_PKEY_PARAM_GROUP_NAME,
  81. curve_name, sizeof(curve_name), &len)) {
  82. /* Error */
  83. }
  84. if (!EVP_PKEY_get_octet_string_param(key, OSSL_PKEY_PARAM_PUB_KEY,
  85. pub, sizeof(pub), &len)) {
  86. /* Error */
  87. }
  88. if (!EVP_PKEY_get_bn_param(key, OSSL_PKEY_PARAM_PRIV_KEY, &bn_priv)) {
  89. /* Error */
  90. }
  91. BN_clear_free(bn_priv);
  92. =head1 SEE ALSO
  93. L<EVP_PKEY_CTX_new(3)>, L<provider-keymgmt(7)>, L<OSSL_PARAM(3)>
  94. =head1 HISTORY
  95. These functions were added in OpenSSL 3.0.
  96. =head1 COPYRIGHT
  97. Copyright 2020-2022 The OpenSSL Project Authors. All Rights Reserved.
  98. Licensed under the Apache License 2.0 (the "License"). You may not use
  99. this file except in compliance with the License. You can obtain a copy
  100. in the file LICENSE in the source distribution or at
  101. L<https://www.openssl.org/source/license.html>.
  102. =cut