Skip to content

Commit

Permalink
initialize empty AES-GCM inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
qmuntal committed Jul 27, 2022
1 parent 136d210 commit 56c1156
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions openssl/goopenssl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
Expand Down

0 comments on commit 56c1156

Please sign in to comment.