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