-
Notifications
You must be signed in to change notification settings - Fork 1
/
umac.h
107 lines (83 loc) · 2.22 KB
/
umac.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Author: Lucas Clemente Vella
* Source code placed into public domain. */
#pragma once
#include <stddef.h>
#include <inttypes.h>
#include "buffered.h"
#if(__STDC_VERSION__ >= 199901L)
#define FLEX_ARRAY_MEMBER
#else
#define FLEX_ARRAY_MEMBER 1 // Non-standard usage, but widely accepted.
#endif
/* Internally used: */
typedef struct
{
uint64_t v[2]; /* Big endian; 0: most significant; 1: least significant */
} uint128;
/* Key stuff: */
typedef struct
{
uint64_t k64;
uint128 k128;
} l2_key;
typedef struct
{
uint16_t l2key_offset;
uint16_t l3key1_offset;
uint16_t l3key2_offset;
uint8_t iters;
} uhash_key_attributes;
typedef struct
{
const uhash_key_attributes *attribs;
} uhash_key;
/* State stuff */
typedef struct
{
uint128 y;
uint64_t tmp;
} l2_state;
typedef struct {
uint64_t l1;
l2_state l2;
} uhash_iteration_state;
typedef struct {
uint8_t iters;
uint8_t buffer_len;
/** Data is copied to buffer in native byte order. */
uint32_t buffer[8];
/** How many 32 bytes steps performed so far. */
uint64_t step_count;
} uhash_state_common;
typedef struct {
uhash_state_common common;
uhash_iteration_state partial[FLEX_ARRAY_MEMBER];
} uhash_state;
/* Public interface: */
void uhash_key_setup(uhash_type type, uhash_key *key, buffered_state *full_state);
uhash_type uhash_get_type_from_key(uhash_key *key);
void uhash_init(uhash_type type, uhash_state *state);
void uhash_update(const uhash_key *key, uhash_state *state, const uint8_t *input, size_t len);
void uhash_finish(const uhash_key *key, uhash_state *state, uint8_t *output);
#define UHASH_BITS(bits) \
typedef struct \
{ \
uhash_key header; \
uint32_t l1key[256 + (((bits)-1)/32) * 4]; \
l2_key l2key[(bits)/32]; \
uint64_t l3key1[(bits)/4]; \
uint32_t l3key2[(bits)/32]; \
} uhash_##bits##_key; \
const uhash_key_attributes uhash_##bits##_attributes; \
\
typedef struct \
{ \
uhash_state_common common; \
uhash_iteration_state partial[(bits)/32]; \
} uhash_##bits##_state;
UHASH_BITS(32)
UHASH_BITS(64)
UHASH_BITS(96)
UHASH_BITS(128)
#undef UHASH_BITS
const uhash_key_attributes *const uhash_attributes_array[4];