Ruby 2.0.0p353(2013-11-22revision43784)

- Main Page
- Modules
- Data Structures
- Files

- File List
- Globals

Data Structures | Macros | Functions | Variables
siphash.c File Reference
`#include <string.h>`
`#include <stdio.h>`
`#include "siphash.h"`
`#include <endian.h>`
Include dependency graph for siphash.c:
This graph shows which files directly or indirectly include this file:

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_2_ROUND(m, v0, v1, v2, v3)
#define | OR_BYTE(n)

## Functions
static uint64_t | u8to64_le (const uint8_t *p)
static void | u64to8_le (uint8_t *p, uint64_t v)
static uint64_t * | rotl64_to (uint64_t *v, unsigned int s)
static uint64_t * | rotl64_swap (uint64_t *v)
static uint64_t * | add64_to (uint64_t *v, const uint64_t s)
static uint64_t * | xor64_to (uint64_t *v, const uint64_t s)
static void | int_sip_init (sip_state *state, const uint8_t *key)
static void | int_sip_update (sip_state *state, const uint8_t *data, size_t len)
static void | int_sip_final (sip_state *state, uint64_t *digest)
static void | int_sip_dump (sip_state *state)
static void | int_sip_init (sip_state *state, const uint8_t key[16])
static void | int_sip_round (sip_state *state, int n)
static void | int_sip_update_block (sip_state *state, uint64_t m)
static void | int_sip_pre_update (sip_state *state, const uint8_t **pdata, size_t *plen)
static void | int_sip_post_update (sip_state *state, const uint8_t *data, size_t len)
static void | int_sip_pad_final_block (sip_state *state)
sip_hash * | sip_hash_new (const uint8_t key[16], int c, int d)
sip_hash * | sip_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_hash24 (const uint8_t key[16], const uint8_t *data, size_t len)

## Variables
union {
char bin [32]
uint64_t u64 [4]
} | sip_init_state_bin = {"uespemos""modnarod""arenegyl""setybdet"}
static const sip_interface | sip_methods

## Macro Definition Documentation

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

Definition at line 111 of file siphash.c.

#define BIG_ENDIAN __BIG_ENDIAN

Definition at line 17 of file siphash.c.

#define hi u32[1]

Definition at line 22 of file siphash.c.

Referenced by assign_heap_slot(), and is_pointer_to_heap().

#define LITTLE_ENDIAN __LITTLE_ENDIAN

Definition at line 14 of file siphash.c.

#define lo u32[0]

Definition at line 21 of file siphash.c.

Referenced by assign_heap_slot(), big2dbl(), and is_pointer_to_heap().

#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)
n
ssize_t n
Definition: bigdecimal.c:5655
last
unsigned int last
Definition: nkf.c:4310
uint32_t
unsigned int uint32_t
Definition: sha2.h:101
end
gz end
Definition: zlib.c:2272
if
if(RB_TYPE_P(r, T_FLOAT))
Definition: bigdecimal.c:1186

Referenced by sip_hash24().

#define ROTL64_TO | ( |  | v,
|  |  | s
| ) |  |

Value:
((s) > 32 ? rotl64_swap(rotl64_to(&(v), (s) - 32)) : \
(s) == 32 ? rotl64_swap(&(v)) : rotl64_to(&(v), (s)))
rotl64_to
static uint64_t * rotl64_to(uint64_t *v, unsigned int s)
Definition: siphash.c:93
rotl64_swap
static uint64_t * rotl64_swap(uint64_t *v)
Definition: siphash.c:103
s
register char * s
Definition: os2.c:56
v
BDIGIT v
Definition: bigdecimal.c:5656

Definition at line 90 of file siphash.c.

#define SIP_2_ROUND | ( |  | m,
|  |  | v0,
|  |  | v1,
|  |  | v2,
|  |  | v3
| ) |  |

Value:
do { \
XOR64_TO((v3), (m)); \
SIP_COMPRESS(v0, v1, v2, v3); \
SIP_COMPRESS(v0, v1, v2, v3); \
XOR64_TO((v0), (m)); \
} while (0)
XOR64_TO
#define XOR64_TO(v, s)
Definition: siphash.c:121
m
BDIGIT m
Definition: bigdecimal.c:5085
SIP_COMPRESS
#define SIP_COMPRESS(v0, v1, v2, v3)
Definition: siphash.c:157

Definition at line 388 of file siphash.c.

Referenced by sip_hash24().

#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)
ADD64_TO
#define ADD64_TO(v, s)
Definition: siphash.c:111
XOR64_TO
#define XOR64_TO(v, s)
Definition: siphash.c:121
ROTL64_TO
#define ROTL64_TO(v, s)
Definition: siphash.c:90

Definition at line 157 of file siphash.c.

Referenced by int_sip_round(), and sip_hash24().

#define SIP_HASH_STREAMING 1

Definition at line 5 of file siphash.c.

#define sip_init_state sip_init_state_bin.u64

Definition at line 137 of file siphash.c.

Referenced by int_sip_init(), and sip_hash24().

#define U32TO8_LE | ( |  | p,
|  |  | v
| ) |  |

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)
p
Win32OLEIDispatch * p
Definition: win32ole.c:786
uint8_t
unsigned char uint8_t
Definition: sha2.h:100
v
BDIGIT v
Definition: bigdecimal.c:5656

Definition at line 45 of file siphash.c.

Referenced by u64to8_le().

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

Definition at line 82 of file siphash.c.

Referenced by sip_hash_final().

#define U8TO32_LE | ( |  | p | ) |

Value:
(((uint32_t)((p)[0]) ) | ((uint32_t)((p)[1]) << 8) | \
((uint32_t)((p)[2]) << 16) | ((uint32_t)((p)[3]) << 24)) \
p
Win32OLEIDispatch * p
Definition: win32ole.c:786
uint32_t
unsigned int uint32_t
Definition: sha2.h:101

Definition at line 41 of file siphash.c.

Referenced by u8to64_le().

#define U8TO64_LE | ( |  | p | ) | u8to64_le(p)

Definition at line 72 of file siphash.c.

Referenced by int_sip_final(), int_sip_init(), int_sip_pre_update(), int_sip_update(), and sip_hash24().

#define UNALIGNED_WORD_ACCESS 0

Definition at line 38 of file siphash.c.

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

Definition at line 130 of file siphash.c.

Referenced by int_sip_final(), and sip_hash24().

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

Definition at line 121 of file siphash.c.

Referenced by int_sip_final(), int_sip_init(), int_sip_update_block(), and sip_hash24().

## Function Documentation

static uint64_t* add64_to | ( | uint64_t * | v,
|  | const uint64_t | s
| ) |  |
| inline static

Definition at line 113 of file siphash.c.

References v.

static void int_sip_dump | ( | sip_state * | state | ) |
| static

Definition at line 177 of file siphash.c.

References sip_state::v, and v.

Referenced by sip_hash_dump().

static void int_sip_final | ( | sip_state * | state,
|  | uint64_t * | digest
| ) |  |
| static

Definition at line 292 of file siphash.c.

References sip_state::buf, sip_state::d, int_sip_pad_final_block(), int_sip_round(), int_sip_update_block(), m, U8TO64_LE, sip_state::v, XOR64_INT, and XOR64_TO.

static void int_sip_init | ( | sip_state * | state,
|  | const uint8_t * | key
| ) |  |
| static

static void int_sip_init | ( | sip_state * | state,
|  | const uint8_t | key[16]
| ) |  |
| static

Definition at line 191 of file siphash.c.

References sip_init_state, U8TO64_LE, sip_state::v, and XOR64_TO.

static void int_sip_pad_final_block | ( | sip_state * | state | ) |
| inline static

Definition at line 281 of file siphash.c.

References sip_state::buf, sip_state::buflen, i, and sip_state::msglen_byte.

Referenced by int_sip_final().

static void int_sip_post_update | ( | sip_state * | state,
|  | const uint8_t * | data,
|  | size_t | len
| ) |  |
| inline static

Definition at line 240 of file siphash.c.

References sip_state::buf, sip_state::buflen, memcpy(), and r.

Referenced by int_sip_update().

static void int_sip_pre_update | ( | sip_state * | state,
|  | const uint8_t ** | pdata,
|  | size_t * | plen
| ) |  |
| inline static

Definition at line 223 of file siphash.c.

References sip_state::buf, sip_state::buflen, int_sip_update_block(), m, memcpy(), and U8TO64_LE.

Referenced by int_sip_update().

static void int_sip_round | ( | sip_state * | state,
|  | int | n
| ) |  |
| inline static

Definition at line 205 of file siphash.c.

References i, n, SIP_COMPRESS, and sip_state::v.

Referenced by int_sip_final(), and int_sip_update_block().

static void int_sip_update | ( | sip_state * | state,
|  | const uint8_t * | data,
|  | size_t | len
| ) |  |
| static

Definition at line 250 of file siphash.c.

References data, end, int_sip_post_update(), int_sip_pre_update(), int_sip_update_block(), m, sip_state::msglen_byte, and U8TO64_LE.

static void int_sip_update_block | ( | sip_state * | state,
|  | uint64_t | m
| ) |  |
| inline static

Definition at line 215 of file siphash.c.

References sip_state::c, int_sip_round(), sip_state::v, and XOR64_TO.

Referenced by int_sip_final(), int_sip_pre_update(), and int_sip_update().

static uint64_t* rotl64_swap | ( | uint64_t * | v | ) |
| inline static

Definition at line 103 of file siphash.c.

References t, and v.

static uint64_t* rotl64_to | ( | uint64_t * | v,
|  | unsigned int | s
| ) |  |
| inline static

Definition at line 93 of file siphash.c.

References s, and v.

uint64_t sip_hash24 | ( | const uint8_t | key[16],
|  | const uint8_t * | data,
|  | size_t | len
| ) |  |

Definition at line 397 of file siphash.c.

References end, last, m, OR_BYTE, SIP_2_ROUND, SIP_COMPRESS, sip_init_state, U8TO64_LE, XOR64_INT, and XOR64_TO.

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 362 of file siphash.c.

References sip_hash_final(), and sip_hash_update().

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

Definition at line 369 of file siphash.c.

References sip_hash_final_integer(), and sip_hash_update().

void sip_hash_dump | ( | sip_hash * | h | ) |

Definition at line 382 of file siphash.c.

References int_sip_dump(), and sip_hash::state.

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

Definition at line 340 of file siphash.c.

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

Referenced by sip_hash_digest().

int sip_hash_final_integer | ( | sip_hash * | h,
|  | uint64_t * | digest
| ) |  |

Definition at line 355 of file siphash.c.

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

Referenced by sip_hash_digest_integer().

void sip_hash_free | ( | sip_hash * | h | ) |

Definition at line 376 of file siphash.c.

References free.

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

Definition at line 321 of file siphash.c.

References sip_state::buflen, sip_state::c, c, sip_state::d, d, sip_interface_st::init, sip_hash::methods, sip_state::msglen_byte, sip_methods, and sip_hash::state.

Referenced by sip_hash_new().

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

Definition at line 312 of file siphash.c.

References malloc(), NULL, and sip_hash_init().

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

Definition at line 333 of file siphash.c.

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

Referenced by sip_hash_digest(), and sip_hash_digest_integer().

static void u64to8_le | ( | uint8_t * | p,
|  | uint64_t | v
| ) |  |
| inline static

Definition at line 84 of file siphash.c.

References U32TO8_LE.

static uint64_t u8to64_le | ( | const uint8_t * | p | ) |
| inline static

Definition at line 74 of file siphash.c.

References ret, and U8TO32_LE.

static uint64_t* xor64_to | ( | uint64_t * | v,
|  | const uint64_t | s
| ) |  |
| inline static

Definition at line 123 of file siphash.c.

References v.

## Variable Documentation

char bin[32]

Definition at line 134 of file siphash.c.

union { ... } sip_init_state_bin

const sip_interface sip_methods
| static

Initial value:
= {
int_sip_init,
int_sip_update,
int_sip_final
}
int_sip_final
static void int_sip_final(sip_state *state, uint64_t *digest)
Definition: siphash.c:292
int_sip_update
static void int_sip_update(sip_state *state, const uint8_t *data, size_t len)
Definition: siphash.c:250
int_sip_init
static void int_sip_init(sip_state *state, const uint8_t *key)

Definition at line 150 of file siphash.c.

Referenced by sip_hash_init().

uint64_t u64[4]

Definition at line 135 of file siphash.c.