Add public API docs for newly added EVP_SIGNATURE related functions
[openssl.git] / doc / man3 / EVP_PKEY_derive.pod
1 =pod
2
3 =head1 NAME
4
5 EVP_PKEY_derive_init, EVP_PKEY_derive_init_ex, EVP_PKEY_derive_set_peer,
6 EVP_PKEY_derive - derive public key algorithm shared secret
7
8 =head1 SYNOPSIS
9
10  #include <openssl/evp.h>
11
12  int EVP_PKEY_derive_init_ex(EVP_PKEY_CTX *ctx, EVP_KEYEXCH *exchange);
13  int EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx);
14  int EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer);
15  int EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen);
16
17 =head1 DESCRIPTION
18
19 The EVP_PKEY_derive_init_ex() function initializes a public key algorithm
20 context for shared secret derivation using the key exchange algorithm
21 B<exchange>.
22 The key exchange algorithm B<exchange> should be fetched using a call to
23 L<EVP_KEYEXCH_fetch(3)>.
24 The EVP_PKEY object associated with B<ctx> must be compatible with that
25 algorithm.
26 B<exchange> may be NULL in which case the EVP_KEYEXCH algorithm is fetched
27 implicitly based on the type of EVP_PKEY associated with B<ctx>.
28 See L<provider(7)/Implicit fetch> for more information about implict fetches.
29
30 The EVP_PKEY_derive_init() function is the same as EVP_PKEY_derive_init_ex()
31 except that the EVP_KEYEXCH algorithm is always implicitly fetched.
32
33 The EVP_PKEY_derive_set_peer() function sets the peer key: this will normally
34 be a public key.
35
36 The EVP_PKEY_derive() derives a shared secret using B<ctx>.
37 If B<key> is B<NULL> then the maximum size of the output buffer is written to
38 the B<keylen> parameter. If B<key> is not B<NULL> then before the call the
39 B<keylen> parameter should contain the length of the B<key> buffer, if the call
40 is successful the shared secret is written to B<key> and the amount of data
41 written to B<keylen>.
42
43 =head1 NOTES
44
45 After the call to EVP_PKEY_derive_init() or EVP_PKEY_derive_init_ex() algorithm
46 specific control operations can be performed to set any appropriate parameters
47 for the operation.
48
49 The function EVP_PKEY_derive() can be called more than once on the same
50 context if several operations are performed using the same parameters.
51
52 =head1 RETURN VALUES
53
54 EVP_PKEY_derive_init_ex(), EVP_PKEY_derive_init() and EVP_PKEY_derive() return 1
55 for success and 0 or a negative value for failure.
56 In particular a return value of -2 indicates the operation is not supported by
57 the public key algorithm.
58
59 =head1 EXAMPLES
60
61 Derive shared secret (for example DH or EC keys):
62
63  #include <openssl/evp.h>
64  #include <openssl/rsa.h>
65
66  EVP_PKEY_CTX *ctx;
67  ENGINE *eng;
68  unsigned char *skey;
69  size_t skeylen;
70  EVP_PKEY *pkey, *peerkey;
71  /* NB: assumes pkey, eng, peerkey have been already set up */
72
73  ctx = EVP_PKEY_CTX_new(pkey, eng);
74  if (!ctx)
75      /* Error occurred */
76  if (EVP_PKEY_derive_init(ctx) <= 0)
77      /* Error */
78  if (EVP_PKEY_derive_set_peer(ctx, peerkey) <= 0)
79      /* Error */
80
81  /* Determine buffer length */
82  if (EVP_PKEY_derive(ctx, NULL, &skeylen) <= 0)
83      /* Error */
84
85  skey = OPENSSL_malloc(skeylen);
86
87  if (!skey)
88      /* malloc failure */
89
90  if (EVP_PKEY_derive(ctx, skey, &skeylen) <= 0)
91      /* Error */
92
93  /* Shared secret is skey bytes written to buffer skey */
94
95 =head1 SEE ALSO
96
97 L<EVP_PKEY_CTX_new(3)>,
98 L<EVP_PKEY_encrypt(3)>,
99 L<EVP_PKEY_decrypt(3)>,
100 L<EVP_PKEY_sign(3)>,
101 L<EVP_PKEY_verify(3)>,
102 L<EVP_PKEY_verify_recover(3)>,
103 L<EVP_KEYEXCH_fetch(3)>
104
105 =head1 HISTORY
106
107 These functions were added in OpenSSL 1.0.0. The EVP_PKEY_derive_init_ex()
108 function was added in OpenSSL 3.0.
109
110 =head1 COPYRIGHT
111
112 Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
113
114 Licensed under the Apache License 2.0 (the "License").  You may not use
115 this file except in compliance with the License.  You can obtain a copy
116 in the file LICENSE in the source distribution or at
117 L<https://www.openssl.org/source/license.html>.
118
119 =cut