From 4711fc62a3d691d35400bc7316f9026c64227d51 Mon Sep 17 00:00:00 2001 From: William Wennerström Date: Mon, 20 Jul 2020 13:01:05 +0200 Subject: Run make format on rebase --- src/omemo/crypto.c | 20 ++++++++++++-------- src/omemo/crypto.h | 18 +++++++++--------- src/omemo/omemo.c | 13 ++++++++----- src/omemo/omemo.h | 8 ++++---- 4 files changed, 33 insertions(+), 26 deletions(-) (limited to 'src/omemo') diff --git a/src/omemo/crypto.c b/src/omemo/crypto.c index 3be64636..a9f72626 100644 --- a/src/omemo/crypto.c +++ b/src/omemo/crypto.c @@ -41,7 +41,7 @@ #include "omemo/omemo.h" #include "omemo/crypto.h" -#define AES256_GCM_TAG_LENGTH 16 +#define AES256_GCM_TAG_LENGTH 16 #define AES256_GCM_BUFFER_SIZE 1024 int @@ -377,8 +377,10 @@ out: return res; } -int aes256gcm_crypt_file(FILE *in, FILE *out, off_t file_size, - unsigned char key[], unsigned char nonce[], bool encrypt) { +int +aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size, + unsigned char key[], unsigned char nonce[], bool encrypt) +{ if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P)) { fputs("libgcrypt has not been initialized\n", stderr); @@ -393,7 +395,7 @@ int aes256gcm_crypt_file(FILE *in, FILE *out, off_t file_size, gcry_cipher_hd_t hd; res = gcry_cipher_open(&hd, GCRY_CIPHER_AES256, GCRY_CIPHER_MODE_GCM, - GCRY_CIPHER_SECURE); + GCRY_CIPHER_SECURE); if (res != GPG_ERR_NO_ERROR) { goto out; } @@ -463,18 +465,20 @@ out: return res; } -char *aes256gcm_create_secure_fragment(unsigned char *key, unsigned char *nonce) { +char* +aes256gcm_create_secure_fragment(unsigned char* key, unsigned char* nonce) +{ int key_size = AES256_GCM_KEY_LENGTH; int nonce_size = AES256_GCM_NONCE_LENGTH; - char *fragment = gcry_malloc_secure((nonce_size+key_size)*2+1); + char* fragment = gcry_malloc_secure((nonce_size + key_size) * 2 + 1); for (int i = 0; i < nonce_size; i++) { - sprintf(&(fragment[i*2]), "%02x", nonce[i]); + sprintf(&(fragment[i * 2]), "%02x", nonce[i]); } for (int i = 0; i < key_size; i++) { - sprintf(&(fragment[(i+nonce_size)*2]), "%02x", key[i]); + sprintf(&(fragment[(i + nonce_size) * 2]), "%02x", key[i]); } return fragment; diff --git a/src/omemo/crypto.h b/src/omemo/crypto.h index e8d91ecc..f0090daf 100644 --- a/src/omemo/crypto.h +++ b/src/omemo/crypto.h @@ -40,7 +40,7 @@ #define AES128_GCM_IV_LENGTH 12 #define AES128_GCM_TAG_LENGTH 16 -#define AES256_GCM_KEY_LENGTH 32 +#define AES256_GCM_KEY_LENGTH 32 #define AES256_GCM_NONCE_LENGTH 12 int omemo_crypto_init(void); @@ -181,13 +181,13 @@ int aes128gcm_encrypt(unsigned char* ciphertext, size_t* ciphertext_len, const unsigned char* const plaintext, size_t plaintext_len, const unsigned char* const iv, const unsigned char* const key); -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 iv_len, - const unsigned char *const key, const unsigned char *const tag); +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 iv_len, + const unsigned char* const key, const unsigned char* const tag); -int aes256gcm_crypt_file(FILE *in, FILE *out, off_t file_size, - unsigned char key[], unsigned char nonce[], bool encrypt); +int aes256gcm_crypt_file(FILE* in, FILE* out, off_t file_size, + unsigned char key[], unsigned char nonce[], bool encrypt); -char *aes256gcm_create_secure_fragment(unsigned char *key, - unsigned char *nonce); +char* aes256gcm_create_secure_fragment(unsigned char* key, + unsigned char* nonce); diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c index c6f92e46..e08d3f06 100644 --- a/src/omemo/omemo.c +++ b/src/omemo/omemo.c @@ -1654,13 +1654,16 @@ _generate_signed_pre_key(void) SIGNAL_UNREF(signed_pre_key); } - -void omemo_free(void *a) { +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( +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); @@ -1668,7 +1671,7 @@ char *omemo_encrypt_file(FILE *in, FILE *out, off_t file_size, int *gcry_res) { unsigned char nonce[AES256_GCM_NONCE_LENGTH]; gcry_create_nonce(nonce, AES256_GCM_NONCE_LENGTH); - char *fragment = aes256gcm_create_secure_fragment(key, nonce); + 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) { diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h index 0bddd9cd..e875dadd 100644 --- a/src/omemo/omemo.h +++ b/src/omemo/omemo.h @@ -95,8 +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); +char* omemo_encrypt_file(FILE* in, FILE* out, off_t file_size, int* gcry_res); +void omemo_free(void* a); -- cgit 1.4.1-2-gfad0 '>^
4feb3daf ^



d4b4d018 ^



4feb3daf ^

0ca35d02 ^
d4b4d018 ^
7d2c2d55 ^
4b62edd8 ^
7d2c2d55 ^
4feb3daf ^
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