summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/man/EVP_PKEY_encrypt.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/man/EVP_PKEY_encrypt.3')
-rw-r--r--src/lib/libcrypto/man/EVP_PKEY_encrypt.3117
1 files changed, 117 insertions, 0 deletions
diff --git a/src/lib/libcrypto/man/EVP_PKEY_encrypt.3 b/src/lib/libcrypto/man/EVP_PKEY_encrypt.3
new file mode 100644
index 0000000000..bda37ef160
--- /dev/null
+++ b/src/lib/libcrypto/man/EVP_PKEY_encrypt.3
@@ -0,0 +1,117 @@
1.Dd $Mdocdate: November 3 2016 $
2.Dt EVP_PKEY_ENCRYPT 3
3.Os
4.Sh NAME
5.Nm EVP_PKEY_encrypt_init ,
6.Nm EVP_PKEY_encrypt
7.Nd encrypt using a public key algorithm
8.Sh SYNOPSIS
9.In openssl/evp.h
10.Ft int
11.Fo EVP_PKEY_encrypt_init
12.Fa "EVP_PKEY_CTX *ctx"
13.Fc
14.Ft int
15.Fo EVP_PKEY_encrypt
16.Fa "EVP_PKEY_CTX *ctx"
17.Fa "unsigned char *out"
18.Fa "size_t *outlen"
19.Fa "const unsigned char *in"
20.Fa "size_t inlen"
21.Fc
22.Sh DESCRIPTION
23The
24.Fn EVP_PKEY_encrypt_init
25function initializes a public key algorithm context using key
26.Fa ctx->pkey
27for an encryption operation.
28.Pp
29The
30.Fn EVP_PKEY_encrypt
31function performs a public key encryption operation using
32.Fa ctx .
33The data to be encrypted is specified using the
34.Fa in
35and
36.Fa inlen
37parameters.
38If
39.Fa out
40is
41.Dv NULL ,
42then the maximum size of the output buffer is written to the
43.Fa outlen
44parameter.
45If
46.Fa out
47is not
48.Dv NULL ,
49then before the call the
50.Fa outlen
51parameter should contain the length of the
52.Fa out
53buffer, if the call is successful the encrypted data is written to
54.Fa out
55and the amount of data written to
56.Fa outlen .
57.Pp
58After the call to
59.Fn EVP_PKEY_encrypt_init ,
60algorithm specific control operations can be performed to set any
61appropriate parameters for the operation.
62.Pp
63The function
64.Fn EVP_PKEY_encrypt
65can be called more than once on the same context if several operations
66are performed using the same parameters.
67.Sh RETURN VALUES
68.Fn EVP_PKEY_encrypt_init
69and
70.Fn EVP_PKEY_encrypt
71return 1 for success and 0 or a negative value for failure.
72In particular, a return value of -2 indicates the operation is not
73supported by the public key algorithm.
74.Sh EXAMPLES
75Encrypt data using OAEP (for RSA keys):
76.Bd -literal
77#include <openssl/evp.h>
78#include <openssl/rsa.h>
79
80EVP_PKEY_CTX *ctx;
81unsigned char *out, *in;
82size_t outlen, inlen;
83EVP_PKEY *key;
84/* NB: assumes key in, inlen are already set up
85 * and that key is an RSA public key
86 */
87ctx = EVP_PKEY_CTX_new(key);
88if (!ctx)
89 /* Error occurred */
90if (EVP_PKEY_encrypt_init(ctx) <= 0)
91 /* Error */
92if (EVP_PKEY_CTX_set_rsa_padding(ctx, RSA_PKCS1_OAEP_PADDING) <= 0)
93 /* Error */
94
95/* Determine buffer length */
96if (EVP_PKEY_encrypt(ctx, NULL, &outlen, in, inlen) <= 0)
97 /* Error */
98
99out = malloc(outlen);
100
101if (!out)
102 /* malloc failure */
103
104if (EVP_PKEY_encrypt(ctx, out, &outlen, in, inlen) <= 0)
105 /* Error */
106
107/* Encrypted data is outlen bytes written to buffer out */
108.Ed
109.Sh SEE ALSO
110.Xr EVP_PKEY_CTX_new 3 ,
111.Xr EVP_PKEY_decrypt 3 ,
112.Xr EVP_PKEY_derive 3 ,
113.Xr EVP_PKEY_sign 3 ,
114.Xr EVP_PKEY_verify 3 ,
115.Xr EVP_PKEY_verify_recover 3
116.Sh HISTORY
117These functions were first added to OpenSSL 1.0.0.