ed25519_cert.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. /* ed25519_cert.h -- generated by by Trunnel v1.2.
  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, const 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(const ed25519_cert_extension_t *inp, size_t idx);
  107. /** Change the element at position 'idx' of the fixed array field
  108. * un_signing_key of the ed25519_cert_extension_t in 'inp', so that it
  109. * will hold the value 'elt'.
  110. */
  111. int ed25519_cert_extension_set_un_signing_key(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt);
  112. /** Return a pointer to the 32-element array field un_signing_key of
  113. * 'inp'.
  114. */
  115. uint8_t * ed25519_cert_extension_getarray_un_signing_key(ed25519_cert_extension_t *inp);
  116. /** Return the length of the dynamic array holding the un_unparsed
  117. * field of the ed25519_cert_extension_t in 'inp'.
  118. */
  119. size_t ed25519_cert_extension_getlen_un_unparsed(const ed25519_cert_extension_t *inp);
  120. /** Return the element at position 'idx' of the dynamic array field
  121. * un_unparsed of the ed25519_cert_extension_t in 'inp'.
  122. */
  123. uint8_t ed25519_cert_extension_get_un_unparsed(ed25519_cert_extension_t *inp, size_t idx);
  124. /** Change the element at position 'idx' of the dynamic array field
  125. * un_unparsed of the ed25519_cert_extension_t in 'inp', so that it
  126. * will hold the value 'elt'.
  127. */
  128. int ed25519_cert_extension_set_un_unparsed(ed25519_cert_extension_t *inp, size_t idx, uint8_t elt);
  129. /** Append a new element 'elt' to the dynamic array field un_unparsed
  130. * of the ed25519_cert_extension_t in 'inp'.
  131. */
  132. int ed25519_cert_extension_add_un_unparsed(ed25519_cert_extension_t *inp, uint8_t elt);
  133. /** Return a pointer to the variable-length array field un_unparsed of
  134. * 'inp'.
  135. */
  136. uint8_t * ed25519_cert_extension_getarray_un_unparsed(ed25519_cert_extension_t *inp);
  137. /** Change the length of the variable-length array field un_unparsed
  138. * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on
  139. * success; return -1 and set the error code on 'inp' on failure.
  140. */
  141. int ed25519_cert_extension_setlen_un_unparsed(ed25519_cert_extension_t *inp, size_t newlen);
  142. /** Return a newly allocated ed25519_cert with all elements set to
  143. * zero.
  144. */
  145. ed25519_cert_t *ed25519_cert_new(void);
  146. /** Release all storage held by the ed25519_cert in 'victim'. (Do
  147. * nothing if 'victim' is NULL.)
  148. */
  149. void ed25519_cert_free(ed25519_cert_t *victim);
  150. /** Try to parse a ed25519_cert from the buffer in 'input', using up
  151. * to 'len_in' bytes from the input buffer. On success, return the
  152. * number of bytes consumed and set *output to the newly allocated
  153. * ed25519_cert_t. On failure, return -2 if the input appears
  154. * truncated, and -1 if the input is otherwise invalid.
  155. */
  156. ssize_t ed25519_cert_parse(ed25519_cert_t **output, const uint8_t *input, const size_t len_in);
  157. /** Return the number of bytes we expect to need to encode the
  158. * ed25519_cert in 'obj'. On failure, return a negative value. Note
  159. * that this value may be an overestimate, and can even be an
  160. * underestimate for certain unencodeable objects.
  161. */
  162. ssize_t ed25519_cert_encoded_len(const ed25519_cert_t *obj);
  163. /** Try to encode the ed25519_cert from 'input' into the buffer at
  164. * 'output', using up to 'avail' bytes of the output buffer. On
  165. * success, return the number of bytes used. On failure, return -2 if
  166. * the buffer was not long enough, and -1 if the input was invalid.
  167. */
  168. ssize_t ed25519_cert_encode(uint8_t *output, const size_t avail, const ed25519_cert_t *input);
  169. /** Check whether the internal state of the ed25519_cert in 'obj' is
  170. * consistent. Return NULL if it is, and a short message if it is not.
  171. */
  172. const char *ed25519_cert_check(const ed25519_cert_t *obj);
  173. /** Clear any errors that were set on the object 'obj' by its setter
  174. * functions. Return true iff errors were cleared.
  175. */
  176. int ed25519_cert_clear_errors(ed25519_cert_t *obj);
  177. /** Return the value of the version field of the ed25519_cert_t in
  178. * 'inp'
  179. */
  180. uint8_t ed25519_cert_get_version(ed25519_cert_t *inp);
  181. /** Set the value of the version field of the ed25519_cert_t in 'inp'
  182. * to 'val'. Return 0 on success; return -1 and set the error code on
  183. * 'inp' on failure.
  184. */
  185. int ed25519_cert_set_version(ed25519_cert_t *inp, uint8_t val);
  186. /** Return the value of the cert_type field of the ed25519_cert_t in
  187. * 'inp'
  188. */
  189. uint8_t ed25519_cert_get_cert_type(ed25519_cert_t *inp);
  190. /** Set the value of the cert_type field of the ed25519_cert_t in
  191. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  192. * code on 'inp' on failure.
  193. */
  194. int ed25519_cert_set_cert_type(ed25519_cert_t *inp, uint8_t val);
  195. /** Return the value of the exp_field field of the ed25519_cert_t in
  196. * 'inp'
  197. */
  198. uint32_t ed25519_cert_get_exp_field(ed25519_cert_t *inp);
  199. /** Set the value of the exp_field field of the ed25519_cert_t in
  200. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  201. * code on 'inp' on failure.
  202. */
  203. int ed25519_cert_set_exp_field(ed25519_cert_t *inp, uint32_t val);
  204. /** Return the value of the cert_key_type field of the ed25519_cert_t
  205. * in 'inp'
  206. */
  207. uint8_t ed25519_cert_get_cert_key_type(ed25519_cert_t *inp);
  208. /** Set the value of the cert_key_type field of the ed25519_cert_t in
  209. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  210. * code on 'inp' on failure.
  211. */
  212. int ed25519_cert_set_cert_key_type(ed25519_cert_t *inp, uint8_t val);
  213. /** Return the (constant) length of the array holding the
  214. * certified_key field of the ed25519_cert_t in 'inp'.
  215. */
  216. size_t ed25519_cert_getlen_certified_key(const ed25519_cert_t *inp);
  217. /** Return the element at position 'idx' of the fixed array field
  218. * certified_key of the ed25519_cert_t in 'inp'.
  219. */
  220. uint8_t ed25519_cert_get_certified_key(const ed25519_cert_t *inp, size_t idx);
  221. /** Change the element at position 'idx' of the fixed array field
  222. * certified_key of the ed25519_cert_t in 'inp', so that it will hold
  223. * the value 'elt'.
  224. */
  225. int ed25519_cert_set_certified_key(ed25519_cert_t *inp, size_t idx, uint8_t elt);
  226. /** Return a pointer to the 32-element array field certified_key of
  227. * 'inp'.
  228. */
  229. uint8_t * ed25519_cert_getarray_certified_key(ed25519_cert_t *inp);
  230. /** Return the value of the n_extensions field of the ed25519_cert_t
  231. * in 'inp'
  232. */
  233. uint8_t ed25519_cert_get_n_extensions(ed25519_cert_t *inp);
  234. /** Set the value of the n_extensions field of the ed25519_cert_t in
  235. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  236. * code on 'inp' on failure.
  237. */
  238. int ed25519_cert_set_n_extensions(ed25519_cert_t *inp, uint8_t val);
  239. /** Return the length of the dynamic array holding the ext field of
  240. * the ed25519_cert_t in 'inp'.
  241. */
  242. size_t ed25519_cert_getlen_ext(const ed25519_cert_t *inp);
  243. /** Return the element at position 'idx' of the dynamic array field
  244. * ext of the ed25519_cert_t in 'inp'.
  245. */
  246. struct ed25519_cert_extension_st * ed25519_cert_get_ext(ed25519_cert_t *inp, size_t idx);
  247. /** Change the element at position 'idx' of the dynamic array field
  248. * ext of the ed25519_cert_t in 'inp', so that it will hold the value
  249. * 'elt'. Free the previous value, if any.
  250. */
  251. int ed25519_cert_set_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt);
  252. /** As ed25519_cert_set_ext, but does not free the previous value.
  253. */
  254. int ed25519_cert_set0_ext(ed25519_cert_t *inp, size_t idx, struct ed25519_cert_extension_st * elt);
  255. /** Append a new element 'elt' to the dynamic array field ext of the
  256. * ed25519_cert_t in 'inp'.
  257. */
  258. int ed25519_cert_add_ext(ed25519_cert_t *inp, struct ed25519_cert_extension_st * elt);
  259. /** Return a pointer to the variable-length array field ext of 'inp'.
  260. */
  261. struct ed25519_cert_extension_st * * ed25519_cert_getarray_ext(ed25519_cert_t *inp);
  262. /** Change the length of the variable-length array field ext of 'inp'
  263. * to 'newlen'.Fill extra elements with NULL; free removed elements.
  264. * Return 0 on success; return -1 and set the error code on 'inp' on
  265. * failure.
  266. */
  267. int ed25519_cert_setlen_ext(ed25519_cert_t *inp, size_t newlen);
  268. /** Return the (constant) length of the array holding the signature
  269. * field of the ed25519_cert_t in 'inp'.
  270. */
  271. size_t ed25519_cert_getlen_signature(const ed25519_cert_t *inp);
  272. /** Return the element at position 'idx' of the fixed array field
  273. * signature of the ed25519_cert_t in 'inp'.
  274. */
  275. uint8_t ed25519_cert_get_signature(const ed25519_cert_t *inp, size_t idx);
  276. /** Change the element at position 'idx' of the fixed array field
  277. * signature of the ed25519_cert_t in 'inp', so that it will hold the
  278. * value 'elt'.
  279. */
  280. int ed25519_cert_set_signature(ed25519_cert_t *inp, size_t idx, uint8_t elt);
  281. /** Return a pointer to the 64-element array field signature of 'inp'.
  282. */
  283. uint8_t * ed25519_cert_getarray_signature(ed25519_cert_t *inp);
  284. #endif