Module: Highwayhash

Extended by:
FFI::Library
Defined in:
lib/highwayhash.rb,
lib/highwayhash/version.rb

Constant Summary collapse

VERSION =
"1.0.0"

Class Method Summary collapse

Class Method Details

.hash64(input, key) ⇒ Object

Raises:

  • (ArgumentError)


15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/highwayhash.rb', line 15

private def hash64(input, key)
  raise ArgumentError.new("Key length must be 32 bytes") if key.size != 32

  if input.respond_to?(:read)
    data = input.read
  else
    data = input
  end

  input_size = data.bytesize

  input_p = FFI::MemoryPointer.from_string(data)

  key_p = FFI::MemoryPointer.new(:ulong_long, 4)
  key_p.write_array_of_uint64(key.unpack("Q4"))

  __highway_hash64(key_p, input_p, input_size)
end