6 #define TLS_CHACHA20_IV_LENGTH 12
8 /* ChaCha20 implementation by D. J. Bernstein
12 #define CHACHA_MINKEYLEN 16
13 #define CHACHA_NONCELEN 8
14 #define CHACHA_NONCELEN_96 12
15 #define CHACHA_CTRLEN 8
16 #define CHACHA_CTRLEN_96 4
17 #define CHACHA_STATELEN (CHACHA_NONCELEN+CHACHA_CTRLEN)
18 #define CHACHA_BLOCKLEN 64
20 #define POLY1305_MAX_AAD 32
21 #define POLY1305_KEYLEN 32
22 #define POLY1305_TAGLEN 16
24 #define POLY1305_BLOCK_SIZE 16
28 uint8_t ks[CHACHA_BLOCKLEN];
32 /* 17 + sizeof(size_t) + 14*sizeof(unsigned long) */
33 struct poly1305_context {
38 unsigned char buffer[POLY1305_BLOCK_SIZE];
42 void chacha_keysetup(struct chacha_ctx *x, const unsigned char *k, unsigned int kbits);
43 void chacha_ivsetup(struct chacha_ctx *x, const unsigned char *iv, const unsigned char *ctr);
44 void chacha_ivsetup_96bitnonce(struct chacha_ctx *x, const unsigned char *iv, const unsigned char *ctr);
45 void chacha_encrypt_bytes(struct chacha_ctx *x, const unsigned char *m, unsigned char *c, unsigned int bytes);
46 int poly1305_generate_key(unsigned char *key256, unsigned char *nonce, unsigned int noncelen, unsigned char *poly_key, unsigned int counter);
47 void chacha_ivupdate(struct chacha_ctx *x, const uint8_t *iv, const uint8_t *aad, const uint8_t *counter);
48 void chacha20_poly1305_key(struct chacha_ctx *ctx, unsigned char *poly1305_key);
49 int chacha20_poly1305_aead(struct chacha_ctx *ctx, unsigned char *pt, unsigned int len, unsigned char *aad, unsigned int aad_len, unsigned char *poly_key, unsigned char *out);
50 void tls_poly1305_init(struct poly1305_context *ctx, const unsigned char key[32]);
51 void tls_poly1305_update(struct poly1305_context *ctx, const unsigned char *m, size_t bytes);
52 void tls_poly1305_finish(struct poly1305_context *ctx, unsigned char mac[16]);