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