xref: /freebsd/crypto/openssl/providers/implementations/ciphers/cipher_chacha20_poly1305.h (revision 5ca8e32633c4ffbbcd6762e5888b6a4ba0708c6c)
1 /*
2  * Copyright 2019-2023 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 
10 /* Dispatch functions for chacha20_poly1305 cipher */
11 
12 #include "include/crypto/poly1305.h"
13 #include "cipher_chacha20.h"
14 
15 #define NO_TLS_PAYLOAD_LENGTH ((size_t)-1)
16 #define CHACHA20_POLY1305_IVLEN 12
17 
18 typedef struct {
19     PROV_CIPHER_CTX base;       /* must be first */
20     PROV_CHACHA20_CTX chacha;
21     POLY1305 poly1305;
22     unsigned int nonce[12 / 4];
23     unsigned char tag[POLY1305_BLOCK_SIZE];
24     unsigned char tls_aad[POLY1305_BLOCK_SIZE];
25     struct { uint64_t aad, text; } len;
26     unsigned int aad : 1;
27     unsigned int mac_inited : 1;
28     size_t tag_len;
29     size_t tls_payload_length;
30     size_t tls_aad_pad_sz;
31 } PROV_CHACHA20_POLY1305_CTX;
32 
33 typedef struct prov_cipher_hw_chacha_aead_st {
34     PROV_CIPHER_HW base; /* must be first */
35     int (*aead_cipher)(PROV_CIPHER_CTX *dat, unsigned char *out, size_t *outl,
36                        const unsigned char *in, size_t len);
37     int (*initiv)(PROV_CIPHER_CTX *ctx);
38     int (*tls_init)(PROV_CIPHER_CTX *ctx, unsigned char *aad, size_t alen);
39     int (*tls_iv_set_fixed)(PROV_CIPHER_CTX *ctx, unsigned char *fixed,
40                             size_t flen);
41 } PROV_CIPHER_HW_CHACHA20_POLY1305;
42 
43 const PROV_CIPHER_HW *ossl_prov_cipher_hw_chacha20_poly1305(size_t keybits);
44