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
#ifndef C_HIGHWAYHASH_H_
#define C_HIGHWAYHASH_H_
#include <stdint.h>
#include <string.h>
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
/* Low-level API, use for implementing streams etc... */
typedef struct {
uint64_t v0[4];
uint64_t v1[4];
uint64_t mul0[4];
uint64_t mul1[4];
} HighwayHashState;
/* Initializes state with given key */
static void HighwayHashReset_pure_c(const uint64_t key[4],
HighwayHashState *state);
/* Takes a packet of 32 bytes */
void HighwayHashUpdatePacket_pure_c(const uint8_t *packet,
HighwayHashState *state);
/* Adds the final 1..31 bytes, do not use if 0 remain */
void HighwayHashUpdateRemainder_pure_c(const uint8_t *bytes,
const size_t size_mod32,
HighwayHashState *state);
/* Compute final hash value. Makes state invalid. */
static uint64_t HighwayHashFinalize64_pure_c(HighwayHashState *state);
static void HighwayHashFinalize128_pure_c(HighwayHashState *state,
uint64_t hash[2]);
static void HighwayHashFinalize256_pure_c(HighwayHashState *state,
uint64_t hash[4]);
/* Non-cat API: single call on full data */
uint64_t HighwayHash64_pure_c(const uint64_t key[4], const uint8_t *data,
size_t size);
void HighwayHash128_pure_c(const uint64_t key[4], const uint8_t *data,
size_t size, uint64_t hash[2]);
void HighwayHash256_pure_c(const uint64_t key[4], const uint8_t *data,
size_t size, uint64_t hash[4]);
/* Cat API: allows appending with multiple calls */
typedef struct {
HighwayHashState state;
uint8_t packet[32];
size_t num;
} HighwayHashCat;
/* Allocates new state for a new streaming hash computation */
void HighwayHashCatStart_pure_c(const uint64_t key[4], HighwayHashCat *state);
void HighwayHashCatAppend_pure_c(const uint8_t *bytes, size_t num,
HighwayHashCat *state);
/* Computes final hash value */
uint64_t HighwayHashCatFinish64_pure_c(const HighwayHashCat *state);
void HighwayHashCatFinish128_pure_c(const HighwayHashCat *state,
uint64_t hash[2]);
void HighwayHashCatFinish256_pure_c(const HighwayHashCat *state,
uint64_t hash[4]);
/*
Usage examples:
#include <inttypes.h>
#include <stdio.h>
void Example64() {
uint64_t key[4] = {1, 2, 3, 4};
const char* text = "Hello world!";
size_t size = strlen(text);
uint64_t hash = HighwayHash64((const uint8_t*)text, size, key);
printf("%016"PRIx64"\n", hash);
}
void Example64Cat() {
uint64_t key[4] = {1, 2, 3, 4};
HighwayHashCat state;
uint64_t hash;
HighwayHashCatStart(key, &state);
HighwayHashCatAppend((const uint8_t*)"Hello", 5, &state);
HighwayHashCatAppend((const uint8_t*)" world!", 7, &state);
hash = HighwayHashCatFinish64(state);
printf("%016"PRIx64"\n", hash);
}
*/
#if defined(__cplusplus) || defined(c_plusplus)
} /* extern "C" */
#endif
#endif // C_HIGHWAYHASH_H_