about summary refs log tree commit diff stats
path: root/src/omemo
diff options
context:
space:
mode:
Diffstat (limited to 'src/omemo')
-rw-r--r--src/omemo/crypto.c31
-rw-r--r--src/omemo/crypto.h11
-rw-r--r--src/omemo/omemo.c32
-rw-r--r--src/omemo/omemo.h9
4 files changed, 44 insertions, 39 deletions
diff --git a/src/omemo/crypto.c b/src/omemo/crypto.c
index 7dd3be10..3be64636 100644
--- a/src/omemo/crypto.c
+++ b/src/omemo/crypto.c
@@ -479,34 +479,3 @@ char *aes256gcm_create_secure_fragment(unsigned char *key, unsigned char *nonce)
 
     return fragment;
 }
-
-void aes256gcm_fragment_free(char *fragment) {
-    gcry_free(fragment);
-}
-
-char *aes256gcm_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) {
-    unsigned char *key = gcry_random_bytes_secure(
-        AES256_GCM_KEY_LENGTH,
-        GCRY_VERY_STRONG_RANDOM);
-
-    // Create nonce/IV with random bytes.
-    unsigned char nonce[AES256_GCM_NONCE_LENGTH];
-    gcry_create_nonce(nonce, AES256_GCM_NONCE_LENGTH);
-
-    char *fragment = aes256gcm_create_secure_fragment(key, nonce);
-    *gcry_res = aes256gcm_crypt_file(in, out, file_size, key, nonce, true);
-
-    if (*gcry_res != GPG_ERR_NO_ERROR) {
-        gcry_free(fragment);
-        fragment = NULL;
-    }
-
-    gcry_free(key);
-
-    return fragment;
-}
-
-//int aes256gcm_decrypt_file(FILE *in, FILE *out, off_t file_size,
-//    unsigned char key[], unsigned char nonce[]) {
-//    return aes256gcm_crypt_file(in, out, file_size, key, nonce, false);
-//}
diff --git a/src/omemo/crypto.h b/src/omemo/crypto.h
index f24fa163..e8d91ecc 100644
--- a/src/omemo/crypto.h
+++ b/src/omemo/crypto.h
@@ -33,13 +33,13 @@
  *
  */
 #include <stdio.h>
+#include <stdbool.h>
 #include <signal/signal_protocol_types.h>
 
 #define AES128_GCM_KEY_LENGTH 16
 #define AES128_GCM_IV_LENGTH  12
 #define AES128_GCM_TAG_LENGTH 16
 
-#define AES256_GCM_URL_SCHEME "aesgcm"
 #define AES256_GCM_KEY_LENGTH 32
 #define AES256_GCM_NONCE_LENGTH 12
 
@@ -186,9 +186,8 @@ int aes128gcm_decrypt(unsigned char *plaintext,
     size_t ciphertext_len, const unsigned char *const iv, size_t iv_len,
     const unsigned char *const key, const unsigned char *const tag);
 
-char *aes256gcm_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res);
+int aes256gcm_crypt_file(FILE *in, FILE *out, off_t file_size,
+    unsigned char key[], unsigned char nonce[], bool encrypt);
 
-//int aes256gcm_decrypt_file(FILE *in, FILE *out, off_t file_size,
-//    unsigned char key[], unsigned char nonce[]);
-
-void aes256gcm_fragment_free(char *fragment);
+char *aes256gcm_create_secure_fragment(unsigned char *key,
+    unsigned char *nonce);
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index c6c34ac1..c6f92e46 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -1653,3 +1653,35 @@ _generate_signed_pre_key(void)
     signal_protocol_signed_pre_key_store_key(omemo_ctx.store, signed_pre_key);
     SIGNAL_UNREF(signed_pre_key);
 }
+
+
+void omemo_free(void *a) {
+    gcry_free(a);
+}
+
+char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) {
+    unsigned char *key = gcry_random_bytes_secure(
+        AES256_GCM_KEY_LENGTH,
+        GCRY_VERY_STRONG_RANDOM);
+
+    // Create nonce/IV with random bytes.
+    unsigned char nonce[AES256_GCM_NONCE_LENGTH];
+    gcry_create_nonce(nonce, AES256_GCM_NONCE_LENGTH);
+
+    char *fragment = aes256gcm_create_secure_fragment(key, nonce);
+    *gcry_res = aes256gcm_crypt_file(in, out, file_size, key, nonce, true);
+
+    if (*gcry_res != GPG_ERR_NO_ERROR) {
+        gcry_free(fragment);
+        fragment = NULL;
+    }
+
+    gcry_free(key);
+
+    return fragment;
+}
+
+//int omemo_decrypt_file(FILE *in, FILE *out, off_t file_size,
+//    unsigned char key[], unsigned char nonce[]) {
+//    return aes256gcm_crypt_file(in, out, file_size, key, nonce, false);
+//}
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index ecfc42d9..0bddd9cd 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -40,6 +40,8 @@
 #define OMEMO_ERR_UNSUPPORTED_CRYPTO -10000
 #define OMEMO_ERR_GCRYPT             -20000
 
+#define OMEMO_AESGCM_URL_SCHEME "aesgcm"
+
 typedef enum {
     PROF_OMEMOPOLICY_MANUAL,
     PROF_OMEMOPOLICY_AUTOMATIC,
@@ -93,5 +95,8 @@ void omemo_start_muc_sessions(const char* const roomjid);
 void omemo_start_device_session(const char* const jid, uint32_t device_id, GList* prekeys, uint32_t signed_prekey_id, const unsigned char* const signed_prekey, size_t signed_prekey_len, const unsigned char* const signature, size_t signature_len, const unsigned char* const identity_key, size_t identity_key_len);
 
 gboolean omemo_loaded(void);
-char* omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_receipt, gboolean muc, const char* const replace_id);
-char* omemo_on_message_recv(const char* const from, uint32_t sid, const unsigned char* const iv, size_t iv_len, GList* keys, const unsigned char* const payload, size_t payload_len, gboolean muc, gboolean* trusted);
+char * omemo_on_message_send(ProfWin *win, const char *const message, gboolean request_receipt, gboolean muc, const char *const replace_id);
+char * omemo_on_message_recv(const char *const from, uint32_t sid, const unsigned char *const iv, size_t iv_len, GList *keys, const unsigned char *const payload, size_t payload_len, gboolean muc, gboolean *trusted);
+
+char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res);
+void omemo_free(void *a);