162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 262306a36Sopenharmony_ci/* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */ 362306a36Sopenharmony_ci 462306a36Sopenharmony_ci/* \file cc_aead.h 562306a36Sopenharmony_ci * ARM CryptoCell AEAD Crypto API 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __CC_AEAD_H__ 962306a36Sopenharmony_ci#define __CC_AEAD_H__ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include <linux/kernel.h> 1262306a36Sopenharmony_ci#include <crypto/algapi.h> 1362306a36Sopenharmony_ci#include <crypto/ctr.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* mac_cmp - HW writes 8 B but all bytes hold the same value */ 1662306a36Sopenharmony_ci#define ICV_CMP_SIZE 8 1762306a36Sopenharmony_ci#define CCM_CONFIG_BUF_SIZE (AES_BLOCK_SIZE * 3) 1862306a36Sopenharmony_ci#define MAX_MAC_SIZE SHA256_DIGEST_SIZE 1962306a36Sopenharmony_ci 2062306a36Sopenharmony_ci/* defines for AES GCM configuration buffer */ 2162306a36Sopenharmony_ci#define GCM_BLOCK_LEN_SIZE 8 2262306a36Sopenharmony_ci 2362306a36Sopenharmony_ci#define GCM_BLOCK_RFC4_IV_OFFSET 4 2462306a36Sopenharmony_ci#define GCM_BLOCK_RFC4_IV_SIZE 8 /* IV size for rfc's */ 2562306a36Sopenharmony_ci#define GCM_BLOCK_RFC4_NONCE_OFFSET 0 2662306a36Sopenharmony_ci#define GCM_BLOCK_RFC4_NONCE_SIZE 4 2762306a36Sopenharmony_ci 2862306a36Sopenharmony_ci/* Offsets into AES CCM configuration buffer */ 2962306a36Sopenharmony_ci#define CCM_B0_OFFSET 0 3062306a36Sopenharmony_ci#define CCM_A0_OFFSET 16 3162306a36Sopenharmony_ci#define CCM_CTR_COUNT_0_OFFSET 32 3262306a36Sopenharmony_ci/* CCM B0 and CTR_COUNT constants. */ 3362306a36Sopenharmony_ci#define CCM_BLOCK_NONCE_OFFSET 1 /* Nonce offset inside B0 and CTR_COUNT */ 3462306a36Sopenharmony_ci#define CCM_BLOCK_NONCE_SIZE 3 /* Nonce size inside B0 and CTR_COUNT */ 3562306a36Sopenharmony_ci#define CCM_BLOCK_IV_OFFSET 4 /* IV offset inside B0 and CTR_COUNT */ 3662306a36Sopenharmony_ci#define CCM_BLOCK_IV_SIZE 8 /* IV size inside B0 and CTR_COUNT */ 3762306a36Sopenharmony_ci 3862306a36Sopenharmony_cienum aead_ccm_header_size { 3962306a36Sopenharmony_ci ccm_header_size_null = -1, 4062306a36Sopenharmony_ci ccm_header_size_zero = 0, 4162306a36Sopenharmony_ci ccm_header_size_2 = 2, 4262306a36Sopenharmony_ci ccm_header_size_6 = 6, 4362306a36Sopenharmony_ci ccm_header_size_max = S32_MAX 4462306a36Sopenharmony_ci}; 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_cistruct aead_req_ctx { 4762306a36Sopenharmony_ci /* Allocate cache line although only 4 bytes are needed to 4862306a36Sopenharmony_ci * assure next field falls @ cache line 4962306a36Sopenharmony_ci * Used for both: digest HW compare and CCM/GCM MAC value 5062306a36Sopenharmony_ci */ 5162306a36Sopenharmony_ci u8 mac_buf[MAX_MAC_SIZE] ____cacheline_aligned; 5262306a36Sopenharmony_ci u8 ctr_iv[AES_BLOCK_SIZE] ____cacheline_aligned; 5362306a36Sopenharmony_ci 5462306a36Sopenharmony_ci //used in gcm 5562306a36Sopenharmony_ci u8 gcm_iv_inc1[AES_BLOCK_SIZE] ____cacheline_aligned; 5662306a36Sopenharmony_ci u8 gcm_iv_inc2[AES_BLOCK_SIZE] ____cacheline_aligned; 5762306a36Sopenharmony_ci u8 hkey[AES_BLOCK_SIZE] ____cacheline_aligned; 5862306a36Sopenharmony_ci struct { 5962306a36Sopenharmony_ci u8 len_a[GCM_BLOCK_LEN_SIZE] ____cacheline_aligned; 6062306a36Sopenharmony_ci u8 len_c[GCM_BLOCK_LEN_SIZE]; 6162306a36Sopenharmony_ci } gcm_len_block; 6262306a36Sopenharmony_ci 6362306a36Sopenharmony_ci u8 ccm_config[CCM_CONFIG_BUF_SIZE] ____cacheline_aligned; 6462306a36Sopenharmony_ci /* HW actual size input */ 6562306a36Sopenharmony_ci unsigned int hw_iv_size ____cacheline_aligned; 6662306a36Sopenharmony_ci /* used to prevent cache coherence problem */ 6762306a36Sopenharmony_ci u8 backup_mac[MAX_MAC_SIZE]; 6862306a36Sopenharmony_ci u8 *backup_iv; /* store orig iv */ 6962306a36Sopenharmony_ci u32 assoclen; /* size of AAD buffer to authenticate */ 7062306a36Sopenharmony_ci dma_addr_t mac_buf_dma_addr; /* internal ICV DMA buffer */ 7162306a36Sopenharmony_ci /* buffer for internal ccm configurations */ 7262306a36Sopenharmony_ci dma_addr_t ccm_iv0_dma_addr; 7362306a36Sopenharmony_ci dma_addr_t icv_dma_addr; /* Phys. address of ICV */ 7462306a36Sopenharmony_ci 7562306a36Sopenharmony_ci //used in gcm 7662306a36Sopenharmony_ci /* buffer for internal gcm configurations */ 7762306a36Sopenharmony_ci dma_addr_t gcm_iv_inc1_dma_addr; 7862306a36Sopenharmony_ci /* buffer for internal gcm configurations */ 7962306a36Sopenharmony_ci dma_addr_t gcm_iv_inc2_dma_addr; 8062306a36Sopenharmony_ci dma_addr_t hkey_dma_addr; /* Phys. address of hkey */ 8162306a36Sopenharmony_ci dma_addr_t gcm_block_len_dma_addr; /* Phys. address of gcm block len */ 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci u8 *icv_virt_addr; /* Virt. address of ICV */ 8462306a36Sopenharmony_ci struct async_gen_req_ctx gen_ctx; 8562306a36Sopenharmony_ci struct cc_mlli assoc; 8662306a36Sopenharmony_ci struct cc_mlli src; 8762306a36Sopenharmony_ci struct cc_mlli dst; 8862306a36Sopenharmony_ci struct scatterlist *src_sgl; 8962306a36Sopenharmony_ci struct scatterlist *dst_sgl; 9062306a36Sopenharmony_ci unsigned int src_offset; 9162306a36Sopenharmony_ci unsigned int dst_offset; 9262306a36Sopenharmony_ci enum cc_req_dma_buf_type assoc_buff_type; 9362306a36Sopenharmony_ci enum cc_req_dma_buf_type data_buff_type; 9462306a36Sopenharmony_ci struct mlli_params mlli_params; 9562306a36Sopenharmony_ci unsigned int cryptlen; 9662306a36Sopenharmony_ci struct scatterlist ccm_adata_sg; 9762306a36Sopenharmony_ci enum aead_ccm_header_size ccm_hdr_size; 9862306a36Sopenharmony_ci unsigned int req_authsize; 9962306a36Sopenharmony_ci enum drv_cipher_mode cipher_mode; 10062306a36Sopenharmony_ci bool is_icv_fragmented; 10162306a36Sopenharmony_ci bool is_single_pass; 10262306a36Sopenharmony_ci bool plaintext_authenticate_only; //for gcm_rfc4543 10362306a36Sopenharmony_ci}; 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ciint cc_aead_alloc(struct cc_drvdata *drvdata); 10662306a36Sopenharmony_ciint cc_aead_free(struct cc_drvdata *drvdata); 10762306a36Sopenharmony_ci 10862306a36Sopenharmony_ci#endif /*__CC_AEAD_H__*/ 109