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.6 by root, Sun Jun 27 13:30:43 2004 UTC vs.
Revision 1.7 by root, Tue Jul 21 05:01:01 2015 UTC

3#include "XSUB.h" 3#include "XSUB.h"
4 4
5#include <time.h> 5#include <time.h>
6#include <stdlib.h> 6#include <stdlib.h>
7#include <stdint.h> 7#include <stdint.h>
8
9#include "perlmulticore.h"
8 10
9/* NIST Secure Hash Algorithm */ 11/* NIST Secure Hash Algorithm */
10/* heavily modified by Uwe Hollerbach <uh@alumni.caltech edu> */ 12/* heavily modified by Uwe Hollerbach <uh@alumni.caltech edu> */
11/* from Peter C. Gutmann's implementation as found in */ 13/* from Peter C. Gutmann's implementation as found in */
12/* Applied Cryptography by Bruce Schneier */ 14/* Applied Cryptography by Bruce Schneier */
57# if BYTEORDER == 0x1234 59# if BYTEORDER == 0x1234
58# undef BYTEORDER 60# undef BYTEORDER
59# define BYTEORDER 0x12345678 61# define BYTEORDER 0x12345678
60# elif BYTEORDER == 0x4321 62# elif BYTEORDER == 0x4321
61# undef BYTEORDER 63# undef BYTEORDER
62# define BYTEORDER 0x87654321 64# define BYTEORDER 0x87654321
63# endif 65# endif
64#else 66#else
65typedef uint_fast32_t ULONG; /* 32-or-more-bit quantity */ 67typedef uint_fast32_t ULONG; /* 32-or-more-bit quantity */
66#endif 68#endif
67 69
302 : zprefix (sha_info->digest[1]) + 32; 304 : zprefix (sha_info->digest[1]) + 32;
303} 305}
304 306
305#define TRIALCHAR "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&()*+,-./;<=>?@[]{}^_|" 307#define TRIALCHAR "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!#$%&()*+,-./;<=>?@[]{}^_|"
306 308
307static char nextenc[256]; 309static char
310nextenc[256];
308 311
309static char rand_char () 312static char
313rand_char ()
310{ 314{
311 return TRIALCHAR[rand () % sizeof (TRIALCHAR)]; 315 return TRIALCHAR[(int)(Drand01 () * sizeof (TRIALCHAR))];
312} 316}
313 317
314typedef double (*NVTime)(void); 318typedef double (*NVTime)(void);
315 319
316static double simple_nvtime (void) 320static double
321simple_nvtime (void)
317{ 322{
318 return time (0); 323 return time (0);
319} 324}
320 325
321static NVTime get_nvtime (void) 326static NVTime
327get_nvtime (void)
322{ 328{
323 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0); 329 SV **svp = hv_fetch (PL_modglobal, "Time::NVtime", 12, 0);
324 330
325 if (svp && SvIOK(*svp)) 331 if (svp && SvIOK(*svp))
326 return INT2PTR(NVTime, SvIV(*svp)); 332 return INT2PTR(NVTime, SvIV(*svp));
404 resource, trial); 410 resource, trial);
405 411
406 if (toklen > 8000) 412 if (toklen > 8000)
407 croak ("token length must be <= 8000 in this implementation\n"); 413 croak ("token length must be <= 8000 in this implementation\n");
408 414
415 perlinterp_release ();
416
409 i = toklen + extrarand; 417 i = toklen + extrarand;
410 while (toklen < i) 418 while (toklen < i)
411 token[toklen++] = rand_char (); 419 token[toklen++] = rand_char ();
412 420
413 sha_init (&ctx1); 421 sha_init (&ctx1);
431 do { 439 do {
432 *s = nextenc [*s]; 440 *s = nextenc [*s];
433 } while (*s++ == 'a'); 441 } while (*s++ == 'a');
434 } 442 }
435 443
444 perlinterp_acquire ();
445
436 RETVAL = newSVpvn (token, toklen); 446 RETVAL = newSVpvn (token, toklen);
437} 447}
438 OUTPUT: 448 OUTPUT:
439 RETVAL 449 RETVAL
440 450

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines