Unify this with the trunnel ABI so we don't duplicate.
Part of #30454
Signed-off-by: David Goulet <dgoulet@torproject.org>
}
if (trn_cell_introduce_encrypted_get_onion_key_type(enc_cell) !=
- HS_CELL_ONION_KEY_TYPE_NTOR) {
+ TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR) {
log_info(LD_REND, "INTRODUCE2 onion key type is invalid. Got %u but "
"expected %u on circuit %u for service %s",
trn_cell_introduce_encrypted_get_onion_key_type(enc_cell),
- HS_CELL_ONION_KEY_TYPE_NTOR, TO_CIRCUIT(circ)->n_circ_id,
+ TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR,
+ TO_CIRCUIT(circ)->n_circ_id,
safe_str_client(service->onion_address));
goto err;
}
tor_assert(onion_pk);
/* There is only one possible key type for a non legacy cell. */
trn_cell_introduce_encrypted_set_onion_key_type(cell,
- HS_CELL_ONION_KEY_TYPE_NTOR);
+ TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR);
trn_cell_introduce_encrypted_set_onion_key_len(cell, CURVE25519_PUBKEY_LEN);
trn_cell_introduce_encrypted_setlen_onion_key(cell, CURVE25519_PUBKEY_LEN);
memcpy(trn_cell_introduce_encrypted_getarray_onion_key(cell), onion_pk,
* 3.2.2 of the specification). Below this value, the cell must be padded. */
#define HS_CELL_INTRODUCE1_MIN_SIZE 246
-/* Onion key type found in the INTRODUCE1 cell. */
-typedef enum {
- HS_CELL_ONION_KEY_TYPE_NTOR = 1,
-} hs_cell_onion_key_type_t;
-
/* This data structure contains data that we need to build an INTRODUCE1 cell
* used by the INTRODUCE1 build function. */
typedef struct hs_cell_introduce1_data_t {
trn_cell_introduce_encrypted_t *val = trunnel_calloc(1, sizeof(trn_cell_introduce_encrypted_t));
if (NULL == val)
return NULL;
- val->onion_key_type = 1;
+ val->onion_key_type = TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR;
return val;
}
int
trn_cell_introduce_encrypted_set_onion_key_type(trn_cell_introduce_encrypted_t *inp, uint8_t val)
{
- if (! ((val == 1))) {
+ if (! ((val == TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR))) {
TRUNNEL_SET_ERROR_CODE(inp);
return -1;
}
if (NULL != (msg = trn_cell_extension_check(obj->extensions)))
return msg;
}
- if (! (obj->onion_key_type == 1))
+ if (! (obj->onion_key_type == TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR))
return "Integer out of bounds";
if (TRUNNEL_DYNARRAY_LEN(&obj->onion_key) != obj->onion_key_len)
return "Length mismatch for onion_key";
/* Length of struct trn_cell_extension extensions */
result += trn_cell_extension_encoded_len(obj->extensions);
- /* Length of u8 onion_key_type IN [1] */
+ /* Length of u8 onion_key_type IN [TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR] */
result += 1;
/* Length of u16 onion_key_len */
goto fail; /* XXXXXXX !*/
written += result; ptr += result;
- /* Encode u8 onion_key_type IN [1] */
+ /* Encode u8 onion_key_type IN [TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR] */
trunnel_assert(written <= avail);
if (avail - written < 1)
goto truncated;
trunnel_assert((size_t)result <= remaining);
remaining -= result; ptr += result;
- /* Parse u8 onion_key_type IN [1] */
+ /* Parse u8 onion_key_type IN [TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR] */
CHECK_REMAINING(1, truncated);
obj->onion_key_type = (trunnel_get_uint8(ptr));
remaining -= 1; ptr += 1;
- if (! (obj->onion_key_type == 1))
+ if (! (obj->onion_key_type == TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR))
goto fail;
/* Parse u16 onion_key_len */
#define TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_LEGACY0 0
#define TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_LEGACY1 1
#define TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_ED25519 2
+#define TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR 1
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE1)
struct trn_cell_introduce1_st {
uint8_t legacy_key_id[TRUNNEL_SHA1_LEN];
const TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_LEGACY1 = 0x01;
const TRUNNEL_HS_INTRO_AUTH_KEY_TYPE_ED25519 = 0x02;
+/* Onion key type. */
+const TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR = 0x01;
+
/* INTRODUCE1 payload. See details in section 3.2.1. */
struct trn_cell_introduce1 {
/* Always zeroed. MUST be checked explicitly by the caller. */
struct trn_cell_extension extensions;
/* Onion key material. */
- u8 onion_key_type IN [0x01];
+ u8 onion_key_type IN [TRUNNEL_HS_INTRO_ONION_KEY_TYPE_NTOR];
u16 onion_key_len;
u8 onion_key[onion_key_len];