Skip to content

Specification Requests

Thomas M. DuBuisson edited this page May 29, 2014 · 4 revisions

Is anyone up to the task (however small) of specifying FNV in cryptol?

http://en.wikipedia.org/wiki/Fowler_Noll_Vo_hash

If so, thanks!

TOD: Late. Testing: Minimal. Code:

fnv1a : {n} (fin n) => [n] -> [64]
fnv1a ws = fnv1a' (pad ws)

pad : {msgLen,chunks,padding}
     ( fin msgLen
     , chunks     == (msgLen+63) / 64
     , padding    == (64 - msgLen % 64) % 64
     )
     => [msgLen] -> [chunks][64]
pad msg = split (msg # (zero:[padding]))

fnv1a' : {chunks} (fin chunks) => [chunks][64] -> [64]
fnv1a' msg = Ss ! 0
  where
   Ss = [fnv1a_offset_basis] #
           [ block s m
           | s <- Ss
           | m <- msg
           ]

block : [64] -> [64] -> [64]
block state val = (state ^ val) * fnv1a_prime

fnv1a_offset_basis : [64]
fnv1a_offset_basis = 14695981039346656037

fnv1a_prime : [64]
fnv1a_prime = 1099511628211
Clone this wiki locally