aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLibravatarLibravatar daurnimator <quae@daurnimator.com> 2022-07-08 09:53:44 +1000
committerLibravatarLibravatar daurnimator <quae@daurnimator.com> 2022-07-08 09:59:33 +1000
commita272fe7408d02c98120f6c697113ee5579f4cc25 (patch)
tree3114cc2f64d0a3aa65717b9728049195cb1c5f57 /src
parentbed73b66dee1dde0bfa5a658cf109457c3f70b46 (diff)
downloadluaossl-a272fe7408d02c98120f6c697113ee5579f4cc25.tar.gz
luaossl-a272fe7408d02c98120f6c697113ee5579f4cc25.tar.bz2
luaossl-a272fe7408d02c98120f6c697113ee5579f4cc25.zip
Allow for ciphers with adjustable IV lengths
Diffstat (limited to 'src')
-rw-r--r--src/openssl.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/openssl.c b/src/openssl.c
index 3506089..c8c7677 100644
--- a/src/openssl.c
+++ b/src/openssl.c
@@ -11922,8 +11922,12 @@ static int cipher_init(lua_State *L, _Bool encrypt) {
luaL_argcheck(L, n == m, 2, lua_pushfstring(L, "%d: invalid key length (should be %d)", (int)n, (int)m));
iv = luaL_optlstring(L, 3, NULL, &n);
- m = (size_t)EVP_CIPHER_CTX_iv_length(ctx);
- luaL_argcheck(L, n == m, 3, lua_pushfstring(L, "%d: invalid IV length (should be %d)", (int)n, (int)m));
+ /* Set the IV length before init */
+ if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, n, NULL) <= 0) {
+ /* wasn't able to set IV len; check if it's already correct */
+ m = (size_t)EVP_CIPHER_CTX_iv_length(ctx);
+ luaL_argcheck(L, n == m, 3, lua_pushfstring(L, "%d: invalid IV length (should be %d)", (int)n, (int)m));
+ }
if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, encrypt))
goto sslerr;