ssize_t trn_cell_introduce1_encoded_len(const trn_cell_introduce1_t *obj) { ssize_t result = 0; if (NULL != trn_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 trn_cell_extension extensions */ result += trn_cell_extension_encoded_len(obj->extensions); /* Length of u8 encrypted[] */ result += TRUNNEL_DYNARRAY_LEN(&obj->encrypted); return result; }
ssize_t pwbox_encoded_encoded_len(const pwbox_encoded_t *obj) { ssize_t result = 0; if (NULL != pwbox_encoded_check(obj)) return -1; /* Length of u32 fixedbytes0 IN [PWBOX0_CONST0] */ result += 4; /* Length of u32 fixedbytes1 IN [PWBOX0_CONST1] */ result += 4; /* Length of u8 header_len */ result += 1; /* Length of u8 skey_header[header_len] */ result += TRUNNEL_DYNARRAY_LEN(&obj->skey_header); /* Length of u8 iv[16] */ result += 16; /* Length of u8 data[] */ result += TRUNNEL_DYNARRAY_LEN(&obj->data); /* Length of u8 hmac[32] */ result += 32; return result; }
ssize_t ed25519_cert_extension_encoded_len(const ed25519_cert_extension_t *obj) { ssize_t result = 0; if (NULL != ed25519_cert_extension_check(obj)) return -1; /* Length of u16 ext_length */ result += 2; /* Length of u8 ext_type */ result += 1; /* Length of u8 ext_flags */ result += 1; switch (obj->ext_type) { case CERTEXT_SIGNED_WITH_KEY: /* Length of u8 un_signing_key[32] */ result += 32; break; default: /* Length of u8 un_unparsed[] */ result += TRUNNEL_DYNARRAY_LEN(&obj->un_unparsed); break; } return result; }
ssize_t trn_cell_rendezvous1_encode(uint8_t *output, const size_t avail, const trn_cell_rendezvous1_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 = trn_cell_rendezvous1_encoded_len(obj); #endif if (NULL != (msg = trn_cell_rendezvous1_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN trunnel_assert(encoded_len >= 0); #endif /* Encode u8 rendezvous_cookie[TRUNNEL_REND_COOKIE_LEN] */ trunnel_assert(written <= avail); if (avail - written < TRUNNEL_REND_COOKIE_LEN) goto truncated; memcpy(ptr, obj->rendezvous_cookie, TRUNNEL_REND_COOKIE_LEN); written += TRUNNEL_REND_COOKIE_LEN; ptr += TRUNNEL_REND_COOKIE_LEN; /* Encode u8 handshake_info[] */ { size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->handshake_info); trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; if (elt_len) memcpy(ptr, obj->handshake_info.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; }
ssize_t auth1_encoded_len(const auth1_t *obj, const auth_ctx_t *auth_ctx_ctx) { ssize_t result = 0; if (NULL != auth1_check(obj, auth_ctx_ctx)) return -1; /* Length of u8 type[8] */ result += 8; /* Length of u8 cid[32] */ result += 32; /* Length of u8 sid[32] */ result += 32; switch (auth_ctx_ctx->is_ed) { case 0: break; case 1: /* Length of u8 u1_cid_ed[32] */ result += 32; /* Length of u8 u1_sid_ed[32] */ result += 32; break; default: trunnel_assert(0); break; } /* Length of u8 slog[32] */ result += 32; /* Length of u8 clog[32] */ result += 32; /* Length of u8 scert[32] */ result += 32; /* Length of u8 tlssecrets[32] */ result += 32; /* Length of u8 rand[24] */ result += 24; /* Length of u8 sig[] */ result += TRUNNEL_DYNARRAY_LEN(&obj->sig); return result; }
const char * rsa_ed_crosscert_check(const rsa_ed_crosscert_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->sig) != obj->sig_len) return "Length mismatch for sig"; return NULL; }
const char * auth_challenge_cell_check(const auth_challenge_cell_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->methods) != obj->n_methods) return "Length mismatch for methods"; return NULL; }
const char * certs_cell_cert_check(const certs_cell_cert_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->body) != obj->cert_len) return "Length mismatch for body"; return NULL; }
/** Release all storage held inside 'obj', but do not free 'obj'. */ static void ed25519_cert_clear(ed25519_cert_t *obj) { (void) obj; { unsigned idx; for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->ext); ++idx) { ed25519_cert_extension_free(TRUNNEL_DYNARRAY_GET(&obj->ext, idx)); } } TRUNNEL_DYNARRAY_WIPE(&obj->ext); TRUNNEL_DYNARRAY_CLEAR(&obj->ext); }
/** Release all storage held inside 'obj', but do not free 'obj'. */ static void certs_cell_clear(certs_cell_t *obj) { (void) obj; { unsigned idx; for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->certs); ++idx) { certs_cell_cert_free(TRUNNEL_DYNARRAY_GET(&obj->certs, idx)); } } TRUNNEL_DYNARRAY_WIPE(&obj->certs); TRUNNEL_DYNARRAY_CLEAR(&obj->certs); }
const char * pwbox_encoded_check(const pwbox_encoded_t *obj) { if (obj == NULL) return "Object was NULL"; if (obj->trunnel_error_code_) return "A set function failed on this object"; if (! (obj->fixedbytes0 == PWBOX0_CONST0)) return "Integer out of bounds"; if (! (obj->fixedbytes1 == PWBOX0_CONST1)) return "Integer out of bounds"; if (TRUNNEL_DYNARRAY_LEN(&obj->skey_header) != obj->header_len) return "Length mismatch for skey_header"; return NULL; }
ssize_t trn_cell_rendezvous1_encoded_len(const trn_cell_rendezvous1_t *obj) { ssize_t result = 0; if (NULL != trn_cell_rendezvous1_check(obj)) return -1; /* Length of u8 rendezvous_cookie[TRUNNEL_REND_COOKIE_LEN] */ result += TRUNNEL_REND_COOKIE_LEN; /* Length of u8 handshake_info[] */ result += TRUNNEL_DYNARRAY_LEN(&obj->handshake_info); return result; }
const char * trn_cell_introduce1_check(const trn_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 = trn_cell_extension_check(obj->extensions))) return msg; } return NULL; }
ssize_t auth_challenge_cell_encoded_len(const auth_challenge_cell_t *obj) { ssize_t result = 0; if (NULL != auth_challenge_cell_check(obj)) return -1; /* Length of u8 challenge[32] */ result += 32; /* Length of u16 n_methods */ result += 2; /* Length of u16 methods[n_methods] */ result += 2 * TRUNNEL_DYNARRAY_LEN(&obj->methods); return result; }
ssize_t certs_cell_cert_encoded_len(const certs_cell_cert_t *obj) { ssize_t result = 0; if (NULL != certs_cell_cert_check(obj)) return -1; /* Length of u8 cert_type */ result += 1; /* Length of u16 cert_len */ result += 2; /* Length of u8 body[cert_len] */ result += TRUNNEL_DYNARRAY_LEN(&obj->body); return result; }
/** Release all storage held inside 'obj', but do not free 'obj'. */ static void trn_cell_introduce_encrypted_clear(trn_cell_introduce_encrypted_t *obj) { (void) obj; trn_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); }
ssize_t rsa_ed_crosscert_encoded_len(const rsa_ed_crosscert_t *obj) { ssize_t result = 0; if (NULL != rsa_ed_crosscert_check(obj)) return -1; /* Length of u8 ed_key[32] */ result += 32; /* Length of u32 expiration */ result += 4; /* Length of u8 sig_len */ result += 1; /* Length of u8 sig[sig_len] */ result += TRUNNEL_DYNARRAY_LEN(&obj->sig); return result; }
size_t trn_cell_introduce_encrypted_getlen_nspecs(const trn_cell_introduce_encrypted_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->nspecs); }
size_t trn_cell_introduce_encrypted_getlen_onion_key(const trn_cell_introduce_encrypted_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->onion_key); }
ssize_t trn_cell_introduce1_encode(uint8_t *output, const size_t avail, const trn_cell_introduce1_t *obj) { ssize_t result = 0; size_t written = 0; uint8_t *ptr = output; const char *msg; #ifdef TRUNNEL_CHECK_ENCODED_LEN const ssize_t encoded_len = trn_cell_introduce1_encoded_len(obj); #endif if (NULL != (msg = trn_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 trn_cell_extension extensions */ trunnel_assert(written <= avail); result = trn_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; }
ssize_t auth1_encode(uint8_t *output, const size_t avail, const auth1_t *obj, const auth_ctx_t *auth_ctx_ctx) { 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 = auth1_encoded_len(obj, auth_ctx_ctx); #endif if (NULL != (msg = auth1_check(obj, auth_ctx_ctx))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN trunnel_assert(encoded_len >= 0); #endif /* Encode u8 type[8] */ trunnel_assert(written <= avail); if (avail - written < 8) goto truncated; memcpy(ptr, obj->type, 8); written += 8; ptr += 8; /* Encode u8 cid[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->cid, 32); written += 32; ptr += 32; /* Encode u8 sid[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->sid, 32); written += 32; ptr += 32; /* Encode union u1[auth_ctx.is_ed] */ trunnel_assert(written <= avail); switch (auth_ctx_ctx->is_ed) { case 0: break; case 1: /* Encode u8 u1_cid_ed[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->u1_cid_ed, 32); written += 32; ptr += 32; /* Encode u8 u1_sid_ed[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->u1_sid_ed, 32); written += 32; ptr += 32; break; default: trunnel_assert(0); break; } /* Encode u8 slog[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->slog, 32); written += 32; ptr += 32; /* Encode u8 clog[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->clog, 32); written += 32; ptr += 32; /* Encode u8 scert[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->scert, 32); written += 32; ptr += 32; /* Encode u8 tlssecrets[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->tlssecrets, 32); written += 32; ptr += 32; /* Encode u8 rand[24] */ trunnel_assert(written <= avail); if (avail - written < 24) goto truncated; memcpy(ptr, obj->rand, 24); written += 24; ptr += 24; /* Encode u8 sig[] */ { size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->sig); trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; 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; }
size_t certs_cell_getlen_certs(const certs_cell_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->certs); }
size_t trn_cell_introduce1_getlen_encrypted(const trn_cell_introduce1_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->encrypted); }
size_t trn_cell_introduce1_getlen_auth_key(const trn_cell_introduce1_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->auth_key); }
size_t auth_challenge_cell_getlen_methods(const auth_challenge_cell_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->methods); }
ssize_t rsa_ed_crosscert_encode(uint8_t *output, const size_t avail, const rsa_ed_crosscert_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 = rsa_ed_crosscert_encoded_len(obj); #endif if (NULL != (msg = rsa_ed_crosscert_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN trunnel_assert(encoded_len >= 0); #endif /* Encode u8 ed_key[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->ed_key, 32); written += 32; ptr += 32; /* Encode u32 expiration */ trunnel_assert(written <= avail); if (avail - written < 4) goto truncated; trunnel_set_uint32(ptr, trunnel_htonl(obj->expiration)); written += 4; ptr += 4; /* Encode u8 sig_len */ trunnel_assert(written <= avail); if (avail - written < 1) goto truncated; trunnel_set_uint8(ptr, (obj->sig_len)); written += 1; ptr += 1; /* 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; 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; }
ssize_t auth_challenge_cell_encode(uint8_t *output, const size_t avail, const auth_challenge_cell_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 = auth_challenge_cell_encoded_len(obj); #endif if (NULL != (msg = auth_challenge_cell_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN trunnel_assert(encoded_len >= 0); #endif /* Encode u8 challenge[32] */ trunnel_assert(written <= avail); if (avail - written < 32) goto truncated; memcpy(ptr, obj->challenge, 32); written += 32; ptr += 32; /* Encode u16 n_methods */ trunnel_assert(written <= avail); if (avail - written < 2) goto truncated; trunnel_set_uint16(ptr, trunnel_htons(obj->n_methods)); written += 2; ptr += 2; /* Encode u16 methods[n_methods] */ { unsigned idx; for (idx = 0; idx < TRUNNEL_DYNARRAY_LEN(&obj->methods); ++idx) { trunnel_assert(written <= avail); if (avail - written < 2) goto truncated; trunnel_set_uint16(ptr, trunnel_htons(TRUNNEL_DYNARRAY_GET(&obj->methods, idx))); written += 2; ptr += 2; } } 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; }
size_t rsa_ed_crosscert_getlen_sig(const rsa_ed_crosscert_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->sig); }
ssize_t certs_cell_cert_encode(uint8_t *output, const size_t avail, const certs_cell_cert_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 = certs_cell_cert_encoded_len(obj); #endif if (NULL != (msg = certs_cell_cert_check(obj))) goto check_failed; #ifdef TRUNNEL_CHECK_ENCODED_LEN trunnel_assert(encoded_len >= 0); #endif /* Encode u8 cert_type */ trunnel_assert(written <= avail); if (avail - written < 1) goto truncated; trunnel_set_uint8(ptr, (obj->cert_type)); written += 1; ptr += 1; /* Encode u16 cert_len */ trunnel_assert(written <= avail); if (avail - written < 2) goto truncated; trunnel_set_uint16(ptr, trunnel_htons(obj->cert_len)); written += 2; ptr += 2; /* Encode u8 body[cert_len] */ { size_t elt_len = TRUNNEL_DYNARRAY_LEN(&obj->body); trunnel_assert(obj->cert_len == elt_len); trunnel_assert(written <= avail); if (avail - written < elt_len) goto truncated; memcpy(ptr, obj->body.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; }
size_t certs_cell_cert_getlen_body(const certs_cell_cert_t *inp) { return TRUNNEL_DYNARRAY_LEN(&inp->body); }