openssl dgst, openssl enc: check for end of input
[openssl.git] / doc / man1 / kdf.pod
1 =pod
2
3 =head1 NAME
4
5 openssl-kdf,
6 kdf - perform Key Derivation Function operations
7
8 =head1 SYNOPSIS
9
10 B<openssl kdf>
11 [B<-help>]
12 [B<-kdfopt> I<nm:v>]
13 [B<-keylen> I<num>]
14 [B<-out> I<filename>]
15 [B<-binary>]
16 I<kdf_name>
17
18 =head1 DESCRIPTION
19
20 The key derivation functions generate a derived key from either a secret or
21 password.
22
23 =head1 OPTIONS
24
25 =over 4
26
27 =item B<-help>
28
29 Print a usage message.
30
31 =item B<-keylen> I<num>
32
33 The output size of the derived key. This field is required.
34
35 =item B<-out> I<filename>
36
37 Filename to output to, or standard output by default.
38
39 =item B<-binary>
40
41 Output the derived key in binary form. Uses hexadecimal text format if not specified.
42
43 =item B<-kdfopt> I<nm:v>
44
45 Passes options to the KDF algorithm.
46 A comprehensive list of controls can be found in the EVP_KDF_CTX implementation
47 documentation.
48 Common control strings used by EVP_KDF_ctrl_str() are:
49
50 =over 4
51
52 =item B<key:>I<string>
53
54 Specifies the secret key as an alphanumeric string (use if the key contains
55 printable characters only).
56 The string length must conform to any restrictions of the KDF algorithm.
57 A key must be specified for most KDF algorithms.
58
59 =item B<hexkey:>I<string>
60
61 Specifies the secret key in hexadecimal form (two hex digits per byte).
62 The key length must conform to any restrictions of the KDF algorithm.
63 A key must be specified for most KDF algorithms.
64
65 =item B<pass:>I<string>
66
67 Specifies the password as an alphanumeric string (use if the password contains
68 printable characters only).
69 The password must be specified for PBKDF2 and scrypt.
70
71 =item B<hexpass:>I<string>
72
73 Specifies the password in hexadecimal form (two hex digits per byte).
74 The password must be specified for PBKDF2 and scrypt.
75
76 =item B<digest:>I<string>
77
78 Specifies the name of a digest as an alphanumeric string.
79 To see the list of supported digests, use the command I<list -digest-commands>.
80
81 =back
82
83 =item I<kdf_name>
84
85 Specifies the name of a supported KDF algorithm which will be used.
86 The supported algorithms names are TLS1-PRF, HKDF, SSKDF, PBKDF2, SSHKDF and id-scrypt.
87
88 =back
89
90 =head1 EXAMPLES
91
92 Use TLS1-PRF to create a hex-encoded derived key from a secret key and seed:
93
94     openssl kdf -keylen 16 -kdfopt digest:SHA256 -kdfopt key:secret \
95                 -kdfopt seed:seed TLS1-PRF
96
97 Use HKDF to create a hex-encoded derived key from a secret key, salt and info:
98
99     openssl kdf -keylen 10 -kdfopt digest:SHA256 -kdfopt key:secret \
100                 -kdfopt salt:salt -kdfopt info:label HKDF
101
102 Use SSKDF with KMAC to create a hex-encoded derived key from a secret key, salt and info:
103
104     openssl kdf -keylen 64 -kdfopt mac:KMAC128 -kdfopt maclen:20 \
105                 -kdfopt hexkey:b74a149a161545 -kdfopt hexinfo:348a37a2 \
106                 -kdfopt hexsalt:3638271ccd68a2 SSKDF
107
108 Use SSKDF with HMAC to create a hex-encoded derived key from a secret key, salt and info:
109
110     openssl kdf -keylen 16 -kdfopt mac:HMAC -kdfopt digest:SHA256 \
111                 -kdfopt hexkey:b74a149a -kdfopt hexinfo:348a37a2 \
112                 -kdfopt hexsalt:3638271c SSKDF
113
114 Use SSKDF with Hash to create a hex-encoded derived key from a secret key, salt and info:
115
116     openssl kdf -keylen 14 -kdfopt digest:SHA256 \
117                 -kdfopt hexkey:6dbdc23f045488 \
118                 -kdfopt hexinfo:a1b2c3d4 SSKDF
119
120 Use SSHKDF to create a hex-encoded derived key from a secret key, hash and session_id:
121
122     openssl kdf -keylen 16 -kdfopt digest:SHA256 \
123                 -kdfopt hexkey:0102030405 \
124                 -kdfopt hexxcghash:06090A \
125                 -kdfopt hexsession_id:01020304 \
126                 -kdfopt type:A SSHKDF
127
128 Use PBKDF2 to create a hex-encoded derived key from a password and salt:
129
130     openssl kdf -keylen 32 -kdfopt digest:SHA256 -kdfopt pass:password \
131                 -kdfopt salt:salt -kdfopt iter:2 PBKDF2
132
133 Use scrypt to create a hex-encoded derived key from a password and salt:
134
135     openssl kdf -keylen 64 -kdfopt pass:password -kdfopt salt:NaCl \
136                 -kdfopt N:1024 -kdfopt r:8 -kdfopt p:16 \
137                 -kdfopt maxmem_bytes:10485760 id-scrypt
138
139 =head1 NOTES
140
141 The KDF mechanisms that are available will depend on the options
142 used when building OpenSSL.
143
144 =head1 SEE ALSO
145
146 L<EVP_KDF_CTX(3)>,
147 L<EVP_KDF_SCRYPT(7)>
148 L<EVP_KDF_TLS1_PRF(7)>
149 L<EVP_KDF_PBKDF2(7)>
150 L<EVP_KDF_HKDF(7)>
151 L<EVP_KDF_SS(7)>
152 L<EVP_KDF_SSHKDF(7)>
153 L<pkeyutl(1)>
154
155 =head1 HISTORY
156
157 Added in OpenSSL 3.0
158
159 =head1 COPYRIGHT
160
161 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
162
163 Licensed under the OpenSSL license (the "License").  You may not use
164 this file except in compliance with the License.  You can obtain a copy
165 in the file LICENSE in the source distribution or at
166 L<https://www.openssl.org/source/license.html>.
167
168 =cut