16#include "core/crypto/relay_crypto_tor1.h"
23#define V0_DIGEST_OFFSET 5
24#define V0_DIGEST_LEN 4
25#define V0_RECOGNIZED_OFFSET 1
37 memcpy(cell->
payload + V0_DIGEST_OFFSET, buf, V0_DIGEST_LEN);
52 uint32_t received_integrity, calculated_integrity;
56 CTASSERT(
sizeof(uint32_t) == V0_DIGEST_LEN);
60 memcpy(&received_integrity, cell->
payload + V0_DIGEST_OFFSET, V0_DIGEST_LEN);
61 memset(cell->
payload + V0_DIGEST_OFFSET, 0, V0_DIGEST_LEN);
69 calculated_integrity =
get_uint32(calculated_digest);
73 if (calculated_integrity != received_integrity) {
79 memcpy(cell->
payload + V0_DIGEST_OFFSET, &received_integrity,
86 memwipe(&backup_digest, 0,
sizeof(backup_digest));
91relay_cell_is_recognized_v0(
const cell_t *cell)
165 if (relay_cell_is_recognized_v0(cell)) {
185 if (relay_cell_is_recognized_v0(cell)) {
199 return HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN;
201 return CPATH_KEY_MATERIAL_LEN;
223 const char *key_data,
size_t key_data_len,
224 int reverse,
int is_hs_v3)
227 crypto_cipher_t *tmp_crypto;
228 size_t digest_len = 0;
229 size_t cipher_key_len = 0;
237 if (is_hs_v3 && BUG(key_data_len != HS_NTOR_KEY_EXPANSION_KDF_OUT_LEN)) {
239 }
else if (!is_hs_v3 && BUG(key_data_len != CPATH_KEY_MATERIAL_LEN)) {
259 const int cipher_key_bits = (int) cipher_key_len * 8;
267 log_warn(
LD_BUG,
"Forward cipher initialization failed.");
272 key_data+(2*digest_len)+cipher_key_len,
275 log_warn(
LD_BUG,
"Backward cipher initialization failed.");
290 tor1_crypt_clear(crypto);
309 crypto_cipher_free(crypto->
f_crypto);
310 crypto_cipher_free(crypto->
b_crypto);
static uint16_t get_uint16(const void *cp)
static uint32_t get_uint32(const void *cp)
Fixed-size cell structure.
crypto_cipher_t * crypto_cipher_new_with_bits(const char *key, int bits)
void crypto_cipher_crypt_inplace(crypto_cipher_t *env, char *buf, size_t len)
Headers for crypto_cipher.c.
#define CIPHER256_KEY_LEN
void crypto_digest_checkpoint(crypto_digest_checkpoint_t *checkpoint, const crypto_digest_t *digest)
void crypto_digest_restore(crypto_digest_t *digest, const crypto_digest_checkpoint_t *checkpoint)
void crypto_digest_get_digest(crypto_digest_t *digest, char *out, size_t out_len)
#define crypto_digest_free(d)
crypto_digest_t * crypto_digest256_new(digest_algorithm_t algorithm)
void crypto_digest_add_bytes(crypto_digest_t *digest, const char *data, size_t len)
crypto_digest_t * crypto_digest_new(void)
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
Compile-time assertions: CTASSERT(expression).
CTASSERT(NUMBER_SECOND_GUARDS< 20)
Master header file for Tor-specific functionality.
#define CELL_PAYLOAD_SIZE
Relay-cell encryption state structure.
void tor1_crypt_client_forward(tor1_crypt_t *tor1, cell_t *cell)
void tor1_crypt_assert_ok(const tor1_crypt_t *crypto)
static void tor1_set_digest_v0(crypto_digest_t *digest, cell_t *cell, uint8_t *buf)
void tor1_crypt_relay_backward(tor1_crypt_t *tor1, cell_t *cell)
void tor1_crypt_relay_originate(tor1_crypt_t *tor1, cell_t *cell)
static int tor1_relay_digest_matches_v0(crypto_digest_t *digest, cell_t *cell, uint8_t *buf)
static void tor1_crypt_one_payload(crypto_cipher_t *cipher, uint8_t *in)
int tor1_crypt_init(tor1_crypt_t *crypto, const char *key_data, size_t key_data_len, int reverse, int is_hs_v3)
void tor1_crypt_client_originate(tor1_crypt_t *tor1, cell_t *cell)
bool tor1_crypt_client_backward(tor1_crypt_t *tor1, cell_t *cell)
size_t tor1_key_material_len(bool is_hs)
bool tor1_crypt_relay_forward(tor1_crypt_t *tor1, cell_t *cell)
uint8_t payload[CELL_PAYLOAD_SIZE]
struct crypto_digest_t * b_digest
struct crypto_digest_t * f_digest
uint8_t sendme_digest[DIGEST_LEN]
struct aes_cnt_cipher_t * b_crypto
struct aes_cnt_cipher_t * f_crypto