pwbox.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* pwbox.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_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, const 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(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(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(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. /** Change the element at position 'idx' of the dynamic array field
  95. * skey_header of the pwbox_encoded_t in 'inp', so that it will hold
  96. * the value 'elt'.
  97. */
  98. int pwbox_encoded_set_skey_header(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  99. /** Append a new element 'elt' to the dynamic array field skey_header
  100. * of the pwbox_encoded_t in 'inp'.
  101. */
  102. int pwbox_encoded_add_skey_header(pwbox_encoded_t *inp, uint8_t elt);
  103. /** Return a pointer to the variable-length array field skey_header of
  104. * 'inp'.
  105. */
  106. uint8_t * pwbox_encoded_getarray_skey_header(pwbox_encoded_t *inp);
  107. /** Change the length of the variable-length array field skey_header
  108. * of 'inp' to 'newlen'.Fill extra elements with 0. Return 0 on
  109. * success; return -1 and set the error code on 'inp' on failure.
  110. */
  111. int pwbox_encoded_setlen_skey_header(pwbox_encoded_t *inp, size_t newlen);
  112. /** Return the (constant) length of the array holding the iv field of
  113. * the pwbox_encoded_t in 'inp'.
  114. */
  115. size_t pwbox_encoded_getlen_iv(const pwbox_encoded_t *inp);
  116. /** Return the element at position 'idx' of the fixed array field iv
  117. * of the pwbox_encoded_t in 'inp'.
  118. */
  119. uint8_t pwbox_encoded_get_iv(const pwbox_encoded_t *inp, size_t idx);
  120. /** Change the element at position 'idx' of the fixed array field iv
  121. * of the pwbox_encoded_t in 'inp', so that it will hold the value
  122. * 'elt'.
  123. */
  124. int pwbox_encoded_set_iv(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  125. /** Return a pointer to the 16-element array field iv of 'inp'.
  126. */
  127. uint8_t * pwbox_encoded_getarray_iv(pwbox_encoded_t *inp);
  128. /** Return the length of the dynamic array holding the data field of
  129. * the pwbox_encoded_t in 'inp'.
  130. */
  131. size_t pwbox_encoded_getlen_data(const pwbox_encoded_t *inp);
  132. /** Return the element at position 'idx' of the dynamic array field
  133. * data of the pwbox_encoded_t in 'inp'.
  134. */
  135. uint8_t pwbox_encoded_get_data(pwbox_encoded_t *inp, size_t idx);
  136. /** Change the element at position 'idx' of the dynamic array field
  137. * data of the pwbox_encoded_t in 'inp', so that it will hold the
  138. * value 'elt'.
  139. */
  140. int pwbox_encoded_set_data(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  141. /** Append a new element 'elt' to the dynamic array field data of the
  142. * pwbox_encoded_t in 'inp'.
  143. */
  144. int pwbox_encoded_add_data(pwbox_encoded_t *inp, uint8_t elt);
  145. /** Return a pointer to the variable-length array field data of 'inp'.
  146. */
  147. uint8_t * pwbox_encoded_getarray_data(pwbox_encoded_t *inp);
  148. /** Change the length of the variable-length array field data of 'inp'
  149. * to 'newlen'.Fill extra elements with 0. Return 0 on success; return
  150. * -1 and set the error code on 'inp' on failure.
  151. */
  152. int pwbox_encoded_setlen_data(pwbox_encoded_t *inp, size_t newlen);
  153. /** Return the (constant) length of the array holding the hmac field
  154. * of the pwbox_encoded_t in 'inp'.
  155. */
  156. size_t pwbox_encoded_getlen_hmac(const pwbox_encoded_t *inp);
  157. /** Return the element at position 'idx' of the fixed array field hmac
  158. * of the pwbox_encoded_t in 'inp'.
  159. */
  160. uint8_t pwbox_encoded_get_hmac(const pwbox_encoded_t *inp, size_t idx);
  161. /** Change the element at position 'idx' of the fixed array field hmac
  162. * of the pwbox_encoded_t in 'inp', so that it will hold the value
  163. * 'elt'.
  164. */
  165. int pwbox_encoded_set_hmac(pwbox_encoded_t *inp, size_t idx, uint8_t elt);
  166. /** Return a pointer to the 32-element array field hmac of 'inp'.
  167. */
  168. uint8_t * pwbox_encoded_getarray_hmac(pwbox_encoded_t *inp);
  169. #endif