Use crypto_xof() in hs_ntor.c.

This commit is contained in:
Nick Mathewson 2018-12-13 17:15:03 -05:00
parent 9b0dd1ae04
commit b770adbd03

View File

@ -176,7 +176,6 @@ get_introduce1_key_material(const uint8_t *secret_input,
uint8_t keystream[CIPHER256_KEY_LEN + DIGEST256_LEN]; uint8_t keystream[CIPHER256_KEY_LEN + DIGEST256_LEN];
uint8_t info_blob[INFO_BLOB_LEN]; uint8_t info_blob[INFO_BLOB_LEN];
uint8_t kdf_input[KDF_INPUT_LEN]; uint8_t kdf_input[KDF_INPUT_LEN];
crypto_xof_t *xof;
uint8_t *ptr; uint8_t *ptr;
/* Let's build info */ /* Let's build info */
@ -193,10 +192,8 @@ get_introduce1_key_material(const uint8_t *secret_input,
tor_assert(ptr == kdf_input + sizeof(kdf_input)); tor_assert(ptr == kdf_input + sizeof(kdf_input));
/* Now we need to run kdf_input over SHAKE-256 */ /* Now we need to run kdf_input over SHAKE-256 */
xof = crypto_xof_new(); crypto_xof(keystream, sizeof(keystream),
crypto_xof_add_bytes(xof, kdf_input, sizeof(kdf_input)); kdf_input, sizeof(kdf_input));
crypto_xof_squeeze_bytes(xof, keystream, sizeof(keystream)) ;
crypto_xof_free(xof);
{ /* Get the keys */ { /* Get the keys */
memcpy(&hs_ntor_intro_cell_keys_out->enc_key, keystream,CIPHER256_KEY_LEN); memcpy(&hs_ntor_intro_cell_keys_out->enc_key, keystream,CIPHER256_KEY_LEN);
@ -594,7 +591,6 @@ hs_ntor_circuit_key_expansion(const uint8_t *ntor_key_seed, size_t seed_len,
{ {
uint8_t *ptr; uint8_t *ptr;
uint8_t kdf_input[NTOR_KEY_EXPANSION_KDF_INPUT_LEN]; uint8_t kdf_input[NTOR_KEY_EXPANSION_KDF_INPUT_LEN];
crypto_xof_t *xof;
/* Sanity checks on lengths to make sure we are good */ /* Sanity checks on lengths to make sure we are good */
if (BUG(seed_len != DIGEST256_LEN)) { if (BUG(seed_len != DIGEST256_LEN)) {
@ -611,10 +607,8 @@ hs_ntor_circuit_key_expansion(const uint8_t *ntor_key_seed, size_t seed_len,
tor_assert(ptr == kdf_input + sizeof(kdf_input)); tor_assert(ptr == kdf_input + sizeof(kdf_input));
/* Generate the keys */ /* Generate the keys */
xof = crypto_xof_new(); crypto_xof(keys_out, HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN,
crypto_xof_add_bytes(xof, kdf_input, sizeof(kdf_input)); kdf_input, sizeof(kdf_input));
crypto_xof_squeeze_bytes(xof, keys_out, HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN);
crypto_xof_free(xof);
return 0; return 0;
} }