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.4 by root, Mon Oct 20 04:17:05 2003 UTC vs.
Revision 1.5 by root, Mon Oct 20 04:31:25 2003 UTC

17/* pcg: I was tempted to just rip this code off, after all, if you don't 17/* pcg: I was tempted to just rip this code off, after all, if you don't
18 * demand anything I am inclined not to give anything. *Sigh* something 18 * demand anything I am inclined not to give anything. *Sigh* something
19 * kept me from doing it, so here's the truth: I took this code from the 19 * kept me from doing it, so here's the truth: I took this code from the
20 * SHA1 perl module, since it looked reasonably well-crafted. I modified 20 * SHA1 perl module, since it looked reasonably well-crafted. I modified
21 * it here and there, though. 21 * it here and there, though.
22 */
23
24/*
25 * we have lots of micro-optimizations here, this is just for toying
26 * around...
22 */ 27 */
23 28
24/* don't expect _too_ much from compilers for now. */ 29/* don't expect _too_ much from compilers for now. */
25#if __GNUC__ > 2 30#if __GNUC__ > 2
26# define restrict __restrict__ 31# define restrict __restrict__
30# endif 35# endif
31#elif __STDC_VERSION__ < 199900 36#elif __STDC_VERSION__ < 199900
32# define restrict 37# define restrict
33# define inline 38# define inline
34#endif 39#endif
40
41#if __GNUC__ < 2
42# define __attribute__(x)
43#endif
44
45#ifdef __i386
46# define a_regparm(n) __attribute__((__regparm__(n)))
47#else
48# define a_regparm(n)
49#endif
50
51#define a_const __attribute__((__const__))
35 52
36/* Useful defines & typedefs */ 53/* Useful defines & typedefs */
37 54
38#if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321))) 55#if defined(U64TYPE) && (defined(USE_64_BIT_INT) || ((BYTEORDER != 0x1234) && (BYTEORDER != 0x4321)))
39typedef U64TYPE ULONG; 56typedef U64TYPE ULONG;
51#if GCCX86ASM 68#if GCCX86ASM
52# define zprefix(n) ({ int _r; __asm__ ("bsrl %1, %0" : "=r" (_r) : "r" (n)); 31 - _r ; }) 69# define zprefix(n) ({ int _r; __asm__ ("bsrl %1, %0" : "=r" (_r) : "r" (n)); 31 - _r ; })
53#elif __GNUC__ > 2 && __GNUC_MINOR__ > 3 70#elif __GNUC__ > 2 && __GNUC_MINOR__ > 3
54# define zprefix(n) (__extension__ ({ uint32_t n__ = (n); n ? __builtin_clz (n) : 32; })) 71# define zprefix(n) (__extension__ ({ uint32_t n__ = (n); n ? __builtin_clz (n) : 32; }))
55#else 72#else
56static int zprefix (ULONG n) 73static int a_const zprefix (ULONG n)
57{ 74{
58 static char zp[256] = 75 static char zp[256] =
59 { 76 {
60 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, 77 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
61 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 78 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
129 B = T32(R32(C,5) + f##n(D,E,T) + A + *WP++ + CONST##n); D = R32(D,30) 146 B = T32(R32(C,5) + f##n(D,E,T) + A + *WP++ + CONST##n); D = R32(D,30)
130 147
131#define FT(n) \ 148#define FT(n) \
132 A = T32(R32(B,5) + f##n(C,D,E) + T + *WP++ + CONST##n); C = R32(C,30) 149 A = T32(R32(B,5) + f##n(C,D,E) + T + *WP++ + CONST##n); C = R32(C,30)
133 150
134static void sha_transform(SHA_INFO *restrict sha_info) 151static void a_regparm(1) sha_transform(SHA_INFO *restrict sha_info)
135{ 152{
136 int i; 153 int i;
137 U8 *dp; 154 U8 *restrict dp;
138 ULONG T, A, B, C, D, E, W[80], *restrict WP; 155 ULONG T, A, B, C, D, E, W[80], *restrict WP;
139 156
140 dp = sha_info->data; 157 dp = sha_info->data;
141 158
142#if BYTEORDER == 0x1234 159#if BYTEORDER == 0x1234

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines