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_hash.h 562306a36Sopenharmony_ci * ARM CryptoCell Hash Crypto API 662306a36Sopenharmony_ci */ 762306a36Sopenharmony_ci 862306a36Sopenharmony_ci#ifndef __CC_HASH_H__ 962306a36Sopenharmony_ci#define __CC_HASH_H__ 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci#include "cc_buffer_mgr.h" 1262306a36Sopenharmony_ci 1362306a36Sopenharmony_ci#define HMAC_IPAD_CONST 0x36363636 1462306a36Sopenharmony_ci#define HMAC_OPAD_CONST 0x5C5C5C5C 1562306a36Sopenharmony_ci#define HASH_LEN_SIZE_712 16 1662306a36Sopenharmony_ci#define HASH_LEN_SIZE_630 8 1762306a36Sopenharmony_ci#define HASH_MAX_LEN_SIZE HASH_LEN_SIZE_712 1862306a36Sopenharmony_ci#define CC_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE 1962306a36Sopenharmony_ci#define CC_MAX_HASH_BLCK_SIZE SHA512_BLOCK_SIZE 2062306a36Sopenharmony_ci 2162306a36Sopenharmony_ci#define XCBC_MAC_K1_OFFSET 0 2262306a36Sopenharmony_ci#define XCBC_MAC_K2_OFFSET 16 2362306a36Sopenharmony_ci#define XCBC_MAC_K3_OFFSET 32 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci#define CC_EXPORT_MAGIC 0xC2EE1070U 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci/* this struct was taken from drivers/crypto/nx/nx-aes-xcbc.c and it is used 2862306a36Sopenharmony_ci * for xcbc/cmac statesize 2962306a36Sopenharmony_ci */ 3062306a36Sopenharmony_cistruct aeshash_state { 3162306a36Sopenharmony_ci u8 state[AES_BLOCK_SIZE]; 3262306a36Sopenharmony_ci unsigned int count; 3362306a36Sopenharmony_ci u8 buffer[AES_BLOCK_SIZE]; 3462306a36Sopenharmony_ci}; 3562306a36Sopenharmony_ci 3662306a36Sopenharmony_ci/* ahash state */ 3762306a36Sopenharmony_cistruct ahash_req_ctx { 3862306a36Sopenharmony_ci u8 buffers[2][CC_MAX_HASH_BLCK_SIZE] ____cacheline_aligned; 3962306a36Sopenharmony_ci u8 digest_result_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned; 4062306a36Sopenharmony_ci u8 digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned; 4162306a36Sopenharmony_ci u8 opad_digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned; 4262306a36Sopenharmony_ci u8 digest_bytes_len[HASH_MAX_LEN_SIZE] ____cacheline_aligned; 4362306a36Sopenharmony_ci struct async_gen_req_ctx gen_ctx ____cacheline_aligned; 4462306a36Sopenharmony_ci enum cc_req_dma_buf_type data_dma_buf_type; 4562306a36Sopenharmony_ci dma_addr_t opad_digest_dma_addr; 4662306a36Sopenharmony_ci dma_addr_t digest_buff_dma_addr; 4762306a36Sopenharmony_ci dma_addr_t digest_bytes_len_dma_addr; 4862306a36Sopenharmony_ci dma_addr_t digest_result_dma_addr; 4962306a36Sopenharmony_ci u32 buf_cnt[2]; 5062306a36Sopenharmony_ci u32 buff_index; 5162306a36Sopenharmony_ci u32 xcbc_count; /* count xcbc update operatations */ 5262306a36Sopenharmony_ci struct scatterlist buff_sg[2]; 5362306a36Sopenharmony_ci struct scatterlist *curr_sg; 5462306a36Sopenharmony_ci u32 in_nents; 5562306a36Sopenharmony_ci u32 mlli_nents; 5662306a36Sopenharmony_ci struct mlli_params mlli_params; 5762306a36Sopenharmony_ci}; 5862306a36Sopenharmony_ci 5962306a36Sopenharmony_cistatic inline u32 *cc_hash_buf_cnt(struct ahash_req_ctx *state) 6062306a36Sopenharmony_ci{ 6162306a36Sopenharmony_ci return &state->buf_cnt[state->buff_index]; 6262306a36Sopenharmony_ci} 6362306a36Sopenharmony_ci 6462306a36Sopenharmony_cistatic inline u8 *cc_hash_buf(struct ahash_req_ctx *state) 6562306a36Sopenharmony_ci{ 6662306a36Sopenharmony_ci return state->buffers[state->buff_index]; 6762306a36Sopenharmony_ci} 6862306a36Sopenharmony_ci 6962306a36Sopenharmony_cistatic inline u32 *cc_next_buf_cnt(struct ahash_req_ctx *state) 7062306a36Sopenharmony_ci{ 7162306a36Sopenharmony_ci return &state->buf_cnt[state->buff_index ^ 1]; 7262306a36Sopenharmony_ci} 7362306a36Sopenharmony_ci 7462306a36Sopenharmony_cistatic inline u8 *cc_next_buf(struct ahash_req_ctx *state) 7562306a36Sopenharmony_ci{ 7662306a36Sopenharmony_ci return state->buffers[state->buff_index ^ 1]; 7762306a36Sopenharmony_ci} 7862306a36Sopenharmony_ci 7962306a36Sopenharmony_ciint cc_hash_alloc(struct cc_drvdata *drvdata); 8062306a36Sopenharmony_ciint cc_init_hash_sram(struct cc_drvdata *drvdata); 8162306a36Sopenharmony_ciint cc_hash_free(struct cc_drvdata *drvdata); 8262306a36Sopenharmony_ci 8362306a36Sopenharmony_ci/** 8462306a36Sopenharmony_ci * cc_digest_len_addr() - Gets the initial digest length 8562306a36Sopenharmony_ci * 8662306a36Sopenharmony_ci * @drvdata: Associated device driver context 8762306a36Sopenharmony_ci * @mode: The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA512 8862306a36Sopenharmony_ci * 8962306a36Sopenharmony_ci * Return: 9062306a36Sopenharmony_ci * Returns the address of the initial digest length in SRAM 9162306a36Sopenharmony_ci */ 9262306a36Sopenharmony_ciu32 cc_digest_len_addr(void *drvdata, u32 mode); 9362306a36Sopenharmony_ci 9462306a36Sopenharmony_ci/** 9562306a36Sopenharmony_ci * cc_larval_digest_addr() - Gets the address of the initial digest in SRAM 9662306a36Sopenharmony_ci * according to the given hash mode 9762306a36Sopenharmony_ci * 9862306a36Sopenharmony_ci * @drvdata: Associated device driver context 9962306a36Sopenharmony_ci * @mode: The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA512 10062306a36Sopenharmony_ci * 10162306a36Sopenharmony_ci * Return: 10262306a36Sopenharmony_ci * The address of the initial digest in SRAM 10362306a36Sopenharmony_ci */ 10462306a36Sopenharmony_ciu32 cc_larval_digest_addr(void *drvdata, u32 mode); 10562306a36Sopenharmony_ci 10662306a36Sopenharmony_ci#endif /*__CC_HASH_H__*/ 107