ext/ezmlm/hash/hash.h
author Mahlon E. Smith <mahlon@martini.nu>
Mon, 02 Sep 2019 09:00:47 -0700
changeset 27 a629597fd647
parent 23 eedb2586dea4
permissions -rw-r--r--
Bye, Bitbucket.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
23
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    30
static void surf( unsigned int out[8], const unsigned int in[12], const unsigned int seed[32] );
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    31
static void surfpcs_init( surfpcs *s, const unsigned int k[32] );
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    32
static void surfpcs_add( surfpcs *s, const char *x,unsigned int n );
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    33
static void surfpcs_addlc( surfpcs *s, const char *x,unsigned int n );
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    34
static void surfpcs_out( surfpcs *s, unsigned char h[32] );
16
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
23
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    41
static unsigned int subhashs(const char *s);
eedb2586dea4 Tag C functions as static to avoid name collisions.
Mahlon E. Smith <mahlon@laika.com>
parents: 16
diff changeset
    42
static unsigned int subhashb(const char *s,long len);
16
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