Merge remote-tracking branch 'dgoulet/ticket21919_031_01'

This commit is contained in:
Nick Mathewson 2017-04-13 09:38:59 -04:00
commit 28ec2d9c2c
16 changed files with 984 additions and 976 deletions

View File

@ -31,7 +31,7 @@
# define IS_LITTLE_ENDIAN # define IS_LITTLE_ENDIAN
# endif # endif
#else #else
# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD) # if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__)
# include <sys/endian.h> # include <sys/endian.h>
# else # else
# include <endian.h> # include <endian.h>

View File

@ -43,16 +43,16 @@ get_auth_key_from_cell(ed25519_public_key_t *auth_key_out,
switch (cell_type) { switch (cell_type) {
case RELAY_COMMAND_ESTABLISH_INTRO: case RELAY_COMMAND_ESTABLISH_INTRO:
{ {
const hs_cell_establish_intro_t *c_cell = cell; const trn_cell_establish_intro_t *c_cell = cell;
key_array = hs_cell_establish_intro_getconstarray_auth_key(c_cell); key_array = trn_cell_establish_intro_getconstarray_auth_key(c_cell);
auth_key_len = hs_cell_establish_intro_getlen_auth_key(c_cell); auth_key_len = trn_cell_establish_intro_getlen_auth_key(c_cell);
break; break;
} }
case RELAY_COMMAND_INTRODUCE1: case RELAY_COMMAND_INTRODUCE1:
{ {
const hs_cell_introduce1_t *c_cell = cell; const trn_cell_introduce1_t *c_cell = cell;
key_array = hs_cell_introduce1_getconstarray_auth_key(cell); key_array = trn_cell_introduce1_getconstarray_auth_key(cell);
auth_key_len = hs_cell_introduce1_getlen_auth_key(c_cell); auth_key_len = trn_cell_introduce1_getlen_auth_key(c_cell);
break; break;
} }
default: default:
@ -68,7 +68,7 @@ get_auth_key_from_cell(ed25519_public_key_t *auth_key_out,
/** We received an ESTABLISH_INTRO <b>cell</b>. Verify its signature and MAC, /** We received an ESTABLISH_INTRO <b>cell</b>. Verify its signature and MAC,
* given <b>circuit_key_material</b>. Return 0 on success else -1 on error. */ * given <b>circuit_key_material</b>. Return 0 on success else -1 on error. */
STATIC int STATIC int
verify_establish_intro_cell(const hs_cell_establish_intro_t *cell, verify_establish_intro_cell(const trn_cell_establish_intro_t *cell,
const uint8_t *circuit_key_material, const uint8_t *circuit_key_material,
size_t circuit_key_material_len) size_t circuit_key_material_len)
{ {
@ -82,8 +82,8 @@ verify_establish_intro_cell(const hs_cell_establish_intro_t *cell,
/* Make sure the auth key length is of the right size for this type. For /* Make sure the auth key length is of the right size for this type. For
* EXTRA safety, we check both the size of the array and the length which * EXTRA safety, we check both the size of the array and the length which
* must be the same. Safety first!*/ * must be the same. Safety first!*/
if (hs_cell_establish_intro_getlen_auth_key(cell) != ED25519_PUBKEY_LEN || if (trn_cell_establish_intro_getlen_auth_key(cell) != ED25519_PUBKEY_LEN ||
hs_cell_establish_intro_get_auth_key_len(cell) != ED25519_PUBKEY_LEN) { trn_cell_establish_intro_get_auth_key_len(cell) != ED25519_PUBKEY_LEN) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"ESTABLISH_INTRO auth key length is invalid"); "ESTABLISH_INTRO auth key length is invalid");
return -1; return -1;
@ -94,13 +94,14 @@ verify_establish_intro_cell(const hs_cell_establish_intro_t *cell,
/* Verify the sig */ /* Verify the sig */
{ {
ed25519_signature_t sig_struct; ed25519_signature_t sig_struct;
const uint8_t *sig_array = hs_cell_establish_intro_getconstarray_sig(cell); const uint8_t *sig_array =
trn_cell_establish_intro_getconstarray_sig(cell);
/* Make sure the signature length is of the right size. For EXTRA safety, /* Make sure the signature length is of the right size. For EXTRA safety,
* we check both the size of the array and the length which must be the * we check both the size of the array and the length which must be the
* same. Safety first!*/ * same. Safety first!*/
if (hs_cell_establish_intro_getlen_sig(cell) != sizeof(sig_struct.sig) || if (trn_cell_establish_intro_getlen_sig(cell) != sizeof(sig_struct.sig) ||
hs_cell_establish_intro_get_sig_len(cell) != sizeof(sig_struct.sig)) { trn_cell_establish_intro_get_sig_len(cell) != sizeof(sig_struct.sig)) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"ESTABLISH_INTRO sig len is invalid"); "ESTABLISH_INTRO sig len is invalid");
return -1; return -1;
@ -147,21 +148,21 @@ hs_intro_send_intro_established_cell,(or_circuit_t *circ))
int ret; int ret;
uint8_t *encoded_cell = NULL; uint8_t *encoded_cell = NULL;
ssize_t encoded_len, result_len; ssize_t encoded_len, result_len;
hs_cell_intro_established_t *cell; trn_cell_intro_established_t *cell;
cell_extension_t *ext; trn_cell_extension_t *ext;
tor_assert(circ); tor_assert(circ);
/* Build the cell payload. */ /* Build the cell payload. */
cell = hs_cell_intro_established_new(); cell = trn_cell_intro_established_new();
ext = cell_extension_new(); ext = trn_cell_extension_new();
cell_extension_set_num(ext, 0); trn_cell_extension_set_num(ext, 0);
hs_cell_intro_established_set_extensions(cell, ext); trn_cell_intro_established_set_extensions(cell, ext);
/* Encode the cell to binary format. */ /* Encode the cell to binary format. */
encoded_len = hs_cell_intro_established_encoded_len(cell); encoded_len = trn_cell_intro_established_encoded_len(cell);
tor_assert(encoded_len > 0); tor_assert(encoded_len > 0);
encoded_cell = tor_malloc_zero(encoded_len); encoded_cell = tor_malloc_zero(encoded_len);
result_len = hs_cell_intro_established_encode(encoded_cell, encoded_len, result_len = trn_cell_intro_established_encode(encoded_cell, encoded_len,
cell); cell);
tor_assert(encoded_len == result_len); tor_assert(encoded_len == result_len);
@ -170,7 +171,7 @@ hs_intro_send_intro_established_cell,(or_circuit_t *circ))
(char *) encoded_cell, encoded_len, (char *) encoded_cell, encoded_len,
NULL); NULL);
/* On failure, the above function will close the circuit. */ /* On failure, the above function will close the circuit. */
hs_cell_intro_established_free(cell); trn_cell_intro_established_free(cell);
tor_free(encoded_cell); tor_free(encoded_cell);
return ret; return ret;
} }
@ -180,7 +181,7 @@ hs_intro_send_intro_established_cell,(or_circuit_t *circ))
* establish an intro point. */ * establish an intro point. */
static int static int
handle_verified_establish_intro_cell(or_circuit_t *circ, handle_verified_establish_intro_cell(or_circuit_t *circ,
const hs_cell_establish_intro_t *parsed_cell) const trn_cell_establish_intro_t *parsed_cell)
{ {
/* Get the auth key of this intro point */ /* Get the auth key of this intro point */
ed25519_public_key_t auth_key; ed25519_public_key_t auth_key;
@ -210,7 +211,7 @@ handle_establish_intro(or_circuit_t *circ, const uint8_t *request,
size_t request_len) size_t request_len)
{ {
int cell_ok, retval = -1; int cell_ok, retval = -1;
hs_cell_establish_intro_t *parsed_cell = NULL; trn_cell_establish_intro_t *parsed_cell = NULL;
tor_assert(circ); tor_assert(circ);
tor_assert(request); tor_assert(request);
@ -224,7 +225,7 @@ handle_establish_intro(or_circuit_t *circ, const uint8_t *request,
} }
/* Parse the cell */ /* Parse the cell */
ssize_t parsing_result = hs_cell_establish_intro_parse(&parsed_cell, ssize_t parsing_result = trn_cell_establish_intro_parse(&parsed_cell,
request, request_len); request, request_len);
if (parsing_result < 0) { if (parsing_result < 0) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
@ -259,7 +260,7 @@ handle_establish_intro(or_circuit_t *circ, const uint8_t *request,
circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL); circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL);
done: done:
hs_cell_establish_intro_free(parsed_cell); trn_cell_establish_intro_free(parsed_cell);
return retval; return retval;
} }
@ -339,28 +340,28 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status)
int ret = -1; int ret = -1;
uint8_t *encoded_cell = NULL; uint8_t *encoded_cell = NULL;
ssize_t encoded_len, result_len; ssize_t encoded_len, result_len;
hs_cell_introduce_ack_t *cell; trn_cell_introduce_ack_t *cell;
cell_extension_t *ext; trn_cell_extension_t *ext;
tor_assert(circ); tor_assert(circ);
/* Setup the INTRODUCE_ACK cell. We have no extensions so the N_EXTENSIONS /* Setup the INTRODUCE_ACK cell. We have no extensions so the N_EXTENSIONS
* field is set to 0 by default with a new object. */ * field is set to 0 by default with a new object. */
cell = hs_cell_introduce_ack_new(); cell = trn_cell_introduce_ack_new();
ret = hs_cell_introduce_ack_set_status(cell, status); ret = trn_cell_introduce_ack_set_status(cell, status);
/* We have no cell extensions in an INTRODUCE_ACK cell. */ /* We have no cell extensions in an INTRODUCE_ACK cell. */
ext = cell_extension_new(); ext = trn_cell_extension_new();
cell_extension_set_num(ext, 0); trn_cell_extension_set_num(ext, 0);
hs_cell_introduce_ack_set_extensions(cell, ext); trn_cell_introduce_ack_set_extensions(cell, ext);
/* A wrong status is a very bad code flow error as this value is controlled /* A wrong status is a very bad code flow error as this value is controlled
* by the code in this file and not an external input. This means we use a * by the code in this file and not an external input. This means we use a
* code that is not known by the trunnel ABI. */ * code that is not known by the trunnel ABI. */
tor_assert(ret == 0); tor_assert(ret == 0);
/* Encode the payload. We should never fail to get the encoded length. */ /* Encode the payload. We should never fail to get the encoded length. */
encoded_len = hs_cell_introduce_ack_encoded_len(cell); encoded_len = trn_cell_introduce_ack_encoded_len(cell);
tor_assert(encoded_len > 0); tor_assert(encoded_len > 0);
encoded_cell = tor_malloc_zero(encoded_len); encoded_cell = tor_malloc_zero(encoded_len);
result_len = hs_cell_introduce_ack_encode(encoded_cell, encoded_len, cell); result_len = trn_cell_introduce_ack_encode(encoded_cell, encoded_len, cell);
tor_assert(encoded_len == result_len); tor_assert(encoded_len == result_len);
ret = relay_send_command_from_edge(CONTROL_CELL_ID, TO_CIRCUIT(circ), ret = relay_send_command_from_edge(CONTROL_CELL_ID, TO_CIRCUIT(circ),
@ -368,7 +369,7 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status)
(char *) encoded_cell, encoded_len, (char *) encoded_cell, encoded_len,
NULL); NULL);
/* On failure, the above function will close the circuit. */ /* On failure, the above function will close the circuit. */
hs_cell_introduce_ack_free(cell); trn_cell_introduce_ack_free(cell);
tor_free(encoded_cell); tor_free(encoded_cell);
return ret; return ret;
} }
@ -376,7 +377,7 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status)
/* Validate a parsed INTRODUCE1 <b>cell</b>. Return 0 if valid or else a /* Validate a parsed INTRODUCE1 <b>cell</b>. Return 0 if valid or else a
* negative value for an invalid cell that should be NACKed. */ * negative value for an invalid cell that should be NACKed. */
STATIC int STATIC int
validate_introduce1_parsed_cell(const hs_cell_introduce1_t *cell) validate_introduce1_parsed_cell(const trn_cell_introduce1_t *cell)
{ {
size_t legacy_key_id_len; size_t legacy_key_id_len;
const uint8_t *legacy_key_id; const uint8_t *legacy_key_id;
@ -385,29 +386,29 @@ validate_introduce1_parsed_cell(const hs_cell_introduce1_t *cell)
/* This code path SHOULD NEVER be reached if the cell is a legacy type so /* This code path SHOULD NEVER be reached if the cell is a legacy type so
* safety net here. The legacy ID must be zeroes in this case. */ * safety net here. The legacy ID must be zeroes in this case. */
legacy_key_id_len = hs_cell_introduce1_getlen_legacy_key_id(cell); legacy_key_id_len = trn_cell_introduce1_getlen_legacy_key_id(cell);
legacy_key_id = hs_cell_introduce1_getconstarray_legacy_key_id(cell); legacy_key_id = trn_cell_introduce1_getconstarray_legacy_key_id(cell);
if (BUG(!tor_mem_is_zero((char *) legacy_key_id, legacy_key_id_len))) { if (BUG(!tor_mem_is_zero((char *) legacy_key_id, legacy_key_id_len))) {
goto invalid; goto invalid;
} }
/* The auth key of an INTRODUCE1 should be of type ed25519 thus leading to a /* The auth key of an INTRODUCE1 should be of type ed25519 thus leading to a
* known fixed length as well. */ * known fixed length as well. */
if (hs_cell_introduce1_get_auth_key_type(cell) != if (trn_cell_introduce1_get_auth_key_type(cell) !=
HS_INTRO_AUTH_KEY_TYPE_ED25519) { HS_INTRO_AUTH_KEY_TYPE_ED25519) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Rejecting invalid INTRODUCE1 cell auth key type. " "Rejecting invalid INTRODUCE1 cell auth key type. "
"Responding with NACK."); "Responding with NACK.");
goto invalid; goto invalid;
} }
if (hs_cell_introduce1_get_auth_key_len(cell) != ED25519_PUBKEY_LEN || if (trn_cell_introduce1_get_auth_key_len(cell) != ED25519_PUBKEY_LEN ||
hs_cell_introduce1_getlen_auth_key(cell) != ED25519_PUBKEY_LEN) { trn_cell_introduce1_getlen_auth_key(cell) != ED25519_PUBKEY_LEN) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Rejecting invalid INTRODUCE1 cell auth key length. " "Rejecting invalid INTRODUCE1 cell auth key length. "
"Responding with NACK."); "Responding with NACK.");
goto invalid; goto invalid;
} }
if (hs_cell_introduce1_getlen_encrypted(cell) == 0) { if (trn_cell_introduce1_getlen_encrypted(cell) == 0) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
"Rejecting invalid INTRODUCE1 cell encrypted length. " "Rejecting invalid INTRODUCE1 cell encrypted length. "
"Responding with NACK."); "Responding with NACK.");
@ -430,7 +431,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request,
{ {
int ret = -1; int ret = -1;
or_circuit_t *service_circ; or_circuit_t *service_circ;
hs_cell_introduce1_t *parsed_cell; trn_cell_introduce1_t *parsed_cell;
hs_intro_ack_status_t status = HS_INTRO_ACK_STATUS_SUCCESS; hs_intro_ack_status_t status = HS_INTRO_ACK_STATUS_SUCCESS;
tor_assert(client_circ); tor_assert(client_circ);
@ -439,7 +440,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request,
/* Parse cell. Note that we can only parse the non encrypted section for /* Parse cell. Note that we can only parse the non encrypted section for
* which we'll use the authentication key to find the service introduction * which we'll use the authentication key to find the service introduction
* circuit and relay the cell on it. */ * circuit and relay the cell on it. */
ssize_t cell_size = hs_cell_introduce1_parse(&parsed_cell, request, ssize_t cell_size = trn_cell_introduce1_parse(&parsed_cell, request,
request_len); request_len);
if (cell_size < 0) { if (cell_size < 0) {
log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL,
@ -505,7 +506,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request,
circuit_mark_for_close(TO_CIRCUIT(client_circ), END_CIRC_REASON_INTERNAL); circuit_mark_for_close(TO_CIRCUIT(client_circ), END_CIRC_REASON_INTERNAL);
} }
done: done:
hs_cell_introduce1_free(parsed_cell); trn_cell_introduce1_free(parsed_cell);
return ret; return ret;
} }

View File

@ -41,7 +41,7 @@ int hs_intro_circuit_is_suitable_for_establish_intro(const or_circuit_t *circ);
#include "hs/cell_introduce1.h" #include "hs/cell_introduce1.h"
STATIC int STATIC int
verify_establish_intro_cell(const hs_cell_establish_intro_t *out, verify_establish_intro_cell(const trn_cell_establish_intro_t *out,
const uint8_t *circuit_key_material, const uint8_t *circuit_key_material,
size_t circuit_key_material_len); size_t circuit_key_material_len);
@ -52,7 +52,7 @@ get_auth_key_from_cell(ed25519_public_key_t *auth_key_out,
STATIC int introduce1_cell_is_legacy(const uint8_t *request); STATIC int introduce1_cell_is_legacy(const uint8_t *request);
STATIC int handle_introduce1(or_circuit_t *client_circ, STATIC int handle_introduce1(or_circuit_t *client_circ,
const uint8_t *request, size_t request_len); const uint8_t *request, size_t request_len);
STATIC int validate_introduce1_parsed_cell(const hs_cell_introduce1_t *cell); STATIC int validate_introduce1_parsed_cell(const trn_cell_introduce1_t *cell);
STATIC int circuit_is_suitable_for_introduce1(const or_circuit_t *circ); STATIC int circuit_is_suitable_for_introduce1(const or_circuit_t *circ);
#endif /* HS_INTROPOINT_PRIVATE */ #endif /* HS_INTROPOINT_PRIVATE */

View File

@ -27,7 +27,7 @@
* bytes written, or a negative integer if there was an error. */ * bytes written, or a negative integer if there was an error. */
ssize_t ssize_t
get_establish_intro_payload(uint8_t *buf_out, size_t buf_out_len, get_establish_intro_payload(uint8_t *buf_out, size_t buf_out_len,
const hs_cell_establish_intro_t *cell) const trn_cell_establish_intro_t *cell)
{ {
ssize_t bytes_used = 0; ssize_t bytes_used = 0;
@ -35,31 +35,31 @@ get_establish_intro_payload(uint8_t *buf_out, size_t buf_out_len,
return -1; return -1;
} }
bytes_used = hs_cell_establish_intro_encode(buf_out, buf_out_len, bytes_used = trn_cell_establish_intro_encode(buf_out, buf_out_len,
cell); cell);
return bytes_used; return bytes_used;
} }
/* Set the cell extensions of <b>cell</b>. */ /* Set the cell extensions of <b>cell</b>. */
static void static void
set_cell_extensions(hs_cell_establish_intro_t *cell) set_trn_cell_extensions(trn_cell_establish_intro_t *cell)
{ {
cell_extension_t *cell_extensions = cell_extension_new(); trn_cell_extension_t *trn_cell_extensions = trn_cell_extension_new();
/* For now, we don't use extensions at all. */ /* For now, we don't use extensions at all. */
cell_extensions->num = 0; /* It's already zeroed, but be explicit. */ trn_cell_extensions->num = 0; /* It's already zeroed, but be explicit. */
hs_cell_establish_intro_set_extensions(cell, cell_extensions); trn_cell_establish_intro_set_extensions(cell, trn_cell_extensions);
} }
/** Given the circuit handshake info in <b>circuit_key_material</b>, create and /** Given the circuit handshake info in <b>circuit_key_material</b>, create and
* return an ESTABLISH_INTRO cell. Return NULL if something went wrong. The * return an ESTABLISH_INTRO cell. Return NULL if something went wrong. The
* returned cell is allocated on the heap and it's the responsibility of the * returned cell is allocated on the heap and it's the responsibility of the
* caller to free it. */ * caller to free it. */
hs_cell_establish_intro_t * trn_cell_establish_intro_t *
generate_establish_intro_cell(const uint8_t *circuit_key_material, generate_establish_intro_cell(const uint8_t *circuit_key_material,
size_t circuit_key_material_len) size_t circuit_key_material_len)
{ {
hs_cell_establish_intro_t *cell = NULL; trn_cell_establish_intro_t *cell = NULL;
ssize_t encoded_len; ssize_t encoded_len;
log_warn(LD_GENERAL, log_warn(LD_GENERAL,
@ -72,31 +72,31 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material,
goto err; goto err;
} }
cell = hs_cell_establish_intro_new(); cell = trn_cell_establish_intro_new();
/* Set AUTH_KEY_TYPE: 2 means ed25519 */ /* Set AUTH_KEY_TYPE: 2 means ed25519 */
hs_cell_establish_intro_set_auth_key_type(cell, AUTH_KEY_ED25519); trn_cell_establish_intro_set_auth_key_type(cell, AUTH_KEY_ED25519);
/* Set AUTH_KEY_LEN field */ /* Set AUTH_KEY_LEN field */
/* Must also set byte-length of AUTH_KEY to match */ /* Must also set byte-length of AUTH_KEY to match */
int auth_key_len = ED25519_PUBKEY_LEN; int auth_key_len = ED25519_PUBKEY_LEN;
hs_cell_establish_intro_set_auth_key_len(cell, auth_key_len); trn_cell_establish_intro_set_auth_key_len(cell, auth_key_len);
hs_cell_establish_intro_setlen_auth_key(cell, auth_key_len); trn_cell_establish_intro_setlen_auth_key(cell, auth_key_len);
/* Set AUTH_KEY field */ /* Set AUTH_KEY field */
uint8_t *auth_key_ptr = hs_cell_establish_intro_getarray_auth_key(cell); uint8_t *auth_key_ptr = trn_cell_establish_intro_getarray_auth_key(cell);
memcpy(auth_key_ptr, key_struct.pubkey.pubkey, auth_key_len); memcpy(auth_key_ptr, key_struct.pubkey.pubkey, auth_key_len);
/* No cell extensions needed */ /* No cell extensions needed */
set_cell_extensions(cell); set_trn_cell_extensions(cell);
/* Set signature size. /* Set signature size.
We need to do this up here, because _encode() needs it and we need to call We need to do this up here, because _encode() needs it and we need to call
_encode() to calculate the MAC and signature. _encode() to calculate the MAC and signature.
*/ */
int sig_len = ED25519_SIG_LEN; int sig_len = ED25519_SIG_LEN;
hs_cell_establish_intro_set_sig_len(cell, sig_len); trn_cell_establish_intro_set_sig_len(cell, sig_len);
hs_cell_establish_intro_setlen_sig(cell, sig_len); trn_cell_establish_intro_setlen_sig(cell, sig_len);
/* XXX How to make this process easier and nicer? */ /* XXX How to make this process easier and nicer? */
@ -107,7 +107,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material,
uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0}; uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0};
uint8_t mac[TRUNNEL_SHA3_256_LEN]; uint8_t mac[TRUNNEL_SHA3_256_LEN];
encoded_len = hs_cell_establish_intro_encode(cell_bytes_tmp, encoded_len = trn_cell_establish_intro_encode(cell_bytes_tmp,
sizeof(cell_bytes_tmp), sizeof(cell_bytes_tmp),
cell); cell);
if (encoded_len < 0) { if (encoded_len < 0) {
@ -126,7 +126,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material,
(ED25519_SIG_LEN + 2 + TRUNNEL_SHA3_256_LEN)); (ED25519_SIG_LEN + 2 + TRUNNEL_SHA3_256_LEN));
/* Write the MAC to the cell */ /* Write the MAC to the cell */
uint8_t *handshake_ptr = uint8_t *handshake_ptr =
hs_cell_establish_intro_getarray_handshake_mac(cell); trn_cell_establish_intro_getarray_handshake_mac(cell);
memcpy(handshake_ptr, mac, sizeof(mac)); memcpy(handshake_ptr, mac, sizeof(mac));
} }
@ -137,7 +137,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material,
uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0}; uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0};
ed25519_signature_t sig; ed25519_signature_t sig;
encoded_len = hs_cell_establish_intro_encode(cell_bytes_tmp, encoded_len = trn_cell_establish_intro_encode(cell_bytes_tmp,
sizeof(cell_bytes_tmp), sizeof(cell_bytes_tmp),
cell); cell);
if (encoded_len < 0) { if (encoded_len < 0) {
@ -158,7 +158,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material,
} }
/* And write the signature to the cell */ /* And write the signature to the cell */
uint8_t *sig_ptr = hs_cell_establish_intro_getarray_sig(cell); uint8_t *sig_ptr = trn_cell_establish_intro_getarray_sig(cell);
memcpy(sig_ptr, sig.sig, sig_len); memcpy(sig_ptr, sig.sig, sig_len);
} }
@ -166,7 +166,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material,
return cell; return cell;
err: err:
hs_cell_establish_intro_free(cell); trn_cell_establish_intro_free(cell);
return NULL; return NULL;
} }

View File

@ -16,12 +16,12 @@
* hs_service.o ends up with no symbols in libor.a which makes clang throw a * hs_service.o ends up with no symbols in libor.a which makes clang throw a
* warning at compile time. See #21825. */ * warning at compile time. See #21825. */
hs_cell_establish_intro_t * trn_cell_establish_intro_t *
generate_establish_intro_cell(const uint8_t *circuit_key_material, generate_establish_intro_cell(const uint8_t *circuit_key_material,
size_t circuit_key_material_len); size_t circuit_key_material_len);
ssize_t ssize_t
get_establish_intro_payload(uint8_t *buf, size_t buf_len, get_establish_intro_payload(uint8_t *buf, size_t buf_len,
const hs_cell_establish_intro_t *cell); const trn_cell_establish_intro_t *cell);
#endif /* TOR_HS_SERVICE_H */ #endif /* TOR_HS_SERVICE_H */

View File

@ -69,10 +69,10 @@ helper_create_intro_circuit(void)
return circ; return circ;
} }
static hs_cell_introduce1_t * static trn_cell_introduce1_t *
helper_create_introduce1_cell(void) helper_create_introduce1_cell(void)
{ {
hs_cell_introduce1_t *cell = NULL; trn_cell_introduce1_t *cell = NULL;
ed25519_keypair_t auth_key_kp; ed25519_keypair_t auth_key_kp;
/* Generate the auth_key of the cell. */ /* Generate the auth_key of the cell. */
@ -80,39 +80,39 @@ helper_create_introduce1_cell(void)
goto err; goto err;
} }
cell = hs_cell_introduce1_new(); cell = trn_cell_introduce1_new();
tt_assert(cell); tt_assert(cell);
/* Set the auth key. */ /* Set the auth key. */
{ {
size_t auth_key_len = sizeof(auth_key_kp.pubkey); size_t auth_key_len = sizeof(auth_key_kp.pubkey);
hs_cell_introduce1_set_auth_key_type(cell, trn_cell_introduce1_set_auth_key_type(cell,
HS_INTRO_AUTH_KEY_TYPE_ED25519); HS_INTRO_AUTH_KEY_TYPE_ED25519);
hs_cell_introduce1_set_auth_key_len(cell, auth_key_len); trn_cell_introduce1_set_auth_key_len(cell, auth_key_len);
hs_cell_introduce1_setlen_auth_key(cell, auth_key_len); trn_cell_introduce1_setlen_auth_key(cell, auth_key_len);
uint8_t *auth_key_ptr = hs_cell_introduce1_getarray_auth_key(cell); uint8_t *auth_key_ptr = trn_cell_introduce1_getarray_auth_key(cell);
memcpy(auth_key_ptr, auth_key_kp.pubkey.pubkey, auth_key_len); memcpy(auth_key_ptr, auth_key_kp.pubkey.pubkey, auth_key_len);
} }
/* Set the cell extentions to none. */ /* Set the cell extentions to none. */
{ {
cell_extension_t *ext = cell_extension_new(); trn_cell_extension_t *ext = trn_cell_extension_new();
cell_extension_set_num(ext, 0); trn_cell_extension_set_num(ext, 0);
hs_cell_introduce1_set_extensions(cell, ext); trn_cell_introduce1_set_extensions(cell, ext);
} }
/* Set the encrypted section to some data. */ /* Set the encrypted section to some data. */
{ {
size_t enc_len = 128; size_t enc_len = 128;
hs_cell_introduce1_setlen_encrypted(cell, enc_len); trn_cell_introduce1_setlen_encrypted(cell, enc_len);
uint8_t *enc_ptr = hs_cell_introduce1_getarray_encrypted(cell); uint8_t *enc_ptr = trn_cell_introduce1_getarray_encrypted(cell);
memset(enc_ptr, 'a', enc_len); memset(enc_ptr, 'a', enc_len);
} }
return cell; return cell;
err: err:
done: done:
hs_cell_introduce1_free(cell); trn_cell_introduce1_free(cell);
return NULL; return NULL;
} }
@ -122,7 +122,7 @@ static void
test_establish_intro_wrong_purpose(void *arg) test_establish_intro_wrong_purpose(void *arg)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
or_circuit_t *intro_circ = or_circuit_new(0,NULL);; or_circuit_t *intro_circ = or_circuit_new(0,NULL);;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
@ -154,7 +154,7 @@ test_establish_intro_wrong_purpose(void *arg)
tt_int_op(retval, ==, -1); tt_int_op(retval, ==, -1);
done: done:
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
} }
@ -198,7 +198,7 @@ static void
test_establish_intro_wrong_keytype2(void *arg) test_establish_intro_wrong_keytype2(void *arg)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
or_circuit_t *intro_circ = or_circuit_new(0,NULL);; or_circuit_t *intro_circ = or_circuit_new(0,NULL);;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
@ -230,7 +230,7 @@ test_establish_intro_wrong_keytype2(void *arg)
tt_int_op(retval, ==, -1); tt_int_op(retval, ==, -1);
done: done:
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
} }
@ -239,7 +239,7 @@ static void
test_establish_intro_wrong_mac(void *arg) test_establish_intro_wrong_mac(void *arg)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
or_circuit_t *intro_circ = or_circuit_new(0,NULL);; or_circuit_t *intro_circ = or_circuit_new(0,NULL);;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
@ -258,7 +258,7 @@ test_establish_intro_wrong_mac(void *arg)
tt_assert(establish_intro_cell); tt_assert(establish_intro_cell);
/* Mangle one byte of the MAC. */ /* Mangle one byte of the MAC. */
uint8_t *handshake_ptr = uint8_t *handshake_ptr =
hs_cell_establish_intro_getarray_handshake_mac(establish_intro_cell); trn_cell_establish_intro_getarray_handshake_mac(establish_intro_cell);
handshake_ptr[TRUNNEL_SHA3_256_LEN - 1]++; handshake_ptr[TRUNNEL_SHA3_256_LEN - 1]++;
/* We need to resign the payload with that change. */ /* We need to resign the payload with that change. */
{ {
@ -269,7 +269,7 @@ test_establish_intro_wrong_mac(void *arg)
retval = ed25519_keypair_generate(&key_struct, 0); retval = ed25519_keypair_generate(&key_struct, 0);
tt_int_op(retval, OP_EQ, 0); tt_int_op(retval, OP_EQ, 0);
uint8_t *auth_key_ptr = uint8_t *auth_key_ptr =
hs_cell_establish_intro_getarray_auth_key(establish_intro_cell); trn_cell_establish_intro_getarray_auth_key(establish_intro_cell);
memcpy(auth_key_ptr, key_struct.pubkey.pubkey, ED25519_PUBKEY_LEN); memcpy(auth_key_ptr, key_struct.pubkey.pubkey, ED25519_PUBKEY_LEN);
/* Encode payload so we can sign it. */ /* Encode payload so we can sign it. */
cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body), cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body),
@ -284,7 +284,7 @@ test_establish_intro_wrong_mac(void *arg)
tt_int_op(retval, OP_EQ, 0); tt_int_op(retval, OP_EQ, 0);
/* And write the signature to the cell */ /* And write the signature to the cell */
uint8_t *sig_ptr = uint8_t *sig_ptr =
hs_cell_establish_intro_getarray_sig(establish_intro_cell); trn_cell_establish_intro_getarray_sig(establish_intro_cell);
memcpy(sig_ptr, sig.sig, establish_intro_cell->sig_len); memcpy(sig_ptr, sig.sig, establish_intro_cell->sig_len);
/* Re-encode with the new signature. */ /* Re-encode with the new signature. */
cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body), cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body),
@ -299,7 +299,7 @@ test_establish_intro_wrong_mac(void *arg)
tt_int_op(retval, ==, -1); tt_int_op(retval, ==, -1);
done: done:
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
} }
@ -309,7 +309,7 @@ static void
test_establish_intro_wrong_auth_key_len(void *arg) test_establish_intro_wrong_auth_key_len(void *arg)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
or_circuit_t *intro_circ = or_circuit_new(0,NULL);; or_circuit_t *intro_circ = or_circuit_new(0,NULL);;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
@ -328,9 +328,9 @@ test_establish_intro_wrong_auth_key_len(void *arg)
sizeof(circuit_key_material)); sizeof(circuit_key_material));
tt_assert(establish_intro_cell); tt_assert(establish_intro_cell);
/* Mangle the auth key length. */ /* Mangle the auth key length. */
hs_cell_establish_intro_set_auth_key_len(establish_intro_cell, trn_cell_establish_intro_set_auth_key_len(establish_intro_cell,
bad_auth_key_len); bad_auth_key_len);
hs_cell_establish_intro_setlen_auth_key(establish_intro_cell, trn_cell_establish_intro_setlen_auth_key(establish_intro_cell,
bad_auth_key_len); bad_auth_key_len);
cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body), cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body),
establish_intro_cell); establish_intro_cell);
@ -344,7 +344,7 @@ test_establish_intro_wrong_auth_key_len(void *arg)
tt_int_op(retval, ==, -1); tt_int_op(retval, ==, -1);
done: done:
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
} }
@ -354,7 +354,7 @@ static void
test_establish_intro_wrong_sig_len(void *arg) test_establish_intro_wrong_sig_len(void *arg)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
or_circuit_t *intro_circ = or_circuit_new(0,NULL);; or_circuit_t *intro_circ = or_circuit_new(0,NULL);;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
@ -373,8 +373,8 @@ test_establish_intro_wrong_sig_len(void *arg)
sizeof(circuit_key_material)); sizeof(circuit_key_material));
tt_assert(establish_intro_cell); tt_assert(establish_intro_cell);
/* Mangle the signature length. */ /* Mangle the signature length. */
hs_cell_establish_intro_set_sig_len(establish_intro_cell, bad_sig_len); trn_cell_establish_intro_set_sig_len(establish_intro_cell, bad_sig_len);
hs_cell_establish_intro_setlen_sig(establish_intro_cell, bad_sig_len); trn_cell_establish_intro_setlen_sig(establish_intro_cell, bad_sig_len);
cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body), cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body),
establish_intro_cell); establish_intro_cell);
tt_int_op(cell_len, >, 0); tt_int_op(cell_len, >, 0);
@ -387,7 +387,7 @@ test_establish_intro_wrong_sig_len(void *arg)
tt_int_op(retval, ==, -1); tt_int_op(retval, ==, -1);
done: done:
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
} }
@ -397,7 +397,7 @@ static void
test_establish_intro_wrong_sig(void *arg) test_establish_intro_wrong_sig(void *arg)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
or_circuit_t *intro_circ = or_circuit_new(0,NULL);; or_circuit_t *intro_circ = or_circuit_new(0,NULL);;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
@ -429,17 +429,17 @@ test_establish_intro_wrong_sig(void *arg)
tt_int_op(retval, ==, -1); tt_int_op(retval, ==, -1);
done: done:
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
} }
/* Helper function: Send a well-formed v3 ESTABLISH_INTRO cell to /* Helper function: Send a well-formed v3 ESTABLISH_INTRO cell to
* <b>intro_circ</b>. Return the cell. */ * <b>intro_circ</b>. Return the cell. */
static hs_cell_establish_intro_t * static trn_cell_establish_intro_t *
helper_establish_intro_v3(or_circuit_t *intro_circ) helper_establish_intro_v3(or_circuit_t *intro_circ)
{ {
int retval; int retval;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
uint8_t cell_body[RELAY_PAYLOAD_SIZE]; uint8_t cell_body[RELAY_PAYLOAD_SIZE];
ssize_t cell_len = 0; ssize_t cell_len = 0;
uint8_t circuit_key_material[DIGEST_LEN] = {0}; uint8_t circuit_key_material[DIGEST_LEN] = {0};
@ -512,7 +512,7 @@ test_intro_point_registration(void *arg)
hs_circuitmap_ht *the_hs_circuitmap = NULL; hs_circuitmap_ht *the_hs_circuitmap = NULL;
or_circuit_t *intro_circ = NULL; or_circuit_t *intro_circ = NULL;
hs_cell_establish_intro_t *establish_intro_cell = NULL; trn_cell_establish_intro_t *establish_intro_cell = NULL;
ed25519_public_key_t auth_key; ed25519_public_key_t auth_key;
crypto_pk_t *legacy_auth_key = NULL; crypto_pk_t *legacy_auth_key = NULL;
@ -580,7 +580,7 @@ test_intro_point_registration(void *arg)
crypto_pk_free(legacy_auth_key); crypto_pk_free(legacy_auth_key);
circuit_free(TO_CIRCUIT(intro_circ)); circuit_free(TO_CIRCUIT(intro_circ));
circuit_free(TO_CIRCUIT(legacy_intro_circ)); circuit_free(TO_CIRCUIT(legacy_intro_circ));
hs_cell_establish_intro_free(establish_intro_cell); trn_cell_establish_intro_free(establish_intro_cell);
{ /* Test circuitmap free_all function. */ { /* Test circuitmap free_all function. */
the_hs_circuitmap = get_hs_circuitmap(); the_hs_circuitmap = get_hs_circuitmap();
@ -674,7 +674,7 @@ static void
test_introduce1_validation(void *arg) test_introduce1_validation(void *arg)
{ {
int ret; int ret;
hs_cell_introduce1_t *cell = NULL; trn_cell_introduce1_t *cell = NULL;
(void) arg; (void) arg;
@ -714,25 +714,25 @@ test_introduce1_validation(void *arg)
ret = validate_introduce1_parsed_cell(cell); ret = validate_introduce1_parsed_cell(cell);
tt_int_op(ret, OP_EQ, 0); tt_int_op(ret, OP_EQ, 0);
/* Set an invalid size of the auth key buffer. */ /* Set an invalid size of the auth key buffer. */
hs_cell_introduce1_setlen_auth_key(cell, 3); trn_cell_introduce1_setlen_auth_key(cell, 3);
ret = validate_introduce1_parsed_cell(cell); ret = validate_introduce1_parsed_cell(cell);
tt_int_op(ret, OP_EQ, -1); tt_int_op(ret, OP_EQ, -1);
/* Reset auth key buffer and make sure it works. */ /* Reset auth key buffer and make sure it works. */
hs_cell_introduce1_setlen_auth_key(cell, sizeof(ed25519_public_key_t)); trn_cell_introduce1_setlen_auth_key(cell, sizeof(ed25519_public_key_t));
ret = validate_introduce1_parsed_cell(cell); ret = validate_introduce1_parsed_cell(cell);
tt_int_op(ret, OP_EQ, 0); tt_int_op(ret, OP_EQ, 0);
/* Empty encrypted section. */ /* Empty encrypted section. */
hs_cell_introduce1_setlen_encrypted(cell, 0); trn_cell_introduce1_setlen_encrypted(cell, 0);
ret = validate_introduce1_parsed_cell(cell); ret = validate_introduce1_parsed_cell(cell);
tt_int_op(ret, OP_EQ, -1); tt_int_op(ret, OP_EQ, -1);
/* Reset it to some non zero bytes and validate. */ /* Reset it to some non zero bytes and validate. */
hs_cell_introduce1_setlen_encrypted(cell, 1); trn_cell_introduce1_setlen_encrypted(cell, 1);
ret = validate_introduce1_parsed_cell(cell); ret = validate_introduce1_parsed_cell(cell);
tt_int_op(ret, OP_EQ, 0); tt_int_op(ret, OP_EQ, 0);
done: done:
hs_cell_introduce1_free(cell); trn_cell_introduce1_free(cell);
} }
static void static void
@ -740,7 +740,7 @@ test_received_introduce1_handling(void *arg)
{ {
int ret; int ret;
uint8_t *request = NULL, buf[128]; uint8_t *request = NULL, buf[128];
hs_cell_introduce1_t *cell = NULL; trn_cell_introduce1_t *cell = NULL;
or_circuit_t *circ = NULL; or_circuit_t *circ = NULL;
(void) arg; (void) arg;
@ -774,11 +774,11 @@ test_received_introduce1_handling(void *arg)
/* Valid case. */ /* Valid case. */
{ {
cell = helper_create_introduce1_cell(); cell = helper_create_introduce1_cell();
ssize_t request_len = hs_cell_introduce1_encoded_len(cell); ssize_t request_len = trn_cell_introduce1_encoded_len(cell);
tt_size_op(request_len, OP_GT, 0); tt_size_op(request_len, OP_GT, 0);
request = tor_malloc_zero(request_len); request = tor_malloc_zero(request_len);
ssize_t encoded_len = ssize_t encoded_len =
hs_cell_introduce1_encode(request, request_len, cell); trn_cell_introduce1_encode(request, request_len, cell);
tt_size_op(encoded_len, OP_GT, 0); tt_size_op(encoded_len, OP_GT, 0);
circ = helper_create_intro_circuit(); circ = helper_create_intro_circuit();
@ -788,7 +788,7 @@ test_received_introduce1_handling(void *arg)
/* Register the circuit in the map for the auth key of the cell. */ /* Register the circuit in the map for the auth key of the cell. */
ed25519_public_key_t auth_key; ed25519_public_key_t auth_key;
const uint8_t *cell_auth_key = const uint8_t *cell_auth_key =
hs_cell_introduce1_getconstarray_auth_key(cell); trn_cell_introduce1_getconstarray_auth_key(cell);
memcpy(auth_key.pubkey, cell_auth_key, ED25519_PUBKEY_LEN); memcpy(auth_key.pubkey, cell_auth_key, ED25519_PUBKEY_LEN);
hs_circuitmap_register_intro_circ_v3(service_circ, &auth_key); hs_circuitmap_register_intro_circ_v3(service_circ, &auth_key);
ret = hs_intro_received_introduce1(circ, request, request_len); ret = hs_intro_received_introduce1(circ, request, request_len);
@ -800,16 +800,16 @@ test_received_introduce1_handling(void *arg)
/* Valid legacy cell. */ /* Valid legacy cell. */
{ {
tor_free(request); tor_free(request);
hs_cell_introduce1_free(cell); trn_cell_introduce1_free(cell);
cell = helper_create_introduce1_cell(); cell = helper_create_introduce1_cell();
uint8_t *legacy_key_id = hs_cell_introduce1_getarray_legacy_key_id(cell); uint8_t *legacy_key_id = trn_cell_introduce1_getarray_legacy_key_id(cell);
memset(legacy_key_id, 'a', DIGEST_LEN); memset(legacy_key_id, 'a', DIGEST_LEN);
/* Add an arbitrary amount of data for the payload of a v2 cell. */ /* Add an arbitrary amount of data for the payload of a v2 cell. */
size_t request_len = hs_cell_introduce1_encoded_len(cell) + 256; size_t request_len = trn_cell_introduce1_encoded_len(cell) + 256;
tt_size_op(request_len, OP_GT, 0); tt_size_op(request_len, OP_GT, 0);
request = tor_malloc_zero(request_len + 256); request = tor_malloc_zero(request_len + 256);
ssize_t encoded_len = ssize_t encoded_len =
hs_cell_introduce1_encode(request, request_len, cell); trn_cell_introduce1_encode(request, request_len, cell);
tt_size_op(encoded_len, OP_GT, 0); tt_size_op(encoded_len, OP_GT, 0);
circ = helper_create_intro_circuit(); circ = helper_create_intro_circuit();
@ -827,7 +827,7 @@ test_received_introduce1_handling(void *arg)
} }
done: done:
hs_cell_introduce1_free(cell); trn_cell_introduce1_free(cell);
tor_free(request); tor_free(request);
hs_circuitmap_free_all(); hs_circuitmap_free_all();
UNMOCK(relay_send_command_from_edge_); UNMOCK(relay_send_command_from_edge_);

View File

@ -28,8 +28,8 @@ test_gen_establish_intro_cell(void *arg)
ssize_t retval; ssize_t retval;
uint8_t circuit_key_material[DIGEST_LEN] = {0}; uint8_t circuit_key_material[DIGEST_LEN] = {0};
uint8_t buf[RELAY_PAYLOAD_SIZE]; uint8_t buf[RELAY_PAYLOAD_SIZE];
hs_cell_establish_intro_t *cell_out = NULL; trn_cell_establish_intro_t *cell_out = NULL;
hs_cell_establish_intro_t *cell_in = NULL; trn_cell_establish_intro_t *cell_in = NULL;
crypto_rand((char *) circuit_key_material, sizeof(circuit_key_material)); crypto_rand((char *) circuit_key_material, sizeof(circuit_key_material));
@ -46,7 +46,7 @@ test_gen_establish_intro_cell(void *arg)
/* Parse it as the receiver */ /* Parse it as the receiver */
{ {
ssize_t parse_result = hs_cell_establish_intro_parse(&cell_in, ssize_t parse_result = trn_cell_establish_intro_parse(&cell_in,
buf, sizeof(buf)); buf, sizeof(buf));
tt_int_op(parse_result, >=, 0); tt_int_op(parse_result, >=, 0);
@ -57,8 +57,8 @@ test_gen_establish_intro_cell(void *arg)
} }
done: done:
hs_cell_establish_intro_free(cell_out); trn_cell_establish_intro_free(cell_out);
hs_cell_establish_intro_free(cell_in); trn_cell_establish_intro_free(cell_in);
} }
/* Mocked ed25519_sign_prefixed() function that always fails :) */ /* Mocked ed25519_sign_prefixed() function that always fails :) */
@ -80,7 +80,7 @@ static void
test_gen_establish_intro_cell_bad(void *arg) test_gen_establish_intro_cell_bad(void *arg)
{ {
(void) arg; (void) arg;
hs_cell_establish_intro_t *cell = NULL; trn_cell_establish_intro_t *cell = NULL;
uint8_t circuit_key_material[DIGEST_LEN] = {0}; uint8_t circuit_key_material[DIGEST_LEN] = {0};
MOCK(ed25519_sign_prefixed, mock_ed25519_sign_prefixed); MOCK(ed25519_sign_prefixed, mock_ed25519_sign_prefixed);
@ -98,7 +98,7 @@ test_gen_establish_intro_cell_bad(void *arg)
tt_assert(!cell); tt_assert(!cell);
done: done:
hs_cell_establish_intro_free(cell); trn_cell_establish_intro_free(cell);
UNMOCK(ed25519_sign_prefixed); UNMOCK(ed25519_sign_prefixed);
} }

View File

@ -28,10 +28,10 @@ int cellcommon_deadcode_dummy__ = 0;
} \ } \
} while (0) } while (0)
cell_extension_fields_t * trn_cell_extension_fields_t *
cell_extension_fields_new(void) trn_cell_extension_fields_new(void)
{ {
cell_extension_fields_t *val = trunnel_calloc(1, sizeof(cell_extension_fields_t)); trn_cell_extension_fields_t *val = trunnel_calloc(1, sizeof(trn_cell_extension_fields_t));
if (NULL == val) if (NULL == val)
return NULL; return NULL;
return val; return val;
@ -40,7 +40,7 @@ cell_extension_fields_new(void)
/** Release all storage held inside 'obj', but do not free 'obj'. /** Release all storage held inside 'obj', but do not free 'obj'.
*/ */
static void static void
cell_extension_fields_clear(cell_extension_fields_t *obj) trn_cell_extension_fields_clear(trn_cell_extension_fields_t *obj)
{ {
(void) obj; (void) obj;
TRUNNEL_DYNARRAY_WIPE(&obj->field); TRUNNEL_DYNARRAY_WIPE(&obj->field);
@ -48,62 +48,62 @@ cell_extension_fields_clear(cell_extension_fields_t *obj)
} }
void void
cell_extension_fields_free(cell_extension_fields_t *obj) trn_cell_extension_fields_free(trn_cell_extension_fields_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return; return;
cell_extension_fields_clear(obj); trn_cell_extension_fields_clear(obj);
trunnel_memwipe(obj, sizeof(cell_extension_fields_t)); trunnel_memwipe(obj, sizeof(trn_cell_extension_fields_t));
trunnel_free_(obj); trunnel_free_(obj);
} }
uint8_t uint8_t
cell_extension_fields_get_field_type(const cell_extension_fields_t *inp) trn_cell_extension_fields_get_field_type(const trn_cell_extension_fields_t *inp)
{ {
return inp->field_type; return inp->field_type;
} }
int int
cell_extension_fields_set_field_type(cell_extension_fields_t *inp, uint8_t val) trn_cell_extension_fields_set_field_type(trn_cell_extension_fields_t *inp, uint8_t val)
{ {
inp->field_type = val; inp->field_type = val;
return 0; return 0;
} }
uint8_t uint8_t
cell_extension_fields_get_field_len(const cell_extension_fields_t *inp) trn_cell_extension_fields_get_field_len(const trn_cell_extension_fields_t *inp)
{ {
return inp->field_len; return inp->field_len;
} }
int int
cell_extension_fields_set_field_len(cell_extension_fields_t *inp, uint8_t val) trn_cell_extension_fields_set_field_len(trn_cell_extension_fields_t *inp, uint8_t val)
{ {
inp->field_len = val; inp->field_len = val;
return 0; return 0;
} }
size_t size_t
cell_extension_fields_getlen_field(const cell_extension_fields_t *inp) trn_cell_extension_fields_getlen_field(const trn_cell_extension_fields_t *inp)
{ {
return TRUNNEL_DYNARRAY_LEN(&inp->field); return TRUNNEL_DYNARRAY_LEN(&inp->field);
} }
uint8_t uint8_t
cell_extension_fields_get_field(cell_extension_fields_t *inp, size_t idx) trn_cell_extension_fields_get_field(trn_cell_extension_fields_t *inp, size_t idx)
{ {
return TRUNNEL_DYNARRAY_GET(&inp->field, idx); return TRUNNEL_DYNARRAY_GET(&inp->field, idx);
} }
uint8_t uint8_t
cell_extension_fields_getconst_field(const cell_extension_fields_t *inp, size_t idx) trn_cell_extension_fields_getconst_field(const trn_cell_extension_fields_t *inp, size_t idx)
{ {
return cell_extension_fields_get_field((cell_extension_fields_t*)inp, idx); return trn_cell_extension_fields_get_field((trn_cell_extension_fields_t*)inp, idx);
} }
int int
cell_extension_fields_set_field(cell_extension_fields_t *inp, size_t idx, uint8_t elt) trn_cell_extension_fields_set_field(trn_cell_extension_fields_t *inp, size_t idx, uint8_t elt)
{ {
TRUNNEL_DYNARRAY_SET(&inp->field, idx, elt); TRUNNEL_DYNARRAY_SET(&inp->field, idx, elt);
return 0; return 0;
} }
int int
cell_extension_fields_add_field(cell_extension_fields_t *inp, uint8_t elt) trn_cell_extension_fields_add_field(trn_cell_extension_fields_t *inp, uint8_t elt)
{ {
#if SIZE_MAX >= UINT8_MAX #if SIZE_MAX >= UINT8_MAX
if (inp->field.n_ == UINT8_MAX) if (inp->field.n_ == UINT8_MAX)
@ -117,17 +117,17 @@ cell_extension_fields_add_field(cell_extension_fields_t *inp, uint8_t elt)
} }
uint8_t * uint8_t *
cell_extension_fields_getarray_field(cell_extension_fields_t *inp) trn_cell_extension_fields_getarray_field(trn_cell_extension_fields_t *inp)
{ {
return inp->field.elts_; return inp->field.elts_;
} }
const uint8_t * const uint8_t *
cell_extension_fields_getconstarray_field(const cell_extension_fields_t *inp) trn_cell_extension_fields_getconstarray_field(const trn_cell_extension_fields_t *inp)
{ {
return (const uint8_t *)cell_extension_fields_getarray_field((cell_extension_fields_t*)inp); return (const uint8_t *)trn_cell_extension_fields_getarray_field((trn_cell_extension_fields_t*)inp);
} }
int int
cell_extension_fields_setlen_field(cell_extension_fields_t *inp, size_t newlen) trn_cell_extension_fields_setlen_field(trn_cell_extension_fields_t *inp, size_t newlen)
{ {
uint8_t *newptr; uint8_t *newptr;
#if UINT8_MAX < SIZE_MAX #if UINT8_MAX < SIZE_MAX
@ -147,7 +147,7 @@ cell_extension_fields_setlen_field(cell_extension_fields_t *inp, size_t newlen)
return -1; return -1;
} }
const char * const char *
cell_extension_fields_check(const cell_extension_fields_t *obj) trn_cell_extension_fields_check(const trn_cell_extension_fields_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return "Object was NULL"; return "Object was NULL";
@ -159,11 +159,11 @@ cell_extension_fields_check(const cell_extension_fields_t *obj)
} }
ssize_t ssize_t
cell_extension_fields_encoded_len(const cell_extension_fields_t *obj) trn_cell_extension_fields_encoded_len(const trn_cell_extension_fields_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
if (NULL != cell_extension_fields_check(obj)) if (NULL != trn_cell_extension_fields_check(obj))
return -1; return -1;
@ -178,24 +178,24 @@ cell_extension_fields_encoded_len(const cell_extension_fields_t *obj)
return result; return result;
} }
int int
cell_extension_fields_clear_errors(cell_extension_fields_t *obj) trn_cell_extension_fields_clear_errors(trn_cell_extension_fields_t *obj)
{ {
int r = obj->trunnel_error_code_; int r = obj->trunnel_error_code_;
obj->trunnel_error_code_ = 0; obj->trunnel_error_code_ = 0;
return r; return r;
} }
ssize_t ssize_t
cell_extension_fields_encode(uint8_t *output, const size_t avail, const cell_extension_fields_t *obj) trn_cell_extension_fields_encode(uint8_t *output, const size_t avail, const trn_cell_extension_fields_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
size_t written = 0; size_t written = 0;
uint8_t *ptr = output; uint8_t *ptr = output;
const char *msg; const char *msg;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
const ssize_t encoded_len = cell_extension_fields_encoded_len(obj); const ssize_t encoded_len = trn_cell_extension_fields_encoded_len(obj);
#endif #endif
if (NULL != (msg = cell_extension_fields_check(obj))) if (NULL != (msg = trn_cell_extension_fields_check(obj)))
goto check_failed; goto check_failed;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
@ -252,11 +252,11 @@ cell_extension_fields_encode(uint8_t *output, const size_t avail, const cell_ext
return result; return result;
} }
/** As cell_extension_fields_parse(), but do not allocate the output /** As trn_cell_extension_fields_parse(), but do not allocate the
* object. * output object.
*/ */
static ssize_t static ssize_t
cell_extension_fields_parse_into(cell_extension_fields_t *obj, const uint8_t *input, const size_t len_in) trn_cell_extension_fields_parse_into(trn_cell_extension_fields_t *obj, const uint8_t *input, const size_t len_in)
{ {
const uint8_t *ptr = input; const uint8_t *ptr = input;
size_t remaining = len_in; size_t remaining = len_in;
@ -290,23 +290,23 @@ cell_extension_fields_parse_into(cell_extension_fields_t *obj, const uint8_t *in
} }
ssize_t ssize_t
cell_extension_fields_parse(cell_extension_fields_t **output, const uint8_t *input, const size_t len_in) trn_cell_extension_fields_parse(trn_cell_extension_fields_t **output, const uint8_t *input, const size_t len_in)
{ {
ssize_t result; ssize_t result;
*output = cell_extension_fields_new(); *output = trn_cell_extension_fields_new();
if (NULL == *output) if (NULL == *output)
return -1; return -1;
result = cell_extension_fields_parse_into(*output, input, len_in); result = trn_cell_extension_fields_parse_into(*output, input, len_in);
if (result < 0) { if (result < 0) {
cell_extension_fields_free(*output); trn_cell_extension_fields_free(*output);
*output = NULL; *output = NULL;
} }
return result; return result;
} }
cell_extension_t * trn_cell_extension_t *
cell_extension_new(void) trn_cell_extension_new(void)
{ {
cell_extension_t *val = trunnel_calloc(1, sizeof(cell_extension_t)); trn_cell_extension_t *val = trunnel_calloc(1, sizeof(trn_cell_extension_t));
if (NULL == val) if (NULL == val)
return NULL; return NULL;
return val; return val;
@ -315,14 +315,14 @@ cell_extension_new(void)
/** Release all storage held inside 'obj', but do not free 'obj'. /** Release all storage held inside 'obj', but do not free 'obj'.
*/ */
static void static void
cell_extension_clear(cell_extension_t *obj) trn_cell_extension_clear(trn_cell_extension_t *obj)
{ {
(void) obj; (void) obj;
{ {
unsigned idx; unsigned idx;
for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) { for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) {
cell_extension_fields_free(TRUNNEL_DYNARRAY_GET(&obj->fields, idx)); trn_cell_extension_fields_free(TRUNNEL_DYNARRAY_GET(&obj->fields, idx));
} }
} }
TRUNNEL_DYNARRAY_WIPE(&obj->fields); TRUNNEL_DYNARRAY_WIPE(&obj->fields);
@ -330,92 +330,92 @@ cell_extension_clear(cell_extension_t *obj)
} }
void void
cell_extension_free(cell_extension_t *obj) trn_cell_extension_free(trn_cell_extension_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return; return;
cell_extension_clear(obj); trn_cell_extension_clear(obj);
trunnel_memwipe(obj, sizeof(cell_extension_t)); trunnel_memwipe(obj, sizeof(trn_cell_extension_t));
trunnel_free_(obj); trunnel_free_(obj);
} }
uint8_t uint8_t
cell_extension_get_num(const cell_extension_t *inp) trn_cell_extension_get_num(const trn_cell_extension_t *inp)
{ {
return inp->num; return inp->num;
} }
int int
cell_extension_set_num(cell_extension_t *inp, uint8_t val) trn_cell_extension_set_num(trn_cell_extension_t *inp, uint8_t val)
{ {
inp->num = val; inp->num = val;
return 0; return 0;
} }
size_t size_t
cell_extension_getlen_fields(const cell_extension_t *inp) trn_cell_extension_getlen_fields(const trn_cell_extension_t *inp)
{ {
return TRUNNEL_DYNARRAY_LEN(&inp->fields); return TRUNNEL_DYNARRAY_LEN(&inp->fields);
} }
struct cell_extension_fields_st * struct trn_cell_extension_fields_st *
cell_extension_get_fields(cell_extension_t *inp, size_t idx) trn_cell_extension_get_fields(trn_cell_extension_t *inp, size_t idx)
{ {
return TRUNNEL_DYNARRAY_GET(&inp->fields, idx); return TRUNNEL_DYNARRAY_GET(&inp->fields, idx);
} }
const struct cell_extension_fields_st * const struct trn_cell_extension_fields_st *
cell_extension_getconst_fields(const cell_extension_t *inp, size_t idx) trn_cell_extension_getconst_fields(const trn_cell_extension_t *inp, size_t idx)
{ {
return cell_extension_get_fields((cell_extension_t*)inp, idx); return trn_cell_extension_get_fields((trn_cell_extension_t*)inp, idx);
} }
int int
cell_extension_set_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt) trn_cell_extension_set_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt)
{ {
cell_extension_fields_t *oldval = TRUNNEL_DYNARRAY_GET(&inp->fields, idx); trn_cell_extension_fields_t *oldval = TRUNNEL_DYNARRAY_GET(&inp->fields, idx);
if (oldval && oldval != elt) if (oldval && oldval != elt)
cell_extension_fields_free(oldval); trn_cell_extension_fields_free(oldval);
return cell_extension_set0_fields(inp, idx, elt); return trn_cell_extension_set0_fields(inp, idx, elt);
} }
int int
cell_extension_set0_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt) trn_cell_extension_set0_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt)
{ {
TRUNNEL_DYNARRAY_SET(&inp->fields, idx, elt); TRUNNEL_DYNARRAY_SET(&inp->fields, idx, elt);
return 0; return 0;
} }
int int
cell_extension_add_fields(cell_extension_t *inp, struct cell_extension_fields_st * elt) trn_cell_extension_add_fields(trn_cell_extension_t *inp, struct trn_cell_extension_fields_st * elt)
{ {
#if SIZE_MAX >= UINT8_MAX #if SIZE_MAX >= UINT8_MAX
if (inp->fields.n_ == UINT8_MAX) if (inp->fields.n_ == UINT8_MAX)
goto trunnel_alloc_failed; goto trunnel_alloc_failed;
#endif #endif
TRUNNEL_DYNARRAY_ADD(struct cell_extension_fields_st *, &inp->fields, elt, {}); TRUNNEL_DYNARRAY_ADD(struct trn_cell_extension_fields_st *, &inp->fields, elt, {});
return 0; return 0;
trunnel_alloc_failed: trunnel_alloc_failed:
TRUNNEL_SET_ERROR_CODE(inp); TRUNNEL_SET_ERROR_CODE(inp);
return -1; return -1;
} }
struct cell_extension_fields_st * * struct trn_cell_extension_fields_st * *
cell_extension_getarray_fields(cell_extension_t *inp) trn_cell_extension_getarray_fields(trn_cell_extension_t *inp)
{ {
return inp->fields.elts_; return inp->fields.elts_;
} }
const struct cell_extension_fields_st * const * const struct trn_cell_extension_fields_st * const *
cell_extension_getconstarray_fields(const cell_extension_t *inp) trn_cell_extension_getconstarray_fields(const trn_cell_extension_t *inp)
{ {
return (const struct cell_extension_fields_st * const *)cell_extension_getarray_fields((cell_extension_t*)inp); return (const struct trn_cell_extension_fields_st * const *)trn_cell_extension_getarray_fields((trn_cell_extension_t*)inp);
} }
int int
cell_extension_setlen_fields(cell_extension_t *inp, size_t newlen) trn_cell_extension_setlen_fields(trn_cell_extension_t *inp, size_t newlen)
{ {
struct cell_extension_fields_st * *newptr; struct trn_cell_extension_fields_st * *newptr;
#if UINT8_MAX < SIZE_MAX #if UINT8_MAX < SIZE_MAX
if (newlen > UINT8_MAX) if (newlen > UINT8_MAX)
goto trunnel_alloc_failed; goto trunnel_alloc_failed;
#endif #endif
newptr = trunnel_dynarray_setlen(&inp->fields.allocated_, newptr = trunnel_dynarray_setlen(&inp->fields.allocated_,
&inp->fields.n_, inp->fields.elts_, newlen, &inp->fields.n_, inp->fields.elts_, newlen,
sizeof(inp->fields.elts_[0]), (trunnel_free_fn_t) cell_extension_fields_free, sizeof(inp->fields.elts_[0]), (trunnel_free_fn_t) trn_cell_extension_fields_free,
&inp->trunnel_error_code_); &inp->trunnel_error_code_);
if (newlen != 0 && newptr == NULL) if (newlen != 0 && newptr == NULL)
goto trunnel_alloc_failed; goto trunnel_alloc_failed;
@ -426,7 +426,7 @@ cell_extension_setlen_fields(cell_extension_t *inp, size_t newlen)
return -1; return -1;
} }
const char * const char *
cell_extension_check(const cell_extension_t *obj) trn_cell_extension_check(const trn_cell_extension_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return "Object was NULL"; return "Object was NULL";
@ -437,7 +437,7 @@ cell_extension_check(const cell_extension_t *obj)
unsigned idx; unsigned idx;
for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) { for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) {
if (NULL != (msg = cell_extension_fields_check(TRUNNEL_DYNARRAY_GET(&obj->fields, idx)))) if (NULL != (msg = trn_cell_extension_fields_check(TRUNNEL_DYNARRAY_GET(&obj->fields, idx))))
return msg; return msg;
} }
} }
@ -447,46 +447,46 @@ cell_extension_check(const cell_extension_t *obj)
} }
ssize_t ssize_t
cell_extension_encoded_len(const cell_extension_t *obj) trn_cell_extension_encoded_len(const trn_cell_extension_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
if (NULL != cell_extension_check(obj)) if (NULL != trn_cell_extension_check(obj))
return -1; return -1;
/* Length of u8 num */ /* Length of u8 num */
result += 1; result += 1;
/* Length of struct cell_extension_fields fields[num] */ /* Length of struct trn_cell_extension_fields fields[num] */
{ {
unsigned idx; unsigned idx;
for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) { for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) {
result += cell_extension_fields_encoded_len(TRUNNEL_DYNARRAY_GET(&obj->fields, idx)); result += trn_cell_extension_fields_encoded_len(TRUNNEL_DYNARRAY_GET(&obj->fields, idx));
} }
} }
return result; return result;
} }
int int
cell_extension_clear_errors(cell_extension_t *obj) trn_cell_extension_clear_errors(trn_cell_extension_t *obj)
{ {
int r = obj->trunnel_error_code_; int r = obj->trunnel_error_code_;
obj->trunnel_error_code_ = 0; obj->trunnel_error_code_ = 0;
return r; return r;
} }
ssize_t ssize_t
cell_extension_encode(uint8_t *output, const size_t avail, const cell_extension_t *obj) trn_cell_extension_encode(uint8_t *output, const size_t avail, const trn_cell_extension_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
size_t written = 0; size_t written = 0;
uint8_t *ptr = output; uint8_t *ptr = output;
const char *msg; const char *msg;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
const ssize_t encoded_len = cell_extension_encoded_len(obj); const ssize_t encoded_len = trn_cell_extension_encoded_len(obj);
#endif #endif
if (NULL != (msg = cell_extension_check(obj))) if (NULL != (msg = trn_cell_extension_check(obj)))
goto check_failed; goto check_failed;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
@ -500,13 +500,13 @@ cell_extension_encode(uint8_t *output, const size_t avail, const cell_extension_
trunnel_set_uint8(ptr, (obj->num)); trunnel_set_uint8(ptr, (obj->num));
written += 1; ptr += 1; written += 1; ptr += 1;
/* Encode struct cell_extension_fields fields[num] */ /* Encode struct trn_cell_extension_fields fields[num] */
{ {
unsigned idx; unsigned idx;
for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) { for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) {
trunnel_assert(written <= avail); trunnel_assert(written <= avail);
result = cell_extension_fields_encode(ptr, avail - written, TRUNNEL_DYNARRAY_GET(&obj->fields, idx)); result = trn_cell_extension_fields_encode(ptr, avail - written, TRUNNEL_DYNARRAY_GET(&obj->fields, idx));
if (result < 0) if (result < 0)
goto fail; /* XXXXXXX !*/ goto fail; /* XXXXXXX !*/
written += result; ptr += result; written += result; ptr += result;
@ -537,10 +537,11 @@ cell_extension_encode(uint8_t *output, const size_t avail, const cell_extension_
return result; return result;
} }
/** As cell_extension_parse(), but do not allocate the output object. /** As trn_cell_extension_parse(), but do not allocate the output
* object.
*/ */
static ssize_t static ssize_t
cell_extension_parse_into(cell_extension_t *obj, const uint8_t *input, const size_t len_in) trn_cell_extension_parse_into(trn_cell_extension_t *obj, const uint8_t *input, const size_t len_in)
{ {
const uint8_t *ptr = input; const uint8_t *ptr = input;
size_t remaining = len_in; size_t remaining = len_in;
@ -552,18 +553,18 @@ cell_extension_parse_into(cell_extension_t *obj, const uint8_t *input, const siz
obj->num = (trunnel_get_uint8(ptr)); obj->num = (trunnel_get_uint8(ptr));
remaining -= 1; ptr += 1; remaining -= 1; ptr += 1;
/* Parse struct cell_extension_fields fields[num] */ /* Parse struct trn_cell_extension_fields fields[num] */
TRUNNEL_DYNARRAY_EXPAND(cell_extension_fields_t *, &obj->fields, obj->num, {}); TRUNNEL_DYNARRAY_EXPAND(trn_cell_extension_fields_t *, &obj->fields, obj->num, {});
{ {
cell_extension_fields_t * elt; trn_cell_extension_fields_t * elt;
unsigned idx; unsigned idx;
for (idx = 0; idx < obj->num; ++idx) { for (idx = 0; idx < obj->num; ++idx) {
result = cell_extension_fields_parse(&elt, ptr, remaining); result = trn_cell_extension_fields_parse(&elt, ptr, remaining);
if (result < 0) if (result < 0)
goto relay_fail; goto relay_fail;
trunnel_assert((size_t)result <= remaining); trunnel_assert((size_t)result <= remaining);
remaining -= result; ptr += result; remaining -= result; ptr += result;
TRUNNEL_DYNARRAY_ADD(cell_extension_fields_t *, &obj->fields, elt, {cell_extension_fields_free(elt);}); TRUNNEL_DYNARRAY_ADD(trn_cell_extension_fields_t *, &obj->fields, elt, {trn_cell_extension_fields_free(elt);});
} }
} }
trunnel_assert(ptr + remaining == input + len_in); trunnel_assert(ptr + remaining == input + len_in);
@ -579,15 +580,15 @@ cell_extension_parse_into(cell_extension_t *obj, const uint8_t *input, const siz
} }
ssize_t ssize_t
cell_extension_parse(cell_extension_t **output, const uint8_t *input, const size_t len_in) trn_cell_extension_parse(trn_cell_extension_t **output, const uint8_t *input, const size_t len_in)
{ {
ssize_t result; ssize_t result;
*output = cell_extension_new(); *output = trn_cell_extension_new();
if (NULL == *output) if (NULL == *output)
return -1; return -1;
result = cell_extension_parse_into(*output, input, len_in); result = trn_cell_extension_parse_into(*output, input, len_in);
if (result < 0) { if (result < 0) {
cell_extension_free(*output); trn_cell_extension_free(*output);
*output = NULL; *output = NULL;
} }
return result; return result;

View File

@ -8,191 +8,196 @@
#include <stdint.h> #include <stdint.h>
#include "trunnel.h" #include "trunnel.h"
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CELL_EXTENSION_FIELDS) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_EXTENSION_FIELDS)
struct cell_extension_fields_st { struct trn_cell_extension_fields_st {
uint8_t field_type; uint8_t field_type;
uint8_t field_len; uint8_t field_len;
TRUNNEL_DYNARRAY_HEAD(, uint8_t) field; TRUNNEL_DYNARRAY_HEAD(, uint8_t) field;
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct cell_extension_fields_st cell_extension_fields_t; typedef struct trn_cell_extension_fields_st trn_cell_extension_fields_t;
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CELL_EXTENSION) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_EXTENSION)
struct cell_extension_st { struct trn_cell_extension_st {
uint8_t num; uint8_t num;
TRUNNEL_DYNARRAY_HEAD(, struct cell_extension_fields_st *) fields; TRUNNEL_DYNARRAY_HEAD(, struct trn_cell_extension_fields_st *) fields;
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct cell_extension_st cell_extension_t; typedef struct trn_cell_extension_st trn_cell_extension_t;
/** Return a newly allocated cell_extension_fields with all elements /** Return a newly allocated trn_cell_extension_fields with all
* set to zero. * elements set to zero.
*/ */
cell_extension_fields_t *cell_extension_fields_new(void); trn_cell_extension_fields_t *trn_cell_extension_fields_new(void);
/** Release all storage held by the cell_extension_fields in 'victim'. /** Release all storage held by the trn_cell_extension_fields in
* (Do nothing if 'victim' is NULL.) * 'victim'. (Do nothing if 'victim' is NULL.)
*/ */
void cell_extension_fields_free(cell_extension_fields_t *victim); void trn_cell_extension_fields_free(trn_cell_extension_fields_t *victim);
/** Try to parse a cell_extension_fields from the buffer in 'input', /** Try to parse a trn_cell_extension_fields from the buffer in
* using up to 'len_in' bytes from the input buffer. On success, * 'input', using up to 'len_in' bytes from the input buffer. On
* return the number of bytes consumed and set *output to the newly * success, return the number of bytes consumed and set *output to the
* allocated cell_extension_fields_t. On failure, return -2 if the * newly allocated trn_cell_extension_fields_t. On failure, return -2
* input appears truncated, and -1 if the input is otherwise invalid. * if the input appears truncated, and -1 if the input is otherwise
* invalid.
*/ */
ssize_t cell_extension_fields_parse(cell_extension_fields_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_extension_fields_parse(trn_cell_extension_fields_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* cell_extension_fields in 'obj'. On failure, return a negative * trn_cell_extension_fields in 'obj'. On failure, return a negative
* value. Note that this value may be an overestimate, and can even be * value. Note that this value may be an overestimate, and can even be
* an underestimate for certain unencodeable objects. * an underestimate for certain unencodeable objects.
*/ */
ssize_t cell_extension_fields_encoded_len(const cell_extension_fields_t *obj); ssize_t trn_cell_extension_fields_encoded_len(const trn_cell_extension_fields_t *obj);
/** Try to encode the cell_extension_fields from 'input' into the /** Try to encode the trn_cell_extension_fields from 'input' into the
* buffer at 'output', using up to 'avail' bytes of the output buffer. * buffer at 'output', using up to 'avail' bytes of the output buffer.
* On success, return the number of bytes used. On failure, return -2 * On success, return the number of bytes used. On failure, return -2
* if the buffer was not long enough, and -1 if the input was invalid. * if the buffer was not long enough, and -1 if the input was invalid.
*/ */
ssize_t cell_extension_fields_encode(uint8_t *output, size_t avail, const cell_extension_fields_t *input); ssize_t trn_cell_extension_fields_encode(uint8_t *output, size_t avail, const trn_cell_extension_fields_t *input);
/** Check whether the internal state of the cell_extension_fields in /** Check whether the internal state of the trn_cell_extension_fields
* 'obj' is consistent. Return NULL if it is, and a short message if * in 'obj' is consistent. Return NULL if it is, and a short message
* it is not. * if it is not.
*/ */
const char *cell_extension_fields_check(const cell_extension_fields_t *obj); const char *trn_cell_extension_fields_check(const trn_cell_extension_fields_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int cell_extension_fields_clear_errors(cell_extension_fields_t *obj); int trn_cell_extension_fields_clear_errors(trn_cell_extension_fields_t *obj);
/** Return the value of the field_type field of the /** Return the value of the field_type field of the
* cell_extension_fields_t in 'inp' * trn_cell_extension_fields_t in 'inp'
*/ */
uint8_t cell_extension_fields_get_field_type(const cell_extension_fields_t *inp); uint8_t trn_cell_extension_fields_get_field_type(const trn_cell_extension_fields_t *inp);
/** Set the value of the field_type field of the /** Set the value of the field_type field of the
* cell_extension_fields_t in 'inp' to 'val'. Return 0 on success; * trn_cell_extension_fields_t in 'inp' to 'val'. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int cell_extension_fields_set_field_type(cell_extension_fields_t *inp, uint8_t val); int trn_cell_extension_fields_set_field_type(trn_cell_extension_fields_t *inp, uint8_t val);
/** Return the value of the field_len field of the /** Return the value of the field_len field of the
* cell_extension_fields_t in 'inp' * trn_cell_extension_fields_t in 'inp'
*/ */
uint8_t cell_extension_fields_get_field_len(const cell_extension_fields_t *inp); uint8_t trn_cell_extension_fields_get_field_len(const trn_cell_extension_fields_t *inp);
/** Set the value of the field_len field of the /** Set the value of the field_len field of the
* cell_extension_fields_t in 'inp' to 'val'. Return 0 on success; * trn_cell_extension_fields_t in 'inp' to 'val'. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int cell_extension_fields_set_field_len(cell_extension_fields_t *inp, uint8_t val); int trn_cell_extension_fields_set_field_len(trn_cell_extension_fields_t *inp, uint8_t val);
/** Return the length of the dynamic array holding the field field of /** Return the length of the dynamic array holding the field field of
* the cell_extension_fields_t in 'inp'. * the trn_cell_extension_fields_t in 'inp'.
*/ */
size_t cell_extension_fields_getlen_field(const cell_extension_fields_t *inp); size_t trn_cell_extension_fields_getlen_field(const trn_cell_extension_fields_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* field of the cell_extension_fields_t in 'inp'. * field of the trn_cell_extension_fields_t in 'inp'.
*/ */
uint8_t cell_extension_fields_get_field(cell_extension_fields_t *inp, size_t idx); uint8_t trn_cell_extension_fields_get_field(trn_cell_extension_fields_t *inp, size_t idx);
/** As cell_extension_fields_get_field, but take and return a const /** As trn_cell_extension_fields_get_field, but take and return a
* pointer * const pointer
*/ */
uint8_t cell_extension_fields_getconst_field(const cell_extension_fields_t *inp, size_t idx); uint8_t trn_cell_extension_fields_getconst_field(const trn_cell_extension_fields_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* field of the cell_extension_fields_t in 'inp', so that it will hold * field of the trn_cell_extension_fields_t in 'inp', so that it will
* the value 'elt'. * hold the value 'elt'.
*/ */
int cell_extension_fields_set_field(cell_extension_fields_t *inp, size_t idx, uint8_t elt); int trn_cell_extension_fields_set_field(trn_cell_extension_fields_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field field of the /** Append a new element 'elt' to the dynamic array field field of the
* cell_extension_fields_t in 'inp'. * trn_cell_extension_fields_t in 'inp'.
*/ */
int cell_extension_fields_add_field(cell_extension_fields_t *inp, uint8_t elt); int trn_cell_extension_fields_add_field(trn_cell_extension_fields_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field field of /** Return a pointer to the variable-length array field field of
* 'inp'. * 'inp'.
*/ */
uint8_t * cell_extension_fields_getarray_field(cell_extension_fields_t *inp); uint8_t * trn_cell_extension_fields_getarray_field(trn_cell_extension_fields_t *inp);
/** As cell_extension_fields_get_field, but take and return a const /** As trn_cell_extension_fields_get_field, but take and return a
* pointer * const pointer
*/ */
const uint8_t * cell_extension_fields_getconstarray_field(const cell_extension_fields_t *inp); const uint8_t * trn_cell_extension_fields_getconstarray_field(const trn_cell_extension_fields_t *inp);
/** Change the length of the variable-length array field field of /** Change the length of the variable-length array field field of
* 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int cell_extension_fields_setlen_field(cell_extension_fields_t *inp, size_t newlen); int trn_cell_extension_fields_setlen_field(trn_cell_extension_fields_t *inp, size_t newlen);
/** Return a newly allocated cell_extension with all elements set to /** Return a newly allocated trn_cell_extension with all elements set
* zero. * to zero.
*/ */
cell_extension_t *cell_extension_new(void); trn_cell_extension_t *trn_cell_extension_new(void);
/** Release all storage held by the cell_extension in 'victim'. (Do /** Release all storage held by the trn_cell_extension in 'victim'.
* nothing if 'victim' is NULL.) * (Do nothing if 'victim' is NULL.)
*/ */
void cell_extension_free(cell_extension_t *victim); void trn_cell_extension_free(trn_cell_extension_t *victim);
/** Try to parse a cell_extension from the buffer in 'input', using up /** Try to parse a trn_cell_extension from the buffer in 'input',
* to 'len_in' bytes from the input buffer. On success, return the * using up to 'len_in' bytes from the input buffer. On success,
* number of bytes consumed and set *output to the newly allocated * return the number of bytes consumed and set *output to the newly
* cell_extension_t. On failure, return -2 if the input appears * allocated trn_cell_extension_t. On failure, return -2 if the input
* truncated, and -1 if the input is otherwise invalid. * appears truncated, and -1 if the input is otherwise invalid.
*/ */
ssize_t cell_extension_parse(cell_extension_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_extension_parse(trn_cell_extension_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* cell_extension in 'obj'. On failure, return a negative value. Note * trn_cell_extension in 'obj'. On failure, return a negative value.
* that this value may be an overestimate, and can even be an * Note that this value may be an overestimate, and can even be an
* underestimate for certain unencodeable objects. * underestimate for certain unencodeable objects.
*/ */
ssize_t cell_extension_encoded_len(const cell_extension_t *obj); ssize_t trn_cell_extension_encoded_len(const trn_cell_extension_t *obj);
/** Try to encode the cell_extension from 'input' into the buffer at /** Try to encode the trn_cell_extension from 'input' into the buffer
* 'output', using up to 'avail' bytes of the output buffer. On * at 'output', using up to 'avail' bytes of the output buffer. On
* success, return the number of bytes used. On failure, return -2 if * success, return the number of bytes used. On failure, return -2 if
* the buffer was not long enough, and -1 if the input was invalid. * the buffer was not long enough, and -1 if the input was invalid.
*/ */
ssize_t cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input); ssize_t trn_cell_extension_encode(uint8_t *output, size_t avail, const trn_cell_extension_t *input);
/** Check whether the internal state of the cell_extension in 'obj' is /** Check whether the internal state of the trn_cell_extension in
* consistent. Return NULL if it is, and a short message if it is not. * 'obj' is consistent. Return NULL if it is, and a short message if
* it is not.
*/ */
const char *cell_extension_check(const cell_extension_t *obj); const char *trn_cell_extension_check(const trn_cell_extension_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int cell_extension_clear_errors(cell_extension_t *obj); int trn_cell_extension_clear_errors(trn_cell_extension_t *obj);
/** Return the value of the num field of the cell_extension_t in 'inp' /** Return the value of the num field of the trn_cell_extension_t in
* 'inp'
*/ */
uint8_t cell_extension_get_num(const cell_extension_t *inp); uint8_t trn_cell_extension_get_num(const trn_cell_extension_t *inp);
/** Set the value of the num field of the cell_extension_t in 'inp' to /** Set the value of the num field of the trn_cell_extension_t in
* 'val'. Return 0 on success; return -1 and set the error code on * 'inp' to 'val'. Return 0 on success; return -1 and set the error
* 'inp' on failure. * code on 'inp' on failure.
*/ */
int cell_extension_set_num(cell_extension_t *inp, uint8_t val); int trn_cell_extension_set_num(trn_cell_extension_t *inp, uint8_t val);
/** Return the length of the dynamic array holding the fields field of /** Return the length of the dynamic array holding the fields field of
* the cell_extension_t in 'inp'. * the trn_cell_extension_t in 'inp'.
*/ */
size_t cell_extension_getlen_fields(const cell_extension_t *inp); size_t trn_cell_extension_getlen_fields(const trn_cell_extension_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* fields of the cell_extension_t in 'inp'. * fields of the trn_cell_extension_t in 'inp'.
*/ */
struct cell_extension_fields_st * cell_extension_get_fields(cell_extension_t *inp, size_t idx); struct trn_cell_extension_fields_st * trn_cell_extension_get_fields(trn_cell_extension_t *inp, size_t idx);
/** As cell_extension_get_fields, but take and return a const pointer /** As trn_cell_extension_get_fields, but take and return a const
* pointer
*/ */
const struct cell_extension_fields_st * cell_extension_getconst_fields(const cell_extension_t *inp, size_t idx); const struct trn_cell_extension_fields_st * trn_cell_extension_getconst_fields(const trn_cell_extension_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* fields of the cell_extension_t in 'inp', so that it will hold the * fields of the trn_cell_extension_t in 'inp', so that it will hold
* value 'elt'. Free the previous value, if any. * the value 'elt'. Free the previous value, if any.
*/ */
int cell_extension_set_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt); int trn_cell_extension_set_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt);
/** As cell_extension_set_fields, but does not free the previous /** As trn_cell_extension_set_fields, but does not free the previous
* value. * value.
*/ */
int cell_extension_set0_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt); int trn_cell_extension_set0_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt);
/** Append a new element 'elt' to the dynamic array field fields of /** Append a new element 'elt' to the dynamic array field fields of
* the cell_extension_t in 'inp'. * the trn_cell_extension_t in 'inp'.
*/ */
int cell_extension_add_fields(cell_extension_t *inp, struct cell_extension_fields_st * elt); int trn_cell_extension_add_fields(trn_cell_extension_t *inp, struct trn_cell_extension_fields_st * elt);
/** Return a pointer to the variable-length array field fields of /** Return a pointer to the variable-length array field fields of
* 'inp'. * 'inp'.
*/ */
struct cell_extension_fields_st * * cell_extension_getarray_fields(cell_extension_t *inp); struct trn_cell_extension_fields_st * * trn_cell_extension_getarray_fields(trn_cell_extension_t *inp);
/** As cell_extension_get_fields, but take and return a const pointer /** As trn_cell_extension_get_fields, but take and return a const
* pointer
*/ */
const struct cell_extension_fields_st * const * cell_extension_getconstarray_fields(const cell_extension_t *inp); const struct trn_cell_extension_fields_st * const * trn_cell_extension_getconstarray_fields(const trn_cell_extension_t *inp);
/** Change the length of the variable-length array field fields of /** Change the length of the variable-length array field fields of
* 'inp' to 'newlen'.Fill extra elements with NULL; free removed * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
* elements. Return 0 on success; return -1 and set the error code on * elements. Return 0 on success; return -1 and set the error code on
* 'inp' on failure. * 'inp' on failure.
*/ */
int cell_extension_setlen_fields(cell_extension_t *inp, size_t newlen); int trn_cell_extension_setlen_fields(trn_cell_extension_t *inp, size_t newlen);
#endif #endif

View File

@ -1,12 +1,12 @@
/* This file contains common data structure that cells use. */ /* This file contains common data structure that cells use. */
struct cell_extension_fields { struct trn_cell_extension_fields {
u8 field_type; u8 field_type;
u8 field_len; u8 field_len;
u8 field[field_len]; u8 field[field_len];
}; };
struct cell_extension { struct trn_cell_extension {
u8 num; u8 num;
struct cell_extension_fields fields[num]; struct trn_cell_extension_fields fields[num];
}; };

View File

@ -28,18 +28,18 @@ int cellestablishintro_deadcode_dummy__ = 0;
} \ } \
} while (0) } while (0)
typedef struct cell_extension_st cell_extension_t; typedef struct trn_cell_extension_st trn_cell_extension_t;
cell_extension_t *cell_extension_new(void); trn_cell_extension_t *trn_cell_extension_new(void);
void cell_extension_free(cell_extension_t *victim); void trn_cell_extension_free(trn_cell_extension_t *victim);
ssize_t cell_extension_parse(cell_extension_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_extension_parse(trn_cell_extension_t **output, const uint8_t *input, const size_t len_in);
ssize_t cell_extension_encoded_len(const cell_extension_t *obj); ssize_t trn_cell_extension_encoded_len(const trn_cell_extension_t *obj);
ssize_t cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input); ssize_t trn_cell_extension_encode(uint8_t *output, size_t avail, const trn_cell_extension_t *input);
const char *cell_extension_check(const cell_extension_t *obj); const char *trn_cell_extension_check(const trn_cell_extension_t *obj);
int cell_extension_clear_errors(cell_extension_t *obj); int trn_cell_extension_clear_errors(trn_cell_extension_t *obj);
hs_cell_establish_intro_t * trn_cell_establish_intro_t *
hs_cell_establish_intro_new(void) trn_cell_establish_intro_new(void)
{ {
hs_cell_establish_intro_t *val = trunnel_calloc(1, sizeof(hs_cell_establish_intro_t)); trn_cell_establish_intro_t *val = trunnel_calloc(1, sizeof(trn_cell_establish_intro_t));
if (NULL == val) if (NULL == val)
return NULL; return NULL;
return val; return val;
@ -48,39 +48,39 @@ hs_cell_establish_intro_new(void)
/** Release all storage held inside 'obj', but do not free 'obj'. /** Release all storage held inside 'obj', but do not free 'obj'.
*/ */
static void static void
hs_cell_establish_intro_clear(hs_cell_establish_intro_t *obj) trn_cell_establish_intro_clear(trn_cell_establish_intro_t *obj)
{ {
(void) obj; (void) obj;
TRUNNEL_DYNARRAY_WIPE(&obj->auth_key); TRUNNEL_DYNARRAY_WIPE(&obj->auth_key);
TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key); TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key);
cell_extension_free(obj->extensions); trn_cell_extension_free(obj->extensions);
obj->extensions = NULL; obj->extensions = NULL;
TRUNNEL_DYNARRAY_WIPE(&obj->sig); TRUNNEL_DYNARRAY_WIPE(&obj->sig);
TRUNNEL_DYNARRAY_CLEAR(&obj->sig); TRUNNEL_DYNARRAY_CLEAR(&obj->sig);
} }
void void
hs_cell_establish_intro_free(hs_cell_establish_intro_t *obj) trn_cell_establish_intro_free(trn_cell_establish_intro_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return; return;
hs_cell_establish_intro_clear(obj); trn_cell_establish_intro_clear(obj);
trunnel_memwipe(obj, sizeof(hs_cell_establish_intro_t)); trunnel_memwipe(obj, sizeof(trn_cell_establish_intro_t));
trunnel_free_(obj); trunnel_free_(obj);
} }
const uint8_t * const uint8_t *
hs_cell_establish_intro_get_start_cell(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_start_cell(const trn_cell_establish_intro_t *inp)
{ {
return inp->start_cell; return inp->start_cell;
} }
uint8_t uint8_t
hs_cell_establish_intro_get_auth_key_type(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_auth_key_type(const trn_cell_establish_intro_t *inp)
{ {
return inp->auth_key_type; return inp->auth_key_type;
} }
int int
hs_cell_establish_intro_set_auth_key_type(hs_cell_establish_intro_t *inp, uint8_t val) trn_cell_establish_intro_set_auth_key_type(trn_cell_establish_intro_t *inp, uint8_t val)
{ {
if (! ((val == 0 || val == 1 || val == 2))) { if (! ((val == 0 || val == 1 || val == 2))) {
TRUNNEL_SET_ERROR_CODE(inp); TRUNNEL_SET_ERROR_CODE(inp);
@ -90,41 +90,41 @@ hs_cell_establish_intro_set_auth_key_type(hs_cell_establish_intro_t *inp, uint8_
return 0; return 0;
} }
uint16_t uint16_t
hs_cell_establish_intro_get_auth_key_len(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_auth_key_len(const trn_cell_establish_intro_t *inp)
{ {
return inp->auth_key_len; return inp->auth_key_len;
} }
int int
hs_cell_establish_intro_set_auth_key_len(hs_cell_establish_intro_t *inp, uint16_t val) trn_cell_establish_intro_set_auth_key_len(trn_cell_establish_intro_t *inp, uint16_t val)
{ {
inp->auth_key_len = val; inp->auth_key_len = val;
return 0; return 0;
} }
size_t size_t
hs_cell_establish_intro_getlen_auth_key(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getlen_auth_key(const trn_cell_establish_intro_t *inp)
{ {
return TRUNNEL_DYNARRAY_LEN(&inp->auth_key); return TRUNNEL_DYNARRAY_LEN(&inp->auth_key);
} }
uint8_t uint8_t
hs_cell_establish_intro_get_auth_key(hs_cell_establish_intro_t *inp, size_t idx) trn_cell_establish_intro_get_auth_key(trn_cell_establish_intro_t *inp, size_t idx)
{ {
return TRUNNEL_DYNARRAY_GET(&inp->auth_key, idx); return TRUNNEL_DYNARRAY_GET(&inp->auth_key, idx);
} }
uint8_t uint8_t
hs_cell_establish_intro_getconst_auth_key(const hs_cell_establish_intro_t *inp, size_t idx) trn_cell_establish_intro_getconst_auth_key(const trn_cell_establish_intro_t *inp, size_t idx)
{ {
return hs_cell_establish_intro_get_auth_key((hs_cell_establish_intro_t*)inp, idx); return trn_cell_establish_intro_get_auth_key((trn_cell_establish_intro_t*)inp, idx);
} }
int int
hs_cell_establish_intro_set_auth_key(hs_cell_establish_intro_t *inp, size_t idx, uint8_t elt) trn_cell_establish_intro_set_auth_key(trn_cell_establish_intro_t *inp, size_t idx, uint8_t elt)
{ {
TRUNNEL_DYNARRAY_SET(&inp->auth_key, idx, elt); TRUNNEL_DYNARRAY_SET(&inp->auth_key, idx, elt);
return 0; return 0;
} }
int int
hs_cell_establish_intro_add_auth_key(hs_cell_establish_intro_t *inp, uint8_t elt) trn_cell_establish_intro_add_auth_key(trn_cell_establish_intro_t *inp, uint8_t elt)
{ {
#if SIZE_MAX >= UINT16_MAX #if SIZE_MAX >= UINT16_MAX
if (inp->auth_key.n_ == UINT16_MAX) if (inp->auth_key.n_ == UINT16_MAX)
@ -138,17 +138,17 @@ hs_cell_establish_intro_add_auth_key(hs_cell_establish_intro_t *inp, uint8_t elt
} }
uint8_t * uint8_t *
hs_cell_establish_intro_getarray_auth_key(hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getarray_auth_key(trn_cell_establish_intro_t *inp)
{ {
return inp->auth_key.elts_; return inp->auth_key.elts_;
} }
const uint8_t * const uint8_t *
hs_cell_establish_intro_getconstarray_auth_key(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getconstarray_auth_key(const trn_cell_establish_intro_t *inp)
{ {
return (const uint8_t *)hs_cell_establish_intro_getarray_auth_key((hs_cell_establish_intro_t*)inp); return (const uint8_t *)trn_cell_establish_intro_getarray_auth_key((trn_cell_establish_intro_t*)inp);
} }
int int
hs_cell_establish_intro_setlen_auth_key(hs_cell_establish_intro_t *inp, size_t newlen) trn_cell_establish_intro_setlen_auth_key(trn_cell_establish_intro_t *inp, size_t newlen)
{ {
uint8_t *newptr; uint8_t *newptr;
#if UINT16_MAX < SIZE_MAX #if UINT16_MAX < SIZE_MAX
@ -167,54 +167,54 @@ hs_cell_establish_intro_setlen_auth_key(hs_cell_establish_intro_t *inp, size_t n
TRUNNEL_SET_ERROR_CODE(inp); TRUNNEL_SET_ERROR_CODE(inp);
return -1; return -1;
} }
struct cell_extension_st * struct trn_cell_extension_st *
hs_cell_establish_intro_get_extensions(hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_extensions(trn_cell_establish_intro_t *inp)
{ {
return inp->extensions; return inp->extensions;
} }
const struct cell_extension_st * const struct trn_cell_extension_st *
hs_cell_establish_intro_getconst_extensions(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getconst_extensions(const trn_cell_establish_intro_t *inp)
{ {
return hs_cell_establish_intro_get_extensions((hs_cell_establish_intro_t*) inp); return trn_cell_establish_intro_get_extensions((trn_cell_establish_intro_t*) inp);
} }
int int
hs_cell_establish_intro_set_extensions(hs_cell_establish_intro_t *inp, struct cell_extension_st *val) trn_cell_establish_intro_set_extensions(trn_cell_establish_intro_t *inp, struct trn_cell_extension_st *val)
{ {
if (inp->extensions && inp->extensions != val) if (inp->extensions && inp->extensions != val)
cell_extension_free(inp->extensions); trn_cell_extension_free(inp->extensions);
return hs_cell_establish_intro_set0_extensions(inp, val); return trn_cell_establish_intro_set0_extensions(inp, val);
} }
int int
hs_cell_establish_intro_set0_extensions(hs_cell_establish_intro_t *inp, struct cell_extension_st *val) trn_cell_establish_intro_set0_extensions(trn_cell_establish_intro_t *inp, struct trn_cell_extension_st *val)
{ {
inp->extensions = val; inp->extensions = val;
return 0; return 0;
} }
const uint8_t * const uint8_t *
hs_cell_establish_intro_get_end_mac_fields(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_end_mac_fields(const trn_cell_establish_intro_t *inp)
{ {
return inp->end_mac_fields; return inp->end_mac_fields;
} }
size_t size_t
hs_cell_establish_intro_getlen_handshake_mac(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getlen_handshake_mac(const trn_cell_establish_intro_t *inp)
{ {
(void)inp; return TRUNNEL_SHA3_256_LEN; (void)inp; return TRUNNEL_SHA3_256_LEN;
} }
uint8_t uint8_t
hs_cell_establish_intro_get_handshake_mac(hs_cell_establish_intro_t *inp, size_t idx) trn_cell_establish_intro_get_handshake_mac(trn_cell_establish_intro_t *inp, size_t idx)
{ {
trunnel_assert(idx < TRUNNEL_SHA3_256_LEN); trunnel_assert(idx < TRUNNEL_SHA3_256_LEN);
return inp->handshake_mac[idx]; return inp->handshake_mac[idx];
} }
uint8_t uint8_t
hs_cell_establish_intro_getconst_handshake_mac(const hs_cell_establish_intro_t *inp, size_t idx) trn_cell_establish_intro_getconst_handshake_mac(const trn_cell_establish_intro_t *inp, size_t idx)
{ {
return hs_cell_establish_intro_get_handshake_mac((hs_cell_establish_intro_t*)inp, idx); return trn_cell_establish_intro_get_handshake_mac((trn_cell_establish_intro_t*)inp, idx);
} }
int int
hs_cell_establish_intro_set_handshake_mac(hs_cell_establish_intro_t *inp, size_t idx, uint8_t elt) trn_cell_establish_intro_set_handshake_mac(trn_cell_establish_intro_t *inp, size_t idx, uint8_t elt)
{ {
trunnel_assert(idx < TRUNNEL_SHA3_256_LEN); trunnel_assert(idx < TRUNNEL_SHA3_256_LEN);
inp->handshake_mac[idx] = elt; inp->handshake_mac[idx] = elt;
@ -222,56 +222,56 @@ hs_cell_establish_intro_set_handshake_mac(hs_cell_establish_intro_t *inp, size_t
} }
uint8_t * uint8_t *
hs_cell_establish_intro_getarray_handshake_mac(hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getarray_handshake_mac(trn_cell_establish_intro_t *inp)
{ {
return inp->handshake_mac; return inp->handshake_mac;
} }
const uint8_t * const uint8_t *
hs_cell_establish_intro_getconstarray_handshake_mac(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getconstarray_handshake_mac(const trn_cell_establish_intro_t *inp)
{ {
return (const uint8_t *)hs_cell_establish_intro_getarray_handshake_mac((hs_cell_establish_intro_t*)inp); return (const uint8_t *)trn_cell_establish_intro_getarray_handshake_mac((trn_cell_establish_intro_t*)inp);
} }
const uint8_t * const uint8_t *
hs_cell_establish_intro_get_end_sig_fields(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_end_sig_fields(const trn_cell_establish_intro_t *inp)
{ {
return inp->end_sig_fields; return inp->end_sig_fields;
} }
uint16_t uint16_t
hs_cell_establish_intro_get_sig_len(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_get_sig_len(const trn_cell_establish_intro_t *inp)
{ {
return inp->sig_len; return inp->sig_len;
} }
int int
hs_cell_establish_intro_set_sig_len(hs_cell_establish_intro_t *inp, uint16_t val) trn_cell_establish_intro_set_sig_len(trn_cell_establish_intro_t *inp, uint16_t val)
{ {
inp->sig_len = val; inp->sig_len = val;
return 0; return 0;
} }
size_t size_t
hs_cell_establish_intro_getlen_sig(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getlen_sig(const trn_cell_establish_intro_t *inp)
{ {
return TRUNNEL_DYNARRAY_LEN(&inp->sig); return TRUNNEL_DYNARRAY_LEN(&inp->sig);
} }
uint8_t uint8_t
hs_cell_establish_intro_get_sig(hs_cell_establish_intro_t *inp, size_t idx) trn_cell_establish_intro_get_sig(trn_cell_establish_intro_t *inp, size_t idx)
{ {
return TRUNNEL_DYNARRAY_GET(&inp->sig, idx); return TRUNNEL_DYNARRAY_GET(&inp->sig, idx);
} }
uint8_t uint8_t
hs_cell_establish_intro_getconst_sig(const hs_cell_establish_intro_t *inp, size_t idx) trn_cell_establish_intro_getconst_sig(const trn_cell_establish_intro_t *inp, size_t idx)
{ {
return hs_cell_establish_intro_get_sig((hs_cell_establish_intro_t*)inp, idx); return trn_cell_establish_intro_get_sig((trn_cell_establish_intro_t*)inp, idx);
} }
int int
hs_cell_establish_intro_set_sig(hs_cell_establish_intro_t *inp, size_t idx, uint8_t elt) trn_cell_establish_intro_set_sig(trn_cell_establish_intro_t *inp, size_t idx, uint8_t elt)
{ {
TRUNNEL_DYNARRAY_SET(&inp->sig, idx, elt); TRUNNEL_DYNARRAY_SET(&inp->sig, idx, elt);
return 0; return 0;
} }
int int
hs_cell_establish_intro_add_sig(hs_cell_establish_intro_t *inp, uint8_t elt) trn_cell_establish_intro_add_sig(trn_cell_establish_intro_t *inp, uint8_t elt)
{ {
#if SIZE_MAX >= UINT16_MAX #if SIZE_MAX >= UINT16_MAX
if (inp->sig.n_ == UINT16_MAX) if (inp->sig.n_ == UINT16_MAX)
@ -285,17 +285,17 @@ hs_cell_establish_intro_add_sig(hs_cell_establish_intro_t *inp, uint8_t elt)
} }
uint8_t * uint8_t *
hs_cell_establish_intro_getarray_sig(hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getarray_sig(trn_cell_establish_intro_t *inp)
{ {
return inp->sig.elts_; return inp->sig.elts_;
} }
const uint8_t * const uint8_t *
hs_cell_establish_intro_getconstarray_sig(const hs_cell_establish_intro_t *inp) trn_cell_establish_intro_getconstarray_sig(const trn_cell_establish_intro_t *inp)
{ {
return (const uint8_t *)hs_cell_establish_intro_getarray_sig((hs_cell_establish_intro_t*)inp); return (const uint8_t *)trn_cell_establish_intro_getarray_sig((trn_cell_establish_intro_t*)inp);
} }
int int
hs_cell_establish_intro_setlen_sig(hs_cell_establish_intro_t *inp, size_t newlen) trn_cell_establish_intro_setlen_sig(trn_cell_establish_intro_t *inp, size_t newlen)
{ {
uint8_t *newptr; uint8_t *newptr;
#if UINT16_MAX < SIZE_MAX #if UINT16_MAX < SIZE_MAX
@ -315,7 +315,7 @@ hs_cell_establish_intro_setlen_sig(hs_cell_establish_intro_t *inp, size_t newlen
return -1; return -1;
} }
const char * const char *
hs_cell_establish_intro_check(const hs_cell_establish_intro_t *obj) trn_cell_establish_intro_check(const trn_cell_establish_intro_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return "Object was NULL"; return "Object was NULL";
@ -327,7 +327,7 @@ hs_cell_establish_intro_check(const hs_cell_establish_intro_t *obj)
return "Length mismatch for auth_key"; return "Length mismatch for auth_key";
{ {
const char *msg; const char *msg;
if (NULL != (msg = cell_extension_check(obj->extensions))) if (NULL != (msg = trn_cell_extension_check(obj->extensions)))
return msg; return msg;
} }
if (TRUNNEL_DYNARRAY_LEN(&obj->sig) != obj->sig_len) if (TRUNNEL_DYNARRAY_LEN(&obj->sig) != obj->sig_len)
@ -336,11 +336,11 @@ hs_cell_establish_intro_check(const hs_cell_establish_intro_t *obj)
} }
ssize_t ssize_t
hs_cell_establish_intro_encoded_len(const hs_cell_establish_intro_t *obj) trn_cell_establish_intro_encoded_len(const trn_cell_establish_intro_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
if (NULL != hs_cell_establish_intro_check(obj)) if (NULL != trn_cell_establish_intro_check(obj))
return -1; return -1;
@ -353,8 +353,8 @@ hs_cell_establish_intro_encoded_len(const hs_cell_establish_intro_t *obj)
/* Length of u8 auth_key[auth_key_len] */ /* Length of u8 auth_key[auth_key_len] */
result += TRUNNEL_DYNARRAY_LEN(&obj->auth_key); result += TRUNNEL_DYNARRAY_LEN(&obj->auth_key);
/* Length of struct cell_extension extensions */ /* Length of struct trn_cell_extension extensions */
result += cell_extension_encoded_len(obj->extensions); result += trn_cell_extension_encoded_len(obj->extensions);
/* Length of u8 handshake_mac[TRUNNEL_SHA3_256_LEN] */ /* Length of u8 handshake_mac[TRUNNEL_SHA3_256_LEN] */
result += TRUNNEL_SHA3_256_LEN; result += TRUNNEL_SHA3_256_LEN;
@ -367,24 +367,24 @@ hs_cell_establish_intro_encoded_len(const hs_cell_establish_intro_t *obj)
return result; return result;
} }
int int
hs_cell_establish_intro_clear_errors(hs_cell_establish_intro_t *obj) trn_cell_establish_intro_clear_errors(trn_cell_establish_intro_t *obj)
{ {
int r = obj->trunnel_error_code_; int r = obj->trunnel_error_code_;
obj->trunnel_error_code_ = 0; obj->trunnel_error_code_ = 0;
return r; return r;
} }
ssize_t ssize_t
hs_cell_establish_intro_encode(uint8_t *output, const size_t avail, const hs_cell_establish_intro_t *obj) trn_cell_establish_intro_encode(uint8_t *output, const size_t avail, const trn_cell_establish_intro_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
size_t written = 0; size_t written = 0;
uint8_t *ptr = output; uint8_t *ptr = output;
const char *msg; const char *msg;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
const ssize_t encoded_len = hs_cell_establish_intro_encoded_len(obj); const ssize_t encoded_len = trn_cell_establish_intro_encoded_len(obj);
#endif #endif
if (NULL != (msg = hs_cell_establish_intro_check(obj))) if (NULL != (msg = trn_cell_establish_intro_check(obj)))
goto check_failed; goto check_failed;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
@ -417,9 +417,9 @@ hs_cell_establish_intro_encode(uint8_t *output, const size_t avail, const hs_cel
written += elt_len; ptr += elt_len; written += elt_len; ptr += elt_len;
} }
/* Encode struct cell_extension extensions */ /* Encode struct trn_cell_extension extensions */
trunnel_assert(written <= avail); trunnel_assert(written <= avail);
result = cell_extension_encode(ptr, avail - written, obj->extensions); result = trn_cell_extension_encode(ptr, avail - written, obj->extensions);
if (result < 0) if (result < 0)
goto fail; /* XXXXXXX !*/ goto fail; /* XXXXXXX !*/
written += result; ptr += result; written += result; ptr += result;
@ -474,11 +474,11 @@ hs_cell_establish_intro_encode(uint8_t *output, const size_t avail, const hs_cel
return result; return result;
} }
/** As hs_cell_establish_intro_parse(), but do not allocate the output /** As trn_cell_establish_intro_parse(), but do not allocate the
* object. * output object.
*/ */
static ssize_t static ssize_t
hs_cell_establish_intro_parse_into(hs_cell_establish_intro_t *obj, const uint8_t *input, const size_t len_in) trn_cell_establish_intro_parse_into(trn_cell_establish_intro_t *obj, const uint8_t *input, const size_t len_in)
{ {
const uint8_t *ptr = input; const uint8_t *ptr = input;
size_t remaining = len_in; size_t remaining = len_in;
@ -506,8 +506,8 @@ hs_cell_establish_intro_parse_into(hs_cell_establish_intro_t *obj, const uint8_t
memcpy(obj->auth_key.elts_, ptr, obj->auth_key_len); memcpy(obj->auth_key.elts_, ptr, obj->auth_key_len);
ptr += obj->auth_key_len; remaining -= obj->auth_key_len; ptr += obj->auth_key_len; remaining -= obj->auth_key_len;
/* Parse struct cell_extension extensions */ /* Parse struct trn_cell_extension extensions */
result = cell_extension_parse(&obj->extensions, ptr, remaining); result = trn_cell_extension_parse(&obj->extensions, ptr, remaining);
if (result < 0) if (result < 0)
goto relay_fail; goto relay_fail;
trunnel_assert((size_t)result <= remaining); trunnel_assert((size_t)result <= remaining);
@ -548,23 +548,23 @@ hs_cell_establish_intro_parse_into(hs_cell_establish_intro_t *obj, const uint8_t
} }
ssize_t ssize_t
hs_cell_establish_intro_parse(hs_cell_establish_intro_t **output, const uint8_t *input, const size_t len_in) trn_cell_establish_intro_parse(trn_cell_establish_intro_t **output, const uint8_t *input, const size_t len_in)
{ {
ssize_t result; ssize_t result;
*output = hs_cell_establish_intro_new(); *output = trn_cell_establish_intro_new();
if (NULL == *output) if (NULL == *output)
return -1; return -1;
result = hs_cell_establish_intro_parse_into(*output, input, len_in); result = trn_cell_establish_intro_parse_into(*output, input, len_in);
if (result < 0) { if (result < 0) {
hs_cell_establish_intro_free(*output); trn_cell_establish_intro_free(*output);
*output = NULL; *output = NULL;
} }
return result; return result;
} }
hs_cell_intro_established_t * trn_cell_intro_established_t *
hs_cell_intro_established_new(void) trn_cell_intro_established_new(void)
{ {
hs_cell_intro_established_t *val = trunnel_calloc(1, sizeof(hs_cell_intro_established_t)); trn_cell_intro_established_t *val = trunnel_calloc(1, sizeof(trn_cell_intro_established_t));
if (NULL == val) if (NULL == val)
return NULL; return NULL;
return val; return val;
@ -573,48 +573,48 @@ hs_cell_intro_established_new(void)
/** Release all storage held inside 'obj', but do not free 'obj'. /** Release all storage held inside 'obj', but do not free 'obj'.
*/ */
static void static void
hs_cell_intro_established_clear(hs_cell_intro_established_t *obj) trn_cell_intro_established_clear(trn_cell_intro_established_t *obj)
{ {
(void) obj; (void) obj;
cell_extension_free(obj->extensions); trn_cell_extension_free(obj->extensions);
obj->extensions = NULL; obj->extensions = NULL;
} }
void void
hs_cell_intro_established_free(hs_cell_intro_established_t *obj) trn_cell_intro_established_free(trn_cell_intro_established_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return; return;
hs_cell_intro_established_clear(obj); trn_cell_intro_established_clear(obj);
trunnel_memwipe(obj, sizeof(hs_cell_intro_established_t)); trunnel_memwipe(obj, sizeof(trn_cell_intro_established_t));
trunnel_free_(obj); trunnel_free_(obj);
} }
struct cell_extension_st * struct trn_cell_extension_st *
hs_cell_intro_established_get_extensions(hs_cell_intro_established_t *inp) trn_cell_intro_established_get_extensions(trn_cell_intro_established_t *inp)
{ {
return inp->extensions; return inp->extensions;
} }
const struct cell_extension_st * const struct trn_cell_extension_st *
hs_cell_intro_established_getconst_extensions(const hs_cell_intro_established_t *inp) trn_cell_intro_established_getconst_extensions(const trn_cell_intro_established_t *inp)
{ {
return hs_cell_intro_established_get_extensions((hs_cell_intro_established_t*) inp); return trn_cell_intro_established_get_extensions((trn_cell_intro_established_t*) inp);
} }
int int
hs_cell_intro_established_set_extensions(hs_cell_intro_established_t *inp, struct cell_extension_st *val) trn_cell_intro_established_set_extensions(trn_cell_intro_established_t *inp, struct trn_cell_extension_st *val)
{ {
if (inp->extensions && inp->extensions != val) if (inp->extensions && inp->extensions != val)
cell_extension_free(inp->extensions); trn_cell_extension_free(inp->extensions);
return hs_cell_intro_established_set0_extensions(inp, val); return trn_cell_intro_established_set0_extensions(inp, val);
} }
int int
hs_cell_intro_established_set0_extensions(hs_cell_intro_established_t *inp, struct cell_extension_st *val) trn_cell_intro_established_set0_extensions(trn_cell_intro_established_t *inp, struct trn_cell_extension_st *val)
{ {
inp->extensions = val; inp->extensions = val;
return 0; return 0;
} }
const char * const char *
hs_cell_intro_established_check(const hs_cell_intro_established_t *obj) trn_cell_intro_established_check(const trn_cell_intro_established_t *obj)
{ {
if (obj == NULL) if (obj == NULL)
return "Object was NULL"; return "Object was NULL";
@ -622,53 +622,53 @@ hs_cell_intro_established_check(const hs_cell_intro_established_t *obj)
return "A set function failed on this object"; return "A set function failed on this object";
{ {
const char *msg; const char *msg;
if (NULL != (msg = cell_extension_check(obj->extensions))) if (NULL != (msg = trn_cell_extension_check(obj->extensions)))
return msg; return msg;
} }
return NULL; return NULL;
} }
ssize_t ssize_t
hs_cell_intro_established_encoded_len(const hs_cell_intro_established_t *obj) trn_cell_intro_established_encoded_len(const trn_cell_intro_established_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
if (NULL != hs_cell_intro_established_check(obj)) if (NULL != trn_cell_intro_established_check(obj))
return -1; return -1;
/* Length of struct cell_extension extensions */ /* Length of struct trn_cell_extension extensions */
result += cell_extension_encoded_len(obj->extensions); result += trn_cell_extension_encoded_len(obj->extensions);
return result; return result;
} }
int int
hs_cell_intro_established_clear_errors(hs_cell_intro_established_t *obj) trn_cell_intro_established_clear_errors(trn_cell_intro_established_t *obj)
{ {
int r = obj->trunnel_error_code_; int r = obj->trunnel_error_code_;
obj->trunnel_error_code_ = 0; obj->trunnel_error_code_ = 0;
return r; return r;
} }
ssize_t ssize_t
hs_cell_intro_established_encode(uint8_t *output, const size_t avail, const hs_cell_intro_established_t *obj) trn_cell_intro_established_encode(uint8_t *output, const size_t avail, const trn_cell_intro_established_t *obj)
{ {
ssize_t result = 0; ssize_t result = 0;
size_t written = 0; size_t written = 0;
uint8_t *ptr = output; uint8_t *ptr = output;
const char *msg; const char *msg;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
const ssize_t encoded_len = hs_cell_intro_established_encoded_len(obj); const ssize_t encoded_len = trn_cell_intro_established_encoded_len(obj);
#endif #endif
if (NULL != (msg = hs_cell_intro_established_check(obj))) if (NULL != (msg = trn_cell_intro_established_check(obj)))
goto check_failed; goto check_failed;
#ifdef TRUNNEL_CHECK_ENCODED_LEN #ifdef TRUNNEL_CHECK_ENCODED_LEN
trunnel_assert(encoded_len >= 0); trunnel_assert(encoded_len >= 0);
#endif #endif
/* Encode struct cell_extension extensions */ /* Encode struct trn_cell_extension extensions */
trunnel_assert(written <= avail); trunnel_assert(written <= avail);
result = cell_extension_encode(ptr, avail - written, obj->extensions); result = trn_cell_extension_encode(ptr, avail - written, obj->extensions);
if (result < 0) if (result < 0)
goto fail; /* XXXXXXX !*/ goto fail; /* XXXXXXX !*/
written += result; ptr += result; written += result; ptr += result;
@ -694,19 +694,19 @@ hs_cell_intro_established_encode(uint8_t *output, const size_t avail, const hs_c
return result; return result;
} }
/** As hs_cell_intro_established_parse(), but do not allocate the /** As trn_cell_intro_established_parse(), but do not allocate the
* output object. * output object.
*/ */
static ssize_t static ssize_t
hs_cell_intro_established_parse_into(hs_cell_intro_established_t *obj, const uint8_t *input, const size_t len_in) trn_cell_intro_established_parse_into(trn_cell_intro_established_t *obj, const uint8_t *input, const size_t len_in)
{ {
const uint8_t *ptr = input; const uint8_t *ptr = input;
size_t remaining = len_in; size_t remaining = len_in;
ssize_t result = 0; ssize_t result = 0;
(void)result; (void)result;
/* Parse struct cell_extension extensions */ /* Parse struct trn_cell_extension extensions */
result = cell_extension_parse(&obj->extensions, ptr, remaining); result = trn_cell_extension_parse(&obj->extensions, ptr, remaining);
if (result < 0) if (result < 0)
goto relay_fail; goto relay_fail;
trunnel_assert((size_t)result <= remaining); trunnel_assert((size_t)result <= remaining);
@ -720,15 +720,15 @@ hs_cell_intro_established_parse_into(hs_cell_intro_established_t *obj, const uin
} }
ssize_t ssize_t
hs_cell_intro_established_parse(hs_cell_intro_established_t **output, const uint8_t *input, const size_t len_in) trn_cell_intro_established_parse(trn_cell_intro_established_t **output, const uint8_t *input, const size_t len_in)
{ {
ssize_t result; ssize_t result;
*output = hs_cell_intro_established_new(); *output = trn_cell_intro_established_new();
if (NULL == *output) if (NULL == *output)
return -1; return -1;
result = hs_cell_intro_established_parse_into(*output, input, len_in); result = trn_cell_intro_established_parse_into(*output, input, len_in);
if (result < 0) { if (result < 0) {
hs_cell_intro_established_free(*output); trn_cell_intro_established_free(*output);
*output = NULL; *output = NULL;
} }
return result; return result;

View File

@ -8,15 +8,15 @@
#include <stdint.h> #include <stdint.h>
#include "trunnel.h" #include "trunnel.h"
struct cell_extension_st; struct trn_cell_extension_st;
#define TRUNNEL_SHA3_256_LEN 32 #define TRUNNEL_SHA3_256_LEN 32
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_ESTABLISH_INTRO) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_ESTABLISH_INTRO)
struct hs_cell_establish_intro_st { struct trn_cell_establish_intro_st {
const uint8_t *start_cell; const uint8_t *start_cell;
uint8_t auth_key_type; uint8_t auth_key_type;
uint16_t auth_key_len; uint16_t auth_key_len;
TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key; TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key;
struct cell_extension_st *extensions; struct trn_cell_extension_st *extensions;
const uint8_t *end_mac_fields; const uint8_t *end_mac_fields;
uint8_t handshake_mac[TRUNNEL_SHA3_256_LEN]; uint8_t handshake_mac[TRUNNEL_SHA3_256_LEN];
const uint8_t *end_sig_fields; const uint8_t *end_sig_fields;
@ -25,251 +25,252 @@ struct hs_cell_establish_intro_st {
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct hs_cell_establish_intro_st hs_cell_establish_intro_t; typedef struct trn_cell_establish_intro_st trn_cell_establish_intro_t;
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRO_ESTABLISHED) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRO_ESTABLISHED)
struct hs_cell_intro_established_st { struct trn_cell_intro_established_st {
struct cell_extension_st *extensions; struct trn_cell_extension_st *extensions;
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct hs_cell_intro_established_st hs_cell_intro_established_t; typedef struct trn_cell_intro_established_st trn_cell_intro_established_t;
/** Return a newly allocated hs_cell_establish_intro with all elements /** Return a newly allocated trn_cell_establish_intro with all
* set to zero. * elements set to zero.
*/ */
hs_cell_establish_intro_t *hs_cell_establish_intro_new(void); trn_cell_establish_intro_t *trn_cell_establish_intro_new(void);
/** Release all storage held by the hs_cell_establish_intro in /** Release all storage held by the trn_cell_establish_intro in
* 'victim'. (Do nothing if 'victim' is NULL.) * 'victim'. (Do nothing if 'victim' is NULL.)
*/ */
void hs_cell_establish_intro_free(hs_cell_establish_intro_t *victim); void trn_cell_establish_intro_free(trn_cell_establish_intro_t *victim);
/** Try to parse a hs_cell_establish_intro from the buffer in 'input', /** Try to parse a trn_cell_establish_intro from the buffer in
* using up to 'len_in' bytes from the input buffer. On success, * 'input', using up to 'len_in' bytes from the input buffer. On
* return the number of bytes consumed and set *output to the newly * success, return the number of bytes consumed and set *output to the
* allocated hs_cell_establish_intro_t. On failure, return -2 if the * newly allocated trn_cell_establish_intro_t. On failure, return -2
* input appears truncated, and -1 if the input is otherwise invalid. * if the input appears truncated, and -1 if the input is otherwise
* invalid.
*/ */
ssize_t hs_cell_establish_intro_parse(hs_cell_establish_intro_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_establish_intro_parse(trn_cell_establish_intro_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* hs_cell_establish_intro in 'obj'. On failure, return a negative * trn_cell_establish_intro in 'obj'. On failure, return a negative
* value. Note that this value may be an overestimate, and can even be * value. Note that this value may be an overestimate, and can even be
* an underestimate for certain unencodeable objects. * an underestimate for certain unencodeable objects.
*/ */
ssize_t hs_cell_establish_intro_encoded_len(const hs_cell_establish_intro_t *obj); ssize_t trn_cell_establish_intro_encoded_len(const trn_cell_establish_intro_t *obj);
/** Try to encode the hs_cell_establish_intro from 'input' into the /** Try to encode the trn_cell_establish_intro from 'input' into the
* buffer at 'output', using up to 'avail' bytes of the output buffer. * buffer at 'output', using up to 'avail' bytes of the output buffer.
* On success, return the number of bytes used. On failure, return -2 * On success, return the number of bytes used. On failure, return -2
* if the buffer was not long enough, and -1 if the input was invalid. * if the buffer was not long enough, and -1 if the input was invalid.
*/ */
ssize_t hs_cell_establish_intro_encode(uint8_t *output, size_t avail, const hs_cell_establish_intro_t *input); ssize_t trn_cell_establish_intro_encode(uint8_t *output, size_t avail, const trn_cell_establish_intro_t *input);
/** Check whether the internal state of the hs_cell_establish_intro in /** Check whether the internal state of the trn_cell_establish_intro
* 'obj' is consistent. Return NULL if it is, and a short message if * in 'obj' is consistent. Return NULL if it is, and a short message
* it is not. * if it is not.
*/ */
const char *hs_cell_establish_intro_check(const hs_cell_establish_intro_t *obj); const char *trn_cell_establish_intro_check(const trn_cell_establish_intro_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int hs_cell_establish_intro_clear_errors(hs_cell_establish_intro_t *obj); int trn_cell_establish_intro_clear_errors(trn_cell_establish_intro_t *obj);
/** Return the position for start_cell when we parsed this object /** Return the position for start_cell when we parsed this object
*/ */
const uint8_t * hs_cell_establish_intro_get_start_cell(const hs_cell_establish_intro_t *inp); const uint8_t * trn_cell_establish_intro_get_start_cell(const trn_cell_establish_intro_t *inp);
/** Return the value of the auth_key_type field of the /** Return the value of the auth_key_type field of the
* hs_cell_establish_intro_t in 'inp' * trn_cell_establish_intro_t in 'inp'
*/ */
uint8_t hs_cell_establish_intro_get_auth_key_type(const hs_cell_establish_intro_t *inp); uint8_t trn_cell_establish_intro_get_auth_key_type(const trn_cell_establish_intro_t *inp);
/** Set the value of the auth_key_type field of the /** Set the value of the auth_key_type field of the
* hs_cell_establish_intro_t in 'inp' to 'val'. Return 0 on success; * trn_cell_establish_intro_t in 'inp' to 'val'. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_establish_intro_set_auth_key_type(hs_cell_establish_intro_t *inp, uint8_t val); int trn_cell_establish_intro_set_auth_key_type(trn_cell_establish_intro_t *inp, uint8_t val);
/** Return the value of the auth_key_len field of the /** Return the value of the auth_key_len field of the
* hs_cell_establish_intro_t in 'inp' * trn_cell_establish_intro_t in 'inp'
*/ */
uint16_t hs_cell_establish_intro_get_auth_key_len(const hs_cell_establish_intro_t *inp); uint16_t trn_cell_establish_intro_get_auth_key_len(const trn_cell_establish_intro_t *inp);
/** Set the value of the auth_key_len field of the /** Set the value of the auth_key_len field of the
* hs_cell_establish_intro_t in 'inp' to 'val'. Return 0 on success; * trn_cell_establish_intro_t in 'inp' to 'val'. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_establish_intro_set_auth_key_len(hs_cell_establish_intro_t *inp, uint16_t val); int trn_cell_establish_intro_set_auth_key_len(trn_cell_establish_intro_t *inp, uint16_t val);
/** Return the length of the dynamic array holding the auth_key field /** Return the length of the dynamic array holding the auth_key field
* of the hs_cell_establish_intro_t in 'inp'. * of the trn_cell_establish_intro_t in 'inp'.
*/ */
size_t hs_cell_establish_intro_getlen_auth_key(const hs_cell_establish_intro_t *inp); size_t trn_cell_establish_intro_getlen_auth_key(const trn_cell_establish_intro_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* auth_key of the hs_cell_establish_intro_t in 'inp'. * auth_key of the trn_cell_establish_intro_t in 'inp'.
*/ */
uint8_t hs_cell_establish_intro_get_auth_key(hs_cell_establish_intro_t *inp, size_t idx); uint8_t trn_cell_establish_intro_get_auth_key(trn_cell_establish_intro_t *inp, size_t idx);
/** As hs_cell_establish_intro_get_auth_key, but take and return a /** As trn_cell_establish_intro_get_auth_key, but take and return a
* const pointer * const pointer
*/ */
uint8_t hs_cell_establish_intro_getconst_auth_key(const hs_cell_establish_intro_t *inp, size_t idx); uint8_t trn_cell_establish_intro_getconst_auth_key(const trn_cell_establish_intro_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* auth_key of the hs_cell_establish_intro_t in 'inp', so that it will * auth_key of the trn_cell_establish_intro_t in 'inp', so that it
* hold the value 'elt'. * will hold the value 'elt'.
*/ */
int hs_cell_establish_intro_set_auth_key(hs_cell_establish_intro_t *inp, size_t idx, uint8_t elt); int trn_cell_establish_intro_set_auth_key(trn_cell_establish_intro_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field auth_key of /** Append a new element 'elt' to the dynamic array field auth_key of
* the hs_cell_establish_intro_t in 'inp'. * the trn_cell_establish_intro_t in 'inp'.
*/ */
int hs_cell_establish_intro_add_auth_key(hs_cell_establish_intro_t *inp, uint8_t elt); int trn_cell_establish_intro_add_auth_key(trn_cell_establish_intro_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field auth_key of /** Return a pointer to the variable-length array field auth_key of
* 'inp'. * 'inp'.
*/ */
uint8_t * hs_cell_establish_intro_getarray_auth_key(hs_cell_establish_intro_t *inp); uint8_t * trn_cell_establish_intro_getarray_auth_key(trn_cell_establish_intro_t *inp);
/** As hs_cell_establish_intro_get_auth_key, but take and return a /** As trn_cell_establish_intro_get_auth_key, but take and return a
* const pointer * const pointer
*/ */
const uint8_t * hs_cell_establish_intro_getconstarray_auth_key(const hs_cell_establish_intro_t *inp); const uint8_t * trn_cell_establish_intro_getconstarray_auth_key(const trn_cell_establish_intro_t *inp);
/** Change the length of the variable-length array field auth_key of /** Change the length of the variable-length array field auth_key of
* 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_establish_intro_setlen_auth_key(hs_cell_establish_intro_t *inp, size_t newlen); int trn_cell_establish_intro_setlen_auth_key(trn_cell_establish_intro_t *inp, size_t newlen);
/** Return the value of the extensions field of the /** Return the value of the extensions field of the
* hs_cell_establish_intro_t in 'inp' * trn_cell_establish_intro_t in 'inp'
*/ */
struct cell_extension_st * hs_cell_establish_intro_get_extensions(hs_cell_establish_intro_t *inp); struct trn_cell_extension_st * trn_cell_establish_intro_get_extensions(trn_cell_establish_intro_t *inp);
/** As hs_cell_establish_intro_get_extensions, but take and return a /** As trn_cell_establish_intro_get_extensions, but take and return a
* const pointer * const pointer
*/ */
const struct cell_extension_st * hs_cell_establish_intro_getconst_extensions(const hs_cell_establish_intro_t *inp); const struct trn_cell_extension_st * trn_cell_establish_intro_getconst_extensions(const trn_cell_establish_intro_t *inp);
/** Set the value of the extensions field of the /** Set the value of the extensions field of the
* hs_cell_establish_intro_t in 'inp' to 'val'. Free the old value if * trn_cell_establish_intro_t in 'inp' to 'val'. Free the old value if
* any. Steals the referenceto 'val'.Return 0 on success; return -1 * any. Steals the referenceto 'val'.Return 0 on success; return -1
* and set the error code on 'inp' on failure. * and set the error code on 'inp' on failure.
*/ */
int hs_cell_establish_intro_set_extensions(hs_cell_establish_intro_t *inp, struct cell_extension_st *val); int trn_cell_establish_intro_set_extensions(trn_cell_establish_intro_t *inp, struct trn_cell_extension_st *val);
/** As hs_cell_establish_intro_set_extensions, but does not free the /** As trn_cell_establish_intro_set_extensions, but does not free the
* previous value. * previous value.
*/ */
int hs_cell_establish_intro_set0_extensions(hs_cell_establish_intro_t *inp, struct cell_extension_st *val); int trn_cell_establish_intro_set0_extensions(trn_cell_establish_intro_t *inp, struct trn_cell_extension_st *val);
/** Return the position for end_mac_fields when we parsed this object /** Return the position for end_mac_fields when we parsed this object
*/ */
const uint8_t * hs_cell_establish_intro_get_end_mac_fields(const hs_cell_establish_intro_t *inp); const uint8_t * trn_cell_establish_intro_get_end_mac_fields(const trn_cell_establish_intro_t *inp);
/** Return the (constant) length of the array holding the /** Return the (constant) length of the array holding the
* handshake_mac field of the hs_cell_establish_intro_t in 'inp'. * handshake_mac field of the trn_cell_establish_intro_t in 'inp'.
*/ */
size_t hs_cell_establish_intro_getlen_handshake_mac(const hs_cell_establish_intro_t *inp); size_t trn_cell_establish_intro_getlen_handshake_mac(const trn_cell_establish_intro_t *inp);
/** Return the element at position 'idx' of the fixed array field /** Return the element at position 'idx' of the fixed array field
* handshake_mac of the hs_cell_establish_intro_t in 'inp'. * handshake_mac of the trn_cell_establish_intro_t in 'inp'.
*/ */
uint8_t hs_cell_establish_intro_get_handshake_mac(hs_cell_establish_intro_t *inp, size_t idx); uint8_t trn_cell_establish_intro_get_handshake_mac(trn_cell_establish_intro_t *inp, size_t idx);
/** As hs_cell_establish_intro_get_handshake_mac, but take and return /** As trn_cell_establish_intro_get_handshake_mac, but take and return
* a const pointer * a const pointer
*/ */
uint8_t hs_cell_establish_intro_getconst_handshake_mac(const hs_cell_establish_intro_t *inp, size_t idx); uint8_t trn_cell_establish_intro_getconst_handshake_mac(const trn_cell_establish_intro_t *inp, size_t idx);
/** Change the element at position 'idx' of the fixed array field /** Change the element at position 'idx' of the fixed array field
* handshake_mac of the hs_cell_establish_intro_t in 'inp', so that it * handshake_mac of the trn_cell_establish_intro_t in 'inp', so that
* will hold the value 'elt'. * it will hold the value 'elt'.
*/ */
int hs_cell_establish_intro_set_handshake_mac(hs_cell_establish_intro_t *inp, size_t idx, uint8_t elt); int trn_cell_establish_intro_set_handshake_mac(trn_cell_establish_intro_t *inp, size_t idx, uint8_t elt);
/** Return a pointer to the TRUNNEL_SHA3_256_LEN-element array field /** Return a pointer to the TRUNNEL_SHA3_256_LEN-element array field
* handshake_mac of 'inp'. * handshake_mac of 'inp'.
*/ */
uint8_t * hs_cell_establish_intro_getarray_handshake_mac(hs_cell_establish_intro_t *inp); uint8_t * trn_cell_establish_intro_getarray_handshake_mac(trn_cell_establish_intro_t *inp);
/** As hs_cell_establish_intro_get_handshake_mac, but take and return /** As trn_cell_establish_intro_get_handshake_mac, but take and return
* a const pointer * a const pointer
*/ */
const uint8_t * hs_cell_establish_intro_getconstarray_handshake_mac(const hs_cell_establish_intro_t *inp); const uint8_t * trn_cell_establish_intro_getconstarray_handshake_mac(const trn_cell_establish_intro_t *inp);
/** Return the position for end_sig_fields when we parsed this object /** Return the position for end_sig_fields when we parsed this object
*/ */
const uint8_t * hs_cell_establish_intro_get_end_sig_fields(const hs_cell_establish_intro_t *inp); const uint8_t * trn_cell_establish_intro_get_end_sig_fields(const trn_cell_establish_intro_t *inp);
/** Return the value of the sig_len field of the /** Return the value of the sig_len field of the
* hs_cell_establish_intro_t in 'inp' * trn_cell_establish_intro_t in 'inp'
*/ */
uint16_t hs_cell_establish_intro_get_sig_len(const hs_cell_establish_intro_t *inp); uint16_t trn_cell_establish_intro_get_sig_len(const trn_cell_establish_intro_t *inp);
/** Set the value of the sig_len field of the /** Set the value of the sig_len field of the
* hs_cell_establish_intro_t in 'inp' to 'val'. Return 0 on success; * trn_cell_establish_intro_t in 'inp' to 'val'. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_establish_intro_set_sig_len(hs_cell_establish_intro_t *inp, uint16_t val); int trn_cell_establish_intro_set_sig_len(trn_cell_establish_intro_t *inp, uint16_t val);
/** Return the length of the dynamic array holding the sig field of /** Return the length of the dynamic array holding the sig field of
* the hs_cell_establish_intro_t in 'inp'. * the trn_cell_establish_intro_t in 'inp'.
*/ */
size_t hs_cell_establish_intro_getlen_sig(const hs_cell_establish_intro_t *inp); size_t trn_cell_establish_intro_getlen_sig(const trn_cell_establish_intro_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* sig of the hs_cell_establish_intro_t in 'inp'. * sig of the trn_cell_establish_intro_t in 'inp'.
*/ */
uint8_t hs_cell_establish_intro_get_sig(hs_cell_establish_intro_t *inp, size_t idx); uint8_t trn_cell_establish_intro_get_sig(trn_cell_establish_intro_t *inp, size_t idx);
/** As hs_cell_establish_intro_get_sig, but take and return a const /** As trn_cell_establish_intro_get_sig, but take and return a const
* pointer * pointer
*/ */
uint8_t hs_cell_establish_intro_getconst_sig(const hs_cell_establish_intro_t *inp, size_t idx); uint8_t trn_cell_establish_intro_getconst_sig(const trn_cell_establish_intro_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* sig of the hs_cell_establish_intro_t in 'inp', so that it will hold * sig of the trn_cell_establish_intro_t in 'inp', so that it will
* the value 'elt'. * hold the value 'elt'.
*/ */
int hs_cell_establish_intro_set_sig(hs_cell_establish_intro_t *inp, size_t idx, uint8_t elt); int trn_cell_establish_intro_set_sig(trn_cell_establish_intro_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field sig of the /** Append a new element 'elt' to the dynamic array field sig of the
* hs_cell_establish_intro_t in 'inp'. * trn_cell_establish_intro_t in 'inp'.
*/ */
int hs_cell_establish_intro_add_sig(hs_cell_establish_intro_t *inp, uint8_t elt); int trn_cell_establish_intro_add_sig(trn_cell_establish_intro_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field sig of 'inp'. /** Return a pointer to the variable-length array field sig of 'inp'.
*/ */
uint8_t * hs_cell_establish_intro_getarray_sig(hs_cell_establish_intro_t *inp); uint8_t * trn_cell_establish_intro_getarray_sig(trn_cell_establish_intro_t *inp);
/** As hs_cell_establish_intro_get_sig, but take and return a const /** As trn_cell_establish_intro_get_sig, but take and return a const
* pointer * pointer
*/ */
const uint8_t * hs_cell_establish_intro_getconstarray_sig(const hs_cell_establish_intro_t *inp); const uint8_t * trn_cell_establish_intro_getconstarray_sig(const trn_cell_establish_intro_t *inp);
/** Change the length of the variable-length array field sig of 'inp' /** Change the length of the variable-length array field sig of 'inp'
* to 'newlen'.Fill extra elements with 0. Return 0 on success; return * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
* -1 and set the error code on 'inp' on failure. * -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_establish_intro_setlen_sig(hs_cell_establish_intro_t *inp, size_t newlen); int trn_cell_establish_intro_setlen_sig(trn_cell_establish_intro_t *inp, size_t newlen);
/** Return a newly allocated hs_cell_intro_established with all /** Return a newly allocated trn_cell_intro_established with all
* elements set to zero. * elements set to zero.
*/ */
hs_cell_intro_established_t *hs_cell_intro_established_new(void); trn_cell_intro_established_t *trn_cell_intro_established_new(void);
/** Release all storage held by the hs_cell_intro_established in /** Release all storage held by the trn_cell_intro_established in
* 'victim'. (Do nothing if 'victim' is NULL.) * 'victim'. (Do nothing if 'victim' is NULL.)
*/ */
void hs_cell_intro_established_free(hs_cell_intro_established_t *victim); void trn_cell_intro_established_free(trn_cell_intro_established_t *victim);
/** Try to parse a hs_cell_intro_established from the buffer in /** Try to parse a trn_cell_intro_established from the buffer in
* 'input', using up to 'len_in' bytes from the input buffer. On * 'input', using up to 'len_in' bytes from the input buffer. On
* success, return the number of bytes consumed and set *output to the * success, return the number of bytes consumed and set *output to the
* newly allocated hs_cell_intro_established_t. On failure, return -2 * newly allocated trn_cell_intro_established_t. On failure, return -2
* if the input appears truncated, and -1 if the input is otherwise * if the input appears truncated, and -1 if the input is otherwise
* invalid. * invalid.
*/ */
ssize_t hs_cell_intro_established_parse(hs_cell_intro_established_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_intro_established_parse(trn_cell_intro_established_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* hs_cell_intro_established in 'obj'. On failure, return a negative * trn_cell_intro_established in 'obj'. On failure, return a negative
* value. Note that this value may be an overestimate, and can even be * value. Note that this value may be an overestimate, and can even be
* an underestimate for certain unencodeable objects. * an underestimate for certain unencodeable objects.
*/ */
ssize_t hs_cell_intro_established_encoded_len(const hs_cell_intro_established_t *obj); ssize_t trn_cell_intro_established_encoded_len(const trn_cell_intro_established_t *obj);
/** Try to encode the hs_cell_intro_established from 'input' into the /** Try to encode the trn_cell_intro_established from 'input' into the
* buffer at 'output', using up to 'avail' bytes of the output buffer. * buffer at 'output', using up to 'avail' bytes of the output buffer.
* On success, return the number of bytes used. On failure, return -2 * On success, return the number of bytes used. On failure, return -2
* if the buffer was not long enough, and -1 if the input was invalid. * if the buffer was not long enough, and -1 if the input was invalid.
*/ */
ssize_t hs_cell_intro_established_encode(uint8_t *output, size_t avail, const hs_cell_intro_established_t *input); ssize_t trn_cell_intro_established_encode(uint8_t *output, size_t avail, const trn_cell_intro_established_t *input);
/** Check whether the internal state of the hs_cell_intro_established /** Check whether the internal state of the trn_cell_intro_established
* in 'obj' is consistent. Return NULL if it is, and a short message * in 'obj' is consistent. Return NULL if it is, and a short message
* if it is not. * if it is not.
*/ */
const char *hs_cell_intro_established_check(const hs_cell_intro_established_t *obj); const char *trn_cell_intro_established_check(const trn_cell_intro_established_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int hs_cell_intro_established_clear_errors(hs_cell_intro_established_t *obj); int trn_cell_intro_established_clear_errors(trn_cell_intro_established_t *obj);
/** Return the value of the extensions field of the /** Return the value of the extensions field of the
* hs_cell_intro_established_t in 'inp' * trn_cell_intro_established_t in 'inp'
*/ */
struct cell_extension_st * hs_cell_intro_established_get_extensions(hs_cell_intro_established_t *inp); struct trn_cell_extension_st * trn_cell_intro_established_get_extensions(trn_cell_intro_established_t *inp);
/** As hs_cell_intro_established_get_extensions, but take and return a /** As trn_cell_intro_established_get_extensions, but take and return
* const pointer * a const pointer
*/ */
const struct cell_extension_st * hs_cell_intro_established_getconst_extensions(const hs_cell_intro_established_t *inp); const struct trn_cell_extension_st * trn_cell_intro_established_getconst_extensions(const trn_cell_intro_established_t *inp);
/** Set the value of the extensions field of the /** Set the value of the extensions field of the
* hs_cell_intro_established_t in 'inp' to 'val'. Free the old value * trn_cell_intro_established_t in 'inp' to 'val'. Free the old value
* if any. Steals the referenceto 'val'.Return 0 on success; return -1 * if any. Steals the referenceto 'val'.Return 0 on success; return -1
* and set the error code on 'inp' on failure. * and set the error code on 'inp' on failure.
*/ */
int hs_cell_intro_established_set_extensions(hs_cell_intro_established_t *inp, struct cell_extension_st *val); int trn_cell_intro_established_set_extensions(trn_cell_intro_established_t *inp, struct trn_cell_extension_st *val);
/** As hs_cell_intro_established_set_extensions, but does not free the /** As trn_cell_intro_established_set_extensions, but does not free
* previous value. * the previous value.
*/ */
int hs_cell_intro_established_set0_extensions(hs_cell_intro_established_t *inp, struct cell_extension_st *val); int trn_cell_intro_established_set0_extensions(trn_cell_intro_established_t *inp, struct trn_cell_extension_st *val);
#endif #endif

View File

@ -4,12 +4,12 @@
* specified in proposal 224 section 3.1. * specified in proposal 224 section 3.1.
*/ */
extern struct cell_extension; extern struct trn_cell_extension;
const TRUNNEL_SHA3_256_LEN = 32; const TRUNNEL_SHA3_256_LEN = 32;
/* ESTABLISH_INTRO payload. See details in section 3.1.1 */ /* ESTABLISH_INTRO payload. See details in section 3.1.1 */
struct hs_cell_establish_intro { struct trn_cell_establish_intro {
/* Indicate the start of the handshake authentication data. */ /* Indicate the start of the handshake authentication data. */
@ptr start_cell; @ptr start_cell;
@ -19,7 +19,7 @@ struct hs_cell_establish_intro {
u8 auth_key[auth_key_len]; u8 auth_key[auth_key_len];
/* Extension(s). Reserved fields. */ /* Extension(s). Reserved fields. */
struct cell_extension extensions; struct trn_cell_extension extensions;
@ptr end_mac_fields; @ptr end_mac_fields;
/* Handshake MAC. */ /* Handshake MAC. */
@ -35,7 +35,7 @@ struct hs_cell_establish_intro {
/* INTRO_ESTABLISHED payload which is an acknowledge of the ESTABLISH_INTRO /* INTRO_ESTABLISHED payload which is an acknowledge of the ESTABLISH_INTRO
* cell. For legacy node, this payload is empty so the following only applies * cell. For legacy node, this payload is empty so the following only applies
* to version >= 3. */ * to version >= 3. */
struct hs_cell_intro_established { struct trn_cell_intro_established {
/* Extension(s). Reserved fields. */ /* Extension(s). Reserved fields. */
struct cell_extension extensions; struct trn_cell_extension extensions;
}; };

File diff suppressed because it is too large Load Diff

View File

@ -8,34 +8,34 @@
#include <stdint.h> #include <stdint.h>
#include "trunnel.h" #include "trunnel.h"
struct cell_extension_st; struct trn_cell_extension_st;
struct link_specifier_st; struct link_specifier_st;
#define TRUNNEL_SHA1_LEN 20 #define TRUNNEL_SHA1_LEN 20
#define TRUNNEL_REND_COOKIE_LEN 20 #define TRUNNEL_REND_COOKIE_LEN 20
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE1) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE1)
struct hs_cell_introduce1_st { struct trn_cell_introduce1_st {
uint8_t legacy_key_id[TRUNNEL_SHA1_LEN]; uint8_t legacy_key_id[TRUNNEL_SHA1_LEN];
uint8_t auth_key_type; uint8_t auth_key_type;
uint16_t auth_key_len; uint16_t auth_key_len;
TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key; TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key;
struct cell_extension_st *extensions; struct trn_cell_extension_st *extensions;
TRUNNEL_DYNARRAY_HEAD(, uint8_t) encrypted; TRUNNEL_DYNARRAY_HEAD(, uint8_t) encrypted;
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct hs_cell_introduce1_st hs_cell_introduce1_t; typedef struct trn_cell_introduce1_st trn_cell_introduce1_t;
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE_ACK) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE_ACK)
struct hs_cell_introduce_ack_st { struct trn_cell_introduce_ack_st {
uint16_t status; uint16_t status;
struct cell_extension_st *extensions; struct trn_cell_extension_st *extensions;
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct hs_cell_introduce_ack_st hs_cell_introduce_ack_t; typedef struct trn_cell_introduce_ack_st trn_cell_introduce_ack_t;
#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE_ENCRYPTED) #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE_ENCRYPTED)
struct hs_cell_introduce_encrypted_st { struct trn_cell_introduce_encrypted_st {
uint8_t rend_cookie[TRUNNEL_REND_COOKIE_LEN]; uint8_t rend_cookie[TRUNNEL_REND_COOKIE_LEN];
struct cell_extension_st *extensions; struct trn_cell_extension_st *extensions;
uint8_t onion_key_type; uint8_t onion_key_type;
uint16_t onion_key_len; uint16_t onion_key_len;
TRUNNEL_DYNARRAY_HEAD(, uint8_t) onion_key; TRUNNEL_DYNARRAY_HEAD(, uint8_t) onion_key;
@ -45,449 +45,449 @@ struct hs_cell_introduce_encrypted_st {
uint8_t trunnel_error_code_; uint8_t trunnel_error_code_;
}; };
#endif #endif
typedef struct hs_cell_introduce_encrypted_st hs_cell_introduce_encrypted_t; typedef struct trn_cell_introduce_encrypted_st trn_cell_introduce_encrypted_t;
/** Return a newly allocated hs_cell_introduce1 with all elements set /** Return a newly allocated trn_cell_introduce1 with all elements set
* to zero. * to zero.
*/ */
hs_cell_introduce1_t *hs_cell_introduce1_new(void); trn_cell_introduce1_t *trn_cell_introduce1_new(void);
/** Release all storage held by the hs_cell_introduce1 in 'victim'. /** Release all storage held by the trn_cell_introduce1 in 'victim'.
* (Do nothing if 'victim' is NULL.) * (Do nothing if 'victim' is NULL.)
*/ */
void hs_cell_introduce1_free(hs_cell_introduce1_t *victim); void trn_cell_introduce1_free(trn_cell_introduce1_t *victim);
/** Try to parse a hs_cell_introduce1 from the buffer in 'input', /** Try to parse a trn_cell_introduce1 from the buffer in 'input',
* using up to 'len_in' bytes from the input buffer. On success, * using up to 'len_in' bytes from the input buffer. On success,
* return the number of bytes consumed and set *output to the newly * return the number of bytes consumed and set *output to the newly
* allocated hs_cell_introduce1_t. On failure, return -2 if the input * allocated trn_cell_introduce1_t. On failure, return -2 if the input
* appears truncated, and -1 if the input is otherwise invalid. * appears truncated, and -1 if the input is otherwise invalid.
*/ */
ssize_t hs_cell_introduce1_parse(hs_cell_introduce1_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_introduce1_parse(trn_cell_introduce1_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* hs_cell_introduce1 in 'obj'. On failure, return a negative value. * trn_cell_introduce1 in 'obj'. On failure, return a negative value.
* Note that this value may be an overestimate, and can even be an * Note that this value may be an overestimate, and can even be an
* underestimate for certain unencodeable objects. * underestimate for certain unencodeable objects.
*/ */
ssize_t hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj); ssize_t trn_cell_introduce1_encoded_len(const trn_cell_introduce1_t *obj);
/** Try to encode the hs_cell_introduce1 from 'input' into the buffer /** Try to encode the trn_cell_introduce1 from 'input' into the buffer
* at 'output', using up to 'avail' bytes of the output buffer. On * at 'output', using up to 'avail' bytes of the output buffer. On
* success, return the number of bytes used. On failure, return -2 if * success, return the number of bytes used. On failure, return -2 if
* the buffer was not long enough, and -1 if the input was invalid. * the buffer was not long enough, and -1 if the input was invalid.
*/ */
ssize_t hs_cell_introduce1_encode(uint8_t *output, size_t avail, const hs_cell_introduce1_t *input); ssize_t trn_cell_introduce1_encode(uint8_t *output, size_t avail, const trn_cell_introduce1_t *input);
/** Check whether the internal state of the hs_cell_introduce1 in /** Check whether the internal state of the trn_cell_introduce1 in
* 'obj' is consistent. Return NULL if it is, and a short message if * 'obj' is consistent. Return NULL if it is, and a short message if
* it is not. * it is not.
*/ */
const char *hs_cell_introduce1_check(const hs_cell_introduce1_t *obj); const char *trn_cell_introduce1_check(const trn_cell_introduce1_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int hs_cell_introduce1_clear_errors(hs_cell_introduce1_t *obj); int trn_cell_introduce1_clear_errors(trn_cell_introduce1_t *obj);
/** Return the (constant) length of the array holding the /** Return the (constant) length of the array holding the
* legacy_key_id field of the hs_cell_introduce1_t in 'inp'. * legacy_key_id field of the trn_cell_introduce1_t in 'inp'.
*/ */
size_t hs_cell_introduce1_getlen_legacy_key_id(const hs_cell_introduce1_t *inp); size_t trn_cell_introduce1_getlen_legacy_key_id(const trn_cell_introduce1_t *inp);
/** Return the element at position 'idx' of the fixed array field /** Return the element at position 'idx' of the fixed array field
* legacy_key_id of the hs_cell_introduce1_t in 'inp'. * legacy_key_id of the trn_cell_introduce1_t in 'inp'.
*/ */
uint8_t hs_cell_introduce1_get_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx); uint8_t trn_cell_introduce1_get_legacy_key_id(trn_cell_introduce1_t *inp, size_t idx);
/** As hs_cell_introduce1_get_legacy_key_id, but take and return a /** As trn_cell_introduce1_get_legacy_key_id, but take and return a
* const pointer * const pointer
*/ */
uint8_t hs_cell_introduce1_getconst_legacy_key_id(const hs_cell_introduce1_t *inp, size_t idx); uint8_t trn_cell_introduce1_getconst_legacy_key_id(const trn_cell_introduce1_t *inp, size_t idx);
/** Change the element at position 'idx' of the fixed array field /** Change the element at position 'idx' of the fixed array field
* legacy_key_id of the hs_cell_introduce1_t in 'inp', so that it will * legacy_key_id of the trn_cell_introduce1_t in 'inp', so that it
* hold the value 'elt'. * will hold the value 'elt'.
*/ */
int hs_cell_introduce1_set_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt); int trn_cell_introduce1_set_legacy_key_id(trn_cell_introduce1_t *inp, size_t idx, uint8_t elt);
/** Return a pointer to the TRUNNEL_SHA1_LEN-element array field /** Return a pointer to the TRUNNEL_SHA1_LEN-element array field
* legacy_key_id of 'inp'. * legacy_key_id of 'inp'.
*/ */
uint8_t * hs_cell_introduce1_getarray_legacy_key_id(hs_cell_introduce1_t *inp); uint8_t * trn_cell_introduce1_getarray_legacy_key_id(trn_cell_introduce1_t *inp);
/** As hs_cell_introduce1_get_legacy_key_id, but take and return a /** As trn_cell_introduce1_get_legacy_key_id, but take and return a
* const pointer * const pointer
*/ */
const uint8_t * hs_cell_introduce1_getconstarray_legacy_key_id(const hs_cell_introduce1_t *inp); const uint8_t * trn_cell_introduce1_getconstarray_legacy_key_id(const trn_cell_introduce1_t *inp);
/** Return the value of the auth_key_type field of the /** Return the value of the auth_key_type field of the
* hs_cell_introduce1_t in 'inp' * trn_cell_introduce1_t in 'inp'
*/ */
uint8_t hs_cell_introduce1_get_auth_key_type(const hs_cell_introduce1_t *inp); uint8_t trn_cell_introduce1_get_auth_key_type(const trn_cell_introduce1_t *inp);
/** Set the value of the auth_key_type field of the /** Set the value of the auth_key_type field of the
* hs_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; return * trn_cell_introduce1_t in 'inp' to 'val'. Return 0 on success;
* -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce1_set_auth_key_type(hs_cell_introduce1_t *inp, uint8_t val); int trn_cell_introduce1_set_auth_key_type(trn_cell_introduce1_t *inp, uint8_t val);
/** Return the value of the auth_key_len field of the /** Return the value of the auth_key_len field of the
* hs_cell_introduce1_t in 'inp' * trn_cell_introduce1_t in 'inp'
*/ */
uint16_t hs_cell_introduce1_get_auth_key_len(const hs_cell_introduce1_t *inp); uint16_t trn_cell_introduce1_get_auth_key_len(const trn_cell_introduce1_t *inp);
/** Set the value of the auth_key_len field of the /** Set the value of the auth_key_len field of the
* hs_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; return * trn_cell_introduce1_t in 'inp' to 'val'. Return 0 on success;
* -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce1_set_auth_key_len(hs_cell_introduce1_t *inp, uint16_t val); int trn_cell_introduce1_set_auth_key_len(trn_cell_introduce1_t *inp, uint16_t val);
/** Return the length of the dynamic array holding the auth_key field /** Return the length of the dynamic array holding the auth_key field
* of the hs_cell_introduce1_t in 'inp'. * of the trn_cell_introduce1_t in 'inp'.
*/ */
size_t hs_cell_introduce1_getlen_auth_key(const hs_cell_introduce1_t *inp); size_t trn_cell_introduce1_getlen_auth_key(const trn_cell_introduce1_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* auth_key of the hs_cell_introduce1_t in 'inp'. * auth_key of the trn_cell_introduce1_t in 'inp'.
*/ */
uint8_t hs_cell_introduce1_get_auth_key(hs_cell_introduce1_t *inp, size_t idx); uint8_t trn_cell_introduce1_get_auth_key(trn_cell_introduce1_t *inp, size_t idx);
/** As hs_cell_introduce1_get_auth_key, but take and return a const /** As trn_cell_introduce1_get_auth_key, but take and return a const
* pointer * pointer
*/ */
uint8_t hs_cell_introduce1_getconst_auth_key(const hs_cell_introduce1_t *inp, size_t idx); uint8_t trn_cell_introduce1_getconst_auth_key(const trn_cell_introduce1_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* auth_key of the hs_cell_introduce1_t in 'inp', so that it will hold * auth_key of the trn_cell_introduce1_t in 'inp', so that it will
* the value 'elt'. * hold the value 'elt'.
*/ */
int hs_cell_introduce1_set_auth_key(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt); int trn_cell_introduce1_set_auth_key(trn_cell_introduce1_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field auth_key of /** Append a new element 'elt' to the dynamic array field auth_key of
* the hs_cell_introduce1_t in 'inp'. * the trn_cell_introduce1_t in 'inp'.
*/ */
int hs_cell_introduce1_add_auth_key(hs_cell_introduce1_t *inp, uint8_t elt); int trn_cell_introduce1_add_auth_key(trn_cell_introduce1_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field auth_key of /** Return a pointer to the variable-length array field auth_key of
* 'inp'. * 'inp'.
*/ */
uint8_t * hs_cell_introduce1_getarray_auth_key(hs_cell_introduce1_t *inp); uint8_t * trn_cell_introduce1_getarray_auth_key(trn_cell_introduce1_t *inp);
/** As hs_cell_introduce1_get_auth_key, but take and return a const /** As trn_cell_introduce1_get_auth_key, but take and return a const
* pointer * pointer
*/ */
const uint8_t * hs_cell_introduce1_getconstarray_auth_key(const hs_cell_introduce1_t *inp); const uint8_t * trn_cell_introduce1_getconstarray_auth_key(const trn_cell_introduce1_t *inp);
/** Change the length of the variable-length array field auth_key of /** Change the length of the variable-length array field auth_key of
* 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce1_setlen_auth_key(hs_cell_introduce1_t *inp, size_t newlen); int trn_cell_introduce1_setlen_auth_key(trn_cell_introduce1_t *inp, size_t newlen);
/** Return the value of the extensions field of the /** Return the value of the extensions field of the
* hs_cell_introduce1_t in 'inp' * trn_cell_introduce1_t in 'inp'
*/ */
struct cell_extension_st * hs_cell_introduce1_get_extensions(hs_cell_introduce1_t *inp); struct trn_cell_extension_st * trn_cell_introduce1_get_extensions(trn_cell_introduce1_t *inp);
/** As hs_cell_introduce1_get_extensions, but take and return a const /** As trn_cell_introduce1_get_extensions, but take and return a const
* pointer * pointer
*/ */
const struct cell_extension_st * hs_cell_introduce1_getconst_extensions(const hs_cell_introduce1_t *inp); const struct trn_cell_extension_st * trn_cell_introduce1_getconst_extensions(const trn_cell_introduce1_t *inp);
/** Set the value of the extensions field of the hs_cell_introduce1_t /** Set the value of the extensions field of the trn_cell_introduce1_t
* in 'inp' to 'val'. Free the old value if any. Steals the * in 'inp' to 'val'. Free the old value if any. Steals the
* referenceto 'val'.Return 0 on success; return -1 and set the error * referenceto 'val'.Return 0 on success; return -1 and set the error
* code on 'inp' on failure. * code on 'inp' on failure.
*/ */
int hs_cell_introduce1_set_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val); int trn_cell_introduce1_set_extensions(trn_cell_introduce1_t *inp, struct trn_cell_extension_st *val);
/** As hs_cell_introduce1_set_extensions, but does not free the /** As trn_cell_introduce1_set_extensions, but does not free the
* previous value. * previous value.
*/ */
int hs_cell_introduce1_set0_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val); int trn_cell_introduce1_set0_extensions(trn_cell_introduce1_t *inp, struct trn_cell_extension_st *val);
/** Return the length of the dynamic array holding the encrypted field /** Return the length of the dynamic array holding the encrypted field
* of the hs_cell_introduce1_t in 'inp'. * of the trn_cell_introduce1_t in 'inp'.
*/ */
size_t hs_cell_introduce1_getlen_encrypted(const hs_cell_introduce1_t *inp); size_t trn_cell_introduce1_getlen_encrypted(const trn_cell_introduce1_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* encrypted of the hs_cell_introduce1_t in 'inp'. * encrypted of the trn_cell_introduce1_t in 'inp'.
*/ */
uint8_t hs_cell_introduce1_get_encrypted(hs_cell_introduce1_t *inp, size_t idx); uint8_t trn_cell_introduce1_get_encrypted(trn_cell_introduce1_t *inp, size_t idx);
/** As hs_cell_introduce1_get_encrypted, but take and return a const /** As trn_cell_introduce1_get_encrypted, but take and return a const
* pointer * pointer
*/ */
uint8_t hs_cell_introduce1_getconst_encrypted(const hs_cell_introduce1_t *inp, size_t idx); uint8_t trn_cell_introduce1_getconst_encrypted(const trn_cell_introduce1_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* encrypted of the hs_cell_introduce1_t in 'inp', so that it will * encrypted of the trn_cell_introduce1_t in 'inp', so that it will
* hold the value 'elt'. * hold the value 'elt'.
*/ */
int hs_cell_introduce1_set_encrypted(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt); int trn_cell_introduce1_set_encrypted(trn_cell_introduce1_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field encrypted of /** Append a new element 'elt' to the dynamic array field encrypted of
* the hs_cell_introduce1_t in 'inp'. * the trn_cell_introduce1_t in 'inp'.
*/ */
int hs_cell_introduce1_add_encrypted(hs_cell_introduce1_t *inp, uint8_t elt); int trn_cell_introduce1_add_encrypted(trn_cell_introduce1_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field encrypted of /** Return a pointer to the variable-length array field encrypted of
* 'inp'. * 'inp'.
*/ */
uint8_t * hs_cell_introduce1_getarray_encrypted(hs_cell_introduce1_t *inp); uint8_t * trn_cell_introduce1_getarray_encrypted(trn_cell_introduce1_t *inp);
/** As hs_cell_introduce1_get_encrypted, but take and return a const /** As trn_cell_introduce1_get_encrypted, but take and return a const
* pointer * pointer
*/ */
const uint8_t * hs_cell_introduce1_getconstarray_encrypted(const hs_cell_introduce1_t *inp); const uint8_t * trn_cell_introduce1_getconstarray_encrypted(const trn_cell_introduce1_t *inp);
/** Change the length of the variable-length array field encrypted of /** Change the length of the variable-length array field encrypted of
* 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce1_setlen_encrypted(hs_cell_introduce1_t *inp, size_t newlen); int trn_cell_introduce1_setlen_encrypted(trn_cell_introduce1_t *inp, size_t newlen);
/** Return a newly allocated hs_cell_introduce_ack with all elements /** Return a newly allocated trn_cell_introduce_ack with all elements
* set to zero. * set to zero.
*/ */
hs_cell_introduce_ack_t *hs_cell_introduce_ack_new(void); trn_cell_introduce_ack_t *trn_cell_introduce_ack_new(void);
/** Release all storage held by the hs_cell_introduce_ack in 'victim'. /** Release all storage held by the trn_cell_introduce_ack in
* (Do nothing if 'victim' is NULL.) * 'victim'. (Do nothing if 'victim' is NULL.)
*/ */
void hs_cell_introduce_ack_free(hs_cell_introduce_ack_t *victim); void trn_cell_introduce_ack_free(trn_cell_introduce_ack_t *victim);
/** Try to parse a hs_cell_introduce_ack from the buffer in 'input', /** Try to parse a trn_cell_introduce_ack from the buffer in 'input',
* using up to 'len_in' bytes from the input buffer. On success, * using up to 'len_in' bytes from the input buffer. On success,
* return the number of bytes consumed and set *output to the newly * return the number of bytes consumed and set *output to the newly
* allocated hs_cell_introduce_ack_t. On failure, return -2 if the * allocated trn_cell_introduce_ack_t. On failure, return -2 if the
* input appears truncated, and -1 if the input is otherwise invalid. * input appears truncated, and -1 if the input is otherwise invalid.
*/ */
ssize_t hs_cell_introduce_ack_parse(hs_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_introduce_ack_parse(trn_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* hs_cell_introduce_ack in 'obj'. On failure, return a negative * trn_cell_introduce_ack in 'obj'. On failure, return a negative
* value. Note that this value may be an overestimate, and can even be * value. Note that this value may be an overestimate, and can even be
* an underestimate for certain unencodeable objects. * an underestimate for certain unencodeable objects.
*/ */
ssize_t hs_cell_introduce_ack_encoded_len(const hs_cell_introduce_ack_t *obj); ssize_t trn_cell_introduce_ack_encoded_len(const trn_cell_introduce_ack_t *obj);
/** Try to encode the hs_cell_introduce_ack from 'input' into the /** Try to encode the trn_cell_introduce_ack from 'input' into the
* buffer at 'output', using up to 'avail' bytes of the output buffer. * buffer at 'output', using up to 'avail' bytes of the output buffer.
* On success, return the number of bytes used. On failure, return -2 * On success, return the number of bytes used. On failure, return -2
* if the buffer was not long enough, and -1 if the input was invalid. * if the buffer was not long enough, and -1 if the input was invalid.
*/ */
ssize_t hs_cell_introduce_ack_encode(uint8_t *output, size_t avail, const hs_cell_introduce_ack_t *input); ssize_t trn_cell_introduce_ack_encode(uint8_t *output, size_t avail, const trn_cell_introduce_ack_t *input);
/** Check whether the internal state of the hs_cell_introduce_ack in /** Check whether the internal state of the trn_cell_introduce_ack in
* 'obj' is consistent. Return NULL if it is, and a short message if * 'obj' is consistent. Return NULL if it is, and a short message if
* it is not. * it is not.
*/ */
const char *hs_cell_introduce_ack_check(const hs_cell_introduce_ack_t *obj); const char *trn_cell_introduce_ack_check(const trn_cell_introduce_ack_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int hs_cell_introduce_ack_clear_errors(hs_cell_introduce_ack_t *obj); int trn_cell_introduce_ack_clear_errors(trn_cell_introduce_ack_t *obj);
/** Return the value of the status field of the /** Return the value of the status field of the
* hs_cell_introduce_ack_t in 'inp' * trn_cell_introduce_ack_t in 'inp'
*/ */
uint16_t hs_cell_introduce_ack_get_status(const hs_cell_introduce_ack_t *inp); uint16_t trn_cell_introduce_ack_get_status(const trn_cell_introduce_ack_t *inp);
/** Set the value of the status field of the hs_cell_introduce_ack_t /** Set the value of the status field of the trn_cell_introduce_ack_t
* in 'inp' to 'val'. Return 0 on success; return -1 and set the error * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
* code on 'inp' on failure. * code on 'inp' on failure.
*/ */
int hs_cell_introduce_ack_set_status(hs_cell_introduce_ack_t *inp, uint16_t val); int trn_cell_introduce_ack_set_status(trn_cell_introduce_ack_t *inp, uint16_t val);
/** Return the value of the extensions field of the /** Return the value of the extensions field of the
* hs_cell_introduce_ack_t in 'inp' * trn_cell_introduce_ack_t in 'inp'
*/ */
struct cell_extension_st * hs_cell_introduce_ack_get_extensions(hs_cell_introduce_ack_t *inp); struct trn_cell_extension_st * trn_cell_introduce_ack_get_extensions(trn_cell_introduce_ack_t *inp);
/** As hs_cell_introduce_ack_get_extensions, but take and return a /** As trn_cell_introduce_ack_get_extensions, but take and return a
* const pointer * const pointer
*/ */
const struct cell_extension_st * hs_cell_introduce_ack_getconst_extensions(const hs_cell_introduce_ack_t *inp); const struct trn_cell_extension_st * trn_cell_introduce_ack_getconst_extensions(const trn_cell_introduce_ack_t *inp);
/** Set the value of the extensions field of the /** Set the value of the extensions field of the
* hs_cell_introduce_ack_t in 'inp' to 'val'. Free the old value if * trn_cell_introduce_ack_t in 'inp' to 'val'. Free the old value if
* any. Steals the referenceto 'val'.Return 0 on success; return -1 * any. Steals the referenceto 'val'.Return 0 on success; return -1
* and set the error code on 'inp' on failure. * and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_ack_set_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val); int trn_cell_introduce_ack_set_extensions(trn_cell_introduce_ack_t *inp, struct trn_cell_extension_st *val);
/** As hs_cell_introduce_ack_set_extensions, but does not free the /** As trn_cell_introduce_ack_set_extensions, but does not free the
* previous value. * previous value.
*/ */
int hs_cell_introduce_ack_set0_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val); int trn_cell_introduce_ack_set0_extensions(trn_cell_introduce_ack_t *inp, struct trn_cell_extension_st *val);
/** Return a newly allocated hs_cell_introduce_encrypted with all /** Return a newly allocated trn_cell_introduce_encrypted with all
* elements set to zero. * elements set to zero.
*/ */
hs_cell_introduce_encrypted_t *hs_cell_introduce_encrypted_new(void); trn_cell_introduce_encrypted_t *trn_cell_introduce_encrypted_new(void);
/** Release all storage held by the hs_cell_introduce_encrypted in /** Release all storage held by the trn_cell_introduce_encrypted in
* 'victim'. (Do nothing if 'victim' is NULL.) * 'victim'. (Do nothing if 'victim' is NULL.)
*/ */
void hs_cell_introduce_encrypted_free(hs_cell_introduce_encrypted_t *victim); void trn_cell_introduce_encrypted_free(trn_cell_introduce_encrypted_t *victim);
/** Try to parse a hs_cell_introduce_encrypted from the buffer in /** Try to parse a trn_cell_introduce_encrypted from the buffer in
* 'input', using up to 'len_in' bytes from the input buffer. On * 'input', using up to 'len_in' bytes from the input buffer. On
* success, return the number of bytes consumed and set *output to the * success, return the number of bytes consumed and set *output to the
* newly allocated hs_cell_introduce_encrypted_t. On failure, return * newly allocated trn_cell_introduce_encrypted_t. On failure, return
* -2 if the input appears truncated, and -1 if the input is otherwise * -2 if the input appears truncated, and -1 if the input is otherwise
* invalid. * invalid.
*/ */
ssize_t hs_cell_introduce_encrypted_parse(hs_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in); ssize_t trn_cell_introduce_encrypted_parse(trn_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in);
/** Return the number of bytes we expect to need to encode the /** Return the number of bytes we expect to need to encode the
* hs_cell_introduce_encrypted in 'obj'. On failure, return a negative * trn_cell_introduce_encrypted in 'obj'. On failure, return a
* value. Note that this value may be an overestimate, and can even be * negative value. Note that this value may be an overestimate, and
* an underestimate for certain unencodeable objects. * can even be an underestimate for certain unencodeable objects.
*/ */
ssize_t hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj); ssize_t trn_cell_introduce_encrypted_encoded_len(const trn_cell_introduce_encrypted_t *obj);
/** Try to encode the hs_cell_introduce_encrypted from 'input' into /** Try to encode the trn_cell_introduce_encrypted from 'input' into
* the buffer at 'output', using up to 'avail' bytes of the output * the buffer at 'output', using up to 'avail' bytes of the output
* buffer. On success, return the number of bytes used. On failure, * buffer. On success, return the number of bytes used. On failure,
* return -2 if the buffer was not long enough, and -1 if the input * return -2 if the buffer was not long enough, and -1 if the input
* was invalid. * was invalid.
*/ */
ssize_t hs_cell_introduce_encrypted_encode(uint8_t *output, size_t avail, const hs_cell_introduce_encrypted_t *input); ssize_t trn_cell_introduce_encrypted_encode(uint8_t *output, size_t avail, const trn_cell_introduce_encrypted_t *input);
/** Check whether the internal state of the /** Check whether the internal state of the
* hs_cell_introduce_encrypted in 'obj' is consistent. Return NULL if * trn_cell_introduce_encrypted in 'obj' is consistent. Return NULL if
* it is, and a short message if it is not. * it is, and a short message if it is not.
*/ */
const char *hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj); const char *trn_cell_introduce_encrypted_check(const trn_cell_introduce_encrypted_t *obj);
/** Clear any errors that were set on the object 'obj' by its setter /** Clear any errors that were set on the object 'obj' by its setter
* functions. Return true iff errors were cleared. * functions. Return true iff errors were cleared.
*/ */
int hs_cell_introduce_encrypted_clear_errors(hs_cell_introduce_encrypted_t *obj); int trn_cell_introduce_encrypted_clear_errors(trn_cell_introduce_encrypted_t *obj);
/** Return the (constant) length of the array holding the rend_cookie /** Return the (constant) length of the array holding the rend_cookie
* field of the hs_cell_introduce_encrypted_t in 'inp'. * field of the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
size_t hs_cell_introduce_encrypted_getlen_rend_cookie(const hs_cell_introduce_encrypted_t *inp); size_t trn_cell_introduce_encrypted_getlen_rend_cookie(const trn_cell_introduce_encrypted_t *inp);
/** Return the element at position 'idx' of the fixed array field /** Return the element at position 'idx' of the fixed array field
* rend_cookie of the hs_cell_introduce_encrypted_t in 'inp'. * rend_cookie of the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
uint8_t hs_cell_introduce_encrypted_get_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx); uint8_t trn_cell_introduce_encrypted_get_rend_cookie(trn_cell_introduce_encrypted_t *inp, size_t idx);
/** As hs_cell_introduce_encrypted_get_rend_cookie, but take and /** As trn_cell_introduce_encrypted_get_rend_cookie, but take and
* return a const pointer * return a const pointer
*/ */
uint8_t hs_cell_introduce_encrypted_getconst_rend_cookie(const hs_cell_introduce_encrypted_t *inp, size_t idx); uint8_t trn_cell_introduce_encrypted_getconst_rend_cookie(const trn_cell_introduce_encrypted_t *inp, size_t idx);
/** Change the element at position 'idx' of the fixed array field /** Change the element at position 'idx' of the fixed array field
* rend_cookie of the hs_cell_introduce_encrypted_t in 'inp', so that * rend_cookie of the trn_cell_introduce_encrypted_t in 'inp', so that
* it will hold the value 'elt'. * it will hold the value 'elt'.
*/ */
int hs_cell_introduce_encrypted_set_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt); int trn_cell_introduce_encrypted_set_rend_cookie(trn_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt);
/** Return a pointer to the TRUNNEL_REND_COOKIE_LEN-element array /** Return a pointer to the TRUNNEL_REND_COOKIE_LEN-element array
* field rend_cookie of 'inp'. * field rend_cookie of 'inp'.
*/ */
uint8_t * hs_cell_introduce_encrypted_getarray_rend_cookie(hs_cell_introduce_encrypted_t *inp); uint8_t * trn_cell_introduce_encrypted_getarray_rend_cookie(trn_cell_introduce_encrypted_t *inp);
/** As hs_cell_introduce_encrypted_get_rend_cookie, but take and /** As trn_cell_introduce_encrypted_get_rend_cookie, but take and
* return a const pointer * return a const pointer
*/ */
const uint8_t * hs_cell_introduce_encrypted_getconstarray_rend_cookie(const hs_cell_introduce_encrypted_t *inp); const uint8_t * trn_cell_introduce_encrypted_getconstarray_rend_cookie(const trn_cell_introduce_encrypted_t *inp);
/** Return the value of the extensions field of the /** Return the value of the extensions field of the
* hs_cell_introduce_encrypted_t in 'inp' * trn_cell_introduce_encrypted_t in 'inp'
*/ */
struct cell_extension_st * hs_cell_introduce_encrypted_get_extensions(hs_cell_introduce_encrypted_t *inp); struct trn_cell_extension_st * trn_cell_introduce_encrypted_get_extensions(trn_cell_introduce_encrypted_t *inp);
/** As hs_cell_introduce_encrypted_get_extensions, but take and return /** As trn_cell_introduce_encrypted_get_extensions, but take and
* a const pointer * return a const pointer
*/ */
const struct cell_extension_st * hs_cell_introduce_encrypted_getconst_extensions(const hs_cell_introduce_encrypted_t *inp); const struct trn_cell_extension_st * trn_cell_introduce_encrypted_getconst_extensions(const trn_cell_introduce_encrypted_t *inp);
/** Set the value of the extensions field of the /** Set the value of the extensions field of the
* hs_cell_introduce_encrypted_t in 'inp' to 'val'. Free the old value * trn_cell_introduce_encrypted_t in 'inp' to 'val'. Free the old
* if any. Steals the referenceto 'val'.Return 0 on success; return -1 * value if any. Steals the referenceto 'val'.Return 0 on success;
* and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_set_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val); int trn_cell_introduce_encrypted_set_extensions(trn_cell_introduce_encrypted_t *inp, struct trn_cell_extension_st *val);
/** As hs_cell_introduce_encrypted_set_extensions, but does not free /** As trn_cell_introduce_encrypted_set_extensions, but does not free
* the previous value. * the previous value.
*/ */
int hs_cell_introduce_encrypted_set0_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val); int trn_cell_introduce_encrypted_set0_extensions(trn_cell_introduce_encrypted_t *inp, struct trn_cell_extension_st *val);
/** Return the value of the onion_key_type field of the /** Return the value of the onion_key_type field of the
* hs_cell_introduce_encrypted_t in 'inp' * trn_cell_introduce_encrypted_t in 'inp'
*/ */
uint8_t hs_cell_introduce_encrypted_get_onion_key_type(const hs_cell_introduce_encrypted_t *inp); uint8_t trn_cell_introduce_encrypted_get_onion_key_type(const trn_cell_introduce_encrypted_t *inp);
/** Set the value of the onion_key_type field of the /** Set the value of the onion_key_type field of the
* hs_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on * trn_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on
* success; return -1 and set the error code on 'inp' on failure. * success; return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_set_onion_key_type(hs_cell_introduce_encrypted_t *inp, uint8_t val); int trn_cell_introduce_encrypted_set_onion_key_type(trn_cell_introduce_encrypted_t *inp, uint8_t val);
/** Return the value of the onion_key_len field of the /** Return the value of the onion_key_len field of the
* hs_cell_introduce_encrypted_t in 'inp' * trn_cell_introduce_encrypted_t in 'inp'
*/ */
uint16_t hs_cell_introduce_encrypted_get_onion_key_len(const hs_cell_introduce_encrypted_t *inp); uint16_t trn_cell_introduce_encrypted_get_onion_key_len(const trn_cell_introduce_encrypted_t *inp);
/** Set the value of the onion_key_len field of the /** Set the value of the onion_key_len field of the
* hs_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on * trn_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on
* success; return -1 and set the error code on 'inp' on failure. * success; return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_set_onion_key_len(hs_cell_introduce_encrypted_t *inp, uint16_t val); int trn_cell_introduce_encrypted_set_onion_key_len(trn_cell_introduce_encrypted_t *inp, uint16_t val);
/** Return the length of the dynamic array holding the onion_key field /** Return the length of the dynamic array holding the onion_key field
* of the hs_cell_introduce_encrypted_t in 'inp'. * of the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
size_t hs_cell_introduce_encrypted_getlen_onion_key(const hs_cell_introduce_encrypted_t *inp); size_t trn_cell_introduce_encrypted_getlen_onion_key(const trn_cell_introduce_encrypted_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* onion_key of the hs_cell_introduce_encrypted_t in 'inp'. * onion_key of the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
uint8_t hs_cell_introduce_encrypted_get_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx); uint8_t trn_cell_introduce_encrypted_get_onion_key(trn_cell_introduce_encrypted_t *inp, size_t idx);
/** As hs_cell_introduce_encrypted_get_onion_key, but take and return /** As trn_cell_introduce_encrypted_get_onion_key, but take and return
* a const pointer * a const pointer
*/ */
uint8_t hs_cell_introduce_encrypted_getconst_onion_key(const hs_cell_introduce_encrypted_t *inp, size_t idx); uint8_t trn_cell_introduce_encrypted_getconst_onion_key(const trn_cell_introduce_encrypted_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* onion_key of the hs_cell_introduce_encrypted_t in 'inp', so that it * onion_key of the trn_cell_introduce_encrypted_t in 'inp', so that
* will hold the value 'elt'. * it will hold the value 'elt'.
*/ */
int hs_cell_introduce_encrypted_set_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt); int trn_cell_introduce_encrypted_set_onion_key(trn_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field onion_key of /** Append a new element 'elt' to the dynamic array field onion_key of
* the hs_cell_introduce_encrypted_t in 'inp'. * the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
int hs_cell_introduce_encrypted_add_onion_key(hs_cell_introduce_encrypted_t *inp, uint8_t elt); int trn_cell_introduce_encrypted_add_onion_key(trn_cell_introduce_encrypted_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field onion_key of /** Return a pointer to the variable-length array field onion_key of
* 'inp'. * 'inp'.
*/ */
uint8_t * hs_cell_introduce_encrypted_getarray_onion_key(hs_cell_introduce_encrypted_t *inp); uint8_t * trn_cell_introduce_encrypted_getarray_onion_key(trn_cell_introduce_encrypted_t *inp);
/** As hs_cell_introduce_encrypted_get_onion_key, but take and return /** As trn_cell_introduce_encrypted_get_onion_key, but take and return
* a const pointer * a const pointer
*/ */
const uint8_t * hs_cell_introduce_encrypted_getconstarray_onion_key(const hs_cell_introduce_encrypted_t *inp); const uint8_t * trn_cell_introduce_encrypted_getconstarray_onion_key(const trn_cell_introduce_encrypted_t *inp);
/** Change the length of the variable-length array field onion_key of /** Change the length of the variable-length array field onion_key of
* 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
* return -1 and set the error code on 'inp' on failure. * return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_setlen_onion_key(hs_cell_introduce_encrypted_t *inp, size_t newlen); int trn_cell_introduce_encrypted_setlen_onion_key(trn_cell_introduce_encrypted_t *inp, size_t newlen);
/** Return the value of the nspec field of the /** Return the value of the nspec field of the
* hs_cell_introduce_encrypted_t in 'inp' * trn_cell_introduce_encrypted_t in 'inp'
*/ */
uint8_t hs_cell_introduce_encrypted_get_nspec(const hs_cell_introduce_encrypted_t *inp); uint8_t trn_cell_introduce_encrypted_get_nspec(const trn_cell_introduce_encrypted_t *inp);
/** Set the value of the nspec field of the /** Set the value of the nspec field of the
* hs_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on * trn_cell_introduce_encrypted_t in 'inp' to 'val'. Return 0 on
* success; return -1 and set the error code on 'inp' on failure. * success; return -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_set_nspec(hs_cell_introduce_encrypted_t *inp, uint8_t val); int trn_cell_introduce_encrypted_set_nspec(trn_cell_introduce_encrypted_t *inp, uint8_t val);
/** Return the length of the dynamic array holding the nspecs field of /** Return the length of the dynamic array holding the nspecs field of
* the hs_cell_introduce_encrypted_t in 'inp'. * the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
size_t hs_cell_introduce_encrypted_getlen_nspecs(const hs_cell_introduce_encrypted_t *inp); size_t trn_cell_introduce_encrypted_getlen_nspecs(const trn_cell_introduce_encrypted_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* nspecs of the hs_cell_introduce_encrypted_t in 'inp'. * nspecs of the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
struct link_specifier_st * hs_cell_introduce_encrypted_get_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx); struct link_specifier_st * trn_cell_introduce_encrypted_get_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx);
/** As hs_cell_introduce_encrypted_get_nspecs, but take and return a /** As trn_cell_introduce_encrypted_get_nspecs, but take and return a
* const pointer * const pointer
*/ */
const struct link_specifier_st * hs_cell_introduce_encrypted_getconst_nspecs(const hs_cell_introduce_encrypted_t *inp, size_t idx); const struct link_specifier_st * trn_cell_introduce_encrypted_getconst_nspecs(const trn_cell_introduce_encrypted_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* nspecs of the hs_cell_introduce_encrypted_t in 'inp', so that it * nspecs of the trn_cell_introduce_encrypted_t in 'inp', so that it
* will hold the value 'elt'. Free the previous value, if any. * will hold the value 'elt'. Free the previous value, if any.
*/ */
int hs_cell_introduce_encrypted_set_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt); int trn_cell_introduce_encrypted_set_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt);
/** As hs_cell_introduce_encrypted_set_nspecs, but does not free the /** As trn_cell_introduce_encrypted_set_nspecs, but does not free the
* previous value. * previous value.
*/ */
int hs_cell_introduce_encrypted_set0_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt); int trn_cell_introduce_encrypted_set0_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt);
/** Append a new element 'elt' to the dynamic array field nspecs of /** Append a new element 'elt' to the dynamic array field nspecs of
* the hs_cell_introduce_encrypted_t in 'inp'. * the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
int hs_cell_introduce_encrypted_add_nspecs(hs_cell_introduce_encrypted_t *inp, struct link_specifier_st * elt); int trn_cell_introduce_encrypted_add_nspecs(trn_cell_introduce_encrypted_t *inp, struct link_specifier_st * elt);
/** Return a pointer to the variable-length array field nspecs of /** Return a pointer to the variable-length array field nspecs of
* 'inp'. * 'inp'.
*/ */
struct link_specifier_st * * hs_cell_introduce_encrypted_getarray_nspecs(hs_cell_introduce_encrypted_t *inp); struct link_specifier_st * * trn_cell_introduce_encrypted_getarray_nspecs(trn_cell_introduce_encrypted_t *inp);
/** As hs_cell_introduce_encrypted_get_nspecs, but take and return a /** As trn_cell_introduce_encrypted_get_nspecs, but take and return a
* const pointer * const pointer
*/ */
const struct link_specifier_st * const * hs_cell_introduce_encrypted_getconstarray_nspecs(const hs_cell_introduce_encrypted_t *inp); const struct link_specifier_st * const * trn_cell_introduce_encrypted_getconstarray_nspecs(const trn_cell_introduce_encrypted_t *inp);
/** Change the length of the variable-length array field nspecs of /** Change the length of the variable-length array field nspecs of
* 'inp' to 'newlen'.Fill extra elements with NULL; free removed * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
* elements. Return 0 on success; return -1 and set the error code on * elements. Return 0 on success; return -1 and set the error code on
* 'inp' on failure. * 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_setlen_nspecs(hs_cell_introduce_encrypted_t *inp, size_t newlen); int trn_cell_introduce_encrypted_setlen_nspecs(trn_cell_introduce_encrypted_t *inp, size_t newlen);
/** Return the length of the dynamic array holding the pad field of /** Return the length of the dynamic array holding the pad field of
* the hs_cell_introduce_encrypted_t in 'inp'. * the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
size_t hs_cell_introduce_encrypted_getlen_pad(const hs_cell_introduce_encrypted_t *inp); size_t trn_cell_introduce_encrypted_getlen_pad(const trn_cell_introduce_encrypted_t *inp);
/** Return the element at position 'idx' of the dynamic array field /** Return the element at position 'idx' of the dynamic array field
* pad of the hs_cell_introduce_encrypted_t in 'inp'. * pad of the trn_cell_introduce_encrypted_t in 'inp'.
*/ */
uint8_t hs_cell_introduce_encrypted_get_pad(hs_cell_introduce_encrypted_t *inp, size_t idx); uint8_t trn_cell_introduce_encrypted_get_pad(trn_cell_introduce_encrypted_t *inp, size_t idx);
/** As hs_cell_introduce_encrypted_get_pad, but take and return a /** As trn_cell_introduce_encrypted_get_pad, but take and return a
* const pointer * const pointer
*/ */
uint8_t hs_cell_introduce_encrypted_getconst_pad(const hs_cell_introduce_encrypted_t *inp, size_t idx); uint8_t trn_cell_introduce_encrypted_getconst_pad(const trn_cell_introduce_encrypted_t *inp, size_t idx);
/** Change the element at position 'idx' of the dynamic array field /** Change the element at position 'idx' of the dynamic array field
* pad of the hs_cell_introduce_encrypted_t in 'inp', so that it will * pad of the trn_cell_introduce_encrypted_t in 'inp', so that it will
* hold the value 'elt'. * hold the value 'elt'.
*/ */
int hs_cell_introduce_encrypted_set_pad(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt); int trn_cell_introduce_encrypted_set_pad(trn_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt);
/** Append a new element 'elt' to the dynamic array field pad of the /** Append a new element 'elt' to the dynamic array field pad of the
* hs_cell_introduce_encrypted_t in 'inp'. * trn_cell_introduce_encrypted_t in 'inp'.
*/ */
int hs_cell_introduce_encrypted_add_pad(hs_cell_introduce_encrypted_t *inp, uint8_t elt); int trn_cell_introduce_encrypted_add_pad(trn_cell_introduce_encrypted_t *inp, uint8_t elt);
/** Return a pointer to the variable-length array field pad of 'inp'. /** Return a pointer to the variable-length array field pad of 'inp'.
*/ */
uint8_t * hs_cell_introduce_encrypted_getarray_pad(hs_cell_introduce_encrypted_t *inp); uint8_t * trn_cell_introduce_encrypted_getarray_pad(trn_cell_introduce_encrypted_t *inp);
/** As hs_cell_introduce_encrypted_get_pad, but take and return a /** As trn_cell_introduce_encrypted_get_pad, but take and return a
* const pointer * const pointer
*/ */
const uint8_t * hs_cell_introduce_encrypted_getconstarray_pad(const hs_cell_introduce_encrypted_t *inp); const uint8_t * trn_cell_introduce_encrypted_getconstarray_pad(const trn_cell_introduce_encrypted_t *inp);
/** Change the length of the variable-length array field pad of 'inp' /** Change the length of the variable-length array field pad of 'inp'
* to 'newlen'.Fill extra elements with 0. Return 0 on success; return * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
* -1 and set the error code on 'inp' on failure. * -1 and set the error code on 'inp' on failure.
*/ */
int hs_cell_introduce_encrypted_setlen_pad(hs_cell_introduce_encrypted_t *inp, size_t newlen); int trn_cell_introduce_encrypted_setlen_pad(trn_cell_introduce_encrypted_t *inp, size_t newlen);
#endif #endif

View File

@ -5,7 +5,7 @@
*/ */
/* From cell_common.trunnel. */ /* From cell_common.trunnel. */
extern struct cell_extension; extern struct trn_cell_extension;
/* From ed25519_cert.trunnel. */ /* From ed25519_cert.trunnel. */
extern struct link_specifier; extern struct link_specifier;
@ -13,7 +13,7 @@ const TRUNNEL_SHA1_LEN = 20;
const TRUNNEL_REND_COOKIE_LEN = 20; const TRUNNEL_REND_COOKIE_LEN = 20;
/* INTRODUCE1 payload. See details in section 3.2.1. */ /* INTRODUCE1 payload. See details in section 3.2.1. */
struct hs_cell_introduce1 { struct trn_cell_introduce1 {
/* Always zeroed. MUST be checked explicitely by the caller. */ /* Always zeroed. MUST be checked explicitely by the caller. */
u8 legacy_key_id[TRUNNEL_SHA1_LEN]; u8 legacy_key_id[TRUNNEL_SHA1_LEN];
@ -23,28 +23,28 @@ struct hs_cell_introduce1 {
u8 auth_key[auth_key_len]; u8 auth_key[auth_key_len];
/* Extension(s). Reserved fields. */ /* Extension(s). Reserved fields. */
struct cell_extension extensions; struct trn_cell_extension extensions;
/* Variable length, up to the end of cell. */ /* Variable length, up to the end of cell. */
u8 encrypted[]; u8 encrypted[];
}; };
/* INTRODUCE_ACK payload. See details in section 3.2.2. */ /* INTRODUCE_ACK payload. See details in section 3.2.2. */
struct hs_cell_introduce_ack { struct trn_cell_introduce_ack {
/* Status of introduction. */ /* Status of introduction. */
u16 status IN [0x0000, 0x0001, 0x0002]; u16 status IN [0x0000, 0x0001, 0x0002];
/* Extension(s). Reserved fields. */ /* Extension(s). Reserved fields. */
struct cell_extension extensions; struct trn_cell_extension extensions;
}; };
/* Encrypted section of the INTRODUCE1/INTRODUCE2 cell. */ /* Encrypted section of the INTRODUCE1/INTRODUCE2 cell. */
struct hs_cell_introduce_encrypted { struct trn_cell_introduce_encrypted {
/* Rendezvous cookie. */ /* Rendezvous cookie. */
u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN]; u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN];
/* Extension(s). Reserved fields. */ /* Extension(s). Reserved fields. */
struct cell_extension extensions; struct trn_cell_extension extensions;
/* Onion key material. */ /* Onion key material. */
u8 onion_key_type IN [0x01]; u8 onion_key_type IN [0x01];