General utilities cleanup. Add signature support to catcrypt. Throw in
[u/mdw/catacomb] / catcrypt.1
CommitLineData
c65df279 1.\" -*-nroff-*-
2.de VS
3.sp 1
4.RS
5.nf
6.ft B
7..
8.de VE
9.ft R
10.fi
11.RE
12.sp 1
13..
14.ie t \{\
15. if \n(.g \{\
16. fam P
17. \}
18.\}
19.de hP
20.IP
21.ft B
22\h'-\w'\\$1\ 'u'\\$1\ \c
23.ft P
24..
25.ie t .ds o \(bu
26.el .ds o o
27.TH catcrypt 1 "30 September 2004" "Straylight/Edgeware" "Catacomb cryptographic library"
28.SH NAME
29catcrypt \- encrypt and decrypt messages
30.SH SYNOPSIS
31.B catcrypt
32.RB [ \-k
33.IR keyring ]
34.I command
35.PP
36where
37.I command
38is one of:
39.PP
40.B help
41.RI [ command ...]
42.br
43.B show
44.RI [ item ...]
45.br
46.B encrypt
47.RB [ \-a ]
48.RB [ \-k
49.IR tag ]
50.RB [ \-f
51.IR format ]
52.RB [ \-o
53.IR output ]
54.RI [ file ]
55.br
56.B decrypt
57.RB [ \-aqv ]
58.RB [ \-f
59.IR format ]
60.RB [ \-o
61.IR output ]
62.RI [ file ]
63.br
64.B encode
65.RB [ \-f
66.IR format ]
67.RB [ \-b
68.IR boundary ]
69.RB [ \-o
70.IR output ]
71.RI [ file ]
72.br
73.B encode
74.RB [ \-f
75.IR format ]
76.RB [ \-b
77.IR boundary ]
78.RB [ \-o
79.IR output ]
80.RI [ file ]
81.SH "DESCRIPTION"
82The
83.B catcrypt
84command encrypts and decrypts messages. It also works as a simple PEM
85encoder and decoder. It provides a number of subcommands, by which the
86various operations may be carried out.
87.SS "Global options"
88Before the command name,
89.I "global options"
90may be given. The following global options are supported:
91.TP
92.BR "\-h, \-\-help " [ \fIcommand ...]
93Writes a brief summary of
94.BR catcrypt 's
95various options to standard output, and returns a successful exit
96status. With command names, gives help on those commands.
97.TP
98.B "\-v, \-\-version"
99Writes the program's version number to standard output, and returns a
100successful exit status.
101.TP
102.B "\-u, \-\-usage"
103Writes a very terse command line summary to standard output, and returns
104a successful exit status.
105.TP
106.BI "\-k, \-\-keyring " file
107Names the keyring file which
108.B key
109is to process. The default keyring, used if this option doesn't specify
110one, is the file named
111.B keyring
112in the current directory. See
113.BR key (1)
114and
115.BR keyring (5)
116for more details about keyring files.
117.SH "KEY SETUP"
118Algorithms to be used with a particular key are described by attributes
119on the key, or its type. The
120.B catcrypt
121command deals with both signing and key-encapsulation keys.
122.SS "Key-encapsulation keys"
123(Key encapsulation is a means of transmitting a short, known, random
124secret to a recipient. It differs from encryption in technical ways
125which are largely uninteresting at this point.)
126.PP
127A
128.I kemalgspec
129has the syntax
130.IR kem \c
131.RB [ / \c
132.IR cipher \c
133.RB [ / \c
134.IR hash ]].
135If a
136.B kem
137attribute is present on the key, then it must have this form; otherwise,
138the key's type must have the form
139.BR cckem- \c
140.IR kemalgspec .
141Algorithm selections are taken from appropriately-named attributes, or,
142failing that, from the
143.IR kemalgspec .
144.PP
145The key-encapsulation mechanism is chosen according to the setting of
146.I kem
147as follows. Run
148.B catcrypt show kem
149for a list of supported KEMs.
150.TP
151.B rsa
152This is Shoup's RSA-KEM (formerly Simple RSA); see
153.I
154A proposal for an ISO standard for public key encryption (version 2.0)
155available at
156.BR http://eprint.iacr.org/2000/060/ .
157Use the
158.B rsa
159algorithm of the
160.B key add
161command (see
162.BR key (1))
163to generate the key.
164.TP
165.B dh
166This is standard Diffie-Hellman key exchange, hashing the resulting
167shared secret to form the key, as used in, e.g., DLIES (P1363a).
168Use the
169.B dh
170algorithm of the
171.B key add
172command, preferably with the
173.B \-LS
174options, to generate the key.
175.TP
176.B ec
177This is the elliptic-curve analogue of
178.BR dh . Use the
179.B ec
180algorithm of the
181.BR key (1))
182command to generate the key.
183.PP
184As well as the KEM itself, a number of supporting algorithms are used.
185These are taken from appropriately named attributes on the key or,
186failing that, derived from other attributes as described below.
187.TP
188.B cipher
189This is the symmetric encryption algorithm used for bulk data
190encryption. If there is no
191.B cipher
192attribute then the
193.I cipher
194in the
195.I kemalgspec
196is used; if that it absent, then the default of
197.B blowfish-cbc
198is used. Run
199.B catcrypt show cipher
200for a list of supported symmetric encryption algorithms.
201.TP
202.B hash
203This is the hash function used to distil entropy from the shared secret
204constructed by the raw KEM. If there is no
205.B hash
206attribute then the
207.I hash
208in the
209.I kemalgspec is used; if that is absent then the default of
210.B rmd160
211is used. Run
212.B catcrypt show hash
213for a list of supported symmetric encryption algorithms.
214.TP
215.B mac
216This is the message authentication algorithm used during bulk data
217encryption to ensure integrity of the encrypted message and defend
218against chosen-ciphertext attacks. If there is no
219.B mac
220attribute then
221.IB hash -hmac
222is chosen as a default. Run
223.B catcrypt show mac
224for a list of supported message authentication algorithms.
225.TP
226.B kdf
227This is the key derivation function used to stretch the hashed shared
228secret to a sufficient length to select symmetric encryption and
229authentication keys, initialization vectors and other necessary
230pseudorandom quantities. If there is no
231.B kdf
232attribute then
233.IB hash -mgf
234is chosen as a default. Run
235.B catcrypt show kdf
236for a list of supported key derivation functions.
237.B Caution!
238Not all supported functions have the required security features: don't
239override the default choice unless you know what you're doing.
240.SS "Signing keys"
241A
242.I sigalgspec
243has the form
244.IR sig \c
245.RB [ / \c
246.IR hash ].
247If a
248.B sig
249attribute is present on the key, then it must have this form; otherwise,
250the key's type must have the form
251.BI ccsig- \c
252.IR sigalgspec .
253Algorithm selections are taken from appropriately-named attributes, or,
254failing that, from the
255.IR sigalgspec .
256.PP
257The signature algorithm is chosen according to the setting of
258.I sig
259as follows. Run
260.B catcrypt show sig
261for a list of supported signature algorithms.
262.TP
263.B rsapkcs1
264This is almost the same as the RSASSA-PKCS1-v1_5 algorithm described in
265RFC3447; the difference is that the hash is left bare rather than being
266wrapped in a DER-encoded
267.B DigestInfo
268structure. This doesn't affect security since the key can only be used
269with the one hash function anyway, and dropping the DER wrapping permits
270rapid adoption of new hash functions. Regardless, use of this algorithm
271is not recommended, since the padding method has been shown vulnerable
272to attack. Use the
273.B rsa
274algorithm of the
275.B key add
276command (see
277.BR key (1))
278to generate the key.
279.TP
280.B rsapss
281This is the RSASSA-PSS algorithm described in RFC3447. It is the
282preferred RSA-based signature scheme. Use the
283.B rsa
284algorithm of the
285.B key add
286command (see
287.BR key (1))
288to generate the key.
289.TP
290.B dsa
291This is the DSA algorithm described in FIPS180-1 and FIPS180-2. Use the
292.B dsa
293algorithm of the
294.B key add
295command (see
296.BR key (1))
297to generate the key.
298.TP
299.B ecdsa
300This is the ECDSA algorithm described in ANSI X9.62 and FIPS180-2. Use
301the
302.B ec
303algorithm of the
304.B key add
305command (see
306.BR key (1))
307to generate the key.
308.TP
309.B kcdsa
310This is the revised KCDSA (Korean Certificate-based Digital Signature
311Algorithm) described in
312.I The Revised Version of KCDSA
313.RB ( http://dasan.sejong.ac.kr/~chlim/pub/kcdsa1.ps ).
314Use the
315.B dh
316algorithm of the
317.B key add
318command with the
319.B \-LS
320options (see
321.BR key (1))
322to generate the key.
323.TP
324.B eckcdsa
325This is an unofficial elliptic-curve analogue of the KCDSA algorithm.
326Use the
327.B ec
328algorithm of the
329.B key add
330command (see
331.BR key (1))
332to generate the key.
333.PP
334As well as the signature algorithm itself, a hash function is used.
335This is taken from the
336.B hash
337attribute on the key, or, failing that, from the
338.I hash
339specified in the
340.IR sigalgspec ,
341or, if that is absent, determined by the signature algorithm as follows.
342.hP \*o
343For
344.BR rsapkcs1 ,
345.BR rsapss ,
346.BR dsa ,
347and
348.BR ecdsa ,
349the default hash function is
350.BR sha .
351.hP \*o
352For
353.BR kcdsa
354and
355.BR eckcdsa ,
356the default hash function is
357.BR has160 .
358.PP
359Run
360.B catcrypt show hash
361for a list of supported hash functions.
362.SH "ENCODINGS"
363Two encodings for the ciphertext are supported.
364.TP
365.B binary
366The raw format, which has the benefit of being smaller, but needs to be
367attached to mail messages and generally handled with care.
368.TP
369.B pem
370PEM-encapsulated Base-64 encoded text. This format can be included
371directly in email and picked out again automatically; but there is a
3724-to-3 data expansion as a result.
373.SH "COMMAND REFERENCE"
374.SS help
375The
376.B help
377command behaves exactly as the
378.B \-\-help
379option. With no arguments, it shows an overview of
380.BR catcrypt 's
381options; with arguments, it describes the named subcommands.
382.SS show
383The
384.B show
385command prints various lists of tokens understood by
386.BR catcrypt .
387With no arguments, it prints all of the lists; with arguments, it prints
388just the named lists, in order. The recognized lists can be enumerated
389using the
390.VS
391catcrypt show list
392.VE
393command. The lists are as follows.
394.TP
395.B list
396The lists which can be enumerated by the
397.B show
398command.
399.TP
400.B kem
401The key-encapsulation algorithms which can be used in a
402key-encapsulation key's
403.B kem
404attribute.
405.TP
406.B cipher
407The symmetric encryption algorithms which can be used in a
408key-encapsulation key's
409.B cipher
410attribute.
411.TP
412.B mac
413The message authentication algorithms which can be used in a
414key-encapsulation key's
415.B mac
416attribute.
417.TP
418.B sig
419The signature algorithms which can be used in a signing key's
420.B sig
421attribute.
422.TP
423.B hash
424The hash functions which can be used in a key's
425.B hash
426attribute.
427.TP
428.B enc
429The encodings which can be applied to encrypted messages; see
430.B ENCODINGS
431above.
432.SS encrypt
433The
434.B encrypt
435command encrypts a file and writes out the appropriately-encoded
436ciphertext. By default, it reads from standard input and writes to
437standard output. If a filename argument is given, this file is read
438instead (as binary data).
439.PP
440The following options are recognized.
441.TP
442.B "\-a, \-\-armour"
443Produce ASCII-armoured output. This is equivalent to specifying
444.BR "\-f pem" .
445The variant spelling
446.B "\-\-armor"
447is also accepted.
448.TP
449.BI "\-f, \-\-format " format
450Produce output encoded according to
451.IR format .
452.TP
453.BI "\-k, \-\-key " tag
454Use the key-encapsulation key named
455.I tag
456in the current keyring; the default key is
457.BR ccrypt .
458.TP
459.BI "\-s, \-\-sign-key " tag
460Use the signature key named
461.I tag
462in the current keyring; the default is not to sign the ciphertext.
463.TP
464.BI "\-o, \-\-ouptut " file
465Write output to
466.I file
467rather than to standard output.
468.SS decrypt
469The
470.B decrypt
471command decrypts a ciphertext and writes out the plaintext. By default,
472it reads from standard input and writes to standard output. If a
473filename argument is given, this file is read instead.
474.PP
475The following options are recognized.
476.TP
477.B "\-a, \-\-armour"
478Read ASCII-armoured output. This is equivalent to specifying
479.BR "\-f pem" .
480The variant spelling
481.B "\-\-armor"
482is also accepted.
483.TP
484.BI "\-f, \-\-format " format
485Read input encoded according to
486.IR format .
487.TP
488.B "\-v, \-\-verbose"
489Produce more verbose messages. See below for the messages produced
490during decryption. The default verbosity level is 1. (Currently this
491is the most verbose setting. This might not be the case always.)
492.TP
493.B "\-q, \-\-quiet"
494Produce fewer messages.
495.TP
496.BI "\-o, \-\-output " file
497Write output to
498.I file
499instead of to standard output. The file is written in binary mode.
500Fixing line-end conventions is your problem; there are lots of good
501tools for dealing with it.
502.PP
503Output is written to standard output in a machine-readable format.
504Major problems cause the program to write a diagnostic to standard error
505and exit nonzero as usual. The quantity of output varies depending on
506the verbosity level and whether the plaintext is also being written to
507standard output. Output lines begin with a keyword.:
508.TP
509.BI "FAIL " reason
510An error prevented decryption. The program will exit nonzero.
511.TP
512.BI "WARN " reason
513.B catcrypt
514encountered a situation which may or may not invalidate the decryption.
515.TP
516.BI "OK " message
517Decryption was successful. This is only produced if main output is
518being sent somewhere other than standard output.
519.TP
520.B "DATA"
521The plaintext follows, starting just after the next newline character or
522sequence. This is only produced if main output is being sent to
523standard output. If anything goes wrong, a
524.B FAIL
525message is printed, preceded and followed by a newline, and the program
526exits nonzero.
527.TP
528.BI "INFO " note
529Any other information.
530.PP
531The information written at the various verbosity levels is as follows.
532.hP 0.
533No output. Watch the exit status.
534.hP 1.
535All messages.
536.PP
537.B Warning!
538All output written has been checked for authenticity. However, since
539the input is chunked, a chunk will be checked and written before the
540authenticity of following chunks is established. Don't rely on the
541output being complete until
542.B catcrypt decrypt
543prints
544.B OK
545and/or exits successfully.
546.SS "encode"
547The
548.B encode
549command encodes an input file according to one of the encodings
550described above in
551.BR ENCODINGS .
552The input is read from the
553.I file
554given on the command line, or from standard input if none is specified.
555Options provided are:
556.TP
557.BI "\-f, \-\-format " format
558Produce output in
559.IR format .
560Run
561.B catcrypt show enc
562for a list of encoding formats.
563.TP
564.BI "\-b, \-\-boundary " label
565Set the PEM boundary string to
566.IR label ;
567i.e., assuming we're encoding in PEM format, the output will have
568.BI "\-\-\-\-\-BEGIN " label "\-\-\-\-\-"
569at the top and
570.BI "\-\-\-\-\-END " label "\-\-\-\-\-"
571at the bottom. The default
572.I label
573is
574.BR MESSAGE .
575.TP
576.BI "\-o, \-\-output " file
577Write output to
578.I file
579instead of to standard output.
580.SS "decode"
581The
582.B decode
583command decodes an input file encoded according to one of the encodings
584described above in
585.BR ENCODINGS .
586The input is read from the
587.I file
588given on the command line, or from standard input if none is specified.
589Options provided are:
590.TP
591.BI "\-f, \-\-format " format
592Decode input in
593.IR format .
594Run
595.B catcrypt show enc
596for a list of encoding formats.
597.TP
598.BI "\-b, \-\-boundary " label
599Set the PEM boundary string to
600.IR label ;
601i.e., assuming we're encoding in PEM format, start processing input
602between
603.BI "\-\-\-\-\-BEGIN " label "\-\-\-\-\-"
604and
605.BI "\-\-\-\-\-END " label "\-\-\-\-\-"
606lines. Without this option,
607.B catcrypt
608will start reading at the first plausible boundary string, and continue
609processing until it reaches the matching end boundary.
610.TP
611.BI "\-o, \-\-output " file
612Write output to
613.I file
614instead of to standard output.
615.SH "SECURITY PROPERTIES"
616Assuming the security of the underlying primitive algorithms, the
617following security properties of the ciphertext hold.
618.hP \*o
619An adversary given the public key-encapsulation key and capable of
620requesting encryption of arbitrary plaintexts of his own devising is
621unable to decide whether he is given ciphertexts corresponding to his
622chosen plaintexts or random plaintexts of the same length. This holds
623even if the adversary is permitted to request decryption of any
624ciphertext other than one produced as a result of an encryption request.
625This property is called
626.BR IND-CCA2 .
627.hP \*o
628An adversary given the public key-encapsulation and verification keys,
629and capable of requesting encryption of arbitrary plaintext of his own
630devising is unable to produce a new ciphertext which will be accepted as
631genuine. This property is called
632.BR INT-CTXT .
633.hP \*o
634An adversary given the public key-encapsulation and verification keys,
635and capable of requesting encryption of arbitrary plaintext of his own
636devising is unable to decide whether the ciphertexts he is given are
637correctly signed. This property doesn't seem to have a name.
638.PP
639Not all is rosy. If you leak intermediate values during decryption then
640an adversary can construct a new correctly-signed message. Don't do
641that, then \(en leaking intermediate values often voids security
642warranties. But it does avoid the usual problem with separate signing
643and encryption that a careful leak by the recipient can produce evidence
644that you signed some incriminating message.
645.SH "CRYPTOGRAPHIC THEORY"
646Encryption of a message proceeds as follows.
647.hP 0.
648Emit a header packet containing the key-ids for the key-encapsulation
649key, and signature key if any.
650.hP 1.
651Use the KEM to produce a public value and a shared secret the recipient
652will be able to extract from the public value using his private key.
653Emit a packet containing the public value.
654.hP 2.
655Hash the shared secret. Use the KDF to produce a pseudorandom keystream
656of indefinite length.
657.hP 3.
658Use the first bits of the keystream to key a symmetric encryption
659scheme; use the next bits to key a message authentication code.
660.hP 4.
661If we're signing the message then extract 1024 bytes from the keystream,
662sign them, and emit a packet containing the signature. The signature
663packet doesn't contain the signed message, just the signature.
664.hP 5.
665Split the message into blocks. For each block, pick a random IV from
666the keystream, encrypt the block and emit a packet containing the
667IV, ciphertext and a MAC tag.
668.PP
669That's it. Nothing terribly controversial, really.
670.SH "SEE ALSO"
671.BR key (1),
672.BR dsig (1),
673.BR hashsum (1),
674.BR keyring (5).
675.SH AUTHOR
676Mark Wooding, <mdw@nsict.org>