EVP_PKEY_encrypt.3ossl 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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_ENCRYPT 3ossl"
  58. .TH EVP_PKEY_ENCRYPT 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_encrypt_init_ex,
  65. EVP_PKEY_encrypt_init, EVP_PKEY_encrypt \- encrypt using a public key algorithm
  66. .SH SYNOPSIS
  67. .IX Header "SYNOPSIS"
  68. .Vb 1
  69. \& #include <openssl/evp.h>
  70. \&
  71. \& int EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx);
  72. \& int EVP_PKEY_encrypt_init_ex(EVP_PKEY_CTX *ctx, const OSSL_PARAM params[]);
  73. \& int EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx,
  74. \& unsigned char *out, size_t *outlen,
  75. \& const unsigned char *in, size_t inlen);
  76. .Ve
  77. .SH DESCRIPTION
  78. .IX Header "DESCRIPTION"
  79. The \fBEVP_PKEY_encrypt_init()\fR function initializes a public key algorithm
  80. context using key \fBpkey\fR for an encryption operation.
  81. .PP
  82. The \fBEVP_PKEY_encrypt_init_ex()\fR function initializes a public key algorithm
  83. context using key \fBpkey\fR for an encryption operation and sets the
  84. algorithm specific \fBparams\fR.
  85. .PP
  86. The \fBEVP_PKEY_encrypt()\fR function performs a public key encryption operation
  87. using \fBctx\fR. The data to be encrypted is specified using the \fBin\fR and
  88. \&\fBinlen\fR parameters. If \fBout\fR is \fBNULL\fR then the maximum size of the output
  89. buffer is written to the \fBoutlen\fR parameter. If \fBout\fR is not \fBNULL\fR then
  90. before the call the \fBoutlen\fR parameter should contain the length of the
  91. \&\fBout\fR buffer, if the call is successful the encrypted data is written to
  92. \&\fBout\fR and the amount of data written to \fBoutlen\fR.
  93. .SH NOTES
  94. .IX Header "NOTES"
  95. After the call to \fBEVP_PKEY_encrypt_init()\fR algorithm specific control
  96. operations can be performed to set any appropriate parameters for the
  97. operation. These operations can be included in the \fBEVP_PKEY_encrypt_init_ex()\fR
  98. call.
  99. .PP
  100. The function \fBEVP_PKEY_encrypt()\fR can be called more than once on the same
  101. context if several operations are performed using the same parameters.
  102. .SH "RETURN VALUES"
  103. .IX Header "RETURN VALUES"
  104. \&\fBEVP_PKEY_encrypt_init()\fR, \fBEVP_PKEY_encrypt_init_ex()\fR and \fBEVP_PKEY_encrypt()\fR
  105. return 1 for success and 0 or a negative value for failure. In particular a
  106. return value of \-2 indicates the operation is not supported by the public key
  107. algorithm.
  108. .SH EXAMPLES
  109. .IX Header "EXAMPLES"
  110. Encrypt data using OAEP (for RSA keys). See also \fBPEM_read_PUBKEY\fR\|(3) or
  111. \&\fBd2i_X509\fR\|(3) for means to load a public key. You may also simply
  112. set 'eng = NULL;' to start with the default OpenSSL RSA implementation:
  113. .PP
  114. .Vb 3
  115. \& #include <openssl/evp.h>
  116. \& #include <openssl/rsa.h>
  117. \& #include <openssl/engine.h>
  118. \&
  119. \& EVP_PKEY_CTX *ctx;
  120. \& ENGINE *eng;
  121. \& unsigned char *out, *in;
  122. \& size_t outlen, inlen;
  123. \& EVP_PKEY *key;
  124. \&
  125. \& /*
  126. \& * NB: assumes eng, key, in, inlen are already set up,
  127. \& * and that key is an RSA public key
  128. \& */
  129. \& ctx = EVP_PKEY_CTX_new(key, eng);
  130. \& if (!ctx)
  131. \& /* Error occurred */
  132. \& if (EVP_PKEY_encrypt_init(ctx) <= 0)
  133. \& /* Error */
  134. \& if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
  135. \& /* Error */
  136. \&
  137. \& /* Determine buffer length */
  138. \& if (EVP_PKEY_encrypt(ctx, NULL, &outlen, in, inlen) <= 0)
  139. \& /* Error */
  140. \&
  141. \& out = OPENSSL_malloc(outlen);
  142. \&
  143. \& if (!out)
  144. \& /* malloc failure */
  145. \&
  146. \& if (EVP_PKEY_encrypt(ctx, out, &outlen, in, inlen) <= 0)
  147. \& /* Error */
  148. \&
  149. \& /* Encrypted data is outlen bytes written to buffer out */
  150. .Ve
  151. .SH "SEE ALSO"
  152. .IX Header "SEE ALSO"
  153. \&\fBd2i_X509\fR\|(3),
  154. \&\fBENGINE_by_id\fR\|(3),
  155. \&\fBEVP_PKEY_CTX_new\fR\|(3),
  156. \&\fBEVP_PKEY_decrypt\fR\|(3),
  157. \&\fBEVP_PKEY_sign\fR\|(3),
  158. \&\fBEVP_PKEY_verify\fR\|(3),
  159. \&\fBEVP_PKEY_verify_recover\fR\|(3),
  160. \&\fBEVP_PKEY_derive\fR\|(3)
  161. .SH HISTORY
  162. .IX Header "HISTORY"
  163. These functions were added in OpenSSL 1.0.0.
  164. .SH COPYRIGHT
  165. .IX Header "COPYRIGHT"
  166. Copyright 2006\-2021 The OpenSSL Project Authors. All Rights Reserved.
  167. .PP
  168. Licensed under the Apache License 2.0 (the "License"). You may not use
  169. this file except in compliance with the License. You can obtain a copy
  170. in the file LICENSE in the source distribution or at
  171. <https://www.openssl.org/source/license.html>.