Ruby  2.5.0dev(2017-10-22revision60238)
Data Structures | Macros | Functions
siphash.c File Reference
#include <string.h>
#include <stdio.h>
#include "siphash.h"
#include <endian.h>

Go to the source code of this file.

Data Structures

struct  sip_interface_st
 

Macros

#define SIP_HASH_STREAMING   1
 
#define LITTLE_ENDIAN   __LITTLE_ENDIAN
 
#define BIG_ENDIAN   __BIG_ENDIAN
 
#define lo   u32[0]
 
#define hi   u32[1]
 
#define UNALIGNED_WORD_ACCESS   0
 
#define U8TO32_LE(p)
 
#define U32TO8_LE(p, v)
 
#define U8TO64_LE(p)   u8to64_le(p)
 
#define U64TO8_LE(p, v)   u64to8_le(p, v)
 
#define ROTL64_TO(v, s)
 
#define ADD64_TO(v, s)   add64_to(&(v), (s))
 
#define XOR64_TO(v, s)   xor64_to(&(v), (s))
 
#define XOR64_INT(v, x)   ((v).lo ^= (x))
 
#define sip_init_state   sip_init_state_bin.u64
 
#define SIP_COMPRESS(v0, v1, v2, v3)
 
#define SIP_ROUND(m, v0, v1, v2, v3)
 
#define OR_BYTE(n)
 

Functions

sip_hashsip_hash_new (const uint8_t key[16], int c, int d)
 
sip_hashsip_hash_init (sip_hash *h, const uint8_t key[16], int c, int d)
 
int sip_hash_update (sip_hash *h, const uint8_t *msg, size_t len)
 
int sip_hash_final (sip_hash *h, uint8_t **digest, size_t *len)
 
int sip_hash_final_integer (sip_hash *h, uint64_t *digest)
 
int sip_hash_digest (sip_hash *h, const uint8_t *data, size_t data_len, uint8_t **digest, size_t *digest_len)
 
int sip_hash_digest_integer (sip_hash *h, const uint8_t *data, size_t data_len, uint64_t *digest)
 
void sip_hash_free (sip_hash *h)
 
void sip_hash_dump (sip_hash *h)
 
uint64_t sip_hash13 (const uint8_t key[16], const uint8_t *data, size_t len)
 

Macro Definition Documentation

◆ ADD64_TO

#define ADD64_TO (   v,
 
)    add64_to(&(v), (s))

Definition at line 112 of file siphash.c.

◆ BIG_ENDIAN

#define BIG_ENDIAN   __BIG_ENDIAN

Definition at line 17 of file siphash.c.

◆ hi

#define hi   u32[1]

Definition at line 22 of file siphash.c.

◆ LITTLE_ENDIAN

#define LITTLE_ENDIAN   __LITTLE_ENDIAN

Definition at line 14 of file siphash.c.

◆ lo

#define lo   u32[0]

Definition at line 21 of file siphash.c.

◆ OR_BYTE

#define OR_BYTE (   n)
Value:
do { \
if (n >= 4) \
last.hi |= ((uint32_t) end[n]) << ((n) >= 4 ? (n) * 8 - 32 : 0); \
else \
last.lo |= ((uint32_t) end[n]) << ((n) >= 4 ? 0 : (n) * 8); \
} while (0)
unsigned int uint32_t
Definition: sha2.h:101

Referenced by sip_hash13().

◆ ROTL64_TO

#define ROTL64_TO (   v,
 
)
Value:
((s) > 32 ? rotl64_swap(rotl64_to(&(v), (s) - 32)) : \
(s) == 32 ? rotl64_swap(&(v)) : rotl64_to(&(v), (s)))

Definition at line 91 of file siphash.c.

◆ SIP_COMPRESS

#define SIP_COMPRESS (   v0,
  v1,
  v2,
  v3 
)
Value:
do { \
ADD64_TO((v0), (v1)); \
ADD64_TO((v2), (v3)); \
ROTL64_TO((v1), 13); \
ROTL64_TO((v3), 16); \
XOR64_TO((v1), (v0)); \
XOR64_TO((v3), (v2)); \
ROTL64_TO((v0), 32); \
ADD64_TO((v2), (v1)); \
ADD64_TO((v0), (v3)); \
ROTL64_TO((v1), 17); \
ROTL64_TO((v3), 21); \
XOR64_TO((v1), (v2)); \
XOR64_TO((v3), (v0)); \
ROTL64_TO((v2), 32); \
} while(0)

Definition at line 158 of file siphash.c.

Referenced by sip_hash13().

◆ SIP_HASH_STREAMING

#define SIP_HASH_STREAMING   1

Definition at line 5 of file siphash.c.

◆ sip_init_state

#define sip_init_state   sip_init_state_bin.u64

Definition at line 138 of file siphash.c.

Referenced by sip_hash13().

◆ SIP_ROUND

#define SIP_ROUND (   m,
  v0,
  v1,
  v2,
  v3 
)
Value:
do { \
XOR64_TO((v3), (m)); \
SIP_COMPRESS(v0, v1, v2, v3); \
XOR64_TO((v0), (m)); \
} while (0)

Definition at line 389 of file siphash.c.

Referenced by sip_hash13().

◆ U32TO8_LE

#define U32TO8_LE (   p,
 
)
Value:
do { \
(p)[0] = (uint8_t)((v) ); \
(p)[1] = (uint8_t)((v) >> 8); \
(p)[2] = (uint8_t)((v) >> 16); \
(p)[3] = (uint8_t)((v) >> 24); \
} while (0)
unsigned char uint8_t
Definition: sha2.h:100

Definition at line 46 of file siphash.c.

◆ U64TO8_LE

#define U64TO8_LE (   p,
 
)    u64to8_le(p, v)

Definition at line 83 of file siphash.c.

Referenced by sip_hash_final().

◆ U8TO32_LE

#define U8TO32_LE (   p)
Value:
(((uint32_t)((p)[0]) ) | ((uint32_t)((p)[1]) << 8) | \
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24)) \
unsigned int uint32_t
Definition: sha2.h:101

Definition at line 42 of file siphash.c.

◆ U8TO64_LE

#define U8TO64_LE (   p)    u8to64_le(p)

Definition at line 73 of file siphash.c.

Referenced by sip_hash13().

◆ UNALIGNED_WORD_ACCESS

#define UNALIGNED_WORD_ACCESS   0

Definition at line 39 of file siphash.c.

◆ XOR64_INT

#define XOR64_INT (   v,
 
)    ((v).lo ^= (x))

Definition at line 131 of file siphash.c.

Referenced by sip_hash13().

◆ XOR64_TO

#define XOR64_TO (   v,
 
)    xor64_to(&(v), (s))

Definition at line 122 of file siphash.c.

Referenced by sip_hash13().

Function Documentation

◆ sip_hash13()

uint64_t sip_hash13 ( const uint8_t  key[16],
const uint8_t data,
size_t  len 
)

Definition at line 397 of file siphash.c.

References last, OR_BYTE, SIP_COMPRESS, sip_init_state, SIP_ROUND, U8TO64_LE, XOR64_INT, and XOR64_TO.

◆ sip_hash_digest()

int sip_hash_digest ( sip_hash h,
const uint8_t data,
size_t  data_len,
uint8_t **  digest,
size_t *  digest_len 
)

Definition at line 363 of file siphash.c.

References sip_hash_final(), and sip_hash_update().

◆ sip_hash_digest_integer()

int sip_hash_digest_integer ( sip_hash h,
const uint8_t data,
size_t  data_len,
uint64_t digest 
)

Definition at line 370 of file siphash.c.

References sip_hash_final_integer(), and sip_hash_update().

◆ sip_hash_dump()

void sip_hash_dump ( sip_hash h)

Definition at line 383 of file siphash.c.

◆ sip_hash_final()

int sip_hash_final ( sip_hash h,
uint8_t **  digest,
size_t *  len 
)

Definition at line 341 of file siphash.c.

References sip_interface_st::final, malloc, sip_hash::methods, sip_hash::state, and U64TO8_LE.

Referenced by sip_hash_digest().

◆ sip_hash_final_integer()

int sip_hash_final_integer ( sip_hash h,
uint64_t digest 
)

Definition at line 356 of file siphash.c.

References sip_interface_st::final, sip_hash::methods, and sip_hash::state.

Referenced by sip_hash_digest_integer().

◆ sip_hash_free()

void sip_hash_free ( sip_hash h)

Definition at line 377 of file siphash.c.

References free().

◆ sip_hash_init()

sip_hash* sip_hash_init ( sip_hash h,
const uint8_t  key[16],
int  c,
int  d 
)

◆ sip_hash_new()

sip_hash* sip_hash_new ( const uint8_t  key[16],
int  c,
int  d 
)

Definition at line 313 of file siphash.c.

References malloc, NULL, and sip_hash_init().

◆ sip_hash_update()

int sip_hash_update ( sip_hash h,
const uint8_t msg,
size_t  len 
)

Definition at line 334 of file siphash.c.

Referenced by sip_hash_digest(), and sip_hash_digest_integer().

Variable Documentation

◆ bin

char bin[32]

Definition at line 135 of file siphash.c.

Referenced by st_insert(), st_insert2(), st_lookup(), st_shift(), and st_update().

◆ u64

uint64_t u64[4]

Definition at line 136 of file siphash.c.