| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386 |
- .\" -*- mode: troff; coding: utf-8 -*-
- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43)
- .\"
- .\" Standard preamble:
- .\" ========================================================================
- .de Sp \" Vertical space (when we can't use .PP)
- .if t .sp .5v
- .if n .sp
- ..
- .de Vb \" Begin verbatim text
- .ft CW
- .nf
- .ne \\$1
- ..
- .de Ve \" End verbatim text
- .ft R
- .fi
- ..
- .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>.
- .ie n \{\
- . ds C` ""
- . ds C' ""
- 'br\}
- .el\{\
- . ds C`
- . ds C'
- 'br\}
- .\"
- .\" Escape single quotes in literal strings from groff's Unicode transform.
- .ie \n(.g .ds Aq \(aq
- .el .ds Aq '
- .\"
- .\" If the F register is >0, we'll generate index entries on stderr for
- .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index
- .\" entries marked with X<> in POD. Of course, you'll have to process the
- .\" output yourself in some meaningful fashion.
- .\"
- .\" Avoid warning from groff about undefined register 'F'.
- .de IX
- ..
- .nr rF 0
- .if \n(.g .if rF .nr rF 1
- .if (\n(rF:(\n(.g==0)) \{\
- . if \nF \{\
- . de IX
- . tm Index:\\$1\t\\n%\t"\\$2"
- ..
- . if !\nF==2 \{\
- . nr % 0
- . nr F 2
- . \}
- . \}
- .\}
- .rr rF
- .\" ========================================================================
- .\"
- .IX Title "DES_RANDOM_KEY 3ossl"
- .TH DES_RANDOM_KEY 3ossl 2025-01-17 3.4.0 OpenSSL
- .\" For nroff, turn off justification. Always turn off hyphenation; it makes
- .\" way too many mistakes in technical documents.
- .if n .ad l
- .nh
- .SH NAME
- DES_random_key, DES_set_key, DES_key_sched, DES_set_key_checked,
- DES_set_key_unchecked, DES_set_odd_parity, DES_is_weak_key,
- DES_ecb_encrypt, DES_ecb2_encrypt, DES_ecb3_encrypt, DES_ncbc_encrypt,
- DES_cfb_encrypt, DES_ofb_encrypt, DES_pcbc_encrypt, DES_cfb64_encrypt,
- DES_ofb64_encrypt, DES_xcbc_encrypt, DES_ede2_cbc_encrypt,
- DES_ede2_cfb64_encrypt, DES_ede2_ofb64_encrypt, DES_ede3_cbc_encrypt,
- DES_ede3_cfb64_encrypt, DES_ede3_ofb64_encrypt,
- DES_cbc_cksum, DES_quad_cksum, DES_string_to_key, DES_string_to_2keys,
- DES_fcrypt, DES_crypt \- DES encryption
- .SH SYNOPSIS
- .IX Header "SYNOPSIS"
- .Vb 1
- \& #include <openssl/des.h>
- .Ve
- .PP
- The following functions have been deprecated since OpenSSL 3.0, and can be
- hidden entirely by defining \fBOPENSSL_API_COMPAT\fR with a suitable version value,
- see \fBopenssl_user_macros\fR\|(7):
- .PP
- .Vb 1
- \& void DES_random_key(DES_cblock *ret);
- \&
- \& int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule);
- \& int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule);
- \& int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule);
- \& void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule);
- \&
- \& void DES_set_odd_parity(DES_cblock *key);
- \& int DES_is_weak_key(const_DES_cblock *key);
- \&
- \& void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output,
- \& DES_key_schedule *ks, int enc);
- \& void DES_ecb2_encrypt(const_DES_cblock *input, DES_cblock *output,
- \& DES_key_schedule *ks1, DES_key_schedule *ks2, int enc);
- \& void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output,
- \& DES_key_schedule *ks1, DES_key_schedule *ks2,
- \& DES_key_schedule *ks3, int enc);
- \&
- \& void DES_ncbc_encrypt(const unsigned char *input, unsigned char *output,
- \& long length, DES_key_schedule *schedule, DES_cblock *ivec,
- \& int enc);
- \& void DES_cfb_encrypt(const unsigned char *in, unsigned char *out,
- \& int numbits, long length, DES_key_schedule *schedule,
- \& DES_cblock *ivec, int enc);
- \& void DES_ofb_encrypt(const unsigned char *in, unsigned char *out,
- \& int numbits, long length, DES_key_schedule *schedule,
- \& DES_cblock *ivec);
- \& void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output,
- \& long length, DES_key_schedule *schedule, DES_cblock *ivec,
- \& int enc);
- \& void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out,
- \& long length, DES_key_schedule *schedule, DES_cblock *ivec,
- \& int *num, int enc);
- \& void DES_ofb64_encrypt(const unsigned char *in, unsigned char *out,
- \& long length, DES_key_schedule *schedule, DES_cblock *ivec,
- \& int *num);
- \&
- \& void DES_xcbc_encrypt(const unsigned char *input, unsigned char *output,
- \& long length, DES_key_schedule *schedule, DES_cblock *ivec,
- \& const_DES_cblock *inw, const_DES_cblock *outw, int enc);
- \&
- \& void DES_ede2_cbc_encrypt(const unsigned char *input, unsigned char *output,
- \& long length, DES_key_schedule *ks1,
- \& DES_key_schedule *ks2, DES_cblock *ivec, int enc);
- \& void DES_ede2_cfb64_encrypt(const unsigned char *in, unsigned char *out,
- \& long length, DES_key_schedule *ks1,
- \& DES_key_schedule *ks2, DES_cblock *ivec,
- \& int *num, int enc);
- \& void DES_ede2_ofb64_encrypt(const unsigned char *in, unsigned char *out,
- \& long length, DES_key_schedule *ks1,
- \& DES_key_schedule *ks2, DES_cblock *ivec, int *num);
- \&
- \& void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output,
- \& long length, DES_key_schedule *ks1,
- \& DES_key_schedule *ks2, DES_key_schedule *ks3,
- \& DES_cblock *ivec, int enc);
- \& void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out,
- \& long length, DES_key_schedule *ks1,
- \& DES_key_schedule *ks2, DES_key_schedule *ks3,
- \& DES_cblock *ivec, int *num, int enc);
- \& void DES_ede3_ofb64_encrypt(const unsigned char *in, unsigned char *out,
- \& long length, DES_key_schedule *ks1,
- \& DES_key_schedule *ks2, DES_key_schedule *ks3,
- \& DES_cblock *ivec, int *num);
- \&
- \& DES_LONG DES_cbc_cksum(const unsigned char *input, DES_cblock *output,
- \& long length, DES_key_schedule *schedule,
- \& const_DES_cblock *ivec);
- \& DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[],
- \& long length, int out_count, DES_cblock *seed);
- \& void DES_string_to_key(const char *str, DES_cblock *key);
- \& void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2);
- \&
- \& char *DES_fcrypt(const char *buf, const char *salt, char *ret);
- \& char *DES_crypt(const char *buf, const char *salt);
- .Ve
- .SH DESCRIPTION
- .IX Header "DESCRIPTION"
- All of the functions described on this page are deprecated. Applications should
- instead use \fBEVP_EncryptInit_ex\fR\|(3), \fBEVP_EncryptUpdate\fR\|(3) and
- \&\fBEVP_EncryptFinal_ex\fR\|(3) or the equivalently named decrypt functions.
- .PP
- This library contains a fast implementation of the DES encryption
- algorithm.
- .PP
- There are two phases to the use of DES encryption. The first is the
- generation of a \fIDES_key_schedule\fR from a key, the second is the
- actual encryption. A DES key is of type \fIDES_cblock\fR. This type
- consists of 8 bytes with odd parity. The least significant bit in
- each byte is the parity bit. The key schedule is an expanded form of
- the key; it is used to speed the encryption process.
- .PP
- \&\fBDES_random_key()\fR generates a random key. The random generator must be
- seeded when calling this function.
- If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
- external circumstances (see \fBRAND\fR\|(7)), the operation will fail.
- If the function fails, 0 is returned.
- .PP
- Before a DES key can be used, it must be converted into the
- architecture dependent \fIDES_key_schedule\fR via the
- \&\fBDES_set_key_checked()\fR or \fBDES_set_key_unchecked()\fR function.
- .PP
- \&\fBDES_set_key_checked()\fR will check that the key passed is of odd parity
- and is not a weak or semi-weak key. If the parity is wrong, then \-1
- is returned. If the key is a weak key, then \-2 is returned. If an
- error is returned, the key schedule is not generated.
- .PP
- \&\fBDES_set_key()\fR works like \fBDES_set_key_checked()\fR and remains for
- backward compatibility.
- .PP
- \&\fBDES_set_odd_parity()\fR sets the parity of the passed \fIkey\fR to odd.
- .PP
- \&\fBDES_is_weak_key()\fR returns 1 if the passed key is a weak key, 0 if it
- is ok.
- .PP
- The following routines mostly operate on an input and output stream of
- \&\fIDES_cblock\fRs.
- .PP
- \&\fBDES_ecb_encrypt()\fR is the basic DES encryption routine that encrypts or
- decrypts a single 8\-byte \fIDES_cblock\fR in \fIelectronic code book\fR
- (ECB) mode. It always transforms the input data, pointed to by
- \&\fIinput\fR, into the output data, pointed to by the \fIoutput\fR argument.
- If the \fIencrypt\fR argument is nonzero (DES_ENCRYPT), the \fIinput\fR
- (cleartext) is encrypted in to the \fIoutput\fR (ciphertext) using the
- key_schedule specified by the \fIschedule\fR argument, previously set via
- \&\fIDES_set_key\fR. If \fIencrypt\fR is zero (DES_DECRYPT), the \fIinput\fR (now
- ciphertext) is decrypted into the \fIoutput\fR (now cleartext). Input
- and output may overlap. \fBDES_ecb_encrypt()\fR does not return a value.
- .PP
- \&\fBDES_ecb3_encrypt()\fR encrypts/decrypts the \fIinput\fR block by using
- three-key Triple-DES encryption in ECB mode. This involves encrypting
- the input with \fIks1\fR, decrypting with the key schedule \fIks2\fR, and
- then encrypting with \fIks3\fR. This routine greatly reduces the chances
- of brute force breaking of DES and has the advantage of if \fIks1\fR,
- \&\fIks2\fR and \fIks3\fR are the same, it is equivalent to just encryption
- using ECB mode and \fIks1\fR as the key.
- .PP
- The macro \fBDES_ecb2_encrypt()\fR is provided to perform two-key Triple-DES
- encryption by using \fIks1\fR for the final encryption.
- .PP
- \&\fBDES_ncbc_encrypt()\fR encrypts/decrypts using the \fIcipher-block-chaining\fR
- (CBC) mode of DES. If the \fIencrypt\fR argument is nonzero, the
- routine cipher-block-chain encrypts the cleartext data pointed to by
- the \fIinput\fR argument into the ciphertext pointed to by the \fIoutput\fR
- argument, using the key schedule provided by the \fIschedule\fR argument,
- and initialization vector provided by the \fIivec\fR argument. If the
- \&\fIlength\fR argument is not an integral multiple of eight bytes, the
- last block is copied to a temporary area and zero filled. The output
- is always an integral multiple of eight bytes.
- .PP
- \&\fBDES_xcbc_encrypt()\fR is RSA's DESX mode of DES. It uses \fIinw\fR and
- \&\fIoutw\fR to 'whiten' the encryption. \fIinw\fR and \fIoutw\fR are secret
- (unlike the iv) and are as such, part of the key. So the key is sort
- of 24 bytes. This is much better than CBC DES.
- .PP
- \&\fBDES_ede3_cbc_encrypt()\fR implements outer triple CBC DES encryption with
- three keys. This means that each DES operation inside the CBC mode is
- \&\f(CW\*(C`C=E(ks3,D(ks2,E(ks1,M)))\*(C'\fR. This mode is used by SSL.
- .PP
- The \fBDES_ede2_cbc_encrypt()\fR macro implements two-key Triple-DES by
- reusing \fIks1\fR for the final encryption. \f(CW\*(C`C=E(ks1,D(ks2,E(ks1,M)))\*(C'\fR.
- This form of Triple-DES is used by the RSAREF library.
- .PP
- \&\fBDES_pcbc_encrypt()\fR encrypts/decrypts using the propagating cipher block
- chaining mode used by Kerberos v4. Its parameters are the same as
- \&\fBDES_ncbc_encrypt()\fR.
- .PP
- \&\fBDES_cfb_encrypt()\fR encrypts/decrypts using cipher feedback mode. This
- method takes an array of characters as input and outputs an array of
- characters. It does not require any padding to 8 character groups.
- Note: the \fIivec\fR variable is changed and the new changed value needs to
- be passed to the next call to this function. Since this function runs
- a complete DES ECB encryption per \fInumbits\fR, this function is only
- suggested for use when sending a small number of characters.
- .PP
- \&\fBDES_cfb64_encrypt()\fR
- implements CFB mode of DES with 64\-bit feedback. Why is this
- useful you ask? Because this routine will allow you to encrypt an
- arbitrary number of bytes, without 8 byte padding. Each call to this
- routine will encrypt the input bytes to output and then update ivec
- and num. num contains 'how far' we are though ivec. If this does
- not make much sense, read more about CFB mode of DES.
- .PP
- \&\fBDES_ede3_cfb64_encrypt()\fR and \fBDES_ede2_cfb64_encrypt()\fR is the same as
- \&\fBDES_cfb64_encrypt()\fR except that Triple-DES is used.
- .PP
- \&\fBDES_ofb_encrypt()\fR encrypts using output feedback mode. This method
- takes an array of characters as input and outputs an array of
- characters. It does not require any padding to 8 character groups.
- Note: the \fIivec\fR variable is changed and the new changed value needs to
- be passed to the next call to this function. Since this function runs
- a complete DES ECB encryption per \fInumbits\fR, this function is only
- suggested for use when sending a small number of characters.
- .PP
- \&\fBDES_ofb64_encrypt()\fR is the same as \fBDES_cfb64_encrypt()\fR using Output
- Feed Back mode.
- .PP
- \&\fBDES_ede3_ofb64_encrypt()\fR and \fBDES_ede2_ofb64_encrypt()\fR is the same as
- \&\fBDES_ofb64_encrypt()\fR, using Triple-DES.
- .PP
- The following functions are included in the DES library for
- compatibility with the MIT Kerberos library.
- .PP
- \&\fBDES_cbc_cksum()\fR produces an 8 byte checksum based on the input stream
- (via CBC encryption). The last 4 bytes of the checksum are returned
- and the complete 8 bytes are placed in \fIoutput\fR. This function is
- used by Kerberos v4. Other applications should use
- \&\fBEVP_DigestInit\fR\|(3) etc. instead.
- .PP
- \&\fBDES_quad_cksum()\fR is a Kerberos v4 function. It returns a 4 byte
- checksum from the input bytes. The algorithm can be iterated over the
- input, depending on \fIout_count\fR, 1, 2, 3 or 4 times. If \fIoutput\fR is
- non-NULL, the 8 bytes generated by each pass are written into
- \&\fIoutput\fR.
- .PP
- The following are DES-based transformations:
- .PP
- \&\fBDES_fcrypt()\fR is a fast version of the Unix \fBcrypt\fR\|(3) function. This
- version takes only a small amount of space relative to other fast
- \&\fBcrypt()\fR implementations. This is different to the normal \fBcrypt()\fR in
- that the third parameter is the buffer that the return value is
- written into. It needs to be at least 14 bytes long. This function
- is thread safe, unlike the normal \fBcrypt()\fR.
- .PP
- \&\fBDES_crypt()\fR is a faster replacement for the normal system \fBcrypt()\fR.
- This function calls \fBDES_fcrypt()\fR with a static array passed as the
- third parameter. This mostly emulates the normal non-thread-safe semantics
- of \fBcrypt\fR\|(3).
- The \fBsalt\fR must be two ASCII characters.
- .PP
- The values returned by \fBDES_fcrypt()\fR and \fBDES_crypt()\fR are terminated by NUL
- character.
- .PP
- \&\fBDES_enc_write()\fR writes \fIlen\fR bytes to file descriptor \fIfd\fR from
- buffer \fIbuf\fR. The data is encrypted via \fIpcbc_encrypt\fR (default)
- using \fIsched\fR for the key and \fIiv\fR as a starting vector. The actual
- data send down \fIfd\fR consists of 4 bytes (in network byte order)
- containing the length of the following encrypted data. The encrypted
- data then follows, padded with random data out to a multiple of 8
- bytes.
- .SH BUGS
- .IX Header "BUGS"
- \&\fBDES_cbc_encrypt()\fR does not modify \fBivec\fR; use \fBDES_ncbc_encrypt()\fR
- instead.
- .PP
- \&\fBDES_cfb_encrypt()\fR and \fBDES_ofb_encrypt()\fR operates on input of 8 bits.
- What this means is that if you set numbits to 12, and length to 2, the
- first 12 bits will come from the 1st input byte and the low half of
- the second input byte. The second 12 bits will have the low 8 bits
- taken from the 3rd input byte and the top 4 bits taken from the 4th
- input byte. The same holds for output. This function has been
- implemented this way because most people will be using a multiple of 8
- and because once you get into pulling bytes input bytes apart things
- get ugly!
- .PP
- \&\fBDES_string_to_key()\fR is available for backward compatibility with the
- MIT library. New applications should use a cryptographic hash function.
- The same applies for \fBDES_string_to_2key()\fR.
- .SH NOTES
- .IX Header "NOTES"
- The \fBdes\fR library was written to be source code compatible with
- the MIT Kerberos library.
- .PP
- Applications should use the higher level functions
- \&\fBEVP_EncryptInit\fR\|(3) etc. instead of calling these
- functions directly.
- .PP
- Single-key DES is insecure due to its short key size. ECB mode is
- not suitable for most applications; see \fBdes_modes\fR\|(7).
- .SH "RETURN VALUES"
- .IX Header "RETURN VALUES"
- \&\fBDES_set_key()\fR, \fBDES_key_sched()\fR, and \fBDES_set_key_checked()\fR
- return 0 on success or negative values on error.
- .PP
- \&\fBDES_is_weak_key()\fR returns 1 if the passed key is a weak key, 0 if it
- is ok.
- .PP
- \&\fBDES_cbc_cksum()\fR and \fBDES_quad_cksum()\fR return 4\-byte integer representing the
- last 4 bytes of the checksum of the input.
- .PP
- \&\fBDES_fcrypt()\fR returns a pointer to the caller-provided buffer and \fBDES_crypt()\fR \-
- to a static buffer on success; otherwise they return NULL.
- .SH "SEE ALSO"
- .IX Header "SEE ALSO"
- \&\fBdes_modes\fR\|(7),
- \&\fBEVP_EncryptInit\fR\|(3)
- .SH HISTORY
- .IX Header "HISTORY"
- All of these functions were deprecated in OpenSSL 3.0.
- .PP
- The requirement that the \fBsalt\fR parameter to \fBDES_crypt()\fR and \fBDES_fcrypt()\fR
- be two ASCII characters was first enforced in
- OpenSSL 1.1.0. Previous versions tried to use the letter uppercase \fBA\fR
- if both character were not present, and could crash when given non-ASCII
- on some platforms.
- .SH COPYRIGHT
- .IX Header "COPYRIGHT"
- Copyright 2000\-2020 The OpenSSL Project Authors. All Rights Reserved.
- .PP
- Licensed under the Apache License 2.0 (the "License"). You may not use
- this file except in compliance with the License. You can obtain a copy
- in the file LICENSE in the source distribution or at
- <https://www.openssl.org/source/license.html>.
|