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