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