20#ifndef LC_CSHAKE_CRYPT_H
21#define LC_CSHAKE_CRYPT_H
39 struct lc_hash_ctx cshake;
40 struct lc_cshake_ctx auth_ctx;
49#define LC_CC_KEYSTREAM_BLOCK LC_SHA3_256_SIZE_BLOCK
51#define LC_CSHAKE_CRYPT_ALIGNMENT LC_XOR_ALIGNMENT(LC_HASH_COMMON_ALIGNMENT)
53#define LC_ALIGN_CSHAKE_CRYPT_MASK(p) \
54 LC_ALIGN_PTR_8(p, LC_ALIGNMENT_MASK(LC_CSHAKE_CRYPT_ALIGNMENT))
60#define LC_CC_STATE_SIZE \
61 (LC_CSHAKE_STATE_SIZE + LC_CSHAKE_STATE_SIZE_REINIT + \
62 LC_CC_KEYSTREAM_BLOCK + LC_CSHAKE_CRYPT_ALIGNMENT)
63#define LC_CC_CTX_SIZE \
64 (sizeof(struct lc_aead) + sizeof(struct lc_cc_cryptor) + \
68extern const struct lc_aead *lc_cshake_aead;
71#define _LC_CC_SET_CTX(name, hashname) \
72 _LC_HASH_SET_CTX((&name->cshake), hashname, name, \
73 (sizeof(struct lc_cc_cryptor))); \
74 _LC_CSHAKE_SET_CTX_REINIT( \
75 (&name->auth_ctx), hashname, name, \
76 (sizeof(struct lc_cc_cryptor) + LC_CSHAKE_STATE_SIZE)); \
77 name->keystream = LC_ALIGN_CSHAKE_CRYPT_MASK( \
78 (uint8_t *)((uint8_t *)name + (sizeof(struct lc_cc_cryptor) + \
79 LC_CSHAKE_STATE_SIZE + \
80 LC_CSHAKE_STATE_SIZE_REINIT)))
82#define LC_CC_SET_CTX(name, hashname) \
83 LC_AEAD_CTX(name, lc_cshake_aead); \
84 _LC_CC_SET_CTX(((struct lc_cc_cryptor *)name->aead_state), hashname)
109#define LC_CC_CTX_ON_STACK(name, hash) \
110 _Pragma("GCC diagnostic push") _Pragma( \
111 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
112 LC_ALIGNED_BUFFER(name##_ctx_buf, LC_CC_CTX_SIZE, \
113 LC_CSHAKE_CRYPT_ALIGNMENT); \
114 struct lc_aead_ctx *name = (struct lc_aead_ctx *)name##_ctx_buf; \
115 LC_CC_SET_CTX(name, hash); \
116 _Pragma("GCC diagnostic pop")
int lc_hash(const struct lc_hash *hash, const uint8_t *in, size_t inlen, uint8_t *digest)
Calculate message digest - one-shot.
int lc_cc_alloc(const struct lc_hash *hash, struct lc_aead_ctx **ctx)
Allocate cSHAKE cryptor context on heap.