diff options
Diffstat (limited to 'src/trunnel')
-rw-r--r-- | src/trunnel/ed25519_cert.c | 122 | ||||
-rw-r--r-- | src/trunnel/ed25519_cert.h | 90 | ||||
-rw-r--r-- | src/trunnel/hs/cell_common.c | 594 | ||||
-rw-r--r-- | src/trunnel/hs/cell_common.h | 198 | ||||
-rw-r--r-- | src/trunnel/hs/cell_common.trunnel | 12 | ||||
-rw-r--r-- | src/trunnel/hs/cell_establish_intro.c | 735 | ||||
-rw-r--r-- | src/trunnel/hs/cell_establish_intro.h | 275 | ||||
-rw-r--r-- | src/trunnel/hs/cell_establish_intro.trunnel | 41 | ||||
-rw-r--r-- | src/trunnel/hs/cell_introduce1.c | 1357 | ||||
-rw-r--r-- | src/trunnel/hs/cell_introduce1.h | 493 | ||||
-rw-r--r-- | src/trunnel/hs/cell_introduce1.trunnel | 60 | ||||
-rw-r--r-- | src/trunnel/include.am | 15 | ||||
-rw-r--r-- | src/trunnel/link_handshake.c | 206 | ||||
-rw-r--r-- | src/trunnel/link_handshake.h | 134 | ||||
-rw-r--r-- | src/trunnel/pwbox.c | 50 | ||||
-rw-r--r-- | src/trunnel/pwbox.h | 32 |
16 files changed, 4352 insertions, 62 deletions
diff --git a/src/trunnel/ed25519_cert.c b/src/trunnel/ed25519_cert.c index dc1485d19c..dd5088b231 100644 --- a/src/trunnel/ed25519_cert.c +++ b/src/trunnel/ed25519_cert.c @@ -1,4 +1,4 @@ -/* ed25519_cert.c -- generated by Trunnel v1.4.4. +/* ed25519_cert.c -- generated by Trunnel v1.5. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -97,12 +97,17 @@ ed25519_cert_extension_getlen_un_signing_key(const ed25519_cert_extension_t *inp } uint8_t -ed25519_cert_extension_get_un_signing_key(const ed25519_cert_extension_t *inp, size_t idx) +ed25519_cert_extension_get_un_signing_key(ed25519_cert_extension_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->un_signing_key[idx]; } +uint8_t +ed25519_cert_extension_getconst_un_signing_key(const ed25519_cert_extension_t *inp, size_t idx) +{ + return ed25519_cert_extension_get_un_signing_key((ed25519_cert_extension_t*)inp, idx); +} int ed25519_cert_extension_set_un_signing_key(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt) { @@ -116,6 +121,11 @@ ed25519_cert_extension_getarray_un_signing_key(ed25519_cert_extension_t *inp) { return inp->un_signing_key; } +const uint8_t * +ed25519_cert_extension_getconstarray_un_signing_key(const ed25519_cert_extension_t *inp) +{ + return (const uint8_t *)ed25519_cert_extension_getarray_un_signing_key((ed25519_cert_extension_t*)inp); +} size_t ed25519_cert_extension_getlen_un_unparsed(const ed25519_cert_extension_t *inp) { @@ -128,6 +138,11 @@ ed25519_cert_extension_get_un_unparsed(ed25519_cert_extension_t *inp, size_t idx return TRUNNEL_DYNARRAY_GET(&inp->un_unparsed, idx); } +uint8_t +ed25519_cert_extension_getconst_un_unparsed(const ed25519_cert_extension_t *inp, size_t idx) +{ + return ed25519_cert_extension_get_un_unparsed((ed25519_cert_extension_t*)inp, idx); +} int ed25519_cert_extension_set_un_unparsed(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt) { @@ -149,6 +164,11 @@ ed25519_cert_extension_getarray_un_unparsed(ed25519_cert_extension_t *inp) { return inp->un_unparsed.elts_; } +const uint8_t * +ed25519_cert_extension_getconstarray_un_unparsed(const ed25519_cert_extension_t *inp) +{ + return (const uint8_t *)ed25519_cert_extension_getarray_un_unparsed((ed25519_cert_extension_t*)inp); +} int ed25519_cert_extension_setlen_un_unparsed(ed25519_cert_extension_t *inp, size_t newlen) { @@ -157,7 +177,7 @@ ed25519_cert_extension_setlen_un_unparsed(ed25519_cert_extension_t *inp, size_t &inp->un_unparsed.n_, inp->un_unparsed.elts_, newlen, sizeof(inp->un_unparsed.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->un_unparsed.elts_ = newptr; return 0; @@ -490,12 +510,17 @@ link_specifier_getlen_un_ipv6_addr(const link_specifier_t *inp) } uint8_t -link_specifier_get_un_ipv6_addr(const link_specifier_t *inp, size_t idx) +link_specifier_get_un_ipv6_addr(link_specifier_t *inp, size_t idx) { trunnel_assert(idx < 16); return inp->un_ipv6_addr[idx]; } +uint8_t +link_specifier_getconst_un_ipv6_addr(const link_specifier_t *inp, size_t idx) +{ + return link_specifier_get_un_ipv6_addr((link_specifier_t*)inp, idx); +} int link_specifier_set_un_ipv6_addr(link_specifier_t *inp, size_t idx, uint8_t elt) { @@ -509,6 +534,11 @@ link_specifier_getarray_un_ipv6_addr(link_specifier_t *inp) { return inp->un_ipv6_addr; } +const uint8_t * +link_specifier_getconstarray_un_ipv6_addr(const link_specifier_t *inp) +{ + return (const uint8_t *)link_specifier_getarray_un_ipv6_addr((link_specifier_t*)inp); +} uint16_t link_specifier_get_un_ipv6_port(link_specifier_t *inp) { @@ -527,12 +557,17 @@ link_specifier_getlen_un_legacy_id(const link_specifier_t *inp) } uint8_t -link_specifier_get_un_legacy_id(const link_specifier_t *inp, size_t idx) +link_specifier_get_un_legacy_id(link_specifier_t *inp, size_t idx) { trunnel_assert(idx < 20); return inp->un_legacy_id[idx]; } +uint8_t +link_specifier_getconst_un_legacy_id(const link_specifier_t *inp, size_t idx) +{ + return link_specifier_get_un_legacy_id((link_specifier_t*)inp, idx); +} int link_specifier_set_un_legacy_id(link_specifier_t *inp, size_t idx, uint8_t elt) { @@ -546,6 +581,11 @@ link_specifier_getarray_un_legacy_id(link_specifier_t *inp) { return inp->un_legacy_id; } +const uint8_t * +link_specifier_getconstarray_un_legacy_id(const link_specifier_t *inp) +{ + return (const uint8_t *)link_specifier_getarray_un_legacy_id((link_specifier_t*)inp); +} size_t link_specifier_getlen_un_ed25519_id(const link_specifier_t *inp) { @@ -553,12 +593,17 @@ link_specifier_getlen_un_ed25519_id(const link_specifier_t *inp) } uint8_t -link_specifier_get_un_ed25519_id(const link_specifier_t *inp, size_t idx) +link_specifier_get_un_ed25519_id(link_specifier_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->un_ed25519_id[idx]; } +uint8_t +link_specifier_getconst_un_ed25519_id(const link_specifier_t *inp, size_t idx) +{ + return link_specifier_get_un_ed25519_id((link_specifier_t*)inp, idx); +} int link_specifier_set_un_ed25519_id(link_specifier_t *inp, size_t idx, uint8_t elt) { @@ -572,6 +617,11 @@ link_specifier_getarray_un_ed25519_id(link_specifier_t *inp) { return inp->un_ed25519_id; } +const uint8_t * +link_specifier_getconstarray_un_ed25519_id(const link_specifier_t *inp) +{ + return (const uint8_t *)link_specifier_getarray_un_ed25519_id((link_specifier_t*)inp); +} size_t link_specifier_getlen_un_unrecognized(const link_specifier_t *inp) { @@ -584,6 +634,11 @@ link_specifier_get_un_unrecognized(link_specifier_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->un_unrecognized, idx); } +uint8_t +link_specifier_getconst_un_unrecognized(const link_specifier_t *inp, size_t idx) +{ + return link_specifier_get_un_unrecognized((link_specifier_t*)inp, idx); +} int link_specifier_set_un_unrecognized(link_specifier_t *inp, size_t idx, uint8_t elt) { @@ -605,6 +660,11 @@ link_specifier_getarray_un_unrecognized(link_specifier_t *inp) { return inp->un_unrecognized.elts_; } +const uint8_t * +link_specifier_getconstarray_un_unrecognized(const link_specifier_t *inp) +{ + return (const uint8_t *)link_specifier_getarray_un_unrecognized((link_specifier_t*)inp); +} int link_specifier_setlen_un_unrecognized(link_specifier_t *inp, size_t newlen) { @@ -613,7 +673,7 @@ link_specifier_setlen_un_unrecognized(link_specifier_t *inp, size_t newlen) &inp->un_unrecognized.n_, inp->un_unrecognized.elts_, newlen, sizeof(inp->un_unrecognized.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->un_unrecognized.elts_ = newptr; return 0; @@ -1053,12 +1113,17 @@ ed25519_cert_getlen_certified_key(const ed25519_cert_t *inp) } uint8_t -ed25519_cert_get_certified_key(const ed25519_cert_t *inp, size_t idx) +ed25519_cert_get_certified_key(ed25519_cert_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->certified_key[idx]; } +uint8_t +ed25519_cert_getconst_certified_key(const ed25519_cert_t *inp, size_t idx) +{ + return ed25519_cert_get_certified_key((ed25519_cert_t*)inp, idx); +} int ed25519_cert_set_certified_key(ed25519_cert_t *inp, size_t idx, uint8_t elt) { @@ -1072,6 +1137,11 @@ ed25519_cert_getarray_certified_key(ed25519_cert_t *inp) { return inp->certified_key; } +const uint8_t * +ed25519_cert_getconstarray_certified_key(const ed25519_cert_t *inp) +{ + return (const uint8_t *)ed25519_cert_getarray_certified_key((ed25519_cert_t*)inp); +} uint8_t ed25519_cert_get_n_extensions(ed25519_cert_t *inp) { @@ -1095,6 +1165,11 @@ ed25519_cert_get_ext(ed25519_cert_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->ext, idx); } + const struct ed25519_cert_extension_st * +ed25519_cert_getconst_ext(const ed25519_cert_t *inp, size_t idx) +{ + return ed25519_cert_get_ext((ed25519_cert_t*)inp, idx); +} int ed25519_cert_set_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt) { @@ -1128,6 +1203,11 @@ ed25519_cert_getarray_ext(ed25519_cert_t *inp) { return inp->ext.elts_; } +const struct ed25519_cert_extension_st * const * +ed25519_cert_getconstarray_ext(const ed25519_cert_t *inp) +{ + return (const struct ed25519_cert_extension_st * const *)ed25519_cert_getarray_ext((ed25519_cert_t*)inp); +} int ed25519_cert_setlen_ext(ed25519_cert_t *inp, size_t newlen) { @@ -1140,7 +1220,7 @@ ed25519_cert_setlen_ext(ed25519_cert_t *inp, size_t newlen) &inp->ext.n_, inp->ext.elts_, newlen, sizeof(inp->ext.elts_[0]), (trunnel_free_fn_t) ed25519_cert_extension_free, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->ext.elts_ = newptr; return 0; @@ -1155,12 +1235,17 @@ ed25519_cert_getlen_signature(const ed25519_cert_t *inp) } uint8_t -ed25519_cert_get_signature(const ed25519_cert_t *inp, size_t idx) +ed25519_cert_get_signature(ed25519_cert_t *inp, size_t idx) { trunnel_assert(idx < 64); return inp->signature[idx]; } +uint8_t +ed25519_cert_getconst_signature(const ed25519_cert_t *inp, size_t idx) +{ + return ed25519_cert_get_signature((ed25519_cert_t*)inp, idx); +} int ed25519_cert_set_signature(ed25519_cert_t *inp, size_t idx, uint8_t elt) { @@ -1174,6 +1259,11 @@ ed25519_cert_getarray_signature(ed25519_cert_t *inp) { return inp->signature; } +const uint8_t * +ed25519_cert_getconstarray_signature(const ed25519_cert_t *inp) +{ + return (const uint8_t *)ed25519_cert_getarray_signature((ed25519_cert_t*)inp); +} const char * ed25519_cert_check(const ed25519_cert_t *obj) { @@ -1497,6 +1587,11 @@ link_specifier_list_get_spec(link_specifier_list_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->spec, idx); } + const struct link_specifier_st * +link_specifier_list_getconst_spec(const link_specifier_list_t *inp, size_t idx) +{ + return link_specifier_list_get_spec((link_specifier_list_t*)inp, idx); +} int link_specifier_list_set_spec(link_specifier_list_t *inp, size_t idx, struct link_specifier_st * elt) { @@ -1530,6 +1625,11 @@ link_specifier_list_getarray_spec(link_specifier_list_t *inp) { return inp->spec.elts_; } +const struct link_specifier_st * const * +link_specifier_list_getconstarray_spec(const link_specifier_list_t *inp) +{ + return (const struct link_specifier_st * const *)link_specifier_list_getarray_spec((link_specifier_list_t*)inp); +} int link_specifier_list_setlen_spec(link_specifier_list_t *inp, size_t newlen) { @@ -1542,7 +1642,7 @@ link_specifier_list_setlen_spec(link_specifier_list_t *inp, size_t newlen) &inp->spec.n_, inp->spec.elts_, newlen, sizeof(inp->spec.elts_[0]), (trunnel_free_fn_t) link_specifier_free, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->spec.elts_ = newptr; return 0; diff --git a/src/trunnel/ed25519_cert.h b/src/trunnel/ed25519_cert.h index 1893957209..571e6d1a53 100644 --- a/src/trunnel/ed25519_cert.h +++ b/src/trunnel/ed25519_cert.h @@ -1,4 +1,4 @@ -/* ed25519_cert.h -- generated by by Trunnel v1.4.4. +/* ed25519_cert.h -- generated by by Trunnel v1.5. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -132,7 +132,11 @@ size_t ed25519_cert_extension_getlen_un_signing_key(const ed25519_cert_extension /** Return the element at position 'idx' of the fixed array field * un_signing_key of the ed25519_cert_extension_t in 'inp'. */ -uint8_t ed25519_cert_extension_get_un_signing_key(const ed25519_cert_extension_t *inp, size_t idx); +uint8_t ed25519_cert_extension_get_un_signing_key(ed25519_cert_extension_t *inp, size_t idx); +/** As ed25519_cert_extension_get_un_signing_key, but take and return + * a const pointer + */ +uint8_t ed25519_cert_extension_getconst_un_signing_key(const ed25519_cert_extension_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * un_signing_key of the ed25519_cert_extension_t in 'inp', so that it * will hold the value 'elt'. @@ -142,6 +146,10 @@ int ed25519_cert_extension_set_un_signing_key(ed25519_cert_extension_t *inp, siz * 'inp'. */ uint8_t * ed25519_cert_extension_getarray_un_signing_key(ed25519_cert_extension_t *inp); +/** As ed25519_cert_extension_get_un_signing_key, but take and return + * a const pointer + */ +const uint8_t * ed25519_cert_extension_getconstarray_un_signing_key(const ed25519_cert_extension_t *inp); /** Return the length of the dynamic array holding the un_unparsed * field of the ed25519_cert_extension_t in 'inp'. */ @@ -150,6 +158,10 @@ size_t ed25519_cert_extension_getlen_un_unparsed(const ed25519_cert_extension_t * un_unparsed of the ed25519_cert_extension_t in 'inp'. */ uint8_t ed25519_cert_extension_get_un_unparsed(ed25519_cert_extension_t *inp, size_t idx); +/** As ed25519_cert_extension_get_un_unparsed, but take and return a + * const pointer + */ +uint8_t ed25519_cert_extension_getconst_un_unparsed(const ed25519_cert_extension_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * un_unparsed of the ed25519_cert_extension_t in 'inp', so that it * will hold the value 'elt'. @@ -163,6 +175,10 @@ int ed25519_cert_extension_add_un_unparsed(ed25519_cert_extension_t *inp, uint8_ * 'inp'. */ uint8_t * ed25519_cert_extension_getarray_un_unparsed(ed25519_cert_extension_t *inp); +/** As ed25519_cert_extension_get_un_unparsed, but take and return a + * const pointer + */ +const uint8_t * ed25519_cert_extension_getconstarray_un_unparsed(const ed25519_cert_extension_t *inp); /** Change the length of the variable-length array field un_unparsed * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on * success; return -1 and set the error code on 'inp' on failure. @@ -246,7 +262,11 @@ size_t link_specifier_getlen_un_ipv6_addr(const link_specifier_t *inp); /** Return the element at position 'idx' of the fixed array field * un_ipv6_addr of the link_specifier_t in 'inp'. */ -uint8_t link_specifier_get_un_ipv6_addr(const link_specifier_t *inp, size_t idx); +uint8_t link_specifier_get_un_ipv6_addr(link_specifier_t *inp, size_t idx); +/** As link_specifier_get_un_ipv6_addr, but take and return a const + * pointer + */ +uint8_t link_specifier_getconst_un_ipv6_addr(const link_specifier_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * un_ipv6_addr of the link_specifier_t in 'inp', so that it will hold * the value 'elt'. @@ -256,6 +276,10 @@ int link_specifier_set_un_ipv6_addr(link_specifier_t *inp, size_t idx, uint8_t e * 'inp'. */ uint8_t * link_specifier_getarray_un_ipv6_addr(link_specifier_t *inp); +/** As link_specifier_get_un_ipv6_addr, but take and return a const + * pointer + */ +const uint8_t * link_specifier_getconstarray_un_ipv6_addr(const link_specifier_t *inp); /** Return the value of the un_ipv6_port field of the link_specifier_t * in 'inp' */ @@ -272,7 +296,11 @@ size_t link_specifier_getlen_un_legacy_id(const link_specifier_t *inp); /** Return the element at position 'idx' of the fixed array field * un_legacy_id of the link_specifier_t in 'inp'. */ -uint8_t link_specifier_get_un_legacy_id(const link_specifier_t *inp, size_t idx); +uint8_t link_specifier_get_un_legacy_id(link_specifier_t *inp, size_t idx); +/** As link_specifier_get_un_legacy_id, but take and return a const + * pointer + */ +uint8_t link_specifier_getconst_un_legacy_id(const link_specifier_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * un_legacy_id of the link_specifier_t in 'inp', so that it will hold * the value 'elt'. @@ -282,6 +310,10 @@ int link_specifier_set_un_legacy_id(link_specifier_t *inp, size_t idx, uint8_t e * 'inp'. */ uint8_t * link_specifier_getarray_un_legacy_id(link_specifier_t *inp); +/** As link_specifier_get_un_legacy_id, but take and return a const + * pointer + */ +const uint8_t * link_specifier_getconstarray_un_legacy_id(const link_specifier_t *inp); /** Return the (constant) length of the array holding the * un_ed25519_id field of the link_specifier_t in 'inp'. */ @@ -289,7 +321,11 @@ size_t link_specifier_getlen_un_ed25519_id(const link_specifier_t *inp); /** Return the element at position 'idx' of the fixed array field * un_ed25519_id of the link_specifier_t in 'inp'. */ -uint8_t link_specifier_get_un_ed25519_id(const link_specifier_t *inp, size_t idx); +uint8_t link_specifier_get_un_ed25519_id(link_specifier_t *inp, size_t idx); +/** As link_specifier_get_un_ed25519_id, but take and return a const + * pointer + */ +uint8_t link_specifier_getconst_un_ed25519_id(const link_specifier_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * un_ed25519_id of the link_specifier_t in 'inp', so that it will * hold the value 'elt'. @@ -299,6 +335,10 @@ int link_specifier_set_un_ed25519_id(link_specifier_t *inp, size_t idx, uint8_t * 'inp'. */ uint8_t * link_specifier_getarray_un_ed25519_id(link_specifier_t *inp); +/** As link_specifier_get_un_ed25519_id, but take and return a const + * pointer + */ +const uint8_t * link_specifier_getconstarray_un_ed25519_id(const link_specifier_t *inp); /** Return the length of the dynamic array holding the un_unrecognized * field of the link_specifier_t in 'inp'. */ @@ -307,6 +347,10 @@ size_t link_specifier_getlen_un_unrecognized(const link_specifier_t *inp); * un_unrecognized of the link_specifier_t in 'inp'. */ uint8_t link_specifier_get_un_unrecognized(link_specifier_t *inp, size_t idx); +/** As link_specifier_get_un_unrecognized, but take and return a const + * pointer + */ +uint8_t link_specifier_getconst_un_unrecognized(const link_specifier_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * un_unrecognized of the link_specifier_t in 'inp', so that it will * hold the value 'elt'. @@ -320,6 +364,10 @@ int link_specifier_add_un_unrecognized(link_specifier_t *inp, uint8_t elt); * un_unrecognized of 'inp'. */ uint8_t * link_specifier_getarray_un_unrecognized(link_specifier_t *inp); +/** As link_specifier_get_un_unrecognized, but take and return a const + * pointer + */ +const uint8_t * link_specifier_getconstarray_un_unrecognized(const link_specifier_t *inp); /** Change the length of the variable-length array field * un_unrecognized of 'inp' to 'newlen'.Fill extra elements with 0. * Return 0 on success; return -1 and set the error code on 'inp' on @@ -404,7 +452,11 @@ size_t ed25519_cert_getlen_certified_key(const ed25519_cert_t *inp); /** Return the element at position 'idx' of the fixed array field * certified_key of the ed25519_cert_t in 'inp'. */ -uint8_t ed25519_cert_get_certified_key(const ed25519_cert_t *inp, size_t idx); +uint8_t ed25519_cert_get_certified_key(ed25519_cert_t *inp, size_t idx); +/** As ed25519_cert_get_certified_key, but take and return a const + * pointer + */ +uint8_t ed25519_cert_getconst_certified_key(const ed25519_cert_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * certified_key of the ed25519_cert_t in 'inp', so that it will hold * the value 'elt'. @@ -414,6 +466,10 @@ int ed25519_cert_set_certified_key(ed25519_cert_t *inp, size_t idx, uint8_t elt) * 'inp'. */ uint8_t * ed25519_cert_getarray_certified_key(ed25519_cert_t *inp); +/** As ed25519_cert_get_certified_key, but take and return a const + * pointer + */ +const uint8_t * ed25519_cert_getconstarray_certified_key(const ed25519_cert_t *inp); /** Return the value of the n_extensions field of the ed25519_cert_t * in 'inp' */ @@ -431,6 +487,9 @@ size_t ed25519_cert_getlen_ext(const ed25519_cert_t *inp); * ext of the ed25519_cert_t in 'inp'. */ struct ed25519_cert_extension_st * ed25519_cert_get_ext(ed25519_cert_t *inp, size_t idx); +/** As ed25519_cert_get_ext, but take and return a const pointer + */ + const struct ed25519_cert_extension_st * ed25519_cert_getconst_ext(const ed25519_cert_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * ext of the ed25519_cert_t in 'inp', so that it will hold the value * 'elt'. Free the previous value, if any. @@ -446,6 +505,9 @@ int ed25519_cert_add_ext(ed25519_cert_t *inp, struct ed25519_cert_extension_st * /** Return a pointer to the variable-length array field ext of 'inp'. */ struct ed25519_cert_extension_st * * ed25519_cert_getarray_ext(ed25519_cert_t *inp); +/** As ed25519_cert_get_ext, but take and return a const pointer + */ +const struct ed25519_cert_extension_st * const * ed25519_cert_getconstarray_ext(const ed25519_cert_t *inp); /** Change the length of the variable-length array field ext 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 @@ -459,7 +521,10 @@ size_t ed25519_cert_getlen_signature(const ed25519_cert_t *inp); /** Return the element at position 'idx' of the fixed array field * signature of the ed25519_cert_t in 'inp'. */ -uint8_t ed25519_cert_get_signature(const ed25519_cert_t *inp, size_t idx); +uint8_t ed25519_cert_get_signature(ed25519_cert_t *inp, size_t idx); +/** As ed25519_cert_get_signature, but take and return a const pointer + */ +uint8_t ed25519_cert_getconst_signature(const ed25519_cert_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * signature of the ed25519_cert_t in 'inp', so that it will hold the * value 'elt'. @@ -468,6 +533,9 @@ int ed25519_cert_set_signature(ed25519_cert_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 64-element array field signature of 'inp'. */ uint8_t * ed25519_cert_getarray_signature(ed25519_cert_t *inp); +/** As ed25519_cert_get_signature, but take and return a const pointer + */ +const uint8_t * ed25519_cert_getconstarray_signature(const ed25519_cert_t *inp); /** Return a newly allocated link_specifier_list with all elements set * to zero. */ @@ -521,6 +589,10 @@ size_t link_specifier_list_getlen_spec(const link_specifier_list_t *inp); * spec of the link_specifier_list_t in 'inp'. */ struct link_specifier_st * link_specifier_list_get_spec(link_specifier_list_t *inp, size_t idx); +/** As link_specifier_list_get_spec, but take and return a const + * pointer + */ + const struct link_specifier_st * link_specifier_list_getconst_spec(const link_specifier_list_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * spec of the link_specifier_list_t in 'inp', so that it will hold * the value 'elt'. Free the previous value, if any. @@ -537,6 +609,10 @@ int link_specifier_list_add_spec(link_specifier_list_t *inp, struct link_specifi /** Return a pointer to the variable-length array field spec of 'inp'. */ struct link_specifier_st * * link_specifier_list_getarray_spec(link_specifier_list_t *inp); +/** As link_specifier_list_get_spec, but take and return a const + * pointer + */ +const struct link_specifier_st * const * link_specifier_list_getconstarray_spec(const link_specifier_list_t *inp); /** Change the length of the variable-length array field spec 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 diff --git a/src/trunnel/hs/cell_common.c b/src/trunnel/hs/cell_common.c new file mode 100644 index 0000000000..c6c610d213 --- /dev/null +++ b/src/trunnel/hs/cell_common.c @@ -0,0 +1,594 @@ +/* cell_common.c -- generated by Trunnel v1.5. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#include <stdlib.h> +#include "trunnel-impl.h" + +#include "cell_common.h" + +#define TRUNNEL_SET_ERROR_CODE(obj) \ + do { \ + (obj)->trunnel_error_code_ = 1; \ + } while (0) + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +/* If we're runnning a static analysis tool, we don't want it to complain + * that some of our remaining-bytes checks are dead-code. */ +int cellcommon_deadcode_dummy__ = 0; +#define OR_DEADCODE_DUMMY || cellcommon_deadcode_dummy__ +#else +#define OR_DEADCODE_DUMMY +#endif + +#define CHECK_REMAINING(nbytes, label) \ + do { \ + if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \ + goto label; \ + } \ + } while (0) + +cell_extension_fields_t * +cell_extension_fields_new(void) +{ + cell_extension_fields_t *val = trunnel_calloc(1, sizeof(cell_extension_fields_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +cell_extension_fields_clear(cell_extension_fields_t *obj) +{ + (void) obj; + TRUNNEL_DYNARRAY_WIPE(&obj->field); + TRUNNEL_DYNARRAY_CLEAR(&obj->field); +} + +void +cell_extension_fields_free(cell_extension_fields_t *obj) +{ + if (obj == NULL) + return; + cell_extension_fields_clear(obj); + trunnel_memwipe(obj, sizeof(cell_extension_fields_t)); + trunnel_free_(obj); +} + +uint8_t +cell_extension_fields_get_field_type(cell_extension_fields_t *inp) +{ + return inp->field_type; +} +int +cell_extension_fields_set_field_type(cell_extension_fields_t *inp, uint8_t val) +{ + inp->field_type = val; + return 0; +} +uint8_t +cell_extension_fields_get_field_len(cell_extension_fields_t *inp) +{ + return inp->field_len; +} +int +cell_extension_fields_set_field_len(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) +{ + return TRUNNEL_DYNARRAY_LEN(&inp->field); +} + +uint8_t +cell_extension_fields_get_field(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) +{ + return cell_extension_fields_get_field((cell_extension_fields_t*)inp, idx); +} +int +cell_extension_fields_set_field(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) +{ +#if SIZE_MAX >= UINT8_MAX + if (inp->field.n_ == UINT8_MAX) + goto trunnel_alloc_failed; +#endif + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->field, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +cell_extension_fields_getarray_field(cell_extension_fields_t *inp) +{ + return inp->field.elts_; +} +const uint8_t * +cell_extension_fields_getconstarray_field(const cell_extension_fields_t *inp) +{ + return (const uint8_t *)cell_extension_fields_getarray_field((cell_extension_fields_t*)inp); +} +int +cell_extension_fields_setlen_field(cell_extension_fields_t *inp, size_t newlen) +{ + uint8_t *newptr; +#if UINT8_MAX < SIZE_MAX + if (newlen > UINT8_MAX) + goto trunnel_alloc_failed; +#endif + newptr = trunnel_dynarray_setlen(&inp->field.allocated_, + &inp->field.n_, inp->field.elts_, newlen, + sizeof(inp->field.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->field.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +cell_extension_fields_check(const cell_extension_fields_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (TRUNNEL_DYNARRAY_LEN(&obj->field) != obj->field_len) + return "Length mismatch for field"; + return NULL; +} + +ssize_t +cell_extension_fields_encoded_len(const cell_extension_fields_t *obj) +{ + ssize_t result = 0; + + if (NULL != cell_extension_fields_check(obj)) + return -1; + + + /* Length of u8 field_type */ + result += 1; + + /* Length of u8 field_len */ + result += 1; + + /* Length of u8 field[field_len] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->field); + return result; +} +int +cell_extension_fields_clear_errors(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) +{ + 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); +#endif + + if (NULL != (msg = cell_extension_fields_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 field_type */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->field_type)); + written += 1; ptr += 1; + + /* Encode u8 field_len */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->field_len)); + written += 1; ptr += 1; + + /* Encode u8 field[field_len] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->field); + trunnel_assert(obj->field_len == elt_len); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->field.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As 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) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 field_type */ + CHECK_REMAINING(1, truncated); + obj->field_type = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + + /* Parse u8 field_len */ + CHECK_REMAINING(1, truncated); + obj->field_len = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + + /* Parse u8 field[field_len] */ + CHECK_REMAINING(obj->field_len, truncated); + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->field, obj->field_len, {}); + obj->field.n_ = obj->field_len; + if (obj->field_len) + memcpy(obj->field.elts_, ptr, obj->field_len); + ptr += obj->field_len; remaining -= obj->field_len; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + trunnel_alloc_failed: + return -1; +} + +ssize_t +cell_extension_fields_parse(cell_extension_fields_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = cell_extension_fields_new(); + if (NULL == *output) + return -1; + result = cell_extension_fields_parse_into(*output, input, len_in); + if (result < 0) { + cell_extension_fields_free(*output); + *output = NULL; + } + return result; +} +cell_extension_t * +cell_extension_new(void) +{ + cell_extension_t *val = trunnel_calloc(1, sizeof(cell_extension_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +cell_extension_clear(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)); + } + } + TRUNNEL_DYNARRAY_WIPE(&obj->fields); + TRUNNEL_DYNARRAY_CLEAR(&obj->fields); +} + +void +cell_extension_free(cell_extension_t *obj) +{ + if (obj == NULL) + return; + cell_extension_clear(obj); + trunnel_memwipe(obj, sizeof(cell_extension_t)); + trunnel_free_(obj); +} + +uint8_t +cell_extension_get_num(cell_extension_t *inp) +{ + return inp->num; +} +int +cell_extension_set_num(cell_extension_t *inp, uint8_t val) +{ + inp->num = val; + return 0; +} +size_t +cell_extension_getlen_fields(const 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) +{ + 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) +{ + return cell_extension_get_fields((cell_extension_t*)inp, idx); +} +int +cell_extension_set_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt) +{ + 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); +} +int +cell_extension_set0_fields(cell_extension_t *inp, size_t idx, struct 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) +{ +#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, {}); + 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) +{ + return inp->fields.elts_; +} +const struct cell_extension_fields_st * const * +cell_extension_getconstarray_fields(const cell_extension_t *inp) +{ + return (const struct cell_extension_fields_st * const *)cell_extension_getarray_fields((cell_extension_t*)inp); +} +int +cell_extension_setlen_fields(cell_extension_t *inp, size_t newlen) +{ + struct 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, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->fields.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +cell_extension_check(const cell_extension_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + { + const char *msg; + + 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)))) + return msg; + } + } + if (TRUNNEL_DYNARRAY_LEN(&obj->fields) != obj->num) + return "Length mismatch for fields"; + return NULL; +} + +ssize_t +cell_extension_encoded_len(const cell_extension_t *obj) +{ + ssize_t result = 0; + + if (NULL != cell_extension_check(obj)) + return -1; + + + /* Length of u8 num */ + result += 1; + + /* Length of struct 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)); + } + } + return result; +} +int +cell_extension_clear_errors(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) +{ + 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); +#endif + + if (NULL != (msg = cell_extension_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 num */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->num)); + written += 1; ptr += 1; + + /* Encode struct 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)); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + } + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As 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) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 num */ + CHECK_REMAINING(1, truncated); + 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, {}); + { + cell_extension_fields_t * elt; + unsigned idx; + for (idx = 0; idx < obj->num; ++idx) { + result = 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_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + relay_fail: + trunnel_assert(result < 0); + return result; + trunnel_alloc_failed: + return -1; +} + +ssize_t +cell_extension_parse(cell_extension_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = cell_extension_new(); + if (NULL == *output) + return -1; + result = cell_extension_parse_into(*output, input, len_in); + if (result < 0) { + cell_extension_free(*output); + *output = NULL; + } + return result; +} diff --git a/src/trunnel/hs/cell_common.h b/src/trunnel/hs/cell_common.h new file mode 100644 index 0000000000..3c847f71e5 --- /dev/null +++ b/src/trunnel/hs/cell_common.h @@ -0,0 +1,198 @@ +/* cell_common.h -- generated by by Trunnel v1.5. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#ifndef TRUNNEL_CELL_COMMON_H +#define TRUNNEL_CELL_COMMON_H + +#include <stdint.h> +#include "trunnel.h" + +#if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CELL_EXTENSION_FIELDS) +struct 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 { + uint8_t num; + TRUNNEL_DYNARRAY_HEAD(, struct 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); +/** Return the number of bytes we expect to need to encode the + * 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 + * 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. + */ +const char *cell_extension_fields_check(const 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); +/** Return the value of the field_type field of the + * cell_extension_fields_t in 'inp' + */ +uint8_t cell_extension_fields_get_field_type(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; + * 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); +/** Return the value of the field_len field of the + * cell_extension_fields_t in 'inp' + */ +uint8_t cell_extension_fields_get_field_len(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; + * 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); +/** Return the length of the dynamic array holding the field field of + * the cell_extension_fields_t in 'inp'. + */ +size_t cell_extension_fields_getlen_field(const 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'. + */ +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 cell_extension_fields_getconst_field(const 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'. + */ +int cell_extension_fields_set_field(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'. + */ +int cell_extension_fields_add_field(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 + */ +const uint8_t * cell_extension_fields_getconstarray_field(const 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. + */ +cell_extension_t *cell_extension_new(void); +/** Release all storage held by the 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. + */ +ssize_t cell_extension_parse(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 + * 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 + * 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. + */ +const char *cell_extension_check(const 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' + */ +uint8_t cell_extension_get_num(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. + */ +int cell_extension_set_num(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'. + */ +size_t cell_extension_getlen_fields(const cell_extension_t *inp); +/** Return the element at position 'idx' of the dynamic array field + * fields of the 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 + */ + const struct cell_extension_fields_st * cell_extension_getconst_fields(const 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. + */ +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 + * value. + */ +int cell_extension_set0_fields(cell_extension_t *inp, size_t idx, struct cell_extension_fields_st * elt); +/** Append a new element 'elt' to the dynamic array field fields of + * the cell_extension_t in 'inp'. + */ +int cell_extension_add_fields(cell_extension_t *inp, struct 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 + */ +const struct cell_extension_fields_st * const * cell_extension_getconstarray_fields(const 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); + + +#endif diff --git a/src/trunnel/hs/cell_common.trunnel b/src/trunnel/hs/cell_common.trunnel new file mode 100644 index 0000000000..1bbec5a1fe --- /dev/null +++ b/src/trunnel/hs/cell_common.trunnel @@ -0,0 +1,12 @@ +/* This file contains common data structure that cells use. */ + +struct cell_extension_fields { + u8 field_type; + u8 field_len; + u8 field[field_len]; +}; + +struct cell_extension { + u8 num; + struct cell_extension_fields fields[num]; +}; diff --git a/src/trunnel/hs/cell_establish_intro.c b/src/trunnel/hs/cell_establish_intro.c new file mode 100644 index 0000000000..f3a3f53e91 --- /dev/null +++ b/src/trunnel/hs/cell_establish_intro.c @@ -0,0 +1,735 @@ +/* cell_establish_intro.c -- generated by Trunnel v1.5. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#include <stdlib.h> +#include "trunnel-impl.h" + +#include "cell_establish_intro.h" + +#define TRUNNEL_SET_ERROR_CODE(obj) \ + do { \ + (obj)->trunnel_error_code_ = 1; \ + } while (0) + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +/* If we're runnning a static analysis tool, we don't want it to complain + * that some of our remaining-bytes checks are dead-code. */ +int cellestablishintro_deadcode_dummy__ = 0; +#define OR_DEADCODE_DUMMY || cellestablishintro_deadcode_dummy__ +#else +#define OR_DEADCODE_DUMMY +#endif + +#define CHECK_REMAINING(nbytes, label) \ + do { \ + if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \ + goto label; \ + } \ + } 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)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +hs_cell_establish_intro_clear(hs_cell_establish_intro_t *obj) +{ + (void) obj; + TRUNNEL_DYNARRAY_WIPE(&obj->auth_key); + TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key); + 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) +{ + if (obj == NULL) + return; + hs_cell_establish_intro_clear(obj); + trunnel_memwipe(obj, sizeof(hs_cell_establish_intro_t)); + trunnel_free_(obj); +} + +const uint8_t * +hs_cell_establish_intro_get_start_cell(const hs_cell_establish_intro_t *inp) +{ + return inp->start_cell; +} +uint8_t +hs_cell_establish_intro_get_auth_key_type(hs_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) +{ + if (! ((val == 0 || val == 1 || val == 2))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->auth_key_type = val; + return 0; +} +uint16_t +hs_cell_establish_intro_get_auth_key_len(hs_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) +{ + inp->auth_key_len = val; + return 0; +} +size_t +hs_cell_establish_intro_getlen_auth_key(const hs_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) +{ + 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) +{ + return hs_cell_establish_intro_get_auth_key((hs_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) +{ + 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) +{ +#if SIZE_MAX >= UINT16_MAX + if (inp->auth_key.n_ == UINT16_MAX) + goto trunnel_alloc_failed; +#endif + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->auth_key, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +hs_cell_establish_intro_getarray_auth_key(hs_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) +{ + return (const uint8_t *)hs_cell_establish_intro_getarray_auth_key((hs_cell_establish_intro_t*)inp); +} +int +hs_cell_establish_intro_setlen_auth_key(hs_cell_establish_intro_t *inp, size_t newlen) +{ + uint8_t *newptr; +#if UINT16_MAX < SIZE_MAX + if (newlen > UINT16_MAX) + goto trunnel_alloc_failed; +#endif + newptr = trunnel_dynarray_setlen(&inp->auth_key.allocated_, + &inp->auth_key.n_, inp->auth_key.elts_, newlen, + sizeof(inp->auth_key.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->auth_key.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +struct cell_extension_st * +hs_cell_establish_intro_get_extensions(hs_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) +{ + return hs_cell_establish_intro_get_extensions((hs_cell_establish_intro_t*) inp); +} +int +hs_cell_establish_intro_set_extensions(hs_cell_establish_intro_t *inp, struct cell_extension_st *val) +{ + if (inp->extensions && inp->extensions != val) + cell_extension_free(inp->extensions); + return hs_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) +{ + inp->extensions = val; + return 0; +} +const uint8_t * +hs_cell_establish_intro_get_end_mac_fields(const hs_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) +{ + (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) +{ + 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) +{ + return hs_cell_establish_intro_get_handshake_mac((hs_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) +{ + trunnel_assert(idx < TRUNNEL_SHA3_256_LEN); + inp->handshake_mac[idx] = elt; + return 0; +} + +uint8_t * +hs_cell_establish_intro_getarray_handshake_mac(hs_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) +{ + return (const uint8_t *)hs_cell_establish_intro_getarray_handshake_mac((hs_cell_establish_intro_t*)inp); +} +uint16_t +hs_cell_establish_intro_get_sig_len(hs_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) +{ + inp->sig_len = val; + return 0; +} +const uint8_t * +hs_cell_establish_intro_get_end_sig_fields(const hs_cell_establish_intro_t *inp) +{ + return inp->end_sig_fields; +} +size_t +hs_cell_establish_intro_getlen_sig(const hs_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) +{ + 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) +{ + return hs_cell_establish_intro_get_sig((hs_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) +{ + 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) +{ +#if SIZE_MAX >= UINT16_MAX + if (inp->sig.n_ == UINT16_MAX) + goto trunnel_alloc_failed; +#endif + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->sig, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +hs_cell_establish_intro_getarray_sig(hs_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) +{ + return (const uint8_t *)hs_cell_establish_intro_getarray_sig((hs_cell_establish_intro_t*)inp); +} +int +hs_cell_establish_intro_setlen_sig(hs_cell_establish_intro_t *inp, size_t newlen) +{ + uint8_t *newptr; +#if UINT16_MAX < SIZE_MAX + if (newlen > UINT16_MAX) + goto trunnel_alloc_failed; +#endif + newptr = trunnel_dynarray_setlen(&inp->sig.allocated_, + &inp->sig.n_, inp->sig.elts_, newlen, + sizeof(inp->sig.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->sig.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +hs_cell_establish_intro_check(const hs_cell_establish_intro_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2)) + return "Integer out of bounds"; + if (TRUNNEL_DYNARRAY_LEN(&obj->auth_key) != obj->auth_key_len) + return "Length mismatch for auth_key"; + { + const char *msg; + if (NULL != (msg = cell_extension_check(obj->extensions))) + return msg; + } + if (TRUNNEL_DYNARRAY_LEN(&obj->sig) != obj->sig_len) + return "Length mismatch for sig"; + return NULL; +} + +ssize_t +hs_cell_establish_intro_encoded_len(const hs_cell_establish_intro_t *obj) +{ + ssize_t result = 0; + + if (NULL != hs_cell_establish_intro_check(obj)) + return -1; + + + /* Length of u8 auth_key_type IN [0, 1, 2] */ + result += 1; + + /* Length of u16 auth_key_len */ + result += 2; + + /* 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 u8 handshake_mac[TRUNNEL_SHA3_256_LEN] */ + result += TRUNNEL_SHA3_256_LEN; + + /* Length of u16 sig_len */ + result += 2; + + /* Length of u8 sig[sig_len] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->sig); + return result; +} +int +hs_cell_establish_intro_clear_errors(hs_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) +{ + 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); +#endif + + if (NULL != (msg = hs_cell_establish_intro_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 auth_key_type IN [0, 1, 2] */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->auth_key_type)); + written += 1; ptr += 1; + + /* Encode u16 auth_key_len */ + trunnel_assert(written <= avail); + if (avail - written < 2) + goto truncated; + trunnel_set_uint16(ptr, trunnel_htons(obj->auth_key_len)); + written += 2; ptr += 2; + + /* Encode u8 auth_key[auth_key_len] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->auth_key); + trunnel_assert(obj->auth_key_len == elt_len); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->auth_key.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + /* Encode struct cell_extension extensions */ + trunnel_assert(written <= avail); + result = cell_extension_encode(ptr, avail - written, obj->extensions); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + + /* Encode u8 handshake_mac[TRUNNEL_SHA3_256_LEN] */ + trunnel_assert(written <= avail); + if (avail - written < TRUNNEL_SHA3_256_LEN) + goto truncated; + memcpy(ptr, obj->handshake_mac, TRUNNEL_SHA3_256_LEN); + written += TRUNNEL_SHA3_256_LEN; ptr += TRUNNEL_SHA3_256_LEN; + + /* Encode u16 sig_len */ + trunnel_assert(written <= avail); + if (avail - written < 2) + goto truncated; + trunnel_set_uint16(ptr, trunnel_htons(obj->sig_len)); + written += 2; ptr += 2; + + /* Encode u8 sig[sig_len] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->sig); + trunnel_assert(obj->sig_len == elt_len); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->sig.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As hs_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) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + obj->start_cell = ptr; + + /* Parse u8 auth_key_type IN [0, 1, 2] */ + CHECK_REMAINING(1, truncated); + obj->auth_key_type = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2)) + goto fail; + + /* Parse u16 auth_key_len */ + CHECK_REMAINING(2, truncated); + obj->auth_key_len = trunnel_ntohs(trunnel_get_uint16(ptr)); + remaining -= 2; ptr += 2; + + /* Parse u8 auth_key[auth_key_len] */ + CHECK_REMAINING(obj->auth_key_len, truncated); + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->auth_key, obj->auth_key_len, {}); + obj->auth_key.n_ = obj->auth_key_len; + if (obj->auth_key_len) + 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); + if (result < 0) + goto relay_fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + obj->end_mac_fields = ptr; + + /* Parse u8 handshake_mac[TRUNNEL_SHA3_256_LEN] */ + CHECK_REMAINING(TRUNNEL_SHA3_256_LEN, truncated); + memcpy(obj->handshake_mac, ptr, TRUNNEL_SHA3_256_LEN); + remaining -= TRUNNEL_SHA3_256_LEN; ptr += TRUNNEL_SHA3_256_LEN; + + /* Parse u16 sig_len */ + CHECK_REMAINING(2, truncated); + obj->sig_len = trunnel_ntohs(trunnel_get_uint16(ptr)); + remaining -= 2; ptr += 2; + obj->end_sig_fields = ptr; + + /* Parse u8 sig[sig_len] */ + CHECK_REMAINING(obj->sig_len, truncated); + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->sig, obj->sig_len, {}); + obj->sig.n_ = obj->sig_len; + if (obj->sig_len) + memcpy(obj->sig.elts_, ptr, obj->sig_len); + ptr += obj->sig_len; remaining -= obj->sig_len; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + relay_fail: + trunnel_assert(result < 0); + return result; + trunnel_alloc_failed: + return -1; + fail: + result = -1; + return result; +} + +ssize_t +hs_cell_establish_intro_parse(hs_cell_establish_intro_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = hs_cell_establish_intro_new(); + if (NULL == *output) + return -1; + result = hs_cell_establish_intro_parse_into(*output, input, len_in); + if (result < 0) { + hs_cell_establish_intro_free(*output); + *output = NULL; + } + return result; +} +hs_cell_intro_established_t * +hs_cell_intro_established_new(void) +{ + hs_cell_intro_established_t *val = trunnel_calloc(1, sizeof(hs_cell_intro_established_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +hs_cell_intro_established_clear(hs_cell_intro_established_t *obj) +{ + (void) obj; + cell_extension_free(obj->extensions); + obj->extensions = NULL; +} + +void +hs_cell_intro_established_free(hs_cell_intro_established_t *obj) +{ + if (obj == NULL) + return; + hs_cell_intro_established_clear(obj); + trunnel_memwipe(obj, sizeof(hs_cell_intro_established_t)); + trunnel_free_(obj); +} + +struct cell_extension_st * +hs_cell_intro_established_get_extensions(hs_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) +{ + return hs_cell_intro_established_get_extensions((hs_cell_intro_established_t*) inp); +} +int +hs_cell_intro_established_set_extensions(hs_cell_intro_established_t *inp, struct cell_extension_st *val) +{ + if (inp->extensions && inp->extensions != val) + cell_extension_free(inp->extensions); + return hs_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) +{ + inp->extensions = val; + return 0; +} +const char * +hs_cell_intro_established_check(const hs_cell_intro_established_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + { + const char *msg; + if (NULL != (msg = cell_extension_check(obj->extensions))) + return msg; + } + return NULL; +} + +ssize_t +hs_cell_intro_established_encoded_len(const hs_cell_intro_established_t *obj) +{ + ssize_t result = 0; + + if (NULL != hs_cell_intro_established_check(obj)) + return -1; + + + /* Length of struct cell_extension extensions */ + result += cell_extension_encoded_len(obj->extensions); + return result; +} +int +hs_cell_intro_established_clear_errors(hs_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) +{ + 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); +#endif + + if (NULL != (msg = hs_cell_intro_established_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode struct cell_extension extensions */ + trunnel_assert(written <= avail); + result = cell_extension_encode(ptr, avail - written, obj->extensions); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As hs_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) +{ + 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); + if (result < 0) + goto relay_fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + relay_fail: + trunnel_assert(result < 0); + return result; +} + +ssize_t +hs_cell_intro_established_parse(hs_cell_intro_established_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = hs_cell_intro_established_new(); + if (NULL == *output) + return -1; + result = hs_cell_intro_established_parse_into(*output, input, len_in); + if (result < 0) { + hs_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 new file mode 100644 index 0000000000..9a066b1804 --- /dev/null +++ b/src/trunnel/hs/cell_establish_intro.h @@ -0,0 +1,275 @@ +/* cell_establish_intro.h -- generated by by Trunnel v1.5. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#ifndef TRUNNEL_CELL_ESTABLISH_INTRO_H +#define TRUNNEL_CELL_ESTABLISH_INTRO_H + +#include <stdint.h> +#include "trunnel.h" + +struct 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 { + 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; + const uint8_t *end_mac_fields; + uint8_t handshake_mac[TRUNNEL_SHA3_256_LEN]; + uint16_t sig_len; + const uint8_t *end_sig_fields; + TRUNNEL_DYNARRAY_HEAD(, uint8_t) sig; + 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; + 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. + */ +hs_cell_establish_intro_t *hs_cell_establish_intro_new(void); +/** Release all storage held by the hs_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. + */ +ssize_t hs_cell_establish_intro_parse(hs_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 + * 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 + * 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. + */ +const char *hs_cell_establish_intro_check(const hs_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); +/** 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); +/** Return the value of the auth_key_type field of the + * hs_cell_establish_intro_t in 'inp' + */ +uint8_t hs_cell_establish_intro_get_auth_key_type(hs_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; + * 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); +/** Return the value of the auth_key_len field of the + * hs_cell_establish_intro_t in 'inp' + */ +uint16_t hs_cell_establish_intro_get_auth_key_len(hs_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; + * 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); +/** Return the length of the dynamic array holding the auth_key field + * of the hs_cell_establish_intro_t in 'inp'. + */ +size_t hs_cell_establish_intro_getlen_auth_key(const hs_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'. + */ +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 + * const pointer + */ +uint8_t hs_cell_establish_intro_getconst_auth_key(const hs_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'. + */ +int hs_cell_establish_intro_set_auth_key(hs_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'. + */ +int hs_cell_establish_intro_add_auth_key(hs_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 + * const pointer + */ +const uint8_t * hs_cell_establish_intro_getconstarray_auth_key(const hs_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); +/** Return the value of the extensions field of the + * hs_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 + * const pointer + */ +const struct cell_extension_st * hs_cell_establish_intro_getconst_extensions(const hs_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 + * 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 + * previous value. + */ +int hs_cell_establish_intro_set0_extensions(hs_cell_establish_intro_t *inp, struct 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); +/** Return the (constant) length of the array holding the + * handshake_mac field of the hs_cell_establish_intro_t in 'inp'. + */ +size_t hs_cell_establish_intro_getlen_handshake_mac(const hs_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'. + */ +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 + * a const pointer + */ +uint8_t hs_cell_establish_intro_getconst_handshake_mac(const hs_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'. + */ +int hs_cell_establish_intro_set_handshake_mac(hs_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 + * a const pointer + */ +const uint8_t * hs_cell_establish_intro_getconstarray_handshake_mac(const hs_cell_establish_intro_t *inp); +/** Return the value of the sig_len field of the + * hs_cell_establish_intro_t in 'inp' + */ +uint16_t hs_cell_establish_intro_get_sig_len(hs_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; + * 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); +/** 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); +/** Return the length of the dynamic array holding the sig field of + * the hs_cell_establish_intro_t in 'inp'. + */ +size_t hs_cell_establish_intro_getlen_sig(const hs_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'. + */ +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 + * pointer + */ +uint8_t hs_cell_establish_intro_getconst_sig(const hs_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'. + */ +int hs_cell_establish_intro_set_sig(hs_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'. + */ +int hs_cell_establish_intro_add_sig(hs_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 + * pointer + */ +const uint8_t * hs_cell_establish_intro_getconstarray_sig(const hs_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 + * 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 + * '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 + * '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 + * 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); +/** Return the number of bytes we expect to need to encode the + * hs_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 + * 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 + * 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); +/** 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); +/** Return the value of the extensions field of the + * hs_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 + */ +const struct cell_extension_st * hs_cell_intro_established_getconst_extensions(const hs_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 + * 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 hs_cell_intro_established_set0_extensions(hs_cell_intro_established_t *inp, struct cell_extension_st *val); + + +#endif diff --git a/src/trunnel/hs/cell_establish_intro.trunnel b/src/trunnel/hs/cell_establish_intro.trunnel new file mode 100644 index 0000000000..4f9e8f7e08 --- /dev/null +++ b/src/trunnel/hs/cell_establish_intro.trunnel @@ -0,0 +1,41 @@ +/* + * This contains the definition of the ESTABLISH_INTRO and INTRO_ESTABLISHED + * cell for onion service version 3 and onward. The following format is + * specified in proposal 224 section 3.1. + */ + +extern struct cell_extension; + +const TRUNNEL_SHA3_256_LEN = 32; + +/* ESTABLISH_INTRO payload. See details in section 3.1.1 */ +struct hs_cell_establish_intro { + /* Indicate the start of the handshake authentication data. */ + @ptr start_cell; + + /* Authentication key material. */ + u8 auth_key_type IN [0x00, 0x01, 0x02]; + u16 auth_key_len; + u8 auth_key[auth_key_len]; + + /* Extension(s). Reserved fields. */ + struct cell_extension extensions; + @ptr end_mac_fields; + + /* Handshake MAC. */ + u8 handshake_mac[TRUNNEL_SHA3_256_LEN]; + + /* Signature */ + u16 sig_len; + /* Indicate the end of the handshake authentication data. */ + @ptr end_sig_fields; + u8 sig[sig_len]; +}; + +/* 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 { + /* Extension(s). Reserved fields. */ + struct cell_extension extensions; +}; diff --git a/src/trunnel/hs/cell_introduce1.c b/src/trunnel/hs/cell_introduce1.c new file mode 100644 index 0000000000..51f567655e --- /dev/null +++ b/src/trunnel/hs/cell_introduce1.c @@ -0,0 +1,1357 @@ +/* cell_introduce1.c -- generated by Trunnel v1.5. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#include <stdlib.h> +#include "trunnel-impl.h" + +#include "cell_introduce1.h" + +#define TRUNNEL_SET_ERROR_CODE(obj) \ + do { \ + (obj)->trunnel_error_code_ = 1; \ + } while (0) + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +/* If we're runnning a static analysis tool, we don't want it to complain + * that some of our remaining-bytes checks are dead-code. */ +int cellintroduce_deadcode_dummy__ = 0; +#define OR_DEADCODE_DUMMY || cellintroduce_deadcode_dummy__ +#else +#define OR_DEADCODE_DUMMY +#endif + +#define CHECK_REMAINING(nbytes, label) \ + do { \ + if (remaining < (nbytes) OR_DEADCODE_DUMMY) { \ + goto label; \ + } \ + } 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 link_specifier_st link_specifier_t; +link_specifier_t *link_specifier_new(void); +void link_specifier_free(link_specifier_t *victim); +ssize_t link_specifier_parse(link_specifier_t **output, const uint8_t *input, const size_t len_in); +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) +{ + hs_cell_introduce1_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce1_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +hs_cell_introduce1_clear(hs_cell_introduce1_t *obj) +{ + (void) obj; + TRUNNEL_DYNARRAY_WIPE(&obj->auth_key); + TRUNNEL_DYNARRAY_CLEAR(&obj->auth_key); + 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) +{ + if (obj == NULL) + return; + hs_cell_introduce1_clear(obj); + trunnel_memwipe(obj, sizeof(hs_cell_introduce1_t)); + trunnel_free_(obj); +} + +size_t +hs_cell_introduce1_getlen_legacy_key_id(const hs_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) +{ + 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) +{ + return hs_cell_introduce1_get_legacy_key_id((hs_cell_introduce1_t*)inp, idx); +} +int +hs_cell_introduce1_set_legacy_key_id(hs_cell_introduce1_t *inp, size_t idx, uint8_t elt) +{ + trunnel_assert(idx < TRUNNEL_SHA1_LEN); + inp->legacy_key_id[idx] = elt; + return 0; +} + +uint8_t * +hs_cell_introduce1_getarray_legacy_key_id(hs_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) +{ + return (const uint8_t *)hs_cell_introduce1_getarray_legacy_key_id((hs_cell_introduce1_t*)inp); +} +uint8_t +hs_cell_introduce1_get_auth_key_type(hs_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) +{ + if (! ((val == 0 || val == 1 || val == 2))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->auth_key_type = val; + return 0; +} +uint16_t +hs_cell_introduce1_get_auth_key_len(hs_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) +{ + inp->auth_key_len = val; + return 0; +} +size_t +hs_cell_introduce1_getlen_auth_key(const hs_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) +{ + 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) +{ + return hs_cell_introduce1_get_auth_key((hs_cell_introduce1_t*)inp, idx); +} +int +hs_cell_introduce1_set_auth_key(hs_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) +{ +#if SIZE_MAX >= UINT16_MAX + if (inp->auth_key.n_ == UINT16_MAX) + goto trunnel_alloc_failed; +#endif + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->auth_key, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +hs_cell_introduce1_getarray_auth_key(hs_cell_introduce1_t *inp) +{ + return inp->auth_key.elts_; +} +const uint8_t * +hs_cell_introduce1_getconstarray_auth_key(const hs_cell_introduce1_t *inp) +{ + return (const uint8_t *)hs_cell_introduce1_getarray_auth_key((hs_cell_introduce1_t*)inp); +} +int +hs_cell_introduce1_setlen_auth_key(hs_cell_introduce1_t *inp, size_t newlen) +{ + uint8_t *newptr; +#if UINT16_MAX < SIZE_MAX + if (newlen > UINT16_MAX) + goto trunnel_alloc_failed; +#endif + newptr = trunnel_dynarray_setlen(&inp->auth_key.allocated_, + &inp->auth_key.n_, inp->auth_key.elts_, newlen, + sizeof(inp->auth_key.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->auth_key.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +struct cell_extension_st * +hs_cell_introduce1_get_extensions(hs_cell_introduce1_t *inp) +{ + return inp->extensions; +} +const struct cell_extension_st * +hs_cell_introduce1_getconst_extensions(const hs_cell_introduce1_t *inp) +{ + return hs_cell_introduce1_get_extensions((hs_cell_introduce1_t*) inp); +} +int +hs_cell_introduce1_set_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val) +{ + if (inp->extensions && inp->extensions != val) + cell_extension_free(inp->extensions); + return hs_cell_introduce1_set0_extensions(inp, val); +} +int +hs_cell_introduce1_set0_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val) +{ + inp->extensions = val; + return 0; +} +size_t +hs_cell_introduce1_getlen_encrypted(const hs_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) +{ + return TRUNNEL_DYNARRAY_GET(&inp->encrypted, idx); +} + +uint8_t +hs_cell_introduce1_getconst_encrypted(const hs_cell_introduce1_t *inp, size_t idx) +{ + return hs_cell_introduce1_get_encrypted((hs_cell_introduce1_t*)inp, idx); +} +int +hs_cell_introduce1_set_encrypted(hs_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) +{ + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->encrypted, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +hs_cell_introduce1_getarray_encrypted(hs_cell_introduce1_t *inp) +{ + return inp->encrypted.elts_; +} +const uint8_t * +hs_cell_introduce1_getconstarray_encrypted(const hs_cell_introduce1_t *inp) +{ + return (const uint8_t *)hs_cell_introduce1_getarray_encrypted((hs_cell_introduce1_t*)inp); +} +int +hs_cell_introduce1_setlen_encrypted(hs_cell_introduce1_t *inp, size_t newlen) +{ + uint8_t *newptr; + newptr = trunnel_dynarray_setlen(&inp->encrypted.allocated_, + &inp->encrypted.n_, inp->encrypted.elts_, newlen, + sizeof(inp->encrypted.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->encrypted.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +hs_cell_introduce1_check(const hs_cell_introduce1_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2)) + return "Integer out of bounds"; + if (TRUNNEL_DYNARRAY_LEN(&obj->auth_key) != obj->auth_key_len) + return "Length mismatch for auth_key"; + { + const char *msg; + if (NULL != (msg = cell_extension_check(obj->extensions))) + return msg; + } + return NULL; +} + +ssize_t +hs_cell_introduce1_encoded_len(const hs_cell_introduce1_t *obj) +{ + ssize_t result = 0; + + if (NULL != hs_cell_introduce1_check(obj)) + return -1; + + + /* Length of u8 legacy_key_id[TRUNNEL_SHA1_LEN] */ + result += TRUNNEL_SHA1_LEN; + + /* Length of u8 auth_key_type IN [0, 1, 2] */ + result += 1; + + /* Length of u16 auth_key_len */ + result += 2; + + /* 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 u8 encrypted[] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->encrypted); + return result; +} +int +hs_cell_introduce1_clear_errors(hs_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) +{ + 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); +#endif + + if (NULL != (msg = hs_cell_introduce1_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 legacy_key_id[TRUNNEL_SHA1_LEN] */ + trunnel_assert(written <= avail); + if (avail - written < TRUNNEL_SHA1_LEN) + goto truncated; + memcpy(ptr, obj->legacy_key_id, TRUNNEL_SHA1_LEN); + written += TRUNNEL_SHA1_LEN; ptr += TRUNNEL_SHA1_LEN; + + /* Encode u8 auth_key_type IN [0, 1, 2] */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->auth_key_type)); + written += 1; ptr += 1; + + /* Encode u16 auth_key_len */ + trunnel_assert(written <= avail); + if (avail - written < 2) + goto truncated; + trunnel_set_uint16(ptr, trunnel_htons(obj->auth_key_len)); + written += 2; ptr += 2; + + /* Encode u8 auth_key[auth_key_len] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->auth_key); + trunnel_assert(obj->auth_key_len == elt_len); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->auth_key.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + /* Encode struct cell_extension extensions */ + trunnel_assert(written <= avail); + result = cell_extension_encode(ptr, avail - written, obj->extensions); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + + /* Encode u8 encrypted[] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->encrypted); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->encrypted.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As hs_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) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 legacy_key_id[TRUNNEL_SHA1_LEN] */ + CHECK_REMAINING(TRUNNEL_SHA1_LEN, truncated); + memcpy(obj->legacy_key_id, ptr, TRUNNEL_SHA1_LEN); + remaining -= TRUNNEL_SHA1_LEN; ptr += TRUNNEL_SHA1_LEN; + + /* Parse u8 auth_key_type IN [0, 1, 2] */ + CHECK_REMAINING(1, truncated); + obj->auth_key_type = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + if (! (obj->auth_key_type == 0 || obj->auth_key_type == 1 || obj->auth_key_type == 2)) + goto fail; + + /* Parse u16 auth_key_len */ + CHECK_REMAINING(2, truncated); + obj->auth_key_len = trunnel_ntohs(trunnel_get_uint16(ptr)); + remaining -= 2; ptr += 2; + + /* Parse u8 auth_key[auth_key_len] */ + CHECK_REMAINING(obj->auth_key_len, truncated); + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->auth_key, obj->auth_key_len, {}); + obj->auth_key.n_ = obj->auth_key_len; + if (obj->auth_key_len) + 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); + if (result < 0) + goto relay_fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + + /* Parse u8 encrypted[] */ + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->encrypted, remaining, {}); + obj->encrypted.n_ = remaining; + if (remaining) + memcpy(obj->encrypted.elts_, ptr, remaining); + ptr += remaining; remaining -= remaining; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + relay_fail: + trunnel_assert(result < 0); + return result; + trunnel_alloc_failed: + return -1; + fail: + result = -1; + return result; +} + +ssize_t +hs_cell_introduce1_parse(hs_cell_introduce1_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = hs_cell_introduce1_new(); + if (NULL == *output) + return -1; + result = hs_cell_introduce1_parse_into(*output, input, len_in); + if (result < 0) { + hs_cell_introduce1_free(*output); + *output = NULL; + } + return result; +} +hs_cell_introduce_ack_t * +hs_cell_introduce_ack_new(void) +{ + hs_cell_introduce_ack_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_ack_t)); + if (NULL == val) + return NULL; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +hs_cell_introduce_ack_clear(hs_cell_introduce_ack_t *obj) +{ + (void) obj; + cell_extension_free(obj->extensions); + obj->extensions = NULL; +} + +void +hs_cell_introduce_ack_free(hs_cell_introduce_ack_t *obj) +{ + if (obj == NULL) + return; + hs_cell_introduce_ack_clear(obj); + trunnel_memwipe(obj, sizeof(hs_cell_introduce_ack_t)); + trunnel_free_(obj); +} + +uint16_t +hs_cell_introduce_ack_get_status(hs_cell_introduce_ack_t *inp) +{ + return inp->status; +} +int +hs_cell_introduce_ack_set_status(hs_cell_introduce_ack_t *inp, uint16_t val) +{ + if (! ((val == 0 || val == 1 || val == 2))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->status = val; + return 0; +} +struct cell_extension_st * +hs_cell_introduce_ack_get_extensions(hs_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) +{ + return hs_cell_introduce_ack_get_extensions((hs_cell_introduce_ack_t*) inp); +} +int +hs_cell_introduce_ack_set_extensions(hs_cell_introduce_ack_t *inp, struct cell_extension_st *val) +{ + if (inp->extensions && inp->extensions != val) + cell_extension_free(inp->extensions); + return hs_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) +{ + inp->extensions = val; + return 0; +} +const char * +hs_cell_introduce_ack_check(const hs_cell_introduce_ack_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + if (! (obj->status == 0 || obj->status == 1 || obj->status == 2)) + return "Integer out of bounds"; + { + const char *msg; + if (NULL != (msg = cell_extension_check(obj->extensions))) + return msg; + } + return NULL; +} + +ssize_t +hs_cell_introduce_ack_encoded_len(const hs_cell_introduce_ack_t *obj) +{ + ssize_t result = 0; + + if (NULL != hs_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); + return result; +} +int +hs_cell_introduce_ack_clear_errors(hs_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) +{ + 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); +#endif + + if (NULL != (msg = hs_cell_introduce_ack_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u16 status IN [0, 1, 2] */ + trunnel_assert(written <= avail); + if (avail - written < 2) + goto truncated; + trunnel_set_uint16(ptr, trunnel_htons(obj->status)); + written += 2; ptr += 2; + + /* Encode struct cell_extension extensions */ + trunnel_assert(written <= avail); + result = cell_extension_encode(ptr, avail - written, obj->extensions); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As hs_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) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u16 status IN [0, 1, 2] */ + CHECK_REMAINING(2, truncated); + obj->status = trunnel_ntohs(trunnel_get_uint16(ptr)); + remaining -= 2; ptr += 2; + 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); + if (result < 0) + goto relay_fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + relay_fail: + trunnel_assert(result < 0); + return result; + fail: + result = -1; + return result; +} + +ssize_t +hs_cell_introduce_ack_parse(hs_cell_introduce_ack_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = hs_cell_introduce_ack_new(); + if (NULL == *output) + return -1; + result = hs_cell_introduce_ack_parse_into(*output, input, len_in); + if (result < 0) { + hs_cell_introduce_ack_free(*output); + *output = NULL; + } + return result; +} +hs_cell_introduce_encrypted_t * +hs_cell_introduce_encrypted_new(void) +{ + hs_cell_introduce_encrypted_t *val = trunnel_calloc(1, sizeof(hs_cell_introduce_encrypted_t)); + if (NULL == val) + return NULL; + val->onion_key_type = 1; + return val; +} + +/** Release all storage held inside 'obj', but do not free 'obj'. + */ +static void +hs_cell_introduce_encrypted_clear(hs_cell_introduce_encrypted_t *obj) +{ + (void) obj; + cell_extension_free(obj->extensions); + obj->extensions = NULL; + TRUNNEL_DYNARRAY_WIPE(&obj->onion_key); + TRUNNEL_DYNARRAY_CLEAR(&obj->onion_key); + { + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) { + link_specifier_free(TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx)); + } + } + TRUNNEL_DYNARRAY_WIPE(&obj->nspecs); + TRUNNEL_DYNARRAY_CLEAR(&obj->nspecs); + TRUNNEL_DYNARRAY_WIPE(&obj->pad); + TRUNNEL_DYNARRAY_CLEAR(&obj->pad); +} + +void +hs_cell_introduce_encrypted_free(hs_cell_introduce_encrypted_t *obj) +{ + if (obj == NULL) + return; + hs_cell_introduce_encrypted_clear(obj); + trunnel_memwipe(obj, sizeof(hs_cell_introduce_encrypted_t)); + trunnel_free_(obj); +} + +size_t +hs_cell_introduce_encrypted_getlen_rend_cookie(const hs_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) +{ + 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) +{ + return hs_cell_introduce_encrypted_get_rend_cookie((hs_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) +{ + trunnel_assert(idx < TRUNNEL_REND_COOKIE_LEN); + inp->rend_cookie[idx] = elt; + return 0; +} + +uint8_t * +hs_cell_introduce_encrypted_getarray_rend_cookie(hs_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) +{ + return (const uint8_t *)hs_cell_introduce_encrypted_getarray_rend_cookie((hs_cell_introduce_encrypted_t*)inp); +} +struct cell_extension_st * +hs_cell_introduce_encrypted_get_extensions(hs_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) +{ + return hs_cell_introduce_encrypted_get_extensions((hs_cell_introduce_encrypted_t*) inp); +} +int +hs_cell_introduce_encrypted_set_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val) +{ + if (inp->extensions && inp->extensions != val) + cell_extension_free(inp->extensions); + return hs_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) +{ + inp->extensions = val; + return 0; +} +uint8_t +hs_cell_introduce_encrypted_get_onion_key_type(hs_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) +{ + if (! ((val == 1))) { + TRUNNEL_SET_ERROR_CODE(inp); + return -1; + } + inp->onion_key_type = val; + return 0; +} +uint16_t +hs_cell_introduce_encrypted_get_onion_key_len(hs_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) +{ + inp->onion_key_len = val; + return 0; +} +size_t +hs_cell_introduce_encrypted_getlen_onion_key(const hs_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) +{ + 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) +{ + return hs_cell_introduce_encrypted_get_onion_key((hs_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) +{ + 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) +{ +#if SIZE_MAX >= UINT16_MAX + if (inp->onion_key.n_ == UINT16_MAX) + goto trunnel_alloc_failed; +#endif + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->onion_key, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +hs_cell_introduce_encrypted_getarray_onion_key(hs_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) +{ + return (const uint8_t *)hs_cell_introduce_encrypted_getarray_onion_key((hs_cell_introduce_encrypted_t*)inp); +} +int +hs_cell_introduce_encrypted_setlen_onion_key(hs_cell_introduce_encrypted_t *inp, size_t newlen) +{ + uint8_t *newptr; +#if UINT16_MAX < SIZE_MAX + if (newlen > UINT16_MAX) + goto trunnel_alloc_failed; +#endif + newptr = trunnel_dynarray_setlen(&inp->onion_key.allocated_, + &inp->onion_key.n_, inp->onion_key.elts_, newlen, + sizeof(inp->onion_key.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->onion_key.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +uint8_t +hs_cell_introduce_encrypted_get_nspec(hs_cell_introduce_encrypted_t *inp) +{ + return inp->nspec; +} +int +hs_cell_introduce_encrypted_set_nspec(hs_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) +{ + 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) +{ + 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) +{ + return hs_cell_introduce_encrypted_get_nspecs((hs_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) +{ + 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); +} +int +hs_cell_introduce_encrypted_set0_nspecs(hs_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) +{ +#if SIZE_MAX >= UINT8_MAX + if (inp->nspecs.n_ == UINT8_MAX) + goto trunnel_alloc_failed; +#endif + TRUNNEL_DYNARRAY_ADD(struct link_specifier_st *, &inp->nspecs, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +struct link_specifier_st * * +hs_cell_introduce_encrypted_getarray_nspecs(hs_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) +{ + return (const struct link_specifier_st * const *)hs_cell_introduce_encrypted_getarray_nspecs((hs_cell_introduce_encrypted_t*)inp); +} +int +hs_cell_introduce_encrypted_setlen_nspecs(hs_cell_introduce_encrypted_t *inp, size_t newlen) +{ + struct link_specifier_st * *newptr; +#if UINT8_MAX < SIZE_MAX + if (newlen > UINT8_MAX) + goto trunnel_alloc_failed; +#endif + newptr = trunnel_dynarray_setlen(&inp->nspecs.allocated_, + &inp->nspecs.n_, inp->nspecs.elts_, newlen, + sizeof(inp->nspecs.elts_[0]), (trunnel_free_fn_t) link_specifier_free, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->nspecs.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +size_t +hs_cell_introduce_encrypted_getlen_pad(const hs_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) +{ + 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) +{ + return hs_cell_introduce_encrypted_get_pad((hs_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) +{ + 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) +{ + TRUNNEL_DYNARRAY_ADD(uint8_t, &inp->pad, elt, {}); + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} + +uint8_t * +hs_cell_introduce_encrypted_getarray_pad(hs_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) +{ + return (const uint8_t *)hs_cell_introduce_encrypted_getarray_pad((hs_cell_introduce_encrypted_t*)inp); +} +int +hs_cell_introduce_encrypted_setlen_pad(hs_cell_introduce_encrypted_t *inp, size_t newlen) +{ + uint8_t *newptr; + newptr = trunnel_dynarray_setlen(&inp->pad.allocated_, + &inp->pad.n_, inp->pad.elts_, newlen, + sizeof(inp->pad.elts_[0]), (trunnel_free_fn_t) NULL, + &inp->trunnel_error_code_); + if (newlen != 0 && newptr == NULL) + goto trunnel_alloc_failed; + inp->pad.elts_ = newptr; + return 0; + trunnel_alloc_failed: + TRUNNEL_SET_ERROR_CODE(inp); + return -1; +} +const char * +hs_cell_introduce_encrypted_check(const hs_cell_introduce_encrypted_t *obj) +{ + if (obj == NULL) + return "Object was NULL"; + if (obj->trunnel_error_code_) + return "A set function failed on this object"; + { + const char *msg; + if (NULL != (msg = cell_extension_check(obj->extensions))) + return msg; + } + if (! (obj->onion_key_type == 1)) + return "Integer out of bounds"; + if (TRUNNEL_DYNARRAY_LEN(&obj->onion_key) != obj->onion_key_len) + return "Length mismatch for onion_key"; + { + const char *msg; + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) { + if (NULL != (msg = link_specifier_check(TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx)))) + return msg; + } + } + if (TRUNNEL_DYNARRAY_LEN(&obj->nspecs) != obj->nspec) + return "Length mismatch for nspecs"; + return NULL; +} + +ssize_t +hs_cell_introduce_encrypted_encoded_len(const hs_cell_introduce_encrypted_t *obj) +{ + ssize_t result = 0; + + if (NULL != hs_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 u8 onion_key_type IN [1] */ + result += 1; + + /* Length of u16 onion_key_len */ + result += 2; + + /* Length of u8 onion_key[onion_key_len] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->onion_key); + + /* Length of u8 nspec */ + result += 1; + + /* Length of struct link_specifier nspecs[nspec] */ + { + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) { + result += link_specifier_encoded_len(TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx)); + } + } + + /* Length of u8 pad[] */ + result += TRUNNEL_DYNARRAY_LEN(&obj->pad); + return result; +} +int +hs_cell_introduce_encrypted_clear_errors(hs_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) +{ + 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); +#endif + + if (NULL != (msg = hs_cell_introduce_encrypted_check(obj))) + goto check_failed; + +#ifdef TRUNNEL_CHECK_ENCODED_LEN + trunnel_assert(encoded_len >= 0); +#endif + + /* Encode u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN] */ + trunnel_assert(written <= avail); + if (avail - written < TRUNNEL_REND_COOKIE_LEN) + goto truncated; + memcpy(ptr, obj->rend_cookie, TRUNNEL_REND_COOKIE_LEN); + written += TRUNNEL_REND_COOKIE_LEN; ptr += TRUNNEL_REND_COOKIE_LEN; + + /* Encode struct cell_extension extensions */ + trunnel_assert(written <= avail); + result = cell_extension_encode(ptr, avail - written, obj->extensions); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + + /* Encode u8 onion_key_type IN [1] */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->onion_key_type)); + written += 1; ptr += 1; + + /* Encode u16 onion_key_len */ + trunnel_assert(written <= avail); + if (avail - written < 2) + goto truncated; + trunnel_set_uint16(ptr, trunnel_htons(obj->onion_key_len)); + written += 2; ptr += 2; + + /* Encode u8 onion_key[onion_key_len] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->onion_key); + trunnel_assert(obj->onion_key_len == elt_len); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->onion_key.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + /* Encode u8 nspec */ + trunnel_assert(written <= avail); + if (avail - written < 1) + goto truncated; + trunnel_set_uint8(ptr, (obj->nspec)); + written += 1; ptr += 1; + + /* Encode struct link_specifier nspecs[nspec] */ + { + + unsigned idx; + for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->nspecs); ++idx) { + trunnel_assert(written <= avail); + result = link_specifier_encode(ptr, avail - written, TRUNNEL_DYNARRAY_GET(&obj->nspecs, idx)); + if (result < 0) + goto fail; /* XXXXXXX !*/ + written += result; ptr += result; + } + } + + /* Encode u8 pad[] */ + { + size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->pad); + trunnel_assert(written <= avail); + if (avail - written < elt_len) + goto truncated; + if (elt_len) + memcpy(ptr, obj->pad.elts_, elt_len); + written += elt_len; ptr += elt_len; + } + + + trunnel_assert(ptr == output + written); +#ifdef TRUNNEL_CHECK_ENCODED_LEN + { + trunnel_assert(encoded_len >= 0); + trunnel_assert((size_t)encoded_len == written); + } + +#endif + + return written; + + truncated: + result = -2; + goto fail; + check_failed: + (void)msg; + result = -1; + goto fail; + fail: + trunnel_assert(result < 0); + return result; +} + +/** As hs_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) +{ + const uint8_t *ptr = input; + size_t remaining = len_in; + ssize_t result = 0; + (void)result; + + /* Parse u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN] */ + CHECK_REMAINING(TRUNNEL_REND_COOKIE_LEN, truncated); + 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); + if (result < 0) + goto relay_fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + + /* Parse u8 onion_key_type IN [1] */ + CHECK_REMAINING(1, truncated); + obj->onion_key_type = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + if (! (obj->onion_key_type == 1)) + goto fail; + + /* Parse u16 onion_key_len */ + CHECK_REMAINING(2, truncated); + obj->onion_key_len = trunnel_ntohs(trunnel_get_uint16(ptr)); + remaining -= 2; ptr += 2; + + /* Parse u8 onion_key[onion_key_len] */ + CHECK_REMAINING(obj->onion_key_len, truncated); + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->onion_key, obj->onion_key_len, {}); + obj->onion_key.n_ = obj->onion_key_len; + if (obj->onion_key_len) + memcpy(obj->onion_key.elts_, ptr, obj->onion_key_len); + ptr += obj->onion_key_len; remaining -= obj->onion_key_len; + + /* Parse u8 nspec */ + CHECK_REMAINING(1, truncated); + obj->nspec = (trunnel_get_uint8(ptr)); + remaining -= 1; ptr += 1; + + /* Parse struct link_specifier nspecs[nspec] */ + TRUNNEL_DYNARRAY_EXPAND(link_specifier_t *, &obj->nspecs, obj->nspec, {}); + { + link_specifier_t * elt; + unsigned idx; + for (idx = 0; idx < obj->nspec; ++idx) { + result = link_specifier_parse(&elt, ptr, remaining); + if (result < 0) + goto relay_fail; + trunnel_assert((size_t)result <= remaining); + remaining -= result; ptr += result; + TRUNNEL_DYNARRAY_ADD(link_specifier_t *, &obj->nspecs, elt, {link_specifier_free(elt);}); + } + } + + /* Parse u8 pad[] */ + TRUNNEL_DYNARRAY_EXPAND(uint8_t, &obj->pad, remaining, {}); + obj->pad.n_ = remaining; + if (remaining) + memcpy(obj->pad.elts_, ptr, remaining); + ptr += remaining; remaining -= remaining; + trunnel_assert(ptr + remaining == input + len_in); + return len_in - remaining; + + truncated: + return -2; + relay_fail: + trunnel_assert(result < 0); + return result; + trunnel_alloc_failed: + return -1; + fail: + result = -1; + return result; +} + +ssize_t +hs_cell_introduce_encrypted_parse(hs_cell_introduce_encrypted_t **output, const uint8_t *input, const size_t len_in) +{ + ssize_t result; + *output = hs_cell_introduce_encrypted_new(); + if (NULL == *output) + return -1; + result = hs_cell_introduce_encrypted_parse_into(*output, input, len_in); + if (result < 0) { + hs_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 new file mode 100644 index 0000000000..09ee0fb4b3 --- /dev/null +++ b/src/trunnel/hs/cell_introduce1.h @@ -0,0 +1,493 @@ +/* cell_introduce1.h -- generated by by Trunnel v1.5. + * https://gitweb.torproject.org/trunnel.git + * You probably shouldn't edit this file. + */ +#ifndef TRUNNEL_CELL_INTRODUCE1_H +#define TRUNNEL_CELL_INTRODUCE1_H + +#include <stdint.h> +#include "trunnel.h" + +struct 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 { + 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; + 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 { + uint16_t status; + struct 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 { + uint8_t rend_cookie[TRUNNEL_REND_COOKIE_LEN]; + struct cell_extension_st *extensions; + uint8_t onion_key_type; + uint16_t onion_key_len; + TRUNNEL_DYNARRAY_HEAD(, uint8_t) onion_key; + uint8_t nspec; + TRUNNEL_DYNARRAY_HEAD(, struct link_specifier_st *) nspecs; + TRUNNEL_DYNARRAY_HEAD(, uint8_t) pad; + 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 + * to zero. + */ +hs_cell_introduce1_t *hs_cell_introduce1_new(void); +/** Release all storage held by the hs_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', + * 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 + * 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); +/** Return the number of bytes we expect to need to encode the + * hs_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 + * 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 + * '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); +/** 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); +/** Return the (constant) length of the array holding the + * legacy_key_id field of the hs_cell_introduce1_t in 'inp'. + */ +size_t hs_cell_introduce1_getlen_legacy_key_id(const hs_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'. + */ +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 + * const pointer + */ +uint8_t hs_cell_introduce1_getconst_legacy_key_id(const hs_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'. + */ +int hs_cell_introduce1_set_legacy_key_id(hs_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 + * const pointer + */ +const uint8_t * hs_cell_introduce1_getconstarray_legacy_key_id(const hs_cell_introduce1_t *inp); +/** Return the value of the auth_key_type field of the + * hs_cell_introduce1_t in 'inp' + */ +uint8_t hs_cell_introduce1_get_auth_key_type(hs_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. + */ +int hs_cell_introduce1_set_auth_key_type(hs_cell_introduce1_t *inp, uint8_t val); +/** Return the value of the auth_key_len field of the + * hs_cell_introduce1_t in 'inp' + */ +uint16_t hs_cell_introduce1_get_auth_key_len(hs_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. + */ +int hs_cell_introduce1_set_auth_key_len(hs_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'. + */ +size_t hs_cell_introduce1_getlen_auth_key(const hs_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'. + */ +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 + * pointer + */ +uint8_t hs_cell_introduce1_getconst_auth_key(const hs_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'. + */ +int hs_cell_introduce1_set_auth_key(hs_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'. + */ +int hs_cell_introduce1_add_auth_key(hs_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 + * pointer + */ +const uint8_t * hs_cell_introduce1_getconstarray_auth_key(const hs_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); +/** Return the value of the extensions field of the + * hs_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 + * 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 + * 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 + * previous value. + */ +int hs_cell_introduce1_set0_extensions(hs_cell_introduce1_t *inp, struct cell_extension_st *val); +/** Return the length of the dynamic array holding the encrypted field + * of the hs_cell_introduce1_t in 'inp'. + */ +size_t hs_cell_introduce1_getlen_encrypted(const hs_cell_introduce1_t *inp); +/** Return the element at position 'idx' of the dynamic array field + * encrypted of the hs_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 + * pointer + */ +uint8_t hs_cell_introduce1_getconst_encrypted(const hs_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 + * hold the value 'elt'. + */ +int hs_cell_introduce1_set_encrypted(hs_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'. + */ +int hs_cell_introduce1_add_encrypted(hs_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 + * pointer + */ +const uint8_t * hs_cell_introduce1_getconstarray_encrypted(const hs_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 + * 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.) + */ +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', + * 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 + * 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); +/** Return the number of bytes we expect to need to encode the + * hs_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 + * 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 + * '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); +/** 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); +/** Return the value of the status field of the + * hs_cell_introduce_ack_t in 'inp' + */ +uint16_t hs_cell_introduce_ack_get_status(hs_cell_introduce_ack_t *inp); +/** Set the value of the status field of the hs_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); +/** Return the value of the extensions field of the + * hs_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 + * const pointer + */ +const struct cell_extension_st * hs_cell_introduce_ack_getconst_extensions(const hs_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 + * 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 + * 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 + * 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 + * '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 + * '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 + * -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); +/** 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. + */ +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 + * 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); +/** Check whether the internal state of the + * hs_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); +/** 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); +/** Return the (constant) length of the array holding the rend_cookie + * field of the hs_cell_introduce_encrypted_t in 'inp'. + */ +size_t hs_cell_introduce_encrypted_getlen_rend_cookie(const hs_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'. + */ +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 + * return a const pointer + */ +uint8_t hs_cell_introduce_encrypted_getconst_rend_cookie(const hs_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 + * 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); +/** 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 + * return a const pointer + */ +const uint8_t * hs_cell_introduce_encrypted_getconstarray_rend_cookie(const hs_cell_introduce_encrypted_t *inp); +/** Return the value of the extensions field of the + * hs_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 + */ +const struct cell_extension_st * hs_cell_introduce_encrypted_getconst_extensions(const hs_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. + */ +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 + * the previous value. + */ +int hs_cell_introduce_encrypted_set0_extensions(hs_cell_introduce_encrypted_t *inp, struct cell_extension_st *val); +/** Return the value of the onion_key_type field of the + * hs_cell_introduce_encrypted_t in 'inp' + */ +uint8_t hs_cell_introduce_encrypted_get_onion_key_type(hs_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 + * 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); +/** Return the value of the onion_key_len field of the + * hs_cell_introduce_encrypted_t in 'inp' + */ +uint16_t hs_cell_introduce_encrypted_get_onion_key_len(hs_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 + * 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); +/** Return the length of the dynamic array holding the onion_key field + * of the hs_cell_introduce_encrypted_t in 'inp'. + */ +size_t hs_cell_introduce_encrypted_getlen_onion_key(const hs_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'. + */ +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 + * a const pointer + */ +uint8_t hs_cell_introduce_encrypted_getconst_onion_key(const hs_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'. + */ +int hs_cell_introduce_encrypted_set_onion_key(hs_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'. + */ +int hs_cell_introduce_encrypted_add_onion_key(hs_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 + * a const pointer + */ +const uint8_t * hs_cell_introduce_encrypted_getconstarray_onion_key(const hs_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); +/** Return the value of the nspec field of the + * hs_cell_introduce_encrypted_t in 'inp' + */ +uint8_t hs_cell_introduce_encrypted_get_nspec(hs_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 + * 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); +/** Return the length of the dynamic array holding the nspecs field of + * the hs_cell_introduce_encrypted_t in 'inp'. + */ +size_t hs_cell_introduce_encrypted_getlen_nspecs(const hs_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'. + */ +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 + * const pointer + */ + const struct link_specifier_st * hs_cell_introduce_encrypted_getconst_nspecs(const hs_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 + * 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 + * previous value. + */ +int hs_cell_introduce_encrypted_set0_nspecs(hs_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'. + */ +int hs_cell_introduce_encrypted_add_nspecs(hs_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 + * const pointer + */ +const struct link_specifier_st * const * hs_cell_introduce_encrypted_getconstarray_nspecs(const hs_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); +/** Return the length of the dynamic array holding the pad field of + * the hs_cell_introduce_encrypted_t in 'inp'. + */ +size_t hs_cell_introduce_encrypted_getlen_pad(const hs_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'. + */ +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 + * const pointer + */ +uint8_t hs_cell_introduce_encrypted_getconst_pad(const hs_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 + * hold the value 'elt'. + */ +int hs_cell_introduce_encrypted_set_pad(hs_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'. + */ +int hs_cell_introduce_encrypted_add_pad(hs_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 + * const pointer + */ +const uint8_t * hs_cell_introduce_encrypted_getconstarray_pad(const hs_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); + + +#endif diff --git a/src/trunnel/hs/cell_introduce1.trunnel b/src/trunnel/hs/cell_introduce1.trunnel new file mode 100644 index 0000000000..f7776879cd --- /dev/null +++ b/src/trunnel/hs/cell_introduce1.trunnel @@ -0,0 +1,60 @@ +/* + * This contains the definition of the INTRODUCE1 and INTRODUCE_ACK cell for + * onion service version 3 and onward. The following format is specified in + * proposal 224 section 3.2. + */ + +/* From cell_common.trunnel. */ +extern struct cell_extension; +/* From ed25519_cert.trunnel. */ +extern struct link_specifier; + +const TRUNNEL_SHA1_LEN = 20; +const TRUNNEL_REND_COOKIE_LEN = 20; + +/* INTRODUCE1 payload. See details in section 3.2.1. */ +struct hs_cell_introduce1 { + /* Always zeroed. MUST be checked explicitely by the caller. */ + u8 legacy_key_id[TRUNNEL_SHA1_LEN]; + + /* Authentication key material. */ + u8 auth_key_type IN [0x00, 0x01, 0x02]; + u16 auth_key_len; + u8 auth_key[auth_key_len]; + + /* Extension(s). Reserved fields. */ + struct 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 { + /* Status of introduction. */ + u16 status IN [0x0000, 0x0001, 0x0002]; + + /* Extension(s). Reserved fields. */ + struct cell_extension extensions; +}; + +/* Encrypted section of the INTRODUCE1/INTRODUCE2 cell. */ +struct hs_cell_introduce_encrypted { + /* Rendezvous cookie. */ + u8 rend_cookie[TRUNNEL_REND_COOKIE_LEN]; + + /* Extension(s). Reserved fields. */ + struct cell_extension extensions; + + /* Onion key material. */ + u8 onion_key_type IN [0x01]; + u16 onion_key_len; + u8 onion_key[onion_key_len]; + + /* Link specifiers(s) */ + u8 nspec; + struct link_specifier nspecs[nspec]; + + /* Optional padding. This might be empty or not. */ + u8 pad[]; +}; diff --git a/src/trunnel/include.am b/src/trunnel/include.am index b1448b7cb2..9b26d58615 100644 --- a/src/trunnel/include.am +++ b/src/trunnel/include.am @@ -1,4 +1,3 @@ - noinst_LIBRARIES += \ src/trunnel/libor-trunnel.a @@ -18,15 +17,21 @@ TRUNNELSOURCES = \ src/ext/trunnel/trunnel.c \ src/trunnel/ed25519_cert.c \ src/trunnel/link_handshake.c \ - src/trunnel/pwbox.c + src/trunnel/pwbox.c \ + src/trunnel/hs/cell_common.c \ + src/trunnel/hs/cell_establish_intro.c \ + src/trunnel/hs/cell_introduce1.c TRUNNELHEADERS = \ src/ext/trunnel/trunnel.h \ src/ext/trunnel/trunnel-impl.h \ - src/trunnel/trunnel-local.h \ + src/trunnel/trunnel-local.h \ src/trunnel/ed25519_cert.h \ - src/trunnel/link_handshake.h \ - src/trunnel/pwbox.h + src/trunnel/link_handshake.h \ + src/trunnel/pwbox.h \ + src/trunnel/hs/cell_common.h \ + src/trunnel/hs/cell_establish_intro.h \ + src/trunnel/hs/cell_introduce1.h src_trunnel_libor_trunnel_a_SOURCES = $(TRUNNELSOURCES) src_trunnel_libor_trunnel_a_CPPFLAGS = -DTRUNNEL_LOCAL_H $(AM_CPPFLAGS) diff --git a/src/trunnel/link_handshake.c b/src/trunnel/link_handshake.c index 3ef7341ae9..a4b1fe034a 100644 --- a/src/trunnel/link_handshake.c +++ b/src/trunnel/link_handshake.c @@ -1,4 +1,4 @@ -/* link_handshake.c -- generated by Trunnel v1.4.4. +/* link_handshake.c -- generated by Trunnel v1.5. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -64,12 +64,17 @@ auth_challenge_cell_getlen_challenge(const auth_challenge_cell_t *inp) } uint8_t -auth_challenge_cell_get_challenge(const auth_challenge_cell_t *inp, size_t idx) +auth_challenge_cell_get_challenge(auth_challenge_cell_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->challenge[idx]; } +uint8_t +auth_challenge_cell_getconst_challenge(const auth_challenge_cell_t *inp, size_t idx) +{ + return auth_challenge_cell_get_challenge((auth_challenge_cell_t*)inp, idx); +} int auth_challenge_cell_set_challenge(auth_challenge_cell_t *inp, size_t idx, uint8_t elt) { @@ -83,6 +88,11 @@ auth_challenge_cell_getarray_challenge(auth_challenge_cell_t *inp) { return inp->challenge; } +const uint8_t * +auth_challenge_cell_getconstarray_challenge(const auth_challenge_cell_t *inp) +{ + return (const uint8_t *)auth_challenge_cell_getarray_challenge((auth_challenge_cell_t*)inp); +} uint16_t auth_challenge_cell_get_n_methods(auth_challenge_cell_t *inp) { @@ -106,6 +116,11 @@ auth_challenge_cell_get_methods(auth_challenge_cell_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->methods, idx); } +uint16_t +auth_challenge_cell_getconst_methods(const auth_challenge_cell_t *inp, size_t idx) +{ + return auth_challenge_cell_get_methods((auth_challenge_cell_t*)inp, idx); +} int auth_challenge_cell_set_methods(auth_challenge_cell_t *inp, size_t idx, uint16_t elt) { @@ -131,6 +146,11 @@ auth_challenge_cell_getarray_methods(auth_challenge_cell_t *inp) { return inp->methods.elts_; } +const uint16_t * +auth_challenge_cell_getconstarray_methods(const auth_challenge_cell_t *inp) +{ + return (const uint16_t *)auth_challenge_cell_getarray_methods((auth_challenge_cell_t*)inp); +} int auth_challenge_cell_setlen_methods(auth_challenge_cell_t *inp, size_t newlen) { @@ -143,7 +163,7 @@ auth_challenge_cell_setlen_methods(auth_challenge_cell_t *inp, size_t newlen) &inp->methods.n_, inp->methods.elts_, newlen, sizeof(inp->methods.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->methods.elts_ = newptr; return 0; @@ -415,6 +435,11 @@ certs_cell_cert_get_body(certs_cell_cert_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->body, idx); } +uint8_t +certs_cell_cert_getconst_body(const certs_cell_cert_t *inp, size_t idx) +{ + return certs_cell_cert_get_body((certs_cell_cert_t*)inp, idx); +} int certs_cell_cert_set_body(certs_cell_cert_t *inp, size_t idx, uint8_t elt) { @@ -440,6 +465,11 @@ certs_cell_cert_getarray_body(certs_cell_cert_t *inp) { return inp->body.elts_; } +const uint8_t * +certs_cell_cert_getconstarray_body(const certs_cell_cert_t *inp) +{ + return (const uint8_t *)certs_cell_cert_getarray_body((certs_cell_cert_t*)inp); +} int certs_cell_cert_setlen_body(certs_cell_cert_t *inp, size_t newlen) { @@ -452,7 +482,7 @@ certs_cell_cert_setlen_body(certs_cell_cert_t *inp, size_t newlen) &inp->body.n_, inp->body.elts_, newlen, sizeof(inp->body.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->body.elts_ = newptr; return 0; @@ -652,12 +682,17 @@ rsa_ed_crosscert_getlen_ed_key(const rsa_ed_crosscert_t *inp) } uint8_t -rsa_ed_crosscert_get_ed_key(const rsa_ed_crosscert_t *inp, size_t idx) +rsa_ed_crosscert_get_ed_key(rsa_ed_crosscert_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->ed_key[idx]; } +uint8_t +rsa_ed_crosscert_getconst_ed_key(const rsa_ed_crosscert_t *inp, size_t idx) +{ + return rsa_ed_crosscert_get_ed_key((rsa_ed_crosscert_t*)inp, idx); +} int rsa_ed_crosscert_set_ed_key(rsa_ed_crosscert_t *inp, size_t idx, uint8_t elt) { @@ -671,6 +706,11 @@ rsa_ed_crosscert_getarray_ed_key(rsa_ed_crosscert_t *inp) { return inp->ed_key; } +const uint8_t * +rsa_ed_crosscert_getconstarray_ed_key(const rsa_ed_crosscert_t *inp) +{ + return (const uint8_t *)rsa_ed_crosscert_getarray_ed_key((rsa_ed_crosscert_t*)inp); +} uint32_t rsa_ed_crosscert_get_expiration(rsa_ed_crosscert_t *inp) { @@ -710,6 +750,11 @@ rsa_ed_crosscert_get_sig(rsa_ed_crosscert_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->sig, idx); } +uint8_t +rsa_ed_crosscert_getconst_sig(const rsa_ed_crosscert_t *inp, size_t idx) +{ + return rsa_ed_crosscert_get_sig((rsa_ed_crosscert_t*)inp, idx); +} int rsa_ed_crosscert_set_sig(rsa_ed_crosscert_t *inp, size_t idx, uint8_t elt) { @@ -735,6 +780,11 @@ rsa_ed_crosscert_getarray_sig(rsa_ed_crosscert_t *inp) { return inp->sig.elts_; } +const uint8_t * +rsa_ed_crosscert_getconstarray_sig(const rsa_ed_crosscert_t *inp) +{ + return (const uint8_t *)rsa_ed_crosscert_getarray_sig((rsa_ed_crosscert_t*)inp); +} int rsa_ed_crosscert_setlen_sig(rsa_ed_crosscert_t *inp, size_t newlen) { @@ -747,7 +797,7 @@ rsa_ed_crosscert_setlen_sig(rsa_ed_crosscert_t *inp, size_t newlen) &inp->sig.n_, inp->sig.elts_, newlen, sizeof(inp->sig.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->sig.elts_ = newptr; return 0; @@ -964,12 +1014,17 @@ auth1_getlen_type(const auth1_t *inp) } uint8_t -auth1_get_type(const auth1_t *inp, size_t idx) +auth1_get_type(auth1_t *inp, size_t idx) { trunnel_assert(idx < 8); return inp->type[idx]; } +uint8_t +auth1_getconst_type(const auth1_t *inp, size_t idx) +{ + return auth1_get_type((auth1_t*)inp, idx); +} int auth1_set_type(auth1_t *inp, size_t idx, uint8_t elt) { @@ -983,6 +1038,11 @@ auth1_getarray_type(auth1_t *inp) { return inp->type; } +const uint8_t * +auth1_getconstarray_type(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_type((auth1_t*)inp); +} size_t auth1_getlen_cid(const auth1_t *inp) { @@ -990,12 +1050,17 @@ auth1_getlen_cid(const auth1_t *inp) } uint8_t -auth1_get_cid(const auth1_t *inp, size_t idx) +auth1_get_cid(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->cid[idx]; } +uint8_t +auth1_getconst_cid(const auth1_t *inp, size_t idx) +{ + return auth1_get_cid((auth1_t*)inp, idx); +} int auth1_set_cid(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1009,6 +1074,11 @@ auth1_getarray_cid(auth1_t *inp) { return inp->cid; } +const uint8_t * +auth1_getconstarray_cid(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_cid((auth1_t*)inp); +} size_t auth1_getlen_sid(const auth1_t *inp) { @@ -1016,12 +1086,17 @@ auth1_getlen_sid(const auth1_t *inp) } uint8_t -auth1_get_sid(const auth1_t *inp, size_t idx) +auth1_get_sid(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->sid[idx]; } +uint8_t +auth1_getconst_sid(const auth1_t *inp, size_t idx) +{ + return auth1_get_sid((auth1_t*)inp, idx); +} int auth1_set_sid(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1035,6 +1110,11 @@ auth1_getarray_sid(auth1_t *inp) { return inp->sid; } +const uint8_t * +auth1_getconstarray_sid(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_sid((auth1_t*)inp); +} size_t auth1_getlen_u1_cid_ed(const auth1_t *inp) { @@ -1042,12 +1122,17 @@ auth1_getlen_u1_cid_ed(const auth1_t *inp) } uint8_t -auth1_get_u1_cid_ed(const auth1_t *inp, size_t idx) +auth1_get_u1_cid_ed(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->u1_cid_ed[idx]; } +uint8_t +auth1_getconst_u1_cid_ed(const auth1_t *inp, size_t idx) +{ + return auth1_get_u1_cid_ed((auth1_t*)inp, idx); +} int auth1_set_u1_cid_ed(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1061,6 +1146,11 @@ auth1_getarray_u1_cid_ed(auth1_t *inp) { return inp->u1_cid_ed; } +const uint8_t * +auth1_getconstarray_u1_cid_ed(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_u1_cid_ed((auth1_t*)inp); +} size_t auth1_getlen_u1_sid_ed(const auth1_t *inp) { @@ -1068,12 +1158,17 @@ auth1_getlen_u1_sid_ed(const auth1_t *inp) } uint8_t -auth1_get_u1_sid_ed(const auth1_t *inp, size_t idx) +auth1_get_u1_sid_ed(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->u1_sid_ed[idx]; } +uint8_t +auth1_getconst_u1_sid_ed(const auth1_t *inp, size_t idx) +{ + return auth1_get_u1_sid_ed((auth1_t*)inp, idx); +} int auth1_set_u1_sid_ed(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1087,6 +1182,11 @@ auth1_getarray_u1_sid_ed(auth1_t *inp) { return inp->u1_sid_ed; } +const uint8_t * +auth1_getconstarray_u1_sid_ed(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_u1_sid_ed((auth1_t*)inp); +} size_t auth1_getlen_slog(const auth1_t *inp) { @@ -1094,12 +1194,17 @@ auth1_getlen_slog(const auth1_t *inp) } uint8_t -auth1_get_slog(const auth1_t *inp, size_t idx) +auth1_get_slog(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->slog[idx]; } +uint8_t +auth1_getconst_slog(const auth1_t *inp, size_t idx) +{ + return auth1_get_slog((auth1_t*)inp, idx); +} int auth1_set_slog(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1113,6 +1218,11 @@ auth1_getarray_slog(auth1_t *inp) { return inp->slog; } +const uint8_t * +auth1_getconstarray_slog(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_slog((auth1_t*)inp); +} size_t auth1_getlen_clog(const auth1_t *inp) { @@ -1120,12 +1230,17 @@ auth1_getlen_clog(const auth1_t *inp) } uint8_t -auth1_get_clog(const auth1_t *inp, size_t idx) +auth1_get_clog(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->clog[idx]; } +uint8_t +auth1_getconst_clog(const auth1_t *inp, size_t idx) +{ + return auth1_get_clog((auth1_t*)inp, idx); +} int auth1_set_clog(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1139,6 +1254,11 @@ auth1_getarray_clog(auth1_t *inp) { return inp->clog; } +const uint8_t * +auth1_getconstarray_clog(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_clog((auth1_t*)inp); +} size_t auth1_getlen_scert(const auth1_t *inp) { @@ -1146,12 +1266,17 @@ auth1_getlen_scert(const auth1_t *inp) } uint8_t -auth1_get_scert(const auth1_t *inp, size_t idx) +auth1_get_scert(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->scert[idx]; } +uint8_t +auth1_getconst_scert(const auth1_t *inp, size_t idx) +{ + return auth1_get_scert((auth1_t*)inp, idx); +} int auth1_set_scert(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1165,6 +1290,11 @@ auth1_getarray_scert(auth1_t *inp) { return inp->scert; } +const uint8_t * +auth1_getconstarray_scert(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_scert((auth1_t*)inp); +} size_t auth1_getlen_tlssecrets(const auth1_t *inp) { @@ -1172,12 +1302,17 @@ auth1_getlen_tlssecrets(const auth1_t *inp) } uint8_t -auth1_get_tlssecrets(const auth1_t *inp, size_t idx) +auth1_get_tlssecrets(auth1_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->tlssecrets[idx]; } +uint8_t +auth1_getconst_tlssecrets(const auth1_t *inp, size_t idx) +{ + return auth1_get_tlssecrets((auth1_t*)inp, idx); +} int auth1_set_tlssecrets(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1191,6 +1326,11 @@ auth1_getarray_tlssecrets(auth1_t *inp) { return inp->tlssecrets; } +const uint8_t * +auth1_getconstarray_tlssecrets(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_tlssecrets((auth1_t*)inp); +} const uint8_t * auth1_get_end_of_fixed_part(const auth1_t *inp) { @@ -1203,12 +1343,17 @@ auth1_getlen_rand(const auth1_t *inp) } uint8_t -auth1_get_rand(const auth1_t *inp, size_t idx) +auth1_get_rand(auth1_t *inp, size_t idx) { trunnel_assert(idx < 24); return inp->rand[idx]; } +uint8_t +auth1_getconst_rand(const auth1_t *inp, size_t idx) +{ + return auth1_get_rand((auth1_t*)inp, idx); +} int auth1_set_rand(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1222,6 +1367,11 @@ auth1_getarray_rand(auth1_t *inp) { return inp->rand; } +const uint8_t * +auth1_getconstarray_rand(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_rand((auth1_t*)inp); +} const uint8_t * auth1_get_end_of_signed(const auth1_t *inp) { @@ -1239,6 +1389,11 @@ auth1_get_sig(auth1_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->sig, idx); } +uint8_t +auth1_getconst_sig(const auth1_t *inp, size_t idx) +{ + return auth1_get_sig((auth1_t*)inp, idx); +} int auth1_set_sig(auth1_t *inp, size_t idx, uint8_t elt) { @@ -1260,6 +1415,11 @@ auth1_getarray_sig(auth1_t *inp) { return inp->sig.elts_; } +const uint8_t * +auth1_getconstarray_sig(const auth1_t *inp) +{ + return (const uint8_t *)auth1_getarray_sig((auth1_t*)inp); +} int auth1_setlen_sig(auth1_t *inp, size_t newlen) { @@ -1268,7 +1428,7 @@ auth1_setlen_sig(auth1_t *inp, size_t newlen) &inp->sig.n_, inp->sig.elts_, newlen, sizeof(inp->sig.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->sig.elts_ = newptr; return 0; @@ -1669,6 +1829,11 @@ certs_cell_get_certs(certs_cell_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->certs, idx); } + const struct certs_cell_cert_st * +certs_cell_getconst_certs(const certs_cell_t *inp, size_t idx) +{ + return certs_cell_get_certs((certs_cell_t*)inp, idx); +} int certs_cell_set_certs(certs_cell_t *inp, size_t idx, struct certs_cell_cert_st * elt) { @@ -1702,6 +1867,11 @@ certs_cell_getarray_certs(certs_cell_t *inp) { return inp->certs.elts_; } +const struct certs_cell_cert_st * const * +certs_cell_getconstarray_certs(const certs_cell_t *inp) +{ + return (const struct certs_cell_cert_st * const *)certs_cell_getarray_certs((certs_cell_t*)inp); +} int certs_cell_setlen_certs(certs_cell_t *inp, size_t newlen) { @@ -1714,7 +1884,7 @@ certs_cell_setlen_certs(certs_cell_t *inp, size_t newlen) &inp->certs.n_, inp->certs.elts_, newlen, sizeof(inp->certs.elts_[0]), (trunnel_free_fn_t) certs_cell_cert_free, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->certs.elts_ = newptr; return 0; diff --git a/src/trunnel/link_handshake.h b/src/trunnel/link_handshake.h index 2749ec7dd4..0b2ad344ab 100644 --- a/src/trunnel/link_handshake.h +++ b/src/trunnel/link_handshake.h @@ -1,4 +1,4 @@ -/* link_handshake.h -- generated by by Trunnel v1.4.4. +/* link_handshake.h -- generated by by Trunnel v1.5. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -121,7 +121,11 @@ size_t auth_challenge_cell_getlen_challenge(const auth_challenge_cell_t *inp); /** Return the element at position 'idx' of the fixed array field * challenge of the auth_challenge_cell_t in 'inp'. */ -uint8_t auth_challenge_cell_get_challenge(const auth_challenge_cell_t *inp, size_t idx); +uint8_t auth_challenge_cell_get_challenge(auth_challenge_cell_t *inp, size_t idx); +/** As auth_challenge_cell_get_challenge, but take and return a const + * pointer + */ +uint8_t auth_challenge_cell_getconst_challenge(const auth_challenge_cell_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * challenge of the auth_challenge_cell_t in 'inp', so that it will * hold the value 'elt'. @@ -130,6 +134,10 @@ int auth_challenge_cell_set_challenge(auth_challenge_cell_t *inp, size_t idx, ui /** Return a pointer to the 32-element array field challenge of 'inp'. */ uint8_t * auth_challenge_cell_getarray_challenge(auth_challenge_cell_t *inp); +/** As auth_challenge_cell_get_challenge, but take and return a const + * pointer + */ +const uint8_t * auth_challenge_cell_getconstarray_challenge(const auth_challenge_cell_t *inp); /** Return the value of the n_methods field of the * auth_challenge_cell_t in 'inp' */ @@ -147,6 +155,10 @@ size_t auth_challenge_cell_getlen_methods(const auth_challenge_cell_t *inp); * methods of the auth_challenge_cell_t in 'inp'. */ uint16_t auth_challenge_cell_get_methods(auth_challenge_cell_t *inp, size_t idx); +/** As auth_challenge_cell_get_methods, but take and return a const + * pointer + */ +uint16_t auth_challenge_cell_getconst_methods(const auth_challenge_cell_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * methods of the auth_challenge_cell_t in 'inp', so that it will hold * the value 'elt'. @@ -160,6 +172,10 @@ int auth_challenge_cell_add_methods(auth_challenge_cell_t *inp, uint16_t elt); * 'inp'. */ uint16_t * auth_challenge_cell_getarray_methods(auth_challenge_cell_t *inp); +/** As auth_challenge_cell_get_methods, but take and return a const + * pointer + */ +const uint16_t * auth_challenge_cell_getconstarray_methods(const auth_challenge_cell_t *inp); /** Change the length of the variable-length array field methods of * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success; * return -1 and set the error code on 'inp' on failure. @@ -242,6 +258,9 @@ size_t certs_cell_cert_getlen_body(const certs_cell_cert_t *inp); * body of the certs_cell_cert_t in 'inp'. */ uint8_t certs_cell_cert_get_body(certs_cell_cert_t *inp, size_t idx); +/** As certs_cell_cert_get_body, but take and return a const pointer + */ +uint8_t certs_cell_cert_getconst_body(const certs_cell_cert_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * body of the certs_cell_cert_t in 'inp', so that it will hold the * value 'elt'. @@ -254,6 +273,9 @@ int certs_cell_cert_add_body(certs_cell_cert_t *inp, uint8_t elt); /** Return a pointer to the variable-length array field body of 'inp'. */ uint8_t * certs_cell_cert_getarray_body(certs_cell_cert_t *inp); +/** As certs_cell_cert_get_body, but take and return a const pointer + */ +const uint8_t * certs_cell_cert_getconstarray_body(const certs_cell_cert_t *inp); /** Change the length of the variable-length array field body of 'inp' * to 'newlen'.Fill extra elements with 0. Return 0 on success; return * -1 and set the error code on 'inp' on failure. @@ -302,7 +324,11 @@ size_t rsa_ed_crosscert_getlen_ed_key(const rsa_ed_crosscert_t *inp); /** Return the element at position 'idx' of the fixed array field * ed_key of the rsa_ed_crosscert_t in 'inp'. */ -uint8_t rsa_ed_crosscert_get_ed_key(const rsa_ed_crosscert_t *inp, size_t idx); +uint8_t rsa_ed_crosscert_get_ed_key(rsa_ed_crosscert_t *inp, size_t idx); +/** As rsa_ed_crosscert_get_ed_key, but take and return a const + * pointer + */ +uint8_t rsa_ed_crosscert_getconst_ed_key(const rsa_ed_crosscert_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * ed_key of the rsa_ed_crosscert_t in 'inp', so that it will hold the * value 'elt'. @@ -311,6 +337,10 @@ int rsa_ed_crosscert_set_ed_key(rsa_ed_crosscert_t *inp, size_t idx, uint8_t elt /** Return a pointer to the 32-element array field ed_key of 'inp'. */ uint8_t * rsa_ed_crosscert_getarray_ed_key(rsa_ed_crosscert_t *inp); +/** As rsa_ed_crosscert_get_ed_key, but take and return a const + * pointer + */ +const uint8_t * rsa_ed_crosscert_getconstarray_ed_key(const rsa_ed_crosscert_t *inp); /** Return the value of the expiration field of the rsa_ed_crosscert_t * in 'inp' */ @@ -340,6 +370,9 @@ size_t rsa_ed_crosscert_getlen_sig(const rsa_ed_crosscert_t *inp); * sig of the rsa_ed_crosscert_t in 'inp'. */ uint8_t rsa_ed_crosscert_get_sig(rsa_ed_crosscert_t *inp, size_t idx); +/** As rsa_ed_crosscert_get_sig, but take and return a const pointer + */ +uint8_t rsa_ed_crosscert_getconst_sig(const rsa_ed_crosscert_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * sig of the rsa_ed_crosscert_t in 'inp', so that it will hold the * value 'elt'. @@ -352,6 +385,9 @@ int rsa_ed_crosscert_add_sig(rsa_ed_crosscert_t *inp, uint8_t elt); /** Return a pointer to the variable-length array field sig of 'inp'. */ uint8_t * rsa_ed_crosscert_getarray_sig(rsa_ed_crosscert_t *inp); +/** As rsa_ed_crosscert_get_sig, but take and return a const pointer + */ +const uint8_t * rsa_ed_crosscert_getconstarray_sig(const rsa_ed_crosscert_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. @@ -398,7 +434,10 @@ size_t auth1_getlen_type(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field type * of the auth1_t in 'inp'. */ -uint8_t auth1_get_type(const auth1_t *inp, size_t idx); +uint8_t auth1_get_type(auth1_t *inp, size_t idx); +/** As auth1_get_type, but take and return a const pointer + */ +uint8_t auth1_getconst_type(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field type * of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -406,6 +445,9 @@ int auth1_set_type(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 8-element array field type of 'inp'. */ uint8_t * auth1_getarray_type(auth1_t *inp); +/** As auth1_get_type, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_type(const auth1_t *inp); /** Return the (constant) length of the array holding the cid field of * the auth1_t in 'inp'. */ @@ -413,7 +455,10 @@ size_t auth1_getlen_cid(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field cid * of the auth1_t in 'inp'. */ -uint8_t auth1_get_cid(const auth1_t *inp, size_t idx); +uint8_t auth1_get_cid(auth1_t *inp, size_t idx); +/** As auth1_get_cid, but take and return a const pointer + */ +uint8_t auth1_getconst_cid(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field cid * of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -421,6 +466,9 @@ int auth1_set_cid(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field cid of 'inp'. */ uint8_t * auth1_getarray_cid(auth1_t *inp); +/** As auth1_get_cid, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_cid(const auth1_t *inp); /** Return the (constant) length of the array holding the sid field of * the auth1_t in 'inp'. */ @@ -428,7 +476,10 @@ size_t auth1_getlen_sid(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field sid * of the auth1_t in 'inp'. */ -uint8_t auth1_get_sid(const auth1_t *inp, size_t idx); +uint8_t auth1_get_sid(auth1_t *inp, size_t idx); +/** As auth1_get_sid, but take and return a const pointer + */ +uint8_t auth1_getconst_sid(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field sid * of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -436,6 +487,9 @@ int auth1_set_sid(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field sid of 'inp'. */ uint8_t * auth1_getarray_sid(auth1_t *inp); +/** As auth1_get_sid, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_sid(const auth1_t *inp); /** Return the (constant) length of the array holding the u1_cid_ed * field of the auth1_t in 'inp'. */ @@ -443,7 +497,10 @@ size_t auth1_getlen_u1_cid_ed(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field * u1_cid_ed of the auth1_t in 'inp'. */ -uint8_t auth1_get_u1_cid_ed(const auth1_t *inp, size_t idx); +uint8_t auth1_get_u1_cid_ed(auth1_t *inp, size_t idx); +/** As auth1_get_u1_cid_ed, but take and return a const pointer + */ +uint8_t auth1_getconst_u1_cid_ed(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * u1_cid_ed of the auth1_t in 'inp', so that it will hold the value * 'elt'. @@ -452,6 +509,9 @@ int auth1_set_u1_cid_ed(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field u1_cid_ed of 'inp'. */ uint8_t * auth1_getarray_u1_cid_ed(auth1_t *inp); +/** As auth1_get_u1_cid_ed, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_u1_cid_ed(const auth1_t *inp); /** Return the (constant) length of the array holding the u1_sid_ed * field of the auth1_t in 'inp'. */ @@ -459,7 +519,10 @@ size_t auth1_getlen_u1_sid_ed(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field * u1_sid_ed of the auth1_t in 'inp'. */ -uint8_t auth1_get_u1_sid_ed(const auth1_t *inp, size_t idx); +uint8_t auth1_get_u1_sid_ed(auth1_t *inp, size_t idx); +/** As auth1_get_u1_sid_ed, but take and return a const pointer + */ +uint8_t auth1_getconst_u1_sid_ed(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * u1_sid_ed of the auth1_t in 'inp', so that it will hold the value * 'elt'. @@ -468,6 +531,9 @@ int auth1_set_u1_sid_ed(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field u1_sid_ed of 'inp'. */ uint8_t * auth1_getarray_u1_sid_ed(auth1_t *inp); +/** As auth1_get_u1_sid_ed, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_u1_sid_ed(const auth1_t *inp); /** Return the (constant) length of the array holding the slog field * of the auth1_t in 'inp'. */ @@ -475,7 +541,10 @@ size_t auth1_getlen_slog(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field slog * of the auth1_t in 'inp'. */ -uint8_t auth1_get_slog(const auth1_t *inp, size_t idx); +uint8_t auth1_get_slog(auth1_t *inp, size_t idx); +/** As auth1_get_slog, but take and return a const pointer + */ +uint8_t auth1_getconst_slog(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field slog * of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -483,6 +552,9 @@ int auth1_set_slog(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field slog of 'inp'. */ uint8_t * auth1_getarray_slog(auth1_t *inp); +/** As auth1_get_slog, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_slog(const auth1_t *inp); /** Return the (constant) length of the array holding the clog field * of the auth1_t in 'inp'. */ @@ -490,7 +562,10 @@ size_t auth1_getlen_clog(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field clog * of the auth1_t in 'inp'. */ -uint8_t auth1_get_clog(const auth1_t *inp, size_t idx); +uint8_t auth1_get_clog(auth1_t *inp, size_t idx); +/** As auth1_get_clog, but take and return a const pointer + */ +uint8_t auth1_getconst_clog(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field clog * of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -498,6 +573,9 @@ int auth1_set_clog(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field clog of 'inp'. */ uint8_t * auth1_getarray_clog(auth1_t *inp); +/** As auth1_get_clog, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_clog(const auth1_t *inp); /** Return the (constant) length of the array holding the scert field * of the auth1_t in 'inp'. */ @@ -505,7 +583,10 @@ size_t auth1_getlen_scert(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field * scert of the auth1_t in 'inp'. */ -uint8_t auth1_get_scert(const auth1_t *inp, size_t idx); +uint8_t auth1_get_scert(auth1_t *inp, size_t idx); +/** As auth1_get_scert, but take and return a const pointer + */ +uint8_t auth1_getconst_scert(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * scert of the auth1_t in 'inp', so that it will hold the value * 'elt'. @@ -514,6 +595,9 @@ int auth1_set_scert(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field scert of 'inp'. */ uint8_t * auth1_getarray_scert(auth1_t *inp); +/** As auth1_get_scert, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_scert(const auth1_t *inp); /** Return the (constant) length of the array holding the tlssecrets * field of the auth1_t in 'inp'. */ @@ -521,7 +605,10 @@ size_t auth1_getlen_tlssecrets(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field * tlssecrets of the auth1_t in 'inp'. */ -uint8_t auth1_get_tlssecrets(const auth1_t *inp, size_t idx); +uint8_t auth1_get_tlssecrets(auth1_t *inp, size_t idx); +/** As auth1_get_tlssecrets, but take and return a const pointer + */ +uint8_t auth1_getconst_tlssecrets(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field * tlssecrets of the auth1_t in 'inp', so that it will hold the value * 'elt'. @@ -531,6 +618,9 @@ int auth1_set_tlssecrets(auth1_t *inp, size_t idx, uint8_t elt); * 'inp'. */ uint8_t * auth1_getarray_tlssecrets(auth1_t *inp); +/** As auth1_get_tlssecrets, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_tlssecrets(const auth1_t *inp); /** Return the position for end_of_fixed_part when we parsed this * object */ @@ -542,7 +632,10 @@ size_t auth1_getlen_rand(const auth1_t *inp); /** Return the element at position 'idx' of the fixed array field rand * of the auth1_t in 'inp'. */ -uint8_t auth1_get_rand(const auth1_t *inp, size_t idx); +uint8_t auth1_get_rand(auth1_t *inp, size_t idx); +/** As auth1_get_rand, but take and return a const pointer + */ +uint8_t auth1_getconst_rand(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field rand * of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -550,6 +643,9 @@ int auth1_set_rand(auth1_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 24-element array field rand of 'inp'. */ uint8_t * auth1_getarray_rand(auth1_t *inp); +/** As auth1_get_rand, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_rand(const auth1_t *inp); /** Return the position for end_of_signed when we parsed this object */ const uint8_t * auth1_get_end_of_signed(const auth1_t *inp); @@ -561,6 +657,9 @@ size_t auth1_getlen_sig(const auth1_t *inp); * sig of the auth1_t in 'inp'. */ uint8_t auth1_get_sig(auth1_t *inp, size_t idx); +/** As auth1_get_sig, but take and return a const pointer + */ +uint8_t auth1_getconst_sig(const auth1_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * sig of the auth1_t in 'inp', so that it will hold the value 'elt'. */ @@ -572,6 +671,9 @@ int auth1_add_sig(auth1_t *inp, uint8_t elt); /** Return a pointer to the variable-length array field sig of 'inp'. */ uint8_t * auth1_getarray_sig(auth1_t *inp); +/** As auth1_get_sig, but take and return a const pointer + */ +const uint8_t * auth1_getconstarray_sig(const auth1_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. @@ -627,6 +729,9 @@ size_t certs_cell_getlen_certs(const certs_cell_t *inp); * certs of the certs_cell_t in 'inp'. */ struct certs_cell_cert_st * certs_cell_get_certs(certs_cell_t *inp, size_t idx); +/** As certs_cell_get_certs, but take and return a const pointer + */ + const struct certs_cell_cert_st * certs_cell_getconst_certs(const certs_cell_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * certs of the certs_cell_t in 'inp', so that it will hold the value * 'elt'. Free the previous value, if any. @@ -643,6 +748,9 @@ int certs_cell_add_certs(certs_cell_t *inp, struct certs_cell_cert_st * elt); * 'inp'. */ struct certs_cell_cert_st * * certs_cell_getarray_certs(certs_cell_t *inp); +/** As certs_cell_get_certs, but take and return a const pointer + */ +const struct certs_cell_cert_st * const * certs_cell_getconstarray_certs(const certs_cell_t *inp); /** Change the length of the variable-length array field certs of * 'inp' to 'newlen'.Fill extra elements with NULL; free removed * elements. Return 0 on success; return -1 and set the error code on diff --git a/src/trunnel/pwbox.c b/src/trunnel/pwbox.c index 9b348a9b30..059fcfd7da 100644 --- a/src/trunnel/pwbox.c +++ b/src/trunnel/pwbox.c @@ -1,4 +1,4 @@ -/* pwbox.c -- generated by Trunnel v1.4.4. +/* pwbox.c -- generated by Trunnel v1.5. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -114,6 +114,11 @@ pwbox_encoded_get_skey_header(pwbox_encoded_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->skey_header, idx); } +uint8_t +pwbox_encoded_getconst_skey_header(const pwbox_encoded_t *inp, size_t idx) +{ + return pwbox_encoded_get_skey_header((pwbox_encoded_t*)inp, idx); +} int pwbox_encoded_set_skey_header(pwbox_encoded_t *inp, size_t idx, uint8_t elt) { @@ -139,6 +144,11 @@ pwbox_encoded_getarray_skey_header(pwbox_encoded_t *inp) { return inp->skey_header.elts_; } +const uint8_t * +pwbox_encoded_getconstarray_skey_header(const pwbox_encoded_t *inp) +{ + return (const uint8_t *)pwbox_encoded_getarray_skey_header((pwbox_encoded_t*)inp); +} int pwbox_encoded_setlen_skey_header(pwbox_encoded_t *inp, size_t newlen) { @@ -151,7 +161,7 @@ pwbox_encoded_setlen_skey_header(pwbox_encoded_t *inp, size_t newlen) &inp->skey_header.n_, inp->skey_header.elts_, newlen, sizeof(inp->skey_header.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->skey_header.elts_ = newptr; return 0; @@ -166,12 +176,17 @@ pwbox_encoded_getlen_iv(const pwbox_encoded_t *inp) } uint8_t -pwbox_encoded_get_iv(const pwbox_encoded_t *inp, size_t idx) +pwbox_encoded_get_iv(pwbox_encoded_t *inp, size_t idx) { trunnel_assert(idx < 16); return inp->iv[idx]; } +uint8_t +pwbox_encoded_getconst_iv(const pwbox_encoded_t *inp, size_t idx) +{ + return pwbox_encoded_get_iv((pwbox_encoded_t*)inp, idx); +} int pwbox_encoded_set_iv(pwbox_encoded_t *inp, size_t idx, uint8_t elt) { @@ -185,6 +200,11 @@ pwbox_encoded_getarray_iv(pwbox_encoded_t *inp) { return inp->iv; } +const uint8_t * +pwbox_encoded_getconstarray_iv(const pwbox_encoded_t *inp) +{ + return (const uint8_t *)pwbox_encoded_getarray_iv((pwbox_encoded_t*)inp); +} size_t pwbox_encoded_getlen_data(const pwbox_encoded_t *inp) { @@ -197,6 +217,11 @@ pwbox_encoded_get_data(pwbox_encoded_t *inp, size_t idx) return TRUNNEL_DYNARRAY_GET(&inp->data, idx); } +uint8_t +pwbox_encoded_getconst_data(const pwbox_encoded_t *inp, size_t idx) +{ + return pwbox_encoded_get_data((pwbox_encoded_t*)inp, idx); +} int pwbox_encoded_set_data(pwbox_encoded_t *inp, size_t idx, uint8_t elt) { @@ -218,6 +243,11 @@ pwbox_encoded_getarray_data(pwbox_encoded_t *inp) { return inp->data.elts_; } +const uint8_t * +pwbox_encoded_getconstarray_data(const pwbox_encoded_t *inp) +{ + return (const uint8_t *)pwbox_encoded_getarray_data((pwbox_encoded_t*)inp); +} int pwbox_encoded_setlen_data(pwbox_encoded_t *inp, size_t newlen) { @@ -226,7 +256,7 @@ pwbox_encoded_setlen_data(pwbox_encoded_t *inp, size_t newlen) &inp->data.n_, inp->data.elts_, newlen, sizeof(inp->data.elts_[0]), (trunnel_free_fn_t) NULL, &inp->trunnel_error_code_); - if (newptr == NULL) + if (newlen != 0 && newptr == NULL) goto trunnel_alloc_failed; inp->data.elts_ = newptr; return 0; @@ -241,12 +271,17 @@ pwbox_encoded_getlen_hmac(const pwbox_encoded_t *inp) } uint8_t -pwbox_encoded_get_hmac(const pwbox_encoded_t *inp, size_t idx) +pwbox_encoded_get_hmac(pwbox_encoded_t *inp, size_t idx) { trunnel_assert(idx < 32); return inp->hmac[idx]; } +uint8_t +pwbox_encoded_getconst_hmac(const pwbox_encoded_t *inp, size_t idx) +{ + return pwbox_encoded_get_hmac((pwbox_encoded_t*)inp, idx); +} int pwbox_encoded_set_hmac(pwbox_encoded_t *inp, size_t idx, uint8_t elt) { @@ -260,6 +295,11 @@ pwbox_encoded_getarray_hmac(pwbox_encoded_t *inp) { return inp->hmac; } +const uint8_t * +pwbox_encoded_getconstarray_hmac(const pwbox_encoded_t *inp) +{ + return (const uint8_t *)pwbox_encoded_getarray_hmac((pwbox_encoded_t*)inp); +} const char * pwbox_encoded_check(const pwbox_encoded_t *obj) { diff --git a/src/trunnel/pwbox.h b/src/trunnel/pwbox.h index e69e2c1a0e..9376a7cd1b 100644 --- a/src/trunnel/pwbox.h +++ b/src/trunnel/pwbox.h @@ -1,4 +1,4 @@ -/* pwbox.h -- generated by by Trunnel v1.4.4. +/* pwbox.h -- generated by by Trunnel v1.5. * https://gitweb.torproject.org/trunnel.git * You probably shouldn't edit this file. */ @@ -93,6 +93,10 @@ size_t pwbox_encoded_getlen_skey_header(const pwbox_encoded_t *inp); * skey_header of the pwbox_encoded_t in 'inp'. */ uint8_t pwbox_encoded_get_skey_header(pwbox_encoded_t *inp, size_t idx); +/** As pwbox_encoded_get_skey_header, but take and return a const + * pointer + */ +uint8_t pwbox_encoded_getconst_skey_header(const pwbox_encoded_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * skey_header of the pwbox_encoded_t in 'inp', so that it will hold * the value 'elt'. @@ -106,6 +110,10 @@ int pwbox_encoded_add_skey_header(pwbox_encoded_t *inp, uint8_t elt); * 'inp'. */ uint8_t * pwbox_encoded_getarray_skey_header(pwbox_encoded_t *inp); +/** As pwbox_encoded_get_skey_header, but take and return a const + * pointer + */ +const uint8_t * pwbox_encoded_getconstarray_skey_header(const pwbox_encoded_t *inp); /** Change the length of the variable-length array field skey_header * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on * success; return -1 and set the error code on 'inp' on failure. @@ -118,7 +126,10 @@ size_t pwbox_encoded_getlen_iv(const pwbox_encoded_t *inp); /** Return the element at position 'idx' of the fixed array field iv * of the pwbox_encoded_t in 'inp'. */ -uint8_t pwbox_encoded_get_iv(const pwbox_encoded_t *inp, size_t idx); +uint8_t pwbox_encoded_get_iv(pwbox_encoded_t *inp, size_t idx); +/** As pwbox_encoded_get_iv, but take and return a const pointer + */ +uint8_t pwbox_encoded_getconst_iv(const pwbox_encoded_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field iv * of the pwbox_encoded_t in 'inp', so that it will hold the value * 'elt'. @@ -127,6 +138,9 @@ int pwbox_encoded_set_iv(pwbox_encoded_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 16-element array field iv of 'inp'. */ uint8_t * pwbox_encoded_getarray_iv(pwbox_encoded_t *inp); +/** As pwbox_encoded_get_iv, but take and return a const pointer + */ +const uint8_t * pwbox_encoded_getconstarray_iv(const pwbox_encoded_t *inp); /** Return the length of the dynamic array holding the data field of * the pwbox_encoded_t in 'inp'. */ @@ -135,6 +149,9 @@ size_t pwbox_encoded_getlen_data(const pwbox_encoded_t *inp); * data of the pwbox_encoded_t in 'inp'. */ uint8_t pwbox_encoded_get_data(pwbox_encoded_t *inp, size_t idx); +/** As pwbox_encoded_get_data, but take and return a const pointer + */ +uint8_t pwbox_encoded_getconst_data(const pwbox_encoded_t *inp, size_t idx); /** Change the element at position 'idx' of the dynamic array field * data of the pwbox_encoded_t in 'inp', so that it will hold the * value 'elt'. @@ -147,6 +164,9 @@ int pwbox_encoded_add_data(pwbox_encoded_t *inp, uint8_t elt); /** Return a pointer to the variable-length array field data of 'inp'. */ uint8_t * pwbox_encoded_getarray_data(pwbox_encoded_t *inp); +/** As pwbox_encoded_get_data, but take and return a const pointer + */ +const uint8_t * pwbox_encoded_getconstarray_data(const pwbox_encoded_t *inp); /** Change the length of the variable-length array field data of 'inp' * to 'newlen'.Fill extra elements with 0. Return 0 on success; return * -1 and set the error code on 'inp' on failure. @@ -159,7 +179,10 @@ size_t pwbox_encoded_getlen_hmac(const pwbox_encoded_t *inp); /** Return the element at position 'idx' of the fixed array field hmac * of the pwbox_encoded_t in 'inp'. */ -uint8_t pwbox_encoded_get_hmac(const pwbox_encoded_t *inp, size_t idx); +uint8_t pwbox_encoded_get_hmac(pwbox_encoded_t *inp, size_t idx); +/** As pwbox_encoded_get_hmac, but take and return a const pointer + */ +uint8_t pwbox_encoded_getconst_hmac(const pwbox_encoded_t *inp, size_t idx); /** Change the element at position 'idx' of the fixed array field hmac * of the pwbox_encoded_t in 'inp', so that it will hold the value * 'elt'. @@ -168,6 +191,9 @@ int pwbox_encoded_set_hmac(pwbox_encoded_t *inp, size_t idx, uint8_t elt); /** Return a pointer to the 32-element array field hmac of 'inp'. */ uint8_t * pwbox_encoded_getarray_hmac(pwbox_encoded_t *inp); +/** As pwbox_encoded_get_hmac, but take and return a const pointer + */ +const uint8_t * pwbox_encoded_getconstarray_hmac(const pwbox_encoded_t *inp); #endif |