diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libcrypto/man/EVP_PKEY_derive.3 | 120 |
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 | ||
27 | The | ||
28 | .Fn EVP_PKEY_derive_init | ||
29 | function initializes a public key algorithm context using key | ||
30 | .Fa ctx->pkey | ||
31 | for shared secret derivation. | ||
32 | .Pp | ||
33 | The | ||
34 | .Fn EVP_PKEY_derive_set_peer | ||
35 | function sets the peer key: this will normally be a public key. | ||
36 | .Pp | ||
37 | The | ||
38 | .Fn EVP_PKEY_derive | ||
39 | derives a shared secret using | ||
40 | .Fa ctx . | ||
41 | If | ||
42 | .Fa key | ||
43 | is | ||
44 | .Dv NULL , | ||
45 | then the maximum size of the output buffer is written to the | ||
46 | .Fa keylen | ||
47 | parameter. | ||
48 | If | ||
49 | .Fa key | ||
50 | is not | ||
51 | .Dv NULL | ||
52 | then before the call the | ||
53 | .Fa keylen | ||
54 | parameter should contain the length of the | ||
55 | .Fa key | ||
56 | buffer. | ||
57 | If the call is successful, the shared secret is written to | ||
58 | .Fa key | ||
59 | and the amount of data written to | ||
60 | .Fa keylen . | ||
61 | .Pp | ||
62 | After the call to | ||
63 | .Fn EVP_PKEY_derive_init , | ||
64 | algorithm specific control operations can be performed to set any | ||
65 | appropriate parameters for the operation. | ||
66 | .Pp | ||
67 | The function | ||
68 | .Fn EVP_PKEY_derive | ||
69 | can be called more than once on the same context if several operations | ||
70 | are performed using the same parameters. | ||
71 | .Sh RETURN VALUES | ||
72 | .Fn EVP_PKEY_derive_init | ||
73 | and | ||
74 | .Fn EVP_PKEY_derive | ||
75 | return 1 for success and 0 or a negative value for failure. | ||
76 | In particular, a return value of -2 indicates the operation is not | ||
77 | supported by the public key algorithm. | ||
78 | .Sh EXAMPLES | ||
79 | Derive shared secret (for example DH or EC keys): | ||
80 | .Bd -literal | ||
81 | #include <openssl/evp.h> | ||
82 | #include <openssl/rsa.h> | ||
83 | |||
84 | EVP_PKEY_CTX *ctx; | ||
85 | unsigned char *skey; | ||
86 | size_t skeylen; | ||
87 | EVP_PKEY *pkey, *peerkey; | ||
88 | /* NB: assumes pkey, peerkey have been already set up */ | ||
89 | |||
90 | ctx = EVP_PKEY_CTX_new(pkey); | ||
91 | if (!ctx) | ||
92 | /* Error occurred */ | ||
93 | if (EVP_PKEY_derive_init(ctx) <= 0) | ||
94 | /* Error */ | ||
95 | if (EVP_PKEY_derive_set_peer(ctx, peerkey) <= 0) | ||
96 | /* Error */ | ||
97 | |||
98 | /* Determine buffer length */ | ||
99 | if (EVP_PKEY_derive(ctx, NULL, &skeylen) <= 0) | ||
100 | /* Error */ | ||
101 | |||
102 | skey = malloc(skeylen); | ||
103 | |||
104 | if (!skey) | ||
105 | /* malloc failure */ | ||
106 | |||
107 | if (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 | ||
120 | These functions were first added to OpenSSL 1.0.0. | ||