ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Digest-Hashcash/Hashcash.xs
(Generate patch)

Comparing Digest-Hashcash/Hashcash.xs (file contents):
Revision 1.2 by root, Sun Sep 7 00:58:23 2003 UTC vs.
Revision 1.4 by root, Mon Oct 20 04:17:05 2003 UTC

35 35
36/* Useful defines & typedefs */ 36/* Useful defines & typedefs */
37 37
38#if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321))) 38#if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321)))
39typedef U64TYPE ULONG; 39typedef U64TYPE ULONG;
40# if BYTEORDER == 0x1234 40# if BYTEORDER == 0x1234
41# undef BYTEORDER 41# undef BYTEORDER
42# define BYTEORDER 0x12345678 42# define BYTEORDER 0x12345678
43# elif BYTEORDER == 0x4321 43# elif BYTEORDER == 0x4321
44# undef BYTEORDER 44# undef BYTEORDER
45# define BYTEORDER 0x87654321 45# define BYTEORDER 0x87654321
46# endif 46# endif
47#else 47#else
48typedef uint_fast32_t ULONG; /* 32-or-more-bit quantity */ 48typedef uint_fast32_t ULONG; /* 32-or-more-bit quantity */
49#endif 49#endif
50 50
51#if GCCX86ASM 51#if GCCX86ASM
52# define zprefix(n) ({ int _r; __asm__ ("bsrl %1, %0" : "=r" (_r) : "r" (n)); 31 - _r ; }) 52# define zprefix(n) ({ int _r; __asm__ ("bsrl %1, %0" : "=r" (_r) : "r" (n)); 31 - _r ; })
53#elif __GNUC__ > 2 && __GNUC_MINOR__ > 3
54# define zprefix(n) (__extension__ ({ uint32_t n__ = (n); n ? __builtin_clz (n) : 32; }))
53#else 55#else
54static int zprefix (ULONG n) 56static int zprefix (ULONG n)
55{ 57{
56 static char zp[256] = 58 static char zp[256] =
57 { 59 {
324 326
325# could be improved quite a bit in accuracy 327# could be improved quite a bit in accuracy
326NV 328NV
327_estimate_rounds () 329_estimate_rounds ()
328 CODE: 330 CODE:
331{
329 char data[40]; 332 char data[40];
330 NVTime nvtime = get_nvtime (); 333 NVTime nvtime = get_nvtime ();
331 NV t1, t2, t; 334 NV t1, t2, t;
332 int count = 0; 335 int count = 0;
333 SHA_INFO ctx; 336 SHA_INFO ctx;
348 t2 = nvtime (); 351 t2 = nvtime ();
349 352
350 } while (t == t2); 353 } while (t == t2);
351 354
352 RETVAL = (NV)count / (t2 - t1); 355 RETVAL = (NV)count / (t2 - t1);
356}
353 OUTPUT: 357 OUTPUT:
354 RETVAL 358 RETVAL
355 359
356SV * 360SV *
357_gentoken (int size, IV timestamp, char *resource, char *trial = "", int extrarand = 0) 361_gentoken (int size, IV timestamp, char *resource, char *trial = "", int extrarand = 0)
358 CODE: 362 CODE:
363{
359 SHA_INFO ctx1, ctx; 364 SHA_INFO ctx1, ctx;
360 char *token, *seq, *s; 365 char *token, *seq, *s;
361 int toklen, i; 366 int toklen, i;
362 time_t tstamp = timestamp ? timestamp : time (0); 367 time_t tstamp = timestamp ? timestamp : time (0);
363 struct tm *tm = gmtime (&tstamp); 368 struct tm *tm = gmtime (&tstamp);
410 *s = nextenc [*s]; 415 *s = nextenc [*s];
411 } while (*s++ == 'a'); 416 } while (*s++ == 'a');
412 } 417 }
413 418
414 RETVAL = newSVpvn (token, toklen); 419 RETVAL = newSVpvn (token, toklen);
420}
415 OUTPUT: 421 OUTPUT:
416 RETVAL 422 RETVAL
417 423
418int 424int
419_prefixlen (SV *tok) 425_prefixlen (SV *tok)
420 CODE: 426 CODE:
427{
421 STRLEN toklen; 428 STRLEN toklen;
422 char *token = SvPV (tok, toklen); 429 char *token = SvPV (tok, toklen);
423 SHA_INFO ctx; 430 SHA_INFO ctx;
424 431
425 sha_init (&ctx); 432 sha_init (&ctx);
426 sha_update (&ctx, token, toklen); 433 sha_update (&ctx, token, toklen);
427 RETVAL = sha_final (&ctx); 434 RETVAL = sha_final (&ctx);
435}
428 OUTPUT: 436 OUTPUT:
429 RETVAL 437 RETVAL
430 438
431 439

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines