diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | src/ext/trunnel/trunnel.c | 2 | ||||
-rw-r--r-- | src/or/hs_intropoint.c | 91 | ||||
-rw-r--r-- | src/or/hs_intropoint.h | 4 | ||||
-rw-r--r-- | src/or/hs_ntor.c | 626 | ||||
-rw-r--r-- | src/or/hs_ntor.h | 77 | ||||
-rw-r--r-- | src/or/hs_service.c | 42 | ||||
-rw-r--r-- | src/or/hs_service.h | 4 | ||||
-rw-r--r-- | src/or/include.am | 2 | ||||
-rw-r--r-- | src/test/hs_ntor_ref.py | 408 | ||||
-rw-r--r-- | src/test/include.am | 17 | ||||
-rw-r--r-- | src/test/test_hs_intropoint.c | 102 | ||||
-rwxr-xr-x | src/test/test_hs_ntor.sh | 11 | ||||
-rw-r--r-- | src/test/test_hs_ntor_cl.c | 255 | ||||
-rw-r--r-- | src/test/test_hs_service.c | 111 | ||||
-rw-r--r-- | src/trunnel/hs/cell_common.c | 179 | ||||
-rw-r--r-- | src/trunnel/hs/cell_common.h | 207 | ||||
-rw-r--r-- | src/trunnel/hs/cell_common.trunnel | 6 | ||||
-rw-r--r-- | src/trunnel/hs/cell_establish_intro.c | 242 | ||||
-rw-r--r-- | src/trunnel/hs/cell_establish_intro.h | 237 | ||||
-rw-r--r-- | src/trunnel/hs/cell_establish_intro.trunnel | 10 | ||||
-rw-r--r-- | src/trunnel/hs/cell_introduce1.c | 398 | ||||
-rw-r--r-- | src/trunnel/hs/cell_introduce1.h | 416 | ||||
-rw-r--r-- | src/trunnel/hs/cell_introduce1.trunnel | 14 |
24 files changed, 2481 insertions, 982 deletions
diff --git a/.gitignore b/.gitignore index 3163c12765..f8d6e13da7 100644 --- a/.gitignore +++ b/.gitignore @@ -181,6 +181,7 @@ uptime-*.json /src/test/test-child /src/test/test-memwipe /src/test/test-ntor-cl +/src/test/test-hs-ntor-cl /src/test/test-switch-id /src/test/test-timers /src/test/test_workqueue @@ -189,6 +190,7 @@ uptime-*.json /src/test/test-bt-cl.exe /src/test/test-child.exe /src/test/test-ntor-cl.exe +/src/test/test-hs-ntor-cl.exe /src/test/test-memwipe.exe /src/test/test-switch-id.exe /src/test/test-timers.exe 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 <sys/endian.h> # else # include <endian.h> diff --git a/src/or/hs_intropoint.c b/src/or/hs_intropoint.c index a7282aba8f..c32d24480a 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 <b>cell</b>. Verify its signature and MAC, * given <b>circuit_key_material</b>. 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,14 @@ 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 +148,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 +171,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 +181,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 +211,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 +225,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 +260,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 +340,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 +369,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 +377,7 @@ send_introduce_ack_cell(or_circuit_t *circ, hs_intro_ack_status_t status) /* Validate a parsed INTRODUCE1 <b>cell</b>. Return 0 if valid or else a * 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 +386,29 @@ validate_introduce1_parsed_cell(const hs_cell_introduce1_t *cell) /* This code path SHOULD NEVER be reached if the cell is a legacy type so * 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 +431,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 +440,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request, /* Parse cell. Note that we can only parse the non encrypted section for * 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 +506,7 @@ handle_introduce1(or_circuit_t *client_circ, const uint8_t *request, circuit_mark_for_close(TO_CIRCUIT(client_circ), END_CIRC_REASON_INTERNAL); } 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_ntor.c b/src/or/hs_ntor.c new file mode 100644 index 0000000000..119899817e --- /dev/null +++ b/src/or/hs_ntor.c @@ -0,0 +1,626 @@ +/* Copyright (c) 2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** \file hs_ntor.c + * \brief Implements the ntor variant used in Tor hidden services. + * + * \details + * This module handles the variant of the ntor handshake that is documented in + * section [NTOR-WITH-EXTRA-DATA] of rend-spec-ng.txt . + * + * The functions in this file provide an API that should be used when sending + * or receiving INTRODUCE1/RENDEZVOUS1 cells to generate the various key + * material required to create and handle those cells. + * + * In the case of INTRODUCE1 it provides encryption and MAC keys to + * encode/decode the encrypted blob (see hs_ntor_intro_cell_keys_t). The + * relevant pub functions are hs_ntor_{client,service}_get_introduce1_keys(). + * + * In the case of RENDEZVOUS1 it calculates the MAC required to authenticate + * the cell, and also provides the key seed that is used to derive the crypto + * material for rendezvous encryption (see hs_ntor_rend_cell_keys_t). The + * relevant pub functions are hs_ntor_{client,service}_get_rendezvous1_keys(). + * It also provides a function (hs_ntor_circuit_key_expansion()) that does the + * rendezvous key expansion to setup end-to-end rend circuit keys. + */ + +#include "or.h" +#include "hs_ntor.h" + +/* String constants used by the ntor HS protocol */ +#define PROTOID "tor-hs-ntor-curve25519-sha3-256-1" +#define PROTOID_LEN (sizeof(PROTOID) - 1) +#define SERVER_STR "Server" +#define SERVER_STR_LEN (sizeof(SERVER_STR) - 1) + +/* Protocol-specific tweaks to our crypto inputs */ +#define T_HSENC PROTOID ":hs_key_extract" +#define T_HSENC_LEN (sizeof(T_HSENC) - 1) +#define T_HSVERIFY PROTOID ":hs_verify" +#define T_HSMAC PROTOID ":hs_mac" +#define M_HSEXPAND PROTOID ":hs_key_expand" +#define M_HSEXPAND_LEN (sizeof(M_HSEXPAND) - 1) + +/************************* Helper functions: *******************************/ + +/** Helper macro: copy <b>len</b> bytes from <b>inp</b> to <b>ptr</b> and + *advance <b>ptr</b> by the number of bytes copied. Stolen from onion_ntor.c */ +#define APPEND(ptr, inp, len) \ + STMT_BEGIN { \ + memcpy(ptr, (inp), (len)); \ + ptr += len; \ + } STMT_END + +/* Length of EXP(X,y) | EXP(X,b) | AUTH_KEY | B | X | Y | PROTOID */ +#define REND_SECRET_HS_INPUT_LEN (CURVE25519_OUTPUT_LEN * 2 + \ + ED25519_PUBKEY_LEN + CURVE25519_PUBKEY_LEN * 3 + PROTOID_LEN) +/* Length of auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server" */ +#define REND_AUTH_INPUT_LEN (DIGEST256_LEN + ED25519_PUBKEY_LEN + \ + CURVE25519_PUBKEY_LEN * 3 + PROTOID_LEN + SERVER_STR_LEN) + +/** Helper function: Compute the last part of the HS ntor handshake which + * derives key material necessary to create and handle RENDEZVOUS1 + * cells. Function used by both client and service. The actual calculations is + * as follows: + * + * NTOR_KEY_SEED = MAC(rend_secret_hs_input, t_hsenc) + * verify = MAC(rend_secret_hs_input, t_hsverify) + * auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server" + * auth_input_mac = MAC(auth_input, t_hsmac) + * + * where in the above, AUTH_KEY is <b>intro_auth_pubkey</b>, B is + * <b>intro_enc_pubkey</b>, Y is <b>service_ephemeral_rend_pubkey</b>, and X + * is <b>client_ephemeral_enc_pubkey</b>. The provided + * <b>rend_secret_hs_input</b> is of size REND_SECRET_HS_INPUT_LEN. + * + * The final results of NTOR_KEY_SEED and auth_input_mac are placed in + * <b>hs_ntor_rend_cell_keys_out</b>. Return 0 if everything went fine. */ +static int +get_rendezvous1_key_material(const uint8_t *rend_secret_hs_input, + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_public_key_t *intro_enc_pubkey, + const curve25519_public_key_t *service_ephemeral_rend_pubkey, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys_out) +{ + int bad = 0; + uint8_t ntor_key_seed[DIGEST256_LEN]; + uint8_t ntor_verify[DIGEST256_LEN]; + uint8_t rend_auth_input[REND_AUTH_INPUT_LEN]; + uint8_t rend_cell_auth[DIGEST256_LEN]; + uint8_t *ptr; + + /* Let's build NTOR_KEY_SEED */ + crypto_mac_sha3_256(ntor_key_seed, sizeof(ntor_key_seed), + rend_secret_hs_input, REND_SECRET_HS_INPUT_LEN, + (const uint8_t *)T_HSENC, strlen(T_HSENC)); + bad |= safe_mem_is_zero(ntor_key_seed, DIGEST256_LEN); + + /* Let's build ntor_verify */ + crypto_mac_sha3_256(ntor_verify, sizeof(ntor_verify), + rend_secret_hs_input, REND_SECRET_HS_INPUT_LEN, + (const uint8_t *)T_HSVERIFY, strlen(T_HSVERIFY)); + bad |= safe_mem_is_zero(ntor_verify, DIGEST256_LEN); + + /* Let's build auth_input: */ + ptr = rend_auth_input; + /* Append ntor_verify */ + APPEND(ptr, ntor_verify, sizeof(ntor_verify)); + /* Append AUTH_KEY */ + APPEND(ptr, intro_auth_pubkey->pubkey, ED25519_PUBKEY_LEN); + /* Append B */ + APPEND(ptr, intro_enc_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append Y */ + APPEND(ptr, + service_ephemeral_rend_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append X */ + APPEND(ptr, + client_ephemeral_enc_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append PROTOID */ + APPEND(ptr, PROTOID, strlen(PROTOID)); + /* Append "Server" */ + APPEND(ptr, SERVER_STR, strlen(SERVER_STR)); + tor_assert(ptr == rend_auth_input + sizeof(rend_auth_input)); + + /* Let's build auth_input_mac that goes in RENDEZVOUS1 cell */ + crypto_mac_sha3_256(rend_cell_auth, sizeof(rend_cell_auth), + rend_auth_input, sizeof(rend_auth_input), + (const uint8_t *)T_HSMAC, strlen(T_HSMAC)); + bad |= safe_mem_is_zero(ntor_verify, DIGEST256_LEN); + + { /* Get the computed RENDEZVOUS1 material! */ + memcpy(&hs_ntor_rend_cell_keys_out->rend_cell_auth_mac, + rend_cell_auth, DIGEST256_LEN); + memcpy(&hs_ntor_rend_cell_keys_out->ntor_key_seed, + ntor_key_seed, DIGEST256_LEN); + } + + memwipe(rend_cell_auth, 0, sizeof(rend_cell_auth)); + memwipe(rend_auth_input, 0, sizeof(rend_auth_input)); + memwipe(ntor_key_seed, 0, sizeof(ntor_key_seed)); + + return bad; +} + +/** Length of secret_input = EXP(B,x) | AUTH_KEY | X | B | PROTOID */ +#define INTRO_SECRET_HS_INPUT_LEN (CURVE25519_OUTPUT_LEN +ED25519_PUBKEY_LEN +\ + CURVE25519_PUBKEY_LEN + CURVE25519_PUBKEY_LEN + PROTOID_LEN) +/* Length of info = m_hsexpand | subcredential */ +#define INFO_BLOB_LEN (M_HSEXPAND_LEN + DIGEST256_LEN) +/* Length of KDF input = intro_secret_hs_input | t_hsenc | info */ +#define KDF_INPUT_LEN (INTRO_SECRET_HS_INPUT_LEN + T_HSENC_LEN + INFO_BLOB_LEN) + +/** Helper function: Compute the part of the HS ntor handshake that generates + * key material for creating and handling INTRODUCE1 cells. Function used + * by both client and service. Specifically, calculate the following: + * + * info = m_hsexpand | subcredential + * hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN) + * ENC_KEY = hs_keys[0:S_KEY_LEN] + * MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN] + * + * where intro_secret_hs_input is <b>secret_input</b> (of size + * INTRO_SECRET_HS_INPUT_LEN), and <b>subcredential</b> is of size + * DIGEST256_LEN. + * + * If everything went well, fill <b>hs_ntor_intro_cell_keys_out</b> with the + * necessary key material, and return 0. */ +static void +get_introduce1_key_material(const uint8_t *secret_input, + const uint8_t *subcredential, + hs_ntor_intro_cell_keys_t *hs_ntor_intro_cell_keys_out) +{ + uint8_t keystream[CIPHER256_KEY_LEN + DIGEST256_LEN]; + uint8_t info_blob[INFO_BLOB_LEN]; + uint8_t kdf_input[KDF_INPUT_LEN]; + crypto_xof_t *xof; + uint8_t *ptr; + + /* Let's build info */ + ptr = info_blob; + APPEND(ptr, M_HSEXPAND, strlen(M_HSEXPAND)); + APPEND(ptr, subcredential, DIGEST256_LEN); + tor_assert(ptr == info_blob + sizeof(info_blob)); + + /* Let's build the input to the KDF */ + ptr = kdf_input; + APPEND(ptr, secret_input, INTRO_SECRET_HS_INPUT_LEN); + APPEND(ptr, T_HSENC, strlen(T_HSENC)); + APPEND(ptr, info_blob, sizeof(info_blob)); + tor_assert(ptr == kdf_input + sizeof(kdf_input)); + + /* Now we need to run kdf_input over SHAKE-256 */ + xof = crypto_xof_new(); + crypto_xof_add_bytes(xof, kdf_input, sizeof(kdf_input)); + crypto_xof_squeeze_bytes(xof, keystream, sizeof(keystream)) ; + crypto_xof_free(xof); + + { /* Get the keys */ + memcpy(&hs_ntor_intro_cell_keys_out->enc_key, keystream,CIPHER256_KEY_LEN); + memcpy(&hs_ntor_intro_cell_keys_out->mac_key, + keystream+CIPHER256_KEY_LEN, DIGEST256_LEN); + } + + memwipe(keystream, 0, sizeof(keystream)); + memwipe(kdf_input, 0, sizeof(kdf_input)); +} + +/** Helper function: Calculate the 'intro_secret_hs_input' element used by the + * HS ntor handshake and place it in <b>secret_input_out</b>. This function is + * used by both client and service code. + * + * For the client-side it looks like this: + * + * intro_secret_hs_input = EXP(B,x) | AUTH_KEY | X | B | PROTOID + * + * whereas for the service-side it looks like this: + * + * intro_secret_hs_input = EXP(X,b) | AUTH_KEY | X | B | PROTOID + * + * In this function, <b>dh_result</b> carries the EXP() result (and has size + * CURVE25519_OUTPUT_LEN) <b>intro_auth_pubkey</b> is AUTH_KEY, + * <b>client_ephemeral_enc_pubkey</b> is X, and <b>intro_enc_pubkey</b> is B. + */ +static void +get_intro_secret_hs_input(const uint8_t *dh_result, + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + const curve25519_public_key_t *intro_enc_pubkey, + uint8_t *secret_input_out) +{ + uint8_t *ptr; + + /* Append EXP() */ + ptr = secret_input_out; + APPEND(ptr, dh_result, CURVE25519_OUTPUT_LEN); + /* Append AUTH_KEY */ + APPEND(ptr, intro_auth_pubkey->pubkey, ED25519_PUBKEY_LEN); + /* Append X */ + APPEND(ptr, client_ephemeral_enc_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append B */ + APPEND(ptr, intro_enc_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append PROTOID */ + APPEND(ptr, PROTOID, strlen(PROTOID)); + tor_assert(ptr == secret_input_out + INTRO_SECRET_HS_INPUT_LEN); +} + +/** Calculate the 'rend_secret_hs_input' element used by the HS ntor handshake + * and place it in <b>rend_secret_hs_input_out</b>. This function is used by + * both client and service code. + * + * The computation on the client side is: + * rend_secret_hs_input = EXP(X,y) | EXP(X,b) | AUTH_KEY | B | X | Y | PROTOID + * whereas on the service side it is: + * rend_secret_hs_input = EXP(Y,x) | EXP(B,x) | AUTH_KEY | B | X | Y | PROTOID + * + * where: + * <b>dh_result1</b> and <b>dh_result2</b> carry the two EXP() results (of size + * CURVE25519_OUTPUT_LEN) + * <b>intro_auth_pubkey</b> is AUTH_KEY, + * <b>intro_enc_pubkey</b> is B, + * <b>client_ephemeral_enc_pubkey</b> is X, and + * <b>service_ephemeral_rend_pubkey</b> is Y. + */ +static void +get_rend_secret_hs_input(const uint8_t *dh_result1, const uint8_t *dh_result2, + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_public_key_t *intro_enc_pubkey, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + const curve25519_public_key_t *service_ephemeral_rend_pubkey, + uint8_t *rend_secret_hs_input_out) +{ + uint8_t *ptr; + + ptr = rend_secret_hs_input_out; + /* Append the first EXP() */ + APPEND(ptr, dh_result1, CURVE25519_OUTPUT_LEN); + /* Append the other EXP() */ + APPEND(ptr, dh_result2, CURVE25519_OUTPUT_LEN); + /* Append AUTH_KEY */ + APPEND(ptr, intro_auth_pubkey->pubkey, ED25519_PUBKEY_LEN); + /* Append B */ + APPEND(ptr, intro_enc_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append X */ + APPEND(ptr, + client_ephemeral_enc_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append Y */ + APPEND(ptr, + service_ephemeral_rend_pubkey->public_key, CURVE25519_PUBKEY_LEN); + /* Append PROTOID */ + APPEND(ptr, PROTOID, strlen(PROTOID)); + tor_assert(ptr == rend_secret_hs_input_out + REND_SECRET_HS_INPUT_LEN); +} + +/************************* Public functions: *******************************/ + +/* Public function: Do the appropriate ntor calculations and derive the keys + * needed to encrypt and authenticate INTRODUCE1 cells. Return 0 and place the + * final key material in <b>hs_ntor_intro_cell_keys_out</b> if everything went + * well, otherwise return -1; + * + * The relevant calculations are as follows: + * + * intro_secret_hs_input = EXP(B,x) | AUTH_KEY | X | B | PROTOID + * info = m_hsexpand | subcredential + * hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN) + * ENC_KEY = hs_keys[0:S_KEY_LEN] + * MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN] + * + * where: + * <b>intro_auth_pubkey</b> is AUTH_KEY (found in HS descriptor), + * <b>intro_enc_pubkey</b> is B (also found in HS descriptor), + * <b>client_ephemeral_enc_keypair</b> is freshly generated keypair (x,X) + * <b>subcredential</b> is the hidden service subcredential (of size + * DIGEST256_LEN). */ +int +hs_ntor_client_get_introduce1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_public_key_t *intro_enc_pubkey, + const curve25519_keypair_t *client_ephemeral_enc_keypair, + const uint8_t *subcredential, + hs_ntor_intro_cell_keys_t *hs_ntor_intro_cell_keys_out) +{ + int bad = 0; + uint8_t secret_input[INTRO_SECRET_HS_INPUT_LEN]; + uint8_t dh_result[CURVE25519_OUTPUT_LEN]; + + tor_assert(intro_auth_pubkey); + tor_assert(intro_enc_pubkey); + tor_assert(client_ephemeral_enc_keypair); + tor_assert(subcredential); + tor_assert(hs_ntor_intro_cell_keys_out); + + /* Calculate EXP(B,x) */ + curve25519_handshake(dh_result, + &client_ephemeral_enc_keypair->seckey, + intro_enc_pubkey); + bad |= safe_mem_is_zero(dh_result, CURVE25519_OUTPUT_LEN); + + /* Get intro_secret_hs_input */ + get_intro_secret_hs_input(dh_result, intro_auth_pubkey, + &client_ephemeral_enc_keypair->pubkey, + intro_enc_pubkey, secret_input); + bad |= safe_mem_is_zero(secret_input, CURVE25519_OUTPUT_LEN); + + /* Get ENC_KEY and MAC_KEY! */ + get_introduce1_key_material(secret_input, subcredential, + hs_ntor_intro_cell_keys_out); + + /* Cleanup */ + memwipe(secret_input, 0, sizeof(secret_input)); + if (bad) { + memwipe(hs_ntor_intro_cell_keys_out, 0, sizeof(hs_ntor_intro_cell_keys_t)); + } + + return bad ? -1 : 0; +} + +/* Public function: Do the appropriate ntor calculations and derive the keys + * needed to verify RENDEZVOUS1 cells and encrypt further rendezvous + * traffic. Return 0 and place the final key material in + * <b>hs_ntor_rend_cell_keys_out</b> if everything went well, else return -1. + * + * The relevant calculations are as follows: + * + * rend_secret_hs_input = EXP(Y,x) | EXP(B,x) | AUTH_KEY | B | X | Y | PROTOID + * NTOR_KEY_SEED = MAC(rend_secret_hs_input, t_hsenc) + * verify = MAC(rend_secret_hs_input, t_hsverify) + * auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server" + * auth_input_mac = MAC(auth_input, t_hsmac) + * + * where: + * <b>intro_auth_pubkey</b> is AUTH_KEY (found in HS descriptor), + * <b>client_ephemeral_enc_keypair</b> is freshly generated keypair (x,X) + * <b>intro_enc_pubkey</b> is B (also found in HS descriptor), + * <b>service_ephemeral_rend_pubkey</b> is Y (SERVER_PK in RENDEZVOUS1 cell) */ +int +hs_ntor_client_get_rendezvous1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_keypair_t *client_ephemeral_enc_keypair, + const curve25519_public_key_t *intro_enc_pubkey, + const curve25519_public_key_t *service_ephemeral_rend_pubkey, + hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys_out) +{ + int bad = 0; + uint8_t rend_secret_hs_input[REND_SECRET_HS_INPUT_LEN]; + uint8_t dh_result1[CURVE25519_OUTPUT_LEN]; + uint8_t dh_result2[CURVE25519_OUTPUT_LEN]; + + tor_assert(intro_auth_pubkey); + tor_assert(client_ephemeral_enc_keypair); + tor_assert(intro_enc_pubkey); + tor_assert(service_ephemeral_rend_pubkey); + tor_assert(hs_ntor_rend_cell_keys_out); + + /* Compute EXP(Y, x) */ + curve25519_handshake(dh_result1, + &client_ephemeral_enc_keypair->seckey, + service_ephemeral_rend_pubkey); + bad |= safe_mem_is_zero(dh_result1, CURVE25519_OUTPUT_LEN); + + /* Compute EXP(B, x) */ + curve25519_handshake(dh_result2, + &client_ephemeral_enc_keypair->seckey, + intro_enc_pubkey); + bad |= safe_mem_is_zero(dh_result2, CURVE25519_OUTPUT_LEN); + + /* Get rend_secret_hs_input */ + get_rend_secret_hs_input(dh_result1, dh_result2, + intro_auth_pubkey, intro_enc_pubkey, + &client_ephemeral_enc_keypair->pubkey, + service_ephemeral_rend_pubkey, + rend_secret_hs_input); + + /* Get NTOR_KEY_SEED and the auth_input MAC */ + bad |= get_rendezvous1_key_material(rend_secret_hs_input, + intro_auth_pubkey, + intro_enc_pubkey, + service_ephemeral_rend_pubkey, + &client_ephemeral_enc_keypair->pubkey, + hs_ntor_rend_cell_keys_out); + + memwipe(rend_secret_hs_input, 0, sizeof(rend_secret_hs_input)); + if (bad) { + memwipe(hs_ntor_rend_cell_keys_out, 0, sizeof(hs_ntor_rend_cell_keys_t)); + } + + return bad ? -1 : 0; +} + +/* Public function: Do the appropriate ntor calculations and derive the keys + * needed to decrypt and verify INTRODUCE1 cells. Return 0 and place the final + * key material in <b>hs_ntor_intro_cell_keys_out</b> if everything went well, + * otherwise return -1; + * + * The relevant calculations are as follows: + * + * intro_secret_hs_input = EXP(X,b) | AUTH_KEY | X | B | PROTOID + * info = m_hsexpand | subcredential + * hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN) + * HS_DEC_KEY = hs_keys[0:S_KEY_LEN] + * HS_MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN] + * + * where: + * <b>intro_auth_pubkey</b> is AUTH_KEY (introduction point auth key), + * <b>intro_enc_keypair</b> is (b,B) (introduction point encryption keypair), + * <b>client_ephemeral_enc_pubkey</b> is X (CLIENT_PK in INTRODUCE2 cell), + * <b>subcredential</b> is the HS subcredential (of size DIGEST256_LEN) */ +int +hs_ntor_service_get_introduce1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_keypair_t *intro_enc_keypair, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + const uint8_t *subcredential, + hs_ntor_intro_cell_keys_t *hs_ntor_intro_cell_keys_out) +{ + int bad = 0; + uint8_t secret_input[INTRO_SECRET_HS_INPUT_LEN]; + uint8_t dh_result[CURVE25519_OUTPUT_LEN]; + + tor_assert(intro_auth_pubkey); + tor_assert(intro_enc_keypair); + tor_assert(client_ephemeral_enc_pubkey); + tor_assert(subcredential); + tor_assert(hs_ntor_intro_cell_keys_out); + + /* Compute EXP(X, b) */ + curve25519_handshake(dh_result, + &intro_enc_keypair->seckey, + client_ephemeral_enc_pubkey); + bad |= safe_mem_is_zero(dh_result, CURVE25519_OUTPUT_LEN); + + /* Get intro_secret_hs_input */ + get_intro_secret_hs_input(dh_result, intro_auth_pubkey, + client_ephemeral_enc_pubkey, + &intro_enc_keypair->pubkey, + secret_input); + bad |= safe_mem_is_zero(secret_input, CURVE25519_OUTPUT_LEN); + + /* Get ENC_KEY and MAC_KEY! */ + get_introduce1_key_material(secret_input, subcredential, + hs_ntor_intro_cell_keys_out); + + memwipe(secret_input, 0, sizeof(secret_input)); + if (bad) { + memwipe(hs_ntor_intro_cell_keys_out, 0, sizeof(hs_ntor_intro_cell_keys_t)); + } + + return bad ? -1 : 0; +} + +/* Public function: Do the appropriate ntor calculations and derive the keys + * needed to create and authenticate RENDEZVOUS1 cells. Return 0 and place the + * final key material in <b>hs_ntor_rend_cell_keys_out</b> if all went fine, + * return -1 if error happened. + * + * The relevant calculations are as follows: + * + * rend_secret_hs_input = EXP(X,y) | EXP(X,b) | AUTH_KEY | B | X | Y | PROTOID + * NTOR_KEY_SEED = MAC(rend_secret_hs_input, t_hsenc) + * verify = MAC(rend_secret_hs_input, t_hsverify) + * auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server" + * auth_input_mac = MAC(auth_input, t_hsmac) + * + * where: + * <b>intro_auth_pubkey</b> is AUTH_KEY (intro point auth key), + * <b>intro_enc_keypair</b> is (b,B) (intro point enc keypair) + * <b>service_ephemeral_rend_keypair</b> is a fresh (y,Y) keypair + * <b>client_ephemeral_enc_pubkey</b> is X (CLIENT_PK in INTRODUCE2 cell) */ +int +hs_ntor_service_get_rendezvous1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_keypair_t *intro_enc_keypair, + const curve25519_keypair_t *service_ephemeral_rend_keypair, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys_out) +{ + int bad = 0; + uint8_t rend_secret_hs_input[REND_SECRET_HS_INPUT_LEN]; + uint8_t dh_result1[CURVE25519_OUTPUT_LEN]; + uint8_t dh_result2[CURVE25519_OUTPUT_LEN]; + + tor_assert(intro_auth_pubkey); + tor_assert(intro_enc_keypair); + tor_assert(service_ephemeral_rend_keypair); + tor_assert(client_ephemeral_enc_pubkey); + tor_assert(hs_ntor_rend_cell_keys_out); + + /* Compute EXP(X, y) */ + curve25519_handshake(dh_result1, + &service_ephemeral_rend_keypair->seckey, + client_ephemeral_enc_pubkey); + bad |= safe_mem_is_zero(dh_result1, CURVE25519_OUTPUT_LEN); + + /* Compute EXP(X, b) */ + curve25519_handshake(dh_result2, + &intro_enc_keypair->seckey, + client_ephemeral_enc_pubkey); + bad |= safe_mem_is_zero(dh_result2, CURVE25519_OUTPUT_LEN); + + /* Get rend_secret_hs_input */ + get_rend_secret_hs_input(dh_result1, dh_result2, + intro_auth_pubkey, + &intro_enc_keypair->pubkey, + client_ephemeral_enc_pubkey, + &service_ephemeral_rend_keypair->pubkey, + rend_secret_hs_input); + + /* Get NTOR_KEY_SEED and AUTH_INPUT_MAC! */ + bad |= get_rendezvous1_key_material(rend_secret_hs_input, + intro_auth_pubkey, + &intro_enc_keypair->pubkey, + &service_ephemeral_rend_keypair->pubkey, + client_ephemeral_enc_pubkey, + hs_ntor_rend_cell_keys_out); + + memwipe(rend_secret_hs_input, 0, sizeof(rend_secret_hs_input)); + if (bad) { + memwipe(hs_ntor_rend_cell_keys_out, 0, sizeof(hs_ntor_rend_cell_keys_t)); + } + + return bad ? -1 : 0; +} + +/** Given a received RENDEZVOUS2 MAC in <b>mac</b> (of length DIGEST256_LEN), + * and the RENDEZVOUS1 key material in <b>hs_ntor_rend_cell_keys</b>, return 1 + * if the MAC is good, otherwise return 0. */ +int +hs_ntor_client_rendezvous2_mac_is_good( + const hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys, + const uint8_t *rcvd_mac) +{ + tor_assert(rcvd_mac); + tor_assert(hs_ntor_rend_cell_keys); + + return tor_memeq(hs_ntor_rend_cell_keys->rend_cell_auth_mac, + rcvd_mac, DIGEST256_LEN); +} + +/* Input length to KDF for key expansion */ +#define NTOR_KEY_EXPANSION_KDF_INPUT_LEN (DIGEST256_LEN + M_HSEXPAND_LEN) +/* Output length of KDF for key expansion */ +#define NTOR_KEY_EXPANSION_KDF_OUTPUT_LEN (DIGEST256_LEN*3+CIPHER256_KEY_LEN*2) + +/** Given the rendezvous key material in <b>hs_ntor_rend_cell_keys</b>, do the + * circuit key expansion as specified by section '4.2.1. Key expansion' and + * return a hs_ntor_rend_circuit_keys_t structure with the computed keys. */ +hs_ntor_rend_circuit_keys_t * +hs_ntor_circuit_key_expansion( + const hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys) +{ + uint8_t *ptr; + uint8_t kdf_input[NTOR_KEY_EXPANSION_KDF_INPUT_LEN]; + uint8_t keys[NTOR_KEY_EXPANSION_KDF_OUTPUT_LEN]; + crypto_xof_t *xof; + hs_ntor_rend_circuit_keys_t *rend_circuit_keys = NULL; + + /* Let's build the input to the KDF */ + ptr = kdf_input; + APPEND(ptr, hs_ntor_rend_cell_keys->ntor_key_seed, DIGEST256_LEN); + APPEND(ptr, M_HSEXPAND, strlen(M_HSEXPAND)); + tor_assert(ptr == kdf_input + sizeof(kdf_input)); + + /* Generate the keys */ + xof = crypto_xof_new(); + crypto_xof_add_bytes(xof, kdf_input, sizeof(kdf_input)); + crypto_xof_squeeze_bytes(xof, keys, sizeof(keys)); + crypto_xof_free(xof); + + /* Generate keys structure and assign keys to it */ + rend_circuit_keys = tor_malloc_zero(sizeof(hs_ntor_rend_circuit_keys_t)); + ptr = keys; + memcpy(rend_circuit_keys->KH, ptr, DIGEST256_LEN); + ptr += DIGEST256_LEN;; + memcpy(rend_circuit_keys->Df, ptr, DIGEST256_LEN); + ptr += DIGEST256_LEN; + memcpy(rend_circuit_keys->Db, ptr, DIGEST256_LEN); + ptr += DIGEST256_LEN; + memcpy(rend_circuit_keys->Kf, ptr, CIPHER256_KEY_LEN); + ptr += CIPHER256_KEY_LEN; + memcpy(rend_circuit_keys->Kb, ptr, CIPHER256_KEY_LEN); + ptr += CIPHER256_KEY_LEN; + tor_assert(ptr == keys + sizeof(keys)); + + return rend_circuit_keys; +} + diff --git a/src/or/hs_ntor.h b/src/or/hs_ntor.h new file mode 100644 index 0000000000..cd75f46a4c --- /dev/null +++ b/src/or/hs_ntor.h @@ -0,0 +1,77 @@ +/* Copyright (c) 2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +#ifndef TOR_HS_NTOR_H +#define TOR_HS_NTOR_H + +#include "or.h" + +/* Key material needed to encode/decode INTRODUCE1 cells */ +typedef struct { + /* Key used for encryption of encrypted INTRODUCE1 blob */ + uint8_t enc_key[CIPHER256_KEY_LEN]; + /* MAC key used to protect encrypted INTRODUCE1 blob */ + uint8_t mac_key[DIGEST256_LEN]; +} hs_ntor_intro_cell_keys_t; + +/* Key material needed to encode/decode RENDEZVOUS1 cells */ +typedef struct { + /* This is the MAC of the HANDSHAKE_INFO field */ + uint8_t rend_cell_auth_mac[DIGEST256_LEN]; + /* This is the key seed used to derive further rendezvous crypto keys as + * detailed in section 4.2.1 of rend-spec-ng.txt. */ + uint8_t ntor_key_seed[DIGEST256_LEN]; +} hs_ntor_rend_cell_keys_t; + +/* Key material resulting from key expansion as detailed in section "4.2.1. Key + * expansion" of rend-spec-ng.txt. */ +typedef struct { + /* Per-circuit key material used in ESTABLISH_INTRO cell */ + uint8_t KH[DIGEST256_LEN]; + /* Authentication key for outgoing RELAY cells */ + uint8_t Df[DIGEST256_LEN]; + /* Authentication key for incoming RELAY cells */ + uint8_t Db[DIGEST256_LEN]; + /* Encryption key for outgoing RELAY cells */ + uint8_t Kf[CIPHER256_KEY_LEN]; + /* Decryption key for incoming RELAY cells */ + uint8_t Kb[CIPHER256_KEY_LEN]; +} hs_ntor_rend_circuit_keys_t; + +int hs_ntor_client_get_introduce1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_public_key_t *intro_enc_pubkey, + const curve25519_keypair_t *client_ephemeral_enc_keypair, + const uint8_t *subcredential, + hs_ntor_intro_cell_keys_t *hs_ntor_intro_cell_keys_out); + +int hs_ntor_client_get_rendezvous1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_keypair_t *client_ephemeral_enc_keypair, + const curve25519_public_key_t *intro_enc_pubkey, + const curve25519_public_key_t *service_ephemeral_rend_pubkey, + hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys_out); + +int hs_ntor_service_get_introduce1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_keypair_t *intro_enc_keypair, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + const uint8_t *subcredential, + hs_ntor_intro_cell_keys_t *hs_ntor_intro_cell_keys_out); + +int hs_ntor_service_get_rendezvous1_keys( + const ed25519_public_key_t *intro_auth_pubkey, + const curve25519_keypair_t *intro_enc_keypair, + const curve25519_keypair_t *service_ephemeral_rend_keypair, + const curve25519_public_key_t *client_ephemeral_enc_pubkey, + hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys_out); + +hs_ntor_rend_circuit_keys_t *hs_ntor_circuit_key_expansion( + const hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys); + +int hs_ntor_client_rendezvous2_mac_is_good( + const hs_ntor_rend_cell_keys_t *hs_ntor_rend_cell_keys, + const uint8_t *rcvd_mac); + +#endif + 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 <b>cell</b>. */ 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 <b>circuit_key_material</b>, 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/or/include.am b/src/or/include.am index 688ac625ea..1841bbfe9d 100644 --- a/src/or/include.am +++ b/src/or/include.am @@ -50,6 +50,7 @@ LIBTOR_A_SOURCES = \ src/or/geoip.c \ src/or/hs_intropoint.c \ src/or/hs_circuitmap.c \ + src/or/hs_ntor.c \ src/or/hs_service.c \ src/or/entrynodes.c \ src/or/ext_orport.c \ @@ -175,6 +176,7 @@ ORHEADERS = \ src/or/hs_descriptor.h \ src/or/hs_intropoint.h \ src/or/hs_circuitmap.h \ + src/or/hs_ntor.h \ src/or/hs_service.h \ src/or/keypin.h \ src/or/main.h \ diff --git a/src/test/hs_ntor_ref.py b/src/test/hs_ntor_ref.py new file mode 100644 index 0000000000..813e797828 --- /dev/null +++ b/src/test/hs_ntor_ref.py @@ -0,0 +1,408 @@ +#!/usr/bin/python +# Copyright 2017, The Tor Project, Inc +# See LICENSE for licensing information + +""" +hs_ntor_ref.py + +This module is a reference implementation of the modified ntor protocol +proposed for Tor hidden services in proposal 224 (Next Generation Hidden +Services) in section [NTOR-WITH-EXTRA-DATA]. + +The modified ntor protocol is a single-round protocol, with three steps in total: + + 1: Client generates keys and sends them to service via INTRODUCE cell + + 2: Service computes key material based on client's keys, and sends its own + keys to client via RENDEZVOUS cell + + 3: Client computes key material as well. + +It's meant to be used to validate Tor's HS ntor implementation by conducting +various integration tests. Specifically it conducts the following three tests: + +- Tests our Python implementation by running the whole protocol in Python and + making sure that results are consistent. + +- Tests little-t-tor ntor implementation. We use this Python code to instrument + little-t-tor and carry out the handshake by using little-t-tor code. The + small C wrapper at src/test/test-hs-ntor-cl is used for this Python module to + interface with little-t-tor. + +- Cross-tests Python and little-t-tor implementation by running half of the + protocol in Python code and the other in little-t-tor. This is actually two + tests so that all parts of the protocol are run both by little-t-tor and + Python. + +It requires the curve25519 python module from the curve25519-donna package. + +The whole logic and concept for this test suite was taken from ntor_ref.py. + + *** DO NOT USE THIS IN PRODUCTION. *** +""" + +import struct +import os, sys +import binascii +import subprocess + +try: + import curve25519 + curve25519mod = curve25519.keys +except ImportError: + curve25519 = None + import slownacl_curve25519 + curve25519mod = slownacl_curve25519 + +try: + import sha3 +except ImportError: + # error code 77 tells automake to skip this test + sys.exit(77) + +# Import Nick's ntor reference implementation in Python +# We are gonna use a few of its utilities. +from ntor_ref import hash_nil +from ntor_ref import PrivateKey + +# String constants used in this protocol +PROTOID = "tor-hs-ntor-curve25519-sha3-256-1" +T_HSENC = PROTOID + ":hs_key_extract" +T_HSVERIFY = PROTOID + ":hs_verify" +T_HSMAC = PROTOID + ":hs_mac" +M_HSEXPAND = PROTOID + ":hs_key_expand" + +INTRO_SECRET_LEN = 161 +REND_SECRET_LEN = 225 +AUTH_INPUT_LEN = 199 + +# Implements MAC(k,m) = H(htonll(len(k)) | k | m) +def mac(k,m): + def htonll(num): + return struct.pack('!q', num) + + s = sha3.SHA3256() + s.update(htonll(len(k))) + s.update(k) + s.update(m) + return s.digest() + +###################################################################### + +# Functions that implement the modified HS ntor protocol + +"""As client compute key material for INTRODUCE cell as follows: + + intro_secret_hs_input = EXP(B,x) | AUTH_KEY | X | B | PROTOID + info = m_hsexpand | subcredential + hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN) + ENC_KEY = hs_keys[0:S_KEY_LEN] + MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN] +""" +def intro2_ntor_client(intro_auth_pubkey_str, intro_enc_pubkey, + client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, subcredential): + + dh_result = client_ephemeral_enc_privkey.get_shared_key(intro_enc_pubkey, hash_nil) + secret = dh_result + intro_auth_pubkey_str + client_ephemeral_enc_pubkey.serialize() + intro_enc_pubkey.serialize() + PROTOID + assert(len(secret) == INTRO_SECRET_LEN) + info = M_HSEXPAND + subcredential + + kdf = sha3.SHAKE256() + kdf.update(secret + T_HSENC + info) + key_material = kdf.squeeze(64*8) + + enc_key = key_material[0:32] + mac_key = key_material[32:64] + + return enc_key, mac_key + +"""Wrapper over intro2_ntor_client()""" +def client_part1(intro_auth_pubkey_str, intro_enc_pubkey, + client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, subcredential): + enc_key, mac_key = intro2_ntor_client(intro_auth_pubkey_str, intro_enc_pubkey, client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, subcredential) + assert(enc_key) + assert(mac_key) + + return enc_key, mac_key + +"""As service compute key material for INTRODUCE cell as follows: + + intro_secret_hs_input = EXP(X,b) | AUTH_KEY | X | B | PROTOID + info = m_hsexpand | subcredential + hs_keys = KDF(intro_secret_hs_input | t_hsenc | info, S_KEY_LEN+MAC_LEN) + HS_DEC_KEY = hs_keys[0:S_KEY_LEN] + HS_MAC_KEY = hs_keys[S_KEY_LEN:S_KEY_LEN+MAC_KEY_LEN] +""" +def intro2_ntor_service(intro_auth_pubkey_str, client_enc_pubkey, service_enc_privkey, service_enc_pubkey, subcredential): + dh_result = service_enc_privkey.get_shared_key(client_enc_pubkey, hash_nil) + secret = dh_result + intro_auth_pubkey_str + client_enc_pubkey.serialize() + service_enc_pubkey.serialize() + PROTOID + assert(len(secret) == INTRO_SECRET_LEN) + info = M_HSEXPAND + subcredential + + kdf = sha3.SHAKE256() + kdf.update(secret + T_HSENC + info) + key_material = kdf.squeeze(64*8) + + enc_key = key_material[0:32] + mac_key = key_material[32:64] + + return enc_key, mac_key + +"""As service compute key material for INTRODUCE and REDNEZVOUS cells. + + Use intro2_ntor_service() to calculate the INTRODUCE key material, and use + the following computations to do the RENDEZVOUS ones: + + rend_secret_hs_input = EXP(X,y) | EXP(X,b) | AUTH_KEY | B | X | Y | PROTOID + NTOR_KEY_SEED = MAC(rend_secret_hs_input, t_hsenc) + verify = MAC(rend_secret_hs_input, t_hsverify) + auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server" + AUTH_INPUT_MAC = MAC(auth_input, t_hsmac) +""" +def service_part1(intro_auth_pubkey_str, client_enc_pubkey, intro_enc_privkey, intro_enc_pubkey, subcredential): + intro_enc_key, intro_mac_key = intro2_ntor_service(intro_auth_pubkey_str, client_enc_pubkey, intro_enc_privkey, intro_enc_pubkey, subcredential) + assert(intro_enc_key) + assert(intro_mac_key) + + service_ephemeral_privkey = PrivateKey() + service_ephemeral_pubkey = service_ephemeral_privkey.get_public() + + dh_result1 = service_ephemeral_privkey.get_shared_key(client_enc_pubkey, hash_nil) + dh_result2 = intro_enc_privkey.get_shared_key(client_enc_pubkey, hash_nil) + rend_secret_hs_input = dh_result1 + dh_result2 + intro_auth_pubkey_str + intro_enc_pubkey.serialize() + client_enc_pubkey.serialize() + service_ephemeral_pubkey.serialize() + PROTOID + assert(len(rend_secret_hs_input) == REND_SECRET_LEN) + + ntor_key_seed = mac(rend_secret_hs_input, T_HSENC) + verify = mac(rend_secret_hs_input, T_HSVERIFY) + auth_input = verify + intro_auth_pubkey_str + intro_enc_pubkey.serialize() + service_ephemeral_pubkey.serialize() + client_enc_pubkey.serialize() + PROTOID + "Server" + assert(len(auth_input) == AUTH_INPUT_LEN) + auth_input_mac = mac(auth_input, T_HSMAC) + + assert(ntor_key_seed) + assert(auth_input_mac) + assert(service_ephemeral_pubkey) + + return intro_enc_key, intro_mac_key, ntor_key_seed, auth_input_mac, service_ephemeral_pubkey + +"""As client compute key material for rendezvous cells as follows: + + rend_secret_hs_input = EXP(Y,x) | EXP(B,x) | AUTH_KEY | B | X | Y | PROTOID + NTOR_KEY_SEED = MAC(ntor_secret_input, t_hsenc) + verify = MAC(ntor_secret_input, t_hsverify) + auth_input = verify | AUTH_KEY | B | Y | X | PROTOID | "Server" + AUTH_INPUT_MAC = MAC(auth_input, t_hsmac) +""" +def client_part2(intro_auth_pubkey_str, client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, + intro_enc_pubkey, service_ephemeral_rend_pubkey): + dh_result1 = client_ephemeral_enc_privkey.get_shared_key(service_ephemeral_rend_pubkey, hash_nil) + dh_result2 = client_ephemeral_enc_privkey.get_shared_key(intro_enc_pubkey, hash_nil) + rend_secret_hs_input = dh_result1 + dh_result2 + intro_auth_pubkey_str + intro_enc_pubkey.serialize() + client_ephemeral_enc_pubkey.serialize() + service_ephemeral_rend_pubkey.serialize() + PROTOID + assert(len(rend_secret_hs_input) == REND_SECRET_LEN) + + ntor_key_seed = mac(rend_secret_hs_input, T_HSENC) + verify = mac(rend_secret_hs_input, T_HSVERIFY) + auth_input = verify + intro_auth_pubkey_str + intro_enc_pubkey.serialize() + service_ephemeral_rend_pubkey.serialize() + client_ephemeral_enc_pubkey.serialize() + PROTOID + "Server" + assert(len(auth_input) == AUTH_INPUT_LEN) + auth_input_mac = mac(auth_input, T_HSMAC) + + assert(ntor_key_seed) + assert(auth_input_mac) + + return ntor_key_seed, auth_input_mac + +################################################################################# + +""" +Utilities for communicating with the little-t-tor ntor wrapper to conduct the +integration tests +""" + +PROG = b"./src/test/test-hs-ntor-cl" +enhex=lambda s: binascii.b2a_hex(s) +dehex=lambda s: binascii.a2b_hex(s.strip()) + +def tor_client1(intro_auth_pubkey_str, intro_enc_pubkey, + client_ephemeral_enc_privkey, subcredential): + p = subprocess.Popen([PROG, "client1", + enhex(intro_auth_pubkey_str), + enhex(intro_enc_pubkey.serialize()), + enhex(client_ephemeral_enc_privkey.serialize()), + enhex(subcredential)], + stdout=subprocess.PIPE) + return map(dehex, p.stdout.readlines()) + +def tor_server1(intro_auth_pubkey_str, intro_enc_privkey, + client_ephemeral_enc_pubkey, subcredential): + p = subprocess.Popen([PROG, "server1", + enhex(intro_auth_pubkey_str), + enhex(intro_enc_privkey.serialize()), + enhex(client_ephemeral_enc_pubkey.serialize()), + enhex(subcredential)], + stdout=subprocess.PIPE) + return map(dehex, p.stdout.readlines()) + +def tor_client2(intro_auth_pubkey_str, client_ephemeral_enc_privkey, + intro_enc_pubkey, service_ephemeral_rend_pubkey, subcredential): + p = subprocess.Popen([PROG, "client2", + enhex(intro_auth_pubkey_str), + enhex(client_ephemeral_enc_privkey.serialize()), + enhex(intro_enc_pubkey.serialize()), + enhex(service_ephemeral_rend_pubkey.serialize()), + enhex(subcredential)], + stdout=subprocess.PIPE) + return map(dehex, p.stdout.readlines()) + +################################################################################## + +# Perform a pure python ntor test +def do_pure_python_ntor_test(): + # Initialize all needed key material + client_ephemeral_enc_privkey = PrivateKey() + client_ephemeral_enc_pubkey = client_ephemeral_enc_privkey.get_public() + intro_enc_privkey = PrivateKey() + intro_enc_pubkey = intro_enc_privkey.get_public() + intro_auth_pubkey_str = os.urandom(32) + subcredential = os.urandom(32) + + client_enc_key, client_mac_key = client_part1(intro_auth_pubkey_str, intro_enc_pubkey, client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, subcredential) + + service_enc_key, service_mac_key, service_ntor_key_seed, service_auth_input_mac, service_ephemeral_pubkey = service_part1(intro_auth_pubkey_str, client_ephemeral_enc_pubkey, intro_enc_privkey, intro_enc_pubkey, subcredential) + + assert(client_enc_key == service_enc_key) + assert(client_mac_key == service_mac_key) + + client_ntor_key_seed, client_auth_input_mac = client_part2(intro_auth_pubkey_str, client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, + intro_enc_pubkey, service_ephemeral_pubkey) + + assert(client_ntor_key_seed == service_ntor_key_seed) + assert(client_auth_input_mac == service_auth_input_mac) + + print "DONE: python dance [%s]" % repr(client_auth_input_mac) + +# Perform a pure little-t-tor integration test. +def do_little_t_tor_ntor_test(): + # Initialize all needed key material + subcredential = os.urandom(32) + client_ephemeral_enc_privkey = PrivateKey() + client_ephemeral_enc_pubkey = client_ephemeral_enc_privkey.get_public() + intro_enc_privkey = PrivateKey() + intro_enc_pubkey = intro_enc_privkey.get_public() # service-side enc key + intro_auth_pubkey_str = os.urandom(32) + + client_enc_key, client_mac_key = tor_client1(intro_auth_pubkey_str, intro_enc_pubkey, + client_ephemeral_enc_privkey, subcredential) + assert(client_enc_key) + assert(client_mac_key) + + service_enc_key, service_mac_key, service_ntor_auth_mac, service_ntor_key_seed, service_eph_pubkey = tor_server1(intro_auth_pubkey_str, + intro_enc_privkey, + client_ephemeral_enc_pubkey, + subcredential) + assert(service_enc_key) + assert(service_mac_key) + assert(service_ntor_auth_mac) + assert(service_ntor_key_seed) + + assert(client_enc_key == service_enc_key) + assert(client_mac_key == service_mac_key) + + # Turn from bytes to key + service_eph_pubkey = curve25519mod.Public(service_eph_pubkey) + + client_ntor_auth_mac, client_ntor_key_seed = tor_client2(intro_auth_pubkey_str, client_ephemeral_enc_privkey, + intro_enc_pubkey, service_eph_pubkey, subcredential) + assert(client_ntor_auth_mac) + assert(client_ntor_key_seed) + + assert(client_ntor_key_seed == service_ntor_key_seed) + assert(client_ntor_auth_mac == service_ntor_auth_mac) + + print "DONE: tor dance [%s]" % repr(client_ntor_auth_mac) + +""" +Do mixed test as follows: + 1. C -> S (python mode) + 2. C <- S (tor mode) + 3. Client computes keys (python mode) +""" +def do_first_mixed_test(): + subcredential = os.urandom(32) + + client_ephemeral_enc_privkey = PrivateKey() + client_ephemeral_enc_pubkey = client_ephemeral_enc_privkey.get_public() + intro_enc_privkey = PrivateKey() + intro_enc_pubkey = intro_enc_privkey.get_public() # service-side enc key + + intro_auth_pubkey_str = os.urandom(32) + + # Let's do mixed + client_enc_key, client_mac_key = client_part1(intro_auth_pubkey_str, intro_enc_pubkey, + client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, + subcredential) + + service_enc_key, service_mac_key, service_ntor_auth_mac, service_ntor_key_seed, service_eph_pubkey = tor_server1(intro_auth_pubkey_str, + intro_enc_privkey, + client_ephemeral_enc_pubkey, + subcredential) + assert(service_enc_key) + assert(service_mac_key) + assert(service_ntor_auth_mac) + assert(service_ntor_key_seed) + assert(service_eph_pubkey) + + assert(client_enc_key == service_enc_key) + assert(client_mac_key == service_mac_key) + + # Turn from bytes to key + service_eph_pubkey = curve25519mod.Public(service_eph_pubkey) + + client_ntor_key_seed, client_auth_input_mac = client_part2(intro_auth_pubkey_str, client_ephemeral_enc_pubkey, client_ephemeral_enc_privkey, + intro_enc_pubkey, service_eph_pubkey) + + assert(client_auth_input_mac == service_ntor_auth_mac) + assert(client_ntor_key_seed == service_ntor_key_seed) + + print "DONE: 1st mixed dance [%s]" % repr(client_auth_input_mac) + +""" +Do mixed test as follows: + 1. C -> S (tor mode) + 2. C <- S (python mode) + 3. Client computes keys (tor mode) +""" +def do_second_mixed_test(): + subcredential = os.urandom(32) + + client_ephemeral_enc_privkey = PrivateKey() + client_ephemeral_enc_pubkey = client_ephemeral_enc_privkey.get_public() + intro_enc_privkey = PrivateKey() + intro_enc_pubkey = intro_enc_privkey.get_public() # service-side enc key + + intro_auth_pubkey_str = os.urandom(32) + + # Let's do mixed + client_enc_key, client_mac_key = tor_client1(intro_auth_pubkey_str, intro_enc_pubkey, + client_ephemeral_enc_privkey, subcredential) + assert(client_enc_key) + assert(client_mac_key) + + service_enc_key, service_mac_key, service_ntor_key_seed, service_ntor_auth_mac, service_ephemeral_pubkey = service_part1(intro_auth_pubkey_str, client_ephemeral_enc_pubkey, intro_enc_privkey, intro_enc_pubkey, subcredential) + + client_ntor_auth_mac, client_ntor_key_seed = tor_client2(intro_auth_pubkey_str, client_ephemeral_enc_privkey, + intro_enc_pubkey, service_ephemeral_pubkey, subcredential) + assert(client_ntor_auth_mac) + assert(client_ntor_key_seed) + + assert(client_ntor_key_seed == service_ntor_key_seed) + assert(client_ntor_auth_mac == service_ntor_auth_mac) + + print "DONE: 2nd mixed dance [%s]" % repr(client_ntor_auth_mac) + +def do_mixed_tests(): + do_first_mixed_test() + do_second_mixed_test() + +if __name__ == '__main__': + do_pure_python_ntor_test() + do_little_t_tor_ntor_test() + do_mixed_tests() diff --git a/src/test/include.am b/src/test/include.am index 99c80af7a4..c92eab13c9 100644 --- a/src/test/include.am +++ b/src/test/include.am @@ -20,7 +20,7 @@ TESTSCRIPTS = \ src/test/test_switch_id.sh if USEPYTHON -TESTSCRIPTS += src/test/test_ntor.sh src/test/test_bt.sh +TESTSCRIPTS += src/test/test_ntor.sh src/test/test_hs_ntor.sh src/test/test_bt.sh endif TESTS += src/test/test src/test/test-slow src/test/test-memwipe \ @@ -254,6 +254,7 @@ noinst_HEADERS+= \ src/test/vote_descriptors.inc noinst_PROGRAMS+= src/test/test-ntor-cl +noinst_PROGRAMS+= src/test/test-hs-ntor-cl src_test_test_ntor_cl_SOURCES = src/test/test_ntor_cl.c src_test_test_ntor_cl_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ src_test_test_ntor_cl_LDADD = src/or/libtor.a src/common/libor.a \ @@ -264,6 +265,17 @@ src_test_test_ntor_cl_LDADD = src/or/libtor.a src/common/libor.a \ src_test_test_ntor_cl_AM_CPPFLAGS = \ -I"$(top_srcdir)/src/or" +src_test_test_hs_ntor_cl_SOURCES = src/test/test_hs_ntor_cl.c +src_test_test_hs_ntor_cl_LDFLAGS = @TOR_LDFLAGS_zlib@ @TOR_LDFLAGS_openssl@ +src_test_test_hs_ntor_cl_LDADD = src/or/libtor.a src/common/libor.a \ + src/common/libor-ctime.a \ + src/common/libor-crypto.a $(LIBKECCAK_TINY) $(LIBDONNA) \ + @TOR_ZLIB_LIBS@ @TOR_LIB_MATH@ \ + @TOR_OPENSSL_LIBS@ @TOR_LIB_WS32@ @TOR_LIB_GDI@ @CURVE25519_LIBS@ +src_test_test_hs_ntor_cl_AM_CPPFLAGS = \ + -I"$(top_srcdir)/src/or" + + noinst_PROGRAMS += src/test/test-bt-cl src_test_test_bt_cl_SOURCES = src/test/test_bt_cl.c src_test_test_bt_cl_LDADD = src/common/libor-testing.a \ @@ -276,12 +288,13 @@ src_test_test_bt_cl_CPPFLAGS= $(src_test_AM_CPPFLAGS) $(TEST_CPPFLAGS) EXTRA_DIST += \ src/test/bt_test.py \ src/test/ntor_ref.py \ + src/test/hs_ntor_ref.py \ src/test/fuzz_static_testcases.sh \ src/test/slownacl_curve25519.py \ src/test/zero_length_keys.sh \ src/test/test_keygen.sh \ src/test/test_zero_length_keys.sh \ - src/test/test_ntor.sh src/test/test_bt.sh \ + src/test/test_ntor.sh src/test/test_hs_ntor.sh src/test/test_bt.sh \ src/test/test-network.sh \ src/test/test_switch_id.sh \ src/test/test_workqueue_cancel.sh \ 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 * <b>intro_circ</b>. Return the cell. */ -static hs_cell_establish_intro_t * +static trn_cell_establish_intro_t * helper_establish_intro_v3(or_circuit_t *intro_circ) { 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_ntor.sh b/src/test/test_hs_ntor.sh new file mode 100755 index 0000000000..8a0003d44a --- /dev/null +++ b/src/test/test_hs_ntor.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# Validate Tor's ntor implementation. + +exitcode=0 + +# Run the python integration test sand return the exitcode of the python +# script. The python script might ask the testsuite to skip it if not all +# python dependencies are covered. +"${PYTHON:-python}" "${abs_top_srcdir:-.}/src/test/hs_ntor_ref.py" || exitcode=$? + +exit ${exitcode} diff --git a/src/test/test_hs_ntor_cl.c b/src/test/test_hs_ntor_cl.c new file mode 100644 index 0000000000..ed1eda58ea --- /dev/null +++ b/src/test/test_hs_ntor_cl.c @@ -0,0 +1,255 @@ +/* Copyright (c) 2017, The Tor Project, Inc. */ +/* See LICENSE for licensing information */ + +/** This is a wrapper over the little-t-tor HS ntor functions. The wrapper is + * used by src/test/hs_ntor_ref.py to conduct the HS ntor integration + * tests. + * + * The logic of this wrapper is basically copied from src/test/test_ntor_cl.c + */ + +#include "orconfig.h" +#include <stdio.h> +#include <stdlib.h> + +#define ONION_NTOR_PRIVATE +#include "or.h" +#include "util.h" +#include "compat.h" +#include "crypto.h" +#include "crypto_curve25519.h" +#include "hs_ntor.h" +#include "onion_ntor.h" + +#define N_ARGS(n) STMT_BEGIN { \ + if (argc < (n)) { \ + fprintf(stderr, "%s needs %d arguments.\n",argv[1],n); \ + return 1; \ + } \ + } STMT_END +#define BASE16(idx, var, n) STMT_BEGIN { \ + const char *s = argv[(idx)]; \ + if (base16_decode((char*)var, n, s, strlen(s)) < (int)n ) { \ + fprintf(stderr, "couldn't decode argument %d (%s)\n",idx,s); \ + return 1; \ + } \ + } STMT_END +#define INT(idx, var) STMT_BEGIN { \ + var = atoi(argv[(idx)]); \ + if (var <= 0) { \ + fprintf(stderr, "bad integer argument %d (%s)\n",idx,argv[(idx)]); \ + } \ + } STMT_END + +/** The first part of the HS ntor protocol. The client-side computes all + necessary key material and sends the appropriate message to the service. */ +static int +client1(int argc, char **argv) +{ + int retval; + + /* Inputs */ + curve25519_public_key_t intro_enc_pubkey; + ed25519_public_key_t intro_auth_pubkey; + curve25519_keypair_t client_ephemeral_enc_keypair; + uint8_t subcredential[DIGEST256_LEN]; + + /* Output */ + hs_ntor_intro_cell_keys_t hs_ntor_intro_cell_keys; + + char buf[256]; + + N_ARGS(6); + BASE16(2, intro_auth_pubkey.pubkey, ED25519_PUBKEY_LEN); + BASE16(3, intro_enc_pubkey.public_key, CURVE25519_PUBKEY_LEN); + BASE16(4, client_ephemeral_enc_keypair.seckey.secret_key, + CURVE25519_SECKEY_LEN); + BASE16(5, subcredential, DIGEST256_LEN); + + /* Generate keypair */ + curve25519_public_key_generate(&client_ephemeral_enc_keypair.pubkey, + &client_ephemeral_enc_keypair.seckey); + + retval = hs_ntor_client_get_introduce1_keys(&intro_auth_pubkey, + &intro_enc_pubkey, + &client_ephemeral_enc_keypair, + subcredential, + &hs_ntor_intro_cell_keys); + if (retval < 0) { + goto done; + } + + /* Send ENC_KEY */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_intro_cell_keys.enc_key, + sizeof(hs_ntor_intro_cell_keys.enc_key)); + printf("%s\n", buf); + /* Send MAC_KEY */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_intro_cell_keys.mac_key, + sizeof(hs_ntor_intro_cell_keys.mac_key)); + printf("%s\n", buf); + + done: + return retval; +} + +/** The second part of the HS ntor protocol. The service-side computes all + necessary key material and sends the appropriate message to the client */ +static int +server1(int argc, char **argv) +{ + int retval; + + /* Inputs */ + curve25519_keypair_t intro_enc_keypair; + ed25519_public_key_t intro_auth_pubkey; + curve25519_public_key_t client_ephemeral_enc_pubkey; + uint8_t subcredential[DIGEST256_LEN]; + + /* Output */ + hs_ntor_intro_cell_keys_t hs_ntor_intro_cell_keys; + hs_ntor_rend_cell_keys_t hs_ntor_rend_cell_keys; + curve25519_keypair_t service_ephemeral_rend_keypair; + + char buf[256]; + + N_ARGS(6); + BASE16(2, intro_auth_pubkey.pubkey, ED25519_PUBKEY_LEN); + BASE16(3, intro_enc_keypair.seckey.secret_key, CURVE25519_SECKEY_LEN); + BASE16(4, client_ephemeral_enc_pubkey.public_key, CURVE25519_PUBKEY_LEN); + BASE16(5, subcredential, DIGEST256_LEN); + + /* Generate keypair */ + curve25519_public_key_generate(&intro_enc_keypair.pubkey, + &intro_enc_keypair.seckey); + curve25519_keypair_generate(&service_ephemeral_rend_keypair, 0); + + /* Get INTRODUCE1 keys */ + retval = hs_ntor_service_get_introduce1_keys(&intro_auth_pubkey, + &intro_enc_keypair, + &client_ephemeral_enc_pubkey, + subcredential, + &hs_ntor_intro_cell_keys); + if (retval < 0) { + goto done; + } + + /* Get RENDEZVOUS1 keys */ + retval = hs_ntor_service_get_rendezvous1_keys(&intro_auth_pubkey, + &intro_enc_keypair, + &service_ephemeral_rend_keypair, + &client_ephemeral_enc_pubkey, + &hs_ntor_rend_cell_keys); + if (retval < 0) { + goto done; + } + + /* Send ENC_KEY */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_intro_cell_keys.enc_key, + sizeof(hs_ntor_intro_cell_keys.enc_key)); + printf("%s\n", buf); + /* Send MAC_KEY */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_intro_cell_keys.mac_key, + sizeof(hs_ntor_intro_cell_keys.mac_key)); + printf("%s\n", buf); + /* Send AUTH_MAC */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_rend_cell_keys.rend_cell_auth_mac, + sizeof(hs_ntor_rend_cell_keys.rend_cell_auth_mac)); + printf("%s\n", buf); + /* Send NTOR_KEY_SEED */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_rend_cell_keys.ntor_key_seed, + sizeof(hs_ntor_rend_cell_keys.ntor_key_seed)); + printf("%s\n", buf); + /* Send service ephemeral pubkey (Y) */ + base16_encode(buf, sizeof(buf), + (const char*)service_ephemeral_rend_keypair.pubkey.public_key, + sizeof(service_ephemeral_rend_keypair.pubkey.public_key)); + printf("%s\n", buf); + + done: + return retval; +} + +/** The final step of the ntor protocol, the client computes and returns the + * rendezvous key material. */ +static int +client2(int argc, char **argv) +{ + int retval; + + /* Inputs */ + curve25519_public_key_t intro_enc_pubkey; + ed25519_public_key_t intro_auth_pubkey; + curve25519_keypair_t client_ephemeral_enc_keypair; + curve25519_public_key_t service_ephemeral_rend_pubkey; + uint8_t subcredential[DIGEST256_LEN]; + + /* Output */ + hs_ntor_rend_cell_keys_t hs_ntor_rend_cell_keys; + + char buf[256]; + + N_ARGS(7); + BASE16(2, intro_auth_pubkey.pubkey, ED25519_PUBKEY_LEN); + BASE16(3, client_ephemeral_enc_keypair.seckey.secret_key, + CURVE25519_SECKEY_LEN); + BASE16(4, intro_enc_pubkey.public_key, CURVE25519_PUBKEY_LEN); + BASE16(5, service_ephemeral_rend_pubkey.public_key, CURVE25519_PUBKEY_LEN); + BASE16(6, subcredential, DIGEST256_LEN); + + /* Generate keypair */ + curve25519_public_key_generate(&client_ephemeral_enc_keypair.pubkey, + &client_ephemeral_enc_keypair.seckey); + + /* Get RENDEZVOUS1 keys */ + retval = hs_ntor_client_get_rendezvous1_keys(&intro_auth_pubkey, + &client_ephemeral_enc_keypair, + &intro_enc_pubkey, + &service_ephemeral_rend_pubkey, + &hs_ntor_rend_cell_keys); + if (retval < 0) { + goto done; + } + + /* Send AUTH_MAC */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_rend_cell_keys.rend_cell_auth_mac, + sizeof(hs_ntor_rend_cell_keys.rend_cell_auth_mac)); + printf("%s\n", buf); + /* Send NTOR_KEY_SEED */ + base16_encode(buf, sizeof(buf), + (const char*)hs_ntor_rend_cell_keys.ntor_key_seed, + sizeof(hs_ntor_rend_cell_keys.ntor_key_seed)); + printf("%s\n", buf); + + done: + return 1; +} + +/** Perform a different part of the protocol depdning on the argv used. */ +int +main(int argc, char **argv) +{ + if (argc < 2) { + fprintf(stderr, "I need arguments. Read source for more info.\n"); + return 1; + } + + curve25519_init(); + if (!strcmp(argv[1], "client1")) { + return client1(argc, argv); + } else if (!strcmp(argv[1], "server1")) { + return server1(argc, argv); + } else if (!strcmp(argv[1], "client2")) { + return client2(argc, argv); + } else { + fprintf(stderr, "What's a %s?\n", argv[1]); + return 1; + } +} + diff --git a/src/test/test_hs_service.c b/src/test/test_hs_service.c index ae9c0a0300..ec9cc4579b 100644 --- a/src/test/test_hs_service.c +++ b/src/test/test_hs_service.c @@ -17,6 +17,8 @@ #include "hs_service.h" #include "hs_intropoint.h" +#include "hs_ntor.h" + /** We simulate the creation of an outgoing ESTABLISH_INTRO cell, and then we * parse it from the receiver side. */ static void @@ -26,8 +28,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 +46,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 +57,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 +80,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,15 +98,110 @@ 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); } +/** Test the HS ntor handshake. Simulate the sending of an encrypted INTRODUCE1 + * cell, and verify the proper derivation of decryption keys on the other end. + * Then simulate the sending of an authenticated RENDEZVOUS1 cell and verify + * the proper verification on the other end. */ +static void +test_hs_ntor(void *arg) +{ + int retval; + + uint8_t subcredential[DIGEST256_LEN]; + + ed25519_keypair_t service_intro_auth_keypair; + curve25519_keypair_t service_intro_enc_keypair; + curve25519_keypair_t service_ephemeral_rend_keypair; + + curve25519_keypair_t client_ephemeral_enc_keypair; + + hs_ntor_intro_cell_keys_t client_hs_ntor_intro_cell_keys; + hs_ntor_intro_cell_keys_t service_hs_ntor_intro_cell_keys; + + hs_ntor_rend_cell_keys_t service_hs_ntor_rend_cell_keys; + hs_ntor_rend_cell_keys_t client_hs_ntor_rend_cell_keys; + + (void) arg; + + /* Generate fake data for this unittest */ + { + /* Generate fake subcredential */ + memset(subcredential, 'Z', DIGEST256_LEN); + + /* service */ + curve25519_keypair_generate(&service_intro_enc_keypair, 0); + ed25519_keypair_generate(&service_intro_auth_keypair, 0); + curve25519_keypair_generate(&service_ephemeral_rend_keypair, 0); + /* client */ + curve25519_keypair_generate(&client_ephemeral_enc_keypair, 0); + } + + /* Client: Simulate the sending of an encrypted INTRODUCE1 cell */ + retval = + hs_ntor_client_get_introduce1_keys(&service_intro_auth_keypair.pubkey, + &service_intro_enc_keypair.pubkey, + &client_ephemeral_enc_keypair, + subcredential, + &client_hs_ntor_intro_cell_keys); + tt_int_op(retval, ==, 0); + + /* Service: Simulate the decryption of the received INTRODUCE1 */ + retval = + hs_ntor_service_get_introduce1_keys(&service_intro_auth_keypair.pubkey, + &service_intro_enc_keypair, + &client_ephemeral_enc_keypair.pubkey, + subcredential, + &service_hs_ntor_intro_cell_keys); + tt_int_op(retval, ==, 0); + + /* Test that the INTRODUCE1 encryption/mac keys match! */ + tt_mem_op(client_hs_ntor_intro_cell_keys.enc_key, OP_EQ, + service_hs_ntor_intro_cell_keys.enc_key, + CIPHER256_KEY_LEN); + tt_mem_op(client_hs_ntor_intro_cell_keys.mac_key, OP_EQ, + service_hs_ntor_intro_cell_keys.mac_key, + DIGEST256_LEN); + + /* Service: Simulate creation of RENDEZVOUS1 key material. */ + retval = + hs_ntor_service_get_rendezvous1_keys(&service_intro_auth_keypair.pubkey, + &service_intro_enc_keypair, + &service_ephemeral_rend_keypair, + &client_ephemeral_enc_keypair.pubkey, + &service_hs_ntor_rend_cell_keys); + tt_int_op(retval, ==, 0); + + /* Client: Simulate the verification of a received RENDEZVOUS1 cell */ + retval = + hs_ntor_client_get_rendezvous1_keys(&service_intro_auth_keypair.pubkey, + &client_ephemeral_enc_keypair, + &service_intro_enc_keypair.pubkey, + &service_ephemeral_rend_keypair.pubkey, + &client_hs_ntor_rend_cell_keys); + tt_int_op(retval, ==, 0); + + /* Test that the RENDEZVOUS1 key material match! */ + tt_mem_op(client_hs_ntor_rend_cell_keys.rend_cell_auth_mac, OP_EQ, + service_hs_ntor_rend_cell_keys.rend_cell_auth_mac, + DIGEST256_LEN); + tt_mem_op(client_hs_ntor_rend_cell_keys.ntor_key_seed, OP_EQ, + service_hs_ntor_rend_cell_keys.ntor_key_seed, + DIGEST256_LEN); + + done: + ; +} + struct testcase_t hs_service_tests[] = { { "gen_establish_intro_cell", test_gen_establish_intro_cell, TT_FORK, NULL, NULL }, { "gen_establish_intro_cell_bad", test_gen_establish_intro_cell_bad, TT_FORK, NULL, NULL }, + { "hs_ntor", test_hs_ntor, TT_FORK, NULL, NULL }, END_OF_TESTCASES }; 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 <stdint.h> #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. - */ -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.) - */ -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. - */ -ssize_t cell_extension_fields_parse(cell_extension_fields_t **output, const uint8_t *input, const size_t len_in); +typedef struct trn_cell_extension_st trn_cell_extension_t; +/** Return a newly allocated trn_cell_extension_fields with all + * elements set to zero. + */ +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 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 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) -{ - hs_cell_establish_intro_t *val = trunnel_calloc(1, sizeof(hs_cell_establish_intro_t)); +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) +{ + 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 <stdint.h> #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 <stdint.h> #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]; |