···22 tristate "Support for ARM TrustZone CryptoCell C7XX family of Crypto accelerators"33 depends on CRYPTO_HW && OF && HAS_DMA44 default n55+ select CRYPTO_HASH66+ select CRYPTO_SHA177+ select CRYPTO_MD588+ select CRYPTO_SHA25699+ select CRYPTO_SHA5121010+ select CRYPTO_HMAC511 help612 Say 'Y' to enable a driver for the Arm TrustZone CryptoCell 713 C7xx. Currently only the CryptoCell 712 REE is supported.
···220220} __attribute__((__may_alias__));221221222222223223+struct drv_ctx_hash {224224+ enum drv_crypto_alg alg; /* DRV_CRYPTO_ALG_HASH */225225+ enum drv_hash_mode mode;226226+ uint8_t digest[CC_DIGEST_SIZE_MAX];227227+ /* reserve to end of allocated context size */228228+ uint8_t reserved[CC_CTX_SIZE - 2 * sizeof(uint32_t) -229229+ CC_DIGEST_SIZE_MAX];230230+};231231+232232+/* !!!! drv_ctx_hmac should have the same structure as drv_ctx_hash except233233+ k0, k0_size fields */234234+struct drv_ctx_hmac {235235+ enum drv_crypto_alg alg; /* DRV_CRYPTO_ALG_HMAC */236236+ enum drv_hash_mode mode;237237+ uint8_t digest[CC_DIGEST_SIZE_MAX];238238+ uint32_t k0[CC_HMAC_BLOCK_SIZE_MAX/sizeof(uint32_t)];239239+ uint32_t k0_size;240240+ /* reserve to end of allocated context size */241241+ uint8_t reserved[CC_CTX_SIZE - 3 * sizeof(uint32_t) -242242+ CC_DIGEST_SIZE_MAX - CC_HMAC_BLOCK_SIZE_MAX];243243+};244244+223245/*******************************************************************/224246/***************** MESSAGE BASED CONTEXTS **************************/225247/*******************************************************************/
+78
drivers/staging/ccree/hash_defs.h
···11+/*22+ * Copyright (C) 2012-2017 ARM Limited or its affiliates.33+ * 44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License version 2 as66+ * published by the Free Software Foundation.77+ * 88+ * This program is distributed in the hope that it will be useful,99+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1010+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111+ * GNU General Public License for more details.1212+ * 1313+ * You should have received a copy of the GNU General Public License1414+ * along with this program; if not, see <http://www.gnu.org/licenses/>.1515+ */1616+1717+#ifndef _HASH_DEFS_H__1818+#define _HASH_DEFS_H__1919+2020+#include "cc_crypto_ctx.h"2121+2222+/* this files provides definitions required for hash engine drivers */2323+#ifndef CC_CONFIG_HASH_SHA_512_SUPPORTED2424+#define SEP_HASH_LENGTH_WORDS 22525+#else2626+#define SEP_HASH_LENGTH_WORDS 42727+#endif2828+2929+#ifdef BIG__ENDIAN3030+#define OPAD_CURRENT_LENGTH 0x40000000, 0x00000000 , 0x00000000, 0x000000003131+#define HASH_LARVAL_MD5 0x76543210, 0xFEDCBA98, 0x89ABCDEF, 0x012345673232+#define HASH_LARVAL_SHA1 0xF0E1D2C3, 0x76543210, 0xFEDCBA98, 0x89ABCDEF, 0x012345673333+#define HASH_LARVAL_SHA224 0XA44FFABE, 0XA78FF964, 0X11155868, 0X310BC0FF, 0X39590EF7, 0X17DD7030, 0X07D57C36, 0XD89E05C13434+#define HASH_LARVAL_SHA256 0X19CDE05B, 0XABD9831F, 0X8C68059B, 0X7F520E51, 0X3AF54FA5, 0X72F36E3C, 0X85AE67BB, 0X67E6096A3535+#define HASH_LARVAL_SHA384 0X1D48B547, 0XA44FFABE, 0X0D2E0CDB, 0XA78FF964, 0X874AB48E, 0X11155868, 0X67263367, 0X310BC0FF, 0XD8EC2F15, 0X39590EF7, 0X5A015991, 0X17DD7030, 0X2A299A62, 0X07D57C36, 0X5D9DBBCB, 0XD89E05C13636+#define HASH_LARVAL_SHA512 0X19CDE05B, 0X79217E13, 0XABD9831F, 0X6BBD41FB, 0X8C68059B, 0X1F6C3E2B, 0X7F520E51, 0XD182E6AD, 0X3AF54FA5, 0XF1361D5F, 0X72F36E3C, 0X2BF894FE, 0X85AE67BB, 0X3BA7CA84, 0X67E6096A, 0X08C9BCF33737+#else3838+#define OPAD_CURRENT_LENGTH 0x00000040, 0x00000000, 0x00000000, 0x000000003939+#define HASH_LARVAL_MD5 0x10325476, 0x98BADCFE, 0xEFCDAB89, 0x674523014040+#define HASH_LARVAL_SHA1 0xC3D2E1F0, 0x10325476, 0x98BADCFE, 0xEFCDAB89, 0x674523014141+#define HASH_LARVAL_SHA224 0xbefa4fa4, 0x64f98fa7, 0x68581511, 0xffc00b31, 0xf70e5939, 0x3070dd17, 0x367cd507, 0xc1059ed84242+#define HASH_LARVAL_SHA256 0x5be0cd19, 0x1f83d9ab, 0x9b05688c, 0x510e527f, 0xa54ff53a, 0x3c6ef372, 0xbb67ae85, 0x6a09e6674343+#define HASH_LARVAL_SHA384 0X47B5481D, 0XBEFA4FA4, 0XDB0C2E0D, 0X64F98FA7, 0X8EB44A87, 0X68581511, 0X67332667, 0XFFC00B31, 0X152FECD8, 0XF70E5939, 0X9159015A, 0X3070DD17, 0X629A292A, 0X367CD507, 0XCBBB9D5D, 0XC1059ED84444+#define HASH_LARVAL_SHA512 0x5be0cd19, 0x137e2179, 0x1f83d9ab, 0xfb41bd6b, 0x9b05688c, 0x2b3e6c1f, 0x510e527f, 0xade682d1, 0xa54ff53a, 0x5f1d36f1, 0x3c6ef372, 0xfe94f82b, 0xbb67ae85, 0x84caa73b, 0x6a09e667, 0xf3bcc9084545+#endif4646+4747+enum HashConfig1Padding {4848+ HASH_PADDING_DISABLED = 0,4949+ HASH_PADDING_ENABLED = 1,5050+ HASH_DIGEST_RESULT_LITTLE_ENDIAN = 2,5151+ HASH_CONFIG1_PADDING_RESERVE32 = INT32_MAX,5252+};5353+5454+enum HashCipherDoPadding {5555+ DO_NOT_PAD = 0,5656+ DO_PAD = 1,5757+ HASH_CIPHER_DO_PADDING_RESERVE32 = INT32_MAX,5858+};5959+6060+typedef struct SepHashPrivateContext {6161+ /* The current length is placed at the end of the context buffer because the hash 6262+ context is used for all HMAC operations as well. HMAC context includes a 64 bytes 6363+ K0 field. The size of struct drv_ctx_hash reserved field is 88/184 bytes depend if t6464+ he SHA512 is supported ( in this case teh context size is 256 bytes).6565+ The size of struct drv_ctx_hash reseved field is 20 or 52 depend if the SHA512 is supported.6666+ This means that this structure size (without the reserved field can be up to 20 bytes ,6767+ in case sha512 is not suppported it is 20 bytes (SEP_HASH_LENGTH_WORDS define to 2 ) and in the other6868+ case it is 28 (SEP_HASH_LENGTH_WORDS define to 4) */6969+ uint32_t reserved[(sizeof(struct drv_ctx_hash)/sizeof(uint32_t)) - SEP_HASH_LENGTH_WORDS - 3];7070+ uint32_t CurrentDigestedLength[SEP_HASH_LENGTH_WORDS];7171+ uint32_t KeyType;7272+ uint32_t dataCompleted;7373+ uint32_t hmacFinalization;7474+ /* no space left */7575+} SepHashPrivateContext_s;7676+7777+#endif /*_HASH_DEFS_H__*/7878+
+301-10
drivers/staging/ccree/ssi_buffer_mgr.c
···1717#include <linux/crypto.h>1818#include <linux/version.h>1919#include <crypto/algapi.h>2020+#include <crypto/hash.h>2021#include <crypto/authenc.h>2122#include <crypto/scatterwalk.h>2223#include <linux/dmapool.h>···28272928#include "ssi_buffer_mgr.h"3029#include "cc_lli_defs.h"3030+#include "ssi_hash.h"31313232#define LLI_MAX_NUM_OF_DATA_ENTRIES 1283333#define LLI_MAX_NUM_OF_ASSOC_DATA_ENTRIES 4···283281 return 0;284282}285283286286-static int ssi_buffer_mgr_generate_mlli (287287- struct device *dev,288288- struct buffer_array *sg_data,289289- struct mlli_params *mlli_params) __maybe_unused;290290-291284static int ssi_buffer_mgr_generate_mlli(292285 struct device *dev,293286 struct buffer_array *sg_data,···424427 return 0;425428}426429427427-static int ssi_buffer_mgr_map_scatterlist (struct device *dev,428428- struct scatterlist *sg, unsigned int nbytes, int direction,429429- uint32_t *nents, uint32_t max_sg_nents, uint32_t *lbytes,430430- uint32_t *mapped_nents) __maybe_unused;431431-432430static int ssi_buffer_mgr_map_scatterlist(433431 struct device *dev, struct scatterlist *sg,434432 unsigned int nbytes, int direction,···483491 }484492485493 return 0;494494+}495495+496496+static inline int ssi_ahash_handle_curr_buf(struct device *dev,497497+ struct ahash_req_ctx *areq_ctx,498498+ uint8_t* curr_buff,499499+ uint32_t curr_buff_cnt,500500+ struct buffer_array *sg_data)501501+{502502+ SSI_LOG_DEBUG(" handle curr buff %x set to DLLI \n", curr_buff_cnt);503503+ /* create sg for the current buffer */504504+ sg_init_one(areq_ctx->buff_sg,curr_buff, curr_buff_cnt);505505+ if (unlikely(dma_map_sg(dev, areq_ctx->buff_sg, 1,506506+ DMA_TO_DEVICE) != 1)) {507507+ SSI_LOG_ERR("dma_map_sg() "508508+ "src buffer failed\n");509509+ return -ENOMEM;510510+ }511511+ SSI_LOG_DEBUG("Mapped curr_buff: dma_address=0x%llX "512512+ "page_link=0x%08lX addr=%pK "513513+ "offset=%u length=%u\n",514514+ (unsigned long long)sg_dma_address(areq_ctx->buff_sg), 515515+ areq_ctx->buff_sg->page_link, 516516+ sg_virt(areq_ctx->buff_sg),517517+ areq_ctx->buff_sg->offset, 518518+ areq_ctx->buff_sg->length);519519+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_DLLI;520520+ areq_ctx->curr_sg = areq_ctx->buff_sg;521521+ areq_ctx->in_nents = 0;522522+ /* prepare for case of MLLI */523523+ ssi_buffer_mgr_add_scatterlist_entry(sg_data, 1, areq_ctx->buff_sg,524524+ curr_buff_cnt, 0, false, NULL);525525+ return 0;526526+}527527+528528+int ssi_buffer_mgr_map_hash_request_final(529529+ struct ssi_drvdata *drvdata, void *ctx, struct scatterlist *src, unsigned int nbytes, bool do_update)530530+{531531+ struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx;532532+ struct device *dev = &drvdata->plat_dev->dev;533533+ uint8_t* curr_buff = areq_ctx->buff_index ? areq_ctx->buff1 :534534+ areq_ctx->buff0;535535+ uint32_t *curr_buff_cnt = areq_ctx->buff_index ? &areq_ctx->buff1_cnt :536536+ &areq_ctx->buff0_cnt;537537+ struct mlli_params *mlli_params = &areq_ctx->mlli_params; 538538+ struct buffer_array sg_data;539539+ struct buff_mgr_handle *buff_mgr = drvdata->buff_mgr_handle;540540+ uint32_t dummy = 0;541541+ uint32_t mapped_nents = 0;542542+543543+ SSI_LOG_DEBUG(" final params : curr_buff=%pK "544544+ "curr_buff_cnt=0x%X nbytes = 0x%X "545545+ "src=%pK curr_index=%u\n",546546+ curr_buff, *curr_buff_cnt, nbytes,547547+ src, areq_ctx->buff_index);548548+ /* Init the type of the dma buffer */549549+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_NULL;550550+ mlli_params->curr_pool = NULL;551551+ sg_data.num_of_buffers = 0;552552+ areq_ctx->in_nents = 0;553553+554554+ if (unlikely(nbytes == 0 && *curr_buff_cnt == 0)) {555555+ /* nothing to do */556556+ return 0;557557+ }558558+559559+ /*TODO: copy data in case that buffer is enough for operation */560560+ /* map the previous buffer */561561+ if (*curr_buff_cnt != 0 ) {562562+ if (ssi_ahash_handle_curr_buf(dev, areq_ctx, curr_buff,563563+ *curr_buff_cnt, &sg_data) != 0) {564564+ return -ENOMEM;565565+ }566566+ }567567+568568+ if (src && (nbytes > 0) && do_update) {569569+ if ( unlikely( ssi_buffer_mgr_map_scatterlist( dev,src,570570+ nbytes,571571+ DMA_TO_DEVICE,572572+ &areq_ctx->in_nents,573573+ LLI_MAX_NUM_OF_DATA_ENTRIES,574574+ &dummy, &mapped_nents))){575575+ goto unmap_curr_buff;576576+ }577577+ if ( src && (mapped_nents == 1) 578578+ && (areq_ctx->data_dma_buf_type == SSI_DMA_BUF_NULL) ) {579579+ memcpy(areq_ctx->buff_sg,src,580580+ sizeof(struct scatterlist));581581+ areq_ctx->buff_sg->length = nbytes;582582+ areq_ctx->curr_sg = areq_ctx->buff_sg;583583+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_DLLI;584584+ } else {585585+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_MLLI;586586+ }587587+588588+ }589589+590590+ /*build mlli */591591+ if (unlikely(areq_ctx->data_dma_buf_type == SSI_DMA_BUF_MLLI)) {592592+ mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;593593+ /* add the src data to the sg_data */594594+ ssi_buffer_mgr_add_scatterlist_entry(&sg_data,595595+ areq_ctx->in_nents,596596+ src,597597+ nbytes, 0,598598+ true, &areq_ctx->mlli_nents);599599+ if (unlikely(ssi_buffer_mgr_generate_mlli(dev, &sg_data,600600+ mlli_params) != 0)) {601601+ goto fail_unmap_din;602602+ }603603+ }604604+ /* change the buffer index for the unmap function */605605+ areq_ctx->buff_index = (areq_ctx->buff_index^1);606606+ SSI_LOG_DEBUG("areq_ctx->data_dma_buf_type = %s\n",607607+ GET_DMA_BUFFER_TYPE(areq_ctx->data_dma_buf_type));608608+ return 0;609609+610610+fail_unmap_din:611611+ dma_unmap_sg(dev, src, areq_ctx->in_nents, DMA_TO_DEVICE);612612+613613+unmap_curr_buff:614614+ if (*curr_buff_cnt != 0 ) {615615+ dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE);616616+ }617617+ return -ENOMEM;618618+}619619+620620+int ssi_buffer_mgr_map_hash_request_update(621621+ struct ssi_drvdata *drvdata, void *ctx, struct scatterlist *src, unsigned int nbytes, unsigned int block_size)622622+{623623+ struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx;624624+ struct device *dev = &drvdata->plat_dev->dev;625625+ uint8_t* curr_buff = areq_ctx->buff_index ? areq_ctx->buff1 :626626+ areq_ctx->buff0;627627+ uint32_t *curr_buff_cnt = areq_ctx->buff_index ? &areq_ctx->buff1_cnt :628628+ &areq_ctx->buff0_cnt;629629+ uint8_t* next_buff = areq_ctx->buff_index ? areq_ctx->buff0 :630630+ areq_ctx->buff1;631631+ uint32_t *next_buff_cnt = areq_ctx->buff_index ? &areq_ctx->buff0_cnt :632632+ &areq_ctx->buff1_cnt;633633+ struct mlli_params *mlli_params = &areq_ctx->mlli_params; 634634+ unsigned int update_data_len;635635+ uint32_t total_in_len = nbytes + *curr_buff_cnt;636636+ struct buffer_array sg_data;637637+ struct buff_mgr_handle *buff_mgr = drvdata->buff_mgr_handle;638638+ unsigned int swap_index = 0;639639+ uint32_t dummy = 0;640640+ uint32_t mapped_nents = 0;641641+642642+ SSI_LOG_DEBUG(" update params : curr_buff=%pK "643643+ "curr_buff_cnt=0x%X nbytes=0x%X "644644+ "src=%pK curr_index=%u \n",645645+ curr_buff, *curr_buff_cnt, nbytes,646646+ src, areq_ctx->buff_index);647647+ /* Init the type of the dma buffer */648648+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_NULL;649649+ mlli_params->curr_pool = NULL;650650+ areq_ctx->curr_sg = NULL;651651+ sg_data.num_of_buffers = 0;652652+ areq_ctx->in_nents = 0;653653+654654+ if (unlikely(total_in_len < block_size)) {655655+ SSI_LOG_DEBUG(" less than one block: curr_buff=%pK "656656+ "*curr_buff_cnt=0x%X copy_to=%pK\n",657657+ curr_buff, *curr_buff_cnt,658658+ &curr_buff[*curr_buff_cnt]);659659+ areq_ctx->in_nents = 660660+ ssi_buffer_mgr_get_sgl_nents(src,661661+ nbytes,662662+ &dummy, NULL);663663+ sg_copy_to_buffer(src, areq_ctx->in_nents,664664+ &curr_buff[*curr_buff_cnt], nbytes); 665665+ *curr_buff_cnt += nbytes;666666+ return 1;667667+ }668668+669669+ /* Calculate the residue size*/670670+ *next_buff_cnt = total_in_len & (block_size - 1);671671+ /* update data len */672672+ update_data_len = total_in_len - *next_buff_cnt;673673+674674+ SSI_LOG_DEBUG(" temp length : *next_buff_cnt=0x%X "675675+ "update_data_len=0x%X\n",676676+ *next_buff_cnt, update_data_len);677677+678678+ /* Copy the new residue to next buffer */679679+ if (*next_buff_cnt != 0) {680680+ SSI_LOG_DEBUG(" handle residue: next buff %pK skip data %u"681681+ " residue %u \n", next_buff,682682+ (update_data_len - *curr_buff_cnt),683683+ *next_buff_cnt);684684+ ssi_buffer_mgr_copy_scatterlist_portion(next_buff, src,685685+ (update_data_len -*curr_buff_cnt),686686+ nbytes,SSI_SG_TO_BUF);687687+ /* change the buffer index for next operation */688688+ swap_index = 1;689689+ }690690+691691+ if (*curr_buff_cnt != 0) {692692+ if (ssi_ahash_handle_curr_buf(dev, areq_ctx, curr_buff,693693+ *curr_buff_cnt, &sg_data) != 0) {694694+ return -ENOMEM;695695+ }696696+ /* change the buffer index for next operation */697697+ swap_index = 1;698698+ }699699+700700+ if ( update_data_len > *curr_buff_cnt ) {701701+ if ( unlikely( ssi_buffer_mgr_map_scatterlist( dev,src,702702+ (update_data_len -*curr_buff_cnt),703703+ DMA_TO_DEVICE,704704+ &areq_ctx->in_nents,705705+ LLI_MAX_NUM_OF_DATA_ENTRIES,706706+ &dummy, &mapped_nents))){707707+ goto unmap_curr_buff;708708+ }709709+ if ( (mapped_nents == 1) 710710+ && (areq_ctx->data_dma_buf_type == SSI_DMA_BUF_NULL) ) {711711+ /* only one entry in the SG and no previous data */712712+ memcpy(areq_ctx->buff_sg,src,713713+ sizeof(struct scatterlist));714714+ areq_ctx->buff_sg->length = update_data_len;715715+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_DLLI;716716+ areq_ctx->curr_sg = areq_ctx->buff_sg;717717+ } else {718718+ areq_ctx->data_dma_buf_type = SSI_DMA_BUF_MLLI;719719+ }720720+ }721721+722722+ if (unlikely(areq_ctx->data_dma_buf_type == SSI_DMA_BUF_MLLI)) {723723+ mlli_params->curr_pool = buff_mgr->mlli_buffs_pool;724724+ /* add the src data to the sg_data */725725+ ssi_buffer_mgr_add_scatterlist_entry(&sg_data,726726+ areq_ctx->in_nents,727727+ src,728728+ (update_data_len - *curr_buff_cnt), 0,729729+ true, &areq_ctx->mlli_nents);730730+ if (unlikely(ssi_buffer_mgr_generate_mlli(dev, &sg_data,731731+ mlli_params) != 0)) {732732+ goto fail_unmap_din;733733+ }734734+735735+ }736736+ areq_ctx->buff_index = (areq_ctx->buff_index^swap_index);737737+738738+ return 0;739739+740740+fail_unmap_din:741741+ dma_unmap_sg(dev, src, areq_ctx->in_nents, DMA_TO_DEVICE);742742+743743+unmap_curr_buff:744744+ if (*curr_buff_cnt != 0 ) {745745+ dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE);746746+ }747747+ return -ENOMEM;748748+}749749+750750+void ssi_buffer_mgr_unmap_hash_request(751751+ struct device *dev, void *ctx, struct scatterlist *src, bool do_revert)752752+{753753+ struct ahash_req_ctx *areq_ctx = (struct ahash_req_ctx *)ctx;754754+ uint32_t *prev_len = areq_ctx->buff_index ? &areq_ctx->buff0_cnt :755755+ &areq_ctx->buff1_cnt;756756+757757+ /*In case a pool was set, a table was 758758+ allocated and should be released */759759+ if (areq_ctx->mlli_params.curr_pool != NULL) {760760+ SSI_LOG_DEBUG("free MLLI buffer: dma=0x%llX virt=%pK\n", 761761+ (unsigned long long)areq_ctx->mlli_params.mlli_dma_addr,762762+ areq_ctx->mlli_params.mlli_virt_addr);763763+ SSI_RESTORE_DMA_ADDR_TO_48BIT(areq_ctx->mlli_params.mlli_dma_addr);764764+ dma_pool_free(areq_ctx->mlli_params.curr_pool,765765+ areq_ctx->mlli_params.mlli_virt_addr,766766+ areq_ctx->mlli_params.mlli_dma_addr);767767+ }768768+769769+ if ((src) && likely(areq_ctx->in_nents != 0)) {770770+ SSI_LOG_DEBUG("Unmapped sg src: virt=%pK dma=0x%llX len=0x%X\n",771771+ sg_virt(src),772772+ (unsigned long long)sg_dma_address(src), 773773+ sg_dma_len(src));774774+ SSI_RESTORE_DMA_ADDR_TO_48BIT(sg_dma_address(src));775775+ dma_unmap_sg(dev, src, 776776+ areq_ctx->in_nents, DMA_TO_DEVICE);777777+ }778778+779779+ if (*prev_len != 0) {780780+ SSI_LOG_DEBUG("Unmapped buffer: areq_ctx->buff_sg=%pK"781781+ "dma=0x%llX len 0x%X\n", 782782+ sg_virt(areq_ctx->buff_sg),783783+ (unsigned long long)sg_dma_address(areq_ctx->buff_sg), 784784+ sg_dma_len(areq_ctx->buff_sg));785785+ dma_unmap_sg(dev, areq_ctx->buff_sg, 1, DMA_TO_DEVICE);786786+ if (!do_revert) {787787+ /* clean the previous data length for update operation */788788+ *prev_len = 0;789789+ } else {790790+ areq_ctx->buff_index ^= 1;791791+ }792792+ }486793}487794488795int ssi_buffer_mgr_init(struct ssi_drvdata *drvdata)
···11+/*22+ * Copyright (C) 2012-2017 ARM Limited or its affiliates.33+ * 44+ * This program is free software; you can redistribute it and/or modify55+ * it under the terms of the GNU General Public License version 2 as66+ * published by the Free Software Foundation.77+ * 88+ * This program is distributed in the hope that it will be useful,99+ * but WITHOUT ANY WARRANTY; without even the implied warranty of1010+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1111+ * GNU General Public License for more details.1212+ * 1313+ * You should have received a copy of the GNU General Public License1414+ * along with this program; if not, see <http://www.gnu.org/licenses/>.1515+ */1616+1717+/* \file ssi_hash.h1818+ ARM CryptoCell Hash Crypto API1919+ */2020+2121+#ifndef __SSI_HASH_H__2222+#define __SSI_HASH_H__2323+2424+#include "ssi_buffer_mgr.h"2525+2626+#define HMAC_IPAD_CONST 0x363636362727+#define HMAC_OPAD_CONST 0x5C5C5C5C2828+#if (DX_DEV_SHA_MAX > 256)2929+#define HASH_LEN_SIZE 163030+#define SSI_MAX_HASH_DIGEST_SIZE SHA512_DIGEST_SIZE3131+#define SSI_MAX_HASH_BLCK_SIZE SHA512_BLOCK_SIZE3232+#else3333+#define HASH_LEN_SIZE 83434+#define SSI_MAX_HASH_DIGEST_SIZE SHA256_DIGEST_SIZE3535+#define SSI_MAX_HASH_BLCK_SIZE SHA256_BLOCK_SIZE3636+#endif3737+3838+#define XCBC_MAC_K1_OFFSET 03939+#define XCBC_MAC_K2_OFFSET 164040+#define XCBC_MAC_K3_OFFSET 324141+4242+// this struct was taken from drivers/crypto/nx/nx-aes-xcbc.c and it is used for xcbc/cmac statesize4343+struct aeshash_state {4444+ u8 state[AES_BLOCK_SIZE];4545+ unsigned int count;4646+ u8 buffer[AES_BLOCK_SIZE];4747+};4848+4949+/* ahash state */5050+struct ahash_req_ctx {5151+ uint8_t* buff0;5252+ uint8_t* buff1;5353+ uint8_t* digest_result_buff;5454+ struct async_gen_req_ctx gen_ctx;5555+ enum ssi_req_dma_buf_type data_dma_buf_type;5656+ uint8_t *digest_buff;5757+ uint8_t *opad_digest_buff;5858+ uint8_t *digest_bytes_len;5959+ dma_addr_t opad_digest_dma_addr;6060+ dma_addr_t digest_buff_dma_addr;6161+ dma_addr_t digest_bytes_len_dma_addr;6262+ dma_addr_t digest_result_dma_addr;6363+ uint32_t buff0_cnt;6464+ uint32_t buff1_cnt;6565+ uint32_t buff_index;6666+ uint32_t xcbc_count; /* count xcbc update operatations */6767+ struct scatterlist buff_sg[2];6868+ struct scatterlist *curr_sg;6969+ uint32_t in_nents;7070+ uint32_t mlli_nents;7171+ struct mlli_params mlli_params; 7272+};7373+7474+int ssi_hash_alloc(struct ssi_drvdata *drvdata);7575+int ssi_hash_init_sram_digest_consts(struct ssi_drvdata *drvdata);7676+int ssi_hash_free(struct ssi_drvdata *drvdata);7777+7878+/*!7979+ * Gets the initial digest length8080+ * 8181+ * \param drvdata 8282+ * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA5128383+ * 8484+ * \return uint32_t returns the address of the initial digest length in SRAM8585+ */8686+ssi_sram_addr_t8787+ssi_ahash_get_initial_digest_len_sram_addr(void *drvdata, uint32_t mode);8888+8989+/*!9090+ * Gets the address of the initial digest in SRAM 9191+ * according to the given hash mode9292+ * 9393+ * \param drvdata 9494+ * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256/SHA384/SHA5129595+ * 9696+ * \return uint32_t The address of the inital digest in SRAM9797+ */9898+ssi_sram_addr_t ssi_ahash_get_larval_digest_sram_addr(void *drvdata, uint32_t mode);9999+100100+#endif /*__SSI_HASH_H__*/101101+
+4
drivers/staging/ccree/ssi_pm.c
···2626#include "ssi_request_mgr.h"2727#include "ssi_sram_mgr.h"2828#include "ssi_sysfs.h"2929+#include "ssi_hash.h"2930#include "ssi_pm.h"3031#include "ssi_pm_ext.h"3132···8079 return rc;8180 }82818282+ /* must be after the queue resuming as it uses the HW queue*/8383+ ssi_hash_init_sram_digest_consts(drvdata);8484+8385 return 0;8486}8587