| 1 |
.\" -*- mode: troff; coding: utf-8 -*- |
| 2 |
.\" Automatically generated by Pod::Man 5.0102 (Pod::Simple 3.45) |
| 3 |
.\" |
| 4 |
.\" Standard preamble: |
| 5 |
.\" ======================================================================== |
| 6 |
.de Sp \" Vertical space (when we can't use .PP) |
| 7 |
.if t .sp .5v |
| 8 |
.if n .sp |
| 9 |
.. |
| 10 |
.de Vb \" Begin verbatim text |
| 11 |
.ft CW |
| 12 |
.nf |
| 13 |
.ne \\$1 |
| 14 |
.. |
| 15 |
.de Ve \" End verbatim text |
| 16 |
.ft R |
| 17 |
.fi |
| 18 |
.. |
| 19 |
.\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. |
| 20 |
.ie n \{\ |
| 21 |
. ds C` "" |
| 22 |
. ds C' "" |
| 23 |
'br\} |
| 24 |
.el\{\ |
| 25 |
. ds C` |
| 26 |
. ds C' |
| 27 |
'br\} |
| 28 |
.\" |
| 29 |
.\" Escape single quotes in literal strings from groff's Unicode transform. |
| 30 |
.ie \n(.g .ds Aq \(aq |
| 31 |
.el .ds Aq ' |
| 32 |
.\" |
| 33 |
.\" If the F register is >0, we'll generate index entries on stderr for |
| 34 |
.\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index |
| 35 |
.\" entries marked with X<> in POD. Of course, you'll have to process the |
| 36 |
.\" output yourself in some meaningful fashion. |
| 37 |
.\" |
| 38 |
.\" Avoid warning from groff about undefined register 'F'. |
| 39 |
.de IX |
| 40 |
.. |
| 41 |
.nr rF 0 |
| 42 |
.if \n(.g .if rF .nr rF 1 |
| 43 |
.if (\n(rF:(\n(.g==0)) \{\ |
| 44 |
. if \nF \{\ |
| 45 |
. de IX |
| 46 |
. tm Index:\\$1\t\\n%\t"\\$2" |
| 47 |
.. |
| 48 |
. if !\nF==2 \{\ |
| 49 |
. nr % 0 |
| 50 |
. nr F 2 |
| 51 |
. \} |
| 52 |
. \} |
| 53 |
.\} |
| 54 |
.rr rF |
| 55 |
.\" ======================================================================== |
| 56 |
.\" |
| 57 |
.IX Title "EVP_BYTESTOKEY 3SSL" |
| 58 |
.TH EVP_BYTESTOKEY 3SSL 2026-04-07 3.6.2 OpenSSL |
| 59 |
.\" For nroff, turn off justification. Always turn off hyphenation; it makes |
| 60 |
.\" way too many mistakes in technical documents. |
| 61 |
.if n .ad l |
| 62 |
.nh |
| 63 |
.SH NAME |
| 64 |
EVP_BytesToKey \- password based encryption routine |
| 65 |
.SH SYNOPSIS |
| 66 |
.IX Header "SYNOPSIS" |
| 67 |
.Vb 1 |
| 68 |
\& #include <openssl/evp.h> |
| 69 |
\& |
| 70 |
\& int EVP_BytesToKey(const EVP_CIPHER *type, const EVP_MD *md, |
| 71 |
\& const unsigned char *salt, |
| 72 |
\& const unsigned char *data, int datal, int count, |
| 73 |
\& unsigned char *key, unsigned char *iv); |
| 74 |
.Ve |
| 75 |
.SH DESCRIPTION |
| 76 |
.IX Header "DESCRIPTION" |
| 77 |
\&\fBEVP_BytesToKey()\fR derives a key and IV from various parameters. \fBtype\fR is |
| 78 |
the cipher to derive the key and IV for. \fBmd\fR is the message digest to use. |
| 79 |
The \fBsalt\fR parameter is used as a salt in the derivation: it should point to |
| 80 |
an 8 byte buffer or NULL if no salt is used. \fBdata\fR is a buffer containing |
| 81 |
\&\fBdatal\fR bytes which is used to derive the keying data. \fBcount\fR is the |
| 82 |
iteration count to use. The derived key and IV will be written to \fBkey\fR |
| 83 |
and \fBiv\fR respectively. |
| 84 |
.SH NOTES |
| 85 |
.IX Header "NOTES" |
| 86 |
A typical application of this function is to derive keying material for an |
| 87 |
encryption algorithm from a password in the \fBdata\fR parameter. |
| 88 |
.PP |
| 89 |
Increasing the \fBcount\fR parameter slows down the algorithm which makes it |
| 90 |
harder for an attacker to perform a brute force attack using a large number |
| 91 |
of candidate passwords. |
| 92 |
.PP |
| 93 |
If the total key and IV length is less than the digest length and |
| 94 |
\&\fBMD5\fR is used then the derivation algorithm is compatible with PKCS#5 v1.5 |
| 95 |
otherwise a non standard extension is used to derive the extra data. |
| 96 |
.PP |
| 97 |
Newer applications should use a more modern algorithm such as PBKDF2 as |
| 98 |
defined in PKCS#5v2.1 and provided by PKCS5_PBKDF2_HMAC. |
| 99 |
.SH "KEY DERIVATION ALGORITHM" |
| 100 |
.IX Header "KEY DERIVATION ALGORITHM" |
| 101 |
The key and IV is derived by concatenating D_1, D_2, etc until |
| 102 |
enough data is available for the key and IV. D_i is defined as: |
| 103 |
.PP |
| 104 |
.Vb 1 |
| 105 |
\& D_i = HASH^count(D_(i\-1) || data || salt) |
| 106 |
.Ve |
| 107 |
.PP |
| 108 |
where || denotes concatenation, D_0 is empty, HASH is the digest |
| 109 |
algorithm in use, HASH^1(data) is simply HASH(data), HASH^2(data) |
| 110 |
is HASH(HASH(data)) and so on. |
| 111 |
.PP |
| 112 |
The initial bytes are used for the key and the subsequent bytes for |
| 113 |
the IV. |
| 114 |
.SH "RETURN VALUES" |
| 115 |
.IX Header "RETURN VALUES" |
| 116 |
If \fBdata\fR is NULL, then \fBEVP_BytesToKey()\fR returns the number of bytes |
| 117 |
needed to store the derived key. |
| 118 |
Otherwise, \fBEVP_BytesToKey()\fR returns the size of the derived key in bytes, |
| 119 |
or 0 on error. |
| 120 |
.SH "SEE ALSO" |
| 121 |
.IX Header "SEE ALSO" |
| 122 |
\&\fBevp\fR\|(7), \fBRAND_bytes\fR\|(3), |
| 123 |
\&\fBPKCS5_PBKDF2_HMAC\fR\|(3), |
| 124 |
\&\fBEVP_EncryptInit\fR\|(3) |
| 125 |
.SH COPYRIGHT |
| 126 |
.IX Header "COPYRIGHT" |
| 127 |
Copyright 2001\-2016 The OpenSSL Project Authors. All Rights Reserved. |
| 128 |
.PP |
| 129 |
Licensed under the Apache License 2.0 (the "License"). You may not use |
| 130 |
this file except in compliance with the License. You can obtain a copy |
| 131 |
in the file LICENSE in the source distribution or at |
| 132 |
<https://www.openssl.org/source/license.html>. |