pwbox.h 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. /* pwbox.h -- generated by Trunnel v1.5.3.
  2. * https://gitweb.torproject.org/trunnel.git
  3. * You probably shouldn't edit this file.
  4. */
  5. #ifndef TRUNNEL_PWBOX_H
  6. #define TRUNNEL_PWBOX_H
  7. #include <stdint.h>
  8. #include "trunnel.h"
  9. #define PWBOX0_CONST0 1414484546
  10. #define PWBOX0_CONST1 1331179568
  11. #if !defined(TRUNNEL_OPAQUE) && !defined(TRUNNEL_OPAQUE_PWBOX_ENCODED)
  12. struct pwbox_encoded_st {
  13. uint32_t fixedbytes0;
  14. uint32_t fixedbytes1;
  15. uint8_t header_len;
  16. TRUNNEL_DYNARRAY_HEAD(, uint8_t) skey_header;
  17. uint8_t iv[16];
  18. TRUNNEL_DYNARRAY_HEAD(, uint8_t) data;
  19. uint8_t hmac[32];
  20. uint8_t trunnel_error_code_;
  21. };
  22. #endif
  23. typedef struct pwbox_encoded_st pwbox_encoded_t;
  24. /** Return a newly allocated pwbox_encoded with all elements set to
  25. * zero.
  26. */
  27. pwbox_encoded_t *pwbox_encoded_new(void);
  28. /** Release all storage held by the pwbox_encoded in 'victim'. (Do
  29. * nothing if 'victim' is NULL.)
  30. */
  31. void pwbox_encoded_free(pwbox_encoded_t *victim);
  32. /** Try to parse a pwbox_encoded from the buffer in 'input', using up
  33. * to 'len_in' bytes from the input buffer. On success, return the
  34. * number of bytes consumed and set *output to the newly allocated
  35. * pwbox_encoded_t. On failure, return -2 if the input appears
  36. * truncated, and -1 if the input is otherwise invalid.
  37. */
  38. ssize_t pwbox_encoded_parse(pwbox_encoded_t **output, const uint8_t *input, const size_t len_in);
  39. /** Return the number of bytes we expect to need to encode the
  40. * pwbox_encoded in 'obj'. On failure, return a negative value. Note
  41. * that this value may be an overestimate, and can even be an
  42. * underestimate for certain unencodeable objects.
  43. */
  44. ssize_t pwbox_encoded_encoded_len(const pwbox_encoded_t *obj);
  45. /** Try to encode the pwbox_encoded from 'input' into the buffer at
  46. * 'output', using up to 'avail' bytes of the output buffer. On
  47. * success, return the number of bytes used. On failure, return -2 if
  48. * the buffer was not long enough, and -1 if the input was invalid.
  49. */
  50. ssize_t pwbox_encoded_encode(uint8_t *output, size_t avail, const pwbox_encoded_t *input);
  51. /** Check whether the internal state of the pwbox_encoded in 'obj' is
  52. * consistent. Return NULL if it is, and a short message if it is not.
  53. */
  54. const char *pwbox_encoded_check(const pwbox_encoded_t *obj);
  55. /** Clear any errors that were set on the object 'obj' by its setter
  56. * functions. Return true iff errors were cleared.
  57. */
  58. int pwbox_encoded_clear_errors(pwbox_encoded_t *obj);
  59. /** Return the value of the fixedbytes0 field of the pwbox_encoded_t
  60. * in 'inp'
  61. */
  62. uint32_t pwbox_encoded_get_fixedbytes0(const pwbox_encoded_t *inp);
  63. /** Set the value of the fixedbytes0 field of the pwbox_encoded_t in
  64. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  65. * code on 'inp' on failure.
  66. */
  67. int pwbox_encoded_set_fixedbytes0(pwbox_encoded_t *inp, uint32_t val);
  68. /** Return the value of the fixedbytes1 field of the pwbox_encoded_t
  69. * in 'inp'
  70. */
  71. uint32_t pwbox_encoded_get_fixedbytes1(const pwbox_encoded_t *inp);
  72. /** Set the value of the fixedbytes1 field of the pwbox_encoded_t in
  73. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  74. * code on 'inp' on failure.
  75. */
  76. int pwbox_encoded_set_fixedbytes1(pwbox_encoded_t *inp, uint32_t val);
  77. /** Return the value of the header_len field of the pwbox_encoded_t in
  78. * 'inp'
  79. */
  80. uint8_t pwbox_encoded_get_header_len(const pwbox_encoded_t *inp);
  81. /** Set the value of the header_len field of the pwbox_encoded_t in
  82. * 'inp' to 'val'. Return 0 on success; return -1 and set the error
  83. * code on 'inp' on failure.
  84. */
  85. int pwbox_encoded_set_header_len(pwbox_encoded_t *inp, uint8_t val);
  86. /** Return the length of the dynamic array holding the skey_header
  87. * field of the pwbox_encoded_t in 'inp'.
  88. */
  89. size_t pwbox_encoded_getlen_skey_header(const pwbox_encoded_t *inp);
  90. /** Return the element at position 'idx' of the dynamic array field
  91. * skey_header of the pwbox_encoded_t in 'inp'.
  92. */
  93. uint8_t pwbox_encoded_get_skey_header(pwbox_encoded_t *inp, size_t idx);
  94. /** As pwbox_encoded_get_skey_header, but take and return a const
  95. * pointer
  96. */
  97. uint8_t pwbox_encoded_getconst_skey_header(const pwbox_encoded_t *inp, size_t idx);
  98. /** Change the element at position 'idx' of the dynamic array field
  99. * skey_header of the pwbox_encoded_t in 'inp', so that it will hold
  100. * the value 'elt'.
  101. */
  102. int pwbox_encoded_set_skey_header(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  103. /** Append a new element 'elt' to the dynamic array field skey_header
  104. * of the pwbox_encoded_t in 'inp'.
  105. */
  106. int pwbox_encoded_add_skey_header(pwbox_encoded_t *inp, uint8_t elt);
  107. /** Return a pointer to the variable-length array field skey_header of
  108. * 'inp'.
  109. */
  110. uint8_t * pwbox_encoded_getarray_skey_header(pwbox_encoded_t *inp);
  111. /** As pwbox_encoded_get_skey_header, but take and return a const
  112. * pointer
  113. */
  114. const uint8_t * pwbox_encoded_getconstarray_skey_header(const pwbox_encoded_t *inp);
  115. /** Change the length of the variable-length array field skey_header
  116. * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on
  117. * success; return -1 and set the error code on 'inp' on failure.
  118. */
  119. int pwbox_encoded_setlen_skey_header(pwbox_encoded_t *inp, size_t newlen);
  120. /** Return the (constant) length of the array holding the iv field of
  121. * the pwbox_encoded_t in 'inp'.
  122. */
  123. size_t pwbox_encoded_getlen_iv(const pwbox_encoded_t *inp);
  124. /** Return the element at position 'idx' of the fixed array field iv
  125. * of the pwbox_encoded_t in 'inp'.
  126. */
  127. uint8_t pwbox_encoded_get_iv(pwbox_encoded_t *inp, size_t idx);
  128. /** As pwbox_encoded_get_iv, but take and return a const pointer
  129. */
  130. uint8_t pwbox_encoded_getconst_iv(const pwbox_encoded_t *inp, size_t idx);
  131. /** Change the element at position 'idx' of the fixed array field iv
  132. * of the pwbox_encoded_t in 'inp', so that it will hold the value
  133. * 'elt'.
  134. */
  135. int pwbox_encoded_set_iv(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  136. /** Return a pointer to the 16-element array field iv of 'inp'.
  137. */
  138. uint8_t * pwbox_encoded_getarray_iv(pwbox_encoded_t *inp);
  139. /** As pwbox_encoded_get_iv, but take and return a const pointer
  140. */
  141. const uint8_t * pwbox_encoded_getconstarray_iv(const pwbox_encoded_t *inp);
  142. /** Return the length of the dynamic array holding the data field of
  143. * the pwbox_encoded_t in 'inp'.
  144. */
  145. size_t pwbox_encoded_getlen_data(const pwbox_encoded_t *inp);
  146. /** Return the element at position 'idx' of the dynamic array field
  147. * data of the pwbox_encoded_t in 'inp'.
  148. */
  149. uint8_t pwbox_encoded_get_data(pwbox_encoded_t *inp, size_t idx);
  150. /** As pwbox_encoded_get_data, but take and return a const pointer
  151. */
  152. uint8_t pwbox_encoded_getconst_data(const pwbox_encoded_t *inp, size_t idx);
  153. /** Change the element at position 'idx' of the dynamic array field
  154. * data of the pwbox_encoded_t in 'inp', so that it will hold the
  155. * value 'elt'.
  156. */
  157. int pwbox_encoded_set_data(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  158. /** Append a new element 'elt' to the dynamic array field data of the
  159. * pwbox_encoded_t in 'inp'.
  160. */
  161. int pwbox_encoded_add_data(pwbox_encoded_t *inp, uint8_t elt);
  162. /** Return a pointer to the variable-length array field data of 'inp'.
  163. */
  164. uint8_t * pwbox_encoded_getarray_data(pwbox_encoded_t *inp);
  165. /** As pwbox_encoded_get_data, but take and return a const pointer
  166. */
  167. const uint8_t * pwbox_encoded_getconstarray_data(const pwbox_encoded_t *inp);
  168. /** Change the length of the variable-length array field data of 'inp'
  169. * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
  170. * -1 and set the error code on 'inp' on failure.
  171. */
  172. int pwbox_encoded_setlen_data(pwbox_encoded_t *inp, size_t newlen);
  173. /** Return the (constant) length of the array holding the hmac field
  174. * of the pwbox_encoded_t in 'inp'.
  175. */
  176. size_t pwbox_encoded_getlen_hmac(const pwbox_encoded_t *inp);
  177. /** Return the element at position 'idx' of the fixed array field hmac
  178. * of the pwbox_encoded_t in 'inp'.
  179. */
  180. uint8_t pwbox_encoded_get_hmac(pwbox_encoded_t *inp, size_t idx);
  181. /** As pwbox_encoded_get_hmac, but take and return a const pointer
  182. */
  183. uint8_t pwbox_encoded_getconst_hmac(const pwbox_encoded_t *inp, size_t idx);
  184. /** Change the element at position 'idx' of the fixed array field hmac
  185. * of the pwbox_encoded_t in 'inp', so that it will hold the value
  186. * 'elt'.
  187. */
  188. int pwbox_encoded_set_hmac(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  189. /** Return a pointer to the 32-element array field hmac of 'inp'.
  190. */
  191. uint8_t * pwbox_encoded_getarray_hmac(pwbox_encoded_t *inp);
  192. /** As pwbox_encoded_get_hmac, but take and return a const pointer
  193. */
  194. const uint8_t * pwbox_encoded_getconstarray_hmac(const pwbox_encoded_t *inp);
  195. #endif