cc-hash.c: New file containing hash-related code from hashsum and dsig.
[u/mdw/catacomb] / dsig.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 dsig 1 "30 September 2004" "Straylight/Edgeware" "Catacomb cryptographic library"
28 .SH NAME
29 dsig \- compute and verify signatures on collections of files
30 .SH SYNOPSIS
31 .B dsig
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 sign
47 .RB [ \-0bpqvC ]
48 .RB [ \-c
49 .IR comment ]
50 .RB [ \-k
51 .IR tag ]
52 .RB [ \-e
53 .IR expire ]
54 .br
55 \h'8n'
56 .RB [ \-f
57 .IR file ]
58 .RB [ \-o
59 .IR output ]
60 .br
61 .B verify
62 .RB [ \-pqvC ]
63 .RI [ file ]
64 .SH DESCRIPTION
65 The
66 .B dsig
67 command signs and verifies signatures on a collection of files. It
68 provides a number of subcommands, by which the various operations may be
69 carried out.
70 .SS "Global options"
71 Before the command name,
72 .I "global options"
73 may be given. The following global options are supported:
74 .TP
75 .BR "\-h, \-\-help " [ \fIcommand ...]
76 Writes a brief summary of
77 .BR dsig 's
78 various options to standard output, and returns a successful exit
79 status. With command names, gives help on those commands.
80 .TP
81 .B "\-v, \-\-version"
82 Writes the program's version number to standard output, and returns a
83 successful exit status.
84 .TP
85 .B "\-u, \-\-usage"
86 Writes a very terse command line summary to standard output, and returns
87 a successful exit status.
88 .TP
89 .BI "\-k, \-\-keyring " file
90 Names the keyring file which
91 .B key
92 is to process. The default keyring, used if this option doesn't specify
93 one, is the file named
94 .B keyring
95 in the current directory. See
96 .BR key (1)
97 and
98 .BR keyring (5)
99 for more details about keyring files.
100 .SH "KEY SETUP"
101 A
102 .I sigalgspec
103 has the form
104 .IR sig \c
105 .RB [ / \c
106 .IR hash ].
107 If a
108 .B sig
109 attribute is present on the key, then it must have this form; otherwise,
110 the key's type must have the form
111 .BI dsig- \c
112 .IR sigalgspec .
113 Algorithm selections are taken from appropriately-named attributes, or,
114 failing that, from the
115 .IR sigalgspec .
116 .PP
117 The signature algorithm is chosen according to the setting of
118 .I sig
119 as follows. Run
120 .B dsig show sig
121 for a list of supported signature algorithms.
122 .TP
123 .B rsapkcs1
124 This is almost the same as the RSASSA-PKCS1-v1_5 algorithm described in
125 RFC3447; the difference is that the hash is left bare rather than being
126 wrapped in a DER-encoded
127 .B DigestInfo
128 structure. This doesn't affect security since the key can only be used
129 with the one hash function anyway, and dropping the DER wrapping permits
130 rapid adoption of new hash functions. Regardless, use of this algorithm
131 is not recommended, since the padding method has been shown vulnerable
132 to attack. Use the
133 .B rsa
134 algorithm of the
135 .B key add
136 command (see
137 .BR key (1))
138 to generate the key.
139 .TP
140 .B rsapss
141 This is the RSASSA-PSS algorithm described in RFC3447. It is the
142 preferred RSA-based signature scheme. Use the
143 .B rsa
144 algorithm of the
145 .B key add
146 command (see
147 .BR key (1))
148 to generate the key.
149 .TP
150 .B dsa
151 This is the DSA algorithm described in FIPS180-1 and FIPS180-2. Use the
152 .B dsa
153 algorithm of the
154 .B key add
155 command (see
156 .BR key (1))
157 to generate the key.
158 .TP
159 .B ecdsa
160 This is the ECDSA algorithm described in ANSI X9.62 and FIPS180-2. Use
161 the
162 .B ec
163 algorithm of the
164 .B key add
165 command (see
166 .BR key (1))
167 to generate the key.
168 .TP
169 .B kcdsa
170 This is the revised KCDSA (Korean Certificate-based Digital Signature
171 Algorithm) described in
172 .I The Revised Version of KCDSA
173 .RB ( http://dasan.sejong.ac.kr/~chlim/pub/kcdsa1.ps ).
174 Use the
175 .B dh
176 algorithm of the
177 .B key add
178 command with the
179 .B \-LS
180 options (see
181 .BR key (1))
182 to generate the key.
183 .TP
184 .B eckcdsa
185 This is an unofficial elliptic-curve analogue of the KCDSA algorithm.
186 Use the
187 .B ec
188 algorithm of the
189 .B key add
190 command (see
191 .BR key (1))
192 to generate the key.
193 .PP
194 As well as the signature algorithm itself, a hash function is used.
195 This is taken from the
196 .B hash
197 attribute on the key, or, failing that, from the
198 .I hash
199 specified in the
200 .IR sigalgspec ,
201 or, if that is absent, determined by the signature algorithm as follows.
202 .hP \*o
203 For
204 .BR rsapkcs1 ,
205 .BR rsapss ,
206 .BR dsa ,
207 and
208 .BR ecdsa ,
209 the default hash function is
210 .BR sha .
211 .hP \*o
212 For
213 .BR kcdsa
214 and
215 .BR eckcdsa ,
216 the default hash function is
217 .BR has160 .
218 .PP
219 Run
220 .B dsig show hash
221 for a list of supported hash functions.
222 .SH "COMMAND REFERENCE"
223 .SS help
224 The
225 .B help
226 command behaves exactly as the
227 .B \-\-help
228 option. With no arguments, it shows an overview of
229 .BR dsig 's
230 options; with arguments, it describes the named subcommands.
231 .SS show
232 The
233 .B show
234 command prints various lists of tokens understood by
235 .BR dsig .
236 With no arguments, it prints all of the lists; with arguments, it prints
237 just the named lists, in order. The recognized lists can be enumerated
238 using the
239 .VS
240 dsig show list
241 .VE
242 command. The lists are as follows.
243 .TP
244 .B list
245 The lists which can be enumerated by the
246 .B show
247 command.
248 .TP
249 .B sig
250 The signature algorithms which can be used in a key's
251 .B sig
252 attribute.
253 .TP
254 .B hash
255 The hash functions which can be used in a key's
256 .B hash
257 attribute.
258 .SS sign
259 The
260 .B sign
261 command creates a signature for a collection of files. The default
262 behaviour is to read a list of whitespace-separated file names (see
263 below for the precise format) from standard input and write the
264 an output file, containing hashes of the files and a digital signature
265 made by the key
266 .B dsig
267 in the current keyring, to standard output, in plain text with binary
268 values Base64-encoded. It is intended to be used in conjunction with
269 .BR find (1).
270 This behaviour can be modified by specifying command-line options.
271 .TP
272 .B "\-0, \-\-null"
273 Read null-terminated filenames, rather than whitespace-separated names.
274 This is the recommended mode of operation if you have a
275 .BR find (1)
276 which understands the
277 .B \-print0
278 option.
279 .TP
280 .B "\-b, \-\-binary"
281 Produce output in raw binary rather than the textual output. This isn't
282 a useful thing to do unless you're trying to debug
283 .BR dsig .
284 .TP
285 .B "\-v, \-\-verbose"
286 Makes
287 .B dsig
288 more verbose. At present, this just means that it'll print the hashes
289 of files that it comes across in hex. (Use
290 .BR hashsum (1)
291 if this is the output you actually wanted.)
292 .TP
293 .B "\-q, \-\-quiet"
294 Makes
295 .B dsig
296 less verbose.
297 .TP
298 .BI "\-c, \-\-comment " string
299 Writes
300 .I string
301 as a comment in the output file. The comment's integrity is protected
302 by the signature.
303 .TP
304 .BI "\-p, \-\-progress"
305 Write a progress meter to standard error while processing large files.
306 .TP
307 .BI "\-f, \-\-file " name
308 Read filenames from
309 .I name
310 instead of from standard input.
311 .TP
312 .BI "\-o, \-\-output " name
313 Write output to
314 .I name
315 instead of to standard output.
316 .TP
317 .BI "\-k, \-\-key " tag
318 Use the key named
319 .I tag
320 rather than the default
321 .BR dsig .
322 .TP
323 .BI "\-e, \-\-expire " date
324 Set the signature to expire at
325 .IR date .
326 The default is to expire 28 days from creation. Use
327 .B forever
328 to make the signature not expire.
329 .TP
330 .B "\-C, \-\-nocheck"
331 Don't check the private key for validity. This makes signing go much
332 faster, but at the risk of using a duff key, and potentially leaking
333 information about the private key.
334 .PP
335 The whitespace-separated format for filenames allows quoting and
336 escaping of strange characters. The backslash
337 .RB ` \e '
338 can be used to escape whitespace, quotes, or other special characters
339 (including itself), and to represent special characters using the
340 standard C escape sequences
341 .RB ` \ea ',
342 .RB ` \eb ',
343 .RB ` \ef ',
344 .RB ` \en ',
345 .RB ` \et ',
346 and
347 .RB ` \eb '.
348 A filename can be quoted in
349 .BR ` ... ',
350 .BR ' ... '
351 or
352 .BR """" ... """".
353 Whitespace within quotes is part of the filename. The quotes must be at
354 the beginning and end of the name.
355 .SS verify
356 The
357 .B verify
358 command will verify signatures made by the
359 .B sign
360 command. With no arguments, it expects to read a text-format signature
361 file from standard input; with an argument, it examines the file it
362 names to see whether it's text or binary.
363 .PP
364 Command-line options provided are:
365 .TP
366 .B "\-v, \-\-verbose"
367 Produce more informational output. The default verbosity level is 1.
368 .TP
369 .B "\-q, \-\-quiet"
370 Produce less information output.
371 .TP
372 .BI "\-p, \-\-progress"
373 Write a progress meter to standard error while processing large files.
374 .TP
375 .B "\-C, \-\-nocheck"
376 Don't check the public key for validity. This makes verification go
377 much faster, but at the risk of using a duff key, and potentially
378 accepting false signatures.
379 .PP
380 Output is written to standard output in a machine-readable format.
381 Formatting errors cause the program to write a diagnostic to standard
382 error and exit nonzero as usual. Lines begin with a keyword:
383 .TP
384 .BI "FAIL " reason
385 An error prevented verification.
386 .TP
387 .BI "BAD " reason
388 The signature is bad: some file had the wrong hash or the signature is
389 invalid.
390 .TP
391 .BI "WARN " reason
392 .B dsig
393 encountered a situation which may or may not invalidate the signature.
394 .TP
395 .BI "OK " message
396 The signature verified correctly.
397 .TP
398 .BI "INFO " note
399 Any other information.
400 .PP
401 The information written at the various verbosity levels is as follows.
402 .hP 0.
403 No output. Watch the exit status.
404 .B dsig
405 exits zero if the signature was good.
406 .hP 1.
407 All
408 .BR OK ,
409 .B FAIL
410 and
411 .B WARN
412 messages are printed.
413 .hP 2.
414 As for level 1; also
415 .B BAD
416 messages are printed describing reasons why the signature verification
417 failed, and an
418 .B INFO
419 message is printed showing the signature file's comment if any.
420 .hP 3.
421 As for level 2; also
422 .B INFO
423 messages are shown listing the signing program's identification string,
424 the signing key, the signature and expiry dates, and actual signature
425 verification.
426 .hP 4.
427 As for level 3; also
428 .B INFO
429 messages are printed for each file covered, showing its name and hash.
430 .SH "OUTPUT FORMAT"
431 There are two output formats: textual and binary. The hash used in the
432 digital signature is always computed on the
433 .I binary
434 version of the data, regardless of the external representation.
435 .SS "Textual format"
436 Within the file, whitespace and comments between strings are ignored. A
437 comment begins with a hash
438 .RB (` # ')
439 and extends until the next newline.
440 .PP
441 Strings are either quoted or whitespace-delimited. A string may be
442 quoted by
443 .BR ` ... ',
444 .BR ' ... '
445 or
446 .BR """" ... """".
447 The end-quote character can be backslash-escaped within the string. An
448 occurrence of the unescaped end-quote character terminates the string.
449 A whitespace-delimited string is terminated by any unescaped whitespace
450 character. The C-language escape sequences
451 .RB ` \ea ',
452 .RB ` \eb ',
453 .RB ` \ef ',
454 .RB ` \en ',
455 .RB ` \et ',
456 and
457 .RB ` \eb '
458 are recognized within either kind of string.
459 .PP
460 Blocks within the file consist of sequences of strings. The first
461 string is a
462 .I tag
463 \(en a simple string ending in a colon
464 .RB (` : ')
465 \(en which describes the format of the remaining strings.
466 .SS "Binary format"
467 The file consists of a sequence of blocks, each of which begins with a
468 tag byte. The format of the test of the block depends on the tag.
469 Strings are null-terminated; all integers are in network byte order.
470 .PP
471 A binary file always begins with an ident block, which has a tag of 0.
472 .SS "Block types"
473 The following block types are known. They must appear in the order
474 given, and except where noted must appear exactly once each.
475 .TP
476 .BR "ident: " (0)
477 Identification string of the generating program.
478 .BR "keyid: " (1)
479 The signing key's id, as eight hex digits (text) or a 32-bit integer
480 (binary).
481 .TP
482 .BR "comment: " (2)
483 The comment string set with the
484 .B \-c
485 option to the
486 .B sign
487 command. This block need not appear.
488 .TP
489 .BR "date: " (3)
490 The date the signature was made. In a text file, this has the form
491 .IB yyyy-mm-dd
492 .IB hh:mm:ss
493 .IR timezone ;
494 in a binary file, it's a 64-bit integer representing the POSIX time.
495 .TP
496 .BR "expires: " (4)
497 The expiry time of the signature, expressed as for
498 .BR date: .
499 A non-expiring signature is represented by the string
500 .B forever
501 in text files, or all-bits-set in binary.
502 .TP
503 .BR "file: " (5)
504 A file hash. In text, this is two strings which are the Base-64-encoded
505 hash and the file name; in binary, this is a 16-bit hash length, the raw
506 hash, and the null-terminated filename. There can be any number of
507 .B file:
508 blocks.
509 .TP
510 .BR "signature: " (6)
511 The signature. In text, this is the Base-64-encoded signature; in
512 binary, it is a 16-bit length followed by the binary signature.
513 .PP
514 The signature covers the
515 .I binary
516 representations of the file's
517 .BR date: ,
518 .B expires:
519 and
520 .B file:
521 blocks.
522 .SH "SEE ALSO"
523 .BR key (1),
524 .BR hashsum (1),
525 .BR catcrypt (1),
526 .BR catsign (1),
527 .BR keyring (5).
528 .SH AUTHOR
529 Mark Wooding, <mdw@distorted.org.uk>