link_handshake.h 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. /* link_handshake.h -- generated by Trunnel v1.5.2.
  2. * https://gitweb.torproject.org/trunnel.git
  3. * You probably shouldn't edit this file.
  4. */
  5. #ifndef TRUNNEL_LINK_HANDSHAKE_H
  6. #define TRUNNEL_LINK_HANDSHAKE_H
  7. #include <stdint.h>
  8. #include "trunnel.h"
  9. #define CERTTYPE_RSA1024_ID_LINK 1
  10. #define CERTTYPE_RSA1024_ID_ID 2
  11. #define CERTTYPE_RSA1024_ID_AUTH 3
  12. #define CERTTYPE_ED_ID_SIGN 4
  13. #define CERTTYPE_ED_SIGN_LINK 5
  14. #define CERTTYPE_ED_SIGN_AUTH 6
  15. #define CERTTYPE_RSA1024_ID_EDID 7
  16. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_AUTH_CHALLENGE_CELL)
  17. struct auth_challenge_cell_st {
  18. uint8_t challenge[32];
  19. uint16_t n_methods;
  20. TRUNNEL_DYNARRAY_HEAD(, uint16_t) methods;
  21. uint8_t trunnel_error_code_;
  22. };
  23. #endif
  24. typedef struct auth_challenge_cell_st auth_challenge_cell_t;
  25. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_AUTH_CTX)
  26. struct auth_ctx_st {
  27. uint8_t is_ed;
  28. uint8_t trunnel_error_code_;
  29. };
  30. #endif
  31. typedef struct auth_ctx_st auth_ctx_t;
  32. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CERTS_CELL_CERT)
  33. struct certs_cell_cert_st {
  34. uint8_t cert_type;
  35. uint16_t cert_len;
  36. TRUNNEL_DYNARRAY_HEAD(, uint8_t) body;
  37. uint8_t trunnel_error_code_;
  38. };
  39. #endif
  40. typedef struct certs_cell_cert_st certs_cell_cert_t;
  41. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_RSA_ED_CROSSCERT)
  42. struct rsa_ed_crosscert_st {
  43. uint8_t ed_key[32];
  44. uint32_t expiration;
  45. const uint8_t *end_of_signed;
  46. uint8_t sig_len;
  47. TRUNNEL_DYNARRAY_HEAD(, uint8_t) sig;
  48. uint8_t trunnel_error_code_;
  49. };
  50. #endif
  51. typedef struct rsa_ed_crosscert_st rsa_ed_crosscert_t;
  52. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_AUTH1)
  53. struct auth1_st {
  54. uint8_t type[8];
  55. uint8_t cid[32];
  56. uint8_t sid[32];
  57. uint8_t u1_cid_ed[32];
  58. uint8_t u1_sid_ed[32];
  59. uint8_t slog[32];
  60. uint8_t clog[32];
  61. uint8_t scert[32];
  62. uint8_t tlssecrets[32];
  63. const uint8_t *end_of_fixed_part;
  64. uint8_t rand[24];
  65. const uint8_t *end_of_signed;
  66. TRUNNEL_DYNARRAY_HEAD(, uint8_t) sig;
  67. uint8_t trunnel_error_code_;
  68. };
  69. #endif
  70. typedef struct auth1_st auth1_t;
  71. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_CERTS_CELL)
  72. struct certs_cell_st {
  73. uint8_t n_certs;
  74. TRUNNEL_DYNARRAY_HEAD(, struct certs_cell_cert_st *) certs;
  75. uint8_t trunnel_error_code_;
  76. };
  77. #endif
  78. typedef struct certs_cell_st certs_cell_t;
  79. /** Return a newly allocated auth_challenge_cell with all elements set
  80. * to zero.
  81. */
  82. auth_challenge_cell_t *auth_challenge_cell_new(void);
  83. /** Release all storage held by the auth_challenge_cell in 'victim'.
  84. * (Do nothing if 'victim' is NULL.)
  85. */
  86. void auth_challenge_cell_free(auth_challenge_cell_t *victim);
  87. /** Try to parse a auth_challenge_cell from the buffer in 'input',
  88. * using up to 'len_in' bytes from the input buffer. On success,
  89. * return the number of bytes consumed and set *output to the newly
  90. * allocated auth_challenge_cell_t. On failure, return -2 if the input
  91. * appears truncated, and -1 if the input is otherwise invalid.
  92. */
  93. ssize_t auth_challenge_cell_parse(auth_challenge_cell_t **output, const uint8_t *input, const size_t len_in);
  94. /** Return the number of bytes we expect to need to encode the
  95. * auth_challenge_cell in 'obj'. On failure, return a negative value.
  96. * Note that this value may be an overestimate, and can even be an
  97. * underestimate for certain unencodeable objects.
  98. */
  99. ssize_t auth_challenge_cell_encoded_len(const auth_challenge_cell_t *obj);
  100. /** Try to encode the auth_challenge_cell from 'input' into the buffer
  101. * at 'output', using up to 'avail' bytes of the output buffer. On
  102. * success, return the number of bytes used. On failure, return -2 if
  103. * the buffer was not long enough, and -1 if the input was invalid.
  104. */
  105. ssize_t auth_challenge_cell_encode(uint8_t *output, size_t avail, const auth_challenge_cell_t *input);
  106. /** Check whether the internal state of the auth_challenge_cell in
  107. * 'obj' is consistent. Return NULL if it is, and a short message if
  108. * it is not.
  109. */
  110. const char *auth_challenge_cell_check(const auth_challenge_cell_t *obj);
  111. /** Clear any errors that were set on the object 'obj' by its setter
  112. * functions. Return true iff errors were cleared.
  113. */
  114. int auth_challenge_cell_clear_errors(auth_challenge_cell_t *obj);
  115. /** Return the (constant) length of the array holding the challenge
  116. * field of the auth_challenge_cell_t in 'inp'.
  117. */
  118. size_t auth_challenge_cell_getlen_challenge(const auth_challenge_cell_t *inp);
  119. /** Return the element at position 'idx' of the fixed array field
  120. * challenge of the auth_challenge_cell_t in 'inp'.
  121. */
  122. uint8_t auth_challenge_cell_get_challenge(auth_challenge_cell_t *inp, size_t idx);
  123. /** As auth_challenge_cell_get_challenge, but take and return a const
  124. * pointer
  125. */
  126. uint8_t auth_challenge_cell_getconst_challenge(const auth_challenge_cell_t *inp, size_t idx);
  127. /** Change the element at position 'idx' of the fixed array field
  128. * challenge of the auth_challenge_cell_t in 'inp', so that it will
  129. * hold the value 'elt'.
  130. */
  131. int auth_challenge_cell_set_challenge(auth_challenge_cell_t *inp, size_t idx, uint8_t elt);
  132. /** Return a pointer to the 32-element array field challenge of 'inp'.
  133. */
  134. uint8_t * auth_challenge_cell_getarray_challenge(auth_challenge_cell_t *inp);
  135. /** As auth_challenge_cell_get_challenge, but take and return a const
  136. * pointer
  137. */
  138. const uint8_t * auth_challenge_cell_getconstarray_challenge(const auth_challenge_cell_t *inp);
  139. /** Return the value of the n_methods field of the
  140. * auth_challenge_cell_t in 'inp'
  141. */
  142. uint16_t auth_challenge_cell_get_n_methods(const auth_challenge_cell_t *inp);
  143. /** Set the value of the n_methods field of the auth_challenge_cell_t
  144. * in 'inp' to 'val'. Return 0 on success; return -1 and set the error
  145. * code on 'inp' on failure.
  146. */
  147. int auth_challenge_cell_set_n_methods(auth_challenge_cell_t *inp, uint16_t val);
  148. /** Return the length of the dynamic array holding the methods field
  149. * of the auth_challenge_cell_t in 'inp'.
  150. */
  151. size_t auth_challenge_cell_getlen_methods(const auth_challenge_cell_t *inp);
  152. /** Return the element at position 'idx' of the dynamic array field
  153. * methods of the auth_challenge_cell_t in 'inp'.
  154. */
  155. uint16_t auth_challenge_cell_get_methods(auth_challenge_cell_t *inp, size_t idx);
  156. /** As auth_challenge_cell_get_methods, but take and return a const
  157. * pointer
  158. */
  159. uint16_t auth_challenge_cell_getconst_methods(const auth_challenge_cell_t *inp, size_t idx);
  160. /** Change the element at position 'idx' of the dynamic array field
  161. * methods of the auth_challenge_cell_t in 'inp', so that it will hold
  162. * the value 'elt'.
  163. */
  164. int auth_challenge_cell_set_methods(auth_challenge_cell_t *inp, size_t idx, uint16_t elt);
  165. /** Append a new element 'elt' to the dynamic array field methods of
  166. * the auth_challenge_cell_t in 'inp'.
  167. */
  168. int auth_challenge_cell_add_methods(auth_challenge_cell_t *inp, uint16_t elt);
  169. /** Return a pointer to the variable-length array field methods of
  170. * 'inp'.
  171. */
  172. uint16_t * auth_challenge_cell_getarray_methods(auth_challenge_cell_t *inp);
  173. /** As auth_challenge_cell_get_methods, but take and return a const
  174. * pointer
  175. */
  176. const uint16_t * auth_challenge_cell_getconstarray_methods(const auth_challenge_cell_t *inp);
  177. /** Change the length of the variable-length array field methods of
  178. * 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on success;
  179. * return -1 and set the error code on 'inp' on failure.
  180. */
  181. int auth_challenge_cell_setlen_methods(auth_challenge_cell_t *inp, size_t newlen);
  182. /** Return a newly allocated auth_ctx with all elements set to zero.
  183. */
  184. auth_ctx_t *auth_ctx_new(void);
  185. /** Release all storage held by the auth_ctx in 'victim'. (Do nothing
  186. * if 'victim' is NULL.)
  187. */
  188. void auth_ctx_free(auth_ctx_t *victim);
  189. /** Return the value of the is_ed field of the auth_ctx_t in 'inp'
  190. */
  191. uint8_t auth_ctx_get_is_ed(const auth_ctx_t *inp);
  192. /** Set the value of the is_ed field of the auth_ctx_t in 'inp' to
  193. * 'val'. Return 0 on success; return -1 and set the error code on
  194. * 'inp' on failure.
  195. */
  196. int auth_ctx_set_is_ed(auth_ctx_t *inp, uint8_t val);
  197. /** Return a newly allocated certs_cell_cert with all elements set to
  198. * zero.
  199. */
  200. certs_cell_cert_t *certs_cell_cert_new(void);
  201. /** Release all storage held by the certs_cell_cert in 'victim'. (Do
  202. * nothing if 'victim' is NULL.)
  203. */
  204. void certs_cell_cert_free(certs_cell_cert_t *victim);
  205. /** Try to parse a certs_cell_cert from the buffer in 'input', using
  206. * up to 'len_in' bytes from the input buffer. On success, return the
  207. * number of bytes consumed and set *output to the newly allocated
  208. * certs_cell_cert_t. On failure, return -2 if the input appears
  209. * truncated, and -1 if the input is otherwise invalid.
  210. */
  211. ssize_t certs_cell_cert_parse(certs_cell_cert_t **output, const uint8_t *input, const size_t len_in);
  212. /** Return the number of bytes we expect to need to encode the
  213. * certs_cell_cert in 'obj'. On failure, return a negative value. Note
  214. * that this value may be an overestimate, and can even be an
  215. * underestimate for certain unencodeable objects.
  216. */
  217. ssize_t certs_cell_cert_encoded_len(const certs_cell_cert_t *obj);
  218. /** Try to encode the certs_cell_cert from 'input' into the buffer at
  219. * 'output', using up to 'avail' bytes of the output buffer. On
  220. * success, return the number of bytes used. On failure, return -2 if
  221. * the buffer was not long enough, and -1 if the input was invalid.
  222. */
  223. ssize_t certs_cell_cert_encode(uint8_t *output, size_t avail, const certs_cell_cert_t *input);
  224. /** Check whether the internal state of the certs_cell_cert in 'obj'
  225. * is consistent. Return NULL if it is, and a short message if it is
  226. * not.
  227. */
  228. const char *certs_cell_cert_check(const certs_cell_cert_t *obj);
  229. /** Clear any errors that were set on the object 'obj' by its setter
  230. * functions. Return true iff errors were cleared.
  231. */
  232. int certs_cell_cert_clear_errors(certs_cell_cert_t *obj);
  233. /** Return the value of the cert_type field of the certs_cell_cert_t
  234. * in 'inp'
  235. */
  236. uint8_t certs_cell_cert_get_cert_type(const certs_cell_cert_t *inp);
  237. /** Set the value of the cert_type field of the certs_cell_cert_t in
  238. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  239. * code on 'inp' on failure.
  240. */
  241. int certs_cell_cert_set_cert_type(certs_cell_cert_t *inp, uint8_t val);
  242. /** Return the value of the cert_len field of the certs_cell_cert_t in
  243. * 'inp'
  244. */
  245. uint16_t certs_cell_cert_get_cert_len(const certs_cell_cert_t *inp);
  246. /** Set the value of the cert_len field of the certs_cell_cert_t in
  247. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  248. * code on 'inp' on failure.
  249. */
  250. int certs_cell_cert_set_cert_len(certs_cell_cert_t *inp, uint16_t val);
  251. /** Return the length of the dynamic array holding the body field of
  252. * the certs_cell_cert_t in 'inp'.
  253. */
  254. size_t certs_cell_cert_getlen_body(const certs_cell_cert_t *inp);
  255. /** Return the element at position 'idx' of the dynamic array field
  256. * body of the certs_cell_cert_t in 'inp'.
  257. */
  258. uint8_t certs_cell_cert_get_body(certs_cell_cert_t *inp, size_t idx);
  259. /** As certs_cell_cert_get_body, but take and return a const pointer
  260. */
  261. uint8_t certs_cell_cert_getconst_body(const certs_cell_cert_t *inp, size_t idx);
  262. /** Change the element at position 'idx' of the dynamic array field
  263. * body of the certs_cell_cert_t in 'inp', so that it will hold the
  264. * value 'elt'.
  265. */
  266. int certs_cell_cert_set_body(certs_cell_cert_t *inp, size_t idx, uint8_t elt);
  267. /** Append a new element 'elt' to the dynamic array field body of the
  268. * certs_cell_cert_t in 'inp'.
  269. */
  270. int certs_cell_cert_add_body(certs_cell_cert_t *inp, uint8_t elt);
  271. /** Return a pointer to the variable-length array field body of 'inp'.
  272. */
  273. uint8_t * certs_cell_cert_getarray_body(certs_cell_cert_t *inp);
  274. /** As certs_cell_cert_get_body, but take and return a const pointer
  275. */
  276. const uint8_t * certs_cell_cert_getconstarray_body(const certs_cell_cert_t *inp);
  277. /** Change the length of the variable-length array field body of 'inp'
  278. * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
  279. * -1 and set the error code on 'inp' on failure.
  280. */
  281. int certs_cell_cert_setlen_body(certs_cell_cert_t *inp, size_t newlen);
  282. /** Return a newly allocated rsa_ed_crosscert with all elements set to
  283. * zero.
  284. */
  285. rsa_ed_crosscert_t *rsa_ed_crosscert_new(void);
  286. /** Release all storage held by the rsa_ed_crosscert in 'victim'. (Do
  287. * nothing if 'victim' is NULL.)
  288. */
  289. void rsa_ed_crosscert_free(rsa_ed_crosscert_t *victim);
  290. /** Try to parse a rsa_ed_crosscert from the buffer in 'input', using
  291. * up to 'len_in' bytes from the input buffer. On success, return the
  292. * number of bytes consumed and set *output to the newly allocated
  293. * rsa_ed_crosscert_t. On failure, return -2 if the input appears
  294. * truncated, and -1 if the input is otherwise invalid.
  295. */
  296. ssize_t rsa_ed_crosscert_parse(rsa_ed_crosscert_t **output, const uint8_t *input, const size_t len_in);
  297. /** Return the number of bytes we expect to need to encode the
  298. * rsa_ed_crosscert in 'obj'. On failure, return a negative value.
  299. * Note that this value may be an overestimate, and can even be an
  300. * underestimate for certain unencodeable objects.
  301. */
  302. ssize_t rsa_ed_crosscert_encoded_len(const rsa_ed_crosscert_t *obj);
  303. /** Try to encode the rsa_ed_crosscert from 'input' into the buffer at
  304. * 'output', using up to 'avail' bytes of the output buffer. On
  305. * success, return the number of bytes used. On failure, return -2 if
  306. * the buffer was not long enough, and -1 if the input was invalid.
  307. */
  308. ssize_t rsa_ed_crosscert_encode(uint8_t *output, size_t avail, const rsa_ed_crosscert_t *input);
  309. /** Check whether the internal state of the rsa_ed_crosscert in 'obj'
  310. * is consistent. Return NULL if it is, and a short message if it is
  311. * not.
  312. */
  313. const char *rsa_ed_crosscert_check(const rsa_ed_crosscert_t *obj);
  314. /** Clear any errors that were set on the object 'obj' by its setter
  315. * functions. Return true iff errors were cleared.
  316. */
  317. int rsa_ed_crosscert_clear_errors(rsa_ed_crosscert_t *obj);
  318. /** Return the (constant) length of the array holding the ed_key field
  319. * of the rsa_ed_crosscert_t in 'inp'.
  320. */
  321. size_t rsa_ed_crosscert_getlen_ed_key(const rsa_ed_crosscert_t *inp);
  322. /** Return the element at position 'idx' of the fixed array field
  323. * ed_key of the rsa_ed_crosscert_t in 'inp'.
  324. */
  325. uint8_t rsa_ed_crosscert_get_ed_key(rsa_ed_crosscert_t *inp, size_t idx);
  326. /** As rsa_ed_crosscert_get_ed_key, but take and return a const
  327. * pointer
  328. */
  329. uint8_t rsa_ed_crosscert_getconst_ed_key(const rsa_ed_crosscert_t *inp, size_t idx);
  330. /** Change the element at position 'idx' of the fixed array field
  331. * ed_key of the rsa_ed_crosscert_t in 'inp', so that it will hold the
  332. * value 'elt'.
  333. */
  334. int rsa_ed_crosscert_set_ed_key(rsa_ed_crosscert_t *inp, size_t idx, uint8_t elt);
  335. /** Return a pointer to the 32-element array field ed_key of 'inp'.
  336. */
  337. uint8_t * rsa_ed_crosscert_getarray_ed_key(rsa_ed_crosscert_t *inp);
  338. /** As rsa_ed_crosscert_get_ed_key, but take and return a const
  339. * pointer
  340. */
  341. const uint8_t * rsa_ed_crosscert_getconstarray_ed_key(const rsa_ed_crosscert_t *inp);
  342. /** Return the value of the expiration field of the rsa_ed_crosscert_t
  343. * in 'inp'
  344. */
  345. uint32_t rsa_ed_crosscert_get_expiration(const rsa_ed_crosscert_t *inp);
  346. /** Set the value of the expiration field of the rsa_ed_crosscert_t in
  347. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  348. * code on 'inp' on failure.
  349. */
  350. int rsa_ed_crosscert_set_expiration(rsa_ed_crosscert_t *inp, uint32_t val);
  351. /** Return the position for end_of_signed when we parsed this object
  352. */
  353. const uint8_t * rsa_ed_crosscert_get_end_of_signed(const rsa_ed_crosscert_t *inp);
  354. /** Return the value of the sig_len field of the rsa_ed_crosscert_t in
  355. * 'inp'
  356. */
  357. uint8_t rsa_ed_crosscert_get_sig_len(const rsa_ed_crosscert_t *inp);
  358. /** Set the value of the sig_len field of the rsa_ed_crosscert_t in
  359. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  360. * code on 'inp' on failure.
  361. */
  362. int rsa_ed_crosscert_set_sig_len(rsa_ed_crosscert_t *inp, uint8_t val);
  363. /** Return the length of the dynamic array holding the sig field of
  364. * the rsa_ed_crosscert_t in 'inp'.
  365. */
  366. size_t rsa_ed_crosscert_getlen_sig(const rsa_ed_crosscert_t *inp);
  367. /** Return the element at position 'idx' of the dynamic array field
  368. * sig of the rsa_ed_crosscert_t in 'inp'.
  369. */
  370. uint8_t rsa_ed_crosscert_get_sig(rsa_ed_crosscert_t *inp, size_t idx);
  371. /** As rsa_ed_crosscert_get_sig, but take and return a const pointer
  372. */
  373. uint8_t rsa_ed_crosscert_getconst_sig(const rsa_ed_crosscert_t *inp, size_t idx);
  374. /** Change the element at position 'idx' of the dynamic array field
  375. * sig of the rsa_ed_crosscert_t in 'inp', so that it will hold the
  376. * value 'elt'.
  377. */
  378. int rsa_ed_crosscert_set_sig(rsa_ed_crosscert_t *inp, size_t idx, uint8_t elt);
  379. /** Append a new element 'elt' to the dynamic array field sig of the
  380. * rsa_ed_crosscert_t in 'inp'.
  381. */
  382. int rsa_ed_crosscert_add_sig(rsa_ed_crosscert_t *inp, uint8_t elt);
  383. /** Return a pointer to the variable-length array field sig of 'inp'.
  384. */
  385. uint8_t * rsa_ed_crosscert_getarray_sig(rsa_ed_crosscert_t *inp);
  386. /** As rsa_ed_crosscert_get_sig, but take and return a const pointer
  387. */
  388. const uint8_t * rsa_ed_crosscert_getconstarray_sig(const rsa_ed_crosscert_t *inp);
  389. /** Change the length of the variable-length array field sig of 'inp'
  390. * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
  391. * -1 and set the error code on 'inp' on failure.
  392. */
  393. int rsa_ed_crosscert_setlen_sig(rsa_ed_crosscert_t *inp, size_t newlen);
  394. /** Return a newly allocated auth1 with all elements set to zero.
  395. */
  396. auth1_t *auth1_new(void);
  397. /** Release all storage held by the auth1 in 'victim'. (Do nothing if
  398. * 'victim' is NULL.)
  399. */
  400. void auth1_free(auth1_t *victim);
  401. /** Try to parse a auth1 from the buffer in 'input', using up to
  402. * 'len_in' bytes from the input buffer. On success, return the number
  403. * of bytes consumed and set *output to the newly allocated auth1_t.
  404. * On failure, return -2 if the input appears truncated, and -1 if the
  405. * input is otherwise invalid.
  406. */
  407. ssize_t auth1_parse(auth1_t **output, const uint8_t *input, const size_t len_in, const auth_ctx_t *auth_ctx_ctx);
  408. /** Return the number of bytes we expect to need to encode the auth1
  409. * in 'obj'. On failure, return a negative value. Note that this value
  410. * may be an overestimate, and can even be an underestimate for
  411. * certain unencodeable objects.
  412. */
  413. ssize_t auth1_encoded_len(const auth1_t *obj, const auth_ctx_t *auth_ctx_ctx);
  414. /** Try to encode the auth1 from 'input' into the buffer at 'output',
  415. * using up to 'avail' bytes of the output buffer. On success, return
  416. * the number of bytes used. On failure, return -2 if the buffer was
  417. * not long enough, and -1 if the input was invalid.
  418. */
  419. ssize_t auth1_encode(uint8_t *output, size_t avail, const auth1_t *input, const auth_ctx_t *auth_ctx_ctx);
  420. /** Check whether the internal state of the auth1 in 'obj' is
  421. * consistent. Return NULL if it is, and a short message if it is not.
  422. */
  423. const char *auth1_check(const auth1_t *obj, const auth_ctx_t *auth_ctx_ctx);
  424. /** Clear any errors that were set on the object 'obj' by its setter
  425. * functions. Return true iff errors were cleared.
  426. */
  427. int auth1_clear_errors(auth1_t *obj);
  428. /** Return the (constant) length of the array holding the type field
  429. * of the auth1_t in 'inp'.
  430. */
  431. size_t auth1_getlen_type(const auth1_t *inp);
  432. /** Return the element at position 'idx' of the fixed array field type
  433. * of the auth1_t in 'inp'.
  434. */
  435. uint8_t auth1_get_type(auth1_t *inp, size_t idx);
  436. /** As auth1_get_type, but take and return a const pointer
  437. */
  438. uint8_t auth1_getconst_type(const auth1_t *inp, size_t idx);
  439. /** Change the element at position 'idx' of the fixed array field type
  440. * of the auth1_t in 'inp', so that it will hold the value 'elt'.
  441. */
  442. int auth1_set_type(auth1_t *inp, size_t idx, uint8_t elt);
  443. /** Return a pointer to the 8-element array field type of 'inp'.
  444. */
  445. uint8_t * auth1_getarray_type(auth1_t *inp);
  446. /** As auth1_get_type, but take and return a const pointer
  447. */
  448. const uint8_t * auth1_getconstarray_type(const auth1_t *inp);
  449. /** Return the (constant) length of the array holding the cid field of
  450. * the auth1_t in 'inp'.
  451. */
  452. size_t auth1_getlen_cid(const auth1_t *inp);
  453. /** Return the element at position 'idx' of the fixed array field cid
  454. * of the auth1_t in 'inp'.
  455. */
  456. uint8_t auth1_get_cid(auth1_t *inp, size_t idx);
  457. /** As auth1_get_cid, but take and return a const pointer
  458. */
  459. uint8_t auth1_getconst_cid(const auth1_t *inp, size_t idx);
  460. /** Change the element at position 'idx' of the fixed array field cid
  461. * of the auth1_t in 'inp', so that it will hold the value 'elt'.
  462. */
  463. int auth1_set_cid(auth1_t *inp, size_t idx, uint8_t elt);
  464. /** Return a pointer to the 32-element array field cid of 'inp'.
  465. */
  466. uint8_t * auth1_getarray_cid(auth1_t *inp);
  467. /** As auth1_get_cid, but take and return a const pointer
  468. */
  469. const uint8_t * auth1_getconstarray_cid(const auth1_t *inp);
  470. /** Return the (constant) length of the array holding the sid field of
  471. * the auth1_t in 'inp'.
  472. */
  473. size_t auth1_getlen_sid(const auth1_t *inp);
  474. /** Return the element at position 'idx' of the fixed array field sid
  475. * of the auth1_t in 'inp'.
  476. */
  477. uint8_t auth1_get_sid(auth1_t *inp, size_t idx);
  478. /** As auth1_get_sid, but take and return a const pointer
  479. */
  480. uint8_t auth1_getconst_sid(const auth1_t *inp, size_t idx);
  481. /** Change the element at position 'idx' of the fixed array field sid
  482. * of the auth1_t in 'inp', so that it will hold the value 'elt'.
  483. */
  484. int auth1_set_sid(auth1_t *inp, size_t idx, uint8_t elt);
  485. /** Return a pointer to the 32-element array field sid of 'inp'.
  486. */
  487. uint8_t * auth1_getarray_sid(auth1_t *inp);
  488. /** As auth1_get_sid, but take and return a const pointer
  489. */
  490. const uint8_t * auth1_getconstarray_sid(const auth1_t *inp);
  491. /** Return the (constant) length of the array holding the u1_cid_ed
  492. * field of the auth1_t in 'inp'.
  493. */
  494. size_t auth1_getlen_u1_cid_ed(const auth1_t *inp);
  495. /** Return the element at position 'idx' of the fixed array field
  496. * u1_cid_ed of the auth1_t in 'inp'.
  497. */
  498. uint8_t auth1_get_u1_cid_ed(auth1_t *inp, size_t idx);
  499. /** As auth1_get_u1_cid_ed, but take and return a const pointer
  500. */
  501. uint8_t auth1_getconst_u1_cid_ed(const auth1_t *inp, size_t idx);
  502. /** Change the element at position 'idx' of the fixed array field
  503. * u1_cid_ed of the auth1_t in 'inp', so that it will hold the value
  504. * 'elt'.
  505. */
  506. int auth1_set_u1_cid_ed(auth1_t *inp, size_t idx, uint8_t elt);
  507. /** Return a pointer to the 32-element array field u1_cid_ed of 'inp'.
  508. */
  509. uint8_t * auth1_getarray_u1_cid_ed(auth1_t *inp);
  510. /** As auth1_get_u1_cid_ed, but take and return a const pointer
  511. */
  512. const uint8_t * auth1_getconstarray_u1_cid_ed(const auth1_t *inp);
  513. /** Return the (constant) length of the array holding the u1_sid_ed
  514. * field of the auth1_t in 'inp'.
  515. */
  516. size_t auth1_getlen_u1_sid_ed(const auth1_t *inp);
  517. /** Return the element at position 'idx' of the fixed array field
  518. * u1_sid_ed of the auth1_t in 'inp'.
  519. */
  520. uint8_t auth1_get_u1_sid_ed(auth1_t *inp, size_t idx);
  521. /** As auth1_get_u1_sid_ed, but take and return a const pointer
  522. */
  523. uint8_t auth1_getconst_u1_sid_ed(const auth1_t *inp, size_t idx);
  524. /** Change the element at position 'idx' of the fixed array field
  525. * u1_sid_ed of the auth1_t in 'inp', so that it will hold the value
  526. * 'elt'.
  527. */
  528. int auth1_set_u1_sid_ed(auth1_t *inp, size_t idx, uint8_t elt);
  529. /** Return a pointer to the 32-element array field u1_sid_ed of 'inp'.
  530. */
  531. uint8_t * auth1_getarray_u1_sid_ed(auth1_t *inp);
  532. /** As auth1_get_u1_sid_ed, but take and return a const pointer
  533. */
  534. const uint8_t * auth1_getconstarray_u1_sid_ed(const auth1_t *inp);
  535. /** Return the (constant) length of the array holding the slog field
  536. * of the auth1_t in 'inp'.
  537. */
  538. size_t auth1_getlen_slog(const auth1_t *inp);
  539. /** Return the element at position 'idx' of the fixed array field slog
  540. * of the auth1_t in 'inp'.
  541. */
  542. uint8_t auth1_get_slog(auth1_t *inp, size_t idx);
  543. /** As auth1_get_slog, but take and return a const pointer
  544. */
  545. uint8_t auth1_getconst_slog(const auth1_t *inp, size_t idx);
  546. /** Change the element at position 'idx' of the fixed array field slog
  547. * of the auth1_t in 'inp', so that it will hold the value 'elt'.
  548. */
  549. int auth1_set_slog(auth1_t *inp, size_t idx, uint8_t elt);
  550. /** Return a pointer to the 32-element array field slog of 'inp'.
  551. */
  552. uint8_t * auth1_getarray_slog(auth1_t *inp);
  553. /** As auth1_get_slog, but take and return a const pointer
  554. */
  555. const uint8_t * auth1_getconstarray_slog(const auth1_t *inp);
  556. /** Return the (constant) length of the array holding the clog field
  557. * of the auth1_t in 'inp'.
  558. */
  559. size_t auth1_getlen_clog(const auth1_t *inp);
  560. /** Return the element at position 'idx' of the fixed array field clog
  561. * of the auth1_t in 'inp'.
  562. */
  563. uint8_t auth1_get_clog(auth1_t *inp, size_t idx);
  564. /** As auth1_get_clog, but take and return a const pointer
  565. */
  566. uint8_t auth1_getconst_clog(const auth1_t *inp, size_t idx);
  567. /** Change the element at position 'idx' of the fixed array field clog
  568. * of the auth1_t in 'inp', so that it will hold the value 'elt'.
  569. */
  570. int auth1_set_clog(auth1_t *inp, size_t idx, uint8_t elt);
  571. /** Return a pointer to the 32-element array field clog of 'inp'.
  572. */
  573. uint8_t * auth1_getarray_clog(auth1_t *inp);
  574. /** As auth1_get_clog, but take and return a const pointer
  575. */
  576. const uint8_t * auth1_getconstarray_clog(const auth1_t *inp);
  577. /** Return the (constant) length of the array holding the scert field
  578. * of the auth1_t in 'inp'.
  579. */
  580. size_t auth1_getlen_scert(const auth1_t *inp);
  581. /** Return the element at position 'idx' of the fixed array field
  582. * scert of the auth1_t in 'inp'.
  583. */
  584. uint8_t auth1_get_scert(auth1_t *inp, size_t idx);
  585. /** As auth1_get_scert, but take and return a const pointer
  586. */
  587. uint8_t auth1_getconst_scert(const auth1_t *inp, size_t idx);
  588. /** Change the element at position 'idx' of the fixed array field
  589. * scert of the auth1_t in 'inp', so that it will hold the value
  590. * 'elt'.
  591. */
  592. int auth1_set_scert(auth1_t *inp, size_t idx, uint8_t elt);
  593. /** Return a pointer to the 32-element array field scert of 'inp'.
  594. */
  595. uint8_t * auth1_getarray_scert(auth1_t *inp);
  596. /** As auth1_get_scert, but take and return a const pointer
  597. */
  598. const uint8_t * auth1_getconstarray_scert(const auth1_t *inp);
  599. /** Return the (constant) length of the array holding the tlssecrets
  600. * field of the auth1_t in 'inp'.
  601. */
  602. size_t auth1_getlen_tlssecrets(const auth1_t *inp);
  603. /** Return the element at position 'idx' of the fixed array field
  604. * tlssecrets of the auth1_t in 'inp'.
  605. */
  606. uint8_t auth1_get_tlssecrets(auth1_t *inp, size_t idx);
  607. /** As auth1_get_tlssecrets, but take and return a const pointer
  608. */
  609. uint8_t auth1_getconst_tlssecrets(const auth1_t *inp, size_t idx);
  610. /** Change the element at position 'idx' of the fixed array field
  611. * tlssecrets of the auth1_t in 'inp', so that it will hold the value
  612. * 'elt'.
  613. */
  614. int auth1_set_tlssecrets(auth1_t *inp, size_t idx, uint8_t elt);
  615. /** Return a pointer to the 32-element array field tlssecrets of
  616. * 'inp'.
  617. */
  618. uint8_t * auth1_getarray_tlssecrets(auth1_t *inp);
  619. /** As auth1_get_tlssecrets, but take and return a const pointer
  620. */
  621. const uint8_t * auth1_getconstarray_tlssecrets(const auth1_t *inp);
  622. /** Return the position for end_of_fixed_part when we parsed this
  623. * object
  624. */
  625. const uint8_t * auth1_get_end_of_fixed_part(const auth1_t *inp);
  626. /** Return the (constant) length of the array holding the rand field
  627. * of the auth1_t in 'inp'.
  628. */
  629. size_t auth1_getlen_rand(const auth1_t *inp);
  630. /** Return the element at position 'idx' of the fixed array field rand
  631. * of the auth1_t in 'inp'.
  632. */
  633. uint8_t auth1_get_rand(auth1_t *inp, size_t idx);
  634. /** As auth1_get_rand, but take and return a const pointer
  635. */
  636. uint8_t auth1_getconst_rand(const auth1_t *inp, size_t idx);
  637. /** Change the element at position 'idx' of the fixed array field rand
  638. * of the auth1_t in 'inp', so that it will hold the value 'elt'.
  639. */
  640. int auth1_set_rand(auth1_t *inp, size_t idx, uint8_t elt);
  641. /** Return a pointer to the 24-element array field rand of 'inp'.
  642. */
  643. uint8_t * auth1_getarray_rand(auth1_t *inp);
  644. /** As auth1_get_rand, but take and return a const pointer
  645. */
  646. const uint8_t * auth1_getconstarray_rand(const auth1_t *inp);
  647. /** Return the position for end_of_signed when we parsed this object
  648. */
  649. const uint8_t * auth1_get_end_of_signed(const auth1_t *inp);
  650. /** Return the length of the dynamic array holding the sig field of
  651. * the auth1_t in 'inp'.
  652. */
  653. size_t auth1_getlen_sig(const auth1_t *inp);
  654. /** Return the element at position 'idx' of the dynamic array field
  655. * sig of the auth1_t in 'inp'.
  656. */
  657. uint8_t auth1_get_sig(auth1_t *inp, size_t idx);
  658. /** As auth1_get_sig, but take and return a const pointer
  659. */
  660. uint8_t auth1_getconst_sig(const auth1_t *inp, size_t idx);
  661. /** Change the element at position 'idx' of the dynamic array field
  662. * sig of the auth1_t in 'inp', so that it will hold the value 'elt'.
  663. */
  664. int auth1_set_sig(auth1_t *inp, size_t idx, uint8_t elt);
  665. /** Append a new element 'elt' to the dynamic array field sig of the
  666. * auth1_t in 'inp'.
  667. */
  668. int auth1_add_sig(auth1_t *inp, uint8_t elt);
  669. /** Return a pointer to the variable-length array field sig of 'inp'.
  670. */
  671. uint8_t * auth1_getarray_sig(auth1_t *inp);
  672. /** As auth1_get_sig, but take and return a const pointer
  673. */
  674. const uint8_t * auth1_getconstarray_sig(const auth1_t *inp);
  675. /** Change the length of the variable-length array field sig of 'inp'
  676. * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
  677. * -1 and set the error code on 'inp' on failure.
  678. */
  679. int auth1_setlen_sig(auth1_t *inp, size_t newlen);
  680. /** Return a newly allocated certs_cell with all elements set to zero.
  681. */
  682. certs_cell_t *certs_cell_new(void);
  683. /** Release all storage held by the certs_cell in 'victim'. (Do
  684. * nothing if 'victim' is NULL.)
  685. */
  686. void certs_cell_free(certs_cell_t *victim);
  687. /** Try to parse a certs_cell from the buffer in 'input', using up to
  688. * 'len_in' bytes from the input buffer. On success, return the number
  689. * of bytes consumed and set *output to the newly allocated
  690. * certs_cell_t. On failure, return -2 if the input appears truncated,
  691. * and -1 if the input is otherwise invalid.
  692. */
  693. ssize_t certs_cell_parse(certs_cell_t **output, const uint8_t *input, const size_t len_in);
  694. /** Return the number of bytes we expect to need to encode the
  695. * certs_cell in 'obj'. On failure, return a negative value. Note that
  696. * this value may be an overestimate, and can even be an underestimate
  697. * for certain unencodeable objects.
  698. */
  699. ssize_t certs_cell_encoded_len(const certs_cell_t *obj);
  700. /** Try to encode the certs_cell from 'input' into the buffer at
  701. * 'output', using up to 'avail' bytes of the output buffer. On
  702. * success, return the number of bytes used. On failure, return -2 if
  703. * the buffer was not long enough, and -1 if the input was invalid.
  704. */
  705. ssize_t certs_cell_encode(uint8_t *output, size_t avail, const certs_cell_t *input);
  706. /** Check whether the internal state of the certs_cell in 'obj' is
  707. * consistent. Return NULL if it is, and a short message if it is not.
  708. */
  709. const char *certs_cell_check(const certs_cell_t *obj);
  710. /** Clear any errors that were set on the object 'obj' by its setter
  711. * functions. Return true iff errors were cleared.
  712. */
  713. int certs_cell_clear_errors(certs_cell_t *obj);
  714. /** Return the value of the n_certs field of the certs_cell_t in 'inp'
  715. */
  716. uint8_t certs_cell_get_n_certs(const certs_cell_t *inp);
  717. /** Set the value of the n_certs field of the certs_cell_t in 'inp' to
  718. * 'val'. Return 0 on success; return -1 and set the error code on
  719. * 'inp' on failure.
  720. */
  721. int certs_cell_set_n_certs(certs_cell_t *inp, uint8_t val);
  722. /** Return the length of the dynamic array holding the certs field of
  723. * the certs_cell_t in 'inp'.
  724. */
  725. size_t certs_cell_getlen_certs(const certs_cell_t *inp);
  726. /** Return the element at position 'idx' of the dynamic array field
  727. * certs of the certs_cell_t in 'inp'.
  728. */
  729. struct certs_cell_cert_st * certs_cell_get_certs(certs_cell_t *inp, size_t idx);
  730. /** As certs_cell_get_certs, but take and return a const pointer
  731. */
  732. const struct certs_cell_cert_st * certs_cell_getconst_certs(const certs_cell_t *inp, size_t idx);
  733. /** Change the element at position 'idx' of the dynamic array field
  734. * certs of the certs_cell_t in 'inp', so that it will hold the value
  735. * 'elt'. Free the previous value, if any.
  736. */
  737. int certs_cell_set_certs(certs_cell_t *inp, size_t idx, struct certs_cell_cert_st * elt);
  738. /** As certs_cell_set_certs, but does not free the previous value.
  739. */
  740. int certs_cell_set0_certs(certs_cell_t *inp, size_t idx, struct certs_cell_cert_st * elt);
  741. /** Append a new element 'elt' to the dynamic array field certs of the
  742. * certs_cell_t in 'inp'.
  743. */
  744. int certs_cell_add_certs(certs_cell_t *inp, struct certs_cell_cert_st * elt);
  745. /** Return a pointer to the variable-length array field certs of
  746. * 'inp'.
  747. */
  748. struct certs_cell_cert_st * * certs_cell_getarray_certs(certs_cell_t *inp);
  749. /** As certs_cell_get_certs, but take and return a const pointer
  750. */
  751. const struct certs_cell_cert_st * const * certs_cell_getconstarray_certs(const certs_cell_t *inp);
  752. /** Change the length of the variable-length array field certs of
  753. * 'inp' to 'newlen'.Fill extra elements with NULL; free removed
  754. * elements. Return 0 on success; return -1 and set the error code on
  755. * 'inp' on failure.
  756. */
  757. int certs_cell_setlen_certs(certs_cell_t *inp, size_t newlen);
  758. #endif