From 6bacc3c7a88509043613d3bc29534c0ecf8803b1 Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 11 Apr 2017 13:46:41 -0400 Subject: [PATCH] hs: Change trunnel prop224 cell's namespace One of the goals of this change is to have trunnel API/ABI being more explicit so we namespace them with "trn_*". Furthermore, we can now create hs_cells.[ch] without having to confuse it with trunnel which used to be "hs_cell_*" before that change. Here are the perl line that were used for this rename: perl -i -pe 's/cell_extension/trn_cell_extension/g;' src/*/*.[ch] perl -i -pe 's/cell_extension/trn_cell_extension/g;' src/trunnel/hs/*.trunnel perl -i -pe 's/hs_cell_/trn_cell_/g;' src/*/*.[ch] perl -i -pe 's/hs_cell_/trn_cell_/g;' src/trunnel/hs/*.trunnel And then "./scripts/codegen/run_trunnel.sh" with trunnel commit id 613fb1b98e58504e2b84ef56b1602b6380629043. Fixes #21919 Signed-off-by: David Goulet --- src/ext/trunnel/trunnel.c | 2 +- src/or/hs_intropoint.c | 90 ++--- src/or/hs_intropoint.h | 4 +- src/or/hs_service.c | 42 +- src/or/hs_service.h | 4 +- src/test/test_hs_intropoint.c | 102 ++--- src/test/test_hs_service.c | 14 +- src/trunnel/hs/cell_common.c | 179 ++++----- src/trunnel/hs/cell_common.h | 201 +++++----- src/trunnel/hs/cell_common.trunnel | 6 +- src/trunnel/hs/cell_establish_intro.c | 240 +++++------ src/trunnel/hs/cell_establish_intro.h | 237 +++++------ src/trunnel/hs/cell_establish_intro.trunnel | 10 +- src/trunnel/hs/cell_introduce1.c | 398 +++++++++---------- src/trunnel/hs/cell_introduce1.h | 416 ++++++++++---------- src/trunnel/hs/cell_introduce1.trunnel | 14 +- 16 files changed, 983 insertions(+), 976 deletions(-) diff --git a/src/ext/trunnel/trunnel.c b/src/ext/trunnel/trunnel.c index e98a2e0b66..6a42417241 100644 --- a/src/ext/trunnel/trunnel.c +++ b/src/ext/trunnel/trunnel.c @@ -31,7 +31,7 @@ # define IS_LITTLE_ENDIAN # endif #else -# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(OpenBSD) +# if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) # include # else # include diff --git a/src/or/hs_intropoint.c b/src/or/hs_intropoint.c index a7282aba8f..b0515bebdb 100644 --- a/src/or/hs_intropoint.c +++ b/src/or/hs_intropoint.c @@ -43,16 +43,16 @@ get_auth_key_from_cell(ed25519_public_key_t *auth_key_out, switch (cell_type) { case RELAY_COMMAND_ESTABLISH_INTRO: { - const hs_cell_establish_intro_t *c_cell = cell; - key_array = hs_cell_establish_intro_getconstarray_auth_key(c_cell); - auth_key_len = hs_cell_establish_intro_getlen_auth_key(c_cell); + const trn_cell_establish_intro_t *c_cell = cell; + key_array = trn_cell_establish_intro_getconstarray_auth_key(c_cell); + auth_key_len = trn_cell_establish_intro_getlen_auth_key(c_cell); break; } case RELAY_COMMAND_INTRODUCE1: { - const hs_cell_introduce1_t *c_cell = cell; - key_array = hs_cell_introduce1_getconstarray_auth_key(cell); - auth_key_len = hs_cell_introduce1_getlen_auth_key(c_cell); + const trn_cell_introduce1_t *c_cell = cell; + key_array = trn_cell_introduce1_getconstarray_auth_key(cell); + auth_key_len = trn_cell_introduce1_getlen_auth_key(c_cell); break; } default: @@ -68,7 +68,7 @@ get_auth_key_from_cell(ed25519_public_key_t *auth_key_out, /** We received an ESTABLISH_INTRO cell. Verify its signature and MAC, * given circuit_key_material. Return 0 on success else -1 on error. */ 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, 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 * EXTRA safety, we check both the size of the array and the length which * must be the same. Safety first!*/ - if (hs_cell_establish_intro_getlen_auth_key(cell) != ED25519_PUBKEY_LEN || - hs_cell_establish_intro_get_auth_key_len(cell) != ED25519_PUBKEY_LEN) { + if (trn_cell_establish_intro_getlen_auth_key(cell) != ED25519_PUBKEY_LEN || + trn_cell_establish_intro_get_auth_key_len(cell) != ED25519_PUBKEY_LEN) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "ESTABLISH_INTRO auth key length is invalid"); return -1; @@ -94,13 +94,13 @@ verify_establish_intro_cell(const hs_cell_establish_intro_t *cell, /* Verify the sig */ { 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, * we check both the size of the array and the length which must be the * same. Safety first!*/ - if (hs_cell_establish_intro_getlen_sig(cell) != sizeof(sig_struct.sig) || - hs_cell_establish_intro_get_sig_len(cell) != sizeof(sig_struct.sig)) { + if (trn_cell_establish_intro_getlen_sig(cell) != sizeof(sig_struct.sig) || + trn_cell_establish_intro_get_sig_len(cell) != sizeof(sig_struct.sig)) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "ESTABLISH_INTRO sig len is invalid"); return -1; @@ -147,21 +147,21 @@ hs_intro_send_intro_established_cell,(or_circuit_t *circ)) int ret; uint8_t *encoded_cell = NULL; ssize_t encoded_len, result_len; - hs_cell_intro_established_t *cell; - cell_extension_t *ext; + trn_cell_intro_established_t *cell; + trn_cell_extension_t *ext; tor_assert(circ); /* Build the cell payload. */ - cell = hs_cell_intro_established_new(); - ext = cell_extension_new(); - cell_extension_set_num(ext, 0); - hs_cell_intro_established_set_extensions(cell, ext); + cell = trn_cell_intro_established_new(); + ext = trn_cell_extension_new(); + trn_cell_extension_set_num(ext, 0); + trn_cell_intro_established_set_extensions(cell, ext); /* 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); 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); tor_assert(encoded_len == result_len); @@ -170,7 +170,7 @@ hs_intro_send_intro_established_cell,(or_circuit_t *circ)) (char *) encoded_cell, encoded_len, NULL); /* 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); return ret; } @@ -180,7 +180,7 @@ hs_intro_send_intro_established_cell,(or_circuit_t *circ)) * establish an intro point. */ static int 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 */ ed25519_public_key_t auth_key; @@ -210,7 +210,7 @@ handle_establish_intro(or_circuit_t *circ, const uint8_t *request, size_t request_len) { 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(request); @@ -224,7 +224,7 @@ handle_establish_intro(or_circuit_t *circ, const uint8_t *request, } /* 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); if (parsing_result < 0) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, @@ -259,7 +259,7 @@ handle_establish_intro(or_circuit_t *circ, const uint8_t *request, circuit_mark_for_close(TO_CIRCUIT(circ), END_CIRC_REASON_TORPROTOCOL); done: - hs_cell_establish_intro_free(parsed_cell); + trn_cell_establish_intro_free(parsed_cell); return retval; } @@ -339,28 +339,28 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status) int ret = -1; uint8_t *encoded_cell = NULL; ssize_t encoded_len, result_len; - hs_cell_introduce_ack_t *cell; - cell_extension_t *ext; + trn_cell_introduce_ack_t *cell; + trn_cell_extension_t *ext; tor_assert(circ); /* Setup the INTRODUCE_ACK cell. We have no extensions so the N_EXTENSIONS * field is set to 0 by default with a new object. */ - cell = hs_cell_introduce_ack_new(); - ret = hs_cell_introduce_ack_set_status(cell, status); + cell = trn_cell_introduce_ack_new(); + ret = trn_cell_introduce_ack_set_status(cell, status); /* We have no cell extensions in an INTRODUCE_ACK cell. */ - ext = cell_extension_new(); - cell_extension_set_num(ext, 0); - hs_cell_introduce_ack_set_extensions(cell, ext); + ext = trn_cell_extension_new(); + trn_cell_extension_set_num(ext, 0); + trn_cell_introduce_ack_set_extensions(cell, ext); /* 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 * code that is not known by the trunnel ABI. */ tor_assert(ret == 0); /* 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); 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); ret = relay_send_command_from_edge(CONTROL_CELL_ID, TO_CIRCUIT(circ), @@ -368,7 +368,7 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status) (char *) encoded_cell, encoded_len, NULL); /* 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); return ret; } @@ -376,7 +376,7 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status) /* Validate a parsed INTRODUCE1 cell. Return 0 if valid or else a * negative value for an invalid cell that should be NACKed. */ 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; const uint8_t *legacy_key_id; @@ -385,29 +385,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 * 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 = hs_cell_introduce1_getconstarray_legacy_key_id(cell); + legacy_key_id_len = trn_cell_introduce1_getlen_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))) { goto invalid; } /* The auth key of an INTRODUCE1 should be of type ed25519 thus leading to a * 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) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "Rejecting invalid INTRODUCE1 cell auth key type. " "Responding with NACK."); goto invalid; } - if (hs_cell_introduce1_get_auth_key_len(cell) != ED25519_PUBKEY_LEN || - hs_cell_introduce1_getlen_auth_key(cell) != ED25519_PUBKEY_LEN) { + if (trn_cell_introduce1_get_auth_key_len(cell) != ED25519_PUBKEY_LEN || + trn_cell_introduce1_getlen_auth_key(cell) != ED25519_PUBKEY_LEN) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, "Rejecting invalid INTRODUCE1 cell auth key length. " "Responding with NACK."); 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, "Rejecting invalid INTRODUCE1 cell encrypted length. " "Responding with NACK."); @@ -430,7 +430,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request, { int ret = -1; 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; tor_assert(client_circ); @@ -439,7 +439,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 * which we'll use the authentication key to find the service introduction * 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); if (cell_size < 0) { log_fn(LOG_PROTOCOL_WARN, LD_PROTOCOL, @@ -505,7 +505,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request, circuit_mark_for_close(TO_CIRCUIT(client_circ), END_CIRC_REASON_INTERNAL); } done: - hs_cell_introduce1_free(parsed_cell); + trn_cell_introduce1_free(parsed_cell); return ret; } diff --git a/src/or/hs_intropoint.h b/src/or/hs_intropoint.h index 3a84a48dd8..163ed810e7 100644 --- a/src/or/hs_intropoint.h +++ b/src/or/hs_intropoint.h @@ -41,7 +41,7 @@ int hs_intro_circuit_is_suitable_for_establish_intro(const or_circuit_t *circ); #include "hs/cell_introduce1.h" 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, 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 handle_introduce1(or_circuit_t *client_circ, 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); #endif /* HS_INTROPOINT_PRIVATE */ diff --git a/src/or/hs_service.c b/src/or/hs_service.c index 52de2bfa9d..71939e236b 100644 --- a/src/or/hs_service.c +++ b/src/or/hs_service.c @@ -27,7 +27,7 @@ * bytes written, or a negative integer if there was an error. */ ssize_t 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; @@ -35,31 +35,31 @@ get_establish_intro_payload(uint8_t *buf_out, size_t buf_out_len, 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); return bytes_used; } /* Set the cell extensions of cell. */ 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. */ - cell_extensions->num = 0; /* It's already zeroed, but be explicit. */ - hs_cell_establish_intro_set_extensions(cell, cell_extensions); + trn_cell_extensions->num = 0; /* It's already zeroed, but be explicit. */ + trn_cell_establish_intro_set_extensions(cell, trn_cell_extensions); } /** Given the circuit handshake info in circuit_key_material, create and * 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 * caller to free it. */ -hs_cell_establish_intro_t * +trn_cell_establish_intro_t * generate_establish_intro_cell(const uint8_t *circuit_key_material, size_t circuit_key_material_len) { - hs_cell_establish_intro_t *cell = NULL; + trn_cell_establish_intro_t *cell = NULL; ssize_t encoded_len; log_warn(LD_GENERAL, @@ -72,31 +72,31 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material, goto err; } - cell = hs_cell_establish_intro_new(); + cell = trn_cell_establish_intro_new(); /* 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 */ /* Must also set byte-length of AUTH_KEY to match */ int auth_key_len = ED25519_PUBKEY_LEN; - hs_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_set_auth_key_len(cell, auth_key_len); + trn_cell_establish_intro_setlen_auth_key(cell, auth_key_len); /* 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); /* No cell extensions needed */ - set_cell_extensions(cell); + set_trn_cell_extensions(cell); /* Set signature size. We need to do this up here, because _encode() needs it and we need to call _encode() to calculate the MAC and signature. */ int sig_len = ED25519_SIG_LEN; - hs_cell_establish_intro_set_sig_len(cell, sig_len); - hs_cell_establish_intro_setlen_sig(cell, sig_len); + trn_cell_establish_intro_set_sig_len(cell, sig_len); + trn_cell_establish_intro_setlen_sig(cell, sig_len); /* 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 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), cell); 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)); /* Write the MAC to the cell */ 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)); } @@ -137,7 +137,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material, uint8_t cell_bytes_tmp[RELAY_PAYLOAD_SIZE] = {0}; 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), cell); 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 */ - 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); } @@ -166,7 +166,7 @@ generate_establish_intro_cell(const uint8_t *circuit_key_material, return cell; err: - hs_cell_establish_intro_free(cell); + trn_cell_establish_intro_free(cell); return NULL; } diff --git a/src/or/hs_service.h b/src/or/hs_service.h index 1405b26cc8..3302592762 100644 --- a/src/or/hs_service.h +++ b/src/or/hs_service.h @@ -16,12 +16,12 @@ * hs_service.o ends up with no symbols in libor.a which makes clang throw a * 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, size_t circuit_key_material_len); ssize_t 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 */ diff --git a/src/test/test_hs_intropoint.c b/src/test/test_hs_intropoint.c index 2de2d957a2..6e68e2c867 100644 --- a/src/test/test_hs_intropoint.c +++ b/src/test/test_hs_intropoint.c @@ -69,10 +69,10 @@ helper_create_intro_circuit(void) return circ; } -static hs_cell_introduce1_t * +static trn_cell_introduce1_t * helper_create_introduce1_cell(void) { - hs_cell_introduce1_t *cell = NULL; + trn_cell_introduce1_t *cell = NULL; ed25519_keypair_t auth_key_kp; /* Generate the auth_key of the cell. */ @@ -80,39 +80,39 @@ helper_create_introduce1_cell(void) goto err; } - cell = hs_cell_introduce1_new(); + cell = trn_cell_introduce1_new(); tt_assert(cell); /* Set the auth key. */ { 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_cell_introduce1_set_auth_key_len(cell, auth_key_len); - hs_cell_introduce1_setlen_auth_key(cell, auth_key_len); - uint8_t *auth_key_ptr = hs_cell_introduce1_getarray_auth_key(cell); + trn_cell_introduce1_set_auth_key_len(cell, auth_key_len); + trn_cell_introduce1_setlen_auth_key(cell, auth_key_len); + uint8_t *auth_key_ptr = trn_cell_introduce1_getarray_auth_key(cell); memcpy(auth_key_ptr, auth_key_kp.pubkey.pubkey, auth_key_len); } /* Set the cell extentions to none. */ { - cell_extension_t *ext = cell_extension_new(); - cell_extension_set_num(ext, 0); - hs_cell_introduce1_set_extensions(cell, ext); + trn_cell_extension_t *ext = trn_cell_extension_new(); + trn_cell_extension_set_num(ext, 0); + trn_cell_introduce1_set_extensions(cell, ext); } /* Set the encrypted section to some data. */ { size_t enc_len = 128; - hs_cell_introduce1_setlen_encrypted(cell, enc_len); - uint8_t *enc_ptr = hs_cell_introduce1_getarray_encrypted(cell); + trn_cell_introduce1_setlen_encrypted(cell, enc_len); + uint8_t *enc_ptr = trn_cell_introduce1_getarray_encrypted(cell); memset(enc_ptr, 'a', enc_len); } return cell; err: done: - hs_cell_introduce1_free(cell); + trn_cell_introduce1_free(cell); return NULL; } @@ -122,7 +122,7 @@ static void test_establish_intro_wrong_purpose(void *arg) { 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);; uint8_t cell_body[RELAY_PAYLOAD_SIZE]; ssize_t cell_len = 0; @@ -154,7 +154,7 @@ test_establish_intro_wrong_purpose(void *arg) tt_int_op(retval, ==, -1); done: - hs_cell_establish_intro_free(establish_intro_cell); + trn_cell_establish_intro_free(establish_intro_cell); circuit_free(TO_CIRCUIT(intro_circ)); } @@ -198,7 +198,7 @@ static void test_establish_intro_wrong_keytype2(void *arg) { 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);; uint8_t cell_body[RELAY_PAYLOAD_SIZE]; ssize_t cell_len = 0; @@ -230,7 +230,7 @@ test_establish_intro_wrong_keytype2(void *arg) tt_int_op(retval, ==, -1); done: - hs_cell_establish_intro_free(establish_intro_cell); + trn_cell_establish_intro_free(establish_intro_cell); circuit_free(TO_CIRCUIT(intro_circ)); } @@ -239,7 +239,7 @@ static void test_establish_intro_wrong_mac(void *arg) { 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);; uint8_t cell_body[RELAY_PAYLOAD_SIZE]; ssize_t cell_len = 0; @@ -258,7 +258,7 @@ test_establish_intro_wrong_mac(void *arg) tt_assert(establish_intro_cell); /* Mangle one byte of the MAC. */ 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]++; /* 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); tt_int_op(retval, OP_EQ, 0); 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); /* Encode payload so we can sign it. */ 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); /* And write the signature to the cell */ 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); /* Re-encode with the new signature. */ 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); done: - hs_cell_establish_intro_free(establish_intro_cell); + trn_cell_establish_intro_free(establish_intro_cell); circuit_free(TO_CIRCUIT(intro_circ)); } @@ -309,7 +309,7 @@ static void test_establish_intro_wrong_auth_key_len(void *arg) { 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);; uint8_t cell_body[RELAY_PAYLOAD_SIZE]; ssize_t cell_len = 0; @@ -328,9 +328,9 @@ test_establish_intro_wrong_auth_key_len(void *arg) sizeof(circuit_key_material)); tt_assert(establish_intro_cell); /* 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); - hs_cell_establish_intro_setlen_auth_key(establish_intro_cell, + trn_cell_establish_intro_setlen_auth_key(establish_intro_cell, bad_auth_key_len); cell_len = get_establish_intro_payload(cell_body, sizeof(cell_body), establish_intro_cell); @@ -344,7 +344,7 @@ test_establish_intro_wrong_auth_key_len(void *arg) tt_int_op(retval, ==, -1); done: - hs_cell_establish_intro_free(establish_intro_cell); + trn_cell_establish_intro_free(establish_intro_cell); circuit_free(TO_CIRCUIT(intro_circ)); } @@ -354,7 +354,7 @@ static void test_establish_intro_wrong_sig_len(void *arg) { 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);; uint8_t cell_body[RELAY_PAYLOAD_SIZE]; ssize_t cell_len = 0; @@ -373,8 +373,8 @@ test_establish_intro_wrong_sig_len(void *arg) sizeof(circuit_key_material)); tt_assert(establish_intro_cell); /* Mangle the signature length. */ - hs_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_set_sig_len(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), establish_intro_cell); tt_int_op(cell_len, >, 0); @@ -387,7 +387,7 @@ test_establish_intro_wrong_sig_len(void *arg) tt_int_op(retval, ==, -1); done: - hs_cell_establish_intro_free(establish_intro_cell); + trn_cell_establish_intro_free(establish_intro_cell); circuit_free(TO_CIRCUIT(intro_circ)); } @@ -397,7 +397,7 @@ static void test_establish_intro_wrong_sig(void *arg) { 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);; uint8_t cell_body[RELAY_PAYLOAD_SIZE]; ssize_t cell_len = 0; @@ -429,17 +429,17 @@ test_establish_intro_wrong_sig(void *arg) tt_int_op(retval, ==, -1); done: - hs_cell_establish_intro_free(establish_intro_cell); + trn_cell_establish_intro_free(establish_intro_cell); circuit_free(TO_CIRCUIT(intro_circ)); } /* Helper function: Send a well-formed v3 ESTABLISH_INTRO cell to * intro_circ. Return the cell. */ -static hs_cell_establish_intro_t * +static trn_cell_establish_intro_t * helper_establish_intro_v3(or_circuit_t *intro_circ) { 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]; ssize_t cell_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; 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; crypto_pk_t *legacy_auth_key = NULL; @@ -580,7 +580,7 @@ test_intro_point_registration(void *arg) crypto_pk_free(legacy_auth_key); circuit_free(TO_CIRCUIT(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. */ the_hs_circuitmap = get_hs_circuitmap(); @@ -674,7 +674,7 @@ static void test_introduce1_validation(void *arg) { int ret; - hs_cell_introduce1_t *cell = NULL; + trn_cell_introduce1_t *cell = NULL; (void) arg; @@ -714,25 +714,25 @@ test_introduce1_validation(void *arg) ret = validate_introduce1_parsed_cell(cell); tt_int_op(ret, OP_EQ, 0); /* 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); tt_int_op(ret, OP_EQ, -1); /* 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); tt_int_op(ret, OP_EQ, 0); /* Empty encrypted section. */ - hs_cell_introduce1_setlen_encrypted(cell, 0); + trn_cell_introduce1_setlen_encrypted(cell, 0); ret = validate_introduce1_parsed_cell(cell); tt_int_op(ret, OP_EQ, -1); /* 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); tt_int_op(ret, OP_EQ, 0); done: - hs_cell_introduce1_free(cell); + trn_cell_introduce1_free(cell); } static void @@ -740,7 +740,7 @@ test_received_introduce1_handling(void *arg) { int ret; uint8_t *request = NULL, buf[128]; - hs_cell_introduce1_t *cell = NULL; + trn_cell_introduce1_t *cell = NULL; or_circuit_t *circ = NULL; (void) arg; @@ -774,11 +774,11 @@ test_received_introduce1_handling(void *arg) /* Valid case. */ { 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); request = tor_malloc_zero(request_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); 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. */ ed25519_public_key_t 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); hs_circuitmap_register_intro_circ_v3(service_circ, &auth_key); ret = hs_intro_received_introduce1(circ, request, request_len); @@ -800,16 +800,16 @@ test_received_introduce1_handling(void *arg) /* Valid legacy cell. */ { tor_free(request); - hs_cell_introduce1_free(cell); + trn_cell_introduce1_free(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); /* 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); request = tor_malloc_zero(request_len + 256); 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); circ = helper_create_intro_circuit(); @@ -827,7 +827,7 @@ test_received_introduce1_handling(void *arg) } done: - hs_cell_introduce1_free(cell); + trn_cell_introduce1_free(cell); tor_free(request); hs_circuitmap_free_all(); UNMOCK(relay_send_command_from_edge_); diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index ae9c0a0300..c501b4bfe9 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -26,8 +26,8 @@ test_gen_establish_intro_cell(void *arg) ssize_t retval; uint8_t circuit_key_material[DIGEST_LEN] = {0}; uint8_t buf[RELAY_PAYLOAD_SIZE]; - hs_cell_establish_intro_t *cell_out = NULL; - hs_cell_establish_intro_t *cell_in = NULL; + trn_cell_establish_intro_t *cell_out = NULL; + trn_cell_establish_intro_t *cell_in = NULL; crypto_rand((char *) circuit_key_material, sizeof(circuit_key_material)); @@ -44,7 +44,7 @@ test_gen_establish_intro_cell(void *arg) /* 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)); tt_int_op(parse_result, >=, 0); @@ -55,8 +55,8 @@ test_gen_establish_intro_cell(void *arg) } done: - hs_cell_establish_intro_free(cell_out); - hs_cell_establish_intro_free(cell_in); + trn_cell_establish_intro_free(cell_out); + trn_cell_establish_intro_free(cell_in); } /* Mocked ed25519_sign_prefixed() function that always fails :) */ @@ -78,7 +78,7 @@ static void test_gen_establish_intro_cell_bad(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}; MOCK(ed25519_sign_prefixed, mock_ed25519_sign_prefixed); @@ -96,7 +96,7 @@ test_gen_establish_intro_cell_bad(void *arg) tt_assert(!cell); done: - hs_cell_establish_intro_free(cell); + trn_cell_establish_intro_free(cell); UNMOCK(ed25519_sign_prefixed); } diff --git a/src/trunnel/hs/cell_common.c b/src/trunnel/hs/cell_common.c index 830f2260ee..b7f19ffc60 100644 --- a/src/trunnel/hs/cell_common.c +++ b/src/trunnel/hs/cell_common.c @@ -28,10 +28,10 @@ int cellcommon_deadcode_dummy__ = 0; } \ } while (0) -cell_extension_fields_t * -cell_extension_fields_new(void) +trn_cell_extension_fields_t * +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) return NULL; return val; @@ -40,7 +40,7 @@ cell_extension_fields_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ static void -cell_extension_fields_clear(cell_extension_fields_t *obj) +trn_cell_extension_fields_clear(trn_cell_extension_fields_t *obj) { (void) obj; TRUNNEL_DYNARRAY_WIPE(&obj->field); @@ -48,62 +48,62 @@ cell_extension_fields_clear(cell_extension_fields_t *obj) } void -cell_extension_fields_free(cell_extension_fields_t *obj) +trn_cell_extension_fields_free(trn_cell_extension_fields_t *obj) { if (obj == NULL) return; - cell_extension_fields_clear(obj); - trunnel_memwipe(obj, sizeof(cell_extension_fields_t)); + trn_cell_extension_fields_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_extension_fields_t)); trunnel_free_(obj); } 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; } 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; return 0; } 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; } 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; return 0; } 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); } 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); } 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 -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); return 0; } 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 (inp->field.n_ == UINT8_MAX) @@ -117,17 +117,17 @@ cell_extension_fields_add_field(cell_extension_fields_t *inp, uint8_t elt) } 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_; } 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 -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; #if UINT8_MAX < SIZE_MAX @@ -147,7 +147,7 @@ cell_extension_fields_setlen_field(cell_extension_fields_t *inp, size_t newlen) return -1; } 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) return "Object was NULL"; @@ -159,11 +159,11 @@ cell_extension_fields_check(const cell_extension_fields_t *obj) } 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; - if (NULL != cell_extension_fields_check(obj)) + if (NULL != trn_cell_extension_fields_check(obj)) return -1; @@ -178,24 +178,24 @@ cell_extension_fields_encoded_len(const cell_extension_fields_t *obj) return result; } 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_; obj->trunnel_error_code_ = 0; return r; } 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; size_t written = 0; uint8_t *ptr = output; const char *msg; #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 - if (NULL != (msg = cell_extension_fields_check(obj))) + if (NULL != (msg = trn_cell_extension_fields_check(obj))) goto check_failed; #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; } -/** As cell_extension_fields_parse(), but do not allocate the output - * object. +/** As trn_cell_extension_fields_parse(), but do not allocate the + * output object. */ 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; 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 -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; - *output = cell_extension_fields_new(); + *output = trn_cell_extension_fields_new(); if (NULL == *output) 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) { - cell_extension_fields_free(*output); + trn_cell_extension_fields_free(*output); *output = NULL; } return result; } -cell_extension_t * -cell_extension_new(void) +trn_cell_extension_t * +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) return NULL; return val; @@ -315,14 +315,14 @@ cell_extension_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ static void -cell_extension_clear(cell_extension_t *obj) +trn_cell_extension_clear(trn_cell_extension_t *obj) { (void) obj; { unsigned 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); @@ -330,92 +330,92 @@ cell_extension_clear(cell_extension_t *obj) } void -cell_extension_free(cell_extension_t *obj) +trn_cell_extension_free(trn_cell_extension_t *obj) { if (obj == NULL) return; - cell_extension_clear(obj); - trunnel_memwipe(obj, sizeof(cell_extension_t)); + trn_cell_extension_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_extension_t)); trunnel_free_(obj); } 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; } 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; return 0; } 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); } -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) { return TRUNNEL_DYNARRAY_GET(&inp->fields, idx); } - 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) { - return cell_extension_get_fields((cell_extension_t*)inp, idx); + return trn_cell_extension_get_fields((trn_cell_extension_t*)inp, idx); } 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) - cell_extension_fields_free(oldval); - return cell_extension_set0_fields(inp, idx, elt); + trn_cell_extension_fields_free(oldval); + return trn_cell_extension_set0_fields(inp, idx, elt); } 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); return 0; } 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 (inp->fields.n_ == UINT8_MAX) goto trunnel_alloc_failed; #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; trunnel_alloc_failed: TRUNNEL_SET_ERROR_CODE(inp); return -1; } -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) { return inp->fields.elts_; } -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) { - 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 -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 (newlen > UINT8_MAX) goto trunnel_alloc_failed; #endif newptr = trunnel_dynarray_setlen(&inp->fields.allocated_, &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_); if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; @@ -426,7 +426,7 @@ cell_extension_setlen_fields(cell_extension_t *inp, size_t newlen) return -1; } const char * -cell_extension_check(const cell_extension_t *obj) +trn_cell_extension_check(const trn_cell_extension_t *obj) { if (obj == NULL) return "Object was NULL"; @@ -437,7 +437,7 @@ cell_extension_check(const cell_extension_t *obj) unsigned 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; } } @@ -447,46 +447,46 @@ cell_extension_check(const cell_extension_t *obj) } 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; - if (NULL != cell_extension_check(obj)) + if (NULL != trn_cell_extension_check(obj)) return -1; /* Length of u8 num */ result += 1; - /* Length of struct cell_extension_fields fields[num] */ + /* Length of struct trn_cell_extension_fields fields[num] */ { unsigned 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; } 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_; obj->trunnel_error_code_ = 0; return r; } 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; size_t written = 0; uint8_t *ptr = output; const char *msg; #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 - if (NULL != (msg = cell_extension_check(obj))) + if (NULL != (msg = trn_cell_extension_check(obj))) goto check_failed; #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)); written += 1; ptr += 1; - /* Encode struct cell_extension_fields fields[num] */ + /* Encode struct trn_cell_extension_fields fields[num] */ { unsigned idx; for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->fields); ++idx) { 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) goto fail; /* XXXXXXX !*/ written += result; ptr += result; @@ -537,10 +537,11 @@ cell_extension_encode(uint8_t *output, const size_t avail, const cell_extension_ 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 -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; 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)); remaining -= 1; ptr += 1; - /* Parse struct cell_extension_fields fields[num] */ - TRUNNEL_DYNARRAY_EXPAND(cell_extension_fields_t *, &obj->fields, obj->num, {}); + /* Parse struct trn_cell_extension_fields fields[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; 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) goto relay_fail; trunnel_assert((size_t)result <= remaining); 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); @@ -579,15 +580,15 @@ cell_extension_parse_into(cell_extension_t *obj, const uint8_t *input, const siz } 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; - *output = cell_extension_new(); + *output = trn_cell_extension_new(); if (NULL == *output) return -1; - result = cell_extension_parse_into(*output, input, len_in); + result = trn_cell_extension_parse_into(*output, input, len_in); if (result < 0) { - cell_extension_free(*output); + trn_cell_extension_free(*output); *output = NULL; } return result; diff --git a/src/trunnel/hs/cell_common.h b/src/trunnel/hs/cell_common.h index 8999f7da40..4d98a54cf4 100644 --- a/src/trunnel/hs/cell_common.h +++ b/src/trunnel/hs/cell_common.h @@ -8,191 +8,196 @@ #include #include "trunnel.h" -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CELL_EXTENSION_FIELDS) -struct cell_extension_fields_st { +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_EXTENSION_FIELDS) +struct trn_cell_extension_fields_st { uint8_t field_type; uint8_t field_len; TRUNNEL_DYNARRAY_HEAD(, uint8_t) field; uint8_t trunnel_error_code_; }; #endif -typedef struct cell_extension_fields_st cell_extension_fields_t; -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CELL_EXTENSION) -struct cell_extension_st { +typedef struct trn_cell_extension_fields_st trn_cell_extension_fields_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_EXTENSION) +struct trn_cell_extension_st { 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_; }; #endif -typedef struct cell_extension_st cell_extension_t; -/** Return a newly allocated cell_extension_fields with all elements - * set to zero. +typedef struct trn_cell_extension_st trn_cell_extension_t; +/** Return a newly allocated trn_cell_extension_fields with all + * elements set to zero. */ -cell_extension_fields_t *cell_extension_fields_new(void); -/** Release all storage held by the cell_extension_fields in 'victim'. - * (Do nothing if 'victim' is NULL.) +trn_cell_extension_fields_t *trn_cell_extension_fields_new(void); +/** Release all storage held by the trn_cell_extension_fields in + * 'victim'. (Do nothing if 'victim' is NULL.) */ -void cell_extension_fields_free(cell_extension_fields_t *victim); -/** Try to parse a cell_extension_fields from the buffer in 'input', - * using up to 'len_in' bytes from the input buffer. On success, - * return the number of bytes consumed and set *output to the newly - * allocated cell_extension_fields_t. On failure, return -2 if the - * input appears truncated, and -1 if the input is otherwise invalid. +void trn_cell_extension_fields_free(trn_cell_extension_fields_t *victim); +/** Try to parse a trn_cell_extension_fields from the buffer in + * 'input', using up to 'len_in' bytes from the input buffer. On + * success, return the number of bytes consumed and set *output to the + * newly allocated trn_cell_extension_fields_t. On failure, return -2 + * 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 - * 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 * an underestimate for certain unencodeable objects. */ -ssize_t cell_extension_fields_encoded_len(const cell_extension_fields_t *obj); -/** Try to encode the cell_extension_fields from 'input' into the +ssize_t trn_cell_extension_fields_encoded_len(const trn_cell_extension_fields_t *obj); +/** Try to encode the trn_cell_extension_fields from 'input' into the * buffer at 'output', using up to 'avail' bytes of the output 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 was invalid. */ -ssize_t cell_extension_fields_encode(uint8_t *output, size_t avail, const cell_extension_fields_t *input); -/** Check whether the internal state of the cell_extension_fields in - * 'obj' is consistent. Return NULL if it is, and a short message if - * it is not. +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 trn_cell_extension_fields + * in 'obj' is consistent. Return NULL if it is, and a short message + * 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 * 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 - * 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 - * 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. */ -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 - * 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 - * 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. */ -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 - * 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 - * 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); -/** As cell_extension_fields_get_field, but take and return a const - * pointer +uint8_t trn_cell_extension_fields_get_field(trn_cell_extension_fields_t *inp, size_t idx); +/** As trn_cell_extension_fields_get_field, but take and return a + * 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 - * field of the cell_extension_fields_t in 'inp', so that it will hold - * the value 'elt'. + * field of the trn_cell_extension_fields_t in 'inp', so that it will + * 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 - * 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 * 'inp'. */ -uint8_t * cell_extension_fields_getarray_field(cell_extension_fields_t *inp); -/** As cell_extension_fields_get_field, but take and return a const - * pointer +uint8_t * trn_cell_extension_fields_getarray_field(trn_cell_extension_fields_t *inp); +/** As trn_cell_extension_fields_get_field, but take and return a + * 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 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 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); -/** Return a newly allocated cell_extension with all elements set to - * zero. +int trn_cell_extension_fields_setlen_field(trn_cell_extension_fields_t *inp, size_t newlen); +/** Return a newly allocated trn_cell_extension with all elements set + * to zero. */ -cell_extension_t *cell_extension_new(void); -/** Release all storage held by the cell_extension in 'victim'. (Do - * nothing if 'victim' is NULL.) +trn_cell_extension_t *trn_cell_extension_new(void); +/** Release all storage held by the trn_cell_extension in 'victim'. + * (Do nothing if 'victim' is NULL.) */ -void cell_extension_free(cell_extension_t *victim); -/** Try to parse a cell_extension from the buffer in 'input', using up - * to 'len_in' bytes from the input buffer. On success, return the - * number of bytes consumed and set *output to the newly allocated - * cell_extension_t. On failure, return -2 if the input appears - * truncated, and -1 if the input is otherwise invalid. +void trn_cell_extension_free(trn_cell_extension_t *victim); +/** Try to parse a trn_cell_extension from the buffer in 'input', + * using up to 'len_in' bytes from the input buffer. On success, + * return the number of bytes consumed and set *output to the newly + * allocated trn_cell_extension_t. On failure, return -2 if the input + * 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 - * cell_extension in 'obj'. On failure, return a negative value. Note - * that this value may be an overestimate, and can even be an + * trn_cell_extension in 'obj'. On failure, return a negative value. + * Note that this value may be an overestimate, and can even be an * underestimate for certain unencodeable objects. */ -ssize_t cell_extension_encoded_len(const cell_extension_t *obj); -/** Try to encode the cell_extension from 'input' into the buffer at - * 'output', using up to 'avail' bytes of the output buffer. On +ssize_t trn_cell_extension_encoded_len(const trn_cell_extension_t *obj); +/** Try to encode the trn_cell_extension from 'input' into the buffer + * at 'output', using up to 'avail' bytes of the output 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 was invalid. */ -ssize_t cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input); -/** Check whether the internal state of the cell_extension in 'obj' is - * consistent. Return NULL if it is, and a short message if it is not. +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 trn_cell_extension in + * '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 * functions. Return true iff errors were cleared. */ -int cell_extension_clear_errors(cell_extension_t *obj); -/** Return the value of the num field of the cell_extension_t in 'inp' +int trn_cell_extension_clear_errors(trn_cell_extension_t *obj); +/** 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); -/** Set the value of the num field of the cell_extension_t in 'inp' to - * 'val'. Return 0 on success; return -1 and set the error code on - * 'inp' on failure. +uint8_t trn_cell_extension_get_num(const trn_cell_extension_t *inp); +/** Set the value of the num field of the trn_cell_extension_t in + * 'inp' to 'val'. Return 0 on success; return -1 and set the error + * 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 - * 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 - * 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); -/** As cell_extension_get_fields, but take and return a const pointer +struct trn_cell_extension_fields_st * trn_cell_extension_get_fields(trn_cell_extension_t *inp, size_t idx); +/** 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 - * fields of the cell_extension_t in 'inp', so that it will hold the - * value 'elt'. Free the previous value, if any. + * fields of the trn_cell_extension_t in 'inp', so that it will hold + * 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); -/** As cell_extension_set_fields, but does not free the previous +int trn_cell_extension_set_fields(trn_cell_extension_t *inp, size_t idx, struct trn_cell_extension_fields_st * elt); +/** As trn_cell_extension_set_fields, but does not free the previous * 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 - * 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 * 'inp'. */ -struct cell_extension_fields_st * * cell_extension_getarray_fields(cell_extension_t *inp); -/** As cell_extension_get_fields, but take and return a const pointer +struct trn_cell_extension_fields_st * * trn_cell_extension_getarray_fields(trn_cell_extension_t *inp); +/** 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 * 'inp' to 'newlen'.Fill extra elements with NULL; free removed * elements. Return 0 on success; return -1 and set the error code on * '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 diff --git a/src/trunnel/hs/cell_common.trunnel b/src/trunnel/hs/cell_common.trunnel index 1bbec5a1fe..1aa6999de7 100644 --- a/src/trunnel/hs/cell_common.trunnel +++ b/src/trunnel/hs/cell_common.trunnel @@ -1,12 +1,12 @@ /* This file contains common data structure that cells use. */ -struct cell_extension_fields { +struct trn_cell_extension_fields { u8 field_type; u8 field_len; u8 field[field_len]; }; -struct cell_extension { +struct trn_cell_extension { u8 num; - struct cell_extension_fields fields[num]; + struct trn_cell_extension_fields fields[num]; }; diff --git a/src/trunnel/hs/cell_establish_intro.c b/src/trunnel/hs/cell_establish_intro.c index 633bd7c214..22e198c369 100644 --- a/src/trunnel/hs/cell_establish_intro.c +++ b/src/trunnel/hs/cell_establish_intro.c @@ -28,18 +28,18 @@ int cellestablishintro_deadcode_dummy__ = 0; } \ } while (0) -typedef struct cell_extension_st cell_extension_t; -cell_extension_t *cell_extension_new(void); -void cell_extension_free(cell_extension_t *victim); -ssize_t cell_extension_parse(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 cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input); -const char *cell_extension_check(const cell_extension_t *obj); -int cell_extension_clear_errors(cell_extension_t *obj); -hs_cell_establish_intro_t * -hs_cell_establish_intro_new(void) +typedef struct trn_cell_extension_st trn_cell_extension_t; +trn_cell_extension_t *trn_cell_extension_new(void); +void trn_cell_extension_free(trn_cell_extension_t *victim); +ssize_t trn_cell_extension_parse(trn_cell_extension_t **output, const uint8_t *input, const size_t len_in); +ssize_t trn_cell_extension_encoded_len(const trn_cell_extension_t *obj); +ssize_t trn_cell_extension_encode(uint8_t *output, size_t avail, const trn_cell_extension_t *input); +const char *trn_cell_extension_check(const trn_cell_extension_t *obj); +int trn_cell_extension_clear_errors(trn_cell_extension_t *obj); +trn_cell_establish_intro_t * +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) return NULL; return val; @@ -48,39 +48,39 @@ hs_cell_establish_intro_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ 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; TRUNNEL_DYNARRAY_WIPE(&obj->auth_key); TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key); - cell_extension_free(obj->extensions); + trn_cell_extension_free(obj->extensions); obj->extensions = NULL; TRUNNEL_DYNARRAY_WIPE(&obj->sig); TRUNNEL_DYNARRAY_CLEAR(&obj->sig); } 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) return; - hs_cell_establish_intro_clear(obj); - trunnel_memwipe(obj, sizeof(hs_cell_establish_intro_t)); + trn_cell_establish_intro_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_establish_intro_t)); trunnel_free_(obj); } 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; } 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; } 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))) { 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; } 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; } 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; return 0; } 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); } 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); } 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 -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); return 0; } 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 (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 * -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_; } 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 -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; #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); return -1; } -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) { return inp->extensions; } -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) { - 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 -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) - cell_extension_free(inp->extensions); - return hs_cell_establish_intro_set0_extensions(inp, val); + trn_cell_extension_free(inp->extensions); + return trn_cell_establish_intro_set0_extensions(inp, val); } 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; return 0; } 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; } 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; } 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); return inp->handshake_mac[idx]; } 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 -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); 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 * -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; } 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 * -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; } 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; } 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; return 0; } 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); } 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); } 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 -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); return 0; } 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 (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 * -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_; } 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 -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; #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; } 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) 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"; { const char *msg; - if (NULL != (msg = cell_extension_check(obj->extensions))) + if (NULL != (msg = trn_cell_extension_check(obj->extensions))) return msg; } 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 -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; - if (NULL != hs_cell_establish_intro_check(obj)) + if (NULL != trn_cell_establish_intro_check(obj)) 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] */ result += TRUNNEL_DYNARRAY_LEN(&obj->auth_key); - /* Length of struct cell_extension extensions */ - result += cell_extension_encoded_len(obj->extensions); + /* Length of struct trn_cell_extension extensions */ + result += trn_cell_extension_encoded_len(obj->extensions); /* Length of u8 handshake_mac[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; } 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_; obj->trunnel_error_code_ = 0; return r; } 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; size_t written = 0; uint8_t *ptr = output; const char *msg; #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 - if (NULL != (msg = hs_cell_establish_intro_check(obj))) + if (NULL != (msg = trn_cell_establish_intro_check(obj))) goto check_failed; #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; } - /* Encode struct cell_extension extensions */ + /* Encode struct trn_cell_extension extensions */ 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) goto fail; /* XXXXXXX !*/ 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; } -/** As hs_cell_establish_intro_parse(), but do not allocate the output - * object. +/** As trn_cell_establish_intro_parse(), but do not allocate the + * output object. */ 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; 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); ptr += obj->auth_key_len; remaining -= obj->auth_key_len; - /* Parse struct cell_extension extensions */ - result = cell_extension_parse(&obj->extensions, ptr, remaining); + /* Parse struct trn_cell_extension extensions */ + result = trn_cell_extension_parse(&obj->extensions, ptr, remaining); if (result < 0) goto relay_fail; 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 -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; - *output = hs_cell_establish_intro_new(); + *output = trn_cell_establish_intro_new(); if (NULL == *output) 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) { - hs_cell_establish_intro_free(*output); + trn_cell_establish_intro_free(*output); *output = NULL; } return result; } -hs_cell_intro_established_t * -hs_cell_intro_established_new(void) +trn_cell_intro_established_t * +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) return NULL; return val; @@ -573,48 +573,48 @@ hs_cell_intro_established_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ 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; - cell_extension_free(obj->extensions); + trn_cell_extension_free(obj->extensions); obj->extensions = NULL; } 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) return; - hs_cell_intro_established_clear(obj); - trunnel_memwipe(obj, sizeof(hs_cell_intro_established_t)); + trn_cell_intro_established_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_intro_established_t)); trunnel_free_(obj); } -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) { return inp->extensions; } -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) { - 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 -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) - cell_extension_free(inp->extensions); - return hs_cell_intro_established_set0_extensions(inp, val); + trn_cell_extension_free(inp->extensions); + return trn_cell_intro_established_set0_extensions(inp, val); } 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; return 0; } 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) 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"; { const char *msg; - if (NULL != (msg = cell_extension_check(obj->extensions))) + if (NULL != (msg = trn_cell_extension_check(obj->extensions))) return msg; } return NULL; } 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; - if (NULL != hs_cell_intro_established_check(obj)) + if (NULL != trn_cell_intro_established_check(obj)) return -1; - /* Length of struct cell_extension extensions */ - result += cell_extension_encoded_len(obj->extensions); + /* Length of struct trn_cell_extension extensions */ + result += trn_cell_extension_encoded_len(obj->extensions); return result; } 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_; obj->trunnel_error_code_ = 0; return r; } 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; size_t written = 0; uint8_t *ptr = output; const char *msg; #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 - if (NULL != (msg = hs_cell_intro_established_check(obj))) + if (NULL != (msg = trn_cell_intro_established_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN trunnel_assert(encoded_len >= 0); #endif - /* Encode struct cell_extension extensions */ + /* Encode struct trn_cell_extension extensions */ 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) goto fail; /* XXXXXXX !*/ 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; } -/** As hs_cell_intro_established_parse(), but do not allocate the +/** As trn_cell_intro_established_parse(), but do not allocate the * output object. */ 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; size_t remaining = len_in; ssize_t result = 0; (void)result; - /* Parse struct cell_extension extensions */ - result = cell_extension_parse(&obj->extensions, ptr, remaining); + /* Parse struct trn_cell_extension extensions */ + result = trn_cell_extension_parse(&obj->extensions, ptr, remaining); if (result < 0) goto relay_fail; 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 -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; - *output = hs_cell_intro_established_new(); + *output = trn_cell_intro_established_new(); if (NULL == *output) 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) { - hs_cell_intro_established_free(*output); + trn_cell_intro_established_free(*output); *output = NULL; } return result; diff --git a/src/trunnel/hs/cell_establish_intro.h b/src/trunnel/hs/cell_establish_intro.h index 725d47cd85..2f0d893659 100644 --- a/src/trunnel/hs/cell_establish_intro.h +++ b/src/trunnel/hs/cell_establish_intro.h @@ -8,15 +8,15 @@ #include #include "trunnel.h" -struct cell_extension_st; +struct trn_cell_extension_st; #define TRUNNEL_SHA3_256_LEN 32 -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_ESTABLISH_INTRO) -struct hs_cell_establish_intro_st { +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_ESTABLISH_INTRO) +struct trn_cell_establish_intro_st { const uint8_t *start_cell; uint8_t auth_key_type; uint16_t auth_key_len; TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key; - struct cell_extension_st *extensions; + struct trn_cell_extension_st *extensions; const uint8_t *end_mac_fields; uint8_t handshake_mac[TRUNNEL_SHA3_256_LEN]; const uint8_t *end_sig_fields; @@ -25,251 +25,252 @@ struct hs_cell_establish_intro_st { uint8_t trunnel_error_code_; }; #endif -typedef struct hs_cell_establish_intro_st hs_cell_establish_intro_t; -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRO_ESTABLISHED) -struct hs_cell_intro_established_st { - struct cell_extension_st *extensions; +typedef struct trn_cell_establish_intro_st trn_cell_establish_intro_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRO_ESTABLISHED) +struct trn_cell_intro_established_st { + struct trn_cell_extension_st *extensions; uint8_t trunnel_error_code_; }; #endif -typedef struct hs_cell_intro_established_st hs_cell_intro_established_t; -/** Return a newly allocated hs_cell_establish_intro with all elements - * set to zero. +typedef struct trn_cell_intro_established_st trn_cell_intro_established_t; +/** Return a newly allocated trn_cell_establish_intro with all + * elements set to zero. */ -hs_cell_establish_intro_t *hs_cell_establish_intro_new(void); -/** Release all storage held by the hs_cell_establish_intro in +trn_cell_establish_intro_t *trn_cell_establish_intro_new(void); +/** Release all storage held by the trn_cell_establish_intro in * 'victim'. (Do nothing if 'victim' is NULL.) */ -void hs_cell_establish_intro_free(hs_cell_establish_intro_t *victim); -/** Try to parse a hs_cell_establish_intro from the buffer in 'input', - * using up to 'len_in' bytes from the input buffer. On success, - * return the number of bytes consumed and set *output to the newly - * allocated hs_cell_establish_intro_t. On failure, return -2 if the - * input appears truncated, and -1 if the input is otherwise invalid. +void trn_cell_establish_intro_free(trn_cell_establish_intro_t *victim); +/** Try to parse a trn_cell_establish_intro from the buffer in + * 'input', using up to 'len_in' bytes from the input buffer. On + * success, return the number of bytes consumed and set *output to the + * newly allocated trn_cell_establish_intro_t. On failure, return -2 + * 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 - * 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 * an underestimate for certain unencodeable objects. */ -ssize_t hs_cell_establish_intro_encoded_len(const hs_cell_establish_intro_t *obj); -/** Try to encode the hs_cell_establish_intro from 'input' into the +ssize_t trn_cell_establish_intro_encoded_len(const trn_cell_establish_intro_t *obj); +/** Try to encode the trn_cell_establish_intro from 'input' into the * buffer at 'output', using up to 'avail' bytes of the output 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 was invalid. */ -ssize_t hs_cell_establish_intro_encode(uint8_t *output, size_t avail, const hs_cell_establish_intro_t *input); -/** Check whether the internal state of the hs_cell_establish_intro in - * 'obj' is consistent. Return NULL if it is, and a short message if - * it is not. +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 trn_cell_establish_intro + * in 'obj' is consistent. Return NULL if it is, and a short message + * 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 * 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 */ -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 - * 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 - * 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. */ -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 - * 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 - * 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. */ -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 - * 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 - * 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); -/** As hs_cell_establish_intro_get_auth_key, but take and return a +uint8_t trn_cell_establish_intro_get_auth_key(trn_cell_establish_intro_t *inp, size_t idx); +/** As trn_cell_establish_intro_get_auth_key, but take and return a * 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 - * auth_key of the hs_cell_establish_intro_t in 'inp', so that it will - * hold the value 'elt'. + * auth_key of the trn_cell_establish_intro_t in 'inp', so that it + * 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 - * 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 * 'inp'. */ -uint8_t * hs_cell_establish_intro_getarray_auth_key(hs_cell_establish_intro_t *inp); -/** As hs_cell_establish_intro_get_auth_key, but take and return a +uint8_t * trn_cell_establish_intro_getarray_auth_key(trn_cell_establish_intro_t *inp); +/** As trn_cell_establish_intro_get_auth_key, but take and return a * 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 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 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 - * 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); -/** As hs_cell_establish_intro_get_extensions, but take and return a +struct trn_cell_extension_st * trn_cell_establish_intro_get_extensions(trn_cell_establish_intro_t *inp); +/** As trn_cell_establish_intro_get_extensions, but take and return a * 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 - * 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 * 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); -/** As hs_cell_establish_intro_set_extensions, but does not free the +int trn_cell_establish_intro_set_extensions(trn_cell_establish_intro_t *inp, struct trn_cell_extension_st *val); +/** As trn_cell_establish_intro_set_extensions, but does not free the * 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 */ -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 - * 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 - * 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); -/** As hs_cell_establish_intro_get_handshake_mac, but take and return +uint8_t trn_cell_establish_intro_get_handshake_mac(trn_cell_establish_intro_t *inp, size_t idx); +/** As trn_cell_establish_intro_get_handshake_mac, but take and return * 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 - * handshake_mac of the hs_cell_establish_intro_t in 'inp', so that it - * will hold the value 'elt'. + * handshake_mac of the trn_cell_establish_intro_t in 'inp', so that + * 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 * handshake_mac of 'inp'. */ -uint8_t * hs_cell_establish_intro_getarray_handshake_mac(hs_cell_establish_intro_t *inp); -/** As hs_cell_establish_intro_get_handshake_mac, but take and return +uint8_t * trn_cell_establish_intro_getarray_handshake_mac(trn_cell_establish_intro_t *inp); +/** As trn_cell_establish_intro_get_handshake_mac, but take and return * 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 */ -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 - * 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 - * 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. */ -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 - * 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 - * 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); -/** As hs_cell_establish_intro_get_sig, but take and return a const +uint8_t trn_cell_establish_intro_get_sig(trn_cell_establish_intro_t *inp, size_t idx); +/** As trn_cell_establish_intro_get_sig, but take and return a const * 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 - * sig of the hs_cell_establish_intro_t in 'inp', so that it will hold - * the value 'elt'. + * sig of the trn_cell_establish_intro_t in 'inp', so that it will + * 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 - * 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'. */ -uint8_t * hs_cell_establish_intro_getarray_sig(hs_cell_establish_intro_t *inp); -/** As hs_cell_establish_intro_get_sig, but take and return a const +uint8_t * trn_cell_establish_intro_getarray_sig(trn_cell_establish_intro_t *inp); +/** As trn_cell_establish_intro_get_sig, but take and return a const * 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' * to 'newlen'.Fill extra elements with 0. Return 0 on success; return * -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); -/** Return a newly allocated hs_cell_intro_established with all +int trn_cell_establish_intro_setlen_sig(trn_cell_establish_intro_t *inp, size_t newlen); +/** Return a newly allocated trn_cell_intro_established with all * elements set to zero. */ -hs_cell_intro_established_t *hs_cell_intro_established_new(void); -/** Release all storage held by the hs_cell_intro_established in +trn_cell_intro_established_t *trn_cell_intro_established_new(void); +/** Release all storage held by the trn_cell_intro_established in * 'victim'. (Do nothing if 'victim' is NULL.) */ -void hs_cell_intro_established_free(hs_cell_intro_established_t *victim); -/** Try to parse a hs_cell_intro_established from the buffer in +void trn_cell_intro_established_free(trn_cell_intro_established_t *victim); +/** Try to parse a trn_cell_intro_established from the buffer in * 'input', using up to 'len_in' bytes from the input buffer. On * 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 * 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 - * 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 * an underestimate for certain unencodeable objects. */ -ssize_t hs_cell_intro_established_encoded_len(const hs_cell_intro_established_t *obj); -/** Try to encode the hs_cell_intro_established from 'input' into the +ssize_t trn_cell_intro_established_encoded_len(const trn_cell_intro_established_t *obj); +/** Try to encode the trn_cell_intro_established from 'input' into the * buffer at 'output', using up to 'avail' bytes of the output 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 was invalid. */ -ssize_t hs_cell_intro_established_encode(uint8_t *output, size_t avail, const hs_cell_intro_established_t *input); -/** Check whether the internal state of the hs_cell_intro_established +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 trn_cell_intro_established * in 'obj' is consistent. Return NULL if it is, and a short message * 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 * 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 - * 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); -/** As hs_cell_intro_established_get_extensions, but take and return a - * const pointer +struct trn_cell_extension_st * trn_cell_intro_established_get_extensions(trn_cell_intro_established_t *inp); +/** As trn_cell_intro_established_get_extensions, but take and return + * 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 - * 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 * 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); -/** As hs_cell_intro_established_set_extensions, but does not free the - * previous value. +int trn_cell_intro_established_set_extensions(trn_cell_intro_established_t *inp, struct trn_cell_extension_st *val); +/** As trn_cell_intro_established_set_extensions, but does not free + * 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 diff --git a/src/trunnel/hs/cell_establish_intro.trunnel b/src/trunnel/hs/cell_establish_intro.trunnel index 33a133bf67..011ee62a15 100644 --- a/src/trunnel/hs/cell_establish_intro.trunnel +++ b/src/trunnel/hs/cell_establish_intro.trunnel @@ -4,12 +4,12 @@ * specified in proposal 224 section 3.1. */ -extern struct cell_extension; +extern struct trn_cell_extension; const TRUNNEL_SHA3_256_LEN = 32; /* 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. */ @ptr start_cell; @@ -19,7 +19,7 @@ struct hs_cell_establish_intro { u8 auth_key[auth_key_len]; /* Extension(s). Reserved fields. */ - struct cell_extension extensions; + struct trn_cell_extension extensions; @ptr end_mac_fields; /* Handshake MAC. */ @@ -35,7 +35,7 @@ struct hs_cell_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 * to version >= 3. */ -struct hs_cell_intro_established { +struct trn_cell_intro_established { /* Extension(s). Reserved fields. */ - struct cell_extension extensions; + struct trn_cell_extension extensions; }; diff --git a/src/trunnel/hs/cell_introduce1.c b/src/trunnel/hs/cell_introduce1.c index 5922a086dc..7501f6f196 100644 --- a/src/trunnel/hs/cell_introduce1.c +++ b/src/trunnel/hs/cell_introduce1.c @@ -28,14 +28,14 @@ int cellintroduce_deadcode_dummy__ = 0; } \ } while (0) -typedef struct cell_extension_st cell_extension_t; -cell_extension_t *cell_extension_new(void); -void cell_extension_free(cell_extension_t *victim); -ssize_t cell_extension_parse(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 cell_extension_encode(uint8_t *output, size_t avail, const cell_extension_t *input); -const char *cell_extension_check(const cell_extension_t *obj); -int cell_extension_clear_errors(cell_extension_t *obj); +typedef struct trn_cell_extension_st trn_cell_extension_t; +trn_cell_extension_t *trn_cell_extension_new(void); +void trn_cell_extension_free(trn_cell_extension_t *victim); +ssize_t trn_cell_extension_parse(trn_cell_extension_t **output, const uint8_t *input, const size_t len_in); +ssize_t trn_cell_extension_encoded_len(const trn_cell_extension_t *obj); +ssize_t trn_cell_extension_encode(uint8_t *output, size_t avail, const trn_cell_extension_t *input); +const char *trn_cell_extension_check(const trn_cell_extension_t *obj); +int trn_cell_extension_clear_errors(trn_cell_extension_t *obj); typedef struct link_specifier_st link_specifier_t; link_specifier_t *link_specifier_new(void); void link_specifier_free(link_specifier_t *victim); @@ -44,10 +44,10 @@ ssize_t link_specifier_encoded_len(const link_specifier_t *obj); ssize_t link_specifier_encode(uint8_t *output, size_t avail, const link_specifier_t *input); const char *link_specifier_check(const link_specifier_t *obj); int link_specifier_clear_errors(link_specifier_t *obj); -hs_cell_introduce1_t * -hs_cell_introduce1_new(void) +trn_cell_introduce1_t * +trn_cell_introduce1_new(void) { - hs_cell_introduce1_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce1_t)); + trn_cell_introduce1_t *val = trunnel_calloc(1, sizeof(trn_cell_introduce1_t)); if (NULL == val) return NULL; return val; @@ -56,47 +56,47 @@ hs_cell_introduce1_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ static void -hs_cell_introduce1_clear(hs_cell_introduce1_t *obj) +trn_cell_introduce1_clear(trn_cell_introduce1_t *obj) { (void) obj; TRUNNEL_DYNARRAY_WIPE(&obj->auth_key); TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key); - cell_extension_free(obj->extensions); + trn_cell_extension_free(obj->extensions); obj->extensions = NULL; TRUNNEL_DYNARRAY_WIPE(&obj->encrypted); TRUNNEL_DYNARRAY_CLEAR(&obj->encrypted); } void -hs_cell_introduce1_free(hs_cell_introduce1_t *obj) +trn_cell_introduce1_free(trn_cell_introduce1_t *obj) { if (obj == NULL) return; - hs_cell_introduce1_clear(obj); - trunnel_memwipe(obj, sizeof(hs_cell_introduce1_t)); + trn_cell_introduce1_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_introduce1_t)); trunnel_free_(obj); } size_t -hs_cell_introduce1_getlen_legacy_key_id(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_getlen_legacy_key_id(const trn_cell_introduce1_t *inp) { (void)inp; return TRUNNEL_SHA1_LEN; } uint8_t -hs_cell_introduce1_get_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx) +trn_cell_introduce1_get_legacy_key_id(trn_cell_introduce1_t *inp, size_t idx) { trunnel_assert(idx < TRUNNEL_SHA1_LEN); return inp->legacy_key_id[idx]; } uint8_t -hs_cell_introduce1_getconst_legacy_key_id(const hs_cell_introduce1_t *inp, size_t idx) +trn_cell_introduce1_getconst_legacy_key_id(const trn_cell_introduce1_t *inp, size_t idx) { - return hs_cell_introduce1_get_legacy_key_id((hs_cell_introduce1_t*)inp, idx); + return trn_cell_introduce1_get_legacy_key_id((trn_cell_introduce1_t*)inp, idx); } int -hs_cell_introduce1_set_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt) +trn_cell_introduce1_set_legacy_key_id(trn_cell_introduce1_t *inp, size_t idx, uint8_t elt) { trunnel_assert(idx < TRUNNEL_SHA1_LEN); inp->legacy_key_id[idx] = elt; @@ -104,22 +104,22 @@ hs_cell_introduce1_set_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx, uint } uint8_t * -hs_cell_introduce1_getarray_legacy_key_id(hs_cell_introduce1_t *inp) +trn_cell_introduce1_getarray_legacy_key_id(trn_cell_introduce1_t *inp) { return inp->legacy_key_id; } const uint8_t * -hs_cell_introduce1_getconstarray_legacy_key_id(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_getconstarray_legacy_key_id(const trn_cell_introduce1_t *inp) { - return (const uint8_t *)hs_cell_introduce1_getarray_legacy_key_id((hs_cell_introduce1_t*)inp); + return (const uint8_t *)trn_cell_introduce1_getarray_legacy_key_id((trn_cell_introduce1_t*)inp); } uint8_t -hs_cell_introduce1_get_auth_key_type(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_get_auth_key_type(const trn_cell_introduce1_t *inp) { return inp->auth_key_type; } int -hs_cell_introduce1_set_auth_key_type(hs_cell_introduce1_t *inp, uint8_t val) +trn_cell_introduce1_set_auth_key_type(trn_cell_introduce1_t *inp, uint8_t val) { if (! ((val == 0 || val == 1 || val == 2))) { TRUNNEL_SET_ERROR_CODE(inp); @@ -129,41 +129,41 @@ hs_cell_introduce1_set_auth_key_type(hs_cell_introduce1_t *inp, uint8_t val) return 0; } uint16_t -hs_cell_introduce1_get_auth_key_len(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_get_auth_key_len(const trn_cell_introduce1_t *inp) { return inp->auth_key_len; } int -hs_cell_introduce1_set_auth_key_len(hs_cell_introduce1_t *inp, uint16_t val) +trn_cell_introduce1_set_auth_key_len(trn_cell_introduce1_t *inp, uint16_t val) { inp->auth_key_len = val; return 0; } size_t -hs_cell_introduce1_getlen_auth_key(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_getlen_auth_key(const trn_cell_introduce1_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->auth_key); } uint8_t -hs_cell_introduce1_get_auth_key(hs_cell_introduce1_t *inp, size_t idx) +trn_cell_introduce1_get_auth_key(trn_cell_introduce1_t *inp, size_t idx) { return TRUNNEL_DYNARRAY_GET(&inp->auth_key, idx); } uint8_t -hs_cell_introduce1_getconst_auth_key(const hs_cell_introduce1_t *inp, size_t idx) +trn_cell_introduce1_getconst_auth_key(const trn_cell_introduce1_t *inp, size_t idx) { - return hs_cell_introduce1_get_auth_key((hs_cell_introduce1_t*)inp, idx); + return trn_cell_introduce1_get_auth_key((trn_cell_introduce1_t*)inp, idx); } int -hs_cell_introduce1_set_auth_key(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt) +trn_cell_introduce1_set_auth_key(trn_cell_introduce1_t *inp, size_t idx, uint8_t elt) { TRUNNEL_DYNARRAY_SET(&inp->auth_key, idx, elt); return 0; } int -hs_cell_introduce1_add_auth_key(hs_cell_introduce1_t *inp, uint8_t elt) +trn_cell_introduce1_add_auth_key(trn_cell_introduce1_t *inp, uint8_t elt) { #if SIZE_MAX >= UINT16_MAX if (inp->auth_key.n_ == UINT16_MAX) @@ -177,17 +177,17 @@ hs_cell_introduce1_add_auth_key(hs_cell_introduce1_t *inp, uint8_t elt) } uint8_t * -hs_cell_introduce1_getarray_auth_key(hs_cell_introduce1_t *inp) +trn_cell_introduce1_getarray_auth_key(trn_cell_introduce1_t *inp) { return inp->auth_key.elts_; } const uint8_t * -hs_cell_introduce1_getconstarray_auth_key(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_getconstarray_auth_key(const trn_cell_introduce1_t *inp) { - return (const uint8_t *)hs_cell_introduce1_getarray_auth_key((hs_cell_introduce1_t*)inp); + return (const uint8_t *)trn_cell_introduce1_getarray_auth_key((trn_cell_introduce1_t*)inp); } int -hs_cell_introduce1_setlen_auth_key(hs_cell_introduce1_t *inp, size_t newlen) +trn_cell_introduce1_setlen_auth_key(trn_cell_introduce1_t *inp, size_t newlen) { uint8_t *newptr; #if UINT16_MAX < SIZE_MAX @@ -206,54 +206,54 @@ hs_cell_introduce1_setlen_auth_key(hs_cell_introduce1_t *inp, size_t newlen) TRUNNEL_SET_ERROR_CODE(inp); return -1; } -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) { return inp->extensions; } -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) { - return hs_cell_introduce1_get_extensions((hs_cell_introduce1_t*) inp); + return trn_cell_introduce1_get_extensions((trn_cell_introduce1_t*) inp); } int -hs_cell_introduce1_set_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val) +trn_cell_introduce1_set_extensions(trn_cell_introduce1_t *inp, struct trn_cell_extension_st *val) { if (inp->extensions && inp->extensions != val) - cell_extension_free(inp->extensions); - return hs_cell_introduce1_set0_extensions(inp, val); + trn_cell_extension_free(inp->extensions); + return trn_cell_introduce1_set0_extensions(inp, val); } int -hs_cell_introduce1_set0_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val) +trn_cell_introduce1_set0_extensions(trn_cell_introduce1_t *inp, struct trn_cell_extension_st *val) { inp->extensions = val; return 0; } size_t -hs_cell_introduce1_getlen_encrypted(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_getlen_encrypted(const trn_cell_introduce1_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->encrypted); } uint8_t -hs_cell_introduce1_get_encrypted(hs_cell_introduce1_t *inp, size_t idx) +trn_cell_introduce1_get_encrypted(trn_cell_introduce1_t *inp, size_t idx) { return TRUNNEL_DYNARRAY_GET(&inp->encrypted, idx); } uint8_t -hs_cell_introduce1_getconst_encrypted(const hs_cell_introduce1_t *inp, size_t idx) +trn_cell_introduce1_getconst_encrypted(const trn_cell_introduce1_t *inp, size_t idx) { - return hs_cell_introduce1_get_encrypted((hs_cell_introduce1_t*)inp, idx); + return trn_cell_introduce1_get_encrypted((trn_cell_introduce1_t*)inp, idx); } int -hs_cell_introduce1_set_encrypted(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt) +trn_cell_introduce1_set_encrypted(trn_cell_introduce1_t *inp, size_t idx, uint8_t elt) { TRUNNEL_DYNARRAY_SET(&inp->encrypted, idx, elt); return 0; } int -hs_cell_introduce1_add_encrypted(hs_cell_introduce1_t *inp, uint8_t elt) +trn_cell_introduce1_add_encrypted(trn_cell_introduce1_t *inp, uint8_t elt) { TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->encrypted, elt, {}); return 0; @@ -263,17 +263,17 @@ hs_cell_introduce1_add_encrypted(hs_cell_introduce1_t *inp, uint8_t elt) } uint8_t * -hs_cell_introduce1_getarray_encrypted(hs_cell_introduce1_t *inp) +trn_cell_introduce1_getarray_encrypted(trn_cell_introduce1_t *inp) { return inp->encrypted.elts_; } const uint8_t * -hs_cell_introduce1_getconstarray_encrypted(const hs_cell_introduce1_t *inp) +trn_cell_introduce1_getconstarray_encrypted(const trn_cell_introduce1_t *inp) { - return (const uint8_t *)hs_cell_introduce1_getarray_encrypted((hs_cell_introduce1_t*)inp); + return (const uint8_t *)trn_cell_introduce1_getarray_encrypted((trn_cell_introduce1_t*)inp); } int -hs_cell_introduce1_setlen_encrypted(hs_cell_introduce1_t *inp, size_t newlen) +trn_cell_introduce1_setlen_encrypted(trn_cell_introduce1_t *inp, size_t newlen) { uint8_t *newptr; newptr = trunnel_dynarray_setlen(&inp->encrypted.allocated_, @@ -289,7 +289,7 @@ hs_cell_introduce1_setlen_encrypted(hs_cell_introduce1_t *inp, size_t newlen) return -1; } const char * -hs_cell_introduce1_check(const hs_cell_introduce1_t *obj) +trn_cell_introduce1_check(const trn_cell_introduce1_t *obj) { if (obj == NULL) return "Object was NULL"; @@ -301,18 +301,18 @@ hs_cell_introduce1_check(const hs_cell_introduce1_t *obj) return "Length mismatch for auth_key"; { const char *msg; - if (NULL != (msg = cell_extension_check(obj->extensions))) + if (NULL != (msg = trn_cell_extension_check(obj->extensions))) return msg; } return NULL; } ssize_t -hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj) +trn_cell_introduce1_encoded_len(const trn_cell_introduce1_t *obj) { ssize_t result = 0; - if (NULL != hs_cell_introduce1_check(obj)) + if (NULL != trn_cell_introduce1_check(obj)) return -1; @@ -328,32 +328,32 @@ hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj) /* Length of u8 auth_key[auth_key_len] */ result += TRUNNEL_DYNARRAY_LEN(&obj->auth_key); - /* Length of struct cell_extension extensions */ - result += cell_extension_encoded_len(obj->extensions); + /* Length of struct trn_cell_extension extensions */ + result += trn_cell_extension_encoded_len(obj->extensions); /* Length of u8 encrypted[] */ result += TRUNNEL_DYNARRAY_LEN(&obj->encrypted); return result; } int -hs_cell_introduce1_clear_errors(hs_cell_introduce1_t *obj) +trn_cell_introduce1_clear_errors(trn_cell_introduce1_t *obj) { int r = obj->trunnel_error_code_; obj->trunnel_error_code_ = 0; return r; } ssize_t -hs_cell_introduce1_encode(uint8_t *output, const size_t avail, const hs_cell_introduce1_t *obj) +trn_cell_introduce1_encode(uint8_t *output, const size_t avail, const trn_cell_introduce1_t *obj) { ssize_t result = 0; size_t written = 0; uint8_t *ptr = output; const char *msg; #ifdef TRUNNEL_CHECK_ENCODED_LEN - const ssize_t encoded_len = hs_cell_introduce1_encoded_len(obj); + const ssize_t encoded_len = trn_cell_introduce1_encoded_len(obj); #endif - if (NULL != (msg = hs_cell_introduce1_check(obj))) + if (NULL != (msg = trn_cell_introduce1_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN @@ -393,9 +393,9 @@ hs_cell_introduce1_encode(uint8_t *output, const size_t avail, const hs_cell_int written += elt_len; ptr += elt_len; } - /* Encode struct cell_extension extensions */ + /* Encode struct trn_cell_extension extensions */ 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) goto fail; /* XXXXXXX !*/ written += result; ptr += result; @@ -435,11 +435,11 @@ hs_cell_introduce1_encode(uint8_t *output, const size_t avail, const hs_cell_int return result; } -/** As hs_cell_introduce1_parse(), but do not allocate the output +/** As trn_cell_introduce1_parse(), but do not allocate the output * object. */ static ssize_t -hs_cell_introduce1_parse_into(hs_cell_introduce1_t *obj, const uint8_t *input, const size_t len_in) +trn_cell_introduce1_parse_into(trn_cell_introduce1_t *obj, const uint8_t *input, const size_t len_in) { const uint8_t *ptr = input; size_t remaining = len_in; @@ -471,8 +471,8 @@ hs_cell_introduce1_parse_into(hs_cell_introduce1_t *obj, const uint8_t *input, c memcpy(obj->auth_key.elts_, ptr, obj->auth_key_len); ptr += obj->auth_key_len; remaining -= obj->auth_key_len; - /* Parse struct cell_extension extensions */ - result = cell_extension_parse(&obj->extensions, ptr, remaining); + /* Parse struct trn_cell_extension extensions */ + result = trn_cell_extension_parse(&obj->extensions, ptr, remaining); if (result < 0) goto relay_fail; trunnel_assert((size_t)result <= remaining); @@ -500,23 +500,23 @@ hs_cell_introduce1_parse_into(hs_cell_introduce1_t *obj, const uint8_t *input, c } ssize_t -hs_cell_introduce1_parse(hs_cell_introduce1_t **output, const uint8_t *input, const size_t len_in) +trn_cell_introduce1_parse(trn_cell_introduce1_t **output, const uint8_t *input, const size_t len_in) { ssize_t result; - *output = hs_cell_introduce1_new(); + *output = trn_cell_introduce1_new(); if (NULL == *output) return -1; - result = hs_cell_introduce1_parse_into(*output, input, len_in); + result = trn_cell_introduce1_parse_into(*output, input, len_in); if (result < 0) { - hs_cell_introduce1_free(*output); + trn_cell_introduce1_free(*output); *output = NULL; } return result; } -hs_cell_introduce_ack_t * -hs_cell_introduce_ack_new(void) +trn_cell_introduce_ack_t * +trn_cell_introduce_ack_new(void) { - hs_cell_introduce_ack_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_ack_t)); + trn_cell_introduce_ack_t *val = trunnel_calloc(1, sizeof(trn_cell_introduce_ack_t)); if (NULL == val) return NULL; return val; @@ -525,30 +525,30 @@ hs_cell_introduce_ack_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ static void -hs_cell_introduce_ack_clear(hs_cell_introduce_ack_t *obj) +trn_cell_introduce_ack_clear(trn_cell_introduce_ack_t *obj) { (void) obj; - cell_extension_free(obj->extensions); + trn_cell_extension_free(obj->extensions); obj->extensions = NULL; } void -hs_cell_introduce_ack_free(hs_cell_introduce_ack_t *obj) +trn_cell_introduce_ack_free(trn_cell_introduce_ack_t *obj) { if (obj == NULL) return; - hs_cell_introduce_ack_clear(obj); - trunnel_memwipe(obj, sizeof(hs_cell_introduce_ack_t)); + trn_cell_introduce_ack_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_introduce_ack_t)); trunnel_free_(obj); } uint16_t -hs_cell_introduce_ack_get_status(const hs_cell_introduce_ack_t *inp) +trn_cell_introduce_ack_get_status(const trn_cell_introduce_ack_t *inp) { return inp->status; } int -hs_cell_introduce_ack_set_status(hs_cell_introduce_ack_t *inp, uint16_t val) +trn_cell_introduce_ack_set_status(trn_cell_introduce_ack_t *inp, uint16_t val) { if (! ((val == 0 || val == 1 || val == 2))) { TRUNNEL_SET_ERROR_CODE(inp); @@ -557,31 +557,31 @@ hs_cell_introduce_ack_set_status(hs_cell_introduce_ack_t *inp, uint16_t val) inp->status = val; return 0; } -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) { return inp->extensions; } -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) { - return hs_cell_introduce_ack_get_extensions((hs_cell_introduce_ack_t*) inp); + return trn_cell_introduce_ack_get_extensions((trn_cell_introduce_ack_t*) inp); } int -hs_cell_introduce_ack_set_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val) +trn_cell_introduce_ack_set_extensions(trn_cell_introduce_ack_t *inp, struct trn_cell_extension_st *val) { if (inp->extensions && inp->extensions != val) - cell_extension_free(inp->extensions); - return hs_cell_introduce_ack_set0_extensions(inp, val); + trn_cell_extension_free(inp->extensions); + return trn_cell_introduce_ack_set0_extensions(inp, val); } int -hs_cell_introduce_ack_set0_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val) +trn_cell_introduce_ack_set0_extensions(trn_cell_introduce_ack_t *inp, struct trn_cell_extension_st *val) { inp->extensions = val; return 0; } const char * -hs_cell_introduce_ack_check(const hs_cell_introduce_ack_t *obj) +trn_cell_introduce_ack_check(const trn_cell_introduce_ack_t *obj) { if (obj == NULL) return "Object was NULL"; @@ -591,47 +591,47 @@ hs_cell_introduce_ack_check(const hs_cell_introduce_ack_t *obj) return "Integer out of bounds"; { const char *msg; - if (NULL != (msg = cell_extension_check(obj->extensions))) + if (NULL != (msg = trn_cell_extension_check(obj->extensions))) return msg; } return NULL; } ssize_t -hs_cell_introduce_ack_encoded_len(const hs_cell_introduce_ack_t *obj) +trn_cell_introduce_ack_encoded_len(const trn_cell_introduce_ack_t *obj) { ssize_t result = 0; - if (NULL != hs_cell_introduce_ack_check(obj)) + if (NULL != trn_cell_introduce_ack_check(obj)) return -1; /* Length of u16 status IN [0, 1, 2] */ result += 2; - /* Length of struct cell_extension extensions */ - result += cell_extension_encoded_len(obj->extensions); + /* Length of struct trn_cell_extension extensions */ + result += trn_cell_extension_encoded_len(obj->extensions); return result; } int -hs_cell_introduce_ack_clear_errors(hs_cell_introduce_ack_t *obj) +trn_cell_introduce_ack_clear_errors(trn_cell_introduce_ack_t *obj) { int r = obj->trunnel_error_code_; obj->trunnel_error_code_ = 0; return r; } ssize_t -hs_cell_introduce_ack_encode(uint8_t *output, const size_t avail, const hs_cell_introduce_ack_t *obj) +trn_cell_introduce_ack_encode(uint8_t *output, const size_t avail, const trn_cell_introduce_ack_t *obj) { ssize_t result = 0; size_t written = 0; uint8_t *ptr = output; const char *msg; #ifdef TRUNNEL_CHECK_ENCODED_LEN - const ssize_t encoded_len = hs_cell_introduce_ack_encoded_len(obj); + const ssize_t encoded_len = trn_cell_introduce_ack_encoded_len(obj); #endif - if (NULL != (msg = hs_cell_introduce_ack_check(obj))) + if (NULL != (msg = trn_cell_introduce_ack_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN @@ -645,9 +645,9 @@ hs_cell_introduce_ack_encode(uint8_t *output, const size_t avail, const hs_cell_ trunnel_set_uint16(ptr, trunnel_htons(obj->status)); written += 2; ptr += 2; - /* Encode struct cell_extension extensions */ + /* Encode struct trn_cell_extension extensions */ 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) goto fail; /* XXXXXXX !*/ written += result; ptr += result; @@ -676,11 +676,11 @@ hs_cell_introduce_ack_encode(uint8_t *output, const size_t avail, const hs_cell_ return result; } -/** As hs_cell_introduce_ack_parse(), but do not allocate the output +/** As trn_cell_introduce_ack_parse(), but do not allocate the output * object. */ static ssize_t -hs_cell_introduce_ack_parse_into(hs_cell_introduce_ack_t *obj, const uint8_t *input, const size_t len_in) +trn_cell_introduce_ack_parse_into(trn_cell_introduce_ack_t *obj, const uint8_t *input, const size_t len_in) { const uint8_t *ptr = input; size_t remaining = len_in; @@ -694,8 +694,8 @@ hs_cell_introduce_ack_parse_into(hs_cell_introduce_ack_t *obj, const uint8_t *in if (! (obj->status == 0 || obj->status == 1 || obj->status == 2)) goto fail; - /* Parse struct cell_extension extensions */ - result = cell_extension_parse(&obj->extensions, ptr, remaining); + /* Parse struct trn_cell_extension extensions */ + result = trn_cell_extension_parse(&obj->extensions, ptr, remaining); if (result < 0) goto relay_fail; trunnel_assert((size_t)result <= remaining); @@ -714,23 +714,23 @@ hs_cell_introduce_ack_parse_into(hs_cell_introduce_ack_t *obj, const uint8_t *in } ssize_t -hs_cell_introduce_ack_parse(hs_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in) +trn_cell_introduce_ack_parse(trn_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in) { ssize_t result; - *output = hs_cell_introduce_ack_new(); + *output = trn_cell_introduce_ack_new(); if (NULL == *output) return -1; - result = hs_cell_introduce_ack_parse_into(*output, input, len_in); + result = trn_cell_introduce_ack_parse_into(*output, input, len_in); if (result < 0) { - hs_cell_introduce_ack_free(*output); + trn_cell_introduce_ack_free(*output); *output = NULL; } return result; } -hs_cell_introduce_encrypted_t * -hs_cell_introduce_encrypted_new(void) +trn_cell_introduce_encrypted_t * +trn_cell_introduce_encrypted_new(void) { - hs_cell_introduce_encrypted_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_encrypted_t)); + trn_cell_introduce_encrypted_t *val = trunnel_calloc(1, sizeof(trn_cell_introduce_encrypted_t)); if (NULL == val) return NULL; val->onion_key_type = 1; @@ -740,10 +740,10 @@ hs_cell_introduce_encrypted_new(void) /** Release all storage held inside 'obj', but do not free 'obj'. */ static void -hs_cell_introduce_encrypted_clear(hs_cell_introduce_encrypted_t *obj) +trn_cell_introduce_encrypted_clear(trn_cell_introduce_encrypted_t *obj) { (void) obj; - cell_extension_free(obj->extensions); + trn_cell_extension_free(obj->extensions); obj->extensions = NULL; TRUNNEL_DYNARRAY_WIPE(&obj->onion_key); TRUNNEL_DYNARRAY_CLEAR(&obj->onion_key); @@ -761,35 +761,35 @@ hs_cell_introduce_encrypted_clear(hs_cell_introduce_encrypted_t *obj) } void -hs_cell_introduce_encrypted_free(hs_cell_introduce_encrypted_t *obj) +trn_cell_introduce_encrypted_free(trn_cell_introduce_encrypted_t *obj) { if (obj == NULL) return; - hs_cell_introduce_encrypted_clear(obj); - trunnel_memwipe(obj, sizeof(hs_cell_introduce_encrypted_t)); + trn_cell_introduce_encrypted_clear(obj); + trunnel_memwipe(obj, sizeof(trn_cell_introduce_encrypted_t)); trunnel_free_(obj); } size_t -hs_cell_introduce_encrypted_getlen_rend_cookie(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getlen_rend_cookie(const trn_cell_introduce_encrypted_t *inp) { (void)inp; return TRUNNEL_REND_COOKIE_LEN; } uint8_t -hs_cell_introduce_encrypted_get_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_get_rend_cookie(trn_cell_introduce_encrypted_t *inp, size_t idx) { trunnel_assert(idx < TRUNNEL_REND_COOKIE_LEN); return inp->rend_cookie[idx]; } uint8_t -hs_cell_introduce_encrypted_getconst_rend_cookie(const hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_getconst_rend_cookie(const trn_cell_introduce_encrypted_t *inp, size_t idx) { - return hs_cell_introduce_encrypted_get_rend_cookie((hs_cell_introduce_encrypted_t*)inp, idx); + return trn_cell_introduce_encrypted_get_rend_cookie((trn_cell_introduce_encrypted_t*)inp, idx); } int -hs_cell_introduce_encrypted_set_rend_cookie(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt) +trn_cell_introduce_encrypted_set_rend_cookie(trn_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt) { trunnel_assert(idx < TRUNNEL_REND_COOKIE_LEN); inp->rend_cookie[idx] = elt; @@ -797,45 +797,45 @@ hs_cell_introduce_encrypted_set_rend_cookie(hs_cell_introduce_encrypted_t *inp, } uint8_t * -hs_cell_introduce_encrypted_getarray_rend_cookie(hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getarray_rend_cookie(trn_cell_introduce_encrypted_t *inp) { return inp->rend_cookie; } const uint8_t * -hs_cell_introduce_encrypted_getconstarray_rend_cookie(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getconstarray_rend_cookie(const trn_cell_introduce_encrypted_t *inp) { - return (const uint8_t *)hs_cell_introduce_encrypted_getarray_rend_cookie((hs_cell_introduce_encrypted_t*)inp); + return (const uint8_t *)trn_cell_introduce_encrypted_getarray_rend_cookie((trn_cell_introduce_encrypted_t*)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) { return inp->extensions; } -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) { - return hs_cell_introduce_encrypted_get_extensions((hs_cell_introduce_encrypted_t*) inp); + return trn_cell_introduce_encrypted_get_extensions((trn_cell_introduce_encrypted_t*) inp); } int -hs_cell_introduce_encrypted_set_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val) +trn_cell_introduce_encrypted_set_extensions(trn_cell_introduce_encrypted_t *inp, struct trn_cell_extension_st *val) { if (inp->extensions && inp->extensions != val) - cell_extension_free(inp->extensions); - return hs_cell_introduce_encrypted_set0_extensions(inp, val); + trn_cell_extension_free(inp->extensions); + return trn_cell_introduce_encrypted_set0_extensions(inp, val); } int -hs_cell_introduce_encrypted_set0_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val) +trn_cell_introduce_encrypted_set0_extensions(trn_cell_introduce_encrypted_t *inp, struct trn_cell_extension_st *val) { inp->extensions = val; return 0; } uint8_t -hs_cell_introduce_encrypted_get_onion_key_type(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_get_onion_key_type(const trn_cell_introduce_encrypted_t *inp) { return inp->onion_key_type; } int -hs_cell_introduce_encrypted_set_onion_key_type(hs_cell_introduce_encrypted_t *inp, uint8_t val) +trn_cell_introduce_encrypted_set_onion_key_type(trn_cell_introduce_encrypted_t *inp, uint8_t val) { if (! ((val == 1))) { TRUNNEL_SET_ERROR_CODE(inp); @@ -845,41 +845,41 @@ hs_cell_introduce_encrypted_set_onion_key_type(hs_cell_introduce_encrypted_t *in return 0; } uint16_t -hs_cell_introduce_encrypted_get_onion_key_len(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_get_onion_key_len(const trn_cell_introduce_encrypted_t *inp) { return inp->onion_key_len; } int -hs_cell_introduce_encrypted_set_onion_key_len(hs_cell_introduce_encrypted_t *inp, uint16_t val) +trn_cell_introduce_encrypted_set_onion_key_len(trn_cell_introduce_encrypted_t *inp, uint16_t val) { inp->onion_key_len = val; return 0; } size_t -hs_cell_introduce_encrypted_getlen_onion_key(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getlen_onion_key(const trn_cell_introduce_encrypted_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->onion_key); } uint8_t -hs_cell_introduce_encrypted_get_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_get_onion_key(trn_cell_introduce_encrypted_t *inp, size_t idx) { return TRUNNEL_DYNARRAY_GET(&inp->onion_key, idx); } uint8_t -hs_cell_introduce_encrypted_getconst_onion_key(const hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_getconst_onion_key(const trn_cell_introduce_encrypted_t *inp, size_t idx) { - return hs_cell_introduce_encrypted_get_onion_key((hs_cell_introduce_encrypted_t*)inp, idx); + return trn_cell_introduce_encrypted_get_onion_key((trn_cell_introduce_encrypted_t*)inp, idx); } int -hs_cell_introduce_encrypted_set_onion_key(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt) +trn_cell_introduce_encrypted_set_onion_key(trn_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt) { TRUNNEL_DYNARRAY_SET(&inp->onion_key, idx, elt); return 0; } int -hs_cell_introduce_encrypted_add_onion_key(hs_cell_introduce_encrypted_t *inp, uint8_t elt) +trn_cell_introduce_encrypted_add_onion_key(trn_cell_introduce_encrypted_t *inp, uint8_t elt) { #if SIZE_MAX >= UINT16_MAX if (inp->onion_key.n_ == UINT16_MAX) @@ -893,17 +893,17 @@ hs_cell_introduce_encrypted_add_onion_key(hs_cell_introduce_encrypted_t *inp, ui } uint8_t * -hs_cell_introduce_encrypted_getarray_onion_key(hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getarray_onion_key(trn_cell_introduce_encrypted_t *inp) { return inp->onion_key.elts_; } const uint8_t * -hs_cell_introduce_encrypted_getconstarray_onion_key(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getconstarray_onion_key(const trn_cell_introduce_encrypted_t *inp) { - return (const uint8_t *)hs_cell_introduce_encrypted_getarray_onion_key((hs_cell_introduce_encrypted_t*)inp); + return (const uint8_t *)trn_cell_introduce_encrypted_getarray_onion_key((trn_cell_introduce_encrypted_t*)inp); } int -hs_cell_introduce_encrypted_setlen_onion_key(hs_cell_introduce_encrypted_t *inp, size_t newlen) +trn_cell_introduce_encrypted_setlen_onion_key(trn_cell_introduce_encrypted_t *inp, size_t newlen) { uint8_t *newptr; #if UINT16_MAX < SIZE_MAX @@ -923,49 +923,49 @@ hs_cell_introduce_encrypted_setlen_onion_key(hs_cell_introduce_encrypted_t *inp, return -1; } uint8_t -hs_cell_introduce_encrypted_get_nspec(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_get_nspec(const trn_cell_introduce_encrypted_t *inp) { return inp->nspec; } int -hs_cell_introduce_encrypted_set_nspec(hs_cell_introduce_encrypted_t *inp, uint8_t val) +trn_cell_introduce_encrypted_set_nspec(trn_cell_introduce_encrypted_t *inp, uint8_t val) { inp->nspec = val; return 0; } size_t -hs_cell_introduce_encrypted_getlen_nspecs(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getlen_nspecs(const trn_cell_introduce_encrypted_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->nspecs); } struct link_specifier_st * -hs_cell_introduce_encrypted_get_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_get_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx) { return TRUNNEL_DYNARRAY_GET(&inp->nspecs, idx); } const struct link_specifier_st * -hs_cell_introduce_encrypted_getconst_nspecs(const hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_getconst_nspecs(const trn_cell_introduce_encrypted_t *inp, size_t idx) { - return hs_cell_introduce_encrypted_get_nspecs((hs_cell_introduce_encrypted_t*)inp, idx); + return trn_cell_introduce_encrypted_get_nspecs((trn_cell_introduce_encrypted_t*)inp, idx); } int -hs_cell_introduce_encrypted_set_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt) +trn_cell_introduce_encrypted_set_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt) { link_specifier_t *oldval = TRUNNEL_DYNARRAY_GET(&inp->nspecs, idx); if (oldval && oldval != elt) link_specifier_free(oldval); - return hs_cell_introduce_encrypted_set0_nspecs(inp, idx, elt); + return trn_cell_introduce_encrypted_set0_nspecs(inp, idx, elt); } int -hs_cell_introduce_encrypted_set0_nspecs(hs_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt) +trn_cell_introduce_encrypted_set0_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt) { TRUNNEL_DYNARRAY_SET(&inp->nspecs, idx, elt); return 0; } int -hs_cell_introduce_encrypted_add_nspecs(hs_cell_introduce_encrypted_t *inp, struct link_specifier_st * elt) +trn_cell_introduce_encrypted_add_nspecs(trn_cell_introduce_encrypted_t *inp, struct link_specifier_st * elt) { #if SIZE_MAX >= UINT8_MAX if (inp->nspecs.n_ == UINT8_MAX) @@ -979,17 +979,17 @@ hs_cell_introduce_encrypted_add_nspecs(hs_cell_introduce_encrypted_t *inp, struc } struct link_specifier_st * * -hs_cell_introduce_encrypted_getarray_nspecs(hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getarray_nspecs(trn_cell_introduce_encrypted_t *inp) { return inp->nspecs.elts_; } const struct link_specifier_st * const * -hs_cell_introduce_encrypted_getconstarray_nspecs(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getconstarray_nspecs(const trn_cell_introduce_encrypted_t *inp) { - return (const struct link_specifier_st * const *)hs_cell_introduce_encrypted_getarray_nspecs((hs_cell_introduce_encrypted_t*)inp); + return (const struct link_specifier_st * const *)trn_cell_introduce_encrypted_getarray_nspecs((trn_cell_introduce_encrypted_t*)inp); } int -hs_cell_introduce_encrypted_setlen_nspecs(hs_cell_introduce_encrypted_t *inp, size_t newlen) +trn_cell_introduce_encrypted_setlen_nspecs(trn_cell_introduce_encrypted_t *inp, size_t newlen) { struct link_specifier_st * *newptr; #if UINT8_MAX < SIZE_MAX @@ -1009,30 +1009,30 @@ hs_cell_introduce_encrypted_setlen_nspecs(hs_cell_introduce_encrypted_t *inp, si return -1; } size_t -hs_cell_introduce_encrypted_getlen_pad(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getlen_pad(const trn_cell_introduce_encrypted_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->pad); } uint8_t -hs_cell_introduce_encrypted_get_pad(hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_get_pad(trn_cell_introduce_encrypted_t *inp, size_t idx) { return TRUNNEL_DYNARRAY_GET(&inp->pad, idx); } uint8_t -hs_cell_introduce_encrypted_getconst_pad(const hs_cell_introduce_encrypted_t *inp, size_t idx) +trn_cell_introduce_encrypted_getconst_pad(const trn_cell_introduce_encrypted_t *inp, size_t idx) { - return hs_cell_introduce_encrypted_get_pad((hs_cell_introduce_encrypted_t*)inp, idx); + return trn_cell_introduce_encrypted_get_pad((trn_cell_introduce_encrypted_t*)inp, idx); } int -hs_cell_introduce_encrypted_set_pad(hs_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt) +trn_cell_introduce_encrypted_set_pad(trn_cell_introduce_encrypted_t *inp, size_t idx, uint8_t elt) { TRUNNEL_DYNARRAY_SET(&inp->pad, idx, elt); return 0; } int -hs_cell_introduce_encrypted_add_pad(hs_cell_introduce_encrypted_t *inp, uint8_t elt) +trn_cell_introduce_encrypted_add_pad(trn_cell_introduce_encrypted_t *inp, uint8_t elt) { TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->pad, elt, {}); return 0; @@ -1042,17 +1042,17 @@ hs_cell_introduce_encrypted_add_pad(hs_cell_introduce_encrypted_t *inp, uint8_t } uint8_t * -hs_cell_introduce_encrypted_getarray_pad(hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getarray_pad(trn_cell_introduce_encrypted_t *inp) { return inp->pad.elts_; } const uint8_t * -hs_cell_introduce_encrypted_getconstarray_pad(const hs_cell_introduce_encrypted_t *inp) +trn_cell_introduce_encrypted_getconstarray_pad(const trn_cell_introduce_encrypted_t *inp) { - return (const uint8_t *)hs_cell_introduce_encrypted_getarray_pad((hs_cell_introduce_encrypted_t*)inp); + return (const uint8_t *)trn_cell_introduce_encrypted_getarray_pad((trn_cell_introduce_encrypted_t*)inp); } int -hs_cell_introduce_encrypted_setlen_pad(hs_cell_introduce_encrypted_t *inp, size_t newlen) +trn_cell_introduce_encrypted_setlen_pad(trn_cell_introduce_encrypted_t *inp, size_t newlen) { uint8_t *newptr; newptr = trunnel_dynarray_setlen(&inp->pad.allocated_, @@ -1068,7 +1068,7 @@ hs_cell_introduce_encrypted_setlen_pad(hs_cell_introduce_encrypted_t *inp, size_ return -1; } const char * -hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj) +trn_cell_introduce_encrypted_check(const trn_cell_introduce_encrypted_t *obj) { if (obj == NULL) return "Object was NULL"; @@ -1076,7 +1076,7 @@ hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj) return "A set function failed on this object"; { const char *msg; - if (NULL != (msg = cell_extension_check(obj->extensions))) + if (NULL != (msg = trn_cell_extension_check(obj->extensions))) return msg; } if (! (obj->onion_key_type == 1)) @@ -1098,19 +1098,19 @@ hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj) } ssize_t -hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj) +trn_cell_introduce_encrypted_encoded_len(const trn_cell_introduce_encrypted_t *obj) { ssize_t result = 0; - if (NULL != hs_cell_introduce_encrypted_check(obj)) + if (NULL != trn_cell_introduce_encrypted_check(obj)) return -1; /* Length of u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN] */ result += TRUNNEL_REND_COOKIE_LEN; - /* Length of struct cell_extension extensions */ - result += cell_extension_encoded_len(obj->extensions); + /* Length of struct trn_cell_extension extensions */ + result += trn_cell_extension_encoded_len(obj->extensions); /* Length of u8 onion_key_type IN [1] */ result += 1; @@ -1138,24 +1138,24 @@ hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj return result; } int -hs_cell_introduce_encrypted_clear_errors(hs_cell_introduce_encrypted_t *obj) +trn_cell_introduce_encrypted_clear_errors(trn_cell_introduce_encrypted_t *obj) { int r = obj->trunnel_error_code_; obj->trunnel_error_code_ = 0; return r; } ssize_t -hs_cell_introduce_encrypted_encode(uint8_t *output, const size_t avail, const hs_cell_introduce_encrypted_t *obj) +trn_cell_introduce_encrypted_encode(uint8_t *output, const size_t avail, const trn_cell_introduce_encrypted_t *obj) { ssize_t result = 0; size_t written = 0; uint8_t *ptr = output; const char *msg; #ifdef TRUNNEL_CHECK_ENCODED_LEN - const ssize_t encoded_len = hs_cell_introduce_encrypted_encoded_len(obj); + const ssize_t encoded_len = trn_cell_introduce_encrypted_encoded_len(obj); #endif - if (NULL != (msg = hs_cell_introduce_encrypted_check(obj))) + if (NULL != (msg = trn_cell_introduce_encrypted_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN @@ -1169,9 +1169,9 @@ hs_cell_introduce_encrypted_encode(uint8_t *output, const size_t avail, const hs memcpy(ptr, obj->rend_cookie, TRUNNEL_REND_COOKIE_LEN); written += TRUNNEL_REND_COOKIE_LEN; ptr += TRUNNEL_REND_COOKIE_LEN; - /* Encode struct cell_extension extensions */ + /* Encode struct trn_cell_extension extensions */ 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) goto fail; /* XXXXXXX !*/ written += result; ptr += result; @@ -1257,11 +1257,11 @@ hs_cell_introduce_encrypted_encode(uint8_t *output, const size_t avail, const hs return result; } -/** As hs_cell_introduce_encrypted_parse(), but do not allocate the +/** As trn_cell_introduce_encrypted_parse(), but do not allocate the * output object. */ static ssize_t -hs_cell_introduce_encrypted_parse_into(hs_cell_introduce_encrypted_t *obj, const uint8_t *input, const size_t len_in) +trn_cell_introduce_encrypted_parse_into(trn_cell_introduce_encrypted_t *obj, const uint8_t *input, const size_t len_in) { const uint8_t *ptr = input; size_t remaining = len_in; @@ -1273,8 +1273,8 @@ hs_cell_introduce_encrypted_parse_into(hs_cell_introduce_encrypted_t *obj, const memcpy(obj->rend_cookie, ptr, TRUNNEL_REND_COOKIE_LEN); remaining -= TRUNNEL_REND_COOKIE_LEN; ptr += TRUNNEL_REND_COOKIE_LEN; - /* Parse struct cell_extension extensions */ - result = cell_extension_parse(&obj->extensions, ptr, remaining); + /* Parse struct trn_cell_extension extensions */ + result = trn_cell_extension_parse(&obj->extensions, ptr, remaining); if (result < 0) goto relay_fail; trunnel_assert((size_t)result <= remaining); @@ -1342,15 +1342,15 @@ hs_cell_introduce_encrypted_parse_into(hs_cell_introduce_encrypted_t *obj, const } ssize_t -hs_cell_introduce_encrypted_parse(hs_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in) +trn_cell_introduce_encrypted_parse(trn_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in) { ssize_t result; - *output = hs_cell_introduce_encrypted_new(); + *output = trn_cell_introduce_encrypted_new(); if (NULL == *output) return -1; - result = hs_cell_introduce_encrypted_parse_into(*output, input, len_in); + result = trn_cell_introduce_encrypted_parse_into(*output, input, len_in); if (result < 0) { - hs_cell_introduce_encrypted_free(*output); + trn_cell_introduce_encrypted_free(*output); *output = NULL; } return result; diff --git a/src/trunnel/hs/cell_introduce1.h b/src/trunnel/hs/cell_introduce1.h index ccd2cda904..cca825a431 100644 --- a/src/trunnel/hs/cell_introduce1.h +++ b/src/trunnel/hs/cell_introduce1.h @@ -8,34 +8,34 @@ #include #include "trunnel.h" -struct cell_extension_st; +struct trn_cell_extension_st; struct link_specifier_st; #define TRUNNEL_SHA1_LEN 20 #define TRUNNEL_REND_COOKIE_LEN 20 -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE1) -struct hs_cell_introduce1_st { +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE1) +struct trn_cell_introduce1_st { uint8_t legacy_key_id[TRUNNEL_SHA1_LEN]; uint8_t auth_key_type; uint16_t auth_key_len; TRUNNEL_DYNARRAY_HEAD(, uint8_t) auth_key; - struct cell_extension_st *extensions; + struct trn_cell_extension_st *extensions; TRUNNEL_DYNARRAY_HEAD(, uint8_t) encrypted; uint8_t trunnel_error_code_; }; #endif -typedef struct hs_cell_introduce1_st hs_cell_introduce1_t; -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE_ACK) -struct hs_cell_introduce_ack_st { +typedef struct trn_cell_introduce1_st trn_cell_introduce1_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE_ACK) +struct trn_cell_introduce_ack_st { uint16_t status; - struct cell_extension_st *extensions; + struct trn_cell_extension_st *extensions; uint8_t trunnel_error_code_; }; #endif -typedef struct hs_cell_introduce_ack_st hs_cell_introduce_ack_t; -#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_HS_CELL_INTRODUCE_ENCRYPTED) -struct hs_cell_introduce_encrypted_st { +typedef struct trn_cell_introduce_ack_st trn_cell_introduce_ack_t; +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_TRN_CELL_INTRODUCE_ENCRYPTED) +struct trn_cell_introduce_encrypted_st { uint8_t rend_cookie[TRUNNEL_REND_COOKIE_LEN]; - struct cell_extension_st *extensions; + struct trn_cell_extension_st *extensions; uint8_t onion_key_type; uint16_t onion_key_len; TRUNNEL_DYNARRAY_HEAD(, uint8_t) onion_key; @@ -45,449 +45,449 @@ struct hs_cell_introduce_encrypted_st { uint8_t trunnel_error_code_; }; #endif -typedef struct hs_cell_introduce_encrypted_st hs_cell_introduce_encrypted_t; -/** Return a newly allocated hs_cell_introduce1 with all elements set +typedef struct trn_cell_introduce_encrypted_st trn_cell_introduce_encrypted_t; +/** Return a newly allocated trn_cell_introduce1 with all elements set * to zero. */ -hs_cell_introduce1_t *hs_cell_introduce1_new(void); -/** Release all storage held by the hs_cell_introduce1 in 'victim'. +trn_cell_introduce1_t *trn_cell_introduce1_new(void); +/** Release all storage held by the trn_cell_introduce1 in 'victim'. * (Do nothing if 'victim' is NULL.) */ -void hs_cell_introduce1_free(hs_cell_introduce1_t *victim); -/** Try to parse a hs_cell_introduce1 from the buffer in 'input', +void trn_cell_introduce1_free(trn_cell_introduce1_t *victim); +/** Try to parse a trn_cell_introduce1 from the buffer in 'input', * using up to 'len_in' bytes from the input buffer. On success, * 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. */ -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 - * 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 * underestimate for certain unencodeable objects. */ -ssize_t hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj); -/** Try to encode the hs_cell_introduce1 from 'input' into the buffer +ssize_t trn_cell_introduce1_encoded_len(const trn_cell_introduce1_t *obj); +/** Try to encode the trn_cell_introduce1 from 'input' into the buffer * at 'output', using up to 'avail' bytes of the output 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 was invalid. */ -ssize_t hs_cell_introduce1_encode(uint8_t *output, size_t avail, const hs_cell_introduce1_t *input); -/** Check whether the internal state of the hs_cell_introduce1 in +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 trn_cell_introduce1 in * 'obj' is consistent. Return NULL if it is, and a short message if * 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 * 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 - * 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 - * 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); -/** As hs_cell_introduce1_get_legacy_key_id, but take and return a +uint8_t trn_cell_introduce1_get_legacy_key_id(trn_cell_introduce1_t *inp, size_t idx); +/** As trn_cell_introduce1_get_legacy_key_id, but take and return a * 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 - * legacy_key_id of the hs_cell_introduce1_t in 'inp', so that it will - * hold the value 'elt'. + * legacy_key_id of the trn_cell_introduce1_t in 'inp', so that it + * 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 * legacy_key_id of 'inp'. */ -uint8_t * hs_cell_introduce1_getarray_legacy_key_id(hs_cell_introduce1_t *inp); -/** As hs_cell_introduce1_get_legacy_key_id, but take and return a +uint8_t * trn_cell_introduce1_getarray_legacy_key_id(trn_cell_introduce1_t *inp); +/** As trn_cell_introduce1_get_legacy_key_id, but take and return a * 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 - * 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 - * hs_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; return - * -1 and set the error code on 'inp' on failure. + * trn_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; + * 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 - * 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 - * hs_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; return - * -1 and set the error code on 'inp' on failure. + * trn_cell_introduce1_t in 'inp' to 'val'. Return 0 on success; + * 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 - * 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 - * 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); -/** As hs_cell_introduce1_get_auth_key, but take and return a const +uint8_t trn_cell_introduce1_get_auth_key(trn_cell_introduce1_t *inp, size_t idx); +/** As trn_cell_introduce1_get_auth_key, but take and return a const * 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 - * auth_key of the hs_cell_introduce1_t in 'inp', so that it will hold - * the value 'elt'. + * auth_key of the trn_cell_introduce1_t in 'inp', so that it will + * 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 - * 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 * 'inp'. */ -uint8_t * hs_cell_introduce1_getarray_auth_key(hs_cell_introduce1_t *inp); -/** As hs_cell_introduce1_get_auth_key, but take and return a const +uint8_t * trn_cell_introduce1_getarray_auth_key(trn_cell_introduce1_t *inp); +/** As trn_cell_introduce1_get_auth_key, but take and return a const * 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 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 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 - * 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); -/** As hs_cell_introduce1_get_extensions, but take and return a const +struct trn_cell_extension_st * trn_cell_introduce1_get_extensions(trn_cell_introduce1_t *inp); +/** As trn_cell_introduce1_get_extensions, but take and return a const * pointer */ -const struct cell_extension_st * hs_cell_introduce1_getconst_extensions(const hs_cell_introduce1_t *inp); -/** Set the value of the extensions field of the hs_cell_introduce1_t +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 trn_cell_introduce1_t * in 'inp' to 'val'. Free the old value if any. Steals the * referenceto 'val'.Return 0 on success; return -1 and set the error * code on 'inp' on failure. */ -int hs_cell_introduce1_set_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val); -/** As hs_cell_introduce1_set_extensions, but does not free the +int trn_cell_introduce1_set_extensions(trn_cell_introduce1_t *inp, struct trn_cell_extension_st *val); +/** As trn_cell_introduce1_set_extensions, but does not free the * 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 - * 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 - * 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); -/** As hs_cell_introduce1_get_encrypted, but take and return a const +uint8_t trn_cell_introduce1_get_encrypted(trn_cell_introduce1_t *inp, size_t idx); +/** As trn_cell_introduce1_get_encrypted, but take and return a const * 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 - * 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'. */ -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 - * 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 * 'inp'. */ -uint8_t * hs_cell_introduce1_getarray_encrypted(hs_cell_introduce1_t *inp); -/** As hs_cell_introduce1_get_encrypted, but take and return a const +uint8_t * trn_cell_introduce1_getarray_encrypted(trn_cell_introduce1_t *inp); +/** As trn_cell_introduce1_get_encrypted, but take and return a const * 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 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 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); -/** Return a newly allocated hs_cell_introduce_ack with all elements +int trn_cell_introduce1_setlen_encrypted(trn_cell_introduce1_t *inp, size_t newlen); +/** Return a newly allocated trn_cell_introduce_ack with all elements * set to zero. */ -hs_cell_introduce_ack_t *hs_cell_introduce_ack_new(void); -/** Release all storage held by the hs_cell_introduce_ack in 'victim'. - * (Do nothing if 'victim' is NULL.) +trn_cell_introduce_ack_t *trn_cell_introduce_ack_new(void); +/** Release all storage held by the trn_cell_introduce_ack in + * 'victim'. (Do nothing if 'victim' is NULL.) */ -void hs_cell_introduce_ack_free(hs_cell_introduce_ack_t *victim); -/** Try to parse a hs_cell_introduce_ack from the buffer in 'input', +void trn_cell_introduce_ack_free(trn_cell_introduce_ack_t *victim); +/** 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, * 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. */ -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 - * 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 * an underestimate for certain unencodeable objects. */ -ssize_t hs_cell_introduce_ack_encoded_len(const hs_cell_introduce_ack_t *obj); -/** Try to encode the hs_cell_introduce_ack from 'input' into the +ssize_t trn_cell_introduce_ack_encoded_len(const trn_cell_introduce_ack_t *obj); +/** Try to encode the trn_cell_introduce_ack from 'input' into the * buffer at 'output', using up to 'avail' bytes of the output 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 was invalid. */ -ssize_t hs_cell_introduce_ack_encode(uint8_t *output, size_t avail, const hs_cell_introduce_ack_t *input); -/** Check whether the internal state of the hs_cell_introduce_ack in +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 trn_cell_introduce_ack in * 'obj' is consistent. Return NULL if it is, and a short message if * 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 * 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 - * 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); -/** Set the value of the status field of the hs_cell_introduce_ack_t +uint16_t trn_cell_introduce_ack_get_status(const trn_cell_introduce_ack_t *inp); +/** 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 * 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 - * 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); -/** As hs_cell_introduce_ack_get_extensions, but take and return a +struct trn_cell_extension_st * trn_cell_introduce_ack_get_extensions(trn_cell_introduce_ack_t *inp); +/** As trn_cell_introduce_ack_get_extensions, but take and return a * 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 - * 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 * 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); -/** As hs_cell_introduce_ack_set_extensions, but does not free the +int trn_cell_introduce_ack_set_extensions(trn_cell_introduce_ack_t *inp, struct trn_cell_extension_st *val); +/** As trn_cell_introduce_ack_set_extensions, but does not free the * previous value. */ -int hs_cell_introduce_ack_set0_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val); -/** Return a newly allocated hs_cell_introduce_encrypted with all +int trn_cell_introduce_ack_set0_extensions(trn_cell_introduce_ack_t *inp, struct trn_cell_extension_st *val); +/** Return a newly allocated trn_cell_introduce_encrypted with all * elements set to zero. */ -hs_cell_introduce_encrypted_t *hs_cell_introduce_encrypted_new(void); -/** Release all storage held by the hs_cell_introduce_encrypted in +trn_cell_introduce_encrypted_t *trn_cell_introduce_encrypted_new(void); +/** Release all storage held by the trn_cell_introduce_encrypted in * 'victim'. (Do nothing if 'victim' is NULL.) */ -void hs_cell_introduce_encrypted_free(hs_cell_introduce_encrypted_t *victim); -/** Try to parse a hs_cell_introduce_encrypted from the buffer in +void trn_cell_introduce_encrypted_free(trn_cell_introduce_encrypted_t *victim); +/** Try to parse a trn_cell_introduce_encrypted from the buffer in * 'input', using up to 'len_in' bytes from the input buffer. On * 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 * 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 - * hs_cell_introduce_encrypted in 'obj'. On failure, return a negative - * value. Note that this value may be an overestimate, and can even be - * an underestimate for certain unencodeable objects. + * trn_cell_introduce_encrypted in 'obj'. On failure, return a + * negative value. Note that this value may be an overestimate, and + * can even be an underestimate for certain unencodeable objects. */ -ssize_t hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj); -/** Try to encode the hs_cell_introduce_encrypted from 'input' into +ssize_t trn_cell_introduce_encrypted_encoded_len(const trn_cell_introduce_encrypted_t *obj); +/** Try to encode the trn_cell_introduce_encrypted from 'input' into * the buffer at 'output', using up to 'avail' bytes of the output * 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 * 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 - * 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. */ -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 * 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 - * 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 - * 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); -/** As hs_cell_introduce_encrypted_get_rend_cookie, but take and +uint8_t trn_cell_introduce_encrypted_get_rend_cookie(trn_cell_introduce_encrypted_t *inp, size_t idx); +/** As trn_cell_introduce_encrypted_get_rend_cookie, but take and * 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 - * 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'. */ -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 * field rend_cookie of 'inp'. */ -uint8_t * hs_cell_introduce_encrypted_getarray_rend_cookie(hs_cell_introduce_encrypted_t *inp); -/** As hs_cell_introduce_encrypted_get_rend_cookie, but take and +uint8_t * trn_cell_introduce_encrypted_getarray_rend_cookie(trn_cell_introduce_encrypted_t *inp); +/** As trn_cell_introduce_encrypted_get_rend_cookie, but take and * 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 - * 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); -/** As hs_cell_introduce_encrypted_get_extensions, but take and return - * a const pointer +struct trn_cell_extension_st * trn_cell_introduce_encrypted_get_extensions(trn_cell_introduce_encrypted_t *inp); +/** As trn_cell_introduce_encrypted_get_extensions, but take and + * 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 - * hs_cell_introduce_encrypted_t in 'inp' to 'val'. Free the old value - * if any. Steals the referenceto 'val'.Return 0 on success; return -1 - * and set the error code on 'inp' on failure. + * trn_cell_introduce_encrypted_t in 'inp' to 'val'. Free the old + * value if any. Steals the referenceto 'val'.Return 0 on success; + * 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); -/** As hs_cell_introduce_encrypted_set_extensions, but does not free +int trn_cell_introduce_encrypted_set_extensions(trn_cell_introduce_encrypted_t *inp, struct trn_cell_extension_st *val); +/** As trn_cell_introduce_encrypted_set_extensions, but does not free * 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 - * 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 - * 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. */ -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 - * 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 - * 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. */ -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 - * 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 - * 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); -/** As hs_cell_introduce_encrypted_get_onion_key, but take and return +uint8_t trn_cell_introduce_encrypted_get_onion_key(trn_cell_introduce_encrypted_t *inp, size_t idx); +/** As trn_cell_introduce_encrypted_get_onion_key, but take and return * 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 - * onion_key of the hs_cell_introduce_encrypted_t in 'inp', so that it - * will hold the value 'elt'. + * onion_key of the trn_cell_introduce_encrypted_t in 'inp', so that + * 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 - * 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 * 'inp'. */ -uint8_t * hs_cell_introduce_encrypted_getarray_onion_key(hs_cell_introduce_encrypted_t *inp); -/** As hs_cell_introduce_encrypted_get_onion_key, but take and return +uint8_t * trn_cell_introduce_encrypted_getarray_onion_key(trn_cell_introduce_encrypted_t *inp); +/** As trn_cell_introduce_encrypted_get_onion_key, but take and return * 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 * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * 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 - * 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 - * 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. */ -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 - * 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 - * 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); -/** As hs_cell_introduce_encrypted_get_nspecs, but take and return a +struct link_specifier_st * trn_cell_introduce_encrypted_get_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx); +/** As trn_cell_introduce_encrypted_get_nspecs, but take and return a * 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 - * 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. */ -int hs_cell_introduce_encrypted_set_nspecs(hs_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 +int trn_cell_introduce_encrypted_set_nspecs(trn_cell_introduce_encrypted_t *inp, size_t idx, struct link_specifier_st * elt); +/** As trn_cell_introduce_encrypted_set_nspecs, but does not free the * 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 - * 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 * 'inp'. */ -struct link_specifier_st * * hs_cell_introduce_encrypted_getarray_nspecs(hs_cell_introduce_encrypted_t *inp); -/** As hs_cell_introduce_encrypted_get_nspecs, but take and return a +struct link_specifier_st * * trn_cell_introduce_encrypted_getarray_nspecs(trn_cell_introduce_encrypted_t *inp); +/** As trn_cell_introduce_encrypted_get_nspecs, but take and return a * 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 * 'inp' to 'newlen'.Fill extra elements with NULL; free removed * elements. Return 0 on success; return -1 and set the error code on * '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 - * 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 - * 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); -/** As hs_cell_introduce_encrypted_get_pad, but take and return a +uint8_t trn_cell_introduce_encrypted_get_pad(trn_cell_introduce_encrypted_t *inp, size_t idx); +/** As trn_cell_introduce_encrypted_get_pad, but take and return a * 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 - * 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'. */ -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 - * 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'. */ -uint8_t * hs_cell_introduce_encrypted_getarray_pad(hs_cell_introduce_encrypted_t *inp); -/** As hs_cell_introduce_encrypted_get_pad, but take and return a +uint8_t * trn_cell_introduce_encrypted_getarray_pad(trn_cell_introduce_encrypted_t *inp); +/** As trn_cell_introduce_encrypted_get_pad, but take and return a * 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' * to 'newlen'.Fill extra elements with 0. Return 0 on success; return * -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 diff --git a/src/trunnel/hs/cell_introduce1.trunnel b/src/trunnel/hs/cell_introduce1.trunnel index f7776879cd..7577c1526f 100644 --- a/src/trunnel/hs/cell_introduce1.trunnel +++ b/src/trunnel/hs/cell_introduce1.trunnel @@ -5,7 +5,7 @@ */ /* From cell_common.trunnel. */ -extern struct cell_extension; +extern struct trn_cell_extension; /* From ed25519_cert.trunnel. */ extern struct link_specifier; @@ -13,7 +13,7 @@ const TRUNNEL_SHA1_LEN = 20; const TRUNNEL_REND_COOKIE_LEN = 20; /* 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. */ u8 legacy_key_id[TRUNNEL_SHA1_LEN]; @@ -23,28 +23,28 @@ struct hs_cell_introduce1 { u8 auth_key[auth_key_len]; /* Extension(s). Reserved fields. */ - struct cell_extension extensions; + struct trn_cell_extension extensions; /* Variable length, up to the end of cell. */ u8 encrypted[]; }; /* INTRODUCE_ACK payload. See details in section 3.2.2. */ -struct hs_cell_introduce_ack { +struct trn_cell_introduce_ack { /* Status of introduction. */ u16 status IN [0x0000, 0x0001, 0x0002]; /* Extension(s). Reserved fields. */ - struct cell_extension extensions; + struct trn_cell_extension extensions; }; /* Encrypted section of the INTRODUCE1/INTRODUCE2 cell. */ -struct hs_cell_introduce_encrypted { +struct trn_cell_introduce_encrypted { /* Rendezvous cookie. */ u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN]; /* Extension(s). Reserved fields. */ - struct cell_extension extensions; + struct trn_cell_extension extensions; /* Onion key material. */ u8 onion_key_type IN [0x01];