Add Poly1305 tag verification
This commit is contained in:
parent
474d62d082
commit
238058e46f
15
poly1305.lua
15
poly1305.lua
|
@ -4,6 +4,7 @@
|
|||
--
|
||||
|
||||
local expect = require "cc.expect".expect
|
||||
local random = require "ccryptolib.random"
|
||||
|
||||
local band = bit32.band
|
||||
|
||||
|
@ -134,4 +135,18 @@ function mod.mac(key, message)
|
|||
return ("<I2I3I3I2I3I3"):pack(t0, t1, t2, t3, t4, t5)
|
||||
end
|
||||
|
||||
local mac = mod.mac
|
||||
|
||||
--- Verifies a Poly1305 tag.
|
||||
--
|
||||
-- @tparam string key The key used to generate the tag.
|
||||
-- @tparam string message The message to authenticate.
|
||||
-- @tparam string tag The tag to check.
|
||||
-- @treturn boolean Whether the tag is valid or not.
|
||||
--
|
||||
function mod.verify(key, message, tag)
|
||||
local kaux = random.random(32)
|
||||
return mac(kaux, tag) == mac(kaux, mac(key, message))
|
||||
end
|
||||
|
||||
return mod
|
||||
|
|
Loading…
Reference in a new issue