Debian Codegraph @

hashcash.pod

raw ◀ ▶
1 Debian patch touch this file
1 =head1 NAME
2
3 hashcash - hashcash anti-spam / denial of service counter-measure tool
4
5 =head1 SYNOPSIS
6
7 =head2 Mint (create) stamps:
8
9 B<hashcash> I<-m> [ [ I<options> ] [ I<resource> ... ] ... ]
10
11 =head2 Check stamps:
12
13 B<hashcash> I<-c> [ [ I<options> ] I<-r resource> ... ] [ I<stamp> ... ]
14
15 =head2 Speed estimates:
16
17 B<hashcash> I<-s> [ I<options> ] [ I<-b bits> ]
18
19 =head2 Purge database:
20
21 B<hashcash> I<-p now> [ I<-j resource> ] [ I<-k> ] [ I<-t time> ] [ I<-u> ]
22
23 =head2 Count partial preimage bits:
24
25 B<hashcash> I<-w> [ I<options> ] [ I<stamp> ... ]
26
27 =head2 Get resource name:
28
29 B<hashcash> I<-n> [ I<options> ] [ I<stamp> ... ]
30
31 =head2 Get time remaining until expiry
32
33 B<hashcash> I<-l> [ I<options> ] I<-e period> [ I<stamp> ... ]
34
35 =head1 DESCRIPTION
36
37 Hashcash is a denial-of-service counter measure tool. Its main
38 current use is to help hashcash users avoid losing email due to
39 content based and blacklist based anti-spam systems.
40
41 The hashcash tool allows you to create hashcash stamps to attach to
42 emails you send, and to verify hashcash stamps attached to emails you
43 receive. Email senders attach hashcash stamps with the X-Hashcash:
44 header. Vendors and authors of anti-spam tools are encouraged to
45 exempt mail sent with hashcash from their blacklists and content based
46 filtering rules.
47
48 A hashcash stamp constitutes a proof-of-work which takes a
49 parameterizable amount of work to compute for the sender. The
•50 recipient can verify received stamps efficiently.
51
52 The hashcash proof-of-work function is to compute partial hash
53 preimages (the SHA1 hash function is used). By choosing the number of
54 bits of the preimage that are equal to 0, the work required to compute
55 a partial preimage can be made arbitrarily expensive -- from fractions
56 of a second to minutes or hours. The verification is efficient
57 requiring the same small cost whatever the preimage size.
58
59 For more detailed discussion of other applications hashcash has been
60 used for see http://www.hashcash.org/
61
62 =head1 USAGE NOTES
63
64 In this man page a resource name is the name of the service or address
65 the stamp is created for. In the case of email, the resource name is
66 the recipient's email address in the form [email protected].
67
68 =head2 Minting stamps
69
70 The I<-m> flag must be given to mint a stamp.
71
72 The resource name (recipient's email address) to mint the stamp
73 against can be passed as an argument, or if omitted is read from
74 stdin. If stdin is a tty the user is prompted, if stdin is a pipe the
75 resource name is just silently read. The desired preimage size can
76 be specified with the -b option. If no preimage size is specified,
77 the default is 20 bits. See also the I<-b default> option.
78
79 =head2 Checking stamps
80
81 The I<-c> flag must be given to check a stamps expiry. The stamp to
82 check can be given as an argument to C<hashcash>. If no stamp is
83 given the stamp is read from stdin. If stdin is a tty the user will
84 be prompted, if stdin is a pipe the stamp is just silently read. A
85 resource name (the recipient's email address) can be given with the
86 I<-r> option. If a resource name is given the resource name is
87 compared to the resource name in the stamp, if they do not match, the
88 stamp is rejected.
89
90 Note: if no resource name is given the stamp is anyway checked to see
91 if it is otherwise valid, but it could be minted for a different
92 resource, which would allow stamps to be reused across different
93 resources, so hashcash will return unchecked exit code on exit.
94
95 Stamps are by default considered to be valid for 28 days. The validity
96 period can be changed using the I<-e> flag.
97
98 If the stamp has expired or has a date in the future the stamp is
99 rejected and the program exits immediately.
100
101 If a required preimage size is given with the I<-b> flag, the stamps value
102 is computed and compared, if the stamp has insufficent value it is rejected,
103 and the program exits immediately. If the I<-b> flag is not given, the
104 stamp is checked to see if it is otherwise valid, but hashcash will return
105 unchecked exit code on exit.
106
107 If the stamp is double spent the stamp is rejected. Double spending
108 protection is discussed in more detail below in
109 L<Double Spending Protection>. If double spending protection is not
110 enabled, the stamp could be double spent, so hashcash will return
111 unchecked exit code (exit code 2) on exit.
112
113 The I<-w> flag can be used to request that the number of bits of the
114 preimage are counted and displayed. The I<-n> flag can be used to
115 request that the resource name in the stamp is parsed out and
116 displayed. The I<-l> flag can be used to request the number of
117 seconds until expiry of the stamp is output.
118
119 The program will only return exit codes valid or invalid if the I<-c>
120 flag is used, the I<-b> flag is used, I<-d>, I<-r resource> are used.
121 These are the minimum set of options necessary to fully check the
122 validty of a stamp. If these criteria are not met, the program will
123 return exit code unchecked (exit code 2) on exit. (See also the I<-y>
124 flag.)
125
126 =head2 Double Spending Protection
127
128 If the I<-d> flag is used when checking stamps, a database of spent
129 stamps is kept.
130
131 By default stamps expire after 28 days, without expiry the database
132 would grow indefinately. You can specify an alternate expiry period
133 with the I<-e> flag. The recommended (and default) expiry period for
134 email is 28 days. After the expiry period amount of time, the stamp
135 is anyway considered expired and may be purged from the database to
136 save space. (See L<Purging Periodically vs on Next Access> for how to
137 purge stamps.)
138
139 For efficiency reasons a stamp is verified before it is checked in the
140 database; if it is otherwise invalid no database activity will occur.
141
142 Note: The decision about how long the stamp should be considered valid
143 is up to the verifier. If it is too short it is possible for some
144 applications that the stamp will expire before arriving at the
145 recipient (eg with email.) The suggested value of 28 days should be
146 safe for normal email delivery delays. The choice is a trade-off
147 between database size and risk of expiry prior to arrival, and depends
148 on the application.
149
150 Note: Different stamps in the same database can have different
151 validity periods, so for example stamps for different resources with
152 different validity periods can be stored in the same database, or the
153 recipient may change the validity period for future stamps without
154 affecting the validity of old stamps.
155
156 =head2 Purging Periodically vs on Next Access
157
158 To purge old stamps periodically while checking stamps use the I<-p
159 period> option to purge no sooner than the given time period since the
160 last purge. Purging can be used with the I<-k> option to purge
161 unexpired stamps also, and with the I<-j resource> flag to purge only
162 stamps for the given resource.
163
164 There are circumstances where it may be inconvenient to purge stamps
165 on the next access, for example if there is a large double spend
166 database which takes some time to purge, and the response time of the
167 hashcash checker is important. To avoid this problem, purging can be
168 done separately using just the I<-p now> option to request just the
169 purge operation. On unix for example you could call C<hashcash -p
170 now> in a cron job once per day, or on demand when disk was running
171 low.
172
173 =head2 Speed Estimates
174
175 The I<-s> flag requests measurement of how many preimage can be
176 tested per second. No stamp is minted, or verified.
177
178 If the I<-b> flag is used with this option, instead an estimate of how
179 many seconds it would take to mint a stamp of the given size in bits
180 is computed. To find out how much time it will take to mint a default
181 sized stamp use I<-s -b default>.
182
183 =head2 Notes
184
185 All informational output is printed on stderr. Minted stamps, and
186 results of stamp verification and timing are printed on stdout. The
187 quiet flag I<-q> suppresses all informational output. The I<-v> flag
188 requests more informational output. The requested output, which is
189 the only information that is output in quiet mode (when I<-q> is
190 specified) is printed on standard output. If stdout is a pipe, or
191 when quiet mode is in effect the output is printed without description
192 (ie just bits, just seconds, just resource).
193
194 =head1 OPTIONS
195
196 =over 4
197
198 =item I<-c>
199
200 Check the expiry information of stamps given as an argument or on
201 stdin. (Use with I<-b>, I<-d> and I<-r resource> to fully check
202 stamps).
203
204 =item I<-m>
205
206 Mint stamps with the resources given as arguments or on stdin.
207
208 =item I<-b bits>
209
210 When minting a stamp, create a preimage of at least this many bits.
211 When verifying a stamp require that it have a preimage of at minimum
212 this many bits, otherwise reject it. If omitted the default is used.
213
214 When checking stamps, require that the stamps have this many bits.
215
216 The default number of bits can be specified with I<-b default>. Bits
217 relative to the default can also be specified with I<-b +n> for n bits
218 more than the default and I<-b -n> for n bits less than the default.
219
220 I<-b default>, I<-b +0> and I<-b -0> are all equivalent.
221
222 When doing the speed test I<-s>, can to measure speed of default
223 token with I<-s -b default>.
224
225 =item I<-r resource>
226
227 When minting stamps, the resource name (recipient's email address) to
228 mint the stamp against can be given either with I<-r resource> or as
229 an argument to C<hashcash>.
230
231 When checking stamps, the resource name (your own email address) is
232 given with the I<-r> option. If the resource name is given it is
233 checked against the resource name in the stamp, and if they do not
234 match the stamp is rejected. Note if the resource name is not given,
235 stamps for other resources would be accepted, and therefore hashcash
236 returns exit code unchecked (exit code 2) on exit.
237
238 =item I<-o>
239
240 When verifying stamps multiple resources can be given. By default the
241 resources are just checked one by one until a matching valid resource is
242 found. However when you use wildcards or regular expressions (see I<-E>),
243 it is useful to be able to specify that one resource overrides another. For
244 example this: I<-b15 -r [email protected] -o -b10 *@dev.null> states that mail
245 to address I<[email protected]> requires 15 bits, but mail to I<*@dev.null>
246 requires only 10 bits. If we omitted the I<-o> override relationship
247 between the two resources, a stamp of 10 bits would be accepted for address
248 I<[email protected]> because while it would be rejected as having insufficient
249 bits under the first rule, it would be accepted under the 2nd rule. The
250 I<-o> option allows you avoid this problem.
251
252 =item I<-e time>
253
254 Expiry period for spent stamps. While checking stamps (using the I<-c>
255 flag), if the stamp was minted more than the specified amount of time ago,
256 it is considered expired. If this option is not used, by default stamps
257 expire after 28 days. The expiry period is given in seconds by default (an
258 argument of 0 means forever). A single character suffix can be used to
259 specify alternate units (m = minutes, h = hours, d = days, M = months, y = Y
260 = years, and s = seconds).
261
262 If used with the I<-d> option, the spent stamp and its expiry period
263 is recorded in the database. See the I<-p> option for description of
264 how to purge stamps from the database.
265
266 While minting stamps, the I<-e> flag can have an effect on the
267 resolution of time created in the stamp. Without the I<-e> option,
268 the default resolution is days (time format: YYMMDD). Alternate
269 formats based on range of expiry period are as follows:
270
271 While minting you can also given an explicit time width with the I<-z>
272 option instead. (I<-z> overrides I<-e> if both are given. If neither
273 are given the default is 6 chars (time format: YYMMDD)).
274
275 The rules for automatically determining appropriate time width from
276 I<-e> if no I<-z> option is given are:
277
278 =over 8
279
280 =item * period E<gt>= 2 years then time format YY is used rounded down
281 to the nearest year start;
282
283 =item * 2 years E<lt> period E<lt>= 2 months then time format YYMM is
284 used rounded down to the nearest month start;
285
286 =item * 2 months E<lt> period E<lt>= 2 days then time format YYMMDD is
287 used rounded down to the begining of the nearest day;
288
289 =item * 2 days E<lt> period E<lt>= 2 minutes then time format
290 YYMMDDhhmm is used rounded down to the begining of the nearest minute;
291
292 =item * period E<lt> 2 minutes then time format YYMMDDhhmmss is used in
293 seconds.
294
295 =back
296
297 Note the rounding down is based on UTC time, not local time. This can
298 lead to initially suprising results when rounding down to eg days in
299 time zones other than GMT (UTC = GMT). It may be clearer to
300 understand if you use the I<-u> option.
301
302 =item I<-z width>
303
304 The I<-z> option is for use during minting and allows user choice of
305 width of time width field. See also the I<-e> option given in
306 combination with I<-m> to specify an implicit time field width under
307 the description of the I<-e> flag. Valid widths are 6,10 or 12 chars
308 corresponding respectively to: YYMMDD, YYMMDDhhmm, and YYMMDDhhmmss
309 rounded down to the nearest day, or minute respectively.
310
311 Note the rounding down is based on UTC time, not local time. This can
312 lead to initially suprising results when rounding down to eg days in
313 time zones other than GMT (UTC = GMT). It may be clearer to
314 understand if you use the I<-u> option.
315
316 =item I<-g period>
317
318 The I<-g> option is for use when checking hashcash stamps with the
319 I<-c> option and specifies a grace period for clock skew, ie if a
320 hashcash stamp arrives with a date in the future or in the past it
321 will not be rejected as having a futuristic date (or as being expired)
322 unless it is more futuristic (or has been expired for longer) than
323 this period. The default is 2 days, which means as long as the
324 sending system's clock is no more than 2 days ahead (or 2 days behind)
325 of the receiving system's clock, the hashcash stamp will still be
326 accepted.
327
328 The default units for grace period are seconds. A single character
329 suffix can be used to specify alternate units (m = minutes, h = hours,
330 d = days, M = months, y = Y = years, and s = seconds).
331
332 =item I<-d>
333
334 Store stamps in a double spend database. If stamp has been seen
335 before it will be rejected even if it is otherwise valid. The default
336 database file is F<database.sdb> in the current directory. Only
337 otherwise valid stamps will be stored in the database. Only fully
338 validated stamps will be stored in the database, unless the I<-y>
339 option is given.
340
341 =item I<-f dbname>
342
343 Use F<dbname> instead of default filename for double spend database.
344
345 =item I<-p period>
346
347 Purges the database of expired stamps if the given time period has
348 passed since the last time it was purged. As a convenience I<-p now>
349 is equivalent to I<-p 0> both of which mean purge now, regardless of
350 when the database was last purged.
351
352 If used in combination with I<-j resource> only the stamps minted for
353 the given resource are purged.
354
355 If used in combination with I<-k> all stamps even un-expired stamps
356 are purged. Can be used in combination with I<-t time> to expire as
357 if the current time were the given time.
358
359 =item I<-k>
360
361 Use with option I<-p> to request all stamps are purged rather than
362 just expired ones.
363
364 =item I<-j resource>
365
366 Use with option I<-p> to request that just stamps matching the given
367 resource name are to be purged, rather than the default which is to
368 purge all expired stamps. If the resource name is the empty string,
369 all stamps are matched (this is equivalent to omitting the I<-j>
370 option).
371
372 Note the I<-E>, I<-M> and I<-S> type of match flags also apply to
373 resources given with the I<-j resource> flag.
374
375 =item I<-s>
376
377 Print timing information only, and don't proceed to create a stamp.
378 If combined with I<-b bits> flag print estimate of how long the
379 requested preimage size would take to compute, if I<-s> given by
380 itself, just prints speed of the preimage finder. To print an
381 estimate of how long the default number of bits would take use I<-b
382 default>.
383
384 =item I<-h>
385
386 Print short usage information.
387
388 =item I<-v>
389
390 Print more verbose informational output about the stamp minting or
391 verification. (If -v is the only argument, prints the tool version
392 number.)
393
394 =item I<-V>
395
396 Prints tool version number.
397
398 =item I<-q>
399
400 Batch mode. Prints no information other than output. This option
401 overrides the I<-v> option.
402
403 =item I<-X>
404
405 When minting, prints the hashcash email X-header 'X-Hashcash: ' before
406 the stamp. Without this option just the bare stamp is printed.
407
408 When checking, after scanning stamps given as arguments, scans stdin
409 for lines starting with the string 'X-Hashcash:', and uses the rest of
410 the matching line as the stamp. Only the lines up to and ending at
411 the first blank line are scanned (see also I<-i> flag which can be
412 used to override this). A blank line is the separator used to
413 separate the headers from the body of a mail message or USENET
414 article. This is meant to make it convenient to pipe a mail message
415 or USENET article to hashcash on stdin.
416
417 =item I<-x extension>
418
419 An extension string composed of name value sets. The extension format
420 is described below in the section on the hashcash stamp format. This
421 allows users to define their own stamp extensions which are hashed
422 into the stamp, verified by recipients that support them, and ignored
423 by recipients that don't support them. Note the extension hook
424 mechanism has not yet been implemented. This will come in a
425 subsequent release.
426
427 =item I<-i>
428
429 When checking and using the I<-X> flag, ignore the blank line
430 boundary between headers and body of the message, and check for
431 stamps in the body too if one is not found in the headers.
432
433 =item I<-t time>
434
435 Pretend the current time is the time given for purposes of minting
436 stamps, verifying stamps and purging old stamps from the database.
437 Time is given in a format based on UTCTIME format
438 YYMMDD[hhmm[ss]].
439
440 Time is expressed in local time by default. Use with I<-u> flag to
441 give time in UTC (GMT).
442
443 You can also give time relative to the current time by prefixing the
444 argument with + or -. The default units for relative time are
445 seconds. A single character suffix can be used to specify alternate
446 units (m = minutes, h = hours, d = days, M = months, y = Y = years,
447 and s = seconds).
448
449 Note: when time is expressed in local time, if there is daylight
450 savings in your timezone, there are one or two ambiguous hours per
451 year at the time of change from daylight savings time to normal time.
452
453 =item I<-u>
454
455 Input and output absolute times in UTC (GMT) instead of local time.
456
457 =item I<-a period>
458
459 Add (or subtract if number is negative) a random value from the
460 current time before minting the stamp. This hides the time the stamp
461 was created, which may be useful for anonymous users. Note adding
462 (rather than subtracting) a random time may be risky if the stamp
463 takes less than the added time to arrive as the recipient will reject
464 stamps with time stamps in the future.
465
466 =item I<-n>
467
468 Print resource name parsed from stamp being verified. Returns exit
469 code unchecked on exit.
470
471 =item I<-l>
472
473 Print number of seconds left before stamp expires. Returns exit code
474 unchecked on exit.
475
476 Note: the calculation includes the grace period, so can be up to 2
477 times grace period longer than you might otherwise expect (clock fast
478 but system has to presume it could be slow). If you want to exclude
479 the grace period add I<-g0> to set grace period to 0 for the
480 calculation.
481
482 =item I<-w>
483
484 Print number of bits of preimage of stamp. Returns exit code
485 unchecked on exit.
486
487 =item I<-y>
488
489 Returns success if the stamp is valid even if it is not fully checked.
490 Use with I<-c> where not all of I<-d>, I<-r> are specified to get
491 success exit code on valid but partially checked stamp. Similarly can
492 use with I<-n>, I<-l>, I<-w> with same effect.
493
494 =item I<-M>
495
496 When checking stamps, allow wildcard I<*> matching in the resource
497 name to make it simpler to specify multiple email addresses and to
498 allow matching catch-all addresses and addresses including subdomains.
499 This is the default. See also I<-S>, I<-E> and I<-C>
500
501 =item I<-S>
502
503 When checking stamps use simple text compare to compare resource names
504 to those in stamps. See also I<-M>, I<-E> and I<-C>.
505
506 =item I<-E>
507
508 When checking stamps use regular expressions to specify resource names
509 to make it simpler to specify multiple email addresses, catch-all
510 addresses, classes of extension addresses and addresses including
511 subdomains. Note regular expression syntax is POSIX style: special
512 characters do not need to be quoted to have their special meaning; but
513 they do have to be quoted with \ to that character in the searched
514 string. The regular expression automatically has ^ added at the
515 beginning and $ added at the end, if they are not specified. The
516 special characters ^ matches the beginning of the resouce, and $
517 matches the end of resource.
518
519 (Note even if compiled with BSD regular expressions, POSIX style
520 syntax is used; also note BSD regular expressions do not support
521 ranges {}.)
522
523 =item I<-C>
524
525 By default resources are canonicalized to lower case on minting and on
526 checking. The I<-C> flag overrides this so that resources are treated
527 as case sensitive on checking, and not canonizalized on minting.
528
529 =item I<-P>
530
531 Print progress info (number of iterations, expected iterations,
532 percentage done, best stamp size found so far).
533
534 =item I<-O core>
535
536 Select hashcash core with that number. Currently 0-9 are valid cores.
537 Not all cores work on all architectures. Eg some are x86 specific
538 assembler, others PPC specific assembler. If a core is not valid
539 hashcash returns failure and explains what happened.
540
541 =item I<-Z n>
542
543 Compress the stamp. This is a time vs space trade off. Larger stamps
544 are faster, but arguably slightly ugly. For fastest stamps (the
545 default) use -Z 0; for partly compressed stamps use -Z 1; for very
546 compressed, but somewhat slow stamps use -Z 2. (Note: due to a late
547 discovered bug, -Z2 is the same as -Z1 for now until I can fix that.)
548
549 =back
550
551 =head1 EXAMPLES
552
553 =head2 Creating stamps
554
555 =over 4
556
557 =item C<hashcash -s>
558
559 Print timing information about how many preimages the machine can try
560 per second.
561
562 =item C<hashcash -sv>
563
564 More accurate but quite slow benchmarking of different processor
565 specific minting cores.
566
567 =item C<hashcash -s -b default>
568
569 Print how long it would take the machine to compute a default sized
570 preimage (but don't actually compute a preimage).
571
572 =item C<hashcash -s -b 32>
573
574 Print how long it would take the machine to compute a 32 bit preimage
575 (but don't actually compute a preimage).
576
577 =item C<hashcash -m>
578
579 Mint a stamp. Will prompt for resource name and mint with default
580 value (number of preimage bits).
581
582 =item C<hashcash -m foo>
583
584 Compute preimage on resource foo. Will mint with default value
585 (number of preimage bits).
586
587 =item C<hashcash -m foo -b 10>
588
589 Compute 10 bit preimage on resource foo.
590
591 =item C<hashcash -a -3d>
592
593 Subtract a random time of between 0 days and 3 days from the stamp's
594 creation time. This is the same fuzz factor used by mixmaster to
595 reduce risk of timing-correlations.
596
597 =back
598
599 =head2 Examining Stamps
600
601 =over 4
602
603 =item C<hashcash -w 1:24:040806:foo::511801694b4cd6b0:1e7297a>
604
605 Report the value of the stamp (how many bits of preimage) there are.
606 The example is a 24 bit preimage, which takes on average 25 seconds
607 to create on a 3Ghz P4.
608
609 =item C<hashcash -mq -b 10 foo | hashcash -w>
610
611 Create a stamp in batch mode, pass to hashcash on stdin to verify,
612 have it print how many bits there were.
613
614 =item C<hashcash -n 1:24:040806:foo::511801694b4cd6b0:1e7297a>
615
616 Report the resource name from the stamp. The resource name in the
617 example is foo.
618
619 =item C<hashcash -l -e 30y 1:24:040806:foo::511801694b4cd6b0:1e7297a>
620
621 Report how long until the stamp expires if it expires in 30 years from
622 its creation date. (Note dates too far into the future run into the
623 2038 end of Epoch, which is the unix time analog of the y2k bug).
624
625 =back
626
627 =head2 Verifying Stamps
628
629 =over 4
630
631 =item C<hashcash -c 1:24:040806:foo::511801694b4cd6b0:1e7297a>
632
633 Check if the stamp is valid. Note as we are not checking the stamp in
634 a double spend database, and did not specify a resource name or
635 required number of bits of preimage and hashcash will consider the
636 stamp not fully checked, and it will report it as valid but not fully
637 unchecked, or as invalid if there is any problem with the stamp.
638
639 =item C<hashcash -c -b24 1:24:040806:foo::511801694b4cd6b0:1e7297a>
640
641 Check that the value of the stamp is greater or equal to 24 bits.
642 This example has 24 bit value. If you increase the requested number
643 of bits or replace the stamp with one with less than 24 bit preimage
644 the stamp will be rejected.
645
646 =item C<hashcash -c -b24 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
647
648 As above check if the stamp has sufficient value, but in addition
649 check that the resource name given matches the resource name in the
650 stamp.
651
652 =back
653
654 =head2 Double Spending Prevention
655
656 The examples given in L<Verifying Stamps> can be modified to keep a
657 double spend database so that the same stamp will not be accepted
658 twice. Note a stamp will only be checked in and added to the database
659 if it is otherwise valid and fully checked (a required number of bits
660 of preimage has been specified and a resource has been specified).
661
662 =over 4
663
664 =item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
665
666 Check the stamp and add to double spent database if it's valid (has
667 correct resource name and sufficient value).
668
669 =item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
670
671 Try to double spend the stamp. It will be rejected as double spent.
672
673 =back
674
675 =head2 Stamp Expiry
676
677 To prevent the double spend database growing indefinately, the
678 recipient can request that stamps be no older than a specified period.
679 After expiry old stamps can dropped from the double spend database as
680 they will no longer be needed -- expired stamps can be rejected based
681 purely on their old date, so the space taken by expired stamps in the
682 double spend database can be saved without risk of accepting an
683 expired though otherwise valid stamp.
684
685 The third field of the stamp is the UTC time since 1st January 1970.
686 The default time format is YYMMDD, time rounded down to the nearest
687 day. The default validity period is 28 days.
688
689 You can provide an alternative validity period with the I<-e> option.
690
691 =over 4
692
693 =item C<hashcash -cd -b 10 -e 2d -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
694
695 Try verifying an old stamp, the above stamp was created 11 Aug 2002.
696
697 We gave option I<-e 2d> so the stamps expiry date is 2 days after
698 creation, which is now in the past.
699
700 Note: if the creation time is expressed in the stamp in days, the
701 precise creation date is the begining of the specified day in UTC time
702 (similarly for alternate units the creation time is rounded down to
703 the begining of the unit it is expressed in). For units in days, for
704 example, this may mean depending on your time zone that the stamp
705 appears to be considered invalid in under the specified expiry period
706 in days relative to your relative view of what day it is, as the
707 calculation is based on current time in UTC, and the creation time of
708 the stamp is expressed in UTC time.
709
710 =item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>
711
712 Test whether the stamp is otherwise valid, apart from having expired.
713 Omitting the I<-e> tells hashcash that the stamp will never expire.
714 An expiry period of forever can also be given explitly like this: I<-e
715 0>, where an expiry period of 0 means forever.
716
717 =back
718
719 =head2 Purging old stamps
720
721 If the I<-c>, I<-d> options are used together, each time a stamp is
722 checked, if it is valid and all of the mandatory aspects of the stamp
723 are verified (preimage bits check, resource name check) then the
724 stamp and its expiry period is written to the database file. The
725 default expiry period if an expiry period is not given explicitly with
726 the I<-e> option is 28 days (ie stamps expire after 4 weeks).
727
728 First mint and then add a stamp:
729
730 =over 4
731
732 =item C<hashcash -m -b 10 foo -e 1m E<gt> stamp>
733
734 Note: we specified an expiry on minting in this example, to ensure
735 that the stamp creation time is given in high enough resolution in the
736 stamp that the stamp will not be considered expired at time of
737 creation. (Recall the default resolution is in days, a stamp created
738 with a creation time rounded down to the beginging of the day is
739 unlikely to be considered valid 1 minute later unless you mint it at
740 midnight UTC time.)
741
742 =item C<hashcash -cd -e 1m -b 10 -r foo E<lt> stamp>
743
744 The stamp expires in 1 minute. Wait 1 minute and then explicitly
745 request that expired stamps be purged:
746
747 =item C<hashcash -p now>
748
749 Then try resubmitting the same stamp:
750
751 =item C<hashcash -cd -e 1m -b 10 -r foo E<lt> stamp>
752
753 and the stamp will be rejected anyway as it has expired, illustrating
754 why it was not necessary to keep this stamp in the database.
755
756 With the default database (the sdb format) the database contents are
757 human readable, so you can view their contents by cating them to the
758 terminal:
759
760 =item C<cat hashcash.sdb>
761
762 to see that the stamp really is added and then after puring
763 subsequently purged due to expiry.
764
765 =back
766
767 =head2 Purging old stamps on Demand
768
769 As a convenience you can purge at the same time as checking stamps by
770 using the I<-p> option with the I<-c> option.
771
772 =over 4
773
774 =item C<hashcash -m -b 10 foo E<gt> stamp>
775
776 =item C<hashcash -cd -p now -e 1 -b 10 -r foo E<lt> stamp>
777
778 It may be inefficient to purge stamps on every use as the entire
779 database has to be scanned for expired stamps. By giving a time
780 period to the I<-p> option, you can tell C<hashcash> to purge no more
781 frequently than that time period since the previous purge.
782
783 For example:
784
785 =item C<hashcash -cd -p 1d -e 1 -b 10 -r foo E<lt> stamp>
786
787 tells C<hashcash> to purge any expired stamps no more than once per
788 day.
789
790 =item C<hashcash -p 1M -j foo>
791
792 tells C<hashcash> to purge only expired stamps matching resource foo
793 once per month.
794
795 =item C<hashcash -p now -k>
796
797 tells C<hashcash> to purge all stamps (expired and unexpired) now.
798
799 =back
800
801 =head1 stamp format (version 1)
802
803 The current stamp format is version 1. This tool can verify hashcash
804 version 0 stamps also, but version 0 stamps are no longer created as
805 they are being phased out in favor of the more extensible v1 stamp
806 format.
807
808 =over 4
809
810 =item I<ver>:I<bits>:I<date>:I<resource>:[I<ext>]:I<rand>:I<counter>
811
812 =back
813
814 where
815
816 =over 4
817
818 =item I<ver> = 1
819
820 =item I<bits> = how many bits of partial-preimage the stamp is claimed to have
821
822 =item I<date> = YYMMDD[hhmm[ss]]
823
824 =item I<resource> = resource string (eg IP address, email address)
825
826 =item I<ext> = extension -- ignored in the current version
827
828 Format of extension:
829
830 =over 4
831
832 =item [name1[=val1[,val2...]];[name2[=val1[,val2...]]...]]
833
834 Note the value can also contain =. Example extension (not a real one):
835
836 name1=2,3;name2;name3=var1=2,var2=3,2,val
837
838 Which would be extension name1 has values 2 and 3; extension name2 has
839 no values; extension name3 has 3 values "var1=2", "var2=3", "2" and
840 "val". The hashcash extension may interpret the values as it sees fit
841 eg "var1=2" could be the value of an option to the extension name3.
842
843 =back
844
845 =item I<rand> = string of random characters from alphabet
846 a-zA-Z0-9+/= to avoid preimage with other sender's
847 stamps
848
849 =item I<counter> = to find a stamp with the desired number of
850 preimage bits need to try lots of different strings
851 this counter is incremented on each try.
852 The Counter is also composed of characters from the
853 alphabet a-zA-Z0-9+/=. (Note an implementation is
854 not required to count sequentially).
855
856 =back
857
858 =head1 FILES
859
860 =over 4
861
862 =item F<hashcash.sdb>
863
864 default double spend database
865
866 =back
867
868 =head1 EXIT STATUS
869
870 C<hashcash> returns success (exit code 0) after successfully minting a
871 stamp, after fully checking a stamp and finding it valid, and after a
872 timing test.
873
874 If when checking a stamp it is found to be invalid (due to being
875 malformed, being expired, having insufficient value, having a date in
876 the future, or being double spent), C<hashcash> returns failure (exit
877 code 1).
878
879 If insufficient options are given to fully check a stamp, if the stamp
880 is otherwise valid return unchecked (exit code 2). If the I<-y> flag
881 is given and hashcash would normally return unchecked, exit code
882 success is returned instead.
883
884 If any exception occurs (file read failure for database checking or
885 corrupted database contents) an exit status of 3 is returned.
886
887 =head1 AUTHOR
888
889 Written by Adam Back E<lt>[email protected]<gt>
890
891 =head1 SEE ALSO
892
•893 sha1sum(1), sha1(1), http://www.hashcash.org/