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