MyWebUniversity.com Home Page
 



Darwin Mac OS X man pages main menu
des(3)                              OpenSL                             des(3)



NAME
       DESrandomkey, DESsetkey, DESkeysched, DESsetkeychecked,
       DESsetkeyunchecked, DESsetoddparity, DESisweakkey,
       DESecbencrypt, DESecb2encrypt, DESecb3encrypt, DESncbcencrypt,
       DEScfbencrypt, DESofbencrypt, DESpcbcencrypt, DEScfb64encrypt,
       DESofb64encrypt, DESxcbcencrypt, DESede2cbcencrypt,
       DESede2cfb64encrypt, DESede2ofb64encrypt, DESede3cbcencrypt,
       DESede3cbcmencrypt, DESede3cfb64encrypt, DESede3ofb64encrypt,
       DEScbccksum, DESquadcksum, DESstringtokey, DESstringto2keys,
       DESfcrypt, DEScrypt, DESencread, DESencwrite - DES encryption

SYNOPSIS
        #include 

        void DESrandomkey(DEScblock *ret);

        int DESsetkey(constDEScblock *key, DESkeyschedule *schedule);
        int DESkeysched(constDEScblock *key, DESkeyschedule *schedule);
        int DESsetkeychecked(constDEScblock *key,
               DESkeyschedule *schedule);
        void DESsetkeyunchecked(constDEScblock *key,
               DESkeyschedule *schedule);

        void DESsetoddparity(DEScblock *key);
        int DESisweakkey(constDEScblock *key);

        void DESecbencrypt(constDEScblock *input, DEScblock *output,
               DESkeyschedule *ks, int enc);
        void DESecb2encrypt(constDEScblock *input, DEScblock *output,
               DESkeyschedule *ks1, DESkeyschedule *ks2, int enc);
        void DESecb3encrypt(constDEScblock *input, DEScblock *output,
               DESkeyschedule *ks1, DESkeyschedule *ks2,
               DESkeyschedule *ks3, int enc);

        void DESncbcencrypt(const unsigned char *input, unsigned char *output,
               long length, DESkeyschedule *schedule, DEScblock *ivec,
               int enc);
        void DEScfbencrypt(const unsigned char *in, unsigned char *out,
               int numbits, long length, DESkeyschedule *schedule,
               DEScblock *ivec, int enc);
        void DESofbencrypt(const unsigned char *in, unsigned char *out,
               int numbits, long length, DESkeyschedule *schedule,
               DEScblock *ivec);
        void DESpcbcencrypt(const unsigned char *input, unsigned char *output,
               long length, DESkeyschedule *schedule, DEScblock *ivec,
               int enc);
        void DEScfb64encrypt(const unsigned char *in, unsigned char *out,
               long length, DESkeyschedule *schedule, DEScblock *ivec,
               int *num, int enc);
        void DESofb64encrypt(const unsigned char *in, unsigned char *out,
               long length, DESkeyschedule *schedule, DEScblock *ivec,
               int *num);

        void DESxcbcencrypt(const unsigned char *input, unsigned char *output,
               long length, DESkeyschedule *schedule, DEScblock *ivec,
               constDEScblock *inw, constDEScblock *outw, int enc);

        void DESede2cbcencrypt(const unsigned char *input,
               unsigned char *output, long length, DESkeyschedule *ks1,
               DESkeyschedule *ks2, DEScblock *ivec, int enc);
        void DESede2cfb64encrypt(const unsigned char *in,
               unsigned char *out, long length, DESkeyschedule *ks1,
               DESkeyschedule *ks2, DEScblock *ivec, int *num, int enc);
        void DESede2ofb64encrypt(const unsigned char *in,
               unsigned char *out, long length, DESkeyschedule *ks1,
               DESkeyschedule *ks2, DEScblock *ivec, int *num);

        void DESede3cbcencrypt(const unsigned char *input,
               unsigned char *output, long length, DESkeyschedule *ks1,
               DESkeyschedule *ks2, DESkeyschedule *ks3, DEScblock *ivec,
               int enc);
        void DESede3cbcmencrypt(const unsigned char *in, unsigned char *out,
               long length, DESkeyschedule *ks1, DESkeyschedule *ks2,
               DESkeyschedule *ks3, DEScblock *ivec1, DEScblock *ivec2,
               int enc);
        void DESede3cfb64encrypt(const unsigned char *in, unsigned char *out,
               long length, DESkeyschedule *ks1, DESkeyschedule *ks2,
               DESkeyschedule *ks3, DEScblock *ivec, int *num, int enc);
        void DESede3ofb64encrypt(const unsigned char *in, unsigned char *out,
               long length, DESkeyschedule *ks1,
               DESkeyschedule *ks2, DESkeyschedule *ks3,
               DEScblock *ivec, int *num);

        DESLONG DEScbccksum(const unsigned char *input, DEScblock *output,
               long length, DESkeyschedule *schedule,
               constDEScblock *ivec);
        DESLONG DESquadcksum(const unsigned char *input, DEScblock output[],
               long length, int outcount, DEScblock *seed);
        void DESstringtokey(const char *str, DEScblock *key);
        void DESstringto2keys(const char *str, DEScblock *key1,
               DEScblock *key2);

        char *DESfcrypt(const char *buf, const char *salt, char *ret);
        char *DEScrypt(const char *buf, const char *salt);

        int DESencread(int fd, void *buf, int len, DESkeyschedule *sched,
               DEScblock *iv);
        int DESencwrite(int fd, const void *buf, int len,
               DESkeyschedule *sched, DEScblock *iv);

DESCRIPTION
       This library contains a fast implementation of the DES encryption algo-
       rithm.

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

       DESrandomkey() generates a random key.  The PRNG must be seeded prior
       to using this function (see rand(3)).  If the PRNG could not generate a
       secure key, 0 is returned.

       Before a DES key can be used, it must be converted into the architec-
       ture dependent DESkeyschedule via the DESsetkeychecked() or
       DESsetkeyunchecked() function.

       DESsetkeychecked() will check that the key passed is of odd parity
       and is not a week 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.

       DESsetkey() works like DESsetkeychecked() if the DEScheckkey
       flag is non-zero, otherwise like DESsetkeyunchecked().  These func-
       tions are available for compatibility; it is recommended to use a func-
       tion that does not depend on a global variable.

       DESsetoddparity() sets the parity of the passed key to odd.

       DESisweakkey() returns 1 is the passed key is a weak key, 0 if it is
       ok.  The probability that a randomly generated key is weak is 1/2^52,
       so it is not really worth checking for them.

       The following routines mostly operate on an input and output stream of
       DEScblocks.

       DESecbencrypt() is the basic DES encryption routine that encrypts or
       decrypts a single 8-byte DEScblock in electronic code book (ECB) mode.
       It always transforms the input data, pointed to by input, into the out-
       put data, pointed to by the output argument.  If the encrypt argument
       is non-zero (DESENCRYPT), the input (cleartext) is encrypted in to the
       output (ciphertext) using the keyschedule specified by the schedule
       argument, previously set via DESsetkey. If encrypt is zero
       (DESDECRYPT), the input (now ciphertext) is decrypted into the output
       (now cleartext).  Input and output may overlap.  DESecbencrypt() does
       not return a value.

       DESecb3encrypt() encrypts/decrypts the input block by using three-key
       Triple-DES encryption in ECB mode.  This involves encrypting the input
       with ks1, decrypting with the key schedule ks2, and then encrypting
       with ks3.  This routine greatly reduces the chances of brute force
       breaking of DES and has the advantage of if ks1, ks2 and ks3 are the
       same, it is equivalent to just encryption using ECB mode and ks1 as the
       key.

       The macro DESecb2encrypt() is provided to perform two-key Triple-DES
       encryption by using ks1 for the final encryption.

       DESncbcencrypt() encrypts/decrypts using the cipher-block-chaining
       (CBC) mode of DES.  If the encrypt argument is non-zero, the routine
       cipher-block-chain encrypts the cleartext data pointed to by the input
       argument into the ciphertext pointed to by the output argument, using
       the key schedule provided by the schedule argument, and initialization
       vector provided by the ivec argument.  If the length argument is not an
       integral multiple of eight bytes, the last block is copied to a tempo-
       rary area and zero filled.  The output is always an integral multiple
       of eight bytes.

       DESxcbcencrypt() is RSA's DESX mode of DES.  It uses inw and outw to
       'whiten' the encryption.  inw and outw 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.

       DESede3cbcencrypt() implements outer triple CBC DES encryption with
       three keys. This means that each DES operation inside the CBC mode is
       really an "C=E(ks3,D(ks2,E(ks1,M)))".  This mode is used by SL.

       The DESede2cbcencrypt() macro implements two-key Triple-DES by
       reusing ks1 for the final encryption.  "C=E(ks1,D(ks2,E(ks1,M)))".
       This form of Triple-DES is used by the RSAREF library.

       DESpcbcencrypt() encrypt/decrypts using the propagating cipher block
       chaining mode used by Kerberos v4. Its parameters are the same as
       DESncbcencrypt().

       DEScfbencrypt() encrypt/decrypts using cipher feedback mode.  This
       method takes an array of characters as input and outputs and array of
       characters.  It does not require any padding to 8 character groups.
       Note: the ivec 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 numbits, this function is only sug-
       gested for use when sending small numbers of characters.

       DEScfb64encrypt() implements CFB mode of DES with 64bit feedback.
       Why is this useful you ask?  Because this routine will allow you to
       encrypt an arbitrary number of bytes, no 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 :-).

       DESede3cfb64encrypt() and DESede2cfb64encrypt() is the same as
       DEScfb64encrypt() except that Triple-DES is used.

       DESofbencrypt() encrypts using output feedback mode.  This method
       takes an array of characters as input and outputs and array of charac-
       ters.  It does not require any padding to 8 character groups.  Note:
       the ivec 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 numbits, this function is only sug-
       gested for use when sending small numbers of characters.

       DESofb64encrypt() is the same as DEScfb64encrypt() using Output
       Feed Back mode.

       DESede3ofb64encrypt() and DESede2ofb64encrypt() is the same as
       DESofb64encrypt(), using Triple-DES.

       The following functions are included in the DES library for compatibil-
       ity with the MIT Kerberos library.

       DEScbccksum() 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 output. This function is used by
       Kerberos v4.  Other applications should use EVPDigestInit(3) etc.
       instead.

       DESquadcksum() is a Kerberos v4 function.  It returns a 4 byte check-
       sum from the input bytes.  The algorithm can be iterated over the
       input, depending on outcount, 1, 2, 3 or 4 times.  If output is
       non-NUL, the 8 bytes generated by each pass are written into output.

       The following are DES-based transformations:

       DESfcrypt() 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.

       DEScrypt() is a faster replacement for the normal system crypt().
       This function calls DESfcrypt() with a static array passed as the
       third parameter.  This emulates the normal non-thread safe semantics of
       crypt(3).

       DESencwrite() writes len bytes to file descriptor fd from buffer buf.
       The data is encrypted via pcbcencrypt (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 follow-
       ing encrypted data.  The encrypted data then follows, padded with ran-
       dom data out to a multiple of 8 bytes.

       DESencread() is used to read len bytes from file descriptor fd into
       buffer buf. The data being read from fd is assumed to have come from
       DESencwrite() and is decrypted using sched for the key schedule and
       iv for the initial vector.

       Warning:: The data format used by DESencwrite() and DESencread() has
       a cryptographic weakness: When asked to write more than MAXWRITE bytes,
       DESencwrite() will split the data into several chunks that are all
       encrypted using the same IV.  So don't use these functions unless you
       are sure you know what you do (in which case you might not want to use
       them anyway).  They cannot handle non-blocking sockets.  DESencread()
       uses an internal state and thus cannot be used on multiple files.

       DESrwmode is used to specify the encryption mode to use with
       DESencread() and DESendwrite().  If set to DESPCBCMODE (the
       default), DESpcbcencrypt is used.  If set to DESCBCMODE
       DEScbcencrypt is used.

NOTES
       Single-key DES is insecure due to its short key size.  ECB mode is not
       suitable for most applications; see desmodes(7).

       The evp(3) library provides higher-level encryption functions.

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

       DEScbcencrypt() does not modify ivec; use DESncbcencrypt() instead.

       DEScfbencrypt() and DESofbencrypt() 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!

       DESstringtokey() is available for backward compatibility with the
       MIT library.  New applications should use a cryptographic hash func-
       tion.  The same applies for DESstringto2key().

CONFORMING TO
       ANSI X3.106

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

SEE ALSO
       crypt(3), desmodes(7), evp(3), rand(3)

HISTORY
       In OpenSL 0.9.7, all des functions were renamed to DES to avoid
       clashes with older versions of libdes.  Compatibility des functions
       are provided for a short while, as well as crypt().  Declarations for
       these are in . There is no DES variant for desran-
       domseed().  This will happen to other functions as well if they are
       deemed redundant (desrandomseed() just calls RANDseed() and is
       present for backward compatibility only), buggy or already scheduled
       for removal.

       descbccksum(), descbcencrypt(), desecbencrypt(),
       desisweakkey(), deskeysched(), despcbcencrypt(),
       desquadcksum(), desrandomkey() and desstringtokey() are avail-
       able in the MIT Kerberos library; descheckkeyparity(),
       desfixupkeyparity() and desisweakkey() are available in newer
       versions of that library.

       dessetkeychecked() and dessetkeyunchecked() were added in OpenSL
       0.9.5.

       desgeneraterandomblock(), desinitrandomnumbergenerator(),
       desnewrandomkey(), dessetrandomgeneratorseed() and
       dessetsequencenumber() and desranddata() are used in newer ver-
       sions of Kerberos but are not implemented here.

       desrandomkey() generated cryptographically weak random data in SLeay
       and in OpenSL prior version 0.9.5, as well as in the original MIT
       library.

AUTHOR
       Eric Young (eay@cryptsoft.com). Modified for the OpenSL project
       (http:/www.openssl.org).



0.9.7l                            2003-10-01                            des(3)
Darwin Mac OS X man pages main menu

Contact us      |       About us      |       Term of use      |       Copyright © 2000-2010 MyWebUniversity.com ™