From 0060e0b6b28f60415cc3f218898bf9ba9c6d32ce Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 11 Jul 2022 15:34:31 +1000 Subject: [PATCH] src/openssl.c: add compat for pre 1.1.0 --- src/openssl.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index c8c7677..1d1164e 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -11923,7 +11923,14 @@ static int cipher_init(lua_State *L, _Bool encrypt) { iv = luaL_optlstring(L, 3, NULL, &n); /* Set the IV length before init */ +#if defined EVP_CTRL_AEAD_SET_IVLEN if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_IVLEN, n, NULL) <= 0) { +#elif defined EVP_CTRL_GCM_SET_IVLEN + /* https://github.com/openssl/openssl/issues/8330#issuecomment-516838331 */ + if (EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_IVLEN, n, NULL) <= 0) { +#else + { +#endif /* 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));