4.4BSD snapshot (revision 8.1); add 1993 to copyright
[unix-history] / usr / src / usr.bin / bdes / bdes.1
CommitLineData
458416e5
KB
1.\" Copyright (c) 1991, 1993
2.\" The Regents of the University of California. All rights reserved.
c4e28bd8
KB
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Matt Bishop of Dartmouth College.
6.\"
7.\" %sccs.include.redist.roff%
8.\"
458416e5 9.\" @(#)bdes.1 8.1 (Berkeley) %G%
c4e28bd8
KB
10.\"
11.TH BDES 1 ""
707ca442 12.UC 6
886521eb
KB
13.SH NAME
14bdes \- encrypt/decrypt using the Data Encryption Standard
15.SH SYNOPSIS
c4e28bd8
KB
16.nf
17.ft B
18bdes [ \-abdp ] [ \-F N ] [ \-f N ] [ \-k key ]
19.ti +5
20[ \-m N ] [ \-o N ] [ \-v vector ]
21.ft R
22.fi
886521eb
KB
23.SH DESCRIPTION
24.I Bdes
c4e28bd8
KB
25implements all DES modes of operation described in FIPS PUB 81,
26including alternative cipher feedback mode and both authentication
27modes.
28.I Bdes
29reads from the standard input and writes to the standard output.
30By default, the input is encrypted using cipher block chaining mode.
707ca442 31Using the same key for encryption and decryption preserves plain text.
c4e28bd8
KB
32.PP
33All modes but the electronic code book mode require an initialization
34vector; if none is supplied, the zero vector is used.
886521eb
KB
35If no
36.I key
c4e28bd8
KB
37is specified on the command line, the user is prompted for one (see
38.IR getpass (3)
39for more details).
886521eb 40.PP
c4e28bd8 41The options are as follows:
886521eb 42.TP
c4e28bd8
KB
43\-a
44The key and initialization vector strings are to be taken as ASCII,
45suppressing the special interpretation given to leading ``0X'', ``0x'',
46``0B'', and ``0b'' characters.
47This flag applies to
886521eb
KB
48.I both
49the key and initialization vector.
50.TP
c4e28bd8 51\-b
886521eb
KB
52Use electronic code book mode.
53.TP
c4e28bd8 54\-d
8ca535de 55Decrypt the input.
c4e28bd8
KB
56.TP
57\-F
886521eb 58Use
c4e28bd8
KB
59.IR N -bit
60alternative cipher feedback mode.
886521eb 61Currently
c4e28bd8
KB
62.I N
63must be a multiple of 7 between 7 and 56 inclusive (this does not conform
64to the alternative CFB mode specification).
886521eb 65.TP
c4e28bd8 66\-f
886521eb 67Use
c4e28bd8
KB
68.IR N -bit
69cipher feedback mode.
886521eb 70Currently
c4e28bd8
KB
71.I N
72must be a multiple of 8 between 8 and 64 inclusive (this does not conform
73to the standard CFB mode specification).
886521eb 74.TP
c4e28bd8
KB
75\-k
76Use
77.I key
8ca535de 78as the cryptographic key.
886521eb 79.TP
c4e28bd8 80\-m
886521eb 81Compute a message authentication code (MAC) of
c4e28bd8 82.I N
886521eb 83bits on the input.
c4e28bd8
KB
84The value of
85.I N
86must be between 1 and 64 inclusive; if
87.I N
88is not a multiple of 8, enough 0 bits will be added to pad the MAC length
886521eb
KB
89to the nearest multiple of 8.
90Only the MAC is output.
c4e28bd8
KB
91MACs are only available in cipher block chaining mode or in cipher feedback
92mode.
886521eb 93.TP
c4e28bd8 94\-o
886521eb 95Use
c4e28bd8 96.IR N -bit
886521eb
KB
97output feedback mode.
98Currently
c4e28bd8
KB
99.I N
100must be a multiple of 8 between 8 and 64 inclusive (this does not conform
101to the OFB mode specification).
886521eb 102.TP
c4e28bd8 103\-p
886521eb 104Disable the resetting of the parity bit.
c4e28bd8
KB
105This flag forces the parity bit of the key to be used as typed, rather than
106making each character be of odd parity.
107It is used only if the key is given in ASCII.
886521eb 108.TP
c4e28bd8 109\-v
886521eb 110Set the initialization vector to
c4e28bd8 111.IR vector ;
886521eb
KB
112the vector is interpreted in the same way as the key.
113The vector is ignored in electronic codebook mode.
114.PP
8ca535de 115The key and initialization vector are taken as sequences of ASCII
c4e28bd8
KB
116characters which are then mapped into their bit representations.
117If either begins with ``0X'' or ``0x'',
118that one is taken as a sequence of hexadecimal digits indicating the
119bit pattern;
120if either begins with ``0B'' or ``0b'',
121that one is taken as a sequence of binary digits indicating the bit pattern.
122In either case,
123only the leading 64 bits of the key or initialization vector
124are used,
125and if fewer than 64 bits are provided, enough 0 bits are appended
126to pad the key to 64 bits.
127.PP
128According to the DES standard, the low-order bit of each character in the
129key string is deleted.
130Since most ASCII representations set the high-order bit to 0, simply
131deleting the low-order bit effectively reduces the size of the key space
132from 2\u\s-356\s0\d to 2\u\s-348\s0\d keys.
133To prevent this, the high-order bit must be a function depending in part
134upon the low-order bit; so, the high-order bit is set to whatever value
135gives odd parity.
136This preserves the key space size.
137Note this resetting of the parity bit is
138.I not
139done if the key is given in binary or hex, and can be disabled for ASCII
140keys as well.
141.PP
142The DES is considered a very strong cryptosystem, and other than table lookup
143attacks, key search attacks, and Hellman's time-memory tradeoff (all of which
144are very expensive and time-consuming), no cryptanalytic methods for breaking
145the DES are known in the open literature.
146No doubt the choice of keys and key security are the most vulnerable aspect
147of
886521eb
KB
148.IR bdes .
149.SH IMPLEMENTATION NOTES
150For implementors wishing to write software compatible with this program,
151the following notes are provided.
c4e28bd8
KB
152This software is believed to be compatible with the implementation of the
153data encryption standard distributed by Sun Microsystems, Inc.
886521eb 154.PP
c4e28bd8
KB
155In the ECB and CBC modes, plaintext is encrypted in units of 64 bits (8 bytes,
156also called a block).
886521eb
KB
157To ensure that the plaintext file is encrypted correctly,
158.I bdes
c4e28bd8
KB
159will (internally) append from 1 to 8 bytes, the last byte containing an
160integer stating how many bytes of that final block are from the plaintext
161file, and encrypt the resulting block.
162Hence, when decrypting, the last block may contain from 0 to 7 characters
163present in the plaintext file, and the last byte tells how many.
164Note that if during decryption the last byte of the file does not contain an
165integer between 0 and 7, either the file has been corrupted or an incorrect
166key has been given.
167A similar mechanism is used for the OFB and CFB modes, except that those
168simply require the length of the input to be a multiple of the mode size,
169and the final byte contains an integer between 0 and one less than the number
170of bytes being used as the mode.
171(This was another reason that the mode size must be a multiple of 8 for those
172modes.)
886521eb 173.PP
c4e28bd8
KB
174Unlike Sun's implementation, unused bytes of that last block are not filled
175with random data, but instead contain what was in those byte positions in
176the preceding block.
177This is quicker and more portable, and does not weaken the encryption
8ca535de 178significantly.
886521eb 179.PP
c4e28bd8
KB
180If the key is entered in ASCII, the parity bits of the key characters are set
181so that each key character is of odd parity.
182Unlike Sun's implementation, it is possible to enter binary or hexadecimal
183keys on the command line, and if this is done, the parity bits are
886521eb
KB
184.I not
185reset.
186This allows testing using arbitrary bit patterns as keys.
187.PP
c4e28bd8
KB
188The Sun implementation always uses an initialization vector of 0
189(that is, all zeroes).
886521eb
KB
190By default,
191.I bdes
c4e28bd8 192does too, but this may be changed from the command line.
886521eb 193.SH SEE ALSO
c4e28bd8
KB
194crypt(1), crypt(3), getpass(3)
195.sp
886521eb
KB
196.IR "Data Encryption Standard" ,
197Federal Information Processing Standard #46,
198National Bureau of Standards,
199U.S. Department of Commerce,
200Washington DC
201(Jan. 1977)
c4e28bd8 202.sp
886521eb
KB
203.IR "DES Modes of Operation" ,
204Federal Information Processing Standard #81,
205National Bureau of Standards,
206U.S. Department of Commerce
207Washington DC
208(Dec. 1980)
c4e28bd8 209.sp
886521eb
KB
210Dorothy Denning,
211.IR "Cryptography and Data Security" ,
212Addison-Wesley Publishing Co.,
213Reading, MA
214\(co1982.
c4e28bd8 215.sp
886521eb 216Matt Bishop,
707ca442 217.IR "Implementation Notes on bdes(1)" ,
886521eb
KB
218Technical Report PCS-TR-91-158,
219Department of Mathematics and Computer Science,
220Dartmouth College,
221Hanover, NH 03755
8ca535de 222(Apr. 1991).
480cb76e
KB
223.SH DISCLAIMER
224.nf
225THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
226ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
227IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
229FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
230DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
231OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
232HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
233LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
235SUCH DAMAGE.
236.fi
886521eb 237.SH BUGS
886521eb 238There is a controversy raging over whether the DES will still be secure
c4e28bd8
KB
239in a few years.
240The advent of special-purpose hardware could reduce the cost of any of the
241methods of attack named above so that they are no longer computationally
242infeasible.
886521eb 243.PP
c4e28bd8
KB
244As the key or key schedule is stored in memory, the encryption can be
245compromised if memory is readable.
8ca535de
KB
246Additionally, programs which display programs' arguments may compromise the
247key and initialization vector, if they are specified on the command line.
c4e28bd8
KB
248To avoid this
249.I bdes
250overwrites its arguments, however, the obvious race cannot currently be
251avoided.
8ca535de
KB
252.PP
253Certain specific keys should be avoided because they introduce potential
254weaknesses; these keys, called the
255.I weak
256and
257.I semiweak
258keys, are (in hex notation, where p is either 0 or 1, and P is either
259e or f):
260.sp
261.nf
262.in +10n
263.ta \w'0x0p0p0p0p0p0p0p0p\0\0\0'u+5n
2640x0p0p0p0p0p0p0p0p 0x0p1P0p1P0p0P0p0P
2650x0pep0pep0pfp0pfp 0x0pfP0pfP0pfP0pfP
2660x1P0p1P0p0P0p0P0p 0x1P1P1P1P0P0P0P0P
2670x1Pep1Pep0Pfp0Pfp 0x1PfP1PfP0PfP0PfP
2680xep0pep0pfp0pfp0p 0xep1Pep1pfp0Pfp0P
2690xepepepepepepepep 0xepfPepfPfpfPfpfP
2700xfP0pfP0pfP0pfP0p 0xfP1PfP1PfP0PfP0P
2710xfPepfPepfPepfPep 0xfPfPfPfPfPfPfPfP
272.fi
273.in -10n
274.sp
275This is inherent in the DES algorithm (see Moore and Simmons,
276\*(LqCycle structure of the DES with weak and semi-weak keys,\*(Rq
277.I "Advances in Cryptology \- Crypto '86 Proceedings" ,
278Springer-Verlag New York, \(co1987, pp. 9-32.)