Commit 8b4085ff authored by antma's avatar antma

AES_KEY structure clean up

parent 167fcea0
...@@ -348,6 +348,7 @@ void init_aes_unauth (const char server_nonce[16], const char hidden_client_nonc ...@@ -348,6 +348,7 @@ void init_aes_unauth (const char server_nonce[16], const char hidden_client_nonc
} else { } else {
AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key); AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key);
} }
memset (aes_key_raw, 0, sizeof (aes_key_raw));
} }
void init_aes_auth (char auth_key[192], char msg_key[16], int encrypt) { void init_aes_auth (char auth_key[192], char msg_key[16], int encrypt) {
...@@ -387,6 +388,7 @@ void init_aes_auth (char auth_key[192], char msg_key[16], int encrypt) { ...@@ -387,6 +388,7 @@ void init_aes_auth (char auth_key[192], char msg_key[16], int encrypt) {
} else { } else {
AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key); AES_set_decrypt_key (aes_key_raw, 32*8, &aes_key);
} }
memset (aes_key_raw, 0, sizeof (aes_key_raw));
} }
int pad_aes_encrypt (char *from, int from_len, char *to, int size) { int pad_aes_encrypt (char *from, int from_len, char *to, int size) {
......
...@@ -746,6 +746,7 @@ char *encrypt_decrypted_message (struct secret_chat *E) { ...@@ -746,6 +746,7 @@ char *encrypt_decrypted_message (struct secret_chat *E) {
AES_KEY aes_key; AES_KEY aes_key;
AES_set_encrypt_key (key, 256, &aes_key); AES_set_encrypt_key (key, 256, &aes_key);
AES_ige_encrypt ((void *)encr_ptr, (void *)encr_ptr, 4 * (encr_end - encr_ptr), &aes_key, iv, 1); AES_ige_encrypt ((void *)encr_ptr, (void *)encr_ptr, 4 * (encr_end - encr_ptr), &aes_key, iv, 1);
memset (&aes_key, 0, sizeof (aes_key));
return (void *)msg_key; return (void *)msg_key;
} }
...@@ -1290,15 +1291,14 @@ void send_part (struct send_file *f) { ...@@ -1290,15 +1291,14 @@ void send_part (struct send_file *f) {
if (f->encr) { if (f->encr) {
if (x & 15) { if (x & 15) {
assert (f->offset == f->size); assert (f->offset == f->size);
if (x & 15) { secure_random (buf + x, (-x) & 15);
secure_random (buf + x, (-x) & 15); x = (x + 15) & ~15;
x = (x + 15) & ~15;
}
} }
AES_KEY aes_key; AES_KEY aes_key;
AES_set_encrypt_key (f->key, 256, &aes_key); AES_set_encrypt_key (f->key, 256, &aes_key);
AES_ige_encrypt ((void *)buf, (void *)buf, x, &aes_key, f->iv, 1); AES_ige_encrypt ((void *)buf, (void *)buf, x, &aes_key, f->iv, 1);
memset (&aes_key, 0, sizeof (aes_key));
} }
out_cstring (buf, x); out_cstring (buf, x);
if (verbosity >= 2) { if (verbosity >= 2) {
...@@ -1803,6 +1803,7 @@ int download_on_answer (struct query *q) { ...@@ -1803,6 +1803,7 @@ int download_on_answer (struct query *q) {
AES_KEY aes_key; AES_KEY aes_key;
AES_set_decrypt_key (D->key, 256, &aes_key); AES_set_decrypt_key (D->key, 256, &aes_key);
AES_ige_encrypt (ptr, ptr, len, &aes_key, D->iv, 0); AES_ige_encrypt (ptr, ptr, len, &aes_key, D->iv, 0);
memset (&aes_key, 0, sizeof (aes_key));
if (len > D->size - D->offset) { if (len > D->size - D->offset) {
len = D->size - D->offset; len = D->size - D->offset;
} }
......
...@@ -1376,6 +1376,7 @@ int decrypt_encrypted_message (struct secret_chat *E) { ...@@ -1376,6 +1376,7 @@ int decrypt_encrypted_message (struct secret_chat *E) {
AES_KEY aes_key; AES_KEY aes_key;
AES_set_decrypt_key (key, 256, &aes_key); AES_set_decrypt_key (key, 256, &aes_key);
AES_ige_encrypt ((void *)decr_ptr, (void *)decr_ptr, 4 * (decr_end - decr_ptr), &aes_key, iv, 0); AES_ige_encrypt ((void *)decr_ptr, (void *)decr_ptr, 4 * (decr_end - decr_ptr), &aes_key, iv, 0);
memset (&aes_key, 0, sizeof (aes_key));
int x = *(decr_ptr); int x = *(decr_ptr);
if (x < 0 || (x & 3)) { if (x < 0 || (x & 3)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment