--- The Poly1305 one-time authenticator. -- -- @module poly1305 -- local expect = require "cc.expect".expect local random = require "ccryptolib.random" local band = bit32.band local mod = {} --- Computes a Poly1305 message authentication code. -- -- @tparam string key A 32-byte single-use random key. -- @tparam string message The message to authenticate. -- @treturn string The 16-byte authentication tag. -- function mod.mac(key, message) expect(1, key, "string") assert(#key == 32, "key length must be 32") expect(2, message, "string") -- Pad message. local pbplen = #message - 15 if #message % 16 ~= 0 then message = message .. "\1" message = message .. ("\0"):rep(-#message % 16) end -- Decode r. local r0, t1, r2, r3, t4, r5 = ("= 2 ^ 22 - 5 then h5 = 0 h4 = 0 h3 = 0 h2 = 0 h1 = 0 h0 = h0 - (2 ^ 22 - 5) end -- Decode s. local s0, s1, s2, s3, s4, s5 = ("