pwbox.h 7.1 KB

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