12#define RELAY_CRYPTO_CGO_PRIVATE 
   36cgo_et_keylen(
int aesbits)
 
   54  size_t aes_key_bytes = aesbits / 8;
 
   55  et->kb = aes_raw_new(key, aesbits, encrypt);
 
   58  polyvalx_init(&et->ku, key + aes_key_bytes);
 
 
   68  size_t aes_key_bytes = aesbits / 8;
 
   69  aes_raw_set_key(&et->kb, key, aesbits, encrypt);
 
   70  polyvalx_init(&et->ku, key + aes_key_bytes);
 
 
   82  block1[0] = tweak.uiv.cmd;
 
   83  memcpy(block1+1, tweak.x_r, 15);
 
   84  polyvalx_add_block(pvk, tweak.uiv.h);
 
   85  polyvalx_add_block(pvk, block1);
 
   86  polyvalx_add_zpad(pvk, tweak.x_r + 15, ET_TWEAK_LEN_X_R - 15);
 
   87  polyvalx_get_tag(pvk, t_out);
 
 
   93  for (
int i = 0; i < 16; ++i)
 
 
  107  aes_raw_encrypt(et->kb, block);
 
 
  120  aes_raw_decrypt(et->kb, block);
 
 
  131  aes_raw_free(et->kb);
 
 
  135cgo_prf_keylen(
int aesbits)
 
  151  const uint8_t iv[16] = {0};
 
  152  size_t aes_key_bytes = aesbits / 8;
 
  153  memset(prf,0, 
sizeof(*prf));
 
  154  prf->k = aes_new_cipher(key, iv, aesbits);
 
 
  165  size_t aes_key_bytes = aesbits / 8;
 
 
  189  aes_crypt_inplace(prf->k, (
char*) data, PRF_T0_DATA_LEN);
 
  194  const int ns = 16 - (PRF_T0_DATA_LEN & 0xf);
 
  196  aes_crypt_inplace(prf->k, (
char*)hash,  ns);
 
 
  206               uint8_t *buf, 
size_t n)
 
  215  hash[15] += T1_OFFSET; 
 
  219  aes_crypt_inplace(prf->k, (
char*)buf, n);
 
  222  size_t ns = 16-(n&0x0f);
 
  225    aes_crypt_inplace(prf->k, (
char*) hash, ns);
 
 
  236  aes_cipher_free(prf->k);
 
 
  240cgo_uiv_keylen(
int aesbits)
 
  242  return cgo_et_keylen(aesbits) + cgo_prf_keylen(aesbits);
 
  259  size_t aes_key_bytes = aesbits / 8;
 
  260  if (
cgo_et_init(&uiv->j, aesbits, encrypt, key) < 0)
 
  267  tor_assert(total_key_len <= 
sizeof(uiv->uiv_keys_));
 
  268  memset(uiv->uiv_keys_, 0, 
sizeof(uiv->uiv_keys_));
 
  269  memcpy(uiv->uiv_keys_, key, total_key_len);
 
 
  281  uint8_t *X_L = cell_body;
 
  282  uint8_t *X_R = cell_body + 16;
 
  284  const et_tweak_t et_tweak = {
 
 
  299  uint8_t *X_L = cell_body;
 
  300  uint8_t *X_R = cell_body + 16;
 
  302  const et_tweak_t et_tweak = {
 
 
  318  size_t aes_bytes = aesbits / 8;
 
  320  size_t total_key_len = single_key_len * 2 + 16;
 
  323  uint8_t *new_keys = tor_malloc(total_key_len);
 
  330  memcpy(nonce, new_keys + single_key_len * 2, 16);
 
  334  memset(uiv->uiv_keys_, 0, 
sizeof(uiv->uiv_keys_));
 
  335  memcpy(uiv->uiv_keys_, new_keys, total_key_len);
 
  339  memwipe(new_keys, 0, total_key_len);
 
 
  364  tor_assert(aesbits == 128 || aesbits == 192 || aesbits == 256);
 
 
  380cgo_crypt_new(cgo_mode_t mode, 
int aesbits, 
const uint8_t *keys, 
size_t keylen)
 
  383  const uint8_t *end_of_keys = keys + keylen;
 
  386  bool encrypt = (mode == CGO_MODE_RELAY_BACKWARD ||
 
  387                  mode == CGO_MODE_RELAY_FORWARD);
 
  393  keys += cgo_uiv_keylen(aesbits);
 
  398  cgo->aes_bytes = aesbits / 8;
 
   380cgo_crypt_new(cgo_mode_t mode, 
int aesbits, 
const uint8_t *keys, 
size_t keylen) {
…}
 
  421  bool encrypt = (mode == CGO_MODE_RELAY_BACKWARD ||
 
  422                  mode == CGO_MODE_RELAY_FORWARD);
 
  423  cgo_uiv_update(&cgo->uiv, cgo->aes_bytes * 8, encrypt, cgo->nonce);
 
 
  442                        const uint8_t **recognized_tag_out)
 
  453    *recognized_tag_out = cgo->last_tag_relay_fwd;
 
  455    *recognized_tag_out = NULL;
 
 
  490                          const uint8_t **tag_out)
 
  502    *tag_out = cgo->tprime;
 
 
  540                           const uint8_t **tag_out)
 
 
  564                          const uint8_t **recognized_tag_out)
 
  579    *recognized_tag_out = cgo->tprime;
 
  581    *recognized_tag_out = NULL;
 
 
void aes_cipher_set_key(aes_cnt_cipher_t *cipher_, const uint8_t *key, int key_bits)
void aes_cipher_set_iv_aligned(aes_cnt_cipher_t *cipher_, const uint8_t *iv)
Inline functions for reading and writing multibyte values from the middle of strings,...
Fixed-size cell structure.
void memwipe(void *mem, uint8_t byte, size_t sz)
Common functions for cryptographic routines.
int tor_memeq(const void *a, const void *b, size_t sz)
Master header file for Tor-specific functionality.
#define SENDME_TAG_LEN_CGO
Implementation for polyval universal hash function.
void polyval_add_block(polyval_t *, const uint8_t *block)
void polyval_get_tag(const polyval_t *, uint8_t *tag_out)
void polyval_init_from_key(polyval_t *, const polyval_key_t *key)
void polyval_key_init(polyval_key_t *, const uint8_t *key)
Header for relay_crypto.c.
#define MAX_RELAY_KEY_MATERIAL_LEN
STATIC int cgo_et_init(cgo_et_t *et, int aesbits, bool encrypt, const uint8_t *key)
STATIC int cgo_uiv_init(cgo_uiv_t *uiv, int aesbits, bool encrypt, const uint8_t *key)
STATIC void cgo_prf_xor_t0(cgo_prf_t *prf, const uint8_t *input, uint8_t *data)
STATIC void cgo_uiv_clear(cgo_uiv_t *uiv)
void cgo_crypt_relay_originate(cgo_crypt_t *cgo, cell_t *cell, const uint8_t **tag_out)
void cgo_crypt_client_forward(cgo_crypt_t *cgo, cell_t *cell)
static void compute_et_mask(polyvalx_t *pvk, const et_tweak_t tweak, uint8_t *t_out)
void cgo_crypt_relay_backward(cgo_crypt_t *cgo, cell_t *cell)
STATIC void cgo_et_decrypt(cgo_et_t *et, const et_tweak_t tweak, uint8_t *block)
STATIC void cgo_et_set_key(cgo_et_t *et, int aesbits, bool encrypt, const uint8_t *key)
STATIC void cgo_uiv_encrypt(cgo_uiv_t *uiv, const uiv_tweak_t tweak, uint8_t *cell_body)
STATIC void cgo_et_clear(cgo_et_t *et)
STATIC int cgo_prf_init(cgo_prf_t *prf, int aesbits, const uint8_t *key)
size_t cgo_key_material_len(int aesbits)
static void xor_block(uint8_t *out, const uint8_t *inp)
STATIC void cgo_prf_clear(cgo_prf_t *prf)
void cgo_crypt_relay_forward(cgo_crypt_t *cgo, cell_t *cell, const uint8_t **recognized_tag_out)
STATIC void cgo_uiv_update(cgo_uiv_t *uiv, int aesbits, bool encrypt, uint8_t *nonce)
void cgo_crypt_free_(cgo_crypt_t *cgo)
static void cgo_crypt_update(cgo_crypt_t *cgo, cgo_mode_t mode)
STATIC void cgo_prf_set_key(cgo_prf_t *prf, int aesbits, const uint8_t *key)
cgo_crypt_t * cgo_crypt_new(cgo_mode_t mode, int aesbits, const uint8_t *keys, size_t keylen)
STATIC void cgo_prf_gen_t1(cgo_prf_t *prf, const uint8_t *input, uint8_t *buf, size_t n)
void cgo_crypt_client_originate(cgo_crypt_t *cgo, cell_t *cell, const uint8_t **tag_out)
STATIC void cgo_et_encrypt(cgo_et_t *et, const et_tweak_t tweak, uint8_t *block)
void cgo_crypt_client_backward(cgo_crypt_t *cgo, cell_t *cell, const uint8_t **recognized_tag_out)
STATIC void cgo_uiv_decrypt(cgo_uiv_t *uiv, const uiv_tweak_t tweak, uint8_t *cell_body)
Header file for relay_crypto_cgo.c.
struct cgo_crypt_t cgo_crypt_t
uint8_t payload[CELL_PAYLOAD_SIZE]
Macros to manage assertions, fatal and non-fatal.