diff options
author | daurnimator <quae@daurnimator.com> | 2022-07-08 09:53:44 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2022-07-08 09:59:33 +1000 |
commit | a272fe7408d02c98120f6c697113ee5579f4cc25 (patch) | |
tree | 3114cc2f64d0a3aa65717b9728049195cb1c5f57 | |
parent | bed73b66dee1dde0bfa5a658cf109457c3f70b46 (diff) | |
download | luaossl-a272fe7408d02c98120f6c697113ee5579f4cc25.tar.gz luaossl-a272fe7408d02c98120f6c697113ee5579f4cc25.tar.bz2 luaossl-a272fe7408d02c98120f6c697113ee5579f4cc25.zip |
Allow for ciphers with adjustable IV lengths
-rw-r--r-- | src/openssl.c | 8 |
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; |