CIPHER(1)

NAME
cipher, decipher - Fast DES-compatible encryption

SYNOPSIS
cipher [ -de ] [ -i ivec ] [ -x hexkey ] [ -k keystr ]

DESCRIPTION

Cipher is an encryption program compatible with the National Bureau of Standards Data Encryption Standard, published in FIPS Publication 46-1 (January 22, 1988).

Cipher reads from the standard input and writes on the standard output. The keystr is a character string which selects a particular transformation. The output will be unintelligible to anyone who does not specify the same keystr to the decipher program. Output will contain the same number of characters and the input but consists of binary characters of eight-bits each. If no key is given (using the, -k or -x option), cipher demands a key from the terminal and turns off printing while the key is typed in. This is recommended since users running the ps(1) can see keys specified on the command line. To assist in preventing typographic errors during key entry, each key must be entered twice. This feature may be disabled by specifying the -n option.

  Options

-d  Used to decipher previously ciphered text.

-e  Encipher mode. More than one -e or -d option forces multiple encryption.

-n  inhibits key verification

-k keystr
    Specifies a character string to use as the key for encryption/decryption.

-x hexkey
    Specifies the key as a hexadecimal number. One to 16 digits may be specified. This key is left-justified and zero-padded.

-i ivec
    Specifies the initialization vector for cipher-feedback mode (CFB) as a one to 16-digit hexadecimal number. This will be right-justified and zero padded.

The -x, -i, and -k options are primarily useful for test scripts.

Unlike the crypt command, cipher is not its own inverse; you must use the -d option to decipher previously encrypted text or invoke the command as decipher.

The security of the Data Encryption Standard has been controversial. In particular, the number of possible keys has been criticized as too small; only 56-bits are used. To assist in minimizing this risk, multiple-encryption, and "random" key-generation from text strings is provided. The key string may be any length other than zero. This string is hashed to produce the 56-bit key used for the DES. To help thwart dictionary attacks, the key should be as long as convenient and contain a mix of upper-case, lower-case and symbolic characters (space and control characters are permitted). Short sentences or phrases consisting of nonsense words are recommended. These precautions should make it more difficult for someone to use computer(s) (or DES hardware) to guess your key by trial and error. This is a very serious threat and should not be ignored.

For particularly sensitive information, double or triple encryption with independent keys should be used. Attempts to crack the encrypted text may be made more difficult by removing redundancy from the input by using the compress(1) command prior to enciphering and subsequent to deciphering. (Even further security can be obtained by specifying the -n option to compress so that no header is included.)

The following command illustrates encryption of the file clear to produce the file cypher.

    compress -n <clear | cipher >cypher
    Input Key:
    Verify Key:
    rm clear

This command is used to examine the previously enciphered file:

    cipher -d <cypher | uncompress -n | more
    Input Key:

The following command may be used to accomplish multiple-encipherment: (The key text is shown only for illustration)

    cipher -e -e <plain >cipherfile
    Input Key:firsty keyzy
    Input Key:seconDzy keysy

A prompt for each cipher key is shown. When multiple-encipherment is selected, care should be taken to specify the keys in the reverse order when deciphering. All the following commands below are equivalent ways of deciphering the above:

    cipher -d -d <cipherfile >plain
    Input Key:seconDzy keysy
    Input Key:firsty keyzy
    cipher -dk "seconDzy keysy" -dk "firsty keyzy" <cipherfile >plain
    cipher -d -k "seconDzy keysy" <cipherfile \
    | decipher -k "firsty keyzy" >plain

For transmitting encrypted text though the mail system, the atob(1), and btoa(1), commands may be used. These programs are available as part of the compress 4.0 package. (also included with the cipher package)

For example, to send a secret message, typed from the terminal:

    compress -n | cipher | btoa | mail user

The receiver could save the message in the file secret and read it using the command:

    atob <secret | decipher | uncompress -n

Notice that you did not have to worry about stripping mailer headers from the text because the atob program does that automatically.

Since the Data Encryption Standard is, by definition, implemented only in hardware, this algorithm should not be considered as a DES implementation. However, it should yield the same results as DES hardware using 64-bit Cipher-Feedback Mode (CFB). (See FIPS Publications 81 and 74).

The key used as input to the DES is generated as follows: The keystring is padded with blank characters to a positive multiple of eight. A secondary key is generated from the first eight characters of keystr by shifting each character left by one (discarding each high-order bit). This secondary key is used to produce a 64-bit authentication code by enciphering the rest of keystr using DES in cipher-block-chaining (CBC) encryption mode with an initialization vector of zeros. This 64-bit authentication code is used as the encryption key. This is the same method used by FIPS publication 112 except the authentication code is not converted into printable form. This is also identical to FIPS publication 113 with the input padded with blanks instead of zeros. The initialization vector is generated from a string of all zeros.

WARNINGS
If output is piped to nroff(1) and the encryption key is not given on the command line, cipher can leave terminal modes with echoing disabled. (see stty(1)).

If two or more files encrypted with the same key are concatenated and an attempt is made to decrypt the result, only the contents of the first of the original files will be decrypted correctly.

This code is not compatible with Sun's des program. Unlike Sun's this code preserves the original file size and is also suitable for use in communications protocols where one byte of output occurs as each byte is input. As far as I know, this is the only fast implementation of DES in cipher-feedback mode which has the above two properties.

ACKNOWLEDGEMENTS
The author has made every attempt to produce the fastest, portable DES-compatible program possible, but considerable speed improvements remain. Comments and improvements will be greatly appreciated and should be directed to the author:

David A. Barrett (barrett@asgard.cs.Colorado.EDU)

Copyright 1994 by David. A. Barrett

This program is not to be distributed for profit or included in such software without written permission from the author (this means you, TVAnswer). No permission is required for non-profit use.

FILES
/dev/tty    for typed key

SEE ALSO
crypt(1), compress(1), btoa(1), atob(1), makekey(1), des(3), desCFB(3), crypt(3), stty(1).