summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2013-08-01 14:44:51 -0400
committerirungentoo <irungentoo@gmail.com>2013-08-01 14:44:51 -0400
commit633edcf45264203c1c0a2b00aed503e480ab7af4 (patch)
tree4aaf1407009f2e178608461f172cfddd8d1ce566
parentd534a052648cc0085d6d6e40c22701e2feb5b416 (diff)
Fixed possible timing problem.
-rw-r--r--core/net_crypto.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 2cc6f06e..83cb20a2 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -73,10 +73,13 @@ int encrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
73 /* if encryption is successful the first crypto_box_BOXZEROBYTES of the message will be zero 73 /* if encryption is successful the first crypto_box_BOXZEROBYTES of the message will be zero
74 apparently memcmp should not be used so we do this instead:*/ 74 apparently memcmp should not be used so we do this instead:*/
75 uint32_t i; 75 uint32_t i;
76 uint32_t check = 0;
76 for(i = 0; i < crypto_box_BOXZEROBYTES; ++i) { 77 for(i = 0; i < crypto_box_BOXZEROBYTES; ++i) {
77 if (temp_encrypted[i] != 0) 78 if (temp_encrypted[i] != 0)
78 return -1; 79 check = 1;
79 } 80 }
81 if(check == 1)
82 return -1;
80 83
81 /* unpad the encrypted message */ 84 /* unpad the encrypted message */
82 memcpy(encrypted, temp_encrypted + crypto_box_BOXZEROBYTES, length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES); 85 memcpy(encrypted, temp_encrypted + crypto_box_BOXZEROBYTES, length - crypto_box_BOXZEROBYTES + crypto_box_ZEROBYTES);
@@ -105,10 +108,13 @@ int decrypt_data(uint8_t *public_key, uint8_t *secret_key, uint8_t *nonce,
105 /* if decryption is successful the first crypto_box_ZEROBYTES of the message will be zero 108 /* if decryption is successful the first crypto_box_ZEROBYTES of the message will be zero
106 apparently memcmp should not be used so we do this instead:*/ 109 apparently memcmp should not be used so we do this instead:*/
107 uint32_t i; 110 uint32_t i;
111 uint32_t check = 0;
108 for(i = 0; i < crypto_box_ZEROBYTES; ++i) { 112 for(i = 0; i < crypto_box_ZEROBYTES; ++i) {
109 if (temp_plain[i] != 0) 113 if (temp_plain[i] != 0)
110 return -1; 114 check = 1;
111 } 115 }
116 if(check == 1)
117 return -1;
112 118
113 /* unpad the plain message */ 119 /* unpad the plain message */
114 memcpy(plain, temp_plain + crypto_box_ZEROBYTES, length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES); 120 memcpy(plain, temp_plain + crypto_box_ZEROBYTES, length - crypto_box_ZEROBYTES + crypto_box_BOXZEROBYTES);