18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
38c2ecf20Sopenharmony_ci
48c2ecf20Sopenharmony_ci/* \file cc_hash.h
58c2ecf20Sopenharmony_ci * ARM CryptoCell Hash Crypto API
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#ifndef __CC_HASH_H__
98c2ecf20Sopenharmony_ci#define __CC_HASH_H__
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci#include "cc_buffer_mgr.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define HMAC_IPAD_CONST	0x36363636
148c2ecf20Sopenharmony_ci#define HMAC_OPAD_CONST	0x5C5C5C5C
158c2ecf20Sopenharmony_ci#define HASH_LEN_SIZE_712 16
168c2ecf20Sopenharmony_ci#define HASH_LEN_SIZE_630 8
178c2ecf20Sopenharmony_ci#define HASH_MAX_LEN_SIZE HASH_LEN_SIZE_712
188c2ecf20Sopenharmony_ci#define CC_MAX_HASH_DIGEST_SIZE	SHA512_DIGEST_SIZE
198c2ecf20Sopenharmony_ci#define CC_MAX_HASH_BLCK_SIZE SHA512_BLOCK_SIZE
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#define XCBC_MAC_K1_OFFSET 0
228c2ecf20Sopenharmony_ci#define XCBC_MAC_K2_OFFSET 16
238c2ecf20Sopenharmony_ci#define XCBC_MAC_K3_OFFSET 32
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci#define CC_EXPORT_MAGIC 0xC2EE1070U
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci/* this struct was taken from drivers/crypto/nx/nx-aes-xcbc.c and it is used
288c2ecf20Sopenharmony_ci * for xcbc/cmac statesize
298c2ecf20Sopenharmony_ci */
308c2ecf20Sopenharmony_cistruct aeshash_state {
318c2ecf20Sopenharmony_ci	u8 state[AES_BLOCK_SIZE];
328c2ecf20Sopenharmony_ci	unsigned int count;
338c2ecf20Sopenharmony_ci	u8 buffer[AES_BLOCK_SIZE];
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/* ahash state */
378c2ecf20Sopenharmony_cistruct ahash_req_ctx {
388c2ecf20Sopenharmony_ci	u8 buffers[2][CC_MAX_HASH_BLCK_SIZE] ____cacheline_aligned;
398c2ecf20Sopenharmony_ci	u8 digest_result_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
408c2ecf20Sopenharmony_ci	u8 digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
418c2ecf20Sopenharmony_ci	u8 opad_digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
428c2ecf20Sopenharmony_ci	u8 digest_bytes_len[HASH_MAX_LEN_SIZE] ____cacheline_aligned;
438c2ecf20Sopenharmony_ci	struct async_gen_req_ctx gen_ctx ____cacheline_aligned;
448c2ecf20Sopenharmony_ci	enum cc_req_dma_buf_type data_dma_buf_type;
458c2ecf20Sopenharmony_ci	dma_addr_t opad_digest_dma_addr;
468c2ecf20Sopenharmony_ci	dma_addr_t digest_buff_dma_addr;
478c2ecf20Sopenharmony_ci	dma_addr_t digest_bytes_len_dma_addr;
488c2ecf20Sopenharmony_ci	dma_addr_t digest_result_dma_addr;
498c2ecf20Sopenharmony_ci	u32 buf_cnt[2];
508c2ecf20Sopenharmony_ci	u32 buff_index;
518c2ecf20Sopenharmony_ci	u32 xcbc_count; /* count xcbc update operatations */
528c2ecf20Sopenharmony_ci	struct scatterlist buff_sg[2];
538c2ecf20Sopenharmony_ci	struct scatterlist *curr_sg;
548c2ecf20Sopenharmony_ci	u32 in_nents;
558c2ecf20Sopenharmony_ci	u32 mlli_nents;
568c2ecf20Sopenharmony_ci	struct mlli_params mlli_params;
578c2ecf20Sopenharmony_ci};
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_cistatic inline u32 *cc_hash_buf_cnt(struct ahash_req_ctx *state)
608c2ecf20Sopenharmony_ci{
618c2ecf20Sopenharmony_ci	return &state->buf_cnt[state->buff_index];
628c2ecf20Sopenharmony_ci}
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_cistatic inline u8 *cc_hash_buf(struct ahash_req_ctx *state)
658c2ecf20Sopenharmony_ci{
668c2ecf20Sopenharmony_ci	return state->buffers[state->buff_index];
678c2ecf20Sopenharmony_ci}
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_cistatic inline u32 *cc_next_buf_cnt(struct ahash_req_ctx *state)
708c2ecf20Sopenharmony_ci{
718c2ecf20Sopenharmony_ci	return &state->buf_cnt[state->buff_index ^ 1];
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_cistatic inline u8 *cc_next_buf(struct ahash_req_ctx *state)
758c2ecf20Sopenharmony_ci{
768c2ecf20Sopenharmony_ci	return state->buffers[state->buff_index ^ 1];
778c2ecf20Sopenharmony_ci}
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ciint cc_hash_alloc(struct cc_drvdata *drvdata);
808c2ecf20Sopenharmony_ciint cc_init_hash_sram(struct cc_drvdata *drvdata);
818c2ecf20Sopenharmony_ciint cc_hash_free(struct cc_drvdata *drvdata);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci/**
848c2ecf20Sopenharmony_ci * cc_digest_len_addr() - Gets the initial digest length
858c2ecf20Sopenharmony_ci *
868c2ecf20Sopenharmony_ci * @drvdata: Associated device driver context
878c2ecf20Sopenharmony_ci * @mode: The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA512
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * Return:
908c2ecf20Sopenharmony_ci * Returns the address of the initial digest length in SRAM
918c2ecf20Sopenharmony_ci */
928c2ecf20Sopenharmony_ciu32 cc_digest_len_addr(void *drvdata, u32 mode);
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_ci/**
958c2ecf20Sopenharmony_ci * cc_larval_digest_addr() - Gets the address of the initial digest in SRAM
968c2ecf20Sopenharmony_ci * according to the given hash mode
978c2ecf20Sopenharmony_ci *
988c2ecf20Sopenharmony_ci * @drvdata: Associated device driver context
998c2ecf20Sopenharmony_ci * @mode: The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA512
1008c2ecf20Sopenharmony_ci *
1018c2ecf20Sopenharmony_ci * Return:
1028c2ecf20Sopenharmony_ci * The address of the initial digest in SRAM
1038c2ecf20Sopenharmony_ci */
1048c2ecf20Sopenharmony_ciu32 cc_larval_digest_addr(void *drvdata, u32 mode);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#endif /*__CC_HASH_H__*/
107