EVP_PKEY_set1_encoded_public_key.pod 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. =pod
  2. =head1 NAME
  3. EVP_PKEY_set1_encoded_public_key, EVP_PKEY_get1_encoded_public_key,
  4. EVP_PKEY_set1_tls_encodedpoint, EVP_PKEY_get1_tls_encodedpoint
  5. - functions to set and get public key data within an EVP_PKEY
  6. =head1 SYNOPSIS
  7. #include <openssl/evp.h>
  8. int EVP_PKEY_set1_encoded_public_key(EVP_PKEY *pkey,
  9. const unsigned char *pub, size_t publen);
  10. size_t EVP_PKEY_get1_encoded_public_key(EVP_PKEY *pkey, unsigned char **ppub);
  11. Deprecated since OpenSSL 3.0, can be hidden entirely by defining
  12. B<OPENSSL_API_COMPAT> with a suitable version value, see
  13. L<openssl_user_macros(7)>:
  14. int EVP_PKEY_set1_tls_encodedpoint(EVP_PKEY *pkey,
  15. const unsigned char *pt, size_t ptlen);
  16. size_t EVP_PKEY_get1_tls_encodedpoint(EVP_PKEY *pkey, unsigned char **ppt);
  17. =head1 DESCRIPTION
  18. EVP_PKEY_set1_encoded_public_key() can be used to set the public key value
  19. within an existing EVP_PKEY object. For the built-in OpenSSL algorithms this
  20. currently only works for those that support key exchange. Parameters are not
  21. set as part of this operation, so typically an application will create an
  22. EVP_PKEY first, set the parameters on it, and then call this function.
  23. For example setting the parameters might be done using
  24. L<EVP_PKEY_copy_parameters(3)>.
  25. The format for the encoded public key will depend on the algorithm in use. For
  26. DH it should be encoded as a positive integer in big-endian form. For EC is
  27. should be a point conforming to Sec. 2.3.4 of the SECG SEC 1 ("Elliptic
  28. Curve Cryptography") standard. For X25519 and X448 it should be encoded in a
  29. format as defined by RFC7748.
  30. The key to be updated is supplied in B<pkey>. The buffer containing the encoded
  31. key is pointed to be B<pub>. The length of the buffer is supplied in B<publen>.
  32. EVP_PKEY_get1_encoded_public_key() does the equivalent operation except that
  33. the encoded public key is returned to the application. The key containing the
  34. public key data is supplied in B<pkey>. A buffer containing the encoded key will
  35. be allocated and stored in B<*ppub>. The length of the encoded public key is
  36. returned by the function. The application is responsible for freeing the
  37. allocated buffer.
  38. The macro EVP_PKEY_set1_tls_encodedpoint() is deprecated and simply calls
  39. EVP_PKEY_set1_encoded_public_key() with all the same arguments. New applications
  40. should use EVP_PKEY_set1_encoded_public_key() instead.
  41. The macro EVP_PKEY_get1_tls_encodedpoint() is deprecated and simply calls
  42. EVP_PKEY_get1_encoded_public_key() with all the same arguments. New applications
  43. should use EVP_PKEY_get1_encoded_public_key() instead.
  44. =head1 RETURN VALUES
  45. EVP_PKEY_set1_encoded_public_key() returns 1 for success and 0 or a negative
  46. value for failure.
  47. EVP_PKEY_get1_encoded_public_key() return 1
  48. =head1 EXAMPLES
  49. See L<EVP_PKEY_derive_init(3)> and L<EVP_PKEY_derive(3)> for information about
  50. performing a key exchange operation.
  51. =head2 Set up a peer's EVP_PKEY ready for a key exchange operation
  52. #include <openssl/evp.h>
  53. int exchange(EVP_PKEY *ourkey, unsigned char *peer_pub, size_t peer_pub_len)
  54. {
  55. EVP_PKEY *peerkey = EVP_PKEY_new();
  56. if (peerkey == NULL || EVP_PKEY_copy_parameters(peerkey, ourkey) <= 0)
  57. return 0;
  58. if (EVP_PKEY_set1_encoded_public_key(peerkey, peer_pub,
  59. peer_pub_len) <= 0)
  60. return 0;
  61. /* Do the key exchange here */
  62. EVP_PKEY_free(peerkey);
  63. return 1;
  64. }
  65. =head2 Get an encoded public key to send to a peer
  66. #include <openssl/evp.h>
  67. int get_encoded_pub_key(EVP_PKEY *ourkey)
  68. {
  69. unsigned char *pubkey;
  70. size_t pubkey_len;
  71. pubkey_len = EVP_PKEY_get1_encoded_public_key(ourkey, &pubkey);
  72. if (pubkey_len == 0)
  73. return 0;
  74. /*
  75. * Send the encoded public key stored in the buffer at "pubkey" and of
  76. * length pubkey_len, to the peer.
  77. */
  78. OPENSSL_free(pubkey);
  79. return 1;
  80. }
  81. =head1 SEE ALSO
  82. L<EVP_PKEY_new(3)>, L<EVP_PKEY_copy_parameters(3)>,
  83. L<EVP_PKEY_derive_init(3)>, L<EVP_PKEY_derive(3)>,
  84. L<EVP_PKEY-DH(7)>, L<EVP_PKEY-EC(7)>, L<EVP_PKEY-X25519(7)>, L<EVP_PKEY-X448(7)>
  85. =head1 HISTORY
  86. EVP_PKEY_set1_encoded_public_key() and EVP_PKEY_get1_encoded_public_key() were
  87. added in OpenSSL 3.0.
  88. EVP_PKEY_set1_tls_encodedpoint() and EVP_PKEY_get1_tls_encodedpoint() were
  89. deprecated in OpenSSL 3.0.
  90. =head1 COPYRIGHT
  91. Copyright 2020 The OpenSSL Project Authors. All Rights Reserved.
  92. Licensed under the Apache License 2.0 (the "License"). You may not use
  93. this file except in compliance with the License. You can obtain a copy
  94. in the file LICENSE in the source distribution or at
  95. L<https://www.openssl.org/source/license.html>.
  96. =cut