about summary refs log tree commit diff stats
path: root/src/omemo/omemo.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/omemo/omemo.c')
-rw-r--r--src/omemo/omemo.c32
1 files changed, 32 insertions, 0 deletions
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);
+//}