63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1) // SPDX-License-Identifier: GPL-2.0
03963caeb0dd7 (Gilad Ben-Yossef 2019-04-18 16:38:53 +0300 2) /* Copyright (C) 2012-2019 ARM Limited (or its affiliates). */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 3)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 4) #include <linux/kernel.h>
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 5) #include <linux/module.h>
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 6) #include <crypto/algapi.h>
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 7) #include <crypto/hash.h>
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 8) #include <crypto/md5.h>
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 9) #include <crypto/sm3.h>
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 10) #include <crypto/internal/hash.h>
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 11)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 12) #include "cc_driver.h"
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 13) #include "cc_request_mgr.h"
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 14) #include "cc_buffer_mgr.h"
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 15) #include "cc_hash.h"
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 16) #include "cc_sram_mgr.h"
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 17)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 18) #define CC_MAX_HASH_SEQ_LEN 12
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 19) #define CC_MAX_OPAD_KEYS_SIZE CC_MAX_HASH_BLCK_SIZE
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 20) #define CC_SM3_HASH_LEN_SIZE 8
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 21)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 22) struct cc_hash_handle {
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 23) u32 digest_len_sram_addr; /* const value in SRAM*/
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 24) u32 larval_digest_sram_addr; /* const value in SRAM */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 25) struct list_head hash_list;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 26) };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 27)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 28) static const u32 cc_digest_len_init[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 29) 0x00000040, 0x00000000, 0x00000000, 0x00000000 };
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 30) static const u32 cc_md5_init[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 31) SHA1_H3, SHA1_H2, SHA1_H1, SHA1_H0 };
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 32) static const u32 cc_sha1_init[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 33) SHA1_H4, SHA1_H3, SHA1_H2, SHA1_H1, SHA1_H0 };
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 34) static const u32 cc_sha224_init[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 35) SHA224_H7, SHA224_H6, SHA224_H5, SHA224_H4,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 36) SHA224_H3, SHA224_H2, SHA224_H1, SHA224_H0 };
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 37) static const u32 cc_sha256_init[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 38) SHA256_H7, SHA256_H6, SHA256_H5, SHA256_H4,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 39) SHA256_H3, SHA256_H2, SHA256_H1, SHA256_H0 };
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 40) static const u32 cc_digest_len_sha512_init[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 41) 0x00000080, 0x00000000, 0x00000000, 0x00000000 };
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 42)
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 43) /*
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 44) * Due to the way the HW works, every double word in the SHA384 and SHA512
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 45) * larval hashes must be stored in hi/lo order
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 46) */
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 47) #define hilo(x) upper_32_bits(x), lower_32_bits(x)
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 48) static const u32 cc_sha384_init[] = {
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 49) hilo(SHA384_H7), hilo(SHA384_H6), hilo(SHA384_H5), hilo(SHA384_H4),
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 50) hilo(SHA384_H3), hilo(SHA384_H2), hilo(SHA384_H1), hilo(SHA384_H0) };
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 51) static const u32 cc_sha512_init[] = {
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 52) hilo(SHA512_H7), hilo(SHA512_H6), hilo(SHA512_H5), hilo(SHA512_H4),
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 53) hilo(SHA512_H3), hilo(SHA512_H2), hilo(SHA512_H1), hilo(SHA512_H0) };
f08b58501c74d (Geert Uytterhoeven 2020-02-11 19:18:59 +0100 54)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 55) static const u32 cc_sm3_init[] = {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 56) SM3_IVH, SM3_IVG, SM3_IVF, SM3_IVE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 57) SM3_IVD, SM3_IVC, SM3_IVB, SM3_IVA };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 58)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 59) static void cc_setup_xcbc(struct ahash_request *areq, struct cc_hw_desc desc[],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 60) unsigned int *seq_size);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 61)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 62) static void cc_setup_cmac(struct ahash_request *areq, struct cc_hw_desc desc[],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 63) unsigned int *seq_size);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 64)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 65) static const void *cc_larval_digest(struct device *dev, u32 mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 66)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 67) struct cc_hash_alg {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 68) struct list_head entry;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 69) int hash_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 70) int hw_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 71) int inter_digestsize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 72) struct cc_drvdata *drvdata;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 73) struct ahash_alg ahash_alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 74) };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 75)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 76) struct hash_key_req_ctx {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 77) u32 keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 78) dma_addr_t key_dma_addr;
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 79) u8 *key;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 80) };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 81)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 82) /* hash per-session context */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 83) struct cc_hash_ctx {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 84) struct cc_drvdata *drvdata;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 85) /* holds the origin digest; the digest after "setkey" if HMAC,*
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 86) * the initial digest if HASH.
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 87) */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 88) u8 digest_buff[CC_MAX_HASH_DIGEST_SIZE] ____cacheline_aligned;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 89) u8 opad_tmp_keys_buff[CC_MAX_OPAD_KEYS_SIZE] ____cacheline_aligned;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 90)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 91) dma_addr_t opad_tmp_keys_dma_addr ____cacheline_aligned;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 92) dma_addr_t digest_buff_dma_addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 93) /* use for hmac with key large then mode block size */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 94) struct hash_key_req_ctx key_params;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 95) int hash_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 96) int hw_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 97) int inter_digestsize;
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 98) unsigned int hash_len;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 99) struct completion setkey_comp;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 100) bool is_hmac;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 101) };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 102)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 103) static void cc_set_desc(struct ahash_req_ctx *areq_ctx, struct cc_hash_ctx *ctx,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 104) unsigned int flow_mode, struct cc_hw_desc desc[],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 105) bool is_not_last_data, unsigned int *seq_size);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 106)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 107) static void cc_set_endianity(u32 mode, struct cc_hw_desc *desc)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 108) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 109) if (mode == DRV_HASH_MD5 || mode == DRV_HASH_SHA384 ||
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 110) mode == DRV_HASH_SHA512) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 111) set_bytes_swap(desc, 1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 112) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 113) set_cipher_config0(desc, HASH_DIGEST_RESULT_LITTLE_ENDIAN);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 114) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 115) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 116)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 117) static int cc_map_result(struct device *dev, struct ahash_req_ctx *state,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 118) unsigned int digestsize)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 119) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 120) state->digest_result_dma_addr =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 121) dma_map_single(dev, state->digest_result_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 122) digestsize, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 123) if (dma_mapping_error(dev, state->digest_result_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 124) dev_err(dev, "Mapping digest result buffer %u B for DMA failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 125) digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 126) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 127) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 128) dev_dbg(dev, "Mapped digest result buffer %u B at va=%pK to dma=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 129) digestsize, state->digest_result_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 130) &state->digest_result_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 131)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 132) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 133) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 134)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 135) static void cc_init_req(struct device *dev, struct ahash_req_ctx *state,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 136) struct cc_hash_ctx *ctx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 137) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 138) bool is_hmac = ctx->is_hmac;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 139)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 140) memset(state, 0, sizeof(*state));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 141)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 142) if (is_hmac) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 143) if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC &&
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 144) ctx->hw_mode != DRV_CIPHER_CMAC) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 145) dma_sync_single_for_cpu(dev, ctx->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 146) ctx->inter_digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 147) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 148)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 149) memcpy(state->digest_buff, ctx->digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 150) ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 151) if (ctx->hash_mode == DRV_HASH_SHA512 ||
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 152) ctx->hash_mode == DRV_HASH_SHA384)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 153) memcpy(state->digest_bytes_len,
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 154) cc_digest_len_sha512_init,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 155) ctx->hash_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 156) else
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 157) memcpy(state->digest_bytes_len,
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 158) cc_digest_len_init,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 159) ctx->hash_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 160) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 161)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 162) if (ctx->hash_mode != DRV_HASH_NULL) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 163) dma_sync_single_for_cpu(dev,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 164) ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 165) ctx->inter_digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 166) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 167) memcpy(state->opad_digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 168) ctx->opad_tmp_keys_buff, ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 169) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 170) } else { /*hash*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 171) /* Copy the initial digests if hash flow. */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 172) const void *larval = cc_larval_digest(dev, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 173)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 174) memcpy(state->digest_buff, larval, ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 175) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 176) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 177)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 178) static int cc_map_req(struct device *dev, struct ahash_req_ctx *state,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 179) struct cc_hash_ctx *ctx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 180) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 181) bool is_hmac = ctx->is_hmac;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 182)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 183) state->digest_buff_dma_addr =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 184) dma_map_single(dev, state->digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 185) ctx->inter_digestsize, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 186) if (dma_mapping_error(dev, state->digest_buff_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 187) dev_err(dev, "Mapping digest len %d B at va=%pK for DMA failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 188) ctx->inter_digestsize, state->digest_buff);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 189) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 190) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 191) dev_dbg(dev, "Mapped digest %d B at va=%pK to dma=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 192) ctx->inter_digestsize, state->digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 193) &state->digest_buff_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 194)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 195) if (ctx->hw_mode != DRV_CIPHER_XCBC_MAC) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 196) state->digest_bytes_len_dma_addr =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 197) dma_map_single(dev, state->digest_bytes_len,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 198) HASH_MAX_LEN_SIZE, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 199) if (dma_mapping_error(dev, state->digest_bytes_len_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 200) dev_err(dev, "Mapping digest len %u B at va=%pK for DMA failed\n",
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 201) HASH_MAX_LEN_SIZE, state->digest_bytes_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 202) goto unmap_digest_buf;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 203) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 204) dev_dbg(dev, "Mapped digest len %u B at va=%pK to dma=%pad\n",
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 205) HASH_MAX_LEN_SIZE, state->digest_bytes_len,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 206) &state->digest_bytes_len_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 207) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 208)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 209) if (is_hmac && ctx->hash_mode != DRV_HASH_NULL) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 210) state->opad_digest_dma_addr =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 211) dma_map_single(dev, state->opad_digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 212) ctx->inter_digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 213) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 214) if (dma_mapping_error(dev, state->opad_digest_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 215) dev_err(dev, "Mapping opad digest %d B at va=%pK for DMA failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 216) ctx->inter_digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 217) state->opad_digest_buff);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 218) goto unmap_digest_len;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 219) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 220) dev_dbg(dev, "Mapped opad digest %d B at va=%pK to dma=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 221) ctx->inter_digestsize, state->opad_digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 222) &state->opad_digest_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 223) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 224)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 225) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 226)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 227) unmap_digest_len:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 228) if (state->digest_bytes_len_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 229) dma_unmap_single(dev, state->digest_bytes_len_dma_addr,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 230) HASH_MAX_LEN_SIZE, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 231) state->digest_bytes_len_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 232) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 233) unmap_digest_buf:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 234) if (state->digest_buff_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 235) dma_unmap_single(dev, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 236) ctx->inter_digestsize, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 237) state->digest_buff_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 238) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 239)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 240) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 241) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 242)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 243) static void cc_unmap_req(struct device *dev, struct ahash_req_ctx *state,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 244) struct cc_hash_ctx *ctx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 245) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 246) if (state->digest_buff_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 247) dma_unmap_single(dev, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 248) ctx->inter_digestsize, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 249) dev_dbg(dev, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 250) &state->digest_buff_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 251) state->digest_buff_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 252) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 253) if (state->digest_bytes_len_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 254) dma_unmap_single(dev, state->digest_bytes_len_dma_addr,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 255) HASH_MAX_LEN_SIZE, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 256) dev_dbg(dev, "Unmapped digest-bytes-len buffer: digest_bytes_len_dma_addr=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 257) &state->digest_bytes_len_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 258) state->digest_bytes_len_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 259) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 260) if (state->opad_digest_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 261) dma_unmap_single(dev, state->opad_digest_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 262) ctx->inter_digestsize, DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 263) dev_dbg(dev, "Unmapped opad-digest: opad_digest_dma_addr=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 264) &state->opad_digest_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 265) state->opad_digest_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 266) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 267) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 268)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 269) static void cc_unmap_result(struct device *dev, struct ahash_req_ctx *state,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 270) unsigned int digestsize, u8 *result)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 271) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 272) if (state->digest_result_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 273) dma_unmap_single(dev, state->digest_result_dma_addr, digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 274) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 275) dev_dbg(dev, "unmpa digest result buffer va (%pK) pa (%pad) len %u\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 276) state->digest_result_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 277) &state->digest_result_dma_addr, digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 278) memcpy(result, state->digest_result_buff, digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 279) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 280) state->digest_result_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 281) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 282)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 283) static void cc_update_complete(struct device *dev, void *cc_req, int err)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 284) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 285) struct ahash_request *req = (struct ahash_request *)cc_req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 286) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 287) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 288) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 289)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 290) dev_dbg(dev, "req=%pK\n", req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 291)
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 292) if (err != -EINPROGRESS) {
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 293) /* Not a BACKLOG notification */
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 294) cc_unmap_hash_request(dev, state, req->src, false);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 295) cc_unmap_req(dev, state, ctx);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 296) }
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 297)
151ded73a6c4c (Gilad Ben-Yossef 2019-04-18 16:38:47 +0300 298) ahash_request_complete(req, err);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 299) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 300)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 301) static void cc_digest_complete(struct device *dev, void *cc_req, int err)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 302) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 303) struct ahash_request *req = (struct ahash_request *)cc_req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 304) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 305) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 306) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 307) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 308)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 309) dev_dbg(dev, "req=%pK\n", req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 310)
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 311) if (err != -EINPROGRESS) {
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 312) /* Not a BACKLOG notification */
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 313) cc_unmap_hash_request(dev, state, req->src, false);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 314) cc_unmap_result(dev, state, digestsize, req->result);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 315) cc_unmap_req(dev, state, ctx);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 316) }
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 317)
151ded73a6c4c (Gilad Ben-Yossef 2019-04-18 16:38:47 +0300 318) ahash_request_complete(req, err);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 319) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 320)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 321) static void cc_hash_complete(struct device *dev, void *cc_req, int err)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 322) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 323) struct ahash_request *req = (struct ahash_request *)cc_req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 324) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 325) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 326) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 327) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 328)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 329) dev_dbg(dev, "req=%pK\n", req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 330)
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 331) if (err != -EINPROGRESS) {
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 332) /* Not a BACKLOG notification */
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 333) cc_unmap_hash_request(dev, state, req->src, false);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 334) cc_unmap_result(dev, state, digestsize, req->result);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 335) cc_unmap_req(dev, state, ctx);
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 336) }
a108f9311c012 (Gilad Ben-Yossef 2019-04-18 16:38:46 +0300 337)
151ded73a6c4c (Gilad Ben-Yossef 2019-04-18 16:38:47 +0300 338) ahash_request_complete(req, err);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 339) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 340)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 341) static int cc_fin_result(struct cc_hw_desc *desc, struct ahash_request *req,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 342) int idx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 343) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 344) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 345) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 346) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 347) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 348)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 349) /* Get final MAC result */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 350) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 351) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 352) set_dout_dlli(&desc[idx], state->digest_result_dma_addr, digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 353) NS_BIT, 1);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 354) set_queue_last_ind(ctx->drvdata, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 355) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 356) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 357) set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 358) cc_set_endianity(ctx->hash_mode, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 359) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 360)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 361) return idx;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 362) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 363)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 364) static int cc_fin_hmac(struct cc_hw_desc *desc, struct ahash_request *req,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 365) int idx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 366) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 367) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 368) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 369) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 370) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 371)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 372) /* store the hash digest result in the context */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 373) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 374) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 375) set_dout_dlli(&desc[idx], state->digest_buff_dma_addr, digestsize,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 376) NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 377) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 378) cc_set_endianity(ctx->hash_mode, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 379) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 380) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 381)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 382) /* Loading hash opad xor key state */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 383) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 384) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 385) set_din_type(&desc[idx], DMA_DLLI, state->opad_digest_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 386) ctx->inter_digestsize, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 387) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 388) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 389) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 390)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 391) /* Load the hash current length */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 392) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 393) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 394) set_din_sram(&desc[idx],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 395) cc_digest_len_addr(ctx->drvdata, ctx->hash_mode),
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 396) ctx->hash_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 397) set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 398) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 399) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 400) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 401)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 402) /* Memory Barrier: wait for IPAD/OPAD axi write to complete */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 403) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 404) set_din_no_dma(&desc[idx], 0, 0xfffff0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 405) set_dout_no_dma(&desc[idx], 0, 0, 1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 406) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 407)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 408) /* Perform HASH update */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 409) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 410) set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 411) digestsize, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 412) set_flow_mode(&desc[idx], DIN_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 413) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 414)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 415) return idx;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 416) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 417)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 418) static int cc_hash_digest(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 419) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 420) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 421) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 422) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 423) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 424) struct scatterlist *src = req->src;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 425) unsigned int nbytes = req->nbytes;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 426) u8 *result = req->result;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 427) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 428) bool is_hmac = ctx->is_hmac;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 429) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 430) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 431) u32 larval_digest_addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 432) int idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 433) int rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 434) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 435)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 436) dev_dbg(dev, "===== %s-digest (%d) ====\n", is_hmac ? "hmac" : "hash",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 437) nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 438)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 439) cc_init_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 440)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 441) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 442) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 443) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 444) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 445)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 446) if (cc_map_result(dev, state, digestsize)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 447) dev_err(dev, "map_ahash_digest() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 448) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 449) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 450) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 451)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 452) if (cc_map_hash_request_final(ctx->drvdata, state, src, nbytes, 1,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 453) flags)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 454) dev_err(dev, "map_ahash_request_final() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 455) cc_unmap_result(dev, state, digestsize, result);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 456) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 457) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 458) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 459)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 460) /* Setup request structure */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 461) cc_req.user_cb = cc_digest_complete;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 462) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 463)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 464) /* If HMAC then load hash IPAD xor key, if HASH then load initial
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 465) * digest
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 466) */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 467) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 468) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 469) if (is_hmac) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 470) set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 471) ctx->inter_digestsize, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 472) } else {
e431cc0438170 (Geert Uytterhoeven 2020-02-11 19:19:05 +0100 473) larval_digest_addr = cc_larval_digest_addr(ctx->drvdata,
e431cc0438170 (Geert Uytterhoeven 2020-02-11 19:19:05 +0100 474) ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 475) set_din_sram(&desc[idx], larval_digest_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 476) ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 477) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 478) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 479) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 480) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 481)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 482) /* Load the hash current length */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 483) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 484) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 485)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 486) if (is_hmac) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 487) set_din_type(&desc[idx], DMA_DLLI,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 488) state->digest_bytes_len_dma_addr,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 489) ctx->hash_len, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 490) } else {
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 491) set_din_const(&desc[idx], 0, ctx->hash_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 492) if (nbytes)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 493) set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 494) else
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 495) set_cipher_do(&desc[idx], DO_PAD);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 496) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 497) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 498) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 499) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 500)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 501) cc_set_desc(state, ctx, DIN_HASH, desc, false, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 502)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 503) if (is_hmac) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 504) /* HW last hash block padding (aka. "DO_PAD") */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 505) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 506) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 507) set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 508) ctx->hash_len, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 509) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 510) set_setup_mode(&desc[idx], SETUP_WRITE_STATE1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 511) set_cipher_do(&desc[idx], DO_PAD);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 512) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 513)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 514) idx = cc_fin_hmac(desc, req, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 515) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 516)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 517) idx = cc_fin_result(desc, req, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 518)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 519) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 520) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 521) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 522) cc_unmap_hash_request(dev, state, src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 523) cc_unmap_result(dev, state, digestsize, result);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 524) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 525) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 526) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 527) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 528)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 529) static int cc_restore_hash(struct cc_hw_desc *desc, struct cc_hash_ctx *ctx,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 530) struct ahash_req_ctx *state, unsigned int idx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 531) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 532) /* Restore hash digest */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 533) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 534) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 535) set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 536) ctx->inter_digestsize, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 537) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 538) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 539) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 540)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 541) /* Restore hash current length */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 542) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 543) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 544) set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 545) set_din_type(&desc[idx], DMA_DLLI, state->digest_bytes_len_dma_addr,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 546) ctx->hash_len, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 547) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 548) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 549) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 550)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 551) cc_set_desc(state, ctx, DIN_HASH, desc, false, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 552)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 553) return idx;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 554) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 555)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 556) static int cc_hash_update(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 557) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 558) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 559) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 560) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 561) unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 562) struct scatterlist *src = req->src;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 563) unsigned int nbytes = req->nbytes;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 564) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 565) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 566) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 567) u32 idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 568) int rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 569) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 570)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 571) dev_dbg(dev, "===== %s-update (%d) ====\n", ctx->is_hmac ?
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 572) "hmac" : "hash", nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 573)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 574) if (nbytes == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 575) /* no real updates required */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 576) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 577) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 578)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 579) rc = cc_map_hash_request_update(ctx->drvdata, state, src, nbytes,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 580) block_size, flags);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 581) if (rc) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 582) if (rc == 1) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 583) dev_dbg(dev, " data size not require HW update %x\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 584) nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 585) /* No hardware updates are required */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 586) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 587) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 588) dev_err(dev, "map_ahash_request_update() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 589) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 590) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 591)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 592) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 593) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 594) cc_unmap_hash_request(dev, state, src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 595) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 596) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 597)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 598) /* Setup request structure */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 599) cc_req.user_cb = cc_update_complete;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 600) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 601)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 602) idx = cc_restore_hash(desc, ctx, state, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 603)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 604) /* store the hash digest result in context */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 605) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 606) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 607) set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 608) ctx->inter_digestsize, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 609) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 610) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 611) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 612)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 613) /* store current hash length in context */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 614) hw_desc_init(&desc[idx]);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 615) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 616) set_dout_dlli(&desc[idx], state->digest_bytes_len_dma_addr,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 617) ctx->hash_len, NS_BIT, 1);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 618) set_queue_last_ind(ctx->drvdata, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 619) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 620) set_setup_mode(&desc[idx], SETUP_WRITE_STATE1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 621) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 622)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 623) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 624) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 625) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 626) cc_unmap_hash_request(dev, state, src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 627) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 628) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 629) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 630) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 631)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 632) static int cc_do_finup(struct ahash_request *req, bool update)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 633) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 634) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 635) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 636) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 637) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 638) struct scatterlist *src = req->src;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 639) unsigned int nbytes = req->nbytes;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 640) u8 *result = req->result;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 641) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 642) bool is_hmac = ctx->is_hmac;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 643) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 644) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 645) unsigned int idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 646) int rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 647) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 648)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 649) dev_dbg(dev, "===== %s-%s (%d) ====\n", is_hmac ? "hmac" : "hash",
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 650) update ? "finup" : "final", nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 651)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 652) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 653) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 654) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 655) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 656)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 657) if (cc_map_hash_request_final(ctx->drvdata, state, src, nbytes, update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 658) flags)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 659) dev_err(dev, "map_ahash_request_final() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 660) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 661) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 662) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 663) if (cc_map_result(dev, state, digestsize)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 664) dev_err(dev, "map_ahash_digest() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 665) cc_unmap_hash_request(dev, state, src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 666) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 667) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 668) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 669)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 670) /* Setup request structure */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 671) cc_req.user_cb = cc_hash_complete;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 672) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 673)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 674) idx = cc_restore_hash(desc, ctx, state, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 675)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 676) /* Pad the hash */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 677) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 678) set_cipher_do(&desc[idx], DO_PAD);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 679) set_hash_cipher_mode(&desc[idx], ctx->hw_mode, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 680) set_dout_dlli(&desc[idx], state->digest_bytes_len_dma_addr,
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 681) ctx->hash_len, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 682) set_setup_mode(&desc[idx], SETUP_WRITE_STATE1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 683) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 684) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 685)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 686) if (is_hmac)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 687) idx = cc_fin_hmac(desc, req, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 688)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 689) idx = cc_fin_result(desc, req, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 690)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 691) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 692) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 693) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 694) cc_unmap_hash_request(dev, state, src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 695) cc_unmap_result(dev, state, digestsize, result);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 696) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 697) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 698) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 699) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 700)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 701) static int cc_hash_finup(struct ahash_request *req)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 702) {
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 703) return cc_do_finup(req, true);
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 704) }
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 705)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 706)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 707) static int cc_hash_final(struct ahash_request *req)
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 708) {
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 709) return cc_do_finup(req, false);
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 710) }
26497e72a1aba (Hadar Gat 2018-07-01 08:02:34 +0100 711)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 712) static int cc_hash_init(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 713) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 714) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 715) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 716) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 717) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 718)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 719) dev_dbg(dev, "===== init (%d) ====\n", req->nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 720)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 721) cc_init_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 722)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 723) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 724) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 725)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 726) static int cc_hash_setkey(struct crypto_ahash *ahash, const u8 *key,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 727) unsigned int keylen)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 728) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 729) unsigned int hmac_pad_const[2] = { HMAC_IPAD_CONST, HMAC_OPAD_CONST };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 730) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 731) struct cc_hash_ctx *ctx = NULL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 732) int blocksize = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 733) int digestsize = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 734) int i, idx = 0, rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 735) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 736) u32 larval_addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 737) struct device *dev;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 738)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 739) ctx = crypto_ahash_ctx(ahash);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 740) dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 741) dev_dbg(dev, "start keylen: %d", keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 742)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 743) blocksize = crypto_tfm_alg_blocksize(&ahash->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 744) digestsize = crypto_ahash_digestsize(ahash);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 745)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 746) larval_addr = cc_larval_digest_addr(ctx->drvdata, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 747)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 748) /* The keylen value distinguishes HASH in case keylen is ZERO bytes,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 749) * any NON-ZERO value utilizes HMAC flow
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 750) */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 751) ctx->key_params.keylen = keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 752) ctx->key_params.key_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 753) ctx->is_hmac = true;
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 754) ctx->key_params.key = NULL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 755)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 756) if (keylen) {
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 757) ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL);
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 758) if (!ctx->key_params.key)
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 759) return -ENOMEM;
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 760)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 761) ctx->key_params.key_dma_addr =
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 762) dma_map_single(dev, ctx->key_params.key, keylen,
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 763) DMA_TO_DEVICE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 764) if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 765) dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 766) ctx->key_params.key, keylen);
453431a54934d (Waiman Long 2020-08-06 23:18:13 -0700 767) kfree_sensitive(ctx->key_params.key);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 768) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 769) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 770) dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 771) &ctx->key_params.key_dma_addr, ctx->key_params.keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 772)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 773) if (keylen > blocksize) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 774) /* Load hash initial state */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 775) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 776) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 777) set_din_sram(&desc[idx], larval_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 778) ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 779) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 780) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 781) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 782)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 783) /* Load the hash current length*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 784) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 785) set_cipher_mode(&desc[idx], ctx->hw_mode);
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 786) set_din_const(&desc[idx], 0, ctx->hash_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 787) set_cipher_config1(&desc[idx], HASH_PADDING_ENABLED);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 788) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 789) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 790) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 791)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 792) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 793) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 794) ctx->key_params.key_dma_addr, keylen,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 795) NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 796) set_flow_mode(&desc[idx], DIN_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 797) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 798)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 799) /* Get hashed key */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 800) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 801) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 802) set_dout_dlli(&desc[idx], ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 803) digestsize, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 804) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 805) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 806) set_cipher_config1(&desc[idx], HASH_PADDING_DISABLED);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 807) cc_set_endianity(ctx->hash_mode, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 808) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 809)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 810) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 811) set_din_const(&desc[idx], 0, (blocksize - digestsize));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 812) set_flow_mode(&desc[idx], BYPASS);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 813) set_dout_dlli(&desc[idx],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 814) (ctx->opad_tmp_keys_dma_addr +
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 815) digestsize),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 816) (blocksize - digestsize), NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 817) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 818) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 819) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 820) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 821) ctx->key_params.key_dma_addr, keylen,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 822) NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 823) set_flow_mode(&desc[idx], BYPASS);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 824) set_dout_dlli(&desc[idx], ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 825) keylen, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 826) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 827)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 828) if ((blocksize - keylen)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 829) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 830) set_din_const(&desc[idx], 0,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 831) (blocksize - keylen));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 832) set_flow_mode(&desc[idx], BYPASS);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 833) set_dout_dlli(&desc[idx],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 834) (ctx->opad_tmp_keys_dma_addr +
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 835) keylen), (blocksize - keylen),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 836) NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 837) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 838) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 839) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 840) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 841) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 842) set_din_const(&desc[idx], 0, blocksize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 843) set_flow_mode(&desc[idx], BYPASS);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 844) set_dout_dlli(&desc[idx], (ctx->opad_tmp_keys_dma_addr),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 845) blocksize, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 846) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 847) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 848)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 849) rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 850) if (rc) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 851) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 852) goto out;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 853) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 854)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 855) /* calc derived HMAC key */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 856) for (idx = 0, i = 0; i < 2; i++) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 857) /* Load hash initial state */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 858) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 859) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 860) set_din_sram(&desc[idx], larval_addr, ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 861) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 862) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 863) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 864)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 865) /* Load the hash current length*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 866) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 867) set_cipher_mode(&desc[idx], ctx->hw_mode);
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 868) set_din_const(&desc[idx], 0, ctx->hash_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 869) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 870) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 871) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 872)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 873) /* Prepare ipad key */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 874) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 875) set_xor_val(&desc[idx], hmac_pad_const[i]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 876) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 877) set_flow_mode(&desc[idx], S_DIN_to_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 878) set_setup_mode(&desc[idx], SETUP_LOAD_STATE1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 879) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 880)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 881) /* Perform HASH update */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 882) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 883) set_din_type(&desc[idx], DMA_DLLI, ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 884) blocksize, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 885) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 886) set_xor_active(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 887) set_flow_mode(&desc[idx], DIN_HASH);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 888) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 889)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 890) /* Get the IPAD/OPAD xor key (Note, IPAD is the initial digest
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 891) * of the first HASH "update" state)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 892) */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 893) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 894) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 895) if (i > 0) /* Not first iteration */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 896) set_dout_dlli(&desc[idx], ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 897) ctx->inter_digestsize, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 898) else /* First iteration */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 899) set_dout_dlli(&desc[idx], ctx->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 900) ctx->inter_digestsize, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 901) set_flow_mode(&desc[idx], S_HASH_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 902) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 903) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 904) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 905)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 906) rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 907)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 908) out:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 909) if (ctx->key_params.key_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 910) dma_unmap_single(dev, ctx->key_params.key_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 911) ctx->key_params.keylen, DMA_TO_DEVICE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 912) dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 913) &ctx->key_params.key_dma_addr, ctx->key_params.keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 914) }
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 915)
453431a54934d (Waiman Long 2020-08-06 23:18:13 -0700 916) kfree_sensitive(ctx->key_params.key);
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 917)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 918) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 919) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 920)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 921) static int cc_xcbc_setkey(struct crypto_ahash *ahash,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 922) const u8 *key, unsigned int keylen)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 923) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 924) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 925) struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 926) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 927) int rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 928) unsigned int idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 929) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 930)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 931) dev_dbg(dev, "===== setkey (%d) ====\n", keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 932)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 933) switch (keylen) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 934) case AES_KEYSIZE_128:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 935) case AES_KEYSIZE_192:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 936) case AES_KEYSIZE_256:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 937) break;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 938) default:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 939) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 940) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 941)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 942) ctx->key_params.keylen = keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 943)
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 944) ctx->key_params.key = kmemdup(key, keylen, GFP_KERNEL);
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 945) if (!ctx->key_params.key)
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 946) return -ENOMEM;
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 947)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 948) ctx->key_params.key_dma_addr =
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 949) dma_map_single(dev, ctx->key_params.key, keylen, DMA_TO_DEVICE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 950) if (dma_mapping_error(dev, ctx->key_params.key_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 951) dev_err(dev, "Mapping key va=0x%p len=%u for DMA failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 952) key, keylen);
453431a54934d (Waiman Long 2020-08-06 23:18:13 -0700 953) kfree_sensitive(ctx->key_params.key);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 954) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 955) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 956) dev_dbg(dev, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 957) &ctx->key_params.key_dma_addr, ctx->key_params.keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 958)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 959) ctx->is_hmac = true;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 960) /* 1. Load the AES key */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 961) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 962) set_din_type(&desc[idx], DMA_DLLI, ctx->key_params.key_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 963) keylen, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 964) set_cipher_mode(&desc[idx], DRV_CIPHER_ECB);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 965) set_cipher_config0(&desc[idx], DRV_CRYPTO_DIRECTION_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 966) set_key_size_aes(&desc[idx], keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 967) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 968) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 969) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 970)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 971) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 972) set_din_const(&desc[idx], 0x01010101, CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 973) set_flow_mode(&desc[idx], DIN_AES_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 974) set_dout_dlli(&desc[idx],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 975) (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K1_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 976) CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 977) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 978)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 979) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 980) set_din_const(&desc[idx], 0x02020202, CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 981) set_flow_mode(&desc[idx], DIN_AES_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 982) set_dout_dlli(&desc[idx],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 983) (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K2_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 984) CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 985) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 986)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 987) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 988) set_din_const(&desc[idx], 0x03030303, CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 989) set_flow_mode(&desc[idx], DIN_AES_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 990) set_dout_dlli(&desc[idx],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 991) (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K3_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 992) CC_AES_128_BIT_KEY_SIZE, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 993) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 994)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 995) rc = cc_send_sync_request(ctx->drvdata, &cc_req, desc, idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 996)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 997) dma_unmap_single(dev, ctx->key_params.key_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 998) ctx->key_params.keylen, DMA_TO_DEVICE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 999) dev_dbg(dev, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1000) &ctx->key_params.key_dma_addr, ctx->key_params.keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1001)
453431a54934d (Waiman Long 2020-08-06 23:18:13 -0700 1002) kfree_sensitive(ctx->key_params.key);
874e163759f27 (Gilad Ben-Yossef 2019-04-18 16:39:04 +0300 1003)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1004) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1005) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1006)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1007) static int cc_cmac_setkey(struct crypto_ahash *ahash,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1008) const u8 *key, unsigned int keylen)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1009) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1010) struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1011) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1012)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1013) dev_dbg(dev, "===== setkey (%d) ====\n", keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1014)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1015) ctx->is_hmac = true;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1016)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1017) switch (keylen) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1018) case AES_KEYSIZE_128:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1019) case AES_KEYSIZE_192:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1020) case AES_KEYSIZE_256:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1021) break;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1022) default:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1023) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1024) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1025)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1026) ctx->key_params.keylen = keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1027)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1028) /* STAT_PHASE_1: Copy key to ctx */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1029)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1030) dma_sync_single_for_cpu(dev, ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1031) keylen, DMA_TO_DEVICE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1032)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1033) memcpy(ctx->opad_tmp_keys_buff, key, keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1034) if (keylen == 24) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1035) memset(ctx->opad_tmp_keys_buff + 24, 0,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1036) CC_AES_KEY_SIZE_MAX - 24);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1037) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1038)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1039) dma_sync_single_for_device(dev, ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1040) keylen, DMA_TO_DEVICE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1041)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1042) ctx->key_params.keylen = keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1043)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1044) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1045) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1046)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1047) static void cc_free_ctx(struct cc_hash_ctx *ctx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1048) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1049) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1050)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1051) if (ctx->digest_buff_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1052) dma_unmap_single(dev, ctx->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1053) sizeof(ctx->digest_buff), DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1054) dev_dbg(dev, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1055) &ctx->digest_buff_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1056) ctx->digest_buff_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1057) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1058) if (ctx->opad_tmp_keys_dma_addr) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1059) dma_unmap_single(dev, ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1060) sizeof(ctx->opad_tmp_keys_buff),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1061) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1062) dev_dbg(dev, "Unmapped opad-digest: opad_tmp_keys_dma_addr=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1063) &ctx->opad_tmp_keys_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1064) ctx->opad_tmp_keys_dma_addr = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1065) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1066)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1067) ctx->key_params.keylen = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1068) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1069)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1070) static int cc_alloc_ctx(struct cc_hash_ctx *ctx)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1071) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1072) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1073)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1074) ctx->key_params.keylen = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1075)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1076) ctx->digest_buff_dma_addr =
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1077) dma_map_single(dev, ctx->digest_buff, sizeof(ctx->digest_buff),
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1078) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1079) if (dma_mapping_error(dev, ctx->digest_buff_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1080) dev_err(dev, "Mapping digest len %zu B at va=%pK for DMA failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1081) sizeof(ctx->digest_buff), ctx->digest_buff);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1082) goto fail;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1083) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1084) dev_dbg(dev, "Mapped digest %zu B at va=%pK to dma=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1085) sizeof(ctx->digest_buff), ctx->digest_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1086) &ctx->digest_buff_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1087)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1088) ctx->opad_tmp_keys_dma_addr =
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1089) dma_map_single(dev, ctx->opad_tmp_keys_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1090) sizeof(ctx->opad_tmp_keys_buff),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1091) DMA_BIDIRECTIONAL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1092) if (dma_mapping_error(dev, ctx->opad_tmp_keys_dma_addr)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1093) dev_err(dev, "Mapping opad digest %zu B at va=%pK for DMA failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1094) sizeof(ctx->opad_tmp_keys_buff),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1095) ctx->opad_tmp_keys_buff);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1096) goto fail;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1097) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1098) dev_dbg(dev, "Mapped opad_tmp_keys %zu B at va=%pK to dma=%pad\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1099) sizeof(ctx->opad_tmp_keys_buff), ctx->opad_tmp_keys_buff,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1100) &ctx->opad_tmp_keys_dma_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1101)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1102) ctx->is_hmac = false;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1103) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1104)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1105) fail:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1106) cc_free_ctx(ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1107) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1108) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1109)
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1110) static int cc_get_hash_len(struct crypto_tfm *tfm)
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1111) {
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1112) struct cc_hash_ctx *ctx = crypto_tfm_ctx(tfm);
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1113)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1114) if (ctx->hash_mode == DRV_HASH_SM3)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1115) return CC_SM3_HASH_LEN_SIZE;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1116) else
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1117) return cc_get_default_hash_len(ctx->drvdata);
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1118) }
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1119)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1120) static int cc_cra_init(struct crypto_tfm *tfm)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1121) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1122) struct cc_hash_ctx *ctx = crypto_tfm_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1123) struct hash_alg_common *hash_alg_common =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1124) container_of(tfm->__crt_alg, struct hash_alg_common, base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1125) struct ahash_alg *ahash_alg =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1126) container_of(hash_alg_common, struct ahash_alg, halg);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1127) struct cc_hash_alg *cc_alg =
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1128) container_of(ahash_alg, struct cc_hash_alg, ahash_alg);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1129)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1130) crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1131) sizeof(struct ahash_req_ctx));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1132)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1133) ctx->hash_mode = cc_alg->hash_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1134) ctx->hw_mode = cc_alg->hw_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1135) ctx->inter_digestsize = cc_alg->inter_digestsize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1136) ctx->drvdata = cc_alg->drvdata;
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1137) ctx->hash_len = cc_get_hash_len(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1138) return cc_alloc_ctx(ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1139) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1140)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1141) static void cc_cra_exit(struct crypto_tfm *tfm)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1142) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1143) struct cc_hash_ctx *ctx = crypto_tfm_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1144) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1145)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1146) dev_dbg(dev, "cc_cra_exit");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1147) cc_free_ctx(ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1148) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1149)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1150) static int cc_mac_update(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1151) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1152) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1153) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1154) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1155) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1156) unsigned int block_size = crypto_tfm_alg_blocksize(&tfm->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1157) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1158) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1159) int rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1160) u32 idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1161) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1162)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1163) if (req->nbytes == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1164) /* no real updates required */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1165) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1166) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1167)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1168) state->xcbc_count++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1169)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1170) rc = cc_map_hash_request_update(ctx->drvdata, state, req->src,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1171) req->nbytes, block_size, flags);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1172) if (rc) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1173) if (rc == 1) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1174) dev_dbg(dev, " data size not require HW update %x\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1175) req->nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1176) /* No hardware updates are required */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1177) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1178) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1179) dev_err(dev, "map_ahash_request_update() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1180) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1181) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1182)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1183) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1184) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1185) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1186) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1187)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1188) if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1189) cc_setup_xcbc(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1190) else
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1191) cc_setup_cmac(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1192)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1193) cc_set_desc(state, ctx, DIN_AES_DOUT, desc, true, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1194)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1195) /* store the hash digest result in context */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1196) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1197) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1198) set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1199) ctx->inter_digestsize, NS_BIT, 1);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1200) set_queue_last_ind(ctx->drvdata, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1201) set_flow_mode(&desc[idx], S_AES_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1202) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1203) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1204)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1205) /* Setup request structure */
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1206) cc_req.user_cb = cc_update_complete;
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1207) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1208)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1209) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1210) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1211) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1212) cc_unmap_hash_request(dev, state, req->src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1213) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1214) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1215) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1216) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1217)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1218) static int cc_mac_final(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1219) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1220) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1221) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1222) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1223) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1224) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1225) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1226) int idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1227) int rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1228) u32 key_size, key_len;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1229) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1230) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1231) u32 rem_cnt = *cc_hash_buf_cnt(state);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1232)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1233) if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1234) key_size = CC_AES_128_BIT_KEY_SIZE;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1235) key_len = CC_AES_128_BIT_KEY_SIZE;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1236) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1237) key_size = (ctx->key_params.keylen == 24) ? AES_MAX_KEY_SIZE :
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1238) ctx->key_params.keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1239) key_len = ctx->key_params.keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1240) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1241)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1242) dev_dbg(dev, "===== final xcbc reminder (%d) ====\n", rem_cnt);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1243)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1244) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1245) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1246) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1247) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1248)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1249) if (cc_map_hash_request_final(ctx->drvdata, state, req->src,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1250) req->nbytes, 0, flags)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1251) dev_err(dev, "map_ahash_request_final() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1252) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1253) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1254) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1255)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1256) if (cc_map_result(dev, state, digestsize)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1257) dev_err(dev, "map_ahash_digest() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1258) cc_unmap_hash_request(dev, state, req->src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1259) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1260) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1261) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1262)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1263) /* Setup request structure */
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1264) cc_req.user_cb = cc_hash_complete;
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1265) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1266)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1267) if (state->xcbc_count && rem_cnt == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1268) /* Load key for ECB decryption */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1269) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1270) set_cipher_mode(&desc[idx], DRV_CIPHER_ECB);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1271) set_cipher_config0(&desc[idx], DRV_CRYPTO_DIRECTION_DECRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1272) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1273) (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K1_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1274) key_size, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1275) set_key_size_aes(&desc[idx], key_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1276) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1277) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1278) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1279)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1280) /* Initiate decryption of block state to previous
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1281) * block_state-XOR-M[n]
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1282) */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1283) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1284) set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1285) CC_AES_BLOCK_SIZE, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1286) set_dout_dlli(&desc[idx], state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1287) CC_AES_BLOCK_SIZE, NS_BIT, 0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1288) set_flow_mode(&desc[idx], DIN_AES_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1289) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1290)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1291) /* Memory Barrier: wait for axi write to complete */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1292) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1293) set_din_no_dma(&desc[idx], 0, 0xfffff0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1294) set_dout_no_dma(&desc[idx], 0, 0, 1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1295) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1296) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1297)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1298) if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1299) cc_setup_xcbc(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1300) else
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1301) cc_setup_cmac(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1302)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1303) if (state->xcbc_count == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1304) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1305) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1306) set_key_size_aes(&desc[idx], key_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1307) set_cmac_size0_mode(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1308) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1309) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1310) } else if (rem_cnt > 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1311) cc_set_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1312) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1313) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1314) set_din_const(&desc[idx], 0x00, CC_AES_BLOCK_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1315) set_flow_mode(&desc[idx], DIN_AES_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1316) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1317) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1318)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1319) /* Get final MAC result */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1320) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1321) set_dout_dlli(&desc[idx], state->digest_result_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1322) digestsize, NS_BIT, 1);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1323) set_queue_last_ind(ctx->drvdata, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1324) set_flow_mode(&desc[idx], S_AES_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1325) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1326) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1327) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1328)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1329) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1330) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1331) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1332) cc_unmap_hash_request(dev, state, req->src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1333) cc_unmap_result(dev, state, digestsize, req->result);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1334) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1335) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1336) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1337) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1338)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1339) static int cc_mac_finup(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1340) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1341) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1342) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1343) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1344) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1345) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1346) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1347) int idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1348) int rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1349) u32 key_len = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1350) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1351) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1352)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1353) dev_dbg(dev, "===== finup xcbc(%d) ====\n", req->nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1354) if (state->xcbc_count > 0 && req->nbytes == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1355) dev_dbg(dev, "No data to update. Call to fdx_mac_final\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1356) return cc_mac_final(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1357) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1358)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1359) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1360) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1361) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1362) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1363)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1364) if (cc_map_hash_request_final(ctx->drvdata, state, req->src,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1365) req->nbytes, 1, flags)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1366) dev_err(dev, "map_ahash_request_final() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1367) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1368) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1369) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1370) if (cc_map_result(dev, state, digestsize)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1371) dev_err(dev, "map_ahash_digest() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1372) cc_unmap_hash_request(dev, state, req->src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1373) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1374) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1375) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1376)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1377) /* Setup request structure */
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1378) cc_req.user_cb = cc_hash_complete;
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1379) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1380)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1381) if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1382) key_len = CC_AES_128_BIT_KEY_SIZE;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1383) cc_setup_xcbc(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1384) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1385) key_len = ctx->key_params.keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1386) cc_setup_cmac(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1387) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1388)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1389) if (req->nbytes == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1390) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1391) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1392) set_key_size_aes(&desc[idx], key_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1393) set_cmac_size0_mode(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1394) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1395) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1396) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1397) cc_set_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1398) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1399)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1400) /* Get final MAC result */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1401) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1402) set_dout_dlli(&desc[idx], state->digest_result_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1403) digestsize, NS_BIT, 1);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1404) set_queue_last_ind(ctx->drvdata, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1405) set_flow_mode(&desc[idx], S_AES_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1406) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1407) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1408) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1409)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1410) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1411) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1412) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1413) cc_unmap_hash_request(dev, state, req->src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1414) cc_unmap_result(dev, state, digestsize, req->result);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1415) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1416) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1417) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1418) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1419)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1420) static int cc_mac_digest(struct ahash_request *req)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1421) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1422) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1423) struct crypto_ahash *tfm = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1424) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1425) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1426) u32 digestsize = crypto_ahash_digestsize(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1427) struct cc_crypto_req cc_req = {};
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1428) struct cc_hw_desc desc[CC_MAX_HASH_SEQ_LEN];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1429) u32 key_len;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1430) unsigned int idx = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1431) int rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1432) gfp_t flags = cc_gfp_flags(&req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1433)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1434) dev_dbg(dev, "===== -digest mac (%d) ====\n", req->nbytes);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1435)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1436) cc_init_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1437)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1438) if (cc_map_req(dev, state, ctx)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1439) dev_err(dev, "map_ahash_source() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1440) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1441) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1442) if (cc_map_result(dev, state, digestsize)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1443) dev_err(dev, "map_ahash_digest() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1444) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1445) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1446) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1447)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1448) if (cc_map_hash_request_final(ctx->drvdata, state, req->src,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1449) req->nbytes, 1, flags)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1450) dev_err(dev, "map_ahash_request_final() failed\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1451) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1452) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1453) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1454)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1455) /* Setup request structure */
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1456) cc_req.user_cb = cc_digest_complete;
f4274eeca4763 (Geert Uytterhoeven 2020-02-11 19:18:58 +0100 1457) cc_req.user_arg = req;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1458)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1459) if (ctx->hw_mode == DRV_CIPHER_XCBC_MAC) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1460) key_len = CC_AES_128_BIT_KEY_SIZE;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1461) cc_setup_xcbc(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1462) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1463) key_len = ctx->key_params.keylen;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1464) cc_setup_cmac(req, desc, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1465) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1466)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1467) if (req->nbytes == 0) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1468) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1469) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1470) set_key_size_aes(&desc[idx], key_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1471) set_cmac_size0_mode(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1472) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1473) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1474) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1475) cc_set_desc(state, ctx, DIN_AES_DOUT, desc, false, &idx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1476) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1477)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1478) /* Get final MAC result */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1479) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1480) set_dout_dlli(&desc[idx], state->digest_result_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1481) CC_AES_BLOCK_SIZE, NS_BIT, 1);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1482) set_queue_last_ind(ctx->drvdata, &desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1483) set_flow_mode(&desc[idx], S_AES_to_DOUT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1484) set_setup_mode(&desc[idx], SETUP_WRITE_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1485) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1486) set_cipher_mode(&desc[idx], ctx->hw_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1487) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1488)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1489) rc = cc_send_request(ctx->drvdata, &cc_req, desc, idx, &req->base);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1490) if (rc != -EINPROGRESS && rc != -EBUSY) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1491) dev_err(dev, "send_request() failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1492) cc_unmap_hash_request(dev, state, req->src, true);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1493) cc_unmap_result(dev, state, digestsize, req->result);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1494) cc_unmap_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1495) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1496) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1497) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1498)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1499) static int cc_hash_export(struct ahash_request *req, void *out)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1500) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1501) struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1502) struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1503) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1504) u8 *curr_buff = cc_hash_buf(state);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1505) u32 curr_buff_cnt = *cc_hash_buf_cnt(state);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1506) const u32 tmp = CC_EXPORT_MAGIC;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1507)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1508) memcpy(out, &tmp, sizeof(u32));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1509) out += sizeof(u32);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1510)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1511) memcpy(out, state->digest_buff, ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1512) out += ctx->inter_digestsize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1513)
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1514) memcpy(out, state->digest_bytes_len, ctx->hash_len);
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1515) out += ctx->hash_len;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1516)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1517) memcpy(out, &curr_buff_cnt, sizeof(u32));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1518) out += sizeof(u32);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1519)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1520) memcpy(out, curr_buff, curr_buff_cnt);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1521)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1522) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1523) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1524)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1525) static int cc_hash_import(struct ahash_request *req, const void *in)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1526) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1527) struct crypto_ahash *ahash = crypto_ahash_reqtfm(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1528) struct cc_hash_ctx *ctx = crypto_ahash_ctx(ahash);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1529) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1530) struct ahash_req_ctx *state = ahash_request_ctx(req);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1531) u32 tmp;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1532)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1533) memcpy(&tmp, in, sizeof(u32));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1534) if (tmp != CC_EXPORT_MAGIC)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1535) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1536) in += sizeof(u32);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1537)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1538) cc_init_req(dev, state, ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1539)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1540) memcpy(state->digest_buff, in, ctx->inter_digestsize);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1541) in += ctx->inter_digestsize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1542)
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1543) memcpy(state->digest_bytes_len, in, ctx->hash_len);
f1e52fd0fbd67 (Yael Chemla 2018-10-18 13:59:57 +0100 1544) in += ctx->hash_len;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1545)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1546) /* Sanity check the data as much as possible */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1547) memcpy(&tmp, in, sizeof(u32));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1548) if (tmp > CC_MAX_HASH_BLCK_SIZE)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1549) return -EINVAL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1550) in += sizeof(u32);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1551)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1552) state->buf_cnt[0] = tmp;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1553) memcpy(state->buffers[0], in, tmp);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1554)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1555) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1556) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1557)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1558) struct cc_hash_template {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1559) char name[CRYPTO_MAX_ALG_NAME];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1560) char driver_name[CRYPTO_MAX_ALG_NAME];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1561) char mac_name[CRYPTO_MAX_ALG_NAME];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1562) char mac_driver_name[CRYPTO_MAX_ALG_NAME];
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1563) unsigned int blocksize;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1564) bool is_mac;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1565) bool synchronize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1566) struct ahash_alg template_ahash;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1567) int hash_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1568) int hw_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1569) int inter_digestsize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1570) struct cc_drvdata *drvdata;
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1571) u32 min_hw_rev;
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1572) enum cc_std_body std_body;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1573) };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1574)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1575) #define CC_STATE_SIZE(_x) \
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1576) ((_x) + HASH_MAX_LEN_SIZE + CC_MAX_HASH_BLCK_SIZE + (2 * sizeof(u32)))
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1577)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1578) /* hash descriptors */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1579) static struct cc_hash_template driver_hash[] = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1580) //Asynchronize hash template
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1581) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1582) .name = "sha1",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1583) .driver_name = "sha1-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1584) .mac_name = "hmac(sha1)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1585) .mac_driver_name = "hmac-sha1-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1586) .blocksize = SHA1_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1587) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1588) .synchronize = false,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1589) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1590) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1591) .update = cc_hash_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1592) .final = cc_hash_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1593) .finup = cc_hash_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1594) .digest = cc_hash_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1595) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1596) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1597) .setkey = cc_hash_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1598) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1599) .digestsize = SHA1_DIGEST_SIZE,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1600) .statesize = CC_STATE_SIZE(SHA1_DIGEST_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1601) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1602) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1603) .hash_mode = DRV_HASH_SHA1,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1604) .hw_mode = DRV_HASH_HW_SHA1,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1605) .inter_digestsize = SHA1_DIGEST_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1606) .min_hw_rev = CC_HW_REV_630,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1607) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1608) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1609) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1610) .name = "sha256",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1611) .driver_name = "sha256-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1612) .mac_name = "hmac(sha256)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1613) .mac_driver_name = "hmac-sha256-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1614) .blocksize = SHA256_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1615) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1616) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1617) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1618) .update = cc_hash_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1619) .final = cc_hash_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1620) .finup = cc_hash_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1621) .digest = cc_hash_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1622) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1623) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1624) .setkey = cc_hash_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1625) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1626) .digestsize = SHA256_DIGEST_SIZE,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1627) .statesize = CC_STATE_SIZE(SHA256_DIGEST_SIZE)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1628) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1629) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1630) .hash_mode = DRV_HASH_SHA256,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1631) .hw_mode = DRV_HASH_HW_SHA256,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1632) .inter_digestsize = SHA256_DIGEST_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1633) .min_hw_rev = CC_HW_REV_630,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1634) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1635) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1636) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1637) .name = "sha224",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1638) .driver_name = "sha224-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1639) .mac_name = "hmac(sha224)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1640) .mac_driver_name = "hmac-sha224-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1641) .blocksize = SHA224_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1642) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1643) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1644) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1645) .update = cc_hash_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1646) .final = cc_hash_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1647) .finup = cc_hash_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1648) .digest = cc_hash_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1649) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1650) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1651) .setkey = cc_hash_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1652) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1653) .digestsize = SHA224_DIGEST_SIZE,
f3df82b468f00 (Gilad Ben-Yossef 2019-04-18 16:39:02 +0300 1654) .statesize = CC_STATE_SIZE(SHA256_DIGEST_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1655) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1656) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1657) .hash_mode = DRV_HASH_SHA224,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1658) .hw_mode = DRV_HASH_HW_SHA256,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1659) .inter_digestsize = SHA256_DIGEST_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1660) .min_hw_rev = CC_HW_REV_630,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1661) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1662) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1663) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1664) .name = "sha384",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1665) .driver_name = "sha384-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1666) .mac_name = "hmac(sha384)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1667) .mac_driver_name = "hmac-sha384-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1668) .blocksize = SHA384_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1669) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1670) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1671) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1672) .update = cc_hash_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1673) .final = cc_hash_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1674) .finup = cc_hash_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1675) .digest = cc_hash_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1676) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1677) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1678) .setkey = cc_hash_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1679) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1680) .digestsize = SHA384_DIGEST_SIZE,
f3df82b468f00 (Gilad Ben-Yossef 2019-04-18 16:39:02 +0300 1681) .statesize = CC_STATE_SIZE(SHA512_DIGEST_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1682) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1683) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1684) .hash_mode = DRV_HASH_SHA384,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1685) .hw_mode = DRV_HASH_HW_SHA512,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1686) .inter_digestsize = SHA512_DIGEST_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1687) .min_hw_rev = CC_HW_REV_712,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1688) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1689) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1690) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1691) .name = "sha512",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1692) .driver_name = "sha512-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1693) .mac_name = "hmac(sha512)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1694) .mac_driver_name = "hmac-sha512-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1695) .blocksize = SHA512_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1696) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1697) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1698) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1699) .update = cc_hash_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1700) .final = cc_hash_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1701) .finup = cc_hash_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1702) .digest = cc_hash_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1703) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1704) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1705) .setkey = cc_hash_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1706) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1707) .digestsize = SHA512_DIGEST_SIZE,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1708) .statesize = CC_STATE_SIZE(SHA512_DIGEST_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1709) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1710) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1711) .hash_mode = DRV_HASH_SHA512,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1712) .hw_mode = DRV_HASH_HW_SHA512,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1713) .inter_digestsize = SHA512_DIGEST_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1714) .min_hw_rev = CC_HW_REV_712,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1715) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1716) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1717) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1718) .name = "md5",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1719) .driver_name = "md5-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1720) .mac_name = "hmac(md5)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1721) .mac_driver_name = "hmac-md5-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1722) .blocksize = MD5_HMAC_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1723) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1724) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1725) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1726) .update = cc_hash_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1727) .final = cc_hash_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1728) .finup = cc_hash_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1729) .digest = cc_hash_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1730) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1731) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1732) .setkey = cc_hash_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1733) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1734) .digestsize = MD5_DIGEST_SIZE,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1735) .statesize = CC_STATE_SIZE(MD5_DIGEST_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1736) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1737) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1738) .hash_mode = DRV_HASH_MD5,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1739) .hw_mode = DRV_HASH_HW_MD5,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1740) .inter_digestsize = MD5_DIGEST_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1741) .min_hw_rev = CC_HW_REV_630,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1742) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1743) },
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1744) {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1745) .name = "sm3",
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1746) .driver_name = "sm3-ccree",
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1747) .blocksize = SM3_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1748) .is_mac = false,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1749) .template_ahash = {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1750) .init = cc_hash_init,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1751) .update = cc_hash_update,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1752) .final = cc_hash_final,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1753) .finup = cc_hash_finup,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1754) .digest = cc_hash_digest,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1755) .export = cc_hash_export,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1756) .import = cc_hash_import,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1757) .setkey = cc_hash_setkey,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1758) .halg = {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1759) .digestsize = SM3_DIGEST_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1760) .statesize = CC_STATE_SIZE(SM3_DIGEST_SIZE),
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1761) },
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1762) },
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1763) .hash_mode = DRV_HASH_SM3,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1764) .hw_mode = DRV_HASH_HW_SM3,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1765) .inter_digestsize = SM3_DIGEST_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1766) .min_hw_rev = CC_HW_REV_713,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1767) .std_body = CC_STD_OSCCA,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1768) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1769) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1770) .mac_name = "xcbc(aes)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1771) .mac_driver_name = "xcbc-aes-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1772) .blocksize = AES_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1773) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1774) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1775) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1776) .update = cc_mac_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1777) .final = cc_mac_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1778) .finup = cc_mac_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1779) .digest = cc_mac_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1780) .setkey = cc_xcbc_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1781) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1782) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1783) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1784) .digestsize = AES_BLOCK_SIZE,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1785) .statesize = CC_STATE_SIZE(AES_BLOCK_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1786) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1787) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1788) .hash_mode = DRV_HASH_NULL,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1789) .hw_mode = DRV_CIPHER_XCBC_MAC,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1790) .inter_digestsize = AES_BLOCK_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1791) .min_hw_rev = CC_HW_REV_630,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1792) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1793) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1794) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1795) .mac_name = "cmac(aes)",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1796) .mac_driver_name = "cmac-aes-ccree",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1797) .blocksize = AES_BLOCK_SIZE,
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1798) .is_mac = true,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1799) .template_ahash = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1800) .init = cc_hash_init,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1801) .update = cc_mac_update,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1802) .final = cc_mac_final,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1803) .finup = cc_mac_finup,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1804) .digest = cc_mac_digest,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1805) .setkey = cc_cmac_setkey,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1806) .export = cc_hash_export,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1807) .import = cc_hash_import,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1808) .halg = {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1809) .digestsize = AES_BLOCK_SIZE,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1810) .statesize = CC_STATE_SIZE(AES_BLOCK_SIZE),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1811) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1812) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1813) .hash_mode = DRV_HASH_NULL,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1814) .hw_mode = DRV_CIPHER_CMAC,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1815) .inter_digestsize = AES_BLOCK_SIZE,
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1816) .min_hw_rev = CC_HW_REV_630,
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 1817) .std_body = CC_STD_NIST,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1818) },
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1819) };
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1820)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1821) static struct cc_hash_alg *cc_alloc_hash_alg(struct cc_hash_template *template,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1822) struct device *dev, bool keyed)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1823) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1824) struct cc_hash_alg *t_crypto_alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1825) struct crypto_alg *alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1826) struct ahash_alg *halg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1827)
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 1828) t_crypto_alg = devm_kzalloc(dev, sizeof(*t_crypto_alg), GFP_KERNEL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1829) if (!t_crypto_alg)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1830) return ERR_PTR(-ENOMEM);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1831)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1832) t_crypto_alg->ahash_alg = template->template_ahash;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1833) halg = &t_crypto_alg->ahash_alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1834) alg = &halg->halg.base;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1835)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1836) if (keyed) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1837) snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1838) template->mac_name);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1839) snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1840) template->mac_driver_name);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1841) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1842) halg->setkey = NULL;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1843) snprintf(alg->cra_name, CRYPTO_MAX_ALG_NAME, "%s",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1844) template->name);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1845) snprintf(alg->cra_driver_name, CRYPTO_MAX_ALG_NAME, "%s",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1846) template->driver_name);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1847) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1848) alg->cra_module = THIS_MODULE;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1849) alg->cra_ctxsize = sizeof(struct cc_hash_ctx);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1850) alg->cra_priority = CC_CRA_PRIO;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1851) alg->cra_blocksize = template->blocksize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1852) alg->cra_alignmask = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1853) alg->cra_exit = cc_cra_exit;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1854)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1855) alg->cra_init = cc_cra_init;
6a38f62245c9d (Eric Biggers 2018-06-30 15:16:12 -0700 1856) alg->cra_flags = CRYPTO_ALG_ASYNC | CRYPTO_ALG_KERN_DRIVER_ONLY;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1857)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1858) t_crypto_alg->hash_mode = template->hash_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1859) t_crypto_alg->hw_mode = template->hw_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1860) t_crypto_alg->inter_digestsize = template->inter_digestsize;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1861)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1862) return t_crypto_alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1863) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1864)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1865) static int cc_init_copy_sram(struct cc_drvdata *drvdata, const u32 *data,
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1866) unsigned int size, u32 *sram_buff_ofs)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1867) {
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1868) struct cc_hw_desc larval_seq[CC_DIGEST_SIZE_MAX / sizeof(u32)];
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1869) unsigned int larval_seq_len = 0;
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1870) int rc;
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1871)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1872) cc_set_sram_desc(data, *sram_buff_ofs, size / sizeof(*data),
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1873) larval_seq, &larval_seq_len);
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1874) rc = send_request_init(drvdata, larval_seq, larval_seq_len);
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1875) if (rc)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1876) return rc;
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1877)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1878) *sram_buff_ofs += size;
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1879) return 0;
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1880) }
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1881)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1882) int cc_init_hash_sram(struct cc_drvdata *drvdata)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1883) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1884) struct cc_hash_handle *hash_handle = drvdata->hash_handle;
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 1885) u32 sram_buff_ofs = hash_handle->digest_len_sram_addr;
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1886) bool large_sha_supported = (drvdata->hw_rev >= CC_HW_REV_712);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1887) bool sm3_supported = (drvdata->hw_rev >= CC_HW_REV_713);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1888) int rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1889)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1890) /* Copy-to-sram digest-len */
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1891) rc = cc_init_copy_sram(drvdata, cc_digest_len_init,
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1892) sizeof(cc_digest_len_init), &sram_buff_ofs);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1893) if (rc)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1894) goto init_digest_const_err;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1895)
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1896) if (large_sha_supported) {
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1897) /* Copy-to-sram digest-len for sha384/512 */
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1898) rc = cc_init_copy_sram(drvdata, cc_digest_len_sha512_init,
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1899) sizeof(cc_digest_len_sha512_init),
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1900) &sram_buff_ofs);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1901) if (rc)
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1902) goto init_digest_const_err;
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1903) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1904)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1905) /* The initial digests offset */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1906) hash_handle->larval_digest_sram_addr = sram_buff_ofs;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1907)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1908) /* Copy-to-sram initial SHA* digests */
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1909) rc = cc_init_copy_sram(drvdata, cc_md5_init, sizeof(cc_md5_init),
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1910) &sram_buff_ofs);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1911) if (rc)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1912) goto init_digest_const_err;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1913)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1914) rc = cc_init_copy_sram(drvdata, cc_sha1_init, sizeof(cc_sha1_init),
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1915) &sram_buff_ofs);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1916) if (rc)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1917) goto init_digest_const_err;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1918)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1919) rc = cc_init_copy_sram(drvdata, cc_sha224_init, sizeof(cc_sha224_init),
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1920) &sram_buff_ofs);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1921) if (rc)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1922) goto init_digest_const_err;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1923)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1924) rc = cc_init_copy_sram(drvdata, cc_sha256_init, sizeof(cc_sha256_init),
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1925) &sram_buff_ofs);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1926) if (rc)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1927) goto init_digest_const_err;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1928)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1929) if (sm3_supported) {
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1930) rc = cc_init_copy_sram(drvdata, cc_sm3_init,
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1931) sizeof(cc_sm3_init), &sram_buff_ofs);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1932) if (rc)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1933) goto init_digest_const_err;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1934) }
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1935)
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1936) if (large_sha_supported) {
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1937) rc = cc_init_copy_sram(drvdata, cc_sha384_init,
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1938) sizeof(cc_sha384_init), &sram_buff_ofs);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1939) if (rc)
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1940) goto init_digest_const_err;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1941)
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1942) rc = cc_init_copy_sram(drvdata, cc_sha512_init,
08884316bb15e (Geert Uytterhoeven 2020-02-11 19:19:16 +0100 1943) sizeof(cc_sha512_init), &sram_buff_ofs);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1944) if (rc)
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1945) goto init_digest_const_err;
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1946) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1947)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1948) init_digest_const_err:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1949) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1950) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1951)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1952) int cc_hash_alloc(struct cc_drvdata *drvdata)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1953) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1954) struct cc_hash_handle *hash_handle;
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 1955) u32 sram_buff;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1956) u32 sram_size_to_alloc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1957) struct device *dev = drvdata_to_dev(drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1958) int rc = 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1959) int alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1960)
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 1961) hash_handle = devm_kzalloc(dev, sizeof(*hash_handle), GFP_KERNEL);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1962) if (!hash_handle)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1963) return -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1964)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1965) INIT_LIST_HEAD(&hash_handle->hash_list);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1966) drvdata->hash_handle = hash_handle;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1967)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1968) sram_size_to_alloc = sizeof(cc_digest_len_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1969) sizeof(cc_md5_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1970) sizeof(cc_sha1_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1971) sizeof(cc_sha224_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1972) sizeof(cc_sha256_init);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1973)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1974) if (drvdata->hw_rev >= CC_HW_REV_713)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1975) sram_size_to_alloc += sizeof(cc_sm3_init);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 1976)
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1977) if (drvdata->hw_rev >= CC_HW_REV_712)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1978) sram_size_to_alloc += sizeof(cc_digest_len_sha512_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 1979) sizeof(cc_sha384_init) + sizeof(cc_sha512_init);
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 1980)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1981) sram_buff = cc_sram_alloc(drvdata, sram_size_to_alloc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1982) if (sram_buff == NULL_SRAM_ADDR) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1983) rc = -ENOMEM;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1984) goto fail;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1985) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1986)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1987) /* The initial digest-len offset */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1988) hash_handle->digest_len_sram_addr = sram_buff;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1989)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1990) /*must be set before the alg registration as it is being used there*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1991) rc = cc_init_hash_sram(drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1992) if (rc) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1993) dev_err(dev, "Init digest CONST failed (rc=%d)\n", rc);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1994) goto fail;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1995) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1996)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1997) /* ahash registration */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1998) for (alg = 0; alg < ARRAY_SIZE(driver_hash); alg++) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 1999) struct cc_hash_alg *t_alg;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2000) int hw_mode = driver_hash[alg].hw_mode;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2001)
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 2002) /* Check that the HW revision and variants are suitable */
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 2003) if ((driver_hash[alg].min_hw_rev > drvdata->hw_rev) ||
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 2004) !(drvdata->std_bodies & driver_hash[alg].std_body))
27b3b22dd98ca (Gilad Ben-Yossef 2018-02-19 14:51:23 +0000 2005) continue;
1c876a90e2539 (Gilad Ben-Yossef 2018-11-13 09:40:35 +0000 2006)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2007) if (driver_hash[alg].is_mac) {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2008) /* register hmac version */
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2009) t_alg = cc_alloc_hash_alg(&driver_hash[alg], dev, true);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2010) if (IS_ERR(t_alg)) {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2011) rc = PTR_ERR(t_alg);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2012) dev_err(dev, "%s alg allocation failed\n",
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2013) driver_hash[alg].driver_name);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2014) goto fail;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2015) }
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2016) t_alg->drvdata = drvdata;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2017)
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2018) rc = crypto_register_ahash(&t_alg->ahash_alg);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2019) if (rc) {
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2020) dev_err(dev, "%s alg registration failed\n",
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2021) driver_hash[alg].driver_name);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2022) goto fail;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2023) }
ff4d719a5bc7e (Geert Uytterhoeven 2020-02-11 19:19:26 +0100 2024)
ff4d719a5bc7e (Geert Uytterhoeven 2020-02-11 19:19:26 +0100 2025) list_add_tail(&t_alg->entry, &hash_handle->hash_list);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2026) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2027) if (hw_mode == DRV_CIPHER_XCBC_MAC ||
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2028) hw_mode == DRV_CIPHER_CMAC)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2029) continue;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2030)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2031) /* register hash version */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2032) t_alg = cc_alloc_hash_alg(&driver_hash[alg], dev, false);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2033) if (IS_ERR(t_alg)) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2034) rc = PTR_ERR(t_alg);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2035) dev_err(dev, "%s alg allocation failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2036) driver_hash[alg].driver_name);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2037) goto fail;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2038) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2039) t_alg->drvdata = drvdata;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2040)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2041) rc = crypto_register_ahash(&t_alg->ahash_alg);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2042) if (rc) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2043) dev_err(dev, "%s alg registration failed\n",
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2044) driver_hash[alg].driver_name);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2045) goto fail;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2046) }
ff4d719a5bc7e (Geert Uytterhoeven 2020-02-11 19:19:26 +0100 2047)
ff4d719a5bc7e (Geert Uytterhoeven 2020-02-11 19:19:26 +0100 2048) list_add_tail(&t_alg->entry, &hash_handle->hash_list);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2049) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2050)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2051) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2052)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2053) fail:
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 2054) cc_hash_free(drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2055) return rc;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2056) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2057)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2058) int cc_hash_free(struct cc_drvdata *drvdata)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2059) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2060) struct cc_hash_alg *t_hash_alg, *hash_n;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2061) struct cc_hash_handle *hash_handle = drvdata->hash_handle;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2062)
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 2063) list_for_each_entry_safe(t_hash_alg, hash_n, &hash_handle->hash_list,
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 2064) entry) {
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 2065) crypto_unregister_ahash(&t_hash_alg->ahash_alg);
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 2066) list_del(&t_hash_alg->entry);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2067) }
91fc6c7b3328c (Geert Uytterhoeven 2020-02-11 19:19:28 +0100 2068)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2069) return 0;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2070) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2071)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2072) static void cc_setup_xcbc(struct ahash_request *areq, struct cc_hw_desc desc[],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2073) unsigned int *seq_size)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2074) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2075) unsigned int idx = *seq_size;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2076) struct ahash_req_ctx *state = ahash_request_ctx(areq);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2077) struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2078) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2079)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2080) /* Setup XCBC MAC K1 */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2081) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2082) set_din_type(&desc[idx], DMA_DLLI, (ctx->opad_tmp_keys_dma_addr +
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2083) XCBC_MAC_K1_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2084) CC_AES_128_BIT_KEY_SIZE, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2085) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
18a1dc1fd56b4 (Yael Chemla 2018-10-18 13:59:58 +0100 2086) set_hash_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC, ctx->hash_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2087) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2088) set_key_size_aes(&desc[idx], CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2089) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2090) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2091)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2092) /* Setup XCBC MAC K2 */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2093) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2094) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2095) (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K2_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2096) CC_AES_128_BIT_KEY_SIZE, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2097) set_setup_mode(&desc[idx], SETUP_LOAD_STATE1);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2098) set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2099) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2100) set_key_size_aes(&desc[idx], CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2101) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2102) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2103)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2104) /* Setup XCBC MAC K3 */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2105) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2106) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2107) (ctx->opad_tmp_keys_dma_addr + XCBC_MAC_K3_OFFSET),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2108) CC_AES_128_BIT_KEY_SIZE, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2109) set_setup_mode(&desc[idx], SETUP_LOAD_STATE2);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2110) set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2111) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2112) set_key_size_aes(&desc[idx], CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2113) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2114) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2115)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2116) /* Loading MAC state */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2117) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2118) set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2119) CC_AES_BLOCK_SIZE, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2120) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2121) set_cipher_mode(&desc[idx], DRV_CIPHER_XCBC_MAC);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2122) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2123) set_key_size_aes(&desc[idx], CC_AES_128_BIT_KEY_SIZE);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2124) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2125) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2126) *seq_size = idx;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2127) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2128)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2129) static void cc_setup_cmac(struct ahash_request *areq, struct cc_hw_desc desc[],
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2130) unsigned int *seq_size)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2131) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2132) unsigned int idx = *seq_size;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2133) struct ahash_req_ctx *state = ahash_request_ctx(areq);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2134) struct crypto_ahash *tfm = crypto_ahash_reqtfm(areq);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2135) struct cc_hash_ctx *ctx = crypto_ahash_ctx(tfm);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2136)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2137) /* Setup CMAC Key */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2138) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2139) set_din_type(&desc[idx], DMA_DLLI, ctx->opad_tmp_keys_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2140) ((ctx->key_params.keylen == 24) ? AES_MAX_KEY_SIZE :
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2141) ctx->key_params.keylen), NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2142) set_setup_mode(&desc[idx], SETUP_LOAD_KEY0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2143) set_cipher_mode(&desc[idx], DRV_CIPHER_CMAC);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2144) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2145) set_key_size_aes(&desc[idx], ctx->key_params.keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2146) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2147) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2148)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2149) /* Load MAC state */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2150) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2151) set_din_type(&desc[idx], DMA_DLLI, state->digest_buff_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2152) CC_AES_BLOCK_SIZE, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2153) set_setup_mode(&desc[idx], SETUP_LOAD_STATE0);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2154) set_cipher_mode(&desc[idx], DRV_CIPHER_CMAC);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2155) set_cipher_config0(&desc[idx], DESC_DIRECTION_ENCRYPT_ENCRYPT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2156) set_key_size_aes(&desc[idx], ctx->key_params.keylen);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2157) set_flow_mode(&desc[idx], S_DIN_to_AES);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2158) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2159) *seq_size = idx;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2160) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2161)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2162) static void cc_set_desc(struct ahash_req_ctx *areq_ctx,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2163) struct cc_hash_ctx *ctx, unsigned int flow_mode,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2164) struct cc_hw_desc desc[], bool is_not_last_data,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2165) unsigned int *seq_size)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2166) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2167) unsigned int idx = *seq_size;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2168) struct device *dev = drvdata_to_dev(ctx->drvdata);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2169)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2170) if (areq_ctx->data_dma_buf_type == CC_DMA_BUF_DLLI) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2171) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2172) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2173) sg_dma_address(areq_ctx->curr_sg),
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2174) areq_ctx->curr_sg->length, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2175) set_flow_mode(&desc[idx], flow_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2176) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2177) } else {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2178) if (areq_ctx->data_dma_buf_type == CC_DMA_BUF_NULL) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2179) dev_dbg(dev, " NULL mode\n");
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2180) /* nothing to build */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2181) return;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2182) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2183) /* bypass */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2184) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2185) set_din_type(&desc[idx], DMA_DLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2186) areq_ctx->mlli_params.mlli_dma_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2187) areq_ctx->mlli_params.mlli_len, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2188) set_dout_sram(&desc[idx], ctx->drvdata->mlli_sram_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2189) areq_ctx->mlli_params.mlli_len);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2190) set_flow_mode(&desc[idx], BYPASS);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2191) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2192) /* process */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2193) hw_desc_init(&desc[idx]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2194) set_din_type(&desc[idx], DMA_MLLI,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2195) ctx->drvdata->mlli_sram_addr,
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2196) areq_ctx->mlli_nents, NS_BIT);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2197) set_flow_mode(&desc[idx], flow_mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2198) idx++;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2199) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2200) if (is_not_last_data)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2201) set_din_not_last_indication(&desc[(idx - 1)]);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2202) /* return updated desc sequence size */
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2203) *seq_size = idx;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2204) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2205)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2206) static const void *cc_larval_digest(struct device *dev, u32 mode)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2207) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2208) switch (mode) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2209) case DRV_HASH_MD5:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2210) return cc_md5_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2211) case DRV_HASH_SHA1:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2212) return cc_sha1_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2213) case DRV_HASH_SHA224:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2214) return cc_sha224_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2215) case DRV_HASH_SHA256:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2216) return cc_sha256_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2217) case DRV_HASH_SHA384:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2218) return cc_sha384_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2219) case DRV_HASH_SHA512:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2220) return cc_sha512_init;
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2221) case DRV_HASH_SM3:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2222) return cc_sm3_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2223) default:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2224) dev_err(dev, "Invalid hash mode (%d)\n", mode);
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2225) return cc_md5_init;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2226) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2227) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2228)
dc16c9f764721 (Geert Uytterhoeven 2020-02-11 19:19:20 +0100 2229) /**
dc16c9f764721 (Geert Uytterhoeven 2020-02-11 19:19:20 +0100 2230) * cc_larval_digest_addr() - Get the address of the initial digest in SRAM
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2231) * according to the given hash mode
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2232) *
dc16c9f764721 (Geert Uytterhoeven 2020-02-11 19:19:20 +0100 2233) * @drvdata: Associated device driver context
dc16c9f764721 (Geert Uytterhoeven 2020-02-11 19:19:20 +0100 2234) * @mode: The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2235) *
dc16c9f764721 (Geert Uytterhoeven 2020-02-11 19:19:20 +0100 2236) * Return:
dc16c9f764721 (Geert Uytterhoeven 2020-02-11 19:19:20 +0100 2237) * The address of the initial digest in SRAM
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2238) */
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 2239) u32 cc_larval_digest_addr(void *drvdata, u32 mode)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2240) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2241) struct cc_drvdata *_drvdata = (struct cc_drvdata *)drvdata;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2242) struct cc_hash_handle *hash_handle = _drvdata->hash_handle;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2243) struct device *dev = drvdata_to_dev(_drvdata);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2244) bool sm3_supported = (_drvdata->hw_rev >= CC_HW_REV_713);
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 2245) u32 addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2246)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2247) switch (mode) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2248) case DRV_HASH_NULL:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2249) break; /*Ignore*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2250) case DRV_HASH_MD5:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2251) return (hash_handle->larval_digest_sram_addr);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2252) case DRV_HASH_SHA1:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2253) return (hash_handle->larval_digest_sram_addr +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2254) sizeof(cc_md5_init));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2255) case DRV_HASH_SHA224:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2256) return (hash_handle->larval_digest_sram_addr +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2257) sizeof(cc_md5_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2258) sizeof(cc_sha1_init));
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2259) case DRV_HASH_SHA256:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2260) return (hash_handle->larval_digest_sram_addr +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2261) sizeof(cc_md5_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2262) sizeof(cc_sha1_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2263) sizeof(cc_sha224_init));
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2264) case DRV_HASH_SM3:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2265) return (hash_handle->larval_digest_sram_addr +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2266) sizeof(cc_md5_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2267) sizeof(cc_sha1_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2268) sizeof(cc_sha224_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2269) sizeof(cc_sha256_init));
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2270) case DRV_HASH_SHA384:
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2271) addr = (hash_handle->larval_digest_sram_addr +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2272) sizeof(cc_md5_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2273) sizeof(cc_sha1_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2274) sizeof(cc_sha224_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2275) sizeof(cc_sha256_init));
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2276) if (sm3_supported)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2277) addr += sizeof(cc_sm3_init);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2278) return addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2279) case DRV_HASH_SHA512:
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2280) addr = (hash_handle->larval_digest_sram_addr +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2281) sizeof(cc_md5_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2282) sizeof(cc_sha1_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2283) sizeof(cc_sha224_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2284) sizeof(cc_sha256_init) +
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2285) sizeof(cc_sha384_init));
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2286) if (sm3_supported)
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2287) addr += sizeof(cc_sm3_init);
927574e0e85da (Yael Chemla 2018-10-18 13:59:59 +0100 2288) return addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2289) default:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2290) dev_err(dev, "Invalid hash mode (%d)\n", mode);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2291) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2292)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2293) /*This is valid wrong value to avoid kernel crash*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2294) return hash_handle->larval_digest_sram_addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2295) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2296)
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 2297) u32 cc_digest_len_addr(void *drvdata, u32 mode)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2298) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2299) struct cc_drvdata *_drvdata = (struct cc_drvdata *)drvdata;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2300) struct cc_hash_handle *hash_handle = _drvdata->hash_handle;
1a895f1d5bcee (Geert Uytterhoeven 2020-02-11 19:19:07 +0100 2301) u32 digest_len_addr = hash_handle->digest_len_sram_addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2302)
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2303) switch (mode) {
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2304) case DRV_HASH_SHA1:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2305) case DRV_HASH_SHA224:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2306) case DRV_HASH_SHA256:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2307) case DRV_HASH_MD5:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2308) return digest_len_addr;
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2309) case DRV_HASH_SHA384:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2310) case DRV_HASH_SHA512:
e55d8a75c6020 (Hans de Goede 2019-09-01 22:35:28 +0200 2311) return digest_len_addr + sizeof(cc_digest_len_init);
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2312) default:
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2313) return digest_len_addr; /*to avoid kernel crash*/
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2314) }
63893811b0fcb (Gilad Ben-Yossef 2018-01-22 09:27:02 +0000 2315) }