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