annotate support/casc/jenkins96.lua @ 65:8b8b0bade520

Fixed support for mounts using the new MountJournal and mount IDs (no conversion of old profiles at the moment).
author Jerome Vuarand <jerome.vuarand@gmail.com>
date Thu, 23 Oct 2014 13:44:59 +0100
parents
children
rev   line source
jerome@65 1 local M, plat, bin = {}, require("casc.platform"), require("casc.bin")
jerome@65 2
jerome@65 3 local rot, xor, uint32_le, to_le32 = plat.rol, plat.bxor, bin.uint32_le, bin.to_le32
jerome@65 4
jerome@65 5 function M.hash(k)
jerome@65 6 assert(type(k) == "string", 'Syntax: casc.jenkins96.hash("key")')
jerome@65 7
jerome@65 8 if #k == 0 then return 0xdeadbeef, 0xdeadbeef end
jerome@65 9 local a = 0xdeadbeef + #k
jerome@65 10 local b, c, k = a, a, k .. (k ~= "" and ("\0"):rep((12 - #k % 12) % 12) or "")
jerome@65 11 for i=0, #k-13, 12 do
jerome@65 12 a, b, c = a + uint32_le(k, i), b + uint32_le(k, i+4), c + uint32_le(k, i+8)
jerome@65 13 a = xor(a-c, rot(c, 4)); c = c + b
jerome@65 14 b = xor(b-a, rot(a, 6)); a = a + c
jerome@65 15 c = xor(c-b, rot(b, 8)); b = b + a
jerome@65 16 a = xor(a-c, rot(c,16)); c = c + b
jerome@65 17 b = xor(b-a, rot(a,19)); a = a + c
jerome@65 18 c = xor(c-b, rot(b, 4)); b = b + a
jerome@65 19 end
jerome@65 20 local i = #k - 12
jerome@65 21 a, b, c = a + uint32_le(k, i), b + uint32_le(k, i+4), c + uint32_le(k, i+8)
jerome@65 22 c = xor(c, b) - rot(b,14)
jerome@65 23 a = xor(a, c) - rot(c,11)
jerome@65 24 b = xor(b, a) - rot(a,25)
jerome@65 25 c = xor(c, b) - rot(b,16)
jerome@65 26 a = xor(a, c) - rot(c,04)
jerome@65 27 b = xor(b, a) - rot(a,14)
jerome@65 28 c = xor(c, b) - rot(b,24)
jerome@65 29 return c, b
jerome@65 30 end
jerome@65 31
jerome@65 32 function M.hash_path(path)
jerome@65 33 assert(type(path) == "string", 'Syntax: casc.jenkins96.hash_path("path")')
jerome@65 34 local c, b = M.hash((path:upper():gsub('/', '\\')))
jerome@65 35 return to_le32(b) .. to_le32(c)
jerome@65 36 end
jerome@65 37
jerome@65 38 return M