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