File: hashcash.pod

package info (click to toggle)
hashcash 1.21-2
  • links: PTS
  • area: main
  • in suites: bullseye, buster, stretch
  • size: 868 kB
  • ctags: 870
  • sloc: ansic: 8,476; perl: 925; sh: 298; makefile: 226; python: 41
file content (893 lines) | stat: -rw-r--r-- 32,392 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
=head1 NAME

hashcash - hashcash anti-spam / denial of service counter-measure tool

=head1 SYNOPSIS

=head2 Mint (create) stamps:

B<hashcash> I<-m> [ [ I<options> ] [ I<resource> ... ] ... ]

=head2 Check stamps:

B<hashcash> I<-c> [ [ I<options> ] I<-r resource> ... ] [ I<stamp> ... ] 

=head2 Speed estimates:

B<hashcash> I<-s> [ I<options> ] [ I<-b bits> ]

=head2 Purge database:

B<hashcash> I<-p now> [ I<-j resource> ] [ I<-k> ] [ I<-t time> ] [ I<-u> ]

=head2 Count collision bits:

B<hashcash> I<-w> [ I<options> ] [ I<stamp> ... ]

=head2 Get resource name:

B<hashcash> I<-n> [ I<options> ] [ I<stamp> ... ]

=head2 Get time remaining until expiry

B<hashcash> I<-l> [ I<options> ] I<-e period> [ I<stamp> ... ]

=head1 DESCRIPTION

Hashcash is a denial-of-service counter measure tool.  Its main
current use is to help hashcash users avoid losing email due to
content based and blacklist based anti-spam systems.

The hashcash tool allows you to create hashcash stamps to attach to
emails you send, and to verify hashcash stamps attached to emails you
receive.  Email senders attach hashcash stamps with the X-Hashcash:
header.  Vendors and authors of anti-spam tools are encouraged to
exempt mail sent with hashcash from their blacklists and content based
filtering rules.

A hashcash stamp constitutes a proof-of-work which takes a
parameterizable amount of work to compute for the sender.  The
recipient can verify received stamps efficiently.

The hashcash proof-of-work function is to compute partial hash
collisions (the SHA1 hash function is used).  By choosing the number
of bits of collision, the work required to compute a collision can be
made arbitrarily expensive -- from fractions of a second to minutes or
hours.  The verification is efficient requiring the same small cost
whatever the collision size.

For more detailed discussion of other applications hashcash has been
used for see http://www.hashcash.org/

=head1 USAGE NOTES

In this man page a resource name is the name of the service or address
the stamp is created for.  In the case of email, the resource name is
the recipient's email address in the form user@domain.com.

=head2 Minting stamps

The I<-m> flag must be given to mint a stamp.

The resource name (recipient's email address) to mint the stamp
against can be passed as an argument, or if omitted is read from
stdin.  If stdin is a tty the user is prompted, if stdin is a pipe the
resource name is just silently read.  The desired collision size can
be specified with the -b option.  If no collision size is specified,
the default is 20 bits.  See also the I<-b default> option.

=head2 Checking stamps

The I<-c> flag must be given to check a stamps expiry.  The stamp to
check can be given as an argument to C<hashcash>.  If no stamp is
given the stamp is read from stdin.  If stdin is a tty the user will
be prompted, if stdin is a pipe the stamp is just silently read.  A
resource name (the recipient's email address) can be given with the
I<-r> option.  If a resource name is given the resource name is
compared to the resource name in the stamp, if they do not match, the
stamp is rejected.

Note: if no resource name is given the stamp is anyway checked to see
if it is otherwise valid, but it could be minted for a different
resource, which would allow stamps to be reused across different
resources, so hashcash will return unchecked exit code on exit.

Stamps are by default considered to be valid for 28 days.  The validity
period can be changed using the I<-e> flag.

If the stamp has expired or has a date in the future the stamp is
rejected and the program exits immediately.

If a required collision size is given with the I<-b> flag, the stamps value
is computed and compared, if the stamp has insufficent value it is rejected,
and the program exits immediately.  If the I<-b> flag is not given, the
stamp is checked to see if it is otherwise valid, but hashcash will return
unchecked exit code on exit.

If the stamp is double spent the stamp is rejected.  Double spending
protection is discussed in more detail below in 
L<Double Spending Protection>.  If double spending protection is not
enabled, the stamp could be double spent, so hashcash will return
unchecked exit code (exit code 2) on exit.

The I<-w> flag can be used to request that the number of bits of the
collision are counted and displayed. The I<-n> flag can be used to
request that the resource name in the stamp is parsed out and
displayed.  The I<-l> flag can be used to request the number of
seconds until expiry of the stamp is output.

The program will only return exit codes valid or invalid if the I<-c>
flag is used, the I<-b> flag is used, I<-d>, I<-r resource> are used.
These are the minimum set of options necessary to fully check the
validty of a stamp.  If these criteria are not met, the program will
return exit code unchecked (exit code 2) on exit.  (See also the I<-y>
flag.)

=head2 Double Spending Protection

If the I<-d> flag is used when checking stamps, a database of spent
stamps is kept.

By default stamps expire after 28 days, without expiry the database
would grow indefinately.  You can specify an alternate expiry period
with the I<-e> flag.  The recommended (and default) expiry period for
email is 28 days.  After the expiry period amount of time, the stamp
is anyway considered expired and may be purged from the database to
save space.  (See L<Purging Periodically vs on Next Access> for how to
purge stamps.)

For efficiency reasons a stamp is verified before it is checked in the
database; if it is otherwise invalid no database activity will occur.

Note: The decision about how long the stamp should be considered valid
is up to the verifier.  If it is too short it is possible for some
applications that the stamp will expire before arriving at the
recipient (eg with email.)  The suggested value of 28 days should be
safe for normal email delivery delays.  The choice is a trade-off
between database size and risk of expiry prior to arrival, and depends
on the application.

Note: Different stamps in the same database can have different
validity periods, so for example stamps for different resources with
different validity periods can be stored in the same database, or the
recipient may change the validity period for future stamps without
affecting the validity of old stamps.

=head2 Purging Periodically vs on Next Access

To purge old stamps periodically while checking stamps use the I<-p
period> option to purge no sooner than the given time period since the
last purge.  Purging can be used with the I<-k> option to purge
unexpired stamps also, and with the I<-j resource> flag to purge only
stamps for the given resource.

There are circumstances where it may be inconvenient to purge stamps
on the next access, for example if there is a large double spend
database which takes some time to purge, and the response time of the
hashcash checker is important.  To avoid this problem, purging can be
done separately using just the I<-p now> option to request just the
purge operation.  On unix for example you could call C<hashcash -p
now> in a cron job once per day, or on demand when disk was running
low.

=head2 Speed Estimates

The I<-s> flag requests measurement of how many collisions can be
tested per second.  No stamp is minted, or verified.

If the I<-b> flag is used with this option, instead an estimate of how
many seconds it would take to mint a stamp of the given size in bits
is computed.  To find out how much time it will take to mint a default
sized stamp use I<-s -b default>.

=head2 Notes

All informational output is printed on stderr.  Minted stamps, and
results of stamp verification and timing are printed on stdout.  The
quiet flag I<-q> suppresses all informational output.  The I<-v> flag
requests more informational output.  The requested output, which is
the only information that is output in quiet mode (when I<-q> is
specified) is printed on standard output.  If stdout is a pipe, or
when quiet mode is in effect the output is printed without description
(ie just bits, just seconds, just resource).

=head1 OPTIONS

=over 4

=item I<-c>

Check the expiry information of stamps given as an argument or on
stdin.  (Use with I<-b>, I<-d> and I<-r resource> to fully check
stamps).

=item I<-m>

Mint stamps with the resources given as arguments or on stdin.

=item I<-b bits>

When minting a stamp, create a collision of at least this many bits.
When verifying a stamp require that it have a collision of at minimum
this many bits, otherwise reject it.  If omitted the default is used.

When checking stamps, require that the stamps have this many bits.

The default number of bits can be specified with I<-b default>.  Bits
relative to the default can also be specified with I<-b +n> for n bits
more than the default and I<-b -n> for n bits less than the default.

I<-b default>, I<-b +0> and I<-b -0> are all equivalent.

When doing the speed test I<-s>, can to measure speed of default
token with I<-s -b default>.

=item I<-r resource>

When minting stamps, the resource name (recipient's email address) to
mint the stamp against can be given either with I<-r resource> or as
an argument to C<hashcash>.

When checking stamps, the resource name (your own email address) is
given with the I<-r> option.  If the resource name is given it is
checked against the resource name in the stamp, and if they do not
match the stamp is rejected.  Note if the resource name is not given,
stamps for other resources would be accepted, and therefore hashcash
returns exit code unchecked (exit code 2) on exit.

=item I<-o>

When verifying stamps multiple resources can be given.  By default the
resources are just checked one by one until a matching valid resource is
found.  However when you use wildcards or regular expressions (see I<-E>),
it is useful to be able to specify that one resource overrides another.  For
example this: I<-b15 -r adam@dev.null -o -b10 *@dev.null> states that mail
to address I<adam@dev.null> requires 15 bits, but mail to I<*@dev.null>
requires only 10 bits.  If we omitted the I<-o> override relationship
between the two resources, a stamp of 10 bits would be accepted for address
I<adam@dev.null> because while it would be rejected as having insufficient
bits under the first rule, it would be accepted under the 2nd rule.  The
I<-o> option allows you avoid this problem.

=item I<-e time>

Expiry period for spent stamps.  While checking stamps (using the I<-c>
flag), if the stamp was minted more than the specified amount of time ago,
it is considered expired.  If this option is not used, by default stamps
expire after 28 days.  The expiry period is given in seconds by default (an
argument of 0 means forever).  A single character suffix can be used to
specify alternate units (m = minutes, h = hours, d = days, M = months, y = Y
= years, and s = seconds).

If used with the I<-d> option, the spent stamp and its expiry period
is recorded in the database.  See the I<-p> option for description of
how to purge stamps from the database.

While minting stamps, the I<-e> flag can have an effect on the
resolution of time created in the stamp.  Without the I<-e> option,
the default resolution is days (time format: YYMMDD).  Alternate
formats based on range of expiry period are as follows:

While minting you can also given an explicit time width with the I<-z>
option instead.  (I<-z> overrides I<-e> if both are given.  If neither
are given the default is 6 chars (time format: YYMMDD)).

The rules for automatically determining appropriate time width from
I<-e> if no I<-z> option is given are:

=over 8

=item * period E<gt>= 2 years then time format YY is used rounded down
to the nearest year start;

=item * 2 years E<lt> period E<lt>= 2 months then time format YYMM is
used rounded down to the nearest month start;

=item * 2 months E<lt> period E<lt>= 2 days then time format YYMMDD is
used rounded down to the begining of the nearest day;

=item * 2 days E<lt> period E<lt>= 2 minutes then time format
YYMMDDhhmm is used rounded down to the begining of the nearest minute;

=item * period E<lt> 2 minutes then time format YYMMDDhhmmss is used in
seconds.

=back

Note the rounding down is based on UTC time, not local time.  This can
lead to initially suprising results when rounding down to eg days in
time zones other than GMT (UTC = GMT).  It may be clearer to
understand if you use the I<-u> option.

=item I<-z width>

The I<-z> option is for use during minting and allows user choice of
width of time width field.  See also the I<-e> option given in
combination with I<-m> to specify an implicit time field width under
the description of the I<-e> flag.  Valid widths are 6,10 or 12 chars
corresponding respectively to: YYMMDD, YYMMDDhhmm, and YYMMDDhhmmss
rounded down to the nearest day, or minute respectively.

Note the rounding down is based on UTC time, not local time.  This can
lead to initially suprising results when rounding down to eg days in
time zones other than GMT (UTC = GMT).  It may be clearer to
understand if you use the I<-u> option.

=item I<-g period>

The I<-g> option is for use when checking hashcash stamps with the
I<-c> option and specifies a grace period for clock skew, ie if a
hashcash stamp arrives with a date in the future or in the past it
will not be rejected as having a futuristic date (or as being expired)
unless it is more futuristic (or has been expired for longer) than
this period.  The default is 2 days, which means as long as the
sending system's clock is no more than 2 days ahead (or 2 days behind)
of the receiving system's clock, the hashcash stamp will still be
accepted.

The default units for grace period are seconds.  A single character
suffix can be used to specify alternate units (m = minutes, h = hours,
d = days, M = months, y = Y = years, and s = seconds).

=item I<-d>

Store stamps in a double spend database.  If stamp has been seen
before it will be rejected even if it is otherwise valid.  The default
database file is F<database.sdb> in the current directory.  Only
otherwise valid stamps will be stored in the database.  Only fully
validated stamps will be stored in the database, unless the I<-y>
option is given.

=item I<-f dbname>

Use F<dbname> instead of default filename for double spend database.  

=item I<-p period>

Purges the database of expired stamps if the given time period has
passed since the last time it was purged.  As a convenience I<-p now>
is equivalent to I<-p 0> both of which mean purge now, regardless of
when the database was last purged.  

If used in combination with I<-j resource> only the stamps minted for
the given resource are purged.

If used in combination with I<-k> all stamps even un-expired stamps
are purged.  Can be used in combination with I<-t time> to expire as
if the current time were the given time.

=item I<-k>

Use with option I<-p> to request all stamps are purged rather than
just expired ones.

=item I<-j resource>

Use with option I<-p> to request that just stamps matching the given
resource name are to be purged, rather than the default which is to
purge all expired stamps.  If the resource name is the empty string,
all stamps are matched (this is equivalent to omitting the I<-j>
option).

Note the I<-E>, I<-M> and I<-S> type of match flags also apply to
resources given with the I<-j resource> flag.

=item I<-s>

Print timing information only, and don't proceed to create a stamp.
If combined with I<-b bits> flag print estimate of how long the
requested collision size would take to compute, if I<-s> given by
itself, just prints speed of the collision finder.  To print an
estimate of how long the default number of bits would take use I<-b
default>.

=item I<-h>

Print short usage information.

=item I<-v>

Print more verbose informational output about the stamp minting or
verification.  (If -v is the only argument, prints the tool version
number.)

=item I<-V>

Prints tool version number.

=item I<-q>

Batch mode.  Prints no information other than output.  This option
overrides the I<-v> option.

=item I<-X>

When minting, prints the hashcash email X-header 'X-Hashcash: ' before
the stamp.  Without this option just the bare stamp is printed.  

When checking, after scanning stamps given as arguments, scans stdin
for lines starting with the string 'X-Hashcash:', and uses the rest of
the matching line as the stamp.  Only the lines up to and ending at
the first blank line are scanned (see also I<-i> flag which can be
used to override this).  A blank line is the separator used to
separate the headers from the body of a mail message or USENET
article.  This is meant to make it convenient to pipe a mail message
or USENET article to hashcash on stdin.

=item I<-x extension>

An extension string composed of name value sets.  The extension format
is described below in the section on the hashcash stamp format.  This
allows users to define their own stamp extensions which are hashed
into the stamp, verified by recipients that support them, and ignored
by recipients that don't support them.  Note the extension hook
mechanism has not yet been implemented.  This will come in a
subsequent release.

=item I<-i>

When checking and using the I<-X> flag, ignore the blank line
boundary between headers and body of the message, and check for
collision in the body too if one is not found in the headers.

=item I<-t time>

Pretend the current time is the time given for purposes of minting
stamps, verifying stamps and purging old stamps from the database.
Time is given in a format based on UTCTIME format
YYMMDD[hhmm[ss]].

Time is expressed in local time by default.  Use with I<-u> flag to
give time in UTC (GMT).

You can also give time relative to the current time by prefixing the
argument with + or -.  The default units for relative time are
seconds.  A single character suffix can be used to specify alternate
units (m = minutes, h = hours, d = days, M = months, y = Y = years,
and s = seconds).

Note: when time is expressed in local time, if there is daylight
savings in your timezone, there are one or two ambiguous hours per
year at the time of change from daylight savings time to normal time.

=item I<-u>

Input and output absolute times in UTC (GMT) instead of local time.

=item I<-a period>

Add (or subtract if number is negative) a random value from the
current time before minting the stamp.  This hides the time the stamp
was created, which may be useful for anonymous users.  Note adding
(rather than subtracting) a random time may be risky if the stamp
takes less than the added time to arrive as the recipient will reject
stamps with time stamps in the future.

=item I<-n>

Print resource name parsed from stamp being verified.  Returns exit
code unchecked on exit.

=item I<-l>

Print number of seconds left before stamp expires.  Returns exit code
unchecked on exit.

Note: the calculation includes the grace period, so can be up to 2
times grace period longer than you might otherwise expect (clock fast
but system has to presume it could be slow).  If you want to exclude
the grace period add I<-g0> to set grace period to 0 for the
calculation.

=item I<-w>

Print number of bits of collision of stamp.  Returns exit code
unchecked on exit.

=item I<-y>

Returns success if the stamp is valid even if it is not fully checked.
Use with I<-c> where not all of I<-d>, I<-r> are specified to get
success exit code on valid but partially checked stamp.  Similarly can
use with I<-n>, I<-l>, I<-w> with same effect.

=item I<-M>

When checking stamps, allow wildcard I<*> matching in the resource
name to make it simpler to specify multiple email addresses and to
allow matching catch-all addresses and addresses including subdomains.
This is the default.  See also I<-S>, I<-E> and I<-C>

=item I<-S>

When checking stamps use simple text compare to compare resource names
to those in stamps.  See also I<-M>, I<-E> and I<-C>.

=item I<-E>

When checking stamps use regular expressions to specify resource names
to make it simpler to specify multiple email addresses, catch-all
addresses, classes of extension addresses and addresses including
subdomains.  Note regular expression syntax is POSIX style: special
characters do not need to be quoted to have their special meaning; but
they do have to be quoted with \ to that character in the searched
string.  The regular expression automatically has ^ added at the
beginning and $ added at the end, if they are not specified.  The
special characters ^ matches the beginning of the resouce, and $
matches the end of resource.

(Note even if compiled with BSD regular expressions, POSIX style
syntax is used; also note BSD regular expressions do not support
ranges {}.)

=item I<-C>

By default resources are canonicalized to lower case on minting and on
checking.  The I<-C> flag overrides this so that resources are treated
as case sensitive on checking, and not canonizalized on minting.

=item I<-P>

Print progress info (number of iterations, expected iterations,
percentage done, best stamp size found so far). 

=item I<-O core>

Select hashcash core with that number.  Currently 0-9 are valid cores.
Not all cores work on all architectures.  Eg some are x86 specific
assembler, others PPC specific assembler.  If a core is not valid
hashcash returns failure and explains what happened.

=item I<-Z n>

Compress the stamp.  This is a time vs space trade off.  Larger stamps
are faster, but arguably slightly ugly.  For fastest stamps (the
default) use -Z 0; for partly compressed stamps use -Z 1; for very
compressed, but somewhat slow stamps use -Z 2.  (Note: due to a late
discovered bug, -Z2 is the same as -Z1 for now until I can fix that.)

=back

=head1 EXAMPLES

=head2 Creating stamps

=over 4

=item C<hashcash -s>

Print timing information about how many collisions the machine can try
per second.

=item C<hashcash -sv>

More accurate but quite slow benchmarking of different processor
specific minting cores.

=item C<hashcash -s -b default>

Print how long it would take the machine to compute a default sized
collision (but don't actually compute a collision).

=item C<hashcash -s -b 32>

Print how long it would take the machine to compute a 32 bit collision
(but don't actually compute a collision).

=item C<hashcash -m>

Mint a stamp.  Will prompt for resource name and mint with default
value (number of collision bits).

=item C<hashcash -m foo>

Compute collision on resource foo.  Will mint with default value
(number of collision bits).

=item C<hashcash -m foo -b 10>

Compute 10 bit collision on resource foo.

=item C<hashcash -a -3d>

Subtract a random time of between 0 days and 3 days from the stamp's
creation time.  This is the same fuzz factor used by mixmaster to
reduce risk of timing-correlations.

=back

=head2 Examining Stamps

=over 4

=item C<hashcash -w 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Report the value of the stamp (how many bits of collision) there are.
The example is a 24 bit collision, which takes on average 25 seconds
to create on a 3Ghz P4.

=item C<hashcash -mq -b 10 foo | hashcash -w>

Create a stamp in batch mode, pass to hashcash on stdin to verify,
have it print how many bits there were.

=item C<hashcash -n 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Report the resource name from the stamp.  The resource name in the
example is foo.

=item C<hashcash -l -e 30y 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Report how long until the stamp expires if it expires in 30 years from
its creation date.  (Note dates too far into the future run into the
2038 end of Epoch, which is the unix time analog of the y2k bug).

=back

=head2 Verifying Stamps

=over 4 

=item C<hashcash -c 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Check if the stamp is valid.  Note as we are not checking the stamp in
a double spend database, and did not specify a resource name or
required number of bits of collision and hashcash will consider the
stamp not fully checked, and it will report it as valid but not fully
unchecked, or as invalid if there is any problem with the stamp.

=item C<hashcash -c -b24 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Check that the value of the stamp is greater or equal to 24 bits.
This example has 24 bit value.  If you increase the requested number
of bits or replace the stamp with one with less than 24 bit collision
the stamp will be rejected.

=item C<hashcash -c -b24 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>

As above check if the stamp has sufficient value, but in addition
check that the resource name given matches the resource name in the
stamp.

=back

=head2 Double Spending Prevention

The examples given in L<Verifying Stamps> can be modified to keep a
double spend database so that the same stamp will not be accepted
twice.  Note a stamp will only be checked in and added to the database
if it is otherwise valid and fully checked (a required number of bits
of collision has been specified and a resource has been specified).

=over 4

=item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Check the stamp and add to double spent database if it's valid (has
correct resource name and sufficient value).

=item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Try to double spend the stamp.  It will be rejected as double spent.

=back

=head2 Stamp Expiry

To prevent the double spend database growing indefinately, the
recipient can request that stamps be no older than a specified period.
After expiry old stamps can dropped from the double spend database as
they will no longer be needed -- expired stamps can be rejected based
purely on their old date, so the space taken by expired stamps in the
double spend database can be saved without risk of accepting an
expired though otherwise valid stamp.

The third field of the stamp is the UTC time since 1st January 1970.
The default time format is YYMMDD, time rounded down to the nearest
day.  The default validity period is 28 days.

You can provide an alternative validity period with the I<-e> option.

=over 4

=item C<hashcash -cd -b 10 -e 2d -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Try verifying an old stamp, the above stamp was created 11 Aug 2002.

We gave option I<-e 2d> so the stamps expiry date is 2 days after
creation, which is now in the past.

Note: if the creation time is expressed in the stamp in days, the
precise creation date is the begining of the specified day in UTC time
(similarly for alternate units the creation time is rounded down to
the begining of the unit it is expressed in).  For units in days, for
example, this may mean depending on your time zone that the stamp
appears to be considered invalid in under the specified expiry period
in days relative to your relative view of what day it is, as the
calculation is based on current time in UTC, and the creation time of
the stamp is expressed in UTC time.

=item C<hashcash -cd -b 10 -r foo 1:24:040806:foo::511801694b4cd6b0:1e7297a>

Test whether the stamp is otherwise valid, apart from having expired.
Omitting the I<-e> tells hashcash that the stamp will never expire.
An expiry period of forever can also be given explitly like this: I<-e
0>, where an expiry period of 0 means forever.

=back

=head2 Purging old stamps

If the I<-c>, I<-d> options are used together, each time a stamp is
checked, if it is valid and all of the mandatory aspects of the stamp
are verified (collision bits check, resource name check) then the
stamp and its expiry period is written to the database file.  The
default expiry period if an expiry period is not given explicitly with
the I<-e> option is 28 days (ie stamps expire after 4 weeks).

First mint and then add a stamp:

=over 4

=item C<hashcash -m -b 10 foo -e 1m E<gt> stamp>

Note: we specified an expiry on minting in this example, to ensure
that the stamp creation time is given in high enough resolution in the
stamp that the stamp will not be considered expired at time of
creation.  (Recall the default resolution is in days, a stamp created
with a creation time rounded down to the beginging of the day is
unlikely to be considered valid 1 minute later unless you mint it at
midnight UTC time.)

=item C<hashcash -cd -e 1m -b 10 -r foo E<lt> stamp>

The stamp expires in 1 minute.  Wait 1 minute and then explicitly
request that expired stamps be purged:

=item C<hashcash -p now>

Then try resubmitting the same stamp:

=item C<hashcash -cd -e 1m -b 10 -r foo E<lt> stamp>

and the stamp will be rejected anyway as it has expired, illustrating
why it was not necessary to keep this stamp in the database.

With the default database (the sdb format) the database contents are
human readable, so you can view their contents by cating them to the
terminal:

=item C<cat hashcash.sdb>

to see that the stamp really is added and then after puring
subsequently purged due to expiry.

=back

=head2 Purging old stamps on Demand

As a convenience you can purge at the same time as checking stamps by
using the I<-p> option with the I<-c> option.

=over 4

=item C<hashcash -m -b 10 foo E<gt> stamp>

=item C<hashcash -cd -p now -e 1 -b 10 -r foo E<lt> stamp>

It may be inefficient to purge stamps on every use as the entire
database has to be scanned for expired stamps.  By giving a time
period to the I<-p> option, you can tell C<hashcash> to purge no more
frequently than that time period since the previous purge.

For example:

=item C<hashcash -cd -p 1d -e 1 -b 10 -r foo E<lt> stamp>

tells C<hashcash> to purge any expired stamps no more than once per
day.

=item C<hashcash -p 1M -j foo>

tells C<hashcash> to purge only expired stamps matching resource foo
once per month.

=item C<hashcash -p now -k>

tells C<hashcash> to purge all stamps (expired and unexpired) now.

=back

=head1 stamp format (version 1)

The current stamp format is version 1.  This tool can verify hashcash
version 0 stamps also, but version 0 stamps are no longer created as
they are being phased out in favor of the more extensible v1 stamp
format.

=over 4

=item I<ver>:I<bits>:I<date>:I<resource>:[I<ext>]:I<rand>:I<counter>

=back

where 

=over 4

=item I<ver> = 1

=item I<bits> = how many bits of partial-collision the stamp is claimed to have

=item I<date> = YYMMDD[hhmm[ss]]

=item I<resource> = resource string (eg IP address, email address)

=item I<ext> = extension -- ignored in the current version

Format of extension:

=over 4

=item [name1[=val1[,val2...]];[name2[=val1[,val2...]]...]]

Note the value can also contain =.  Example extension (not a real one):

	name1=2,3;name2;name3=var1=2,var2=3,2,val

Which would be extension name1 has values 2 and 3; extension name2 has
no values; extension name3 has 3 values "var1=2", "var2=3", "2" and
"val".  The hashcash extension may interpret the values as it sees fit
eg "var1=2" could be the value of an option to the extension name3.

=back

=item I<rand> = string of random characters from alphabet
		a-zA-Z0-9+/= to avoid collisions with other sender's
		stamps

=item I<counter> = to find a stamp with the desired number of
		   collision bits need to try lots of different strings
                   this counter is incremented on each try.  
		   The Counter is also composed of characters from the
		   alphabet a-zA-Z0-9+/=.  (Note an implementation is
		   not required to count sequentially).

=back

=head1 FILES

=over 4

=item F<hashcash.sdb>

default double spend database

=back

=head1 EXIT STATUS

C<hashcash> returns success (exit code 0) after successfully minting a
stamp, after fully checking a stamp and finding it valid, and after a
timing test.

If when checking a stamp it is found to be invalid (due to being
malformed, being expired, having insufficient value, having a date in
the future, or being double spent), C<hashcash> returns failure (exit
code 1).

If insufficient options are given to fully check a stamp, if the stamp
is otherwise valid return unchecked (exit code 2).  If the I<-y> flag
is given and hashcash would normally return unchecked, exit code
success is returned instead.

If any exception occurs (file read failure for database checking or
corrupted database contents) an exit status of 3 is returned.

=head1 AUTHOR

Written by Adam Back E<lt>adam@cypherspace.orgE<gt>

=head1 SEE ALSO

sha1sum(1), sha1(1), http://www.hashcash.org/