author | Mahlon E. Smith <mahlon@laika.com> |
Tue, 16 May 2017 16:03:03 -0700 | |
changeset 22 | d1b9dd767e3a |
parent 16 | e135ccae6783 |
child 23 | eedb2586dea4 |
permissions | -rw-r--r-- |
16
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
1 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
2 |
#include <ruby.h> |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
3 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
4 |
static VALUE rb_mEzmlm; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
5 |
static VALUE rb_cEZHash; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
6 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
7 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
8 |
#ifndef SURF_H |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
9 |
#define SURF_H |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
10 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
11 |
#define ROTATE(x,b) (((x) << (b)) | ((x) >> (32 - (b)))) |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
12 |
#define MUSH(i,b) x = t[i] += (((x ^ seed[i]) + sum) ^ ROTATE(x,b)); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
13 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
14 |
typedef struct { |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
15 |
unsigned int seed[32]; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
16 |
unsigned int sum[8]; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
17 |
unsigned int out[8]; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
18 |
unsigned int in[12]; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
19 |
int todo; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
20 |
} surfpcs; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
21 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
22 |
static const unsigned int littleendian[8] = { |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
23 |
0x03020100, 0x07060504, 0x0b0a0908, 0x0f0e0d0c, |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
24 |
0x13121110, 0x17161514, 0x1b1a1918, 0x1f1e1d1c |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
25 |
} ; |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
26 |
#define end ((unsigned char *) &littleendian) |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
27 |
#define data ((unsigned char *) s->in) |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
28 |
#define outdata ((unsigned char *) s->out) |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
29 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
30 |
extern void surf( unsigned int out[8], const unsigned int in[12], const unsigned int seed[32] ); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
31 |
extern void surfpcs_init( surfpcs *s, const unsigned int k[32] ); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
32 |
extern void surfpcs_add( surfpcs *s, const char *x,unsigned int n ); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
33 |
extern void surfpcs_addlc( surfpcs *s, const char *x,unsigned int n ); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
34 |
extern void surfpcs_out( surfpcs *s, unsigned char h[32] ); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
35 |
#endif |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
36 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
37 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
38 |
#ifndef SUBHASH_H |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
39 |
#define SUBHASH_H |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
40 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
41 |
unsigned int subhashs(const char *s); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
42 |
unsigned int subhashb(const char *s,long len); |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
43 |
#define subhashsa(SA) subhashb((SA)->s,(SA)->len) |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
44 |
|
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
45 |
#endif |
e135ccae6783
Migrate hashing functions to C.
Mahlon E. Smith <mahlon@laika.com>
parents:
diff
changeset
|
46 |