OLD | NEW |
| (Empty) |
1 /* ssl/fnv1a64.c */ | |
2 | |
3 /* Open sourcing FIXME: include correct copyright header here. */ | |
4 | |
5 /* Fowler-Noll-Vo (FNV) hash: http://isthe.com/chongo/tech/comp/fnv/ */ | |
6 | |
7 #include "fnv1a64.h" | |
8 | |
9 /* http://www.isthe.com/chongo/tech/comp/fnv/index.html#FNV-param */ | |
10 static const FNV1A64 FNV1A64_OFFSET_BASIS = 14695981039346656037ull; | |
11 static const FNV1A64 FNV1A64_PRIME = 1099511628211ull; | |
12 | |
13 void fnv1a64_init(FNV1A64* ctx) | |
14 { | |
15 *ctx = FNV1A64_OFFSET_BASIS; | |
16 } | |
17 | |
18 void fnv1a64_update(FNV1A64* ctx, const void* voiddata, unsigned int length) | |
19 { | |
20 const unsigned char *data = voiddata; | |
21 unsigned int i; | |
22 | |
23 for (i = 0; i < length; i++) | |
24 { | |
25 *ctx ^= data[i]; | |
26 *ctx *= FNV1A64_PRIME; | |
27 } | |
28 } | |
29 | |
30 void fnv1a64_final(unsigned char out[8], const FNV1A64 *ctx) | |
31 { | |
32 const FNV1A64 native_endian_result = *ctx; | |
33 unsigned int i; | |
34 | |
35 for (i = 0; i < 8; i++) | |
36 out[i] = (unsigned char) (native_endian_result >> (8 * (sizeof(F
NV1A64) - i - 1))); | |
37 } | |
OLD | NEW |