2014-05-30 09:13:28 +04:00
|
|
|
/*
|
2016-01-19 22:31:37 +03:00
|
|
|
* Copyright (c) 2014-2016 Galois, Inc.
|
2014-05-30 09:13:28 +04:00
|
|
|
* Distributed under the terms of the BSD3 license (see LICENSE file)
|
|
|
|
*/
|
|
|
|
|
|
|
|
fnv1a : {n} (fin n) => [n] -> [64]
|
|
|
|
fnv1a ws = fnv1a' (pad ws)
|
|
|
|
|
2017-09-28 20:26:31 +03:00
|
|
|
pad : {msgLen} (fin msgLen) => [msgLen] -> [msgLen /^ 8][8]
|
|
|
|
pad msg = split (msg # (zero:[msgLen %^ 8]))
|
2014-05-30 09:13:28 +04:00
|
|
|
|
|
|
|
fnv1a' : {chunks} (fin chunks) => [chunks][8] -> [64]
|
|
|
|
fnv1a' msg = Ss ! 0
|
|
|
|
where
|
|
|
|
Ss = [fnv1a_offset_basis] #
|
|
|
|
[ block s m
|
|
|
|
| s <- Ss
|
|
|
|
| m <- msg
|
|
|
|
]
|
|
|
|
|
2017-09-27 23:55:55 +03:00
|
|
|
block : {padLen} ( padLen == 64 - 8) => [64] -> [8] -> [64]
|
|
|
|
block state val = (state ^ ((zero : [padLen]) # val)) * fnv1a_prime
|
2014-05-30 09:13:28 +04:00
|
|
|
|
|
|
|
fnv1a_offset_basis : [64]
|
|
|
|
fnv1a_offset_basis = 14695981039346656037
|
|
|
|
|
|
|
|
fnv1a_prime : [64]
|
|
|
|
fnv1a_prime = 1099511628211
|
|
|
|
|
|
|
|
t1 = fnv1a [] == 0xcbf29ce484222325
|
|
|
|
t2 = fnv1a (join "a") == 0xaf63dc4c8601ec8c
|
|
|
|
t3 = fnv1a (join "foobar") == 0x85944171f73967e8
|
|
|
|
|
|
|
|
property testsPass = [t1, t2, t3] == ~zero
|