about summary refs log tree commit diff stats
path: root/src/omemo
diff options
context:
space:
mode:
authorWilliam Wennerström <william@wstrm.dev>2020-06-28 15:16:03 +0200
committerWilliam Wennerström <william@wstrm.dev>2020-11-16 21:58:08 +0100
commitf4ab1ca9e75bbc635781c795089bf669ee08942d (patch)
treeb928a6dfcf9c093b6aee7bcecf0dfd139c1298e2 /src/omemo
parente98644f631b516e38dd4142103356ceb31628aab (diff)
downloadprofani-tty-f4ab1ca9e75bbc635781c795089bf669ee08942d.tar.gz
Move file encryption function to public header
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);
Blame the previous revision' href='/akkartik/mu/blame/mu.vim?h=hlt&id=09788d7edfd63e89b05413c0279fa112e237ee50'>^
3e1349d2 ^
af7349d5 ^
3e1349d2 ^


dd660682 ^
01ce563d ^
fbf0536d ^
b38d7fff ^
e82dc626 ^
f918675c ^


b085378e ^
e82dc626 ^
38f0b91a ^
f0c55e6b ^
e82dc626 ^
f0c55e6b ^


e82dc626 ^



f0c55e6b ^





e82dc626 ^

458ee5e3 ^
e82dc626 ^
f0c55e6b ^

816ffe20 ^
458ee5e3 ^
f0c55e6b ^
458ee5e3 ^
b085378e ^
f0c55e6b ^

458ee5e3 ^
b38d7fff ^

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98