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