20#ifndef LC_CHACHA20_POLY1305_H
21#define LC_CHACHA20_POLY1305_H
33struct lc_chacha20_poly1305_cryptor {
34 struct lc_sym_ctx chacha20;
40#define LC_CHACHA20_POLY1305_STATE_SIZE \
41 (LC_SYM_STATE_SIZE_LEN(LC_CC20_STATE_SIZE))
42#define LC_CHACHA20_POLY1305_CTX_SIZE \
43 (sizeof(struct lc_aead) + \
44 sizeof(struct lc_chacha20_poly1305_cryptor) + \
45 LC_CHACHA20_POLY1305_STATE_SIZE)
48extern const struct lc_aead *lc_chacha20_poly1305_aead;
50#define _LC_CHACHA20_POLY1305_SET_CTX(name) \
51 _LC_SYM_SET_CTX((&name->chacha20), lc_chacha20, name, \
52 (sizeof(struct lc_chacha20_poly1305_cryptor))); \
53 (name)->datalen = 0; \
56#define LC_CHACHA20_POLY1305_SET_CTX(name) \
57 LC_AEAD_CTX(name, lc_chacha20_poly1305_aead); \
58 _LC_CHACHA20_POLY1305_SET_CTX( \
59 ((struct lc_chacha20_poly1305_cryptor *)name->aead_state))
76#define LC_CHACHA20_POLY1305_CTX_ON_STACK(name) \
77 _Pragma("GCC diagnostic push") _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.