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 /src | |
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 'src')
-rw-r--r-- | src/openssl.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/openssl.c b/src/openssl.c index 198e6a6..3506089 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -12020,6 +12020,53 @@ sslerr: } /* cipher_final() */ +static int cipher_get_tag(lua_State *L) { + EVP_CIPHER_CTX *ctx = checksimple(L, 1, CIPHER_CLASS); + luaL_Buffer tag; + size_t tag_size = luaL_checkinteger(L, 2); + + luaL_buffinit(L, &tag); + + /* EVP_CTRL_GCM_GET_TAG is works for both GCM and CCM and across all + * supported OpenSSL versions. We can switch to the unified identifier + * 'EVP_CTRL_AEAD_GET_TAG' in OpenSSL 1.1+. + */ + if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_GET_TAG, tag_size, (void*)luaL_prepbuffsize(&tag, tag_size))) { + goto sslerr; + } + + luaL_pushresultsize(&tag, tag_size); + + return 1; + +sslerr: + lua_pushnil(L); + auxL_pusherror(L, auxL_EOPENSSL, NULL); + + return 2; +} /* cipher_get_tag() */ + + +static int cipher_set_tag(lua_State *L) { + EVP_CIPHER_CTX *ctx = checksimple(L, 1, CIPHER_CLASS); + size_t tag_size; + const char* tag = luaL_checklstring(L, 2, &tag_size); + if(1 != EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GCM_SET_TAG, tag_size, (void*)tag)) { + goto sslerr; + } + + lua_pushlstring(L, tag, tag_size); + + return 1; + +sslerr: + lua_pushnil(L); + auxL_pusherror(L, auxL_EOPENSSL, NULL); + + return 2; +} /* cipher_set_tag() */ + + static int cipher__gc(lua_State *L) { EVP_CIPHER_CTX **ctx = luaL_checkudata(L, 1, CIPHER_CLASS); @@ -12035,6 +12082,8 @@ static const auxL_Reg cipher_methods[] = { { "decrypt", &cipher_decrypt }, { "update", &cipher_update }, { "final", &cipher_final }, + { "getTag", &cipher_get_tag }, + { "setTag", &cipher_set_tag }, { NULL, NULL }, }; |