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