summaryrefslogtreecommitdiff
path: root/core/net_crypto.c
diff options
context:
space:
mode:
Diffstat (limited to 'core/net_crypto.c')
-rw-r--r--core/net_crypto.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 31fb24be..3b5b67f4 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -66,11 +66,11 @@ static int incoming_connections[MAX_INCOMING];
66int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce, 66int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
67 uint8_t *plain, uint32_t length, uint8_t *encrypted) 67 uint8_t *plain, uint32_t length, uint8_t *encrypted)
68{ 68{
69 if (length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES > MAX_DATA_SIZE || length == 0) 69 if (length + crypto_box_MACBYTES > MAX_DATA_SIZE || length == 0)
70 return -1; 70 return -1;
71 71
72 uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_ZEROBYTES - crypto_box_BOXZEROBYTES] = {0}; 72 uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0};
73 uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_ZEROBYTES]; 73 uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES];
74 74
75 memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length); /* pad the message with 32 0 bytes. */ 75 memcpy(temp_plain + crypto_box_ZEROBYTES, plain, length); /* pad the message with 32 0 bytes. */
76 76
@@ -87,7 +87,7 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
87 return -1; 87 return -1;
88 88
89 /* unpad the encrypted message */ 89 /* unpad the encrypted message */
90 memcpy(encrypted, temp_encrypted + crypto_box_BOXZEROBYTES, length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES); 90 memcpy(encrypted, temp_encrypted + crypto_box_BOXZEROBYTES, length + crypto_box_MACBYTES);
91 return length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES; 91 return length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES;
92} 92}
93 93
@@ -101,8 +101,8 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
101 if (length > MAX_DATA_SIZE || length <= crypto_box_BOXZEROBYTES) 101 if (length > MAX_DATA_SIZE || length <= crypto_box_BOXZEROBYTES)
102 return -1; 102 return -1;
103 103
104 uint8_t temp_plain[MAX_DATA_SIZE - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES]; 104 uint8_t temp_plain[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES];
105 uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_ZEROBYTES] = {0}; 105 uint8_t temp_encrypted[MAX_DATA_SIZE + crypto_box_BOXZEROBYTES] = {0};
106 106
107 memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length); /* pad the message with 16 0 bytes. */ 107 memcpy(temp_encrypted + crypto_box_BOXZEROBYTES, encrypted, length); /* pad the message with 16 0 bytes. */
108 108
@@ -121,7 +121,7 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
121 return -1; 121 return -1;
122 122
123 /* unpad the plain message */ 123 /* unpad the plain message */
124 memcpy(plain, temp_plain + crypto_box_ZEROBYTES, length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES); 124 memcpy(plain, temp_plain + crypto_box_ZEROBYTES, length - crypto_box_MACBYTES);
125 return length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES; 125 return length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES;
126} 126}
127 127