ed25519_cert.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. /* ed25519_cert.h -- generated by by Trunnel v1.5.
  2. * https://gitweb.torproject.org/trunnel.git
  3. * You probably shouldn't edit this file.
  4. */
  5. #ifndef TRUNNEL_ED25519_CERT_H
  6. #define TRUNNEL_ED25519_CERT_H
  7. #include <stdint.h>
  8. #include "trunnel.h"
  9. #define CERTEXT_SIGNED_WITH_KEY 4
  10. #define CERTEXT_FLAG_AFFECTS_VALIDATION 1
  11. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_ED25519_CERT_EXTENSION)
  12. struct ed25519_cert_extension_st {
  13. uint16_t ext_length;
  14. uint8_t ext_type;
  15. uint8_t ext_flags;
  16. uint8_t un_signing_key[32];
  17. TRUNNEL_DYNARRAY_HEAD(, uint8_t) un_unparsed;
  18. uint8_t trunnel_error_code_;
  19. };
  20. #endif
  21. typedef struct ed25519_cert_extension_st ed25519_cert_extension_t;
  22. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_ED25519_CERT)
  23. struct ed25519_cert_st {
  24. uint8_t version;
  25. uint8_t cert_type;
  26. uint32_t exp_field;
  27. uint8_t cert_key_type;
  28. uint8_t certified_key[32];
  29. uint8_t n_extensions;
  30. TRUNNEL_DYNARRAY_HEAD(, struct ed25519_cert_extension_st *) ext;
  31. uint8_t signature[64];
  32. uint8_t trunnel_error_code_;
  33. };
  34. #endif
  35. typedef struct ed25519_cert_st ed25519_cert_t;
  36. /** Return a newly allocated ed25519_cert_extension with all elements
  37. * set to zero.
  38. */
  39. ed25519_cert_extension_t *ed25519_cert_extension_new(void);
  40. /** Release all storage held by the ed25519_cert_extension in
  41. * 'victim'. (Do nothing if 'victim' is NULL.)
  42. */
  43. void ed25519_cert_extension_free(ed25519_cert_extension_t *victim);
  44. /** Try to parse a ed25519_cert_extension from the buffer in 'input',
  45. * using up to 'len_in' bytes from the input buffer. On success,
  46. * return the number of bytes consumed and set *output to the newly
  47. * allocated ed25519_cert_extension_t. On failure, return -2 if the
  48. * input appears truncated, and -1 if the input is otherwise invalid.
  49. */
  50. ssize_t ed25519_cert_extension_parse(ed25519_cert_extension_t **output, const uint8_t *input, const size_t len_in);
  51. /** Return the number of bytes we expect to need to encode the
  52. * ed25519_cert_extension in 'obj'. On failure, return a negative
  53. * value. Note that this value may be an overestimate, and can even be
  54. * an underestimate for certain unencodeable objects.
  55. */
  56. ssize_t ed25519_cert_extension_encoded_len(const ed25519_cert_extension_t *obj);
  57. /** Try to encode the ed25519_cert_extension from 'input' into the
  58. * buffer at 'output', using up to 'avail' bytes of the output buffer.
  59. * On success, return the number of bytes used. On failure, return -2
  60. * if the buffer was not long enough, and -1 if the input was invalid.
  61. */
  62. ssize_t ed25519_cert_extension_encode(uint8_t *output, size_t avail, const ed25519_cert_extension_t *input);
  63. /** Check whether the internal state of the ed25519_cert_extension in
  64. * 'obj' is consistent. Return NULL if it is, and a short message if
  65. * it is not.
  66. */
  67. const char *ed25519_cert_extension_check(const ed25519_cert_extension_t *obj);
  68. /** Clear any errors that were set on the object 'obj' by its setter
  69. * functions. Return true iff errors were cleared.
  70. */
  71. int ed25519_cert_extension_clear_errors(ed25519_cert_extension_t *obj);
  72. /** Return the value of the ext_length field of the
  73. * ed25519_cert_extension_t in 'inp'
  74. */
  75. uint16_t ed25519_cert_extension_get_ext_length(ed25519_cert_extension_t *inp);
  76. /** Set the value of the ext_length field of the
  77. * ed25519_cert_extension_t in 'inp' to 'val'. Return 0 on success;
  78. * return -1 and set the error code on 'inp' on failure.
  79. */
  80. int ed25519_cert_extension_set_ext_length(ed25519_cert_extension_t *inp, uint16_t val);
  81. /** Return the value of the ext_type field of the
  82. * ed25519_cert_extension_t in 'inp'
  83. */
  84. uint8_t ed25519_cert_extension_get_ext_type(ed25519_cert_extension_t *inp);
  85. /** Set the value of the ext_type field of the
  86. * ed25519_cert_extension_t in 'inp' to 'val'. Return 0 on success;
  87. * return -1 and set the error code on 'inp' on failure.
  88. */
  89. int ed25519_cert_extension_set_ext_type(ed25519_cert_extension_t *inp, uint8_t val);
  90. /** Return the value of the ext_flags field of the
  91. * ed25519_cert_extension_t in 'inp'
  92. */
  93. uint8_t ed25519_cert_extension_get_ext_flags(ed25519_cert_extension_t *inp);
  94. /** Set the value of the ext_flags field of the
  95. * ed25519_cert_extension_t in 'inp' to 'val'. Return 0 on success;
  96. * return -1 and set the error code on 'inp' on failure.
  97. */
  98. int ed25519_cert_extension_set_ext_flags(ed25519_cert_extension_t *inp, uint8_t val);
  99. /** Return the (constant) length of the array holding the
  100. * un_signing_key field of the ed25519_cert_extension_t in 'inp'.
  101. */
  102. size_t ed25519_cert_extension_getlen_un_signing_key(const ed25519_cert_extension_t *inp);
  103. /** Return the element at position 'idx' of the fixed array field
  104. * un_signing_key of the ed25519_cert_extension_t in 'inp'.
  105. */
  106. uint8_t ed25519_cert_extension_get_un_signing_key(ed25519_cert_extension_t *inp, size_t idx);
  107. /** As ed25519_cert_extension_get_un_signing_key, but take and return
  108. * a const pointer
  109. */
  110. uint8_t ed25519_cert_extension_getconst_un_signing_key(const ed25519_cert_extension_t *inp, size_t idx);
  111. /** Change the element at position 'idx' of the fixed array field
  112. * un_signing_key of the ed25519_cert_extension_t in 'inp', so that it
  113. * will hold the value 'elt'.
  114. */
  115. int ed25519_cert_extension_set_un_signing_key(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt);
  116. /** Return a pointer to the 32-element array field un_signing_key of
  117. * 'inp'.
  118. */
  119. uint8_t * ed25519_cert_extension_getarray_un_signing_key(ed25519_cert_extension_t *inp);
  120. /** As ed25519_cert_extension_get_un_signing_key, but take and return
  121. * a const pointer
  122. */
  123. const uint8_t * ed25519_cert_extension_getconstarray_un_signing_key(const ed25519_cert_extension_t *inp);
  124. /** Return the length of the dynamic array holding the un_unparsed
  125. * field of the ed25519_cert_extension_t in 'inp'.
  126. */
  127. size_t ed25519_cert_extension_getlen_un_unparsed(const ed25519_cert_extension_t *inp);
  128. /** Return the element at position 'idx' of the dynamic array field
  129. * un_unparsed of the ed25519_cert_extension_t in 'inp'.
  130. */
  131. uint8_t ed25519_cert_extension_get_un_unparsed(ed25519_cert_extension_t *inp, size_t idx);
  132. /** As ed25519_cert_extension_get_un_unparsed, but take and return a
  133. * const pointer
  134. */
  135. uint8_t ed25519_cert_extension_getconst_un_unparsed(const ed25519_cert_extension_t *inp, size_t idx);
  136. /** Change the element at position 'idx' of the dynamic array field
  137. * un_unparsed of the ed25519_cert_extension_t in 'inp', so that it
  138. * will hold the value 'elt'.
  139. */
  140. int ed25519_cert_extension_set_un_unparsed(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt);
  141. /** Append a new element 'elt' to the dynamic array field un_unparsed
  142. * of the ed25519_cert_extension_t in 'inp'.
  143. */
  144. int ed25519_cert_extension_add_un_unparsed(ed25519_cert_extension_t *inp, uint8_t elt);
  145. /** Return a pointer to the variable-length array field un_unparsed of
  146. * 'inp'.
  147. */
  148. uint8_t * ed25519_cert_extension_getarray_un_unparsed(ed25519_cert_extension_t *inp);
  149. /** As ed25519_cert_extension_get_un_unparsed, but take and return a
  150. * const pointer
  151. */
  152. const uint8_t * ed25519_cert_extension_getconstarray_un_unparsed(const ed25519_cert_extension_t *inp);
  153. /** Change the length of the variable-length array field un_unparsed
  154. * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on
  155. * success; return -1 and set the error code on 'inp' on failure.
  156. */
  157. int ed25519_cert_extension_setlen_un_unparsed(ed25519_cert_extension_t *inp, size_t newlen);
  158. /** Return a newly allocated ed25519_cert with all elements set to
  159. * zero.
  160. */
  161. ed25519_cert_t *ed25519_cert_new(void);
  162. /** Release all storage held by the ed25519_cert in 'victim'. (Do
  163. * nothing if 'victim' is NULL.)
  164. */
  165. void ed25519_cert_free(ed25519_cert_t *victim);
  166. /** Try to parse a ed25519_cert from the buffer in 'input', using up
  167. * to 'len_in' bytes from the input buffer. On success, return the
  168. * number of bytes consumed and set *output to the newly allocated
  169. * ed25519_cert_t. On failure, return -2 if the input appears
  170. * truncated, and -1 if the input is otherwise invalid.
  171. */
  172. ssize_t ed25519_cert_parse(ed25519_cert_t **output, const uint8_t *input, const size_t len_in);
  173. /** Return the number of bytes we expect to need to encode the
  174. * ed25519_cert in 'obj'. On failure, return a negative value. Note
  175. * that this value may be an overestimate, and can even be an
  176. * underestimate for certain unencodeable objects.
  177. */
  178. ssize_t ed25519_cert_encoded_len(const ed25519_cert_t *obj);
  179. /** Try to encode the ed25519_cert from 'input' into the buffer at
  180. * 'output', using up to 'avail' bytes of the output buffer. On
  181. * success, return the number of bytes used. On failure, return -2 if
  182. * the buffer was not long enough, and -1 if the input was invalid.
  183. */
  184. ssize_t ed25519_cert_encode(uint8_t *output, size_t avail, const ed25519_cert_t *input);
  185. /** Check whether the internal state of the ed25519_cert in 'obj' is
  186. * consistent. Return NULL if it is, and a short message if it is not.
  187. */
  188. const char *ed25519_cert_check(const ed25519_cert_t *obj);
  189. /** Clear any errors that were set on the object 'obj' by its setter
  190. * functions. Return true iff errors were cleared.
  191. */
  192. int ed25519_cert_clear_errors(ed25519_cert_t *obj);
  193. /** Return the value of the version field of the ed25519_cert_t in
  194. * 'inp'
  195. */
  196. uint8_t ed25519_cert_get_version(ed25519_cert_t *inp);
  197. /** Set the value of the version field of the ed25519_cert_t in 'inp'
  198. * to 'val'. Return 0 on success; return -1 and set the error code on
  199. * 'inp' on failure.
  200. */
  201. int ed25519_cert_set_version(ed25519_cert_t *inp, uint8_t val);
  202. /** Return the value of the cert_type field of the ed25519_cert_t in
  203. * 'inp'
  204. */
  205. uint8_t ed25519_cert_get_cert_type(ed25519_cert_t *inp);
  206. /** Set the value of the cert_type field of the ed25519_cert_t in
  207. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  208. * code on 'inp' on failure.
  209. */
  210. int ed25519_cert_set_cert_type(ed25519_cert_t *inp, uint8_t val);
  211. /** Return the value of the exp_field field of the ed25519_cert_t in
  212. * 'inp'
  213. */
  214. uint32_t ed25519_cert_get_exp_field(ed25519_cert_t *inp);
  215. /** Set the value of the exp_field field of the ed25519_cert_t in
  216. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  217. * code on 'inp' on failure.
  218. */
  219. int ed25519_cert_set_exp_field(ed25519_cert_t *inp, uint32_t val);
  220. /** Return the value of the cert_key_type field of the ed25519_cert_t
  221. * in 'inp'
  222. */
  223. uint8_t ed25519_cert_get_cert_key_type(ed25519_cert_t *inp);
  224. /** Set the value of the cert_key_type field of the ed25519_cert_t in
  225. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  226. * code on 'inp' on failure.
  227. */
  228. int ed25519_cert_set_cert_key_type(ed25519_cert_t *inp, uint8_t val);
  229. /** Return the (constant) length of the array holding the
  230. * certified_key field of the ed25519_cert_t in 'inp'.
  231. */
  232. size_t ed25519_cert_getlen_certified_key(const ed25519_cert_t *inp);
  233. /** Return the element at position 'idx' of the fixed array field
  234. * certified_key of the ed25519_cert_t in 'inp'.
  235. */
  236. uint8_t ed25519_cert_get_certified_key(ed25519_cert_t *inp, size_t idx);
  237. /** As ed25519_cert_get_certified_key, but take and return a const
  238. * pointer
  239. */
  240. uint8_t ed25519_cert_getconst_certified_key(const ed25519_cert_t *inp, size_t idx);
  241. /** Change the element at position 'idx' of the fixed array field
  242. * certified_key of the ed25519_cert_t in 'inp', so that it will hold
  243. * the value 'elt'.
  244. */
  245. int ed25519_cert_set_certified_key(ed25519_cert_t *inp, size_t idx, uint8_t elt);
  246. /** Return a pointer to the 32-element array field certified_key of
  247. * 'inp'.
  248. */
  249. uint8_t * ed25519_cert_getarray_certified_key(ed25519_cert_t *inp);
  250. /** As ed25519_cert_get_certified_key, but take and return a const
  251. * pointer
  252. */
  253. const uint8_t * ed25519_cert_getconstarray_certified_key(const ed25519_cert_t *inp);
  254. /** Return the value of the n_extensions field of the ed25519_cert_t
  255. * in 'inp'
  256. */
  257. uint8_t ed25519_cert_get_n_extensions(ed25519_cert_t *inp);
  258. /** Set the value of the n_extensions field of the ed25519_cert_t in
  259. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  260. * code on 'inp' on failure.
  261. */
  262. int ed25519_cert_set_n_extensions(ed25519_cert_t *inp, uint8_t val);
  263. /** Return the length of the dynamic array holding the ext field of
  264. * the ed25519_cert_t in 'inp'.
  265. */
  266. size_t ed25519_cert_getlen_ext(const ed25519_cert_t *inp);
  267. /** Return the element at position 'idx' of the dynamic array field
  268. * ext of the ed25519_cert_t in 'inp'.
  269. */
  270. struct ed25519_cert_extension_st * ed25519_cert_get_ext(ed25519_cert_t *inp, size_t idx);
  271. /** As ed25519_cert_get_ext, but take and return a const pointer
  272. */
  273. const struct ed25519_cert_extension_st * ed25519_cert_getconst_ext(const ed25519_cert_t *inp, size_t idx);
  274. /** Change the element at position 'idx' of the dynamic array field
  275. * ext of the ed25519_cert_t in 'inp', so that it will hold the value
  276. * 'elt'. Free the previous value, if any.
  277. */
  278. int ed25519_cert_set_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt);
  279. /** As ed25519_cert_set_ext, but does not free the previous value.
  280. */
  281. int ed25519_cert_set0_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt);
  282. /** Append a new element 'elt' to the dynamic array field ext of the
  283. * ed25519_cert_t in 'inp'.
  284. */
  285. int ed25519_cert_add_ext(ed25519_cert_t *inp, struct ed25519_cert_extension_st * elt);
  286. /** Return a pointer to the variable-length array field ext of 'inp'.
  287. */
  288. struct ed25519_cert_extension_st * * ed25519_cert_getarray_ext(ed25519_cert_t *inp);
  289. /** As ed25519_cert_get_ext, but take and return a const pointer
  290. */
  291. const struct ed25519_cert_extension_st * const * ed25519_cert_getconstarray_ext(const ed25519_cert_t *inp);
  292. /** Change the length of the variable-length array field ext of 'inp'
  293. * to 'newlen'.Fill extra elements with NULL; free removed elements.
  294. * Return 0 on success; return -1 and set the error code on 'inp' on
  295. * failure.
  296. */
  297. int ed25519_cert_setlen_ext(ed25519_cert_t *inp, size_t newlen);
  298. /** Return the (constant) length of the array holding the signature
  299. * field of the ed25519_cert_t in 'inp'.
  300. */
  301. size_t ed25519_cert_getlen_signature(const ed25519_cert_t *inp);
  302. /** Return the element at position 'idx' of the fixed array field
  303. * signature of the ed25519_cert_t in 'inp'.
  304. */
  305. uint8_t ed25519_cert_get_signature(ed25519_cert_t *inp, size_t idx);
  306. /** As ed25519_cert_get_signature, but take and return a const pointer
  307. */
  308. uint8_t ed25519_cert_getconst_signature(const ed25519_cert_t *inp, size_t idx);
  309. /** Change the element at position 'idx' of the fixed array field
  310. * signature of the ed25519_cert_t in 'inp', so that it will hold the
  311. * value 'elt'.
  312. */
  313. int ed25519_cert_set_signature(ed25519_cert_t *inp, size_t idx, uint8_t elt);
  314. /** Return a pointer to the 64-element array field signature of 'inp'.
  315. */
  316. uint8_t * ed25519_cert_getarray_signature(ed25519_cert_t *inp);
  317. /** As ed25519_cert_get_signature, but take and return a const pointer
  318. */
  319. const uint8_t * ed25519_cert_getconstarray_signature(const ed25519_cert_t *inp);
  320. #endif