From 56c115610dfb8ea9a6dd9370c10bfa4788225b8e Mon Sep 17 00:00:00 2001 From: qmuntal Date: Wed, 27 Jul 2022 12:01:21 +0200 Subject: [PATCH] initialize empty AES-GCM inputs --- openssl/goopenssl.h | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/openssl/goopenssl.h b/openssl/goopenssl.h index f0c915d..03aed43 100644 --- a/openssl/goopenssl.h +++ b/openssl/goopenssl.h @@ -91,13 +91,16 @@ go_openssl_EVP_CIPHER_CTX_seal_wrapper(const GO_EVP_CIPHER_CTX_PTR ctx, unsigned char *out, const unsigned char *nonce, const unsigned char *in, int in_len, - const unsigned char *add, int add_len) + const unsigned char *aad, int aad_len) { + if (in_len == 0) in = ""; + if (aad_len == 0) aad = ""; + if (go_openssl_EVP_CipherInit_ex(ctx, NULL, NULL, NULL, nonce, GO_AES_ENCRYPT) != 1) return 0; int discard_len, out_len; - if (go_openssl_EVP_EncryptUpdate(ctx, NULL, &discard_len, add, add_len) != 1 + if (go_openssl_EVP_EncryptUpdate(ctx, NULL, &discard_len, aad, aad_len) != 1 || go_openssl_EVP_EncryptUpdate(ctx, out, &out_len, in, in_len) != 1 || go_openssl_EVP_EncryptFinal_ex(ctx, out + out_len, &discard_len) != 1) { @@ -115,14 +118,17 @@ go_openssl_EVP_CIPHER_CTX_open_wrapper(const GO_EVP_CIPHER_CTX_PTR ctx, unsigned char *out, const unsigned char *nonce, const unsigned char *in, int in_len, - const unsigned char *add, int add_len, + const unsigned char *aad, int aad_len, const unsigned char *tag) { + if (in_len == 0) in = ""; + if (aad_len == 0) aad = ""; + if (go_openssl_EVP_CipherInit_ex(ctx, NULL, NULL, NULL, nonce, GO_AES_DECRYPT) != 1) return 0; int discard_len, out_len; - if (go_openssl_EVP_DecryptUpdate(ctx, NULL, &discard_len, add, add_len) != 1 + if (go_openssl_EVP_DecryptUpdate(ctx, NULL, &discard_len, aad, aad_len) != 1 || go_openssl_EVP_DecryptUpdate(ctx, out, &out_len, in, in_len) != 1) { return 0;