diff --git a/src/omemo/crypto.c b/src/omemo/crypto.c index 560c2be6..d062e058 100644 --- a/src/omemo/crypto.c +++ b/src/omemo/crypto.c @@ -340,7 +340,7 @@ out: } int -aes128gcm_decrypt(unsigned char *plaintext, size_t *plaintext_len, const unsigned char *const ciphertext, size_t ciphertext_len, const unsigned char *const iv, const unsigned char *const key, const unsigned char *const tag) +aes128gcm_decrypt(unsigned char *plaintext, size_t *plaintext_len, const unsigned char *const ciphertext, size_t ciphertext_len, const unsigned char *const iv, size_t iv_len, const unsigned char *const key, const unsigned char *const tag) { gcry_error_t res; gcry_cipher_hd_t hd; @@ -355,7 +355,7 @@ aes128gcm_decrypt(unsigned char *plaintext, size_t *plaintext_len, const unsigne goto out; } - res = gcry_cipher_setiv(hd, iv, AES128_GCM_IV_LENGTH); + res = gcry_cipher_setiv(hd, iv, iv_len); if (res != GPG_ERR_NO_ERROR) { goto out; } diff --git a/src/omemo/crypto.h b/src/omemo/crypto.h index f767568c..4bd6258b 100644 --- a/src/omemo/crypto.h +++ b/src/omemo/crypto.h @@ -178,5 +178,5 @@ int aes128gcm_encrypt(unsigned char *ciphertext, size_t *ciphertext_len, int aes128gcm_decrypt(unsigned char *plaintext, size_t *plaintext_len, const unsigned char *const ciphertext, - size_t ciphertext_len, const unsigned char *const iv, + size_t ciphertext_len, const unsigned char *const iv, size_t iv_len, const unsigned char *const key, const unsigned char *const tag); diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index 55e07a01..e3ccc71f 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -955,7 +955,7 @@ omemo_on_message_recv(const char *const from_jid, uint32_t sid, size_t plaintext_len = payload_len; plaintext = malloc(plaintext_len + 1); res = aes128gcm_decrypt(plaintext, &plaintext_len, payload, payload_len, iv, - signal_buffer_data(plaintext_key), + iv_len, signal_buffer_data(plaintext_key), signal_buffer_data(plaintext_key) + AES128_GCM_KEY_LENGTH); signal_buffer_free(plaintext_key); if (res != 0) {