about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2020-01-20 13:13:31 +0100
committerPaul Fariello <paul@fariello.eu>2020-01-20 14:41:18 +0100
commit8d1202efbdfcaceb2d2cbe1e58e8d1e1f8a506cd (patch)
treefa3714853ed52bb6302b81563259111beb16e867 /src
parent69bf76761a2f20918960b1f143685dcc7e7f6b36 (diff)
downloadprofani-tty-8d1202efbdfcaceb2d2cbe1e58e8d1e1f8a506cd.tar.gz
Add support for 12 bytes IV
16 bytes IV should be used. Some clients can't use it so we should also
support decrypting 12 bytes IV.

Fix #1253
Diffstat (limited to 'src')
-rw-r--r--src/omemo/crypto.c4
-rw-r--r--src/omemo/crypto.h2
-rw-r--r--src/omemo/omemo.c2
3 files changed, 4 insertions, 4 deletions
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) {