You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

588 lines
19 KiB

  1. /**
  2. * @file decaf/shake.h
  3. * @copyright
  4. * Based on CC0 code by David Leon Gil, 2015 \n
  5. * Copyright (c) 2015 Cryptography Research, Inc. \n
  6. * Released under the MIT License. See LICENSE.txt for license information.
  7. * @author Mike Hamburg
  8. * @brief SHA-3-n and SHAKE-n instances.
  9. * @warning EXPERIMENTAL! The names, parameter orders etc are likely to change.
  10. */
  11. #ifndef __SHAKE_H__
  12. #define __SHAKE_H__
  13. #include <stdint.h>
  14. #include <sys/types.h>
  15. #include <stdlib.h> /* for NULL */
  16. #include <decaf/common.h>
  17. /** @cond internal */
  18. #define API_VIS __attribute__((visibility("default")))
  19. #define WARN_UNUSED __attribute__((warn_unused_result))
  20. #define NONNULL1 __attribute__((nonnull(1)))
  21. #define NONNULL2 __attribute__((nonnull(1,2)))
  22. #define NONNULL13 __attribute__((nonnull(1,3)))
  23. #define NONNULL3 __attribute__((nonnull(1,2,3)))
  24. #define INLINE __inline__ __attribute__((always_inline))
  25. #define UNUSED __attribute__((unused))
  26. /** @endcond */
  27. #ifndef INTERNAL_SPONGE_STRUCT
  28. /** Sponge container object for the various primitives. */
  29. typedef struct keccak_sponge_s {
  30. /** @cond internal */
  31. uint64_t opaque[26];
  32. /** @endcond */
  33. } keccak_sponge_t[1];
  34. struct kparams_s;
  35. #endif
  36. typedef struct keccak_sponge_s keccak_strobe_t[1], keccak_prng_t[1];
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /**
  41. * @brief Initialize a sponge context object.
  42. * @param [out] sponge The object to initialize.
  43. * @param [in] params The sponge's parameter description.
  44. */
  45. void sponge_init (
  46. keccak_sponge_t sponge,
  47. const struct kparams_s *params
  48. ) API_VIS;
  49. /**
  50. * @brief Absorb data into a SHA3 or SHAKE hash context.
  51. * @param [inout] sponge The context.
  52. * @param [in] in The input data.
  53. * @param [in] len The input data's length in bytes.
  54. */
  55. void sha3_update (
  56. struct keccak_sponge_s * __restrict__ sponge,
  57. const uint8_t *in,
  58. size_t len
  59. ) API_VIS;
  60. /**
  61. * @brief Squeeze output data from a SHA3 or SHAKE hash context.
  62. * This does not destroy or re-initialize the hash context, and
  63. * sha3 output can be called more times.
  64. *
  65. * @param [inout] sponge The context.
  66. * @param [out] out The output data.
  67. * @param [in] len The requested output data length in bytes.
  68. */
  69. void sha3_output (
  70. keccak_sponge_t sponge,
  71. uint8_t * __restrict__ out,
  72. size_t len
  73. ) API_VIS;
  74. /**
  75. * @brief Return the default output length of the sponge construction,
  76. * for the purpose of C++ default operators.
  77. *
  78. * Returns n/8 for SHA3-n and 2n/8 for SHAKE-n.
  79. *
  80. * @param [inout] sponge The context.
  81. */
  82. size_t sponge_default_output_bytes (
  83. const keccak_sponge_t sponge
  84. ) API_VIS;
  85. /**
  86. * @brief Destroy a SHA3 or SHAKE sponge context by overwriting it with 0.
  87. * @param [out] sponge The context.
  88. */
  89. void sponge_destroy (
  90. keccak_sponge_t sponge
  91. ) API_VIS;
  92. /**
  93. * @brief Hash (in) to (out)
  94. * @param [in] in The input data.
  95. * @param [in] inlen The length of the input data.
  96. * @param [out] out A buffer for the output data.
  97. * @param [in] outlen The length of the output data.
  98. * @param [in] params The parameters of the sponge hash.
  99. */
  100. void sponge_hash (
  101. const uint8_t *in,
  102. size_t inlen,
  103. uint8_t *out,
  104. size_t outlen,
  105. const struct kparams_s *params
  106. ) API_VIS;
  107. /* FUTURE: expand/doxygenate individual SHAKE/SHA3 instances? */
  108. /** @cond internal */
  109. #define DECSHAKE(n) \
  110. extern const struct kparams_s SHAKE##n##_params_s API_VIS; \
  111. typedef struct shake##n##_ctx_s { keccak_sponge_t s; } shake##n##_ctx_t[1]; \
  112. static inline void NONNULL1 shake##n##_init(shake##n##_ctx_t sponge) { \
  113. sponge_init(sponge->s, &SHAKE##n##_params_s); \
  114. } \
  115. static inline void NONNULL1 shake##n##_gen_init(keccak_sponge_t sponge) { \
  116. sponge_init(sponge, &SHAKE##n##_params_s); \
  117. } \
  118. static inline void NONNULL2 shake##n##_update(shake##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \
  119. sha3_update(sponge->s, in, inlen); \
  120. } \
  121. static inline void NONNULL2 shake##n##_final(shake##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
  122. sha3_output(sponge->s, out, outlen); \
  123. sponge_init(sponge->s, &SHAKE##n##_params_s); \
  124. } \
  125. static inline void NONNULL13 shake##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
  126. sponge_hash(in,inlen,out,outlen,&SHAKE##n##_params_s); \
  127. } \
  128. static inline void NONNULL1 shake##n##_destroy( shake##n##_ctx_t sponge ) { \
  129. sponge_destroy(sponge->s); \
  130. }
  131. #define DECSHA3(n) \
  132. extern const struct kparams_s SHA3_##n##_params_s API_VIS; \
  133. typedef struct sha3_##n##_ctx_s { keccak_sponge_t s; } sha3_##n##_ctx_t[1]; \
  134. static inline void NONNULL1 sha3_##n##_init(sha3_##n##_ctx_t sponge) { \
  135. sponge_init(sponge->s, &SHA3_##n##_params_s); \
  136. } \
  137. static inline void NONNULL1 sha3_##n##_gen_init(keccak_sponge_t sponge) { \
  138. sponge_init(sponge, &SHA3_##n##_params_s); \
  139. } \
  140. static inline void NONNULL2 sha3_##n##_update(sha3_##n##_ctx_t sponge, const uint8_t *in, size_t inlen ) { \
  141. sha3_update(sponge->s, in, inlen); \
  142. } \
  143. static inline void NONNULL2 sha3_##n##_final(sha3_##n##_ctx_t sponge, uint8_t *out, size_t outlen ) { \
  144. sha3_output(sponge->s, out, outlen); \
  145. sponge_init(sponge->s, &SHA3_##n##_params_s); \
  146. } \
  147. static inline void NONNULL13 sha3_##n##_hash(uint8_t *out, size_t outlen, const uint8_t *in, size_t inlen) { \
  148. sponge_hash(in,inlen,out,outlen,&SHA3_##n##_params_s); \
  149. } \
  150. static inline void NONNULL1 sha3_##n##_destroy(sha3_##n##_ctx_t sponge) { \
  151. sponge_destroy(sponge->s); \
  152. }
  153. /** @endcond */
  154. DECSHAKE(128)
  155. DECSHAKE(256)
  156. DECSHA3(224)
  157. DECSHA3(256)
  158. DECSHA3(384)
  159. DECSHA3(512)
  160. /**
  161. * @brief Initialize a sponge-based CSPRNG from a buffer.
  162. *
  163. * @param [out] prng The prng object.
  164. * @param [in] in The initial data.
  165. * @param [in] len The length of the initial data.
  166. * @param [in] deterministic If zero, allow RNG to stir in nondeterministic
  167. * data from RDRAND or RDTSC.
  168. */
  169. void spongerng_init_from_buffer (
  170. keccak_prng_t prng,
  171. const uint8_t * __restrict__ in,
  172. size_t len,
  173. int deterministic
  174. ) NONNULL2 API_VIS;
  175. /**
  176. * @brief Initialize a sponge-based CSPRNG from a file.
  177. *
  178. * @param [out] prng The prng object.
  179. * @param [in] file A name of a file containing initial data.
  180. * @param [in] len The length of the initial data. Must be positive.
  181. * @param [in] deterministic If zero, allow RNG to stir in nondeterministic
  182. * data from RDRAND or RDTSC.
  183. *
  184. * @retval DECAF_SUCCESS success.
  185. * @retval DECAF_FAILURE failure.
  186. * @note On failure, errno can be used to determine the cause.
  187. */
  188. decaf_error_t spongerng_init_from_file (
  189. keccak_prng_t prng,
  190. const char *file,
  191. size_t len,
  192. int deterministic
  193. ) NONNULL2 API_VIS WARN_UNUSED;
  194. /**
  195. * @brief Initialize a nondeterministic sponge-based CSPRNG from /dev/urandom.
  196. *
  197. * @param [out] sponge The sponge object.
  198. *
  199. * @retval DECAF_SUCCESS success.
  200. * @retval DECAF_FAILURE failure.
  201. * @note On failure, errno can be used to determine the cause.
  202. */
  203. decaf_error_t spongerng_init_from_dev_urandom (
  204. keccak_prng_t prng
  205. ) API_VIS WARN_UNUSED;
  206. /**
  207. * @brief Output bytes from a sponge-based CSPRNG.
  208. *
  209. * @param [inout] sponge The sponge object.
  210. * @param [out] out The output buffer.
  211. * @param [in] len The output buffer's length.
  212. */
  213. void spongerng_next (
  214. keccak_prng_t prng,
  215. uint8_t * __restrict__ out,
  216. size_t len
  217. ) API_VIS;
  218. /**
  219. * @brief Stir entropy data into a sponge-based CSPRNG from a buffer.
  220. *
  221. * @param [out] sponge The sponge object.
  222. * @param [in] in The entropy data.
  223. * @param [in] len The length of the initial data.
  224. */
  225. void spongerng_stir (
  226. keccak_prng_t prng,
  227. const uint8_t * __restrict__ in,
  228. size_t len
  229. ) NONNULL2 API_VIS;
  230. extern const struct kparams_s STROBE_128 API_VIS;
  231. extern const struct kparams_s STROBE_256 API_VIS;
  232. extern const struct kparams_s STROBE_KEYED_128 API_VIS;
  233. extern const struct kparams_s STROBE_KEYED_256 API_VIS;
  234. typedef enum {
  235. STROBE_MODE_ABSORB = 0,
  236. STROBE_MODE_DUPLEX = 1,
  237. STROBE_MODE_ABSORB_R = 2,
  238. STROBE_MODE_DUPLEX_R = 3,
  239. /* FIXME: no bits allocated in .py version */
  240. STROBE_MODE_PLAINTEXT = 4,
  241. STROBE_MODE_SQUEEZE = 5,
  242. STROBE_MODE_FORGET = 6,
  243. STROBE_MODE_SQUEEZE_R = 7
  244. } strobe_mode_t;
  245. #define STROBE_FLAG_CLIENT_SENT (1<<8)
  246. #define STROBE_FLAG_IMPLICIT (1<<9)
  247. #define STROBE_FLAG_FORGET (1<<12)
  248. #define STROBE_FLAG_NO_LENGTH (1<<15)
  249. /* After 1<<16, flags don't go to the sponge anymore, they just affect the handling */
  250. #define STROBE_FLAG_RECV (1<<16)
  251. #define STROBE_FLAG_RUN_F (1<<17)
  252. #define STROBE_FLAG_MORE (1<<18)
  253. #define STROBE_FLAG_LENGTH_64 (1<<19)
  254. #define STROBE_FLAG_NONDIR (STROBE_FLAG_IMPLICIT)
  255. /** Automatic flags implied by the mode */
  256. /* HACK: SQUEEZE_R is treated as directional because its' MAC */
  257. #define STROBE_AUTO_FLAGS(_mode) \
  258. ( (((_mode)&1) ? STROBE_FLAG_RUN_F : 0) \
  259. | (( ((_mode) & ~2) == STROBE_MODE_ABSORB \
  260. || (_mode) == STROBE_MODE_SQUEEZE \
  261. || (_mode) == STROBE_MODE_FORGET \
  262. ) ? STROBE_FLAG_IMPLICIT|STROBE_FLAG_NONDIR : 0) \
  263. )
  264. #define STROBE_CONTROL_WORD(_name,_id,_mode,_flags) \
  265. static const uint32_t _name = _id | (_mode<<10) | (_mode<<29) | _flags | STROBE_AUTO_FLAGS(_mode)
  266. STROBE_CONTROL_WORD(STROBE_CW_INIT, 0x00, STROBE_MODE_ABSORB, 0);
  267. /* Ciphers */
  268. STROBE_CONTROL_WORD(STROBE_CW_FIXED_KEY, 0x10, STROBE_MODE_ABSORB, 0);
  269. STROBE_CONTROL_WORD(STROBE_CW_STATIC_PUB, 0x11, STROBE_MODE_PLAINTEXT, 0);
  270. STROBE_CONTROL_WORD(STROBE_CW_DH_EPH, 0x12, STROBE_MODE_PLAINTEXT, 0);
  271. STROBE_CONTROL_WORD(STROBE_CW_DH_KEY, 0x13, STROBE_MODE_ABSORB, 0);
  272. STROBE_CONTROL_WORD(STROBE_CW_PRNG, 0x18, STROBE_MODE_SQUEEZE, STROBE_FLAG_FORGET);
  273. STROBE_CONTROL_WORD(STROBE_CW_SESSION_HASH, 0x19, STROBE_MODE_SQUEEZE, 0);
  274. /* Reuse for PRNG */
  275. STROBE_CONTROL_WORD(STROBE_CW_PRNG_INITIAL_SEED, 0x10, STROBE_MODE_ABSORB, STROBE_FLAG_NO_LENGTH);
  276. STROBE_CONTROL_WORD(STROBE_CW_PRNG_RESEED, 0x11, STROBE_MODE_ABSORB, STROBE_FLAG_NO_LENGTH);
  277. STROBE_CONTROL_WORD(STROBE_CW_PRNG_CPU_SEED, 0x12, STROBE_MODE_ABSORB, 0);
  278. STROBE_CONTROL_WORD(STROBE_CW_PRNG_USER_SEED, 0x13, STROBE_MODE_ABSORB, STROBE_FLAG_LENGTH_64);
  279. STROBE_CONTROL_WORD(STROBE_CW_PRNG_PRNG, 0x14, STROBE_MODE_SQUEEZE, STROBE_FLAG_LENGTH_64 | STROBE_FLAG_FORGET);
  280. /* Signatures */
  281. STROBE_CONTROL_WORD(STROBE_CW_SIG_SCHEME, 0x20, STROBE_MODE_ABSORB, 0);
  282. STROBE_CONTROL_WORD(STROBE_CW_SIG_PK, 0x21, STROBE_MODE_ABSORB, 0);
  283. STROBE_CONTROL_WORD(STROBE_CW_SIG_EPH, 0x22, STROBE_MODE_PLAINTEXT, 0);
  284. STROBE_CONTROL_WORD(STROBE_CW_SIG_CHAL, 0x23, STROBE_MODE_SQUEEZE, 0);
  285. STROBE_CONTROL_WORD(STROBE_CW_SIG_RESP, 0x24, STROBE_MODE_DUPLEX, 0);
  286. /* Payloads and encrypted data */
  287. STROBE_CONTROL_WORD(STROBE_CW_PAYLOAD_PLAINTEXT, 0x30, STROBE_MODE_PLAINTEXT, 0);
  288. STROBE_CONTROL_WORD(STROBE_CW_PAYLOAD_CIPHERTEXT, 0x31, STROBE_MODE_DUPLEX, 0);
  289. STROBE_CONTROL_WORD(STROBE_CW_MAC, 0x32, STROBE_MODE_SQUEEZE_R, STROBE_FLAG_FORGET);
  290. STROBE_CONTROL_WORD(STROBE_CW_AD_EXPLICIT, 0x34, STROBE_MODE_PLAINTEXT, 0);
  291. STROBE_CONTROL_WORD(STROBE_CW_AD_IMPLICIT, 0x35, STROBE_MODE_ABSORB, 0);
  292. STROBE_CONTROL_WORD(STROBE_CW_NONCE_EXPLICIT, 0x36, STROBE_MODE_PLAINTEXT, 0);
  293. STROBE_CONTROL_WORD(STROBE_CW_NONCE_IMPLICIT, 0x37, STROBE_MODE_ABSORB, 0);
  294. STROBE_CONTROL_WORD(STROBE_CW_STREAMING_PLAINTEXT,0x30, STROBE_MODE_PLAINTEXT, STROBE_FLAG_NO_LENGTH); /* TODO: orly? */
  295. /* Change spec, control flow, etc */
  296. STROBE_CONTROL_WORD(STROBE_CW_COMPRESS, 0x40, STROBE_MODE_ABSORB_R, 0);
  297. /* FIXME: adjust this respec logic */
  298. STROBE_CONTROL_WORD(STROBE_CW_RESPEC_INFO, 0x41, STROBE_MODE_ABSORB, STROBE_FLAG_RUN_F | STROBE_FLAG_FORGET);
  299. STROBE_CONTROL_WORD(STROBE_CW_RESPEC, 0x42, STROBE_MODE_ABSORB_R, STROBE_FLAG_RUN_F);
  300. STROBE_CONTROL_WORD(STROBE_CW_FORK, 0x43, STROBE_MODE_ABSORB_R, STROBE_FLAG_RUN_F | STROBE_FLAG_FORGET);
  301. /* FIXME: instance can be rolled back to recover other INSTANCEs */
  302. STROBE_CONTROL_WORD(STROBE_CW_INSTANCE, 0x44, STROBE_MODE_ABSORB_R, STROBE_FLAG_FORGET);
  303. STROBE_CONTROL_WORD(STROBE_CW_ACKNOWLEDGE, 0x45, STROBE_MODE_PLAINTEXT, 0);
  304. static INLINE UNUSED WARN_UNUSED uint32_t
  305. strobe_cw_recv(uint32_t cw) {
  306. uint32_t recv_toggle = (cw & STROBE_FLAG_NONDIR) ? 0 : STROBE_FLAG_RECV;
  307. if (cw & STROBE_FLAG_IMPLICIT) {
  308. return cw ^ recv_toggle;
  309. } else {
  310. uint32_t modes_2[8] = {
  311. /* Note: most of these really shouldn't happen... */
  312. STROBE_MODE_ABSORB,
  313. STROBE_MODE_DUPLEX_R,
  314. STROBE_MODE_ABSORB_R,
  315. STROBE_MODE_DUPLEX,
  316. STROBE_MODE_PLAINTEXT,
  317. STROBE_MODE_SQUEEZE,
  318. STROBE_MODE_FORGET,
  319. STROBE_MODE_ABSORB
  320. };
  321. return ((cw & ((1<<29)-1)) | (modes_2[cw>>29]<<29)) ^ recv_toggle;
  322. }
  323. }
  324. #define STROBE_MAX_AUTH_BYTES 32
  325. /**
  326. * @brief Initialize Strobe protocol context.
  327. * @param [out] strobe The uninitialized strobe object.
  328. * @param [in] Strobe parameter descriptor
  329. * @param [in] am_client Nonzero if this party
  330. * is the client.
  331. */
  332. void strobe_init (
  333. keccak_strobe_t strobe,
  334. const struct kparams_s *params,
  335. const char *proto,
  336. uint8_t am_client
  337. ) NONNULL2 API_VIS;
  338. /**
  339. * @brief Run a transaction against a STROBE state.
  340. * @param [inout] strobe The initialized STROBE object.
  341. * @param [out] out The output.
  342. * @param [in] in The input.
  343. * @param [in] len The length of the input/output.
  344. * @param [in] cw_flags The control word with flags.
  345. */
  346. void strobe_transact (
  347. keccak_strobe_t strobe,
  348. unsigned char *out,
  349. const unsigned char *in,
  350. size_t len,
  351. uint32_t cw_flags
  352. ) NONNULL1 API_VIS;
  353. /**
  354. * @brief Send plaintext in strobe context.
  355. * @param [inout] The initialized strobe object.
  356. * @param [in] in The plaintext.
  357. * @param [in] len The length of the plaintext.
  358. * @param [in] iSent Nonzero if this side of exchange sent the plaintext.
  359. */
  360. static INLINE UNUSED void strobe_plaintext (
  361. keccak_strobe_t strobe,
  362. const unsigned char *in,
  363. uint16_t len,
  364. uint8_t iSent
  365. ) {
  366. strobe_transact(
  367. strobe, NULL, in, len,
  368. iSent ? STROBE_CW_PAYLOAD_PLAINTEXT
  369. : strobe_cw_recv(STROBE_CW_PAYLOAD_PLAINTEXT)
  370. );
  371. }
  372. /**
  373. * @brief Report authenticated data in strobe context.
  374. * @param [inout] The initialized strobe object.
  375. * @param [in] in The plaintext.
  376. * @param [in] len The length of the ad.
  377. */
  378. static INLINE UNUSED void strobe_ad (
  379. keccak_strobe_t strobe,
  380. const unsigned char *in,
  381. size_t len
  382. ) {
  383. strobe_transact( strobe, NULL, in, len, STROBE_CW_AD_EXPLICIT );
  384. }
  385. /**
  386. * @brief Set nonce in strobe context.
  387. * @param [inout] The initialized strobe object.
  388. * @param [in] in The nonce.
  389. * @param [in] len The length of the nonce.
  390. */
  391. static INLINE UNUSED void strobe_nonce (
  392. keccak_strobe_t strobe,
  393. const unsigned char *in,
  394. uint16_t len
  395. ) {
  396. strobe_transact( strobe, NULL, in, len, STROBE_CW_NONCE_EXPLICIT );
  397. }
  398. /**
  399. * @brief Set fixed key in strobe context.
  400. * @param [inout] The initialized strobe object.
  401. * @param [in] in The key.
  402. * @param [in] len The length of the key.
  403. */
  404. static INLINE UNUSED void
  405. strobe_fixed_key (
  406. keccak_strobe_t strobe,
  407. const unsigned char *in,
  408. uint16_t len
  409. ) {
  410. strobe_transact( strobe, NULL, in, len, STROBE_CW_FIXED_KEY );
  411. }
  412. /**
  413. * @brief Set Diffie-Hellman key in strobe context.
  414. * @param [inout] The initialized strobe object.
  415. * @param [in] in The key.
  416. * @param [in] len The length of the key.
  417. */
  418. static INLINE UNUSED void
  419. strobe_dh_key (
  420. keccak_strobe_t strobe,
  421. const unsigned char *in,
  422. uint16_t len
  423. ) {
  424. strobe_transact( strobe, NULL, in, len, STROBE_CW_DH_KEY );
  425. }
  426. /**
  427. * @brief Produce an authenticator.
  428. * @param [inout] strobe The Strobe protocol context.
  429. * @param [out] out The authenticator
  430. * @param len The length.
  431. */
  432. static INLINE UNUSED void
  433. strobe_produce_auth (
  434. keccak_strobe_t strobe,
  435. unsigned char *out,
  436. uint16_t len
  437. ) {
  438. strobe_transact( strobe, out, NULL, len, STROBE_CW_MAC );
  439. }
  440. /**
  441. * @brief Encrypt bytes from in to out.
  442. * @warning Doesn't produce an auth tag.
  443. * @param [inout] strobe The Strobe protocol context.
  444. * @param [in] in The plaintext.
  445. * @param [out] out The ciphertext.
  446. * @param [in] len The length of plaintext and ciphertext.
  447. */
  448. static INLINE UNUSED void
  449. strobe_encrypt (
  450. keccak_strobe_t strobe,
  451. unsigned char *out,
  452. const unsigned char *in,
  453. uint16_t len
  454. ) {
  455. strobe_transact(strobe, out, in, len, STROBE_CW_PAYLOAD_CIPHERTEXT);
  456. }
  457. /**
  458. * @brief Decrypt bytes from in to out.
  459. * @warning Doesn't check an auth tag.
  460. * @param [inout] strobe The Strobe protocol context.
  461. * @param [in] in The ciphertext.
  462. * @param [out] out The plaintext.
  463. * @param [in] len The length of plaintext and ciphertext.
  464. */
  465. static INLINE UNUSED void
  466. strobe_decrypt (
  467. keccak_strobe_t strobe,
  468. unsigned char *out,
  469. const unsigned char *in,
  470. uint16_t len
  471. ) {
  472. strobe_transact(strobe, out, in, len, strobe_cw_recv(STROBE_CW_PAYLOAD_CIPHERTEXT));
  473. }
  474. /**
  475. * @brief Produce a session-bound pseudorandom value.
  476. *
  477. * @warning This "prng" value is NOT suitable for
  478. * refreshing forward secrecy! It's to replace things
  479. * like TCP session hash.
  480. *
  481. * @param [inout] strobe The Strobe protocol context
  482. * @param [out] out The output random data.
  483. * @param len The length.
  484. */
  485. static inline void strobe_prng (
  486. keccak_strobe_t strobe,
  487. unsigned char *out,
  488. uint16_t len
  489. ) {
  490. strobe_transact( strobe, out, NULL, len, STROBE_CW_PRNG );
  491. }
  492. /**
  493. * @brief Verify an authenticator.
  494. * @param [inout] strobe The Strobe protocol context
  495. * @param [in] in The authenticator
  496. * @param len The length, which must be no more than
  497. * @todo 32?
  498. * @retval DECAF_SUCCESS The operation applied successfully.
  499. * @retval DECAF_FAILURE The operation failed because of a
  500. * bad validator (or because you aren't keyed)
  501. */
  502. decaf_error_t strobe_verify_auth (
  503. keccak_strobe_t strobe,
  504. const unsigned char *in,
  505. uint16_t len
  506. ) WARN_UNUSED NONNULL2 API_VIS;
  507. /**
  508. * @brief Respecify Strobe protocol object's crypto.
  509. * @param [inout] The initialized strobe context.
  510. * @param [in] Strobe parameter descriptor
  511. * @param [in] am_client Nonzero if this party
  512. * is the client.
  513. */
  514. void strobe_respec (
  515. keccak_strobe_t strobe,
  516. const struct kparams_s *params
  517. ) NONNULL2 API_VIS;
  518. #define strobe_destroy sponge_destroy
  519. #ifdef __cplusplus
  520. } /* extern "C" */
  521. #endif
  522. #undef API_VIS
  523. #undef WARN_UNUSED
  524. #undef NONNULL1
  525. #undef NONNULL13
  526. #undef NONNULL2
  527. #undef NONNULL3
  528. #undef INLINE
  529. #undef UNUSED
  530. #endif /* __SHAKE_H__ */