| 1 |
/* -*- Mode: C; c-file-style: "stroustrup" -*- */cxx . . $ `<file>/hashcash.c`/ |
| 2 |
|
| 3 |
/* hashcash mint and verification |
| 4 |
* |
| 5 |
* hashcash is payment in burnt CPU cycles by calculating n-bit |
| 6 |
* partial hash preimages of the all 0 string |
| 7 |
* |
| 8 |
* see: http://www.hashcash.org/ |
| 9 |
* |
| 10 |
*/ |
| 11 |
|
| 12 |
#if defined( THINK_C ) |
| 13 |
#include <console.h> |
| 14 |
#include <unix.h> |
| 15 |
#elif defined( unixcxx . . $ `<built-in>:395:9`! ) || defined( VMS ) || defined( __APPLE__ ) |
| 16 |
#include <unistd.h> |
| 17 |
#elif defined ( WIN32 ) |
| 18 |
#include <io.h> |
| 19 |
#endif |
| 20 |
|
| 21 |
#include <stdio.h> |
| 22 |
#include <stdlib.h> |
| 23 |
#include <string.h> |
| 24 |
#include <ctype.h> |
| 25 |
#include <time.h> |
| 26 |
#include <errno.h> |
| 27 |
#include <assert.h> |
| 28 |
#include <math.h> |
| 29 |
|
| 30 |
#include "sdb.h"cxx . . $ `<file>/sdb.h`/ |
| 31 |
#include "utct.h"cxx . . $ `<file>/utct.h`/ |
| 32 |
#include "random.h"cxx . . $ `<file>/random.h`/ |
| 33 |
#include "hashcash.h"cxx . . $ `<file>/hashcash.h`/ |
| 34 |
#include "libfastmint.h"cxx . . $ `<file>/libfastmint.h`/ |
| 35 |
#include "sstring.h"cxx . . $ `<file>/sstring.h`/ |
| •36 |
#include <getopt.h> |
| 37 |
|
| 38 |
#if defined( OPENSSL ) |
| 39 |
#include <openssl/sha.h> |
| 40 |
#define SHA1_ctx SHA_CTX |
| 41 |
#define SHA1_Final( x, digest ) SHA1_Final( digest, x ) |
| 42 |
#define SHA1_DIGEST_BYTES SHA_DIGEST_LENGTH |
| 43 |
#else |
| 44 |
#include "sha1.h"cxx . . $ `<file>/sha1.h`/ |
| 45 |
#endif |
| 46 |
|
| 47 |
#define EOKcxx . . $ `hashcash.c:47:9`! 0 /* no error */ |
| 48 |
#define EINPUTcxx . . $ `hashcash.c:48:9`! -1 /* error invalid input */ |
| 49 |
|
| 50 |
#define EXIT_UNCHECKEDcxx . . $ `hashcash.c:50:9`! 2 /* don't consider the token valid because */ |
| 51 |
/* there are aspects of the token that */ |
| 52 |
/* were not checked */ |
| 53 |
#define EXIT_ERRORcxx . . $ `hashcash.c:53:9`! 3 |
| 54 |
|
| 55 |
#define MAX_PERIODcxx . . $ `hashcash.c:55:9`! 11 /* max time_t = 10 plus 's' */ |
| 56 |
#define MAX_HDRcxx . . $ `hashcash.c:56:9`! 256 |
| 57 |
#define MAX_LINEcxx . . $ `hashcash.c:57:9`! 1024+MAX_EXTcxx . . $ `hashcash.h:44:9`!+1 |
| 58 |
|
| 59 |
/* WARNING: the *PRINTF macros assume a coding style which always uses |
| 60 |
* braces {} around conditional code -- unfortunately there is no |
| 61 |
* portable way to do vararg macros or functions which call other |
| 62 |
* vararg functions |
| 63 |
*/ |
| 64 |
|
| 65 |
#define QQEcxx . . $ `hashcash.c:65:9`! (!quiet_flag) |
| 66 |
#define PPEcxx . . $ `hashcash.c:66:9`! (!out_is_tty||quiet_flag) |
| 67 |
#define VVEcxx . . $ `hashcash.c:67:9`! (verbose_flag) |
| 68 |
|
| 69 |
#define QQcxx . . $ `hashcash.c:69:9`! if (QQEcxx . . $ `hashcash.c:65:9`!) |
| 70 |
#define PPcxx . . $ `hashcash.c:70:9`! if (PPEcxx . . $ `hashcash.c:66:9`!) |
| 71 |
#define VVcxx . . $ `hashcash.c:71:9`! if (VVEcxx . . $ `hashcash.c:67:9`!) |
| 72 |
#define QPRINTFcxx . . $ `hashcash.c:72:9`! QQcxx . . $ `hashcash.c:69:9`! fprintf |
| 73 |
#define PPRINTFcxx . . $ `hashcash.c:73:9`! PPcxx . . $ `hashcash.c:70:9`! fprintf |
| 74 |
#define VPRINTFcxx . . $ `hashcash.c:74:9`! VVcxx . . $ `hashcash.c:71:9`! fprintf |
| 75 |
|
| 76 |
#define QPUTScxx . . $ `hashcash.c:76:9`!(f,str) QQcxx . . $ `hashcash.c:69:9`! { fputs(str,f); } |
| 77 |
#define PPUTScxx . . $ `hashcash.c:77:9`!(f,str) PPcxx . . $ `hashcash.c:70:9`! { fputs(str,f); } |
| 78 |
#define VPUTScxx . . $ `hashcash.c:78:9`!(f,str) VVcxx . . $ `hashcash.c:71:9`! { fputs(str,f); } |
| 79 |
|
| 80 |
#define HDR_LINE_LENcxx . . $ `hashcash.c:80:9`! 80 |
| 81 |
char *read_headercxx . . $ read_header(a66d455f0d9c8a09).( FILEcxx . . $ FILE#* f, char** s, int* slen, int* alloc, |
| 82 |
char* a, int alen ); |
| 83 |
int read_eofcxx . . $ read_eof(9f4384670e65005f).( FILEcxx . . $ FILE#* fp, char* a ); |
| 84 |
void chomplfcxx . . $ chomplf(fda57c8427c60377).( char* token ); |
| 85 |
void trimspacecxx . . $ trimspace(fda57c8427c60377).( char* token ); |
| 86 |
void diecxx . . $ die(d4f767463ce0a6b3).( int err ); |
| 87 |
void die_msgcxx . . $ die_msg(85c52e162fed56f9).( const char* ); |
| 88 |
void usagecxx . . $ usage(85c52e162fed56f9).( const char* ); |
| 89 |
int parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( const char* aperiod, long* resp ); |
| 90 |
double report_speedcxx . . $ report_speed(73d891ffc41e4d2c).( int bits, double* time_est, int display ); |
| 91 |
|
| 92 |
#if defined( WIN32 ) |
| 93 |
#define LINEFEED "\r\n" |
| 94 |
#else |
| 95 |
#define LINEFEEDcxx . . $ `hashcash.c:95:9`! "\n" |
| 96 |
#endif |
| 97 |
|
| 98 |
/* avoid needing to export stolower from hashcash.dll */ |
| 99 |
|
| 100 |
void mystolowercxx . . $ mystolower(fda57c8427c60377).( char* str ); |
| 101 |
#define stolowercxx . . $ `hashcash.c:101:9`! mystolower |
| 102 |
|
| 103 |
typedef structcxx . . $ $anonymous_type_aa62bfaa706685ea_0# { |
| 104 |
char* strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str.; |
| 105 |
void* regexpcxx . . $ $anonymous_type_aa62bfaa706685ea_0#regexp.; /* compiled regexp */ |
| 106 |
int typecxx . . $ $anonymous_type_aa62bfaa706685ea_0#type.; |
| 107 |
int case_flagcxx . . $ $anonymous_type_aa62bfaa706685ea_0#case_flag.; |
| 108 |
long validitycxx . . $ $anonymous_type_aa62bfaa706685ea_0#validity.; |
| 109 |
long gracecxx . . $ $anonymous_type_aa62bfaa706685ea_0#grace.; |
| 110 |
long anoncxx . . $ $anonymous_type_aa62bfaa706685ea_0#anon.; |
| 111 |
int widthcxx . . $ $anonymous_type_aa62bfaa706685ea_0#width.; |
| 112 |
int bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits.; |
| 113 |
int overcxx . . $ $anonymous_type_aa62bfaa706685ea_0#over.; |
| 114 |
} ELEMENTcxx . . $ ELEMENT#; |
| 115 |
|
| 116 |
typedef structcxx . . $ $anonymous_type_aa62bfaa706685ea_1# { |
| 117 |
int numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.; |
| 118 |
int maxcxx . . $ $anonymous_type_aa62bfaa706685ea_1#max.; |
| 119 |
ELEMENTcxx . . $ ELEMENT#* eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.; |
| 120 |
} ARRAYcxx . . $ ARRAY#; |
| 121 |
|
| 122 |
void db_opencxx . . $ db_open(5c57a783a5f80a21).( DBcxx . . $ DB#* db, const char* db_filename ); |
| 123 |
void db_purge_arrcxx . . $ db_purge_arr(b34afceb658d5cc2).( DBcxx . . $ DB#* db, ARRAYcxx . . $ ARRAY#* purge_resource, int purge_all, |
| 124 |
long purge_period, time_tcxx . . $ time_t# now_time, long validity_period, |
| 125 |
long grace_period ); |
| 126 |
int db_purgecxx . . $ db_purge(4a5ef610074b5647).( DBcxx . . $ DB#* db, ARRAYcxx . . $ ARRAY#* purge_resource, int purge_all, |
| 127 |
long purge_period, time_tcxx . . $ time_t# now_time, long validity_period, |
| 128 |
long grace_period, int verbose, int* err ); |
| 129 |
int db_incxx . . $ db_in(237208b940db5468).( DBcxx . . $ DB#* db, char* token, char *period ); |
| 130 |
void db_addcxx . . $ db_add(18d537d5cf8b8e63).( DBcxx . . $ DB#* db, char* token, char *token_utime ); |
| 131 |
void db_closecxx . . $ db_close(14613a252c7791ed).( DBcxx . . $ DB#* db ) ; |
| 132 |
|
| 133 |
void array_alloccxx . . $ array_alloc(f36c4182aaae5413).( ARRAYcxx . . $ ARRAY#* array, int num ); |
| 134 |
void array_pushcxx . . $ array_push(1afc9a320aea9297).( ARRAYcxx . . $ ARRAY#* array, const char *str, int type, int case_flag, |
| 135 |
long validity, long grace, long anon, int width, int bits, |
| 136 |
int over ); |
| 137 |
#define array_numcxx . . $ `hashcash.c:137:9`!( a ) ( (a)->num ) |
| 138 |
int bit_cmpcxx . . $ bit_cmp(9148c8c3ff42c9d8).( const void* ap, const void* bp ); |
| 139 |
void array_sortcxx . . $ array_sort(1a42aa0a13f60ad8).( ARRAYcxx . . $ ARRAY#* array, int(*cmp)(const void*, const void*) ); |
| 140 |
|
| 141 |
|
| 142 |
#define hc_est_timecxx . . $ `hashcash.c:142:9`!(b) ( hashcash_expected_tries(b) / \ |
| 143 |
(double)hashcash_per_sec() ) |
| 144 |
int quiet_flagcxx . . $ quiet_flag.; |
| 145 |
int verbose_flagcxx . . $ verbose_flag.; |
| 146 |
int out_is_ttycxx . . $ out_is_tty.; |
| 147 |
int in_is_ttycxx . . $ in_is_tty.; |
| 148 |
|
| 149 |
#define PROGRESS_FMTcxx . . $ `hashcash.c:149:9`! "percent: %%.0lf/%%.0lf = %%.%dlf%%%% [%%d/%%d bits]%%c" |
| 150 |
char progress_formatcxx . . $ progress_format.[80] = { 0 }; |
| 151 |
|
| 152 |
int progress_callbackcxx . . $ progress_callback(69b8e4266e776973).(int percent, int largest, int target, |
| 153 |
double counter, double expected, void* user); |
| 154 |
|
| 155 |
#define PURGED_KEYcxx . . $ `hashcash.c:155:9`! "last_purged" |
| 156 |
|
| 157 |
int maincxx . . $ main(afcd3168fc1188a4).( int argc, char* argv[] ) |
| 158 |
{ |
| 159 |
long validity_period = 28*TIME_DAYcxx . . $ `hashcash.h:49:9`!; /* default validity period: 28 days */ |
| 160 |
long purge_validity_period = 28*TIME_DAYcxx . . $ `hashcash.h:49:9`!; /* same default */ |
| 161 |
long grace_period = 2*TIME_DAYcxx . . $ `hashcash.h:49:9`!; /* default grace period: 2 days */ |
| 162 |
|
| 163 |
char period[ MAX_PERIODcxx . . $ `hashcash.c:55:9`!+1 ], utcttime[ MAX_UTCcxx . . $ `hashcash.h:339:9`!+1 ]; |
| 164 |
const char* db_filename = "hashcash.sdb"; |
| 165 |
int boundary, err, anon_flag = 0, over_flag = 0, grace_flag = 0; |
| 166 |
long anon_period = 0, anon_random = 0 ; |
| 167 |
int default_bits = 20; /* default 20 bits */ |
| 168 |
int count_bits, claimed_bits = 0, bits = 0; |
| 169 |
int check_flag = 0, case_flag = 0, hdr_flag = 0; |
| 170 |
int width_flag = 0, left_flag = 0, speed_flag = 0, utc_flag = 0; |
| 171 |
int bits_flag = 0, str_type = TYPE_WILDcxx . . $ `hashcash.h:36:9`!; /* default to wildcard match */ |
| 172 |
int validity_flag = 0, db_flag = 0, yes_flag = 0, purge_flag = 0; |
| 173 |
int mint_flag = 0, ignore_boundary_flag = 0, name_flag = 0, res_flag = 0; |
| 174 |
int auto_version = 0, version_flag = 0, checked = 0, comma = 0; |
| 175 |
char header[ MAX_HDRcxx . . $ `hashcash.c:56:9`!+1 ] = { 0 }; |
| 176 |
char header2[ MAX_HDRcxx . . $ `hashcash.c:56:9`!+1 ] = { 0 }; |
| 177 |
char* header_wrapped = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 178 |
int hdr_len, hdr2_len, token_found = 0, token2_found = 0, hdrs_found = 0; |
| 179 |
char token[ MAX_TOKcxx . . $ `hashcash.h:45:9`!+1 ] = { 0 }, token_resource[ MAX_REScxx . . $ `hashcash.h:41:9`!+1 ] = { 0 }; |
| 180 |
char *new_token = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ; |
| 181 |
char line_arr[ MAX_LINEcxx . . $ `hashcash.c:57:9`!+1 ] = { 0 }, *line = line_arr; |
| 182 |
int line_max = MAX_LINEcxx . . $ `hashcash.c:57:9`!, line_alloc = 0; |
| 183 |
char ahead[ MAX_LINEcxx . . $ `hashcash.c:57:9`!+1 ] = { 0 } , *ext = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, *junk = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 184 |
ARRAYcxx . . $ ARRAY# purge_resource, resource, tokens, args; |
| 185 |
|
| 186 |
clock_tcxx . . $ clock_t# start = 0, end = 0, tmp = 0; |
| 187 |
|
| 188 |
long purge_period = 0, valid_for = HASHCASH_INVALIDcxx . . $ `hashcash.h:70:9`!, time_period = 0 ; |
| 189 |
int purge_all = 0; |
| 190 |
int multiple_validity = 0, multiple_bits = 0, multiple_resources = 0; |
| 191 |
int multiple_grace = 0, accept = 0, parsed = 0; |
| 192 |
|
| 193 |
char token_utime[ MAX_UTCcxx . . $ `hashcash.h:339:9`!+1 ] = { 0 } ; /* time token created */ |
| 194 |
time_tcxx . . $ time_t# real_time = timecxx . . $ time(7f38134db6521d23).(0); /* now, in UTCTIME */ |
| 195 |
time_tcxx . . $ time_t# now_time = real_time; |
| 196 |
time_tcxx . . $ time_t# token_time = 0, expiry_time = 0; |
| 197 |
int time_width_flag = 0; /* -z option, default 6 YYMMDD */ |
| 198 |
int compress = 0; /* fast by default */ |
| 199 |
int inferred_time_width = 0, time_width = 6; /* default YYMMDD */ |
| 200 |
int core = 0, res = 0, core_flag = 0; |
| 201 |
|
| 202 |
double tries_taken = 0, taken = 0, tries_expected = 0, time_est = 0; |
| 203 |
int opt = 0, vers = 0, db_opened = 0, i = 0, j = 0, t = 0, tty_info = 0; |
| 204 |
int in_headers = 0, skip = 0, over = 0, precision = 0; |
| 205 |
char *re_err = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 206 |
ELEMENTcxx . . $ ELEMENT#* ent = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 207 |
DBcxx . . $ DB# db; |
| 208 |
hashcash_callbackcxx . . $ hashcash_callback# callback = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 209 |
|
| 210 |
#if defined( THINK_C ) |
| 211 |
argc = ccommand(&argv); |
| 212 |
#endif |
| 213 |
|
| 214 |
out_is_ttycxx . . $ out_is_tty. = isattycxx . . $ isatty(7864480464b09eea).( filenocxx . . $ fileno(89bc1efcdac0ca22).( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`! ) ); |
| 215 |
in_is_ttycxx . . $ in_is_tty. = isattycxx . . $ isatty(7864480464b09eea).( filenocxx . . $ fileno(89bc1efcdac0ca22).( stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`! ) ) && !feofcxx . . $ feof(89bc1efcdac0ca22).( stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`! ); |
| 216 |
quiet_flagcxx . . $ quiet_flag. = 0; |
| 217 |
verbose_flagcxx . . $ verbose_flag. = 0; |
| 218 |
|
| 219 |
token_resource[0] = '\0'; |
| 220 |
token[0] = '\0'; |
| 221 |
opterrcxx . . $ opterr. = 0; |
| 222 |
|
| 223 |
array_alloccxx . . $ array_alloc(f36c4182aaae5413).( &resource, 32 ); |
| 224 |
array_alloccxx . . $ array_alloc(f36c4182aaae5413).( &purge_resource, 32 ); |
| 225 |
array_alloccxx . . $ array_alloc(f36c4182aaae5413).( &tokens, 32 ); |
| 226 |
array_alloccxx . . $ array_alloc(f36c4182aaae5413).( &args, 32 ); |
| 227 |
|
| 228 |
while ( (opt=getoptcxx . . $ getopt(2483c31ff9bab884).(argc, argv, |
| 229 |
"-a:b:cde:f:g:hij:klmnop:qr:st:uvwx:yz:CEMO:PSVXZ:")) >0 ) { |
| 230 |
switch ( opt ) { |
| 231 |
case 'a': anon_flag = 1; |
| 232 |
if ( !parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( optargcxx . . $ optarg., &anon_period ) ) { |
| 233 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -a invalid period arg" ); |
| 234 |
} |
| 235 |
break; |
| 236 |
case 'b': |
| 237 |
if ( bits_flag ) { multiple_bits = 1; } |
| 238 |
bits_flag = 1; |
| 239 |
|
| 240 |
if ( strcmpcxx . . $ strcmp(5ae29d726ae57f88).( optargcxx . . $ optarg., "default" ) == 0 ) { |
| 241 |
bits = default_bits; |
| 242 |
} else if ( optargcxx . . $ optarg.[0] == '-' || optargcxx . . $ optarg.[0] == '+' ) { |
| 243 |
bits = atoicxx . . $ atoi(5c4306d8553b3696).( optargcxx . . $ optarg.+1 ); |
| 244 |
if ( bits < 0 ) { usagecxx . . $ usage(85c52e162fed56f9).( "error: -b invalid bits arg" ); } |
| 245 |
if ( optargcxx . . $ optarg.[0] == '-' ) { bits = -bits; } |
| 246 |
bits = default_bits + bits; |
| 247 |
if ( bits < 0 ) { bits = 0; } |
| 248 |
} else { /* absolute */ |
| 249 |
bits = atoicxx . . $ atoi(5c4306d8553b3696).( optargcxx . . $ optarg. ); |
| 250 |
if ( bits < 0 ) { usagecxx . . $ usage(85c52e162fed56f9).( "error: -b invalid bits arg" ); } |
| 251 |
} |
| 252 |
if ( bits > SHA1_DIGEST_BYTEScxx . . $ `sha1.h:17:9`! * 8 ) { |
| 253 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: max preimage with sha1 is 160 bits" ); |
| 254 |
} |
| 255 |
break; |
| 256 |
case 'C': case_flag = 1; break; |
| 257 |
case 'c': check_flag = 1; break; |
| 258 |
case 'd': db_flag = 1; break; |
| 259 |
case 'e': |
| 260 |
if ( validity_flag ) { multiple_validity = 1; } |
| 261 |
validity_flag = 1; |
| 262 |
if ( !parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( optargcxx . . $ optarg., &validity_period ) || |
| 263 |
validity_period < 0 ) { |
| 264 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -e invalid validity period" ); |
| 265 |
} |
| 266 |
break; |
| 267 |
case 'E': str_type = TYPE_REGEXPcxx . . $ `hashcash.h:37:9`!; break; |
| 268 |
case 'f': db_filename = strdupcxx . . $ strdup(a8b8e32347182212).( optargcxx . . $ optarg. ); break; |
| 269 |
case 'g': |
| 270 |
if ( grace_flag ) { multiple_grace = 1; } |
| 271 |
grace_flag = 1; |
| 272 |
if ( optargcxx . . $ optarg.[0] == '-' ) { |
| 273 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -g -ve grace period not valid" ); |
| 274 |
} |
| 275 |
if ( !parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( optargcxx . . $ optarg., &grace_period ) ) { |
| 276 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -g invalid grace period format" ); |
| 277 |
} |
| 278 |
break; |
| 279 |
case 'h': usagecxx . . $ usage(85c52e162fed56f9).( "" ); break; |
| 280 |
case 'i': ignore_boundary_flag = 1; break; |
| 281 |
case 'j': |
| 282 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( &purge_resource, optargcxx . . $ optarg., str_type, case_flag, |
| 283 |
0, 0, 0, 0, 0, 0 ); |
| 284 |
over_flag = 0; |
| 285 |
break; |
| 286 |
case 'k': purge_all = 1; break; |
| 287 |
case 'l': left_flag = 1; break; |
| 288 |
case 'n': name_flag = 1; break; |
| 289 |
case 'o': over_flag = 1; break; |
| 290 |
case 'O': |
| 291 |
core_flag = 1; |
| 292 |
core = atoicxx . . $ atoi(5c4306d8553b3696).( optargcxx . . $ optarg. ); |
| 293 |
res = hashcash_use_corecxx . . $ hashcash_use_core(7864480464b09eea).( core ); |
| 294 |
if ( res < 1 ) { |
| 295 |
usagecxx . . $ usage(85c52e162fed56f9).( res == -1 ? "error: -O no such core\n" : |
| 296 |
"error: -O core does not work on this platform" ); |
| 297 |
} |
| 298 |
break; |
| 299 |
case 'm': mint_flag = 1; |
| 300 |
if ( !bits_flag ) { |
| 301 |
bits_flag = 1; |
| 302 |
bits = default_bits; |
| 303 |
} |
| 304 |
break; |
| 305 |
case 'M': str_type = TYPE_WILDcxx . . $ `hashcash.h:36:9`!; break; |
| 306 |
case 'p': |
| 307 |
if ( purge_flag ) { usagecxx . . $ usage(85c52e162fed56f9).("error: only one -p flag per call"); } |
| 308 |
purge_flag = 1; |
| 309 |
if ( strcmpcxx . . $ strcmp(5ae29d726ae57f88).( optargcxx . . $ optarg., "now" ) == 0 ) { purge_period = 0; } |
| 310 |
else if ( !parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( optargcxx . . $ optarg., &purge_period ) || |
| 311 |
purge_period < 0 ) { |
| 312 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -p invalid purge interval" ); |
| 313 |
} |
| 314 |
purge_validity_period = validity_period; |
| 315 |
break; |
| 316 |
case 'P': callback = progress_callbackcxx . . $ progress_callback(69b8e4266e776973).; break; |
| 317 |
case 'q': quiet_flagcxx . . $ quiet_flag. = 1; break; |
| 318 |
case 1: |
| 319 |
case 'r': |
| 320 |
if ( opt == 'r' ) { |
| 321 |
if ( res_flag ) { multiple_resources = 1; } |
| 322 |
res_flag = 1; |
| 323 |
} |
| 324 |
|
| 325 |
/* infer appropriate time_width from validity period */ |
| 326 |
if ( validity_flag && !time_width_flag && !inferred_time_width ) { |
| 327 |
time_width = hashcash_validity_to_widthcxx . . $ hashcash_validity_to_width(a9e4e82268fd7bfa).( validity_period ); |
| 328 |
if ( !time_width ) { |
| 329 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: -ve validity period" ); |
| 330 |
} |
| 331 |
inferred_time_width = time_width; |
| 332 |
} |
| 333 |
|
| 334 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( &args, optargcxx . . $ optarg., str_type, case_flag, validity_period, |
| 335 |
grace_period, anon_period, time_width, bits, 0 ); |
| 336 |
|
| 337 |
if ( opt == 'r' ) { |
| 338 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( &resource, optargcxx . . $ optarg., str_type, case_flag, |
| 339 |
validity_period, grace_period, anon_period, |
| 340 |
time_width, bits, over_flag ); |
| 341 |
} else if ( opt == 1 ) { |
| 342 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( &tokens, optargcxx . . $ optarg., str_type, case_flag, |
| 343 |
validity_period, grace_period, anon_period, |
| 344 |
time_width, bits, 0 ); |
| 345 |
} |
| 346 |
over_flag = 0; |
| 347 |
|
| 348 |
break; |
| 349 |
case 's': speed_flag = 1; break; |
| 350 |
case 'S': str_type = TYPE_STRcxx . . $ `hashcash.h:35:9`!; break; |
| 351 |
case 't': |
| 352 |
if ( optargcxx . . $ optarg.[0] == '-' || optargcxx . . $ optarg.[0] == '+' ) { |
| 353 |
if ( !parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( optargcxx . . $ optarg., &time_period ) ) { |
| 354 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -t invalid relative time format" ); |
| 355 |
} |
| 356 |
now_time += time_period; |
| 357 |
} else { |
| 358 |
now_time = hashcash_from_utctimestrcxx . . $ hashcash_from_utctimestr(71083d4ee4d9cb41).( optargcxx . . $ optarg., utc_flag ); |
| 359 |
if ( now_time == (time_tcxx . . $ time_t#)-1 ) { |
| 360 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -t invalid time format" ); |
| 361 |
} |
| 362 |
} |
| 363 |
break; |
| 364 |
case 'u': utc_flag = 1; break; |
| 365 |
case 'v': verbose_flagcxx . . $ verbose_flag. = 1; break; |
| 366 |
case 'V': version_flag = 1; break; |
| 367 |
case 'w': width_flag = 1; break; |
| 368 |
case 'x': |
| 369 |
ext = strdupcxx . . $ strdup(a8b8e32347182212).( optargcxx . . $ optarg. ); |
| 370 |
/* deprecate old -x flag */ |
| 371 |
/* hdr_flag = 1; */ |
| 372 |
/* sstrncpy( header, optarg, MAX_HDR ); */ |
| 373 |
break; |
| 374 |
case 'X': |
| 375 |
hdr_flag = 1; |
| 376 |
sstrncpycxx . . $ `sstring.h:3:9`!( header, "X-Hashcash: ", MAX_HDRcxx . . $ `hashcash.c:56:9`! ); |
| 377 |
sstrncpycxx . . $ `sstring.h:3:9`!( header2, "Hashcash: ", MAX_HDRcxx . . $ `hashcash.c:56:9`! ); |
| 378 |
break; |
| 379 |
case 'y': yes_flag = 1; break; |
| 380 |
case 'z': |
| 381 |
time_width_flag = 1; |
| 382 |
time_width = atoicxx . . $ atoi(5c4306d8553b3696).( optargcxx . . $ optarg. ); |
| 383 |
if ( time_width != 6 && time_width != 10 && time_width != 12 ) { |
| 384 |
usagecxx . . $ usage(85c52e162fed56f9).( "error: -z invalid time width: must be 6, 10 or 12" ); |
| 385 |
} |
| 386 |
break; |
| 387 |
case 'Z': compress = atoicxx . . $ atoi(5c4306d8553b3696).( optargcxx . . $ optarg. ); |
| 388 |
/* temporary work around for bug discovered in 1.15, disable -Z2 */ |
| 389 |
/* if ( compress > 1 ) { compress = 1; } */ |
| 390 |
break; |
| 391 |
case '?': |
| 392 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: unrecognized option -%c", optoptcxx . . $ optopt. ); |
| 393 |
usagecxx . . $ usage(85c52e162fed56f9).( "" ); |
| 394 |
break; |
| 395 |
case ':': |
| 396 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: option -%c missing argument", optoptcxx . . $ optopt. ); |
| 397 |
usagecxx . . $ usage(85c52e162fed56f9).( "" ); |
| 398 |
break; |
| 399 |
default: |
| 400 |
usagecxx . . $ usage(85c52e162fed56f9).( "error with argument processing" ); |
| 401 |
break; |
| 402 |
} |
| 403 |
} |
| 404 |
|
| 405 |
if ( validity_flag && !time_width_flag && !inferred_time_width ) { |
| 406 |
time_width = hashcash_validity_to_widthcxx . . $ hashcash_validity_to_width(a9e4e82268fd7bfa).( resource.eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[0].validitycxx . . $ $anonymous_type_aa62bfaa706685ea_0#validity. ); |
| 407 |
if ( !time_width ) { |
| 408 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: -ve validity period" ); |
| 409 |
} |
| 410 |
inferred_time_width = time_width; |
| 411 |
} |
| 412 |
|
| 413 |
if ( array_numcxx . . $ `hashcash.c:137:9`!( &args ) == 0 && verbose_flagcxx . . $ verbose_flag. && |
| 414 |
name_flag + left_flag + width_flag + check_flag + |
| 415 |
mint_flag + purge_flag + speed_flag < 1 ) { |
| 416 |
auto_version = 1; |
| 417 |
version_flag = 1; verbose_flagcxx . . $ verbose_flag. = 0; |
| 418 |
} |
| 419 |
|
| 420 |
if ( version_flag ) { |
| 421 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "Version: hashcash-%s\n", |
| 422 |
HASHCASH_VERSION_STRINGcxx . . $ `hashcash.h:33:9`! ); |
| 423 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s\n", HASHCASH_VERSION_STRINGcxx . . $ `hashcash.h:33:9`! ); |
| 424 |
if ( auto_version ) { exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`! ); } |
| 425 |
} |
| 426 |
|
| 427 |
if ( mint_flag + check_flag > 1 ) { |
| 428 |
usagecxx . . $ usage(85c52e162fed56f9).( "can only specify one of -m, -c" ); |
| 429 |
} |
| 430 |
|
| 431 |
if ( mint_flag && ( name_flag || width_flag || left_flag ) ) { |
| 432 |
usagecxx . . $ usage(85c52e162fed56f9).( "can not use -n, -w or -l with -m" ); |
| 433 |
} |
| 434 |
|
| 435 |
if ( mint_flag + check_flag + name_flag + left_flag + width_flag + db_flag+ |
| 436 |
bits_flag + res_flag + purge_flag + speed_flag + version_flag == 0 ) { |
| 437 |
usagecxx . . $ usage(85c52e162fed56f9).( "must specify at least one of -m, -c, -d, -n, -l-, -w, -b, -r, -p or -s"); |
| 438 |
} |
| 439 |
|
| 440 |
if ( quiet_flagcxx . . $ quiet_flag. ) { verbose_flagcxx . . $ verbose_flag. = 0; } /* quiet overrides verbose */ |
| 441 |
if ( speed_flag && check_flag ) { speed_flag = 0; } /* ignore speed */ |
| 442 |
|
| 443 |
if ( purge_flag ) { |
| 444 |
db_opencxx . . $ db_open(5c57a783a5f80a21).( &db, db_filename ); |
| 445 |
db_opened = 1; |
| 446 |
|
| 447 |
db_purge_arrcxx . . $ db_purge_arr(b34afceb658d5cc2).( &db, &purge_resource, purge_all, purge_period, |
| 448 |
now_time, validity_flag ? purge_validity_period : 0, |
| 449 |
grace_period ); |
| 450 |
|
| 451 |
if ( mint_flag + check_flag + name_flag + left_flag + |
| 452 |
width_flag + bits_flag + res_flag + speed_flag == 0 ) { |
| 453 |
db_closecxx . . $ db_close(14613a252c7791ed).( &db ); /* just -p we're done */ |
| 454 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! ); |
| 455 |
} |
| 456 |
} |
| 457 |
|
| 458 |
if ( mint_flag || speed_flag ) { /* mint stamp */ |
| 459 |
|
| 460 |
if ( mint_flag ) { |
| 461 |
|
| 462 |
/* no resources given, read them from stdin */ |
| 463 |
if ( array_numcxx . . $ `hashcash.c:137:9`!( &args ) == 0 ) { |
| 464 |
if ( in_is_ttycxx . . $ in_is_tty. ) { |
| 465 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "enter resources to mint stamps for one per line:\n" ); |
| 466 |
} |
| 467 |
while ( !feofcxx . . $ feof(89bc1efcdac0ca22).(stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!) ) { |
| 468 |
line[0] = '\0'; |
| 469 |
junk = fgetscxx . . $ fgets(efb0aaba7ac866ae).( line, MAX_LINEcxx . . $ `hashcash.c:57:9`!, stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`! ); |
| 470 |
chomplfcxx . . $ chomplf(fda57c8427c60377).( line ); |
| 471 |
trimspacecxx . . $ trimspace(fda57c8427c60377).( line ); |
| 472 |
if ( line[0] != '\0' ) { |
| 473 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( &args, line, 0, 0, validity_period, |
| 474 |
grace_period, anon_period, time_width, |
| 475 |
bits, 0 ); |
| 476 |
} |
| 477 |
} |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
/* integrate the bench test */ |
| 482 |
|
| 483 |
if ( verbose_flagcxx . . $ verbose_flag. && speed_flag && !mint_flag ) { |
| 484 |
if ( core_flag ) { |
| 485 |
hashcash_benchtestcxx . . $ hashcash_benchtest(beccc266862daf71).( 3, core ); |
| 486 |
} else { |
| 487 |
hashcash_benchtestcxx . . $ hashcash_benchtest(beccc266862daf71).( 3, -1 ); |
| 488 |
} |
| 489 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! ); /* don't actually calculate it */ |
| 490 |
} |
| 491 |
|
| 492 |
if ( !verbose_flagcxx . . $ verbose_flag. && speed_flag && mint_flag ) { |
| 493 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "core: %s\n", |
| 494 |
hashcash_core_namecxx . . $ hashcash_core_name(f7ae7e56280f18ae).( hashcash_corecxx . . $ hashcash_core(b126dc7c1de90089).() ) ); |
| 495 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "speed: %ld preimage tests per second\n", |
| 496 |
hashcash_per_seccxx . . $ hashcash_per_sec(f708dce9a8856c70).() ); |
| 497 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%ld\n", hashcash_per_seccxx . . $ hashcash_per_sec(f708dce9a8856c70).() ); |
| 498 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "compression: %d\n", compress ); |
| 499 |
} |
| 500 |
|
| 501 |
if ( verbose_flagcxx . . $ verbose_flag. || ( speed_flag && !bits_flag ) ) { |
| 502 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "core: %s\n", |
| 503 |
hashcash_core_namecxx . . $ hashcash_core_name(f7ae7e56280f18ae).( hashcash_corecxx . . $ hashcash_core(b126dc7c1de90089).() ) ); |
| 504 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "speed: %ld preimage tests per second\n", |
| 505 |
hashcash_per_seccxx . . $ hashcash_per_sec(f708dce9a8856c70).() ); |
| 506 |
if ( speed_flag && !bits_flag && !mint_flag ) { |
| 507 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%ld\n", hashcash_per_seccxx . . $ hashcash_per_sec(f708dce9a8856c70).() ); |
| 508 |
} |
| 509 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "compression: %d\n", compress ); |
| 510 |
if ( speed_flag && !bits_flag && !mint_flag ) { |
| 511 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! ); /* don't actually calculate it */ |
| 512 |
} |
| 513 |
} |
| 514 |
|
| 515 |
if ( speed_flag && bits_flag && !mint_flag ) { |
| 516 |
tries_expected = report_speedcxx . . $ report_speed(73d891ffc41e4d2c).( bits, (PPEcxx . . $ `hashcash.c:66:9`!) ? &time_est : 0, |
| 517 |
!quiet_flagcxx . . $ quiet_flag. ); |
| 518 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%.0f\n", time_est ); |
| 519 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! ); /* don't actually calculate it */ |
| 520 |
} |
| 521 |
|
| 522 |
for ( i = 0; i < array_numcxx . . $ `hashcash.c:137:9`!( &args ); i++ ) { |
| 523 |
|
| 524 |
start = clockcxx . . $ clock(da6335ded91d79c2).(); |
| 525 |
|
| 526 |
ent = &(args.eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[i]); |
| 527 |
|
| 528 |
tries_expected = report_speedcxx . . $ report_speed(73d891ffc41e4d2c).( ent->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, |
| 529 |
verbose_flagcxx . . $ verbose_flag.||speed_flag ); |
| 530 |
|
| 531 |
if ( !ent->case_flagcxx . . $ $anonymous_type_aa62bfaa706685ea_0#case_flag. ) { stolowercxx . . $ `hashcash.c:101:9`!( ent->strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. ); } |
| 532 |
|
| 533 |
/* calculate precision to see responsive % progress */ |
| 534 |
/* aim to see progress min every 0.25 seconds */ |
| 535 |
time_est = hc_est_timecxx . . $ `hashcash.c:142:9`!( ent->bits ) / 100; |
| 536 |
precision = 0; |
| 537 |
for ( j = 0; j <= 12; j++ ) { |
| 538 |
if ( time_est > 0.25 ) { time_est /= 10; precision++; } |
| 539 |
} |
| 540 |
sprintfcxx . . $ sprintf(26c8642d26409d6d).( progress_formatcxx . . $ progress_format., PROGRESS_FMTcxx . . $ `hashcash.c:149:9`!, precision ); |
| 541 |
|
| 542 |
err = hashcash_mintcxx . . $ hashcash_mint(79bf5527ce570278).( now_time, ent->widthcxx . . $ $anonymous_type_aa62bfaa706685ea_0#width., ent->strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str., ent->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits., |
| 543 |
ent->anoncxx . . $ $anonymous_type_aa62bfaa706685ea_0#anon., &new_token, &anon_random, |
| 544 |
&tries_taken, ext, compress, |
| 545 |
callback, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ); |
| 546 |
end = clockcxx . . $ clock(da6335ded91d79c2).(); |
| 547 |
|
| 548 |
switch ( err ) { |
| 549 |
case HASHCASH_INVALID_TOK_LENcxx . . $ `hashcash.h:60:9`!: |
| 550 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: maximum preimage with sha1 is 160 bits" ); |
| 551 |
case HASHCASH_RNG_FAILEDcxx . . $ `hashcash.h:61:9`!: |
| 552 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: random number generator failed" ); |
| 553 |
case HASHCASH_INVALID_TIMEcxx . . $ `hashcash.h:62:9`!: |
| 554 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: outside unix time Epoch" ); |
| 555 |
case HASHCASH_TOO_MANY_TRIEScxx . . $ `hashcash.h:63:9`!: |
| 556 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: failed to find preimage in 2^96 tries!" ); |
| 557 |
case HASHCASH_EXPIRED_ON_CREATIONcxx . . $ `hashcash.h:64:9`!: |
| 558 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: -a stamp may expire on creation" ); |
| 559 |
case HASHCASH_INVALID_VALIDITY_PERIODcxx . . $ `hashcash.h:65:9`!: |
| 560 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: negative validity period" ); |
| 561 |
case HASHCASH_INVALID_TIME_WIDTHcxx . . $ `hashcash.h:67:9`!: |
| 562 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: invalid time width" ); |
| 563 |
case HASHCASH_INTERNAL_ERRORcxx . . $ `hashcash.h:66:9`!: |
| 564 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: internal error" ); |
| 565 |
case HASHCASH_OKcxx . . $ `hashcash.h:57:9`!: |
| 566 |
break; |
| 567 |
default: |
| 568 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: unknown failure" ); |
| 569 |
} |
| 570 |
|
| 571 |
if ( anon_flag ) { |
| 572 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "anon period: %ld seconds\n", |
| 573 |
(long)anon_period ); |
| 574 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "adding: %ld seconds\n", anon_random ); |
| 575 |
} |
| 576 |
|
| 577 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "tries: %.0f", tries_taken ); |
| 578 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " %.0f%% of expected \n", |
| 579 |
tries_taken / tries_expected * 100 ); |
| 580 |
|
| 581 |
if ( end < start ) { tmp = end; end = start; start = tmp; } |
| 582 |
taken = (end-start)/(double)CLOCKS_PER_SECcxx . . $ `<external>/89459239771508533/time.h:34:9`!; |
| 583 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "time: %.0f seconds\n", taken ); |
| 584 |
|
| 585 |
if ( hdr_flag ) { |
| 586 |
header_wrapped = hashcash_make_headercxx . . $ hashcash_make_header(cfa4c5328a7dc09e).( new_token, HDR_LINE_LENcxx . . $ `hashcash.c:80:9`!, |
| 587 |
header, '\t', |
| 588 |
LINEFEEDcxx . . $ `hashcash.c:95:9`! ); |
| 589 |
if ( header_wrapped == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { |
| 590 |
/* don't expect this but for security fail closed */ |
| 591 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "out of memory\n"); |
| 592 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`! ); |
| 593 |
} |
| 594 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s", header_wrapped ); |
| 595 |
freecxx . . $ free(5d22bdacc48458e8).( header_wrapped ); |
| 596 |
} else { |
| 597 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s%s\n", |
| 598 |
((quiet_flagcxx . . $ quiet_flag.||!out_is_ttycxx . . $ out_is_tty.)? "" : "hashcash stamp: "), |
| 599 |
new_token ); |
| 600 |
} |
| 601 |
freecxx . . $ free(5d22bdacc48458e8).( new_token ); |
| 602 |
} |
| 603 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! ); |
| 604 |
|
| 605 |
} else if ( check_flag || name_flag || width_flag || |
| 606 |
left_flag || bits_flag || res_flag || db_flag ) { |
| 607 |
|
| 608 |
/* check token is valid */ |
| 609 |
trimspacecxx . . $ trimspace(fda57c8427c60377).( header ); /* be forgiving about missing space */ |
| 610 |
hdr_len = strlencxx . . $ strlen(751346f8406fd082).( header ); |
| 611 |
|
| 612 |
if ( header2[0] ) { |
| 613 |
trimspacecxx . . $ trimspace(fda57c8427c60377).( header2 ); |
| 614 |
hdr2_len = strlencxx . . $ strlen(751346f8406fd082).( header2 ); |
| 615 |
} |
| 616 |
|
| 617 |
/* if no resources given create a kind of NULL entry to carry */ |
| 618 |
/* the other options along; hashcash_check knows to not check */ |
| 619 |
/* resource name if resource given is NULL */ |
| 620 |
|
| 621 |
if ( array_numcxx . . $ `hashcash.c:137:9`!( &resource ) == 0 ) { |
| 622 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( &resource, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, str_type, case_flag, validity_period, |
| 623 |
grace_period, anon_period, time_width, bits, 0 ); |
| 624 |
} |
| 625 |
|
| 626 |
hdrs_found = 0; |
| 627 |
tty_info = 0; |
| 628 |
in_headers = 0; |
| 629 |
|
| 630 |
ahead[0] = '\0'; |
| 631 |
for ( t = 0, token_found = 0, boundary = 0; !boundary; ) { |
| 632 |
/* read tokens from cmd line args 1st */ |
| 633 |
if ( t < array_numcxx . . $ `hashcash.c:137:9`!( &tokens ) ) { |
| 634 |
sstrncpycxx . . $ `sstring.h:3:9`!( token, tokens.elt[t].str, MAX_TOKcxx . . $ `hashcash.h:45:9`! ); |
| 635 |
t++; |
| 636 |
token_found = 1; |
| 637 |
} |
| 638 |
/* if no hdr flag, and were cmd line tokens, we're done */ |
| 639 |
else if ( !hdr_flag && array_numcxx . . $ `hashcash.c:137:9`!( &tokens ) > 0 ) { break; } |
| 640 |
else { |
| 641 |
if ( !in_headers ) { in_headers = 1; } |
| 642 |
if ( in_is_ttycxx . . $ in_is_tty. && !tty_info ) { |
| 643 |
if ( hdr_flag ) { |
| 644 |
if ( ignore_boundary_flag ) { |
| 645 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "enter email headers followed by mail body:\n" ); |
| 646 |
} else { |
| 647 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "enter email headers:\n" ); |
| 648 |
} |
| 649 |
} else { |
| 650 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 651 |
"enter stamps to check one per line:\n" ); |
| 652 |
} |
| 653 |
tty_info = 1; |
| 654 |
} |
| 655 |
if ( read_eofcxx . . $ read_eof(9f4384670e65005f).( stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!, ahead ) ) { break; } |
| 656 |
read_headercxx . . $ read_header(a66d455f0d9c8a09).( stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!, &line, &line_max, &line_alloc, |
| 657 |
ahead, MAX_LINEcxx . . $ `hashcash.c:57:9`! ); |
| 658 |
if ( line[0] == '\0' ) { continue; } |
| 659 |
if ( hdr_flag ) { |
| 660 |
token_found = (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).( line, header, |
| 661 |
hdr_len ) == 0); |
| 662 |
token2_found = header2[0] && |
| 663 |
(strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).( line, header2, hdr2_len ) == 0); |
| 664 |
if ( token_found ) { |
| 665 |
sstrncpycxx . . $ `sstring.h:3:9`!( token, line+hdr_len, MAX_TOKcxx . . $ `hashcash.h:45:9`! ); |
| 666 |
hdrs_found = 1; |
| 667 |
} else if ( token2_found ) { |
| 668 |
sstrncpycxx . . $ `sstring.h:3:9`!( token, line+hdr2_len, MAX_TOKcxx . . $ `hashcash.h:45:9`! ); |
| 669 |
hdrs_found = 1; |
| 670 |
token_found = 1; |
| 671 |
} |
| 672 |
} else { |
| 673 |
token_found = 1; |
| 674 |
sstrncpycxx . . $ `sstring.h:3:9`!( token, line, MAX_TOKcxx . . $ `hashcash.h:45:9`! ); |
| 675 |
} |
| 676 |
trimspacecxx . . $ trimspace(fda57c8427c60377).( token ); |
| 677 |
} |
| 678 |
|
| 679 |
/* end of stamp finder which results in clean stamp in token */ |
| 680 |
|
| 681 |
if ( token_found ) { |
| 682 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "examining stamp: %s\n", token ); |
| 683 |
|
| 684 |
skip = 0; |
| 685 |
over = 0; |
| 686 |
accept = 0; |
| 687 |
for ( i = 0; i < array_numcxx . . $ `hashcash.c:137:9`!( &resource ) && !skip; i++ ) { |
| 688 |
ent = &resource.eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[i]; |
| 689 |
|
| 690 |
/* keep going until find non overridden */ |
| 691 |
|
| 692 |
if ( over && ent->overcxx . . $ $anonymous_type_aa62bfaa706685ea_0#over. ) { |
| 693 |
if ( multiple_resources ) { |
| 694 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "checking against resource: %s\n", |
| 695 |
ent->strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. ); |
| 696 |
} |
| 697 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "no match: overridden resource\n" ); |
| 698 |
continue; |
| 699 |
} |
| 700 |
|
| 701 |
over = 0; |
| 702 |
|
| 703 |
if ( !ent->case_flagcxx . . $ $anonymous_type_aa62bfaa706685ea_0#case_flag. ) { stolowercxx . . $ `hashcash.c:101:9`!( ent->strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. ); } |
| 704 |
valid_for = hashcash_checkcxx . . $ hashcash_check(cf6099f7d8aec866).( token, ent->case_flagcxx . . $ $anonymous_type_aa62bfaa706685ea_0#case_flag., |
| 705 |
ent->strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str., |
| 706 |
&(ent->regexpcxx . . $ $anonymous_type_aa62bfaa706685ea_0#regexp.), &re_err, |
| 707 |
ent->typecxx . . $ $anonymous_type_aa62bfaa706685ea_0#type., now_time, |
| 708 |
ent->validitycxx . . $ $anonymous_type_aa62bfaa706685ea_0#validity., ent->gracecxx . . $ $anonymous_type_aa62bfaa706685ea_0#grace., |
| 709 |
bits_flag ? ent->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits. : 0, |
| 710 |
&token_time ); |
| 711 |
|
| 712 |
if ( valid_for < 0 ) { |
| 713 |
switch ( valid_for ) { |
| 714 |
/* reasons token is broken, give up */ |
| 715 |
|
| 716 |
case HASHCASH_INVALIDcxx . . $ `hashcash.h:70:9`!: |
| 717 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "skipped: stamp invalid\n" ); |
| 718 |
skip = 1; continue; |
| 719 |
|
| 720 |
case HASHCASH_UNSUPPORTED_VERSIONcxx . . $ `hashcash.h:73:9`!: |
| 721 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "skipped: unsupported version\n" ); |
| 722 |
skip = 1; continue; |
| 723 |
|
| 724 |
/* avoid plural reporting if one of something */ |
| 725 |
/* not possible for match with */ |
| 726 |
/* other resources in these situations */ |
| 727 |
/* as will just fail for same reason again */ |
| 728 |
|
| 729 |
case HASHCASH_WRONG_RESOURCEcxx . . $ `hashcash.h:71:9`!: |
| 730 |
if ( !multiple_resources ) { |
| 731 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "skipped: stamp with wrong resource\n" ); |
| 732 |
skip = 1; continue; |
| 733 |
} |
| 734 |
break; |
| 735 |
|
| 736 |
case HASHCASH_INSUFFICIENT_BITScxx . . $ `hashcash.h:72:9`!: |
| 737 |
if ( !multiple_bits && bits_flag ) { |
| 738 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 739 |
"skipped: stamp has insufficient bits\n" ); |
| 740 |
skip = 1; continue; |
| 741 |
} |
| 742 |
break; |
| 743 |
|
| 744 |
case HASHCASH_EXPIREDcxx . . $ `hashcash.h:69:9`!: |
| 745 |
if ( !multiple_validity && check_flag ) { |
| 746 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "skipped: stamp expired\n" ); |
| 747 |
skip = 1; continue; |
| 748 |
} |
| 749 |
break; |
| 750 |
|
| 751 |
case HASHCASH_VALID_IN_FUTUREcxx . . $ `hashcash.h:68:9`!: |
| 752 |
if ( !multiple_grace && check_flag ) { |
| 753 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "skipped: stamp valid in future\n" ); |
| 754 |
skip = 1; continue; |
| 755 |
} |
| 756 |
break; |
| 757 |
} |
| 758 |
} |
| 759 |
|
| 760 |
if ( multiple_resources ) { |
| 761 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "checking against resource: %s\n", |
| 762 |
ent->strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. ); |
| 763 |
} |
| 764 |
|
| 765 |
if ( valid_for >= 0 ) { break; } |
| 766 |
|
| 767 |
if ( width_flag || left_flag || name_flag ) { |
| 768 |
accept = 1; |
| 769 |
} |
| 770 |
|
| 771 |
/* reason token failed for this resource */ |
| 772 |
/* but may succeed with diff resource */ |
| 773 |
|
| 774 |
switch ( valid_for ) { |
| 775 |
|
| 776 |
/* need non override to continue after this */ |
| 777 |
/* kind of failure */ |
| 778 |
|
| 779 |
case HASHCASH_INSUFFICIENT_BITScxx . . $ `hashcash.h:72:9`!: |
| 780 |
if ( bits_flag ) { |
| 781 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "no match: stamp has insufficient bits\n" ); |
| 782 |
over = 1; accept = 0; continue; |
| 783 |
} |
| 784 |
break; |
| 785 |
case HASHCASH_VALID_IN_FUTUREcxx . . $ `hashcash.h:68:9`!: |
| 786 |
if ( check_flag ) { |
| 787 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "no match: stamp valid in future\n" ); |
| 788 |
over = 1; accept = 0; continue; |
| 789 |
} |
| 790 |
break; |
| 791 |
case HASHCASH_EXPIREDcxx . . $ `hashcash.h:69:9`!: |
| 792 |
if ( check_flag ) { |
| 793 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "no match: stamp expired\n" ); |
| 794 |
over = 1; accept = 0; continue; |
| 795 |
} |
| 796 |
break; |
| 797 |
case HASHCASH_WRONG_RESOURCEcxx . . $ `hashcash.h:71:9`!: |
| 798 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "no match: wrong resource\n" ); |
| 799 |
accept = 0; |
| 800 |
continue; |
| 801 |
|
| 802 |
/* fatal error stop */ |
| 803 |
|
| 804 |
case HASHCASH_REGEXP_ERRORcxx . . $ `hashcash.h:76:9`!: |
| 805 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "regexp error: " ); |
| 806 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( re_err ); |
| 807 |
break; |
| 808 |
|
| 809 |
default: |
| 810 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "internal error" ); |
| 811 |
break; |
| 812 |
} |
| 813 |
} |
| 814 |
|
| 815 |
if ( valid_for >= 0 || accept ) { |
| 816 |
if ( db_flag ) { |
| 817 |
if ( !db_opened ) { |
| 818 |
db_opencxx . . $ db_open(5c57a783a5f80a21).( &db, db_filename ); |
| 819 |
db_opened = 1; |
| 820 |
} |
| 821 |
if ( db_incxx . . $ db_in(237208b940db5468).( &db, token, token_utime ) ) { |
| 822 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "skipped: spent stamp\n" ); |
| 823 |
valid_for = HASHCASH_SPENTcxx . . $ `hashcash.h:74:9`!; |
| 824 |
continue; /* to next token */ |
| 825 |
} |
| 826 |
} |
| 827 |
|
| 828 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "matched stamp: %s\n", token ); |
| 829 |
|
| 830 |
if ( name_flag || verbose_flagcxx . . $ verbose_flag. ) { |
| 831 |
if ( ext ) { freecxx . . $ free(5d22bdacc48458e8).( ext ); ext = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; } |
| 832 |
hashcash_parsecxx . . $ hashcash_parse(9cd80e4a04369a5f).( token, &vers, &claimed_bits, |
| 833 |
utcttime, MAX_UTCcxx . . $ `hashcash.h:339:9`!, |
| 834 |
token_resource, MAX_REScxx . . $ `hashcash.h:41:9`!, &ext, 0 ); |
| 835 |
parsed = 1; |
| 836 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "stamp resource name: %s\n", |
| 837 |
token_resource ); |
| 838 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%s", token_resource ); |
| 839 |
} |
| 840 |
|
| 841 |
if ( width_flag || verbose_flagcxx . . $ verbose_flag. ) { |
| 842 |
count_bits = hashcash_countcxx . . $ hashcash_count(c61c63047ce273de).( token ); |
| 843 |
if ( !parsed ) { |
| 844 |
hashcash_parsecxx . . $ hashcash_parse(9cd80e4a04369a5f).( token, &vers, &claimed_bits, |
| 845 |
utcttime, MAX_UTCcxx . . $ `hashcash.h:339:9`!, |
| 846 |
token_resource, MAX_REScxx . . $ `hashcash.h:41:9`!, &ext, 0 ); |
| 847 |
parsed = 1; |
| 848 |
} |
| 849 |
if ( vers == 1 ) { |
| 850 |
count_bits = ( count_bits < claimed_bits ) ? |
| 851 |
0 : claimed_bits; |
| 852 |
} |
| 853 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "stamp value: %d\n", count_bits ); |
| 854 |
if ( name_flag || verbose_flagcxx . . $ verbose_flag. ) { |
| 855 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, " " ); |
| 856 |
} |
| 857 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%d", count_bits ); |
| 858 |
} |
| 859 |
|
| 860 |
if ( left_flag || verbose_flagcxx . . $ verbose_flag. ) { |
| 861 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "valid: " ); |
| 862 |
if ( valid_for > 0 ) { |
| 863 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "for %ld seconds\n", |
| 864 |
(long)valid_for ); |
| 865 |
if ( name_flag || width_flag ) { |
| 866 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, " " ); |
| 867 |
} |
| 868 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "%ld", (long)valid_for ); |
| 869 |
} else { |
| 870 |
expiry_time = token_time + validity_period; |
| 871 |
switch ( valid_for ) { |
| 872 |
case HASHCASH_VALID_FOREVERcxx . . $ `hashcash.h:59:9`!: |
| 873 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "forever\n" ); |
| 874 |
if ( name_flag || width_flag ) { |
| 875 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, " " ); |
| 876 |
} |
| 877 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "0" ); |
| 878 |
break; |
| 879 |
case HASHCASH_VALID_IN_FUTUREcxx . . $ `hashcash.h:68:9`!: |
| 880 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "in %ld seconds\n", |
| 881 |
token_time-(now_time+grace_period) ); |
| 882 |
if ( name_flag || width_flag ) { |
| 883 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, " " ); |
| 884 |
} |
| 885 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "+%ld", |
| 886 |
token_time-(now_time+grace_period) ); |
| 887 |
break; |
| 888 |
case HASHCASH_EXPIREDcxx . . $ `hashcash.h:69:9`!: |
| 889 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "expired %ld seconds ago\n", |
| 890 |
now_time-(expiry_time+grace_period) ); |
| 891 |
if ( name_flag || width_flag ) { |
| 892 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, " " ); |
| 893 |
} |
| 894 |
PPRINTFcxx . . $ `hashcash.c:73:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "-%ld", |
| 895 |
now_time-(expiry_time+grace_period) ); |
| 896 |
break; |
| 897 |
default: |
| 898 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "not valid\n" ); |
| 899 |
} |
| 900 |
} |
| 901 |
} |
| 902 |
|
| 903 |
if ( name_flag || width_flag || left_flag ) { |
| 904 |
PPUTScxx . . $ `hashcash.c:77:9`!( stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!, "\n" ); |
| 905 |
continue; /* to next token */ |
| 906 |
} |
| 907 |
|
| 908 |
if ( db_flag ) { |
| 909 |
VPUTScxx . . $ `hashcash.c:78:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, |
| 910 |
"database: not double spent\n" ); |
| 911 |
checked = yes_flag || ( res_flag && bits_flag); |
| 912 |
if ( checked ) { |
| 913 |
sprintfcxx . . $ sprintf(26c8642d26409d6d).( period, "%ld", validity_period ); |
| 914 |
db_addcxx . . $ db_add(18d537d5cf8b8e63).( &db, token, period ); |
| 915 |
} |
| 916 |
} else { |
| 917 |
checked = yes_flag; |
| 918 |
} |
| 919 |
goto leave; /* matched so leave */ |
| 920 |
} |
| 921 |
} else if ( hdr_flag && in_headers && !ignore_boundary_flag ) { |
| 922 |
if ( line[0] == '\0' ) { boundary = 1; } |
| 923 |
} |
| 924 |
} |
| 925 |
if ( !width_flag && !left_flag && !name_flag ) { |
| 926 |
if ( hdr_flag && !hdrs_found ) { |
| 927 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "warning: no line matching %s found in input\n", |
| 928 |
header ); |
| 929 |
} |
| 930 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "rejected: no valid stamps found\n" ); |
| 931 |
valid_for = HASHCASH_NO_TOKENcxx . . $ `hashcash.h:75:9`!; |
| 932 |
} |
| 933 |
|
| 934 |
leave: |
| 935 |
if ( width_flag || left_flag || name_flag ) { |
| 936 |
exitcxx . . $ exit(3ca292c338df9bb3).( yes_flag ? EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! : EXIT_UNCHECKEDcxx . . $ `hashcash.c:50:9`! ); |
| 937 |
} |
| 938 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "check: %s", |
| 939 |
( valid_for >= 0 ) ? |
| 940 |
( checked ? "ok" : "ok but not fully checked as" ) : |
| 941 |
"failed" ); |
| 942 |
if ( valid_for >= 0 ) { |
| 943 |
if ( !checked ) { |
| 944 |
if ( !bits_flag ) { |
| 945 |
comma = 1; QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " bits" ); |
| 946 |
} |
| 947 |
if ( !check_flag ) { |
| 948 |
if ( comma ) { QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "," ); } |
| 949 |
comma = 1; QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " expiry" ); |
| 950 |
} |
| 951 |
if ( !res_flag ) { |
| 952 |
if ( comma ) { QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "," ); } |
| 953 |
comma = 1; QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " resource" ); |
| 954 |
} |
| 955 |
if ( !db_flag ) { |
| 956 |
if ( comma ) { QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "," ); } |
| 957 |
comma = 1; QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " database" ); |
| 958 |
} |
| 959 |
if ( comma ) { QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " not specified" ); } |
| 960 |
} |
| 961 |
} |
| 962 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n" ); |
| 963 |
if ( valid_for < 0 ) { exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`! ); } |
| 964 |
exitcxx . . $ exit(3ca292c338df9bb3).( checked ? EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! : |
| 965 |
( yes_flag ? EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! : EXIT_UNCHECKEDcxx . . $ `hashcash.c:50:9`! ) ); |
| 966 |
} |
| 967 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_ERRORcxx . . $ `hashcash.c:53:9`! ); /* get here if no functional flags */ |
| 968 |
return 0; |
| 969 |
} |
| 970 |
|
| 971 |
int progress_callbackcxx . . $ progress_callback(69b8e4266e776973).(int ignore, int largest, int target, |
| 972 |
double counter, double expected, void* user) |
| 973 |
{ |
| 974 |
static int previous_percent = -1; |
| 975 |
static int previous_largest = -1; |
| 976 |
static double previous_counter = -1; |
| 977 |
double percent; |
| 978 |
|
| 979 |
if ( previous_counter != counter || previous_largest != largest ) { |
| 980 |
percent = counter*100/expected; |
| 981 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, progress_formatcxx . . $ progress_format., |
| 982 |
counter, expected, percent, largest, target, |
| 983 |
(previous_largest == largest) ? '\r' : '\n' ); |
| 984 |
previous_percent = percent; |
| 985 |
previous_largest = largest; |
| 986 |
previous_counter = counter; |
| 987 |
} |
| 988 |
return 1; |
| 989 |
} |
| 990 |
|
| 991 |
int parse_periodcxx . . $ parse_period(ef3eecfa0254c586).( const char* aperiod, long* resp ) |
| 992 |
{ |
| 993 |
int period_len; |
| 994 |
char last_char; |
| 995 |
long res = 1; |
| 996 |
char period_array[MAX_PERIODcxx . . $ `hashcash.c:55:9`!+1]; |
| 997 |
char* period = period_array; |
| 998 |
|
| 999 |
if ( period == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { return 0; } |
| 1000 |
period_len = strlencxx . . $ strlen(751346f8406fd082).( aperiod ); |
| 1001 |
if ( period_len == 0 ) { return 0; } |
| 1002 |
last_char = aperiod[period_len-1]; |
| 1003 |
if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`!( last_char ) && ! strchrcxx . . $ strchr(2050848944e00d54).( "YyMdhmsw", last_char ) ) { |
| 1004 |
return 0; |
| 1005 |
} |
| 1006 |
|
| 1007 |
sstrncpycxx . . $ `sstring.h:3:9`!( period, aperiod, MAX_PERIODcxx . . $ `hashcash.c:55:9`! ); |
| 1008 |
|
| 1009 |
if ( ! isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`!( last_char ) ) { period[--period_len] = '\0'; } |
| 1010 |
if ( period[0] == '+' || period[0] == '-' ) { |
| 1011 |
if ( period[0] == '-' ) { res = -1; } |
| 1012 |
period++; period_len--; |
| 1013 |
} |
| 1014 |
if ( period_len > 0 ) { res *= atoicxx . . $ atoi(5c4306d8553b3696).( period ); } |
| 1015 |
switch ( last_char ) |
| 1016 |
{ |
| 1017 |
case 's': break; |
| 1018 |
case 'm': res *= TIME_MINUTEcxx . . $ `hashcash.h:47:9`!; break; |
| 1019 |
case 'h': res *= TIME_HOURcxx . . $ `hashcash.h:48:9`!; break; |
| 1020 |
case 'd': res *= TIME_DAYcxx . . $ `hashcash.h:49:9`!; break; |
| 1021 |
case 'w': res *= TIME_DAYcxx . . $ `hashcash.h:49:9`!*7; break; |
| 1022 |
case 'M': res *= TIME_MONTHcxx . . $ `hashcash.h:51:9`!; break; |
| 1023 |
case 'y': case 'Y': res *= TIME_YEARcxx . . $ `hashcash.h:50:9`!; break; |
| 1024 |
case '0': case '1': case '2': case '3': case '4': |
| 1025 |
case '5': case '6': case '7': case '8': case '9': break; |
| 1026 |
default: return 0; |
| 1027 |
} |
| 1028 |
*resp = res; |
| 1029 |
return 1; |
| 1030 |
} |
| 1031 |
|
| 1032 |
void usagecxx . . $ usage(85c52e162fed56f9).( const char* msg ) |
| 1033 |
{ |
| 1034 |
if ( msg ) { fputscxx . . $ fputs(874fa6a5e59ab9bd).( msg, stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`! ); fputscxx . . $ fputs(874fa6a5e59ab9bd).( "\n\n", stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`! ); } |
| 1035 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "mint:\t\thashcash [-m] [opts] resource\n" ); |
| 1036 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "measure speed:\thashcash -s [-b bits]\n" ); |
| 1037 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "check:\t\thashcash -c [opts] -d -r resource [-e period] [stamp]\n" ); |
| 1038 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "purge expired:\thashcash -p now [-k] [-j resource] [-t time] [-u]\n" ); |
| 1039 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "count bits:\thashcash -w [opts] [stamp]\n" ); |
| 1040 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "get resource:\thashcash -n [opts] [stamp]\n" ); |
| 1041 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "time remaining:\thashcash -l [opts] -e period [stamp]\n" ); |
| 1042 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n" ); |
| 1043 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-b bits\t\tfind or check partial preimage of length bits\n" ); |
| 1044 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-d\t\tuse database (for double spending detection)\n" ); |
| 1045 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-r resource\tresource name for minting or checking stamp\n" ); |
| 1046 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-o\t\tprevious resource overrides this resource\n" ); |
| 1047 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-e period\ttime until stamp expires\n" ); |
| 1048 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-g\t\tgrace period for clock skew\n" ); |
| 1049 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-t time\t\tmodify current time stamp created at\n" ); |
| 1050 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-a time\t\tmodify time by random amount in range given\n" ); |
| 1051 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-u\t\tgive time in UTC instead of local time\n" ); |
| 1052 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-q\t\tquiet -- suppress all informational output\n" ); |
| 1053 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-v\t\tprint verbose informational output\n" ); |
| 1054 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-h\t\tprint this usage info\n" ); |
| 1055 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-f dbfile\tuse filename dbfile for database\n" ); |
| 1056 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-j resource\twith -p delete just stamps matching the given resource\n" ); |
| 1057 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-k\t\twith -p delete all not just expired\n" ); |
| 1058 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-x ext\t\tput in extension field\n" ); |
| 1059 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-X\t\toutput with header format 'X-Hashcash: '\n" ); |
| 1060 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-i\t\twith -X and -c, check msg body as well\n" ); |
| 1061 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-y\t\treturn success if stamps is valid but not fully checked\n" ); |
| 1062 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-z width\twidth of time field 6,10 or 12 chars (default 6)\n" ); |
| 1063 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-C\t\tmatch resources as case sensitive (default insensitive)\n" ); |
| 1064 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-S\t\tmatch following resources as text strings\n" ); |
| 1065 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-W\t\tmatch following resources with wildcards (default)\n" ); |
| 1066 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-E\t\tmatch following resources as regular expression\n" ); |
| 1067 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-P\t\tshow progress while searching\n"); |
| 1068 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-O core\t\tuse specified minting core\n"); |
| 1069 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\t-Z n\t\t0 = fast (default), 1 = medium, 2 = small/slow\n"); |
| 1070 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "examples:\n" ); |
| 1071 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\thashcash -mb20 foo # mint 20 bit preimage\n" ); |
| 1072 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\thashcash -cdb20 -r foo 1:20:040806:foo::831d0c6f22eb81ff:15eae4 # check preimage\n" ); |
| 1073 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n" ); |
| 1074 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "see hashcash (1) man page or http://www.hashcash.org/ for more details.\n" ); |
| 1075 |
fflushcxx . . $ fflush(89bc1efcdac0ca22).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`! ); |
| 1076 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_ERRORcxx . . $ `hashcash.c:53:9`! ); |
| 1077 |
} |
| 1078 |
|
| 1079 |
typedef structcxx . . $ $anonymous_type_aa62bfaa706685ea_2# { |
| 1080 |
time_tcxx . . $ time_t# expires_beforecxx . . $ $anonymous_type_aa62bfaa706685ea_2#expires_before.; |
| 1081 |
char now_utimecxx . . $ $anonymous_type_aa62bfaa706685ea_2#now_utime.[ MAX_UTCcxx . . $ `hashcash.h:339:9`!+1 ]; |
| 1082 |
int allcxx . . $ $anonymous_type_aa62bfaa706685ea_2#all.; |
| 1083 |
long validitycxx . . $ $anonymous_type_aa62bfaa706685ea_2#validity.; |
| 1084 |
long gracecxx . . $ $anonymous_type_aa62bfaa706685ea_2#grace.; |
| 1085 |
ARRAYcxx . . $ ARRAY#* resourcecxx . . $ $anonymous_type_aa62bfaa706685ea_2#resource.; |
| 1086 |
} db_argcxx . . $ db_arg#; |
| 1087 |
|
| 1088 |
/* compile time assert */ |
| 1089 |
|
| 1090 |
#if MAX_UTCcxx . . $ `hashcash.h:339:9`! > MAX_VALcxx . . $ `sdb.h:34:9`! |
| 1091 |
#error "MAX_UTC must be less than MAX_VAL" |
| 1092 |
#endif |
| 1093 |
|
| 1094 |
static int sdb_cb_token_matchercxx . . $ sdb_cb_token_matcher(8ae94fcf4f89b591).( const char* key, char* val, |
| 1095 |
void* argp, int* err ) { |
| 1096 |
db_argcxx . . $ db_arg#* arg = (db_argcxx . . $ db_arg#*)argp; |
| 1097 |
char token_utime[ MAX_UTCcxx . . $ `hashcash.h:339:9`!+1 ] = {0}; |
| 1098 |
char token_res[ MAX_REScxx . . $ `hashcash.h:41:9`!+1 ] = {0}, lower_token_res[ MAX_REScxx . . $ `hashcash.h:41:9`!+1 ] = {0}; |
| 1099 |
char *res = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1100 |
time_tcxx . . $ time_t# expires = 0; |
| 1101 |
time_tcxx . . $ time_t# expiry_period = 0; |
| 1102 |
time_tcxx . . $ time_t# created = 0; |
| 1103 |
int vers = 0, i = 0, bits = 0, matched = 0, type = 0, case_flag = 0; |
| 1104 |
int lowered = 0 ; |
| 1105 |
void** compile = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1106 |
char* re_err = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1107 |
|
| 1108 |
*err = 0; |
| 1109 |
if ( strcmpcxx . . $ strcmp(5ae29d726ae57f88).( key, PURGED_KEYcxx . . $ `hashcash.c:155:9`! ) == 0 ) { |
| 1110 |
sstrncpycxx . . $ `sstring.h:3:9`!( val, arg->now_utime, MAX_UTCcxx . . $ `hashcash.h:339:9`! ); |
| 1111 |
return 1; /* update purge time */ |
| 1112 |
} |
| 1113 |
|
| 1114 |
if ( !hashcash_parsecxx . . $ hashcash_parse(9cd80e4a04369a5f).( key, &vers, &bits, token_utime, MAX_UTCcxx . . $ `hashcash.h:339:9`!, |
| 1115 |
token_res, MAX_REScxx . . $ `hashcash.h:41:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 0 ) ) { |
| 1116 |
*err = EINPUTcxx . . $ `hashcash.c:48:9`!; /* corrupted token in DB */ |
| 1117 |
return 0; |
| 1118 |
} |
| 1119 |
if ( vers != 0 && vers != 1 ) { |
| 1120 |
*err = EINPUTcxx . . $ `hashcash.c:48:9`!; /* unsupported version number in DB */ |
| 1121 |
return 0; |
| 1122 |
} |
| 1123 |
/* if purging only for given resource */ |
| 1124 |
if ( array_numcxx . . $ `hashcash.c:137:9`!( arg->resource ) > 0 ) { |
| 1125 |
matched = 0; |
| 1126 |
for ( i = 0; !matched && i < array_numcxx . . $ `hashcash.c:137:9`!( arg->resource ); i++ ) { |
| 1127 |
res = arg->resourcecxx . . $ $anonymous_type_aa62bfaa706685ea_2#resource.->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[i].strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str.; |
| 1128 |
type = arg->resourcecxx . . $ $anonymous_type_aa62bfaa706685ea_2#resource.->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[i].typecxx . . $ $anonymous_type_aa62bfaa706685ea_0#type.; |
| 1129 |
case_flag = arg->resourcecxx . . $ $anonymous_type_aa62bfaa706685ea_2#resource.->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[i].case_flagcxx . . $ $anonymous_type_aa62bfaa706685ea_0#case_flag.; |
| 1130 |
compile = &(arg->resourcecxx . . $ $anonymous_type_aa62bfaa706685ea_2#resource.->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[i].regexpcxx . . $ $anonymous_type_aa62bfaa706685ea_0#regexp.); |
| 1131 |
if ( !case_flag && !lowered ) { |
| 1132 |
strncpycxx . . $ strncpy(255158a415b673b0).( lower_token_res, token_res, MAX_REScxx . . $ `hashcash.h:41:9`! ); |
| 1133 |
stolowercxx . . $ `hashcash.c:101:9`!( lower_token_res ); |
| 1134 |
lowered = 1; |
| 1135 |
} |
| 1136 |
matched = hashcash_resource_matchcxx . . $ hashcash_resource_match(4f0b9df207c9eefb).( type, case_flag ? |
| 1137 |
token_res : lower_token_res, |
| 1138 |
res, compile, &re_err ); |
| 1139 |
if ( re_err != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { |
| 1140 |
fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "regexp error: " ); |
| 1141 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( re_err ); |
| 1142 |
} |
| 1143 |
} |
| 1144 |
if ( !matched ) { return 1; } /* if it doesn't match, keep it */ |
| 1145 |
} |
| 1146 |
if ( arg->allcxx . . $ $anonymous_type_aa62bfaa706685ea_2#all. ) { return 0; } /* delete all regardless of expiry */ |
| 1147 |
if ( val[0] == '0' && val[1] == '\0' ) { return 1; } /* keep forever */ |
| 1148 |
if ( strlencxx . . $ strlen(751346f8406fd082).( val ) != strspncxx . . $ strspn(335c1dc86f5c867f).( val, "0123456789" ) ) { |
| 1149 |
*err = EINPUTcxx . . $ `hashcash.c:48:9`!; return 0; |
| 1150 |
} |
| 1151 |
expiry_period = atoicxx . . $ atoi(5c4306d8553b3696).( val ); |
| 1152 |
if ( expiry_period < 0 ) { *err = EINPUTcxx . . $ `hashcash.c:48:9`!; return 0; } /* corrupted */ |
| 1153 |
created = hashcash_from_utctimestrcxx . . $ hashcash_from_utctimestr(71083d4ee4d9cb41).( token_utime, 1 ); |
| 1154 |
if ( created < 0 ) { *err = EINPUTcxx . . $ `hashcash.c:48:9`!; return 0; } /* corrupted */ |
| 1155 |
expires = created |
| 1156 |
+ (arg->validitycxx . . $ $anonymous_type_aa62bfaa706685ea_2#validity. ? arg->validitycxx . . $ $anonymous_type_aa62bfaa706685ea_2#validity. : expiry_period) + arg->gracecxx . . $ $anonymous_type_aa62bfaa706685ea_2#grace.; |
| 1157 |
if ( expires <= arg->expires_beforecxx . . $ $anonymous_type_aa62bfaa706685ea_2#expires_before. ) { return 0; } /* delete if expired */ |
| 1158 |
return 1; /* otherwise keep */ |
| 1159 |
} |
| 1160 |
|
| 1161 |
int hashcash_db_purgecxx . . $ hashcash_db_purge(2b23f03061854877).( DBcxx . . $ DB#* db, const char* purge_resource, int type, |
| 1162 |
int case_flag, long validity_period, long grace_period, |
| 1163 |
int purge_all, long purge_period, time_tcxx . . $ time_t# now_time, |
| 1164 |
int* err ) { |
| 1165 |
ARRAYcxx . . $ ARRAY#* purge_resource_arr = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1166 |
array_alloccxx . . $ array_alloc(f36c4182aaae5413).( purge_resource_arr, 1 ); |
| 1167 |
array_pushcxx . . $ array_push(1afc9a320aea9297).( purge_resource_arr, purge_resource, type, case_flag, |
| 1168 |
validity_period, grace_period, 0, 0, 0, 0 ); |
| 1169 |
return db_purgecxx . . $ db_purge(4a5ef610074b5647).( db, purge_resource_arr, purge_all, purge_period, |
| 1170 |
now_time, validity_period, grace_period, 0, err ); |
| 1171 |
} |
| 1172 |
|
| 1173 |
void db_purge_arrcxx . . $ db_purge_arr(b34afceb658d5cc2).( DBcxx . . $ DB#* db, ARRAYcxx . . $ ARRAY#* purge_resource, int purge_all, |
| 1174 |
long purge_period, time_tcxx . . $ time_t# now_time, long validity_period, |
| 1175 |
long grace_period ) { |
| 1176 |
int res, err = HASHCASH_FAILcxx . . $ `hashcash.h:58:9`!; |
| 1177 |
res = db_purgecxx . . $ db_purge(4a5ef610074b5647).( db, purge_resource, purge_all, purge_period, now_time, |
| 1178 |
validity_period, grace_period, verbose_flagcxx . . $ verbose_flag., &err ); |
| 1179 |
switch ( res ) { |
| 1180 |
case HASHCASH_INVALID_TIMEcxx . . $ `hashcash.h:62:9`!: |
| 1181 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "error: invalid time argument" ); break; |
| 1182 |
case HASHCASH_FAILcxx . . $ `hashcash.h:58:9`!: diecxx . . $ die(d4f767463ce0a6b3).( err ); break; |
| 1183 |
case HASHCASH_OKcxx . . $ `hashcash.h:57:9`!: break; |
| 1184 |
default: diecxx . . $ die(d4f767463ce0a6b3).( err ); |
| 1185 |
} |
| 1186 |
} |
| 1187 |
|
| 1188 |
int db_purgecxx . . $ db_purge(4a5ef610074b5647).( DBcxx . . $ DB#* db, ARRAYcxx . . $ ARRAY#* purge_resource, int purge_all, |
| 1189 |
long purge_period, time_tcxx . . $ time_t# now_time, long validity_period, |
| 1190 |
long grace_period, int verbose, int* err ) { |
| 1191 |
time_tcxx . . $ time_t# last_time = 0 ; |
| 1192 |
char purge_utime[ MAX_UTCcxx . . $ `hashcash.h:339:9`!+1 ] = {0}; /* time token created */ |
| 1193 |
int ret = 0; |
| 1194 |
db_argcxx . . $ db_arg# arg; |
| 1195 |
|
| 1196 |
if ( now_time < 0 ) { return HASHCASH_INVALID_TIMEcxx . . $ `hashcash.h:62:9`!; } |
| 1197 |
|
| 1198 |
if ( !sdb_lookupcxx . . $ sdb_lookup(4eb379e6448fe8d).( db, PURGED_KEYcxx . . $ `hashcash.c:155:9`!, purge_utime, MAX_UTCcxx . . $ `hashcash.h:339:9`!, err ) ) { |
| 1199 |
return 0; |
| 1200 |
} |
| 1201 |
|
| 1202 |
last_time = hashcash_from_utctimestrcxx . . $ hashcash_from_utctimestr(71083d4ee4d9cb41).( purge_utime, 1 ); |
| 1203 |
if ( last_time < 0 ) { /* not first time, but corrupted */ |
| 1204 |
purge_period = 0; /* purge now */ |
| 1205 |
} |
| 1206 |
|
| 1207 |
if ( !hashcash_to_utctimestrcxx . . $ hashcash_to_utctimestr(9276ee04ba38ce81).( arg.now_utimecxx . . $ $anonymous_type_aa62bfaa706685ea_2#now_utime., MAX_UTCcxx . . $ `hashcash.h:339:9`!, now_time ) ) { |
| 1208 |
return HASHCASH_INVALID_TIMEcxx . . $ `hashcash.h:62:9`!; |
| 1209 |
} |
| 1210 |
|
| 1211 |
arg.expires_beforecxx . . $ $anonymous_type_aa62bfaa706685ea_2#expires_before. = now_time; |
| 1212 |
arg.resourcecxx . . $ $anonymous_type_aa62bfaa706685ea_2#resource. = purge_resource; |
| 1213 |
arg.allcxx . . $ $anonymous_type_aa62bfaa706685ea_2#all. = purge_all; |
| 1214 |
arg.validitycxx . . $ $anonymous_type_aa62bfaa706685ea_2#validity. = validity_period; |
| 1215 |
arg.gracecxx . . $ $anonymous_type_aa62bfaa706685ea_2#grace. = grace_period; |
| 1216 |
|
| 1217 |
if ( purge_period == 0 || now_time >= last_time + purge_period ) { |
| 1218 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "purging database: ..." ); |
| 1219 |
ret = sdb_updateiteratecxx . . $ sdb_updateiterate(11caef27b9582e).( db, sdb_cb_token_matchercxx . . $ sdb_cb_token_matcher(8ae94fcf4f89b591)., (void*)&arg, err ); |
| 1220 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, ret ? "done\n" : "failed\n" ); |
| 1221 |
} else { |
| 1222 |
ret = 1; |
| 1223 |
} |
| 1224 |
return ret; |
| 1225 |
} |
| 1226 |
|
| 1227 |
void db_opencxx . . $ db_open(5c57a783a5f80a21).( DBcxx . . $ DB#* db, const char* db_filename ) { |
| 1228 |
int err; |
| 1229 |
if (!hashcash_db_opencxx . . $ hashcash_db_open(e27edb077ed1b892).( db, db_filename, &err )) { diecxx . . $ die(d4f767463ce0a6b3).(err); } |
| 1230 |
} |
| 1231 |
|
| 1232 |
int db_incxx . . $ db_in(237208b940db5468).( DBcxx . . $ DB#* db, char* token, char *period ) { |
| 1233 |
int err = 0; |
| 1234 |
int res; |
| 1235 |
|
| 1236 |
res = hashcash_db_incxx . . $ hashcash_db_in(c165a313c805dd0c).( db, token, period, &err ); |
| 1237 |
if ( err ) { diecxx . . $ die(d4f767463ce0a6b3).( err ); } |
| 1238 |
return res; |
| 1239 |
} |
| 1240 |
|
| 1241 |
void db_addcxx . . $ db_add(18d537d5cf8b8e63).( DBcxx . . $ DB#* db, char* token, char *period ) { |
| 1242 |
int err = 0; |
| 1243 |
if ( !hashcash_db_addcxx . . $ hashcash_db_add(c165a313c805dd0c).( db, token, period, &err ) ) { |
| 1244 |
diecxx . . $ die(d4f767463ce0a6b3).( err ); |
| 1245 |
} |
| 1246 |
} |
| 1247 |
|
| 1248 |
void db_closecxx . . $ db_close(14613a252c7791ed).( DBcxx . . $ DB#* db ) { |
| 1249 |
int err = 0; |
| 1250 |
if ( !hashcash_db_closecxx . . $ hashcash_db_close(f4f73c0fb9625ddd).( db, &err ) ) { |
| 1251 |
diecxx . . $ die(d4f767463ce0a6b3).( err ); |
| 1252 |
} |
| 1253 |
} |
| 1254 |
|
| 1255 |
/* num = start size, auto-grows */ |
| 1256 |
|
| 1257 |
void array_alloccxx . . $ array_alloc(f36c4182aaae5413).( ARRAYcxx . . $ ARRAY#* array, int num ) { |
| 1258 |
array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num. = 0; |
| 1259 |
array->maxcxx . . $ $anonymous_type_aa62bfaa706685ea_1#max. = num; |
| 1260 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt. = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).( sizeof( ELEMENTcxx . . $ ELEMENT# ) * num ); |
| 1261 |
if ( array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { die_msgcxx . . $ die_msg(85c52e162fed56f9).( "out of memory" ); } |
| 1262 |
} |
| 1263 |
|
| 1264 |
/* auto-grow array */ |
| 1265 |
|
| 1266 |
void array_pushcxx . . $ array_push(1afc9a320aea9297).( ARRAYcxx . . $ ARRAY#* array, const char *str, int type, int case_flag, |
| 1267 |
long validity, long grace, long anon, int width, int bits, |
| 1268 |
int over ) |
| 1269 |
{ |
| 1270 |
if ( array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num. >= array->maxcxx . . $ $anonymous_type_aa62bfaa706685ea_1#max. ) { |
| 1271 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt. = realloccxx . . $ realloc(417ab160f6baadc6).( array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt., sizeof( ELEMENTcxx . . $ ELEMENT#) * array->maxcxx . . $ $anonymous_type_aa62bfaa706685ea_1#max. * 2 ); |
| 1272 |
if ( array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { die_msgcxx . . $ die_msg(85c52e162fed56f9).( "out of memory" ); } |
| 1273 |
array->maxcxx . . $ $anonymous_type_aa62bfaa706685ea_1#max. *= 2; |
| 1274 |
} |
| 1275 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].regexpcxx . . $ $anonymous_type_aa62bfaa706685ea_0#regexp. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; /* compiled regexp */ |
| 1276 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].typecxx . . $ $anonymous_type_aa62bfaa706685ea_0#type. = type; |
| 1277 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].case_flagcxx . . $ $anonymous_type_aa62bfaa706685ea_0#case_flag. = case_flag; |
| 1278 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].validitycxx . . $ $anonymous_type_aa62bfaa706685ea_0#validity. = validity; |
| 1279 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].gracecxx . . $ $anonymous_type_aa62bfaa706685ea_0#grace. = grace; |
| 1280 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].anoncxx . . $ $anonymous_type_aa62bfaa706685ea_0#anon. = anon; |
| 1281 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].widthcxx . . $ $anonymous_type_aa62bfaa706685ea_0#width. = width; |
| 1282 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits. = bits; |
| 1283 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].overcxx . . $ $anonymous_type_aa62bfaa706685ea_0#over. = over; |
| 1284 |
if ( str ) { |
| 1285 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. = strdupcxx . . $ strdup(a8b8e32347182212).( str ); |
| 1286 |
if ( array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { |
| 1287 |
die_msgcxx . . $ die_msg(85c52e162fed56f9).( "out of memory" ); |
| 1288 |
} |
| 1289 |
} else { |
| 1290 |
array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt.[array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.].strcxx . . $ $anonymous_type_aa62bfaa706685ea_0#str. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1291 |
} |
| 1292 |
array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num.++; |
| 1293 |
} |
| 1294 |
|
| 1295 |
int bit_cmpcxx . . $ bit_cmp(9148c8c3ff42c9d8).( const void* ap, const void* bp ) |
| 1296 |
{ |
| 1297 |
ELEMENTcxx . . $ ELEMENT#* a = (ELEMENTcxx . . $ ELEMENT#*) ap; |
| 1298 |
ELEMENTcxx . . $ ELEMENT#* b = (ELEMENTcxx . . $ ELEMENT#*) bp; |
| 1299 |
|
| 1300 |
return a->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits. == b->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits. ? 0 : ( a->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits. < b->bitscxx . . $ $anonymous_type_aa62bfaa706685ea_0#bits. ? 1 : -1 ); |
| 1301 |
} |
| 1302 |
|
| 1303 |
void array_sortcxx . . $ array_sort(1a42aa0a13f60ad8).( ARRAYcxx . . $ ARRAY#* array, int(*cmp)(const void*, const void*) ) |
| 1304 |
{ |
| 1305 |
qsortcxx . . $ qsort(ebb60b13a65e77d7).( array->eltcxx . . $ $anonymous_type_aa62bfaa706685ea_1#elt., array->numcxx . . $ $anonymous_type_aa62bfaa706685ea_1#num., sizeof( ELEMENTcxx . . $ ELEMENT# ), cmp ); |
| 1306 |
} |
| 1307 |
|
| 1308 |
void diecxx . . $ die(d4f767463ce0a6b3).( int err ) |
| 1309 |
{ |
| 1310 |
const char* str = ""; |
| 1311 |
|
| 1312 |
switch ( err ) { |
| 1313 |
case EOKcxx . . $ `hashcash.c:47:9`!: |
| 1314 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! ); |
| 1315 |
break; |
| 1316 |
case EINPUTcxx . . $ `hashcash.c:48:9`!: |
| 1317 |
str = "invalid inputs"; |
| 1318 |
break; |
| 1319 |
default: |
| 1320 |
str = strerrorcxx . . $ strerror(ff224f080444ee45).( err ); |
| 1321 |
break; |
| 1322 |
} |
| 1323 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: %s\n", str ); |
| 1324 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_ERRORcxx . . $ `hashcash.c:53:9`! ); |
| 1325 |
} |
| 1326 |
|
| 1327 |
void die_msgcxx . . $ die_msg(85c52e162fed56f9).( const char* str ) |
| 1328 |
{ |
| 1329 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, str ); |
| 1330 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n" ); |
| 1331 |
exitcxx . . $ exit(3ca292c338df9bb3).( EXIT_ERRORcxx . . $ `hashcash.c:53:9`! ); |
| 1332 |
} |
| 1333 |
|
| 1334 |
/* remove unix, DOS and MAC linefeeds from line ending */ |
| 1335 |
|
| 1336 |
void chomplfcxx . . $ chomplf(fda57c8427c60377).( char* token ) { |
| 1337 |
int tok_len = strlencxx . . $ strlen(751346f8406fd082).(token); |
| 1338 |
if ( token[tok_len-1] == '\n' ) { token[--tok_len] = '\0'; } |
| 1339 |
if ( token[tok_len-1] == '\r' ) { token[--tok_len] = '\0'; } |
| 1340 |
if ( token[tok_len-1] == '\n' ) { token[--tok_len] = '\0'; } |
| 1341 |
} |
| 1342 |
|
| 1343 |
void trimspacecxx . . $ trimspace(fda57c8427c60377).( char* token ) { |
| 1344 |
int tok_len = strlencxx . . $ strlen(751346f8406fd082).(token); |
| 1345 |
int tok_begin = 0; |
| 1346 |
while ( tok_begin < tok_len && isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(token[tok_begin]) ) { |
| 1347 |
tok_begin++; |
| 1348 |
} |
| 1349 |
if ( tok_begin > 0 ) { |
| 1350 |
tok_len -= tok_begin; |
| 1351 |
memmovecxx . . $ memmove(cc817cb175f282d).( token, token+tok_begin, strlencxx . . $ strlen(751346f8406fd082).(token+tok_begin)+1 ); |
| 1352 |
} |
| 1353 |
while ( tok_len > 0 && isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(token[tok_len-1]) ) { |
| 1354 |
token[--tok_len] = '\0'; |
| 1355 |
} |
| 1356 |
} |
| 1357 |
|
| 1358 |
double report_speedcxx . . $ report_speed(73d891ffc41e4d2c).( int bits, double* time_est, int display ) |
| 1359 |
{ |
| 1360 |
double te = 0; |
| 1361 |
double tries_expected = hashcash_expected_triescxx . . $ hashcash_expected_tries(4badf5dbac1308a7).( bits ); |
| 1362 |
|
| 1363 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "mint: %d bit partial hash preimage\n", bits ); |
| 1364 |
VPRINTFcxx . . $ `hashcash.c:74:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "expected: %.0f tries (= 2^%d tries)\n", |
| 1365 |
tries_expected, bits ); |
| 1366 |
|
| 1367 |
if ( time_est ) { *time_est = hc_est_timecxx . . $ `hashcash.c:142:9`!( bits ); } |
| 1368 |
|
| 1369 |
if ( display ) { |
| 1370 |
te = hc_est_timecxx . . $ `hashcash.c:142:9`!( bits ); |
| 1371 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "time estimate: %.0f seconds", te ); |
| 1372 |
if ( te > TIME_AEONcxx . . $ `hashcash.h:52:9`! ) { |
| 1373 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f aeons)", te / TIME_AEONcxx . . $ `hashcash.h:52:9`! ); |
| 1374 |
} else if ( te > TIME_YEARcxx . . $ `hashcash.h:50:9`! * 10 ) { |
| 1375 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f years)", te / TIME_YEARcxx . . $ `hashcash.h:50:9`! ); |
| 1376 |
} else if ( te > TIME_YEARcxx . . $ `hashcash.h:50:9`! ) { |
| 1377 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.1f years)", te / TIME_YEARcxx . . $ `hashcash.h:50:9`! ); |
| 1378 |
} else if ( te > TIME_MONTHcxx . . $ `hashcash.h:51:9`! ) { |
| 1379 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.1f months)", te / TIME_MONTHcxx . . $ `hashcash.h:51:9`! ); |
| 1380 |
} else if ( te > TIME_DAYcxx . . $ `hashcash.h:49:9`! * 10 ) { |
| 1381 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f days)", te / TIME_DAYcxx . . $ `hashcash.h:49:9`! ); |
| 1382 |
} else if ( te > TIME_DAYcxx . . $ `hashcash.h:49:9`! ) { |
| 1383 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.1f days)", te / TIME_DAYcxx . . $ `hashcash.h:49:9`! ); |
| 1384 |
} else if ( te > TIME_HOURcxx . . $ `hashcash.h:48:9`! ) { |
| 1385 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f hours)", te / TIME_HOURcxx . . $ `hashcash.h:48:9`! ); |
| 1386 |
} else if ( te > TIME_MINUTEcxx . . $ `hashcash.h:47:9`! ) { |
| 1387 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f minutes)", te / TIME_MINUTEcxx . . $ `hashcash.h:47:9`! ); |
| 1388 |
} else if ( te > 1 ) { |
| 1389 |
/* already printed seconds */ |
| 1390 |
} else if ( te > TIME_MILLI_SECONDcxx . . $ `hashcash.h:53:9`! ) { |
| 1391 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f milli-seconds)", |
| 1392 |
te / TIME_MILLI_SECONDcxx . . $ `hashcash.h:53:9`! ); |
| 1393 |
} else if ( te > TIME_MICRO_SECONDcxx . . $ `hashcash.h:54:9`! ) { |
| 1394 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f micro-seconds)", |
| 1395 |
te / TIME_MICRO_SECONDcxx . . $ `hashcash.h:54:9`! ); |
| 1396 |
} else if ( te > TIME_NANO_SECONDcxx . . $ `hashcash.h:55:9`! ) { |
| 1397 |
QPRINTFcxx . . $ `hashcash.c:72:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, " (%.0f nano-seconds)", |
| 1398 |
te / TIME_NANO_SECONDcxx . . $ `hashcash.h:55:9`! ); |
| 1399 |
} |
| 1400 |
QPUTScxx . . $ `hashcash.c:76:9`!( stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n" ); |
| 1401 |
} |
| 1402 |
return tries_expected; |
| 1403 |
} |
| 1404 |
|
| 1405 |
int read_appendcxx . . $ read_append(bca297112e895168).( char** s, int* smax, int* alloc, char* append ) |
| 1406 |
{ |
| 1407 |
int slen = strlencxx . . $ strlen(751346f8406fd082).( *s ); |
| 1408 |
int alen = strlencxx . . $ strlen(751346f8406fd082).( append ); |
| 1409 |
|
| 1410 |
if ( slen + alen > *smax ) { |
| 1411 |
if ( *alloc ) { |
| 1412 |
*s = realloccxx . . $ realloc(417ab160f6baadc6).( *s, slen+alen+1 ); |
| 1413 |
} else { |
| 1414 |
*s = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).( slen+alen+1 ); |
| 1415 |
*alloc = 1; |
| 1416 |
} |
| 1417 |
if ( *s == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! ) { return 0; } /* out of memory */ |
| 1418 |
} |
| 1419 |
sstrncpycxx . . $ `sstring.h:3:9`!( (*s)+slen, append, alen ); |
| 1420 |
return 1; |
| 1421 |
} |
| 1422 |
|
| 1423 |
char *read_headercxx . . $ read_header(a66d455f0d9c8a09).( FILEcxx . . $ FILE#* f, char** s, int* smax, int* alloc, |
| 1424 |
char* a, int amax ) |
| 1425 |
{ |
| 1426 |
char* junk; |
| 1427 |
|
| 1428 |
(*s)[0] = '\0'; |
| 1429 |
if ( a[0] ) { |
| 1430 |
sstrncpycxx . . $ `sstring.h:3:9`!( *s, a, *smax ); |
| 1431 |
} else { |
| 1432 |
junk = fgetscxx . . $ fgets(efb0aaba7ac866ae).( *s, *smax, f ); |
| 1433 |
chomplfcxx . . $ chomplf(fda57c8427c60377).( *s ); |
| 1434 |
} |
| 1435 |
|
| 1436 |
do { |
| 1437 |
a[0] = '\0'; |
| 1438 |
junk = fgetscxx . . $ fgets(efb0aaba7ac866ae).( a, amax, f ); |
| 1439 |
chomplfcxx . . $ chomplf(fda57c8427c60377).( a ); |
| 1440 |
if ( a[0] == '\t' || a[0] == ' ') { |
| 1441 |
read_appendcxx . . $ read_append(bca297112e895168).( s, smax, alloc, a+1 ); |
| 1442 |
} |
| 1443 |
} while ( a[0] == '\t' || a[0] == ' ' ); |
| 1444 |
|
| 1445 |
return *s; |
| 1446 |
} |
| 1447 |
|
| 1448 |
int read_eofcxx . . $ read_eof(9f4384670e65005f).( FILEcxx . . $ FILE#* fp, char* a ) |
| 1449 |
{ |
| 1450 |
return feofcxx . . $ feof(89bc1efcdac0ca22).(fp) && a[0] == '\0'; |
| 1451 |
} |
| 1452 |
|
| 1453 |
void mystolowercxx . . $ mystolower(fda57c8427c60377).( char* str ) { |
| 1454 |
if ( !str ) { return; } |
| 1455 |
for ( ; *str; str++ ) { |
| 1456 |
*str = tolowercxx . . $ `<external>/17904084882347303253/ctype.h:220:11`!( *str ); |
| 1457 |
} |
| 1458 |
} |