@@ -224,7 +224,7 @@ function _M.new(self, key, salt, _cipher, _hash, hash_rounds, iv_len, enable_pad
224
224
end
225
225
226
226
227
- function _M .encrypt (self , s )
227
+ function _M .encrypt (self , s , aad )
228
228
local typ = type (self )
229
229
if typ ~= " table" then
230
230
error (" bad argument #1 self: table expected, got " .. typ , 2 )
@@ -241,6 +241,12 @@ function _M.encrypt(self, s)
241
241
return nil , " EVP_EncryptInit_ex failed"
242
242
end
243
243
244
+ if self ._cipher == " gcm" and aad ~= nil then
245
+ if C .EVP_EncryptUpdate (ctx , nil , tmp_len , aad , # aad ) == 0 then
246
+ return nil , " C.EVP_EncryptUpdate failed"
247
+ end
248
+ end
249
+
244
250
if C .EVP_EncryptUpdate (ctx , buf , out_len , s , s_len ) == 0 then
245
251
return nil , " EVP_EncryptUpdate failed"
246
252
end
@@ -267,7 +273,7 @@ function _M.encrypt(self, s)
267
273
end
268
274
269
275
270
- function _M .decrypt (self , s , tag )
276
+ function _M .decrypt (self , s , tag , aad )
271
277
local typ = type (self )
272
278
if typ ~= " table" then
273
279
error (" bad argument #1 self: table expected, got " .. typ , 2 )
@@ -284,6 +290,12 @@ function _M.decrypt(self, s, tag)
284
290
return nil , " EVP_DecryptInit_ex failed"
285
291
end
286
292
293
+ if self ._cipher == " gcm" and aad ~= nil then
294
+ if C .EVP_DecryptUpdate (ctx , nil , tmp_len , aad , # aad ) == 0 then
295
+ return nil , " C.EVP_DecryptUpdate failed"
296
+ end
297
+ end
298
+
287
299
if C .EVP_DecryptUpdate (ctx , buf , out_len , s , s_len ) == 0 then
288
300
return nil , " EVP_DecryptUpdate failed"
289
301
end
0 commit comments