diff options
author | daurnimator <quae@daurnimator.com> | 2022-07-03 22:54:31 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2022-07-03 22:56:07 +1000 |
commit | bed73b66dee1dde0bfa5a658cf109457c3f70b46 (patch) | |
tree | 932f7b82052832b459f607323a92dad8929014dc /regress | |
parent | b9212f4029be6d51d12ac0414b06eb9fe450a0e3 (diff) | |
parent | 2922f436c562cf4dc716fc24816784b71da27403 (diff) | |
download | luaossl-bed73b66dee1dde0bfa5a658cf109457c3f70b46.tar.gz luaossl-bed73b66dee1dde0bfa5a658cf109457c3f70b46.tar.bz2 luaossl-bed73b66dee1dde0bfa5a658cf109457c3f70b46.zip |
Merge remote-tracking branch 'origin/refs/pull/201/head'
Diffstat (limited to 'regress')
-rw-r--r-- | regress/115-test-aead.lua | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/regress/115-test-aead.lua b/regress/115-test-aead.lua new file mode 100644 index 0000000..ed0f7f8 --- /dev/null +++ b/regress/115-test-aead.lua @@ -0,0 +1,39 @@ +local regress = require "regress"; +local openssl = require "openssl"; +local cipher = require "openssl.cipher" + + +-- Test AES-256-GCM +local key = "abcdefghijklmnopabcdefghijklmnop" +local iv = "123456123456" +local message = "My secret message" + +function test_aead(params) + local c = cipher.new(params.cipher):encrypt(key, iv) + + local encrypted = c:update(message) + regress.check(encrypted) + regress.check(c:final(), "fail final encrypt") + + local tag = assert(c:getTag(params.tag_length)) + regress.check(tag and #tag == params.tag_length) + + + -- Now for the decryption + local d = cipher.new(params.cipher):decrypt(key, iv) + d:setTag(tag); + + local decrypted = d:update(encrypted) + regress.check(decrypted == message, "decrypted message doesn't match") + regress.check(d:final(), "fail final decrypt") +end + +test_aead { + cipher = "aes-256-gcm"; + tag_length = 16; +} + +test_aead { + cipher = "aes-256-ccm"; + tag_length = 12; +} |