2 * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved.
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
10 /* Dispatch functions for chacha20_poly1305 cipher */
12 #include "include/crypto/poly1305.h"
13 #include "cipher_chacha20.h"
15 #define NO_TLS_PAYLOAD_LENGTH ((size_t)-1)
16 #define CHACHA20_POLY1305_IVLEN 12
19 PROV_CIPHER_CTX base
; /* must be first */
20 PROV_CHACHA20_CTX chacha
;
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
;
27 unsigned int mac_inited
: 1;
28 size_t tag_len
, nonce_len
;
29 size_t tls_payload_length
;
30 size_t tls_aad_pad_sz
;
31 } PROV_CHACHA20_POLY1305_CTX
;
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
,
41 } PROV_CIPHER_HW_CHACHA20_POLY1305
;
43 const PROV_CIPHER_HW
*ossl_prov_cipher_hw_chacha20_poly1305(size_t keybits
);