EVP_PKEY_derive.3ossl 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. .\" -*- mode: troff; coding: utf-8 -*-
  2. .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
  3. .\"
  4. .\" Standard preamble:
  5. .\" ========================================================================
  6. .de Sp \" Vertical space (when we can't use .PP)
  7. .if t .sp .5v
  8. .if n .sp
  9. ..
  10. .de Vb \" Begin verbatim text
  11. .ft CW
  12. .nf
  13. .ne \\$1
  14. ..
  15. .de Ve \" End verbatim text
  16. .ft R
  17. .fi
  18. ..
  19. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
  20. .ie n \{\
  21. . ds C` ""
  22. . ds C' ""
  23. 'br\}
  24. .el\{\
  25. . ds C`
  26. . ds C'
  27. 'br\}
  28. .\"
  29. .\" Escape single quotes in literal strings from groff's Unicode transform.
  30. .ie \n(.g .ds Aq \(aq
  31. .el .ds Aq '
  32. .\"
  33. .\" If the F register is >0, we'll generate index entries on stderr for
  34. .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
  35. .\" entries marked with X<> in POD. Of course, you'll have to process the
  36. .\" output yourself in some meaningful fashion.
  37. .\"
  38. .\" Avoid warning from groff about undefined register 'F'.
  39. .de IX
  40. ..
  41. .nr rF 0
  42. .if \n(.g .if rF .nr rF 1
  43. .if (\n(rF:(\n(.g==0)) \{\
  44. . if \nF \{\
  45. . de IX
  46. . tm Index:\\$1\t\\n%\t"\\$2"
  47. ..
  48. . if !\nF==2 \{\
  49. . nr % 0
  50. . nr F 2
  51. . \}
  52. . \}
  53. .\}
  54. .rr rF
  55. .\" ========================================================================
  56. .\"
  57. .IX Title "EVP_PKEY_DERIVE 3ossl"
  58. .TH EVP_PKEY_DERIVE 3ossl 2025-01-17 3.4.0 OpenSSL
  59. .\" For nroff, turn off justification. Always turn off hyphenation; it makes
  60. .\" way too many mistakes in technical documents.
  61. .if n .ad l
  62. .nh
  63. .SH NAME
  64. EVP_PKEY_derive_init, EVP_PKEY_derive_init_ex,
  65. EVP_PKEY_derive_set_peer_ex, EVP_PKEY_derive_set_peer, EVP_PKEY_derive
  66. \&\- derive public key algorithm shared secret
  67. .SH SYNOPSIS
  68. .IX Header "SYNOPSIS"
  69. .Vb 1
  70. \& #include <openssl/evp.h>
  71. \&
  72. \& int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
  73. \& int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
  74. \& int EVP_PKEY_derive_set_peer_ex(EVP_PKEY_CTX *ctx, EVP_PKEY *peer,
  75. \& int validate_peer);
  76. \& int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer);
  77. \& int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
  78. .Ve
  79. .SH DESCRIPTION
  80. .IX Header "DESCRIPTION"
  81. \&\fBEVP_PKEY_derive_init()\fR initializes a public key algorithm context \fIctx\fR for
  82. shared secret derivation using the algorithm given when the context was created
  83. using \fBEVP_PKEY_CTX_new\fR\|(3) or variants thereof. The algorithm is used to
  84. fetch a \fBEVP_KEYEXCH\fR method implicitly, see "Implicit fetch" in \fBprovider\fR\|(7) for
  85. more information about implicit fetches.
  86. .PP
  87. \&\fBEVP_PKEY_derive_init_ex()\fR is the same as \fBEVP_PKEY_derive_init()\fR but additionally
  88. sets the passed parameters \fIparams\fR on the context before returning.
  89. .PP
  90. \&\fBEVP_PKEY_derive_set_peer_ex()\fR sets the peer key: this will normally
  91. be a public key. The \fIvalidate_peer\fR will validate the public key if this value
  92. is non zero.
  93. .PP
  94. \&\fBEVP_PKEY_derive_set_peer()\fR is similar to \fBEVP_PKEY_derive_set_peer_ex()\fR with
  95. \&\fIvalidate_peer\fR set to 1.
  96. .PP
  97. \&\fBEVP_PKEY_derive()\fR derives a shared secret using \fIctx\fR.
  98. If \fIkey\fR is NULL then the maximum size of the output buffer is written to the
  99. \&\fIkeylen\fR parameter. If \fIkey\fR is not NULL then before the call the \fIkeylen\fR
  100. parameter should contain the length of the \fIkey\fR buffer, if the call is
  101. successful the shared secret is written to \fIkey\fR and the amount of data
  102. written to \fIkeylen\fR.
  103. .SH NOTES
  104. .IX Header "NOTES"
  105. After the call to \fBEVP_PKEY_derive_init()\fR, algorithm
  106. specific control operations can be performed to set any appropriate parameters
  107. for the operation.
  108. .PP
  109. The function \fBEVP_PKEY_derive()\fR can be called more than once on the same
  110. context if several operations are performed using the same parameters.
  111. .SH "RETURN VALUES"
  112. .IX Header "RETURN VALUES"
  113. \&\fBEVP_PKEY_derive_init()\fR and \fBEVP_PKEY_derive()\fR return 1
  114. for success and 0 or a negative value for failure.
  115. In particular a return value of \-2 indicates the operation is not supported by
  116. the public key algorithm.
  117. .SH EXAMPLES
  118. .IX Header "EXAMPLES"
  119. Derive shared secret (for example DH or EC keys):
  120. .PP
  121. .Vb 2
  122. \& #include <openssl/evp.h>
  123. \& #include <openssl/rsa.h>
  124. \&
  125. \& EVP_PKEY_CTX *ctx;
  126. \& ENGINE *eng;
  127. \& unsigned char *skey;
  128. \& size_t skeylen;
  129. \& EVP_PKEY *pkey, *peerkey;
  130. \& /* NB: assumes pkey, eng, peerkey have been already set up */
  131. \&
  132. \& ctx = EVP_PKEY_CTX_new(pkey, eng);
  133. \& if (!ctx)
  134. \& /* Error occurred */
  135. \& if (EVP_PKEY_derive_init(ctx) <= 0)
  136. \& /* Error */
  137. \& if (EVP_PKEY_derive_set_peer(ctx, peerkey) <= 0)
  138. \& /* Error */
  139. \&
  140. \& /* Determine buffer length */
  141. \& if (EVP_PKEY_derive(ctx, NULL, &skeylen) <= 0)
  142. \& /* Error */
  143. \&
  144. \& skey = OPENSSL_malloc(skeylen);
  145. \&
  146. \& if (!skey)
  147. \& /* malloc failure */
  148. \&
  149. \& if (EVP_PKEY_derive(ctx, skey, &skeylen) <= 0)
  150. \& /* Error */
  151. \&
  152. \& /* Shared secret is skey bytes written to buffer skey */
  153. .Ve
  154. .SH "SEE ALSO"
  155. .IX Header "SEE ALSO"
  156. \&\fBEVP_PKEY_CTX_new\fR\|(3),
  157. \&\fBEVP_PKEY_encrypt\fR\|(3),
  158. \&\fBEVP_PKEY_decrypt\fR\|(3),
  159. \&\fBEVP_PKEY_sign\fR\|(3),
  160. \&\fBEVP_PKEY_verify\fR\|(3),
  161. \&\fBEVP_PKEY_verify_recover\fR\|(3),
  162. \&\fBEVP_KEYEXCH_fetch\fR\|(3)
  163. .SH HISTORY
  164. .IX Header "HISTORY"
  165. The \fBEVP_PKEY_derive_init()\fR, \fBEVP_PKEY_derive_set_peer()\fR and \fBEVP_PKEY_derive()\fR
  166. functions were originally added in OpenSSL 1.0.0.
  167. .PP
  168. The \fBEVP_PKEY_derive_init_ex()\fR and \fBEVP_PKEY_derive_set_peer_ex()\fR functions were
  169. added in OpenSSL 3.0.
  170. .SH COPYRIGHT
  171. .IX Header "COPYRIGHT"
  172. Copyright 2006\-2022 The OpenSSL Project Authors. All Rights Reserved.
  173. .PP
  174. Licensed under the Apache License 2.0 (the "License"). You may not use
  175. this file except in compliance with the License. You can obtain a copy
  176. in the file LICENSE in the source distribution or at
  177. <https://www.openssl.org/source/license.html>.