progs/perftest.c: Add measurement support for AEAD schemes.
[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 .TP
208 .B x25519
209 This is Bernstein's Curve25519, a fast Diffie-Hellman using a specific
210 elliptic curve.
211 Use the
212 .B x25519
213 algorithm of the
214 .B key add
215 command
216 (see
217 .BR key (1))
218 to generate the key.
219 .TP
220 .B x448
221 This is Hamburg's Curve25519, a strong Diffie-Hellman using a specific
222 elliptic curve.
223 Use the
224 .B x448
225 algorithm of the
226 .B key add
227 command
228 (see
229 .BR key (1))
230 to generate the key.
231 .PP
232 The bulk crypto transform is chosen based on the
233 .B bulk
234 attribute on the key, or, failing that,
235 from the
236 .I bulk
237 stated in the
238 .IR kemalgspec .
239 Run
240 .B catcrypt show bulk
241 for a list of supported bulk crypto transforms.
242 .TP
243 .B gencomp
244 A generic composition of
245 a cipher secure against chosen-plaintext attack,
246 and a message authentication code.
247 Makes use of
248 .B cipher
249 and
250 .B mac
251 attributes. Run
252 .B catcrypt show cipher
253 for a list of supported symmetric encryption algorithms; the default
254 .I cipher
255 is
256 .BR blowfish-cbc .
257 This is the default transform.
258 .TP
259 .B aead
260 Use an `authenticated encryption with additional data' (AEAD) scheme.
261 The specific scheme is named by the
262 .B cipher
263 attribute. Run
264 .B catcrypt show aead
265 for a list of supported AEAD schemes; the default is
266 .BR chacha20-poly1305 .
267 .TP
268 .B naclbox
269 Use Salsa20 or ChaCha and Poly1305 to secure the bulk data.
270 This is nearly the same as the NaCl
271 .B crypto_secretbox
272 construction,
273 except that
274 .B catcrypt
275 uses Salsa20 or ChaCha rather than XSalsa20,
276 because it doesn't need the latter's extended nonce.
277 The
278 .B cipher
279 attribute may be set to one of
280 .BR salsa20 ,
281 .BR salsa20/12 ,
282 .BR salsa20/8 ,
283 .BR chacha20 ,
284 .BR chacha12 ,
285 or
286 .BR chacha8 ;
287 the default is
288 .BR salsa20 .
289 .PP
290 As well as the KEM itself, a number of supporting algorithms are used.
291 These are taken from appropriately named attributes on the key or,
292 failing that, derived from other attributes as described below.
293 .TP
294 .B cipher
295 This is the symmetric encryption algorithm
296 used by the bulk data transform.
297 If there is no
298 .B cipher
299 attribute then the
300 .I bulk
301 in the
302 .I kemalgspec
303 is used; if that it absent, then the default depends on the bulk
304 transform.
305 .TP
306 .B hash
307 This is the hash function used to distil entropy from the shared secret
308 constructed by the raw KEM. If there is no
309 .B hash
310 attribute then the
311 .I hash
312 in the
313 .I kemalgspec
314 is used; if that is absent then the default of
315 .B rmd160
316 is used. Run
317 .B catcrypt show hash
318 for a list of supported symmetric encryption algorithms.
319 .TP
320 .B mac
321 This is the message authentication algorithm
322 used by the
323 .B gencomp
324 bulk data transform
325 to ensure integrity of the encrypted message and
326 defend against chosen-ciphertext attacks.
327 If there is no
328 .B mac
329 attribute then
330 .IB hash -hmac
331 is chosen as a default. Run
332 .B catcrypt show mac
333 for a list of supported message authentication algorithms.
334 .TP
335 .B kdf
336 This is the key derivation function used to stretch the hashed shared
337 secret to a sufficient length to select symmetric encryption and
338 authentication keys, initialization vectors and other necessary
339 pseudorandom quantities. If there is no
340 .B kdf
341 attribute then
342 .IB hash -mgf
343 is chosen as a default. Run
344 .B catcrypt show kdf
345 for a list of supported key derivation functions.
346 .B Caution!
347 Not all supported functions have the required security features: don't
348 override the default choice unless you know what you're doing.
349 .SS "Signing keys"
350 A
351 .I sigalgspec
352 has the form
353 .IR sig \c
354 .RB [ / \c
355 .IR hash ].
356 If a
357 .B sig
358 attribute is present on the key, then it must have this form; otherwise,
359 the key's type must have the form
360 .BI ccsig- \c
361 .IR sigalgspec .
362 Algorithm selections are taken from appropriately-named attributes, or,
363 failing that, from the
364 .IR sigalgspec .
365 .PP
366 The signature algorithm is chosen according to the setting of
367 .I sig
368 as follows. Run
369 .B catcrypt show sig
370 for a list of supported signature algorithms.
371 .TP
372 .B rsapkcs1
373 This is almost the same as the RSASSA-PKCS1-v1_5 algorithm described in
374 RFC3447; the difference is that the hash is left bare rather than being
375 wrapped in a DER-encoded
376 .B DigestInfo
377 structure. This doesn't affect security since the key can only be used
378 with the one hash function anyway, and dropping the DER wrapping permits
379 rapid adoption of new hash functions. Regardless, use of this algorithm
380 is not recommended, since the padding method has been shown vulnerable
381 to attack. Use the
382 .B rsa
383 algorithm of the
384 .B key add
385 command (see
386 .BR key (1))
387 to generate the key.
388 .TP
389 .B rsapss
390 This is the RSASSA-PSS algorithm described in RFC3447. It is the
391 preferred RSA-based signature scheme. Use the
392 .B rsa
393 algorithm of the
394 .B key add
395 command (see
396 .BR key (1))
397 to generate the key.
398 .TP
399 .B dsa
400 This is the DSA algorithm described in FIPS180-1 and FIPS180-2. Use the
401 .B dsa
402 algorithm of the
403 .B key add
404 command (see
405 .BR key (1))
406 to generate the key.
407 .TP
408 .B ecdsa
409 This is the ECDSA algorithm described in ANSI X9.62 and FIPS180-2. Use
410 the
411 .B ec
412 algorithm of the
413 .B key add
414 command (see
415 .BR key (1))
416 to generate the key.
417 .TP
418 .B kcdsa
419 This is the revised KCDSA (Korean Certificate-based Digital Signature
420 Algorithm) described in
421 .I The Revised Version of KCDSA
422 .RB ( http://dasan.sejong.ac.kr/~chlim/pub/kcdsa1.ps ).
423 Use the
424 .B dh
425 algorithm of the
426 .B key add
427 command with the
428 .B \-LS
429 options (see
430 .BR key (1))
431 to generate the key.
432 .TP
433 .B eckcdsa
434 This is an unofficial elliptic-curve analogue of the KCDSA algorithm.
435 Use the
436 .B ec
437 algorithm of the
438 .B key add
439 command (see
440 .BR key (1))
441 to generate the key.
442 .TP
443 .B ed25519
444 This is Bernstein, Duif, Lange, Schwabe, and Yang's Ed25519 algorithm.
445 More specifically, this is HashEd25519
446 using the selected
447 .B hash
448 algorithm \(en by default
449 .BR sha512 .
450 Use the
451 .B ed25519
452 algorithm of the
453 .B key add
454 command
455 (see
456 .BR key (1))
457 to generate the key.
458 .TP
459 .B ed448
460 This is Bernstein, Duif, Lange, Schwabe, and Yang's EdDSA algorithm,
461 using Hamburg's Ed448-Goldilocks elliptic curve,
462 as specified in RFC8032.
463 More specifically, this is HashEd448
464 using the selected
465 .B hash
466 algorithm \(en by default
467 .BR sha3-512 .
468 Use the
469 .B ed448
470 algorithm of the
471 .B key add
472 command
473 (see
474 .BR key (1))
475 to generate the key.
476 .TP
477 .B mac
478 This uses a symmetric message-authentication algorithm rather than a
479 digital signature. The precise message-authentication scheme used is
480 determined by the
481 .B mac
482 attribute on the key, which defaults to
483 .IB hash -hmac
484 if unspecified. Use the
485 .B binary
486 algorithm of the
487 .B key add
488 command (see
489 .BR key (1))
490 to generate the key.
491 .PP
492 As well as the signature algorithm itself, a hash function is used.
493 This is taken from the
494 .B hash
495 attribute on the key, or, failing that, from the
496 .I hash
497 specified in the
498 .IR sigalgspec ,
499 or, if that is absent, determined by the signature algorithm as follows.
500 .hP \*o
501 For
502 .BR rsapkcs1 ,
503 .BR rsapss ,
504 .BR dsa ,
505 and
506 .BR ecdsa ,
507 the default hash function is
508 .BR sha .
509 .hP \*o
510 For
511 .BR kcdsa
512 and
513 .BR eckcdsa ,
514 the default hash function is
515 .BR has160 .
516 For
517 .BR ed25519 ,
518 the default hash function is
519 .BR sha512 .
520 For
521 .BR ed448 ,
522 the default hash function is
523 .BR shake256 .
524 .PP
525 Run
526 .B catcrypt show hash
527 for a list of supported hash functions.
528 .SH "ENCODINGS"
529 Two encodings for the ciphertext are supported.
530 .TP
531 .B binary
532 The raw format, which has the benefit of being smaller, but needs to be
533 attached to mail messages and generally handled with care.
534 .TP
535 .B pem
536 PEM-encapsulated Base-64 encoded text. This format can be included
537 directly in email and picked out again automatically; but there is a
538 4-to-3 data expansion as a result.
539 .SH "COMMAND REFERENCE"
540 .SS help
541 The
542 .B help
543 command behaves exactly as the
544 .B \-\-help
545 option. With no arguments, it shows an overview of
546 .BR catcrypt 's
547 options; with arguments, it describes the named subcommands.
548 .SS show
549 The
550 .B show
551 command prints various lists of tokens understood by
552 .BR catcrypt .
553 With no arguments, it prints all of the lists; with arguments, it prints
554 just the named lists, in order. The recognized lists can be enumerated
555 using the
556 .VS
557 catcrypt show list
558 .VE
559 command. The lists are as follows.
560 .TP
561 .B list
562 The lists which can be enumerated by the
563 .B show
564 command.
565 .TP
566 .B kem
567 The key-encapsulation algorithms which can be used in a
568 key-encapsulation key's
569 .B kem
570 attribute.
571 .TP
572 .B cipher
573 The symmetric encryption algorithms which can be named in a
574 key-encapsulation key's
575 .B cipher
576 attribute when using the
577 .B gencomp
578 bulk transform.
579 .TP
580 .B mac
581 The message authentication algorithms which can be named in a
582 key-encapsulation key's
583 .B mac
584 attribute.
585 .TP
586 .B sig
587 The signature algorithms which can be named in a signing key's
588 .B sig
589 attribute.
590 .TP
591 .B hash
592 The hash functions which can be named in a key's
593 .B hash
594 attribute.
595 .TP
596 .B enc
597 The encodings which can be applied to encrypted messages; see
598 .B ENCODINGS
599 above.
600 .SS encrypt
601 The
602 .B encrypt
603 command encrypts a file and writes out the appropriately-encoded
604 ciphertext. By default, it reads from standard input and writes to
605 standard output. If a filename argument is given, this file is read
606 instead (as binary data).
607 .PP
608 The following options are recognized.
609 .TP
610 .B "\-a, \-\-armour"
611 Produce ASCII-armoured output. This is equivalent to specifying
612 .BR "\-f pem" .
613 The variant spelling
614 .B "\-\-armor"
615 is also accepted.
616 .TP
617 .BI "\-f, \-\-format " format
618 Produce output encoded according to
619 .IR format .
620 .TP
621 .BI "\-k, \-\-key " tag
622 Use the key-encapsulation key named
623 .I tag
624 in the current keyring; the default key is
625 .BR ccrypt .
626 .TP
627 .BI "\-p, \-\-progress"
628 Write a progress meter to standard error while processing large files.
629 .TP
630 .BI "\-s, \-\-sign-key " tag
631 Use the signature key named
632 .I tag
633 in the current keyring; the default is not to sign the ciphertext.
634 .TP
635 .BI "\-o, \-\-ouptut " file
636 Write output to
637 .I file
638 rather than to standard output.
639 .TP
640 .B "\-C, \-\-nocheck"
641 Don't check the public key for validity. This makes encryption go much
642 faster, but at the risk of using a duff key.
643 .SS decrypt
644 The
645 .B decrypt
646 command decrypts a ciphertext and writes out the plaintext. By default,
647 it reads from standard input and writes to standard output. If a
648 filename argument is given, this file is read instead.
649 .PP
650 The following options are recognized.
651 .TP
652 .B "\-a, \-\-armour"
653 Read ASCII-armoured input. This is equivalent to specifying
654 .BR "\-f pem" .
655 The variant spelling
656 .B "\-\-armor"
657 is also accepted.
658 .TP
659 .B "\-b, \-\-buffer"
660 Buffer plaintext data until we're sure we've got it all. This is forced
661 on if output is to stdout, but is always available as an option.
662 .TP
663 .BI "\-f, \-\-format " format
664 Read input encoded according to
665 .IR format .
666 .TP
667 .BI "\-p, \-\-progress"
668 Write a progress meter to standard error while processing large files.
669 .TP
670 .B "\-v, \-\-verbose"
671 Produce more verbose messages. See below for the messages produced
672 during decryption. The default verbosity level is 1. (Currently this
673 is the most verbose setting. This might not be the case always.)
674 .TP
675 .B "\-q, \-\-quiet"
676 Produce fewer messages.
677 .TP
678 .BI "\-o, \-\-output " file
679 Write output to
680 .I file
681 instead of to standard output. The file is written in binary mode.
682 Fixing line-end conventions is your problem; there are lots of good
683 tools for dealing with it.
684 .TP
685 .B "\-C, \-\-nocheck"
686 Don't check the private key for validity. This makes decryption go much
687 faster, but at the risk of using a duff key, and possibly leaking
688 information about the private key.
689 .PP
690 Output is written to standard output in a machine-readable format.
691 Major problems cause the program to write a diagnostic to standard error
692 and exit nonzero as usual. The quantity of output varies depending on
693 the verbosity level and whether the plaintext is also being written to
694 standard output. Output lines begin with a keyword:
695 .TP
696 .BI "FAIL " reason
697 An error prevented decryption. The program will exit nonzero.
698 .TP
699 .BI "WARN " reason
700 .B catcrypt
701 encountered a situation which may or may not invalidate the decryption.
702 .TP
703 .BI "OK " message
704 Decryption was successful. This is only produced if main output is
705 being sent somewhere other than standard output.
706 .TP
707 .B "DATA"
708 The plaintext follows, starting just after the next newline character or
709 sequence. This is only produced if main output is also being sent to
710 standard output.
711 .TP
712 .BI "INFO " note
713 Any other information.
714 .PP
715 The information written at the various verbosity levels is as follows.
716 .hP 0.
717 No output. Watch the exit status.
718 .hP 1.
719 All messages.
720 .PP
721 .B Warning!
722 All output written has been checked for authenticity. However, output
723 can fail midway through for many reasons, and the resulting message may
724 therefore be truncated. Don't rely on the output being complete until
725 .B OK
726 is printed or
727 .B catcrypt decrypt
728 exits successfully.
729 .SS "encode"
730 The
731 .B encode
732 command encodes an input file according to one of the encodings
733 described above in
734 .BR ENCODINGS .
735 The input is read from the
736 .I file
737 given on the command line, or from standard input if none is specified.
738 Options provided are:
739 .TP
740 .BI "\-p, \-\-progress"
741 Write a progress meter to standard error while processing large files.
742 .TP
743 .BI "\-f, \-\-format " format
744 Produce output in
745 .IR format .
746 Run
747 .B catcrypt show enc
748 for a list of encoding formats.
749 .TP
750 .BI "\-b, \-\-boundary " label
751 Set the PEM boundary string to
752 .IR label ;
753 i.e., assuming we're encoding in PEM format, the output will have
754 .BI "\-\-\-\-\-BEGIN " label "\-\-\-\-\-"
755 at the top and
756 .BI "\-\-\-\-\-END " label "\-\-\-\-\-"
757 at the bottom. The default
758 .I label
759 is
760 .BR MESSAGE .
761 .TP
762 .BI "\-o, \-\-output " file
763 Write output to
764 .I file
765 instead of to standard output.
766 .SS "decode"
767 The
768 .B decode
769 command decodes an input file encoded according to one of the encodings
770 described above in
771 .BR ENCODINGS .
772 The input is read from the
773 .I file
774 given on the command line, or from standard input if none is specified.
775 Options provided are:
776 .TP
777 .BI "\-f, \-\-format " format
778 Decode input in
779 .IR format .
780 Run
781 .B catcrypt show enc
782 for a list of encoding formats.
783 .TP
784 .BI "\-b, \-\-boundary " label
785 Set the PEM boundary string to
786 .IR label ;
787 i.e., assuming we're encoding in PEM format, start processing input
788 between
789 .BI "\-\-\-\-\-BEGIN " label "\-\-\-\-\-"
790 and
791 .BI "\-\-\-\-\-END " label "\-\-\-\-\-"
792 lines. Without this option,
793 .B catcrypt
794 will start reading at the first plausible boundary string, and continue
795 processing until it reaches the matching end boundary.
796 .TP
797 .BI "\-p, \-\-progress"
798 Write a progress meter to standard error while processing large files.
799 .TP
800 .BI "\-o, \-\-output " file
801 Write output to
802 .I file
803 instead of to standard output.
804 .SH "SECURITY PROPERTIES"
805 Assuming the security of the underlying primitive algorithms, the
806 following security properties of the ciphertext hold.
807 .hP \*o
808 An adversary given the public key-encapsulation key and capable of
809 requesting encryption of arbitrary plaintexts of his own devising is
810 unable to decide whether he is given ciphertexts corresponding to his
811 chosen plaintexts or random plaintexts of the same length. This holds
812 even if the adversary is permitted to request decryption of any
813 ciphertext other than one produced as a result of an encryption request.
814 This property is called
815 .BR IND-CCA2 .
816 .hP \*o
817 An adversary given the public key-encapsulation and verification keys,
818 and capable of requesting encryption of arbitrary plaintext of his own
819 devising is unable to produce a new ciphertext which will be accepted as
820 genuine. This property is called
821 .BR INT-CTXT .
822 .hP \*o
823 An adversary given the public key-encapsulation and verification keys,
824 and capable of requesting encryption of arbitrary plaintext of his own
825 devising is unable to decide whether the ciphertexts he is given are
826 correctly signed. This property doesn't seem to have a name.
827 .PP
828 Not all is rosy. If you leak intermediate values during decryption then
829 an adversary can construct a new correctly-signed message. Don't do
830 that, then \(en leaking intermediate values often voids security
831 warranties. But it does avoid the usual problem with separate signing
832 and encryption that a careful leak by the recipient can produce evidence
833 that you signed some incriminating message.
834 .PP
835 Note that
836 .BR catcrypt 's
837 signatures do
838 .I not
839 provide `non-repudiation' in any useful way. This is deliberate: the
840 purpose of signing is to convince the recipient of the sender's
841 identity, rather than to allow the recipient to persuade anyone else.
842 Indeed, given an encrypted and signed message, the recipient can
843 straightforwardly construct a new message, apparently from the same
844 sender, and whose signature still verifies, but with arbitrarily chosen
845 content.
846 .SH "CRYPTOGRAPHIC THEORY"
847 Encryption of a message proceeds as follows.
848 .hP 0.
849 Emit a header packet containing the key-ids for the key-encapsulation
850 key, and signature key if any.
851 .hP 1.
852 Use the KEM to produce a public value and a shared secret the recipient
853 will be able to extract from the public value using his private key.
854 Emit a packet containing the public value.
855 .hP 2.
856 Hash the shared secret. Use the KDF to produce a pseudorandom keystream
857 of indefinite length.
858 .hP 3.
859 Use the first bits of the keystream to key a symmetric encryption
860 scheme; use the next bits to key a message authentication code.
861 .hP 4.
862 If we're signing the message then extract 1024 bytes from the keystream,
863 sign the header and public value, and the keystream bytes; emit a packet
864 containing the signature. The signature packet doesn't contain the
865 signed message, just the signature.
866 .hP 5.
867 Split the message into blocks. For each block, pick a random IV from
868 the keystream, encrypt the block and emit a packet containing the
869 IV, ciphertext, and a MAC tag over the ciphertext and a sequence number.
870 .hP 6.
871 The last chunk is the encryption of an empty plaintext block. No
872 previous plaintext block is empty. This lets us determine the
873 difference between a complete file and one that's been maliciously
874 truncated.
875 .PP
876 That's it. Nothing terribly controversial, really.
877 .SH "SEE ALSO"
878 .BR key (1),
879 .BR catsign (1),
880 .BR dsig (1),
881 .BR hashsum (1),
882 .BR keyring (5).
883 .SH AUTHOR
884 Mark Wooding, <mdw@distorted.org.uk>