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