36 lines
850 B
Lua
36 lines
850 B
Lua
local gcrypt = require("luagcrypt")
|
|
|
|
local function new(_)
|
|
local fake_instance = {}
|
|
|
|
function fake_instance:encrypt(key, iv, data, _, auth)
|
|
local cipher = gcrypt.Cipher(gcrypt.CIPHER_AES256, gcrypt.CIPHER_MODE_GCM)
|
|
cipher:setkey(key)
|
|
cipher:setiv(iv)
|
|
cipher:authenticate(auth)
|
|
local encrypted = assert(cipher:encrypt(data))
|
|
self.tag = cipher:gettag()
|
|
return encrypted, nil
|
|
end
|
|
|
|
function fake_instance:get_aead_tag()
|
|
return self.tag
|
|
end
|
|
|
|
function fake_instance:decrypt(key, iv, data, _, auth, tag)
|
|
local cipher = gcrypt.Cipher(gcrypt.CIPHER_AES256, gcrypt.CIPHER_MODE_GCM)
|
|
cipher:setkey(key)
|
|
cipher:setiv(iv)
|
|
cipher:authenticate(auth)
|
|
local decrypted = assert(cipher:decrypt(data))
|
|
cipher:checktag(tag)
|
|
return decrypted
|
|
end
|
|
|
|
return fake_instance
|
|
end
|
|
|
|
return {
|
|
new = new,
|
|
}
|