--- The Poly1305 one-time authenticator. -- -- @module poly1305 -- local expect = require "cc.expect".expect local random = require "ccryptolib.random" 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 or #message == 0 then message = message .. "\1" message = message .. ("\0"):rep(-#message % 16) end -- Decode r. local R0, R1, R2, R3 = ("= 0xfffb then c7, c6, c5, c4, c3, c2, c1, c0 = 0, 0, 0, 0, 0, 0, 0, c0 - 0xfffb end -- Decode s. local s0, s1, s2, s3 = ("