20#ifndef LC_CHACHA20_POLY1305_H
21#define LC_CHACHA20_POLY1305_H
33struct lc_chacha20_poly1305_cryptor {
34 struct lc_sym_ctx chacha20;
35 struct lc_poly1305_context poly1305_ctx;
40#define LC_CHACHA20_POLY1305_STATE_SIZE (LC_SYM_STATE_SIZE(lc_chacha20))
41#define LC_CHACHA20_POLY1305_CTX_SIZE \
42 (sizeof(struct lc_aead) + \
43 sizeof(struct lc_chacha20_poly1305_cryptor) + \
44 LC_CHACHA20_POLY1305_STATE_SIZE)
47extern const struct lc_aead *lc_chacha20_poly1305_aead;
49#define _LC_CHACHA20_POLY1305_SET_CTX(name) \
50 _LC_SYM_SET_CTX((&name->chacha20), lc_chacha20, name, \
51 (sizeof(struct lc_chacha20_poly1305_cryptor))); \
52 (name)->datalen = 0; \
55#define LC_CHACHA20_POLY1305_SET_CTX(name) \
56 LC_AEAD_CTX(name, lc_chacha20_poly1305_aead); \
57 _LC_CHACHA20_POLY1305_SET_CTX( \
58 ((struct lc_chacha20_poly1305_cryptor *)name->aead_state))
75#define LC_CHACHA20_POLY1305_CTX_ON_STACK(name) \
76 _Pragma("GCC diagnostic push") \
77 _Pragma("GCC diagnostic ignored \"-Wvla\"") _Pragma( \
78 "GCC diagnostic ignored \"-Wdeclaration-after-statement\"") \
79 LC_ALIGNED_BUFFER(name##_ctx_buf, \
80 LC_CHACHA20_POLY1305_CTX_SIZE, \
81 LC_MEM_COMMON_ALIGNMENT); \
82 struct lc_aead_ctx *name = (struct lc_aead_ctx *)name##_ctx_buf; \
83 LC_CHACHA20_POLY1305_SET_CTX(name); \
85 _Pragma("GCC diagnostic pop")
int lc_chacha20_poly1305_alloc(struct lc_aead_ctx **ctx)
Allocate ChaCha20 Poly1305 cryptor context on heap.