aboutsummaryrefslogtreecommitdiff
path: root/src/test/test_crypto.c
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2016-12-12 16:45:28 -0500
committerNick Mathewson <nickm@torproject.org>2016-12-14 15:18:40 -0500
commit118691cd47e53521319cdcbf994f29ecca3db4d1 (patch)
tree78d64377d8a03653091601e18c3db6fc6424e65b /src/test/test_crypto.c
parent7a204ae8f9c54c15e9bc05b9c2bd62c7e46d6ebb (diff)
downloadtor-118691cd47e53521319cdcbf994f29ecca3db4d1.tar.gz
tor-118691cd47e53521319cdcbf994f29ecca3db4d1.zip
crypto: Change crypto_mac_sha3_256 to use the key length in the construction
Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/test/test_crypto.c')
-rw-r--r--src/test/test_crypto.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/test/test_crypto.c b/src/test/test_crypto.c
index 91c55d8c3d..d66ddccd4f 100644
--- a/src/test/test_crypto.c
+++ b/src/test/test_crypto.c
@@ -1147,28 +1147,34 @@ test_crypto_mac_sha3(void *arg)
const char msg[] = "i am in a library somewhere using my computer";
const char key[] = "i'm from the past talking to the future.";
- char hmac_test[DIGEST256_LEN];
+ uint8_t hmac_test[DIGEST256_LEN];
char hmac_manual[DIGEST256_LEN];
(void) arg;
/* First let's use our nice HMAC-SHA3 function */
crypto_mac_sha3_256(hmac_test, sizeof(hmac_test),
- key, strlen(key),
- msg, strlen(msg));
+ (uint8_t *) key, strlen(key),
+ (uint8_t *) msg, strlen(msg));
- /* Now let's try a manual H(k || m) construction */
+ /* Now let's try a manual H(len(k) || k || m) construction */
{
- char *key_msg_concat = NULL;
+ char *key_msg_concat = NULL, *all = NULL;
int result;
+ const uint64_t key_len_netorder = tor_htonll(strlen(key));
+ size_t all_len;
tor_asprintf(&key_msg_concat, "%s%s", key, msg);
+ all_len = sizeof(key_len_netorder) + strlen(key_msg_concat);
+ all = tor_malloc_zero(all_len);
+ memcpy(all, &key_len_netorder, sizeof(key_len_netorder));
+ memcpy(all + sizeof(key_len_netorder), key_msg_concat,
+ strlen(key_msg_concat));
- result = crypto_digest256(hmac_manual,
- key_msg_concat, strlen(key_msg_concat),
- DIGEST_SHA3_256);
- tt_int_op(result, ==, 0);
+ result = crypto_digest256(hmac_manual, all, all_len, DIGEST_SHA3_256);
tor_free(key_msg_concat);
+ tor_free(all);
+ tt_int_op(result, ==, 0);
}
/* Now compare the two results */