DES_random_key

- NAME
- SYNOPSIS
- DESCRIPTION
- BUGS
- NOTES
- HISTORY
- SEE ALSO
- COPYRIGHT

# 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

# SYNOPSIS

     #include <openssl/des.h>

     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);

# DESCRIPTION

This library contains a fast implementation of the DES encryption algorithm.

There are two phases to the use of DES encryption. The first is the generation of a DES_key_schedule from a key, the second is the actual encryption. A DES key is of type DES_cblock. This type is 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.

DES_random_key() generates a random key. The PRNG must be seeded prior to using this function (see EVP_DigestInit(3) etc. instead.

DES_quad_cksum() 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 out_count, 1, 2, 3 or 4 times. If output is non-NULL, the 8 bytes generated by each pass are written into output.

The following are DES-based transformations:

DES_fcrypt() is a fast version of the Unix crypt(3) function. This version takes only a small amount of space relative to other fast crypt() implementations. This is different to the normal crypt 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 crypt.

DES_crypt() is a faster replacement for the normal system crypt(). This function calls DES_fcrypt() with a static array passed as the third parameter. This mostly emulates the normal non-thread-safe semantics of crypt(3). The salt must be two ASCII characters.

DES_enc_write() writes len bytes to file descriptor fd from buffer buf. The data is encrypted via pcbc_encrypt (default) using sched for the key and iv as a starting vector. The actual data send down fd 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.

# BUGS

DES_3cbc_encrypt() is flawed and must not be used in applications.

DES_cbc_encrypt() does not modify ivec; use DES_ncbc_encrypt() instead.

DES_cfb_encrypt() and DES_ofb_encrypt() 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!

DES_string_to_key() is available for backward compatibility with the MIT library. New applications should use a cryptographic hash function. The same applies for DES_string_to_2key().

# NOTES

The des library was written to be source code compatible with the MIT Kerberos library.

Applications should use the higher level functions des_modes(7).

# HISTORY

The requirement that the salt parameter to DES_crypt() and DES_fcrypt() be two ASCII characters was first enforced in OpenSSL 1.1.0. Previous versions tried to use the letter uppercase A if both character were not present, and could crash when given non-ASCII on some platforms.

# SEE ALSO

EVP_EncryptInit(3)

# COPYRIGHT

Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the OpenSSL license (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.