1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2012-2018 ARM Limited or its affiliates. */
4 #include <linux/kernel.h>
5 #include <linux/module.h>
6 #include <crypto/algapi.h>
7 #include <crypto/hash.h>
8 #include <crypto/md5.h>
9 #include <crypto/internal/hash.h>
11 #include "cc_driver.h"
12 #include "cc_request_mgr.h"
13 #include "cc_buffer_mgr.h"
15 #include "cc_sram_mgr.h"
17 #define CC_MAX_HASH_SEQ_LEN 12
18 #define CC_MAX_OPAD_KEYS_SIZE CC_MAX_HASH_BLCK_SIZE
20 struct cc_hash_handle
{
21 cc_sram_addr_t digest_len_sram_addr
; /* const value in SRAM*/
22 cc_sram_addr_t larval_digest_sram_addr
; /* const value in SRAM */
23 struct list_head hash_list
;
26 static const u32 digest_len_init
[] = {
27 0x00000040, 0x00000000, 0x00000000, 0x00000000 };
28 static const u32 md5_init
[] = {
29 SHA1_H3
, SHA1_H2
, SHA1_H1
, SHA1_H0
};
30 static const u32 sha1_init
[] = {
31 SHA1_H4
, SHA1_H3
, SHA1_H2
, SHA1_H1
, SHA1_H0
};
32 static const u32 sha224_init
[] = {
33 SHA224_H7
, SHA224_H6
, SHA224_H5
, SHA224_H4
,
34 SHA224_H3
, SHA224_H2
, SHA224_H1
, SHA224_H0
};
35 static const u32 sha256_init
[] = {
36 SHA256_H7
, SHA256_H6
, SHA256_H5
, SHA256_H4
,
37 SHA256_H3
, SHA256_H2
, SHA256_H1
, SHA256_H0
};
38 static const u32 digest_len_sha512_init
[] = {
39 0x00000080, 0x00000000, 0x00000000, 0x00000000 };
40 static u64 sha384_init
[] = {
41 SHA384_H7
, SHA384_H6
, SHA384_H5
, SHA384_H4
,
42 SHA384_H3
, SHA384_H2
, SHA384_H1
, SHA384_H0
};
43 static u64 sha512_init
[] = {
44 SHA512_H7
, SHA512_H6
, SHA512_H5
, SHA512_H4
,
45 SHA512_H3
, SHA512_H2
, SHA512_H1
, SHA512_H0
};
47 static void cc_setup_xcbc(struct ahash_request
*areq
, struct cc_hw_desc desc
[],
48 unsigned int *seq_size
);
50 static void cc_setup_cmac(struct ahash_request
*areq
, struct cc_hw_desc desc
[],
51 unsigned int *seq_size
);
53 static const void *cc_larval_digest(struct device
*dev
, u32 mode
);
56 struct list_head entry
;
60 struct cc_drvdata
*drvdata
;
61 struct ahash_alg ahash_alg
;
64 struct hash_key_req_ctx
{
66 dma_addr_t key_dma_addr
;
69 /* hash per-session context */
71 struct cc_drvdata
*drvdata
;
72 /* holds the origin digest; the digest after "setkey" if HMAC,*
73 * the initial digest if HASH.
75 u8 digest_buff
[CC_MAX_HASH_DIGEST_SIZE
] ____cacheline_aligned
;
76 u8 opad_tmp_keys_buff
[CC_MAX_OPAD_KEYS_SIZE
] ____cacheline_aligned
;
78 dma_addr_t opad_tmp_keys_dma_addr ____cacheline_aligned
;
79 dma_addr_t digest_buff_dma_addr
;
80 /* use for hmac with key large then mode block size */
81 struct hash_key_req_ctx key_params
;
85 struct completion setkey_comp
;
89 static void cc_set_desc(struct ahash_req_ctx
*areq_ctx
, struct cc_hash_ctx
*ctx
,
90 unsigned int flow_mode
, struct cc_hw_desc desc
[],
91 bool is_not_last_data
, unsigned int *seq_size
);
93 static void cc_set_endianity(u32 mode
, struct cc_hw_desc
*desc
)
95 if (mode
== DRV_HASH_MD5
|| mode
== DRV_HASH_SHA384
||
96 mode
== DRV_HASH_SHA512
) {
97 set_bytes_swap(desc
, 1);
99 set_cipher_config0(desc
, HASH_DIGEST_RESULT_LITTLE_ENDIAN
);
103 static int cc_map_result(struct device
*dev
, struct ahash_req_ctx
*state
,
104 unsigned int digestsize
)
106 state
->digest_result_dma_addr
=
107 dma_map_single(dev
, state
->digest_result_buff
,
108 digestsize
, DMA_BIDIRECTIONAL
);
109 if (dma_mapping_error(dev
, state
->digest_result_dma_addr
)) {
110 dev_err(dev
, "Mapping digest result buffer %u B for DMA failed\n",
114 dev_dbg(dev
, "Mapped digest result buffer %u B at va=%pK to dma=%pad\n",
115 digestsize
, state
->digest_result_buff
,
116 &state
->digest_result_dma_addr
);
121 static void cc_init_req(struct device
*dev
, struct ahash_req_ctx
*state
,
122 struct cc_hash_ctx
*ctx
)
124 bool is_hmac
= ctx
->is_hmac
;
126 memset(state
, 0, sizeof(*state
));
129 if (ctx
->hw_mode
!= DRV_CIPHER_XCBC_MAC
&&
130 ctx
->hw_mode
!= DRV_CIPHER_CMAC
) {
131 dma_sync_single_for_cpu(dev
, ctx
->digest_buff_dma_addr
,
132 ctx
->inter_digestsize
,
135 memcpy(state
->digest_buff
, ctx
->digest_buff
,
136 ctx
->inter_digestsize
);
137 if (ctx
->hash_mode
== DRV_HASH_SHA512
||
138 ctx
->hash_mode
== DRV_HASH_SHA384
)
139 memcpy(state
->digest_bytes_len
,
140 digest_len_sha512_init
,
141 ctx
->drvdata
->hash_len_sz
);
143 memcpy(state
->digest_bytes_len
, digest_len_init
,
144 ctx
->drvdata
->hash_len_sz
);
147 if (ctx
->hash_mode
!= DRV_HASH_NULL
) {
148 dma_sync_single_for_cpu(dev
,
149 ctx
->opad_tmp_keys_dma_addr
,
150 ctx
->inter_digestsize
,
152 memcpy(state
->opad_digest_buff
,
153 ctx
->opad_tmp_keys_buff
, ctx
->inter_digestsize
);
156 /* Copy the initial digests if hash flow. */
157 const void *larval
= cc_larval_digest(dev
, ctx
->hash_mode
);
159 memcpy(state
->digest_buff
, larval
, ctx
->inter_digestsize
);
163 static int cc_map_req(struct device
*dev
, struct ahash_req_ctx
*state
,
164 struct cc_hash_ctx
*ctx
)
166 bool is_hmac
= ctx
->is_hmac
;
168 state
->digest_buff_dma_addr
=
169 dma_map_single(dev
, state
->digest_buff
,
170 ctx
->inter_digestsize
, DMA_BIDIRECTIONAL
);
171 if (dma_mapping_error(dev
, state
->digest_buff_dma_addr
)) {
172 dev_err(dev
, "Mapping digest len %d B at va=%pK for DMA failed\n",
173 ctx
->inter_digestsize
, state
->digest_buff
);
176 dev_dbg(dev
, "Mapped digest %d B at va=%pK to dma=%pad\n",
177 ctx
->inter_digestsize
, state
->digest_buff
,
178 &state
->digest_buff_dma_addr
);
180 if (ctx
->hw_mode
!= DRV_CIPHER_XCBC_MAC
) {
181 state
->digest_bytes_len_dma_addr
=
182 dma_map_single(dev
, state
->digest_bytes_len
,
183 HASH_MAX_LEN_SIZE
, DMA_BIDIRECTIONAL
);
184 if (dma_mapping_error(dev
, state
->digest_bytes_len_dma_addr
)) {
185 dev_err(dev
, "Mapping digest len %u B at va=%pK for DMA failed\n",
186 HASH_MAX_LEN_SIZE
, state
->digest_bytes_len
);
187 goto unmap_digest_buf
;
189 dev_dbg(dev
, "Mapped digest len %u B at va=%pK to dma=%pad\n",
190 HASH_MAX_LEN_SIZE
, state
->digest_bytes_len
,
191 &state
->digest_bytes_len_dma_addr
);
194 if (is_hmac
&& ctx
->hash_mode
!= DRV_HASH_NULL
) {
195 state
->opad_digest_dma_addr
=
196 dma_map_single(dev
, state
->opad_digest_buff
,
197 ctx
->inter_digestsize
,
199 if (dma_mapping_error(dev
, state
->opad_digest_dma_addr
)) {
200 dev_err(dev
, "Mapping opad digest %d B at va=%pK for DMA failed\n",
201 ctx
->inter_digestsize
,
202 state
->opad_digest_buff
);
203 goto unmap_digest_len
;
205 dev_dbg(dev
, "Mapped opad digest %d B at va=%pK to dma=%pad\n",
206 ctx
->inter_digestsize
, state
->opad_digest_buff
,
207 &state
->opad_digest_dma_addr
);
213 if (state
->digest_bytes_len_dma_addr
) {
214 dma_unmap_single(dev
, state
->digest_bytes_len_dma_addr
,
215 HASH_MAX_LEN_SIZE
, DMA_BIDIRECTIONAL
);
216 state
->digest_bytes_len_dma_addr
= 0;
219 if (state
->digest_buff_dma_addr
) {
220 dma_unmap_single(dev
, state
->digest_buff_dma_addr
,
221 ctx
->inter_digestsize
, DMA_BIDIRECTIONAL
);
222 state
->digest_buff_dma_addr
= 0;
228 static void cc_unmap_req(struct device
*dev
, struct ahash_req_ctx
*state
,
229 struct cc_hash_ctx
*ctx
)
231 if (state
->digest_buff_dma_addr
) {
232 dma_unmap_single(dev
, state
->digest_buff_dma_addr
,
233 ctx
->inter_digestsize
, DMA_BIDIRECTIONAL
);
234 dev_dbg(dev
, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n",
235 &state
->digest_buff_dma_addr
);
236 state
->digest_buff_dma_addr
= 0;
238 if (state
->digest_bytes_len_dma_addr
) {
239 dma_unmap_single(dev
, state
->digest_bytes_len_dma_addr
,
240 HASH_MAX_LEN_SIZE
, DMA_BIDIRECTIONAL
);
241 dev_dbg(dev
, "Unmapped digest-bytes-len buffer: digest_bytes_len_dma_addr=%pad\n",
242 &state
->digest_bytes_len_dma_addr
);
243 state
->digest_bytes_len_dma_addr
= 0;
245 if (state
->opad_digest_dma_addr
) {
246 dma_unmap_single(dev
, state
->opad_digest_dma_addr
,
247 ctx
->inter_digestsize
, DMA_BIDIRECTIONAL
);
248 dev_dbg(dev
, "Unmapped opad-digest: opad_digest_dma_addr=%pad\n",
249 &state
->opad_digest_dma_addr
);
250 state
->opad_digest_dma_addr
= 0;
254 static void cc_unmap_result(struct device
*dev
, struct ahash_req_ctx
*state
,
255 unsigned int digestsize
, u8
*result
)
257 if (state
->digest_result_dma_addr
) {
258 dma_unmap_single(dev
, state
->digest_result_dma_addr
, digestsize
,
260 dev_dbg(dev
, "unmpa digest result buffer va (%pK) pa (%pad) len %u\n",
261 state
->digest_result_buff
,
262 &state
->digest_result_dma_addr
, digestsize
);
263 memcpy(result
, state
->digest_result_buff
, digestsize
);
265 state
->digest_result_dma_addr
= 0;
268 static void cc_update_complete(struct device
*dev
, void *cc_req
, int err
)
270 struct ahash_request
*req
= (struct ahash_request
*)cc_req
;
271 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
272 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
273 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
275 dev_dbg(dev
, "req=%pK\n", req
);
277 cc_unmap_hash_request(dev
, state
, req
->src
, false);
278 cc_unmap_req(dev
, state
, ctx
);
279 req
->base
.complete(&req
->base
, err
);
282 static void cc_digest_complete(struct device
*dev
, void *cc_req
, int err
)
284 struct ahash_request
*req
= (struct ahash_request
*)cc_req
;
285 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
286 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
287 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
288 u32 digestsize
= crypto_ahash_digestsize(tfm
);
290 dev_dbg(dev
, "req=%pK\n", req
);
292 cc_unmap_hash_request(dev
, state
, req
->src
, false);
293 cc_unmap_result(dev
, state
, digestsize
, req
->result
);
294 cc_unmap_req(dev
, state
, ctx
);
295 req
->base
.complete(&req
->base
, err
);
298 static void cc_hash_complete(struct device
*dev
, void *cc_req
, int err
)
300 struct ahash_request
*req
= (struct ahash_request
*)cc_req
;
301 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
302 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
303 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
304 u32 digestsize
= crypto_ahash_digestsize(tfm
);
306 dev_dbg(dev
, "req=%pK\n", req
);
308 cc_unmap_hash_request(dev
, state
, req
->src
, false);
309 cc_unmap_result(dev
, state
, digestsize
, req
->result
);
310 cc_unmap_req(dev
, state
, ctx
);
311 req
->base
.complete(&req
->base
, err
);
314 static int cc_fin_result(struct cc_hw_desc
*desc
, struct ahash_request
*req
,
317 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
318 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
319 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
320 u32 digestsize
= crypto_ahash_digestsize(tfm
);
322 /* Get final MAC result */
323 hw_desc_init(&desc
[idx
]);
324 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
326 set_dout_dlli(&desc
[idx
], state
->digest_result_dma_addr
, digestsize
,
328 set_queue_last_ind(ctx
->drvdata
, &desc
[idx
]);
329 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
330 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
331 set_cipher_config1(&desc
[idx
], HASH_PADDING_DISABLED
);
332 cc_set_endianity(ctx
->hash_mode
, &desc
[idx
]);
338 static int cc_fin_hmac(struct cc_hw_desc
*desc
, struct ahash_request
*req
,
341 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
342 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
343 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
344 u32 digestsize
= crypto_ahash_digestsize(tfm
);
346 /* store the hash digest result in the context */
347 hw_desc_init(&desc
[idx
]);
348 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
349 set_dout_dlli(&desc
[idx
], state
->digest_buff_dma_addr
, digestsize
,
351 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
352 cc_set_endianity(ctx
->hash_mode
, &desc
[idx
]);
353 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
356 /* Loading hash opad xor key state */
357 hw_desc_init(&desc
[idx
]);
358 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
359 set_din_type(&desc
[idx
], DMA_DLLI
, state
->opad_digest_dma_addr
,
360 ctx
->inter_digestsize
, NS_BIT
);
361 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
362 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
365 /* Load the hash current length */
366 hw_desc_init(&desc
[idx
]);
367 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
368 set_din_sram(&desc
[idx
],
369 cc_digest_len_addr(ctx
->drvdata
, ctx
->hash_mode
),
370 ctx
->drvdata
->hash_len_sz
);
371 set_cipher_config1(&desc
[idx
], HASH_PADDING_ENABLED
);
372 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
373 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
376 /* Memory Barrier: wait for IPAD/OPAD axi write to complete */
377 hw_desc_init(&desc
[idx
]);
378 set_din_no_dma(&desc
[idx
], 0, 0xfffff0);
379 set_dout_no_dma(&desc
[idx
], 0, 0, 1);
382 /* Perform HASH update */
383 hw_desc_init(&desc
[idx
]);
384 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_buff_dma_addr
,
386 set_flow_mode(&desc
[idx
], DIN_HASH
);
392 static int cc_hash_digest(struct ahash_request
*req
)
394 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
395 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
396 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
397 u32 digestsize
= crypto_ahash_digestsize(tfm
);
398 struct scatterlist
*src
= req
->src
;
399 unsigned int nbytes
= req
->nbytes
;
400 u8
*result
= req
->result
;
401 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
402 bool is_hmac
= ctx
->is_hmac
;
403 struct cc_crypto_req cc_req
= {};
404 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
405 cc_sram_addr_t larval_digest_addr
=
406 cc_larval_digest_addr(ctx
->drvdata
, ctx
->hash_mode
);
409 gfp_t flags
= cc_gfp_flags(&req
->base
);
411 dev_dbg(dev
, "===== %s-digest (%d) ====\n", is_hmac
? "hmac" : "hash",
414 cc_init_req(dev
, state
, ctx
);
416 if (cc_map_req(dev
, state
, ctx
)) {
417 dev_err(dev
, "map_ahash_source() failed\n");
421 if (cc_map_result(dev
, state
, digestsize
)) {
422 dev_err(dev
, "map_ahash_digest() failed\n");
423 cc_unmap_req(dev
, state
, ctx
);
427 if (cc_map_hash_request_final(ctx
->drvdata
, state
, src
, nbytes
, 1,
429 dev_err(dev
, "map_ahash_request_final() failed\n");
430 cc_unmap_result(dev
, state
, digestsize
, result
);
431 cc_unmap_req(dev
, state
, ctx
);
435 /* Setup request structure */
436 cc_req
.user_cb
= cc_digest_complete
;
437 cc_req
.user_arg
= req
;
439 /* If HMAC then load hash IPAD xor key, if HASH then load initial
442 hw_desc_init(&desc
[idx
]);
443 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
445 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_buff_dma_addr
,
446 ctx
->inter_digestsize
, NS_BIT
);
448 set_din_sram(&desc
[idx
], larval_digest_addr
,
449 ctx
->inter_digestsize
);
451 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
452 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
455 /* Load the hash current length */
456 hw_desc_init(&desc
[idx
]);
457 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
460 set_din_type(&desc
[idx
], DMA_DLLI
,
461 state
->digest_bytes_len_dma_addr
,
462 ctx
->drvdata
->hash_len_sz
, NS_BIT
);
464 set_din_const(&desc
[idx
], 0, ctx
->drvdata
->hash_len_sz
);
466 set_cipher_config1(&desc
[idx
], HASH_PADDING_ENABLED
);
468 set_cipher_do(&desc
[idx
], DO_PAD
);
470 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
471 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
474 cc_set_desc(state
, ctx
, DIN_HASH
, desc
, false, &idx
);
477 /* HW last hash block padding (aka. "DO_PAD") */
478 hw_desc_init(&desc
[idx
]);
479 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
480 set_dout_dlli(&desc
[idx
], state
->digest_buff_dma_addr
,
481 ctx
->drvdata
->hash_len_sz
, NS_BIT
, 0);
482 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
483 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE1
);
484 set_cipher_do(&desc
[idx
], DO_PAD
);
487 idx
= cc_fin_hmac(desc
, req
, idx
);
490 idx
= cc_fin_result(desc
, req
, idx
);
492 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
493 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
494 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
495 cc_unmap_hash_request(dev
, state
, src
, true);
496 cc_unmap_result(dev
, state
, digestsize
, result
);
497 cc_unmap_req(dev
, state
, ctx
);
502 static int cc_restore_hash(struct cc_hw_desc
*desc
, struct cc_hash_ctx
*ctx
,
503 struct ahash_req_ctx
*state
, unsigned int idx
)
505 /* Restore hash digest */
506 hw_desc_init(&desc
[idx
]);
507 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
508 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_buff_dma_addr
,
509 ctx
->inter_digestsize
, NS_BIT
);
510 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
511 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
514 /* Restore hash current length */
515 hw_desc_init(&desc
[idx
]);
516 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
517 set_cipher_config1(&desc
[idx
], HASH_PADDING_DISABLED
);
518 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_bytes_len_dma_addr
,
519 ctx
->drvdata
->hash_len_sz
, NS_BIT
);
520 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
521 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
524 cc_set_desc(state
, ctx
, DIN_HASH
, desc
, false, &idx
);
529 static int cc_hash_update(struct ahash_request
*req
)
531 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
532 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
533 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
534 unsigned int block_size
= crypto_tfm_alg_blocksize(&tfm
->base
);
535 struct scatterlist
*src
= req
->src
;
536 unsigned int nbytes
= req
->nbytes
;
537 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
538 struct cc_crypto_req cc_req
= {};
539 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
542 gfp_t flags
= cc_gfp_flags(&req
->base
);
544 dev_dbg(dev
, "===== %s-update (%d) ====\n", ctx
->is_hmac
?
545 "hmac" : "hash", nbytes
);
548 /* no real updates required */
552 rc
= cc_map_hash_request_update(ctx
->drvdata
, state
, src
, nbytes
,
556 dev_dbg(dev
, " data size not require HW update %x\n",
558 /* No hardware updates are required */
561 dev_err(dev
, "map_ahash_request_update() failed\n");
565 if (cc_map_req(dev
, state
, ctx
)) {
566 dev_err(dev
, "map_ahash_source() failed\n");
567 cc_unmap_hash_request(dev
, state
, src
, true);
571 /* Setup request structure */
572 cc_req
.user_cb
= cc_update_complete
;
573 cc_req
.user_arg
= req
;
575 idx
= cc_restore_hash(desc
, ctx
, state
, idx
);
577 /* store the hash digest result in context */
578 hw_desc_init(&desc
[idx
]);
579 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
580 set_dout_dlli(&desc
[idx
], state
->digest_buff_dma_addr
,
581 ctx
->inter_digestsize
, NS_BIT
, 0);
582 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
583 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
586 /* store current hash length in context */
587 hw_desc_init(&desc
[idx
]);
588 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
589 set_dout_dlli(&desc
[idx
], state
->digest_bytes_len_dma_addr
,
590 ctx
->drvdata
->hash_len_sz
, NS_BIT
, 1);
591 set_queue_last_ind(ctx
->drvdata
, &desc
[idx
]);
592 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
593 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE1
);
596 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
597 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
598 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
599 cc_unmap_hash_request(dev
, state
, src
, true);
600 cc_unmap_req(dev
, state
, ctx
);
605 static int cc_hash_finup(struct ahash_request
*req
)
607 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
608 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
609 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
610 u32 digestsize
= crypto_ahash_digestsize(tfm
);
611 struct scatterlist
*src
= req
->src
;
612 unsigned int nbytes
= req
->nbytes
;
613 u8
*result
= req
->result
;
614 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
615 bool is_hmac
= ctx
->is_hmac
;
616 struct cc_crypto_req cc_req
= {};
617 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
618 unsigned int idx
= 0;
620 gfp_t flags
= cc_gfp_flags(&req
->base
);
622 dev_dbg(dev
, "===== %s-finup (%d) ====\n", is_hmac
? "hmac" : "hash",
625 if (cc_map_req(dev
, state
, ctx
)) {
626 dev_err(dev
, "map_ahash_source() failed\n");
630 if (cc_map_hash_request_final(ctx
->drvdata
, state
, src
, nbytes
, 1,
632 dev_err(dev
, "map_ahash_request_final() failed\n");
633 cc_unmap_req(dev
, state
, ctx
);
636 if (cc_map_result(dev
, state
, digestsize
)) {
637 dev_err(dev
, "map_ahash_digest() failed\n");
638 cc_unmap_hash_request(dev
, state
, src
, true);
639 cc_unmap_req(dev
, state
, ctx
);
643 /* Setup request structure */
644 cc_req
.user_cb
= cc_hash_complete
;
645 cc_req
.user_arg
= req
;
647 idx
= cc_restore_hash(desc
, ctx
, state
, idx
);
650 idx
= cc_fin_hmac(desc
, req
, idx
);
652 idx
= cc_fin_result(desc
, req
, idx
);
654 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
655 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
656 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
657 cc_unmap_hash_request(dev
, state
, src
, true);
658 cc_unmap_result(dev
, state
, digestsize
, result
);
659 cc_unmap_req(dev
, state
, ctx
);
664 static int cc_hash_final(struct ahash_request
*req
)
666 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
667 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
668 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
669 u32 digestsize
= crypto_ahash_digestsize(tfm
);
670 struct scatterlist
*src
= req
->src
;
671 unsigned int nbytes
= req
->nbytes
;
672 u8
*result
= req
->result
;
673 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
674 bool is_hmac
= ctx
->is_hmac
;
675 struct cc_crypto_req cc_req
= {};
676 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
677 unsigned int idx
= 0;
679 gfp_t flags
= cc_gfp_flags(&req
->base
);
681 dev_dbg(dev
, "===== %s-final (%d) ====\n", is_hmac
? "hmac" : "hash",
684 if (cc_map_req(dev
, state
, ctx
)) {
685 dev_err(dev
, "map_ahash_source() failed\n");
689 if (cc_map_hash_request_final(ctx
->drvdata
, state
, src
, nbytes
, 0,
691 dev_err(dev
, "map_ahash_request_final() failed\n");
692 cc_unmap_req(dev
, state
, ctx
);
696 if (cc_map_result(dev
, state
, digestsize
)) {
697 dev_err(dev
, "map_ahash_digest() failed\n");
698 cc_unmap_hash_request(dev
, state
, src
, true);
699 cc_unmap_req(dev
, state
, ctx
);
703 /* Setup request structure */
704 cc_req
.user_cb
= cc_hash_complete
;
705 cc_req
.user_arg
= req
;
707 idx
= cc_restore_hash(desc
, ctx
, state
, idx
);
709 /* "DO-PAD" must be enabled only when writing current length to HW */
710 hw_desc_init(&desc
[idx
]);
711 set_cipher_do(&desc
[idx
], DO_PAD
);
712 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
713 set_dout_dlli(&desc
[idx
], state
->digest_bytes_len_dma_addr
,
714 ctx
->drvdata
->hash_len_sz
, NS_BIT
, 0);
715 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE1
);
716 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
720 idx
= cc_fin_hmac(desc
, req
, idx
);
722 idx
= cc_fin_result(desc
, req
, idx
);
724 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
725 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
726 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
727 cc_unmap_hash_request(dev
, state
, src
, true);
728 cc_unmap_result(dev
, state
, digestsize
, result
);
729 cc_unmap_req(dev
, state
, ctx
);
734 static int cc_hash_init(struct ahash_request
*req
)
736 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
737 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
738 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
739 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
741 dev_dbg(dev
, "===== init (%d) ====\n", req
->nbytes
);
743 cc_init_req(dev
, state
, ctx
);
748 static int cc_hash_setkey(struct crypto_ahash
*ahash
, const u8
*key
,
751 unsigned int hmac_pad_const
[2] = { HMAC_IPAD_CONST
, HMAC_OPAD_CONST
};
752 struct cc_crypto_req cc_req
= {};
753 struct cc_hash_ctx
*ctx
= NULL
;
756 int i
, idx
= 0, rc
= 0;
757 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
758 cc_sram_addr_t larval_addr
;
761 ctx
= crypto_ahash_ctx(ahash
);
762 dev
= drvdata_to_dev(ctx
->drvdata
);
763 dev_dbg(dev
, "start keylen: %d", keylen
);
765 blocksize
= crypto_tfm_alg_blocksize(&ahash
->base
);
766 digestsize
= crypto_ahash_digestsize(ahash
);
768 larval_addr
= cc_larval_digest_addr(ctx
->drvdata
, ctx
->hash_mode
);
770 /* The keylen value distinguishes HASH in case keylen is ZERO bytes,
771 * any NON-ZERO value utilizes HMAC flow
773 ctx
->key_params
.keylen
= keylen
;
774 ctx
->key_params
.key_dma_addr
= 0;
778 ctx
->key_params
.key_dma_addr
=
779 dma_map_single(dev
, (void *)key
, keylen
, DMA_TO_DEVICE
);
780 if (dma_mapping_error(dev
, ctx
->key_params
.key_dma_addr
)) {
781 dev_err(dev
, "Mapping key va=0x%p len=%u for DMA failed\n",
785 dev_dbg(dev
, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n",
786 &ctx
->key_params
.key_dma_addr
, ctx
->key_params
.keylen
);
788 if (keylen
> blocksize
) {
789 /* Load hash initial state */
790 hw_desc_init(&desc
[idx
]);
791 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
792 set_din_sram(&desc
[idx
], larval_addr
,
793 ctx
->inter_digestsize
);
794 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
795 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
798 /* Load the hash current length*/
799 hw_desc_init(&desc
[idx
]);
800 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
801 set_din_const(&desc
[idx
], 0, ctx
->drvdata
->hash_len_sz
);
802 set_cipher_config1(&desc
[idx
], HASH_PADDING_ENABLED
);
803 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
804 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
807 hw_desc_init(&desc
[idx
]);
808 set_din_type(&desc
[idx
], DMA_DLLI
,
809 ctx
->key_params
.key_dma_addr
, keylen
,
811 set_flow_mode(&desc
[idx
], DIN_HASH
);
815 hw_desc_init(&desc
[idx
]);
816 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
817 set_dout_dlli(&desc
[idx
], ctx
->opad_tmp_keys_dma_addr
,
818 digestsize
, NS_BIT
, 0);
819 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
820 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
821 set_cipher_config1(&desc
[idx
], HASH_PADDING_DISABLED
);
822 cc_set_endianity(ctx
->hash_mode
, &desc
[idx
]);
825 hw_desc_init(&desc
[idx
]);
826 set_din_const(&desc
[idx
], 0, (blocksize
- digestsize
));
827 set_flow_mode(&desc
[idx
], BYPASS
);
828 set_dout_dlli(&desc
[idx
],
829 (ctx
->opad_tmp_keys_dma_addr
+
831 (blocksize
- digestsize
), NS_BIT
, 0);
834 hw_desc_init(&desc
[idx
]);
835 set_din_type(&desc
[idx
], DMA_DLLI
,
836 ctx
->key_params
.key_dma_addr
, keylen
,
838 set_flow_mode(&desc
[idx
], BYPASS
);
839 set_dout_dlli(&desc
[idx
], ctx
->opad_tmp_keys_dma_addr
,
843 if ((blocksize
- keylen
)) {
844 hw_desc_init(&desc
[idx
]);
845 set_din_const(&desc
[idx
], 0,
846 (blocksize
- keylen
));
847 set_flow_mode(&desc
[idx
], BYPASS
);
848 set_dout_dlli(&desc
[idx
],
849 (ctx
->opad_tmp_keys_dma_addr
+
850 keylen
), (blocksize
- keylen
),
856 hw_desc_init(&desc
[idx
]);
857 set_din_const(&desc
[idx
], 0, blocksize
);
858 set_flow_mode(&desc
[idx
], BYPASS
);
859 set_dout_dlli(&desc
[idx
], (ctx
->opad_tmp_keys_dma_addr
),
860 blocksize
, NS_BIT
, 0);
864 rc
= cc_send_sync_request(ctx
->drvdata
, &cc_req
, desc
, idx
);
866 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
870 /* calc derived HMAC key */
871 for (idx
= 0, i
= 0; i
< 2; i
++) {
872 /* Load hash initial state */
873 hw_desc_init(&desc
[idx
]);
874 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
875 set_din_sram(&desc
[idx
], larval_addr
, ctx
->inter_digestsize
);
876 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
877 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
880 /* Load the hash current length*/
881 hw_desc_init(&desc
[idx
]);
882 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
883 set_din_const(&desc
[idx
], 0, ctx
->drvdata
->hash_len_sz
);
884 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
885 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
888 /* Prepare ipad key */
889 hw_desc_init(&desc
[idx
]);
890 set_xor_val(&desc
[idx
], hmac_pad_const
[i
]);
891 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
892 set_flow_mode(&desc
[idx
], S_DIN_to_HASH
);
893 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE1
);
896 /* Perform HASH update */
897 hw_desc_init(&desc
[idx
]);
898 set_din_type(&desc
[idx
], DMA_DLLI
, ctx
->opad_tmp_keys_dma_addr
,
900 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
901 set_xor_active(&desc
[idx
]);
902 set_flow_mode(&desc
[idx
], DIN_HASH
);
905 /* Get the IPAD/OPAD xor key (Note, IPAD is the initial digest
906 * of the first HASH "update" state)
908 hw_desc_init(&desc
[idx
]);
909 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
910 if (i
> 0) /* Not first iteration */
911 set_dout_dlli(&desc
[idx
], ctx
->opad_tmp_keys_dma_addr
,
912 ctx
->inter_digestsize
, NS_BIT
, 0);
913 else /* First iteration */
914 set_dout_dlli(&desc
[idx
], ctx
->digest_buff_dma_addr
,
915 ctx
->inter_digestsize
, NS_BIT
, 0);
916 set_flow_mode(&desc
[idx
], S_HASH_to_DOUT
);
917 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
921 rc
= cc_send_sync_request(ctx
->drvdata
, &cc_req
, desc
, idx
);
925 crypto_ahash_set_flags(ahash
, CRYPTO_TFM_RES_BAD_KEY_LEN
);
927 if (ctx
->key_params
.key_dma_addr
) {
928 dma_unmap_single(dev
, ctx
->key_params
.key_dma_addr
,
929 ctx
->key_params
.keylen
, DMA_TO_DEVICE
);
930 dev_dbg(dev
, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n",
931 &ctx
->key_params
.key_dma_addr
, ctx
->key_params
.keylen
);
936 static int cc_xcbc_setkey(struct crypto_ahash
*ahash
,
937 const u8
*key
, unsigned int keylen
)
939 struct cc_crypto_req cc_req
= {};
940 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(ahash
);
941 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
943 unsigned int idx
= 0;
944 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
946 dev_dbg(dev
, "===== setkey (%d) ====\n", keylen
);
949 case AES_KEYSIZE_128
:
950 case AES_KEYSIZE_192
:
951 case AES_KEYSIZE_256
:
957 ctx
->key_params
.keylen
= keylen
;
959 ctx
->key_params
.key_dma_addr
=
960 dma_map_single(dev
, (void *)key
, keylen
, DMA_TO_DEVICE
);
961 if (dma_mapping_error(dev
, ctx
->key_params
.key_dma_addr
)) {
962 dev_err(dev
, "Mapping key va=0x%p len=%u for DMA failed\n",
966 dev_dbg(dev
, "mapping key-buffer: key_dma_addr=%pad keylen=%u\n",
967 &ctx
->key_params
.key_dma_addr
, ctx
->key_params
.keylen
);
970 /* 1. Load the AES key */
971 hw_desc_init(&desc
[idx
]);
972 set_din_type(&desc
[idx
], DMA_DLLI
, ctx
->key_params
.key_dma_addr
,
974 set_cipher_mode(&desc
[idx
], DRV_CIPHER_ECB
);
975 set_cipher_config0(&desc
[idx
], DRV_CRYPTO_DIRECTION_ENCRYPT
);
976 set_key_size_aes(&desc
[idx
], keylen
);
977 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
978 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
981 hw_desc_init(&desc
[idx
]);
982 set_din_const(&desc
[idx
], 0x01010101, CC_AES_128_BIT_KEY_SIZE
);
983 set_flow_mode(&desc
[idx
], DIN_AES_DOUT
);
984 set_dout_dlli(&desc
[idx
],
985 (ctx
->opad_tmp_keys_dma_addr
+ XCBC_MAC_K1_OFFSET
),
986 CC_AES_128_BIT_KEY_SIZE
, NS_BIT
, 0);
989 hw_desc_init(&desc
[idx
]);
990 set_din_const(&desc
[idx
], 0x02020202, CC_AES_128_BIT_KEY_SIZE
);
991 set_flow_mode(&desc
[idx
], DIN_AES_DOUT
);
992 set_dout_dlli(&desc
[idx
],
993 (ctx
->opad_tmp_keys_dma_addr
+ XCBC_MAC_K2_OFFSET
),
994 CC_AES_128_BIT_KEY_SIZE
, NS_BIT
, 0);
997 hw_desc_init(&desc
[idx
]);
998 set_din_const(&desc
[idx
], 0x03030303, CC_AES_128_BIT_KEY_SIZE
);
999 set_flow_mode(&desc
[idx
], DIN_AES_DOUT
);
1000 set_dout_dlli(&desc
[idx
],
1001 (ctx
->opad_tmp_keys_dma_addr
+ XCBC_MAC_K3_OFFSET
),
1002 CC_AES_128_BIT_KEY_SIZE
, NS_BIT
, 0);
1005 rc
= cc_send_sync_request(ctx
->drvdata
, &cc_req
, desc
, idx
);
1008 crypto_ahash_set_flags(ahash
, CRYPTO_TFM_RES_BAD_KEY_LEN
);
1010 dma_unmap_single(dev
, ctx
->key_params
.key_dma_addr
,
1011 ctx
->key_params
.keylen
, DMA_TO_DEVICE
);
1012 dev_dbg(dev
, "Unmapped key-buffer: key_dma_addr=%pad keylen=%u\n",
1013 &ctx
->key_params
.key_dma_addr
, ctx
->key_params
.keylen
);
1018 static int cc_cmac_setkey(struct crypto_ahash
*ahash
,
1019 const u8
*key
, unsigned int keylen
)
1021 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(ahash
);
1022 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1024 dev_dbg(dev
, "===== setkey (%d) ====\n", keylen
);
1026 ctx
->is_hmac
= true;
1029 case AES_KEYSIZE_128
:
1030 case AES_KEYSIZE_192
:
1031 case AES_KEYSIZE_256
:
1037 ctx
->key_params
.keylen
= keylen
;
1039 /* STAT_PHASE_1: Copy key to ctx */
1041 dma_sync_single_for_cpu(dev
, ctx
->opad_tmp_keys_dma_addr
,
1042 keylen
, DMA_TO_DEVICE
);
1044 memcpy(ctx
->opad_tmp_keys_buff
, key
, keylen
);
1046 memset(ctx
->opad_tmp_keys_buff
+ 24, 0,
1047 CC_AES_KEY_SIZE_MAX
- 24);
1050 dma_sync_single_for_device(dev
, ctx
->opad_tmp_keys_dma_addr
,
1051 keylen
, DMA_TO_DEVICE
);
1053 ctx
->key_params
.keylen
= keylen
;
1058 static void cc_free_ctx(struct cc_hash_ctx
*ctx
)
1060 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1062 if (ctx
->digest_buff_dma_addr
) {
1063 dma_unmap_single(dev
, ctx
->digest_buff_dma_addr
,
1064 sizeof(ctx
->digest_buff
), DMA_BIDIRECTIONAL
);
1065 dev_dbg(dev
, "Unmapped digest-buffer: digest_buff_dma_addr=%pad\n",
1066 &ctx
->digest_buff_dma_addr
);
1067 ctx
->digest_buff_dma_addr
= 0;
1069 if (ctx
->opad_tmp_keys_dma_addr
) {
1070 dma_unmap_single(dev
, ctx
->opad_tmp_keys_dma_addr
,
1071 sizeof(ctx
->opad_tmp_keys_buff
),
1073 dev_dbg(dev
, "Unmapped opad-digest: opad_tmp_keys_dma_addr=%pad\n",
1074 &ctx
->opad_tmp_keys_dma_addr
);
1075 ctx
->opad_tmp_keys_dma_addr
= 0;
1078 ctx
->key_params
.keylen
= 0;
1081 static int cc_alloc_ctx(struct cc_hash_ctx
*ctx
)
1083 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1085 ctx
->key_params
.keylen
= 0;
1087 ctx
->digest_buff_dma_addr
=
1088 dma_map_single(dev
, (void *)ctx
->digest_buff
,
1089 sizeof(ctx
->digest_buff
), DMA_BIDIRECTIONAL
);
1090 if (dma_mapping_error(dev
, ctx
->digest_buff_dma_addr
)) {
1091 dev_err(dev
, "Mapping digest len %zu B at va=%pK for DMA failed\n",
1092 sizeof(ctx
->digest_buff
), ctx
->digest_buff
);
1095 dev_dbg(dev
, "Mapped digest %zu B at va=%pK to dma=%pad\n",
1096 sizeof(ctx
->digest_buff
), ctx
->digest_buff
,
1097 &ctx
->digest_buff_dma_addr
);
1099 ctx
->opad_tmp_keys_dma_addr
=
1100 dma_map_single(dev
, (void *)ctx
->opad_tmp_keys_buff
,
1101 sizeof(ctx
->opad_tmp_keys_buff
),
1103 if (dma_mapping_error(dev
, ctx
->opad_tmp_keys_dma_addr
)) {
1104 dev_err(dev
, "Mapping opad digest %zu B at va=%pK for DMA failed\n",
1105 sizeof(ctx
->opad_tmp_keys_buff
),
1106 ctx
->opad_tmp_keys_buff
);
1109 dev_dbg(dev
, "Mapped opad_tmp_keys %zu B at va=%pK to dma=%pad\n",
1110 sizeof(ctx
->opad_tmp_keys_buff
), ctx
->opad_tmp_keys_buff
,
1111 &ctx
->opad_tmp_keys_dma_addr
);
1113 ctx
->is_hmac
= false;
1121 static int cc_cra_init(struct crypto_tfm
*tfm
)
1123 struct cc_hash_ctx
*ctx
= crypto_tfm_ctx(tfm
);
1124 struct hash_alg_common
*hash_alg_common
=
1125 container_of(tfm
->__crt_alg
, struct hash_alg_common
, base
);
1126 struct ahash_alg
*ahash_alg
=
1127 container_of(hash_alg_common
, struct ahash_alg
, halg
);
1128 struct cc_hash_alg
*cc_alg
=
1129 container_of(ahash_alg
, struct cc_hash_alg
, ahash_alg
);
1131 crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm
),
1132 sizeof(struct ahash_req_ctx
));
1134 ctx
->hash_mode
= cc_alg
->hash_mode
;
1135 ctx
->hw_mode
= cc_alg
->hw_mode
;
1136 ctx
->inter_digestsize
= cc_alg
->inter_digestsize
;
1137 ctx
->drvdata
= cc_alg
->drvdata
;
1139 return cc_alloc_ctx(ctx
);
1142 static void cc_cra_exit(struct crypto_tfm
*tfm
)
1144 struct cc_hash_ctx
*ctx
= crypto_tfm_ctx(tfm
);
1145 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1147 dev_dbg(dev
, "cc_cra_exit");
1151 static int cc_mac_update(struct ahash_request
*req
)
1153 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
1154 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
1155 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
1156 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1157 unsigned int block_size
= crypto_tfm_alg_blocksize(&tfm
->base
);
1158 struct cc_crypto_req cc_req
= {};
1159 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
1162 gfp_t flags
= cc_gfp_flags(&req
->base
);
1164 if (req
->nbytes
== 0) {
1165 /* no real updates required */
1169 state
->xcbc_count
++;
1171 rc
= cc_map_hash_request_update(ctx
->drvdata
, state
, req
->src
,
1172 req
->nbytes
, block_size
, flags
);
1175 dev_dbg(dev
, " data size not require HW update %x\n",
1177 /* No hardware updates are required */
1180 dev_err(dev
, "map_ahash_request_update() failed\n");
1184 if (cc_map_req(dev
, state
, ctx
)) {
1185 dev_err(dev
, "map_ahash_source() failed\n");
1189 if (ctx
->hw_mode
== DRV_CIPHER_XCBC_MAC
)
1190 cc_setup_xcbc(req
, desc
, &idx
);
1192 cc_setup_cmac(req
, desc
, &idx
);
1194 cc_set_desc(state
, ctx
, DIN_AES_DOUT
, desc
, true, &idx
);
1196 /* store the hash digest result in context */
1197 hw_desc_init(&desc
[idx
]);
1198 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1199 set_dout_dlli(&desc
[idx
], state
->digest_buff_dma_addr
,
1200 ctx
->inter_digestsize
, NS_BIT
, 1);
1201 set_queue_last_ind(ctx
->drvdata
, &desc
[idx
]);
1202 set_flow_mode(&desc
[idx
], S_AES_to_DOUT
);
1203 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
1206 /* Setup request structure */
1207 cc_req
.user_cb
= (void *)cc_update_complete
;
1208 cc_req
.user_arg
= (void *)req
;
1210 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
1211 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
1212 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
1213 cc_unmap_hash_request(dev
, state
, req
->src
, true);
1214 cc_unmap_req(dev
, state
, ctx
);
1219 static int cc_mac_final(struct ahash_request
*req
)
1221 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
1222 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
1223 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
1224 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1225 struct cc_crypto_req cc_req
= {};
1226 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
1229 u32 key_size
, key_len
;
1230 u32 digestsize
= crypto_ahash_digestsize(tfm
);
1231 gfp_t flags
= cc_gfp_flags(&req
->base
);
1232 u32 rem_cnt
= *cc_hash_buf_cnt(state
);
1234 if (ctx
->hw_mode
== DRV_CIPHER_XCBC_MAC
) {
1235 key_size
= CC_AES_128_BIT_KEY_SIZE
;
1236 key_len
= CC_AES_128_BIT_KEY_SIZE
;
1238 key_size
= (ctx
->key_params
.keylen
== 24) ? AES_MAX_KEY_SIZE
:
1239 ctx
->key_params
.keylen
;
1240 key_len
= ctx
->key_params
.keylen
;
1243 dev_dbg(dev
, "===== final xcbc reminder (%d) ====\n", rem_cnt
);
1245 if (cc_map_req(dev
, state
, ctx
)) {
1246 dev_err(dev
, "map_ahash_source() failed\n");
1250 if (cc_map_hash_request_final(ctx
->drvdata
, state
, req
->src
,
1251 req
->nbytes
, 0, flags
)) {
1252 dev_err(dev
, "map_ahash_request_final() failed\n");
1253 cc_unmap_req(dev
, state
, ctx
);
1257 if (cc_map_result(dev
, state
, digestsize
)) {
1258 dev_err(dev
, "map_ahash_digest() failed\n");
1259 cc_unmap_hash_request(dev
, state
, req
->src
, true);
1260 cc_unmap_req(dev
, state
, ctx
);
1264 /* Setup request structure */
1265 cc_req
.user_cb
= (void *)cc_hash_complete
;
1266 cc_req
.user_arg
= (void *)req
;
1268 if (state
->xcbc_count
&& rem_cnt
== 0) {
1269 /* Load key for ECB decryption */
1270 hw_desc_init(&desc
[idx
]);
1271 set_cipher_mode(&desc
[idx
], DRV_CIPHER_ECB
);
1272 set_cipher_config0(&desc
[idx
], DRV_CRYPTO_DIRECTION_DECRYPT
);
1273 set_din_type(&desc
[idx
], DMA_DLLI
,
1274 (ctx
->opad_tmp_keys_dma_addr
+ XCBC_MAC_K1_OFFSET
),
1276 set_key_size_aes(&desc
[idx
], key_len
);
1277 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
1278 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
1281 /* Initiate decryption of block state to previous
1282 * block_state-XOR-M[n]
1284 hw_desc_init(&desc
[idx
]);
1285 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_buff_dma_addr
,
1286 CC_AES_BLOCK_SIZE
, NS_BIT
);
1287 set_dout_dlli(&desc
[idx
], state
->digest_buff_dma_addr
,
1288 CC_AES_BLOCK_SIZE
, NS_BIT
, 0);
1289 set_flow_mode(&desc
[idx
], DIN_AES_DOUT
);
1292 /* Memory Barrier: wait for axi write to complete */
1293 hw_desc_init(&desc
[idx
]);
1294 set_din_no_dma(&desc
[idx
], 0, 0xfffff0);
1295 set_dout_no_dma(&desc
[idx
], 0, 0, 1);
1299 if (ctx
->hw_mode
== DRV_CIPHER_XCBC_MAC
)
1300 cc_setup_xcbc(req
, desc
, &idx
);
1302 cc_setup_cmac(req
, desc
, &idx
);
1304 if (state
->xcbc_count
== 0) {
1305 hw_desc_init(&desc
[idx
]);
1306 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1307 set_key_size_aes(&desc
[idx
], key_len
);
1308 set_cmac_size0_mode(&desc
[idx
]);
1309 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
1311 } else if (rem_cnt
> 0) {
1312 cc_set_desc(state
, ctx
, DIN_AES_DOUT
, desc
, false, &idx
);
1314 hw_desc_init(&desc
[idx
]);
1315 set_din_const(&desc
[idx
], 0x00, CC_AES_BLOCK_SIZE
);
1316 set_flow_mode(&desc
[idx
], DIN_AES_DOUT
);
1320 /* Get final MAC result */
1321 hw_desc_init(&desc
[idx
]);
1323 set_dout_dlli(&desc
[idx
], state
->digest_result_dma_addr
,
1324 digestsize
, NS_BIT
, 1);
1325 set_queue_last_ind(ctx
->drvdata
, &desc
[idx
]);
1326 set_flow_mode(&desc
[idx
], S_AES_to_DOUT
);
1327 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
1328 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1331 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
1332 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
1333 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
1334 cc_unmap_hash_request(dev
, state
, req
->src
, true);
1335 cc_unmap_result(dev
, state
, digestsize
, req
->result
);
1336 cc_unmap_req(dev
, state
, ctx
);
1341 static int cc_mac_finup(struct ahash_request
*req
)
1343 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
1344 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
1345 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
1346 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1347 struct cc_crypto_req cc_req
= {};
1348 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
1352 u32 digestsize
= crypto_ahash_digestsize(tfm
);
1353 gfp_t flags
= cc_gfp_flags(&req
->base
);
1355 dev_dbg(dev
, "===== finup xcbc(%d) ====\n", req
->nbytes
);
1356 if (state
->xcbc_count
> 0 && req
->nbytes
== 0) {
1357 dev_dbg(dev
, "No data to update. Call to fdx_mac_final\n");
1358 return cc_mac_final(req
);
1361 if (cc_map_req(dev
, state
, ctx
)) {
1362 dev_err(dev
, "map_ahash_source() failed\n");
1366 if (cc_map_hash_request_final(ctx
->drvdata
, state
, req
->src
,
1367 req
->nbytes
, 1, flags
)) {
1368 dev_err(dev
, "map_ahash_request_final() failed\n");
1369 cc_unmap_req(dev
, state
, ctx
);
1372 if (cc_map_result(dev
, state
, digestsize
)) {
1373 dev_err(dev
, "map_ahash_digest() failed\n");
1374 cc_unmap_hash_request(dev
, state
, req
->src
, true);
1375 cc_unmap_req(dev
, state
, ctx
);
1379 /* Setup request structure */
1380 cc_req
.user_cb
= (void *)cc_hash_complete
;
1381 cc_req
.user_arg
= (void *)req
;
1383 if (ctx
->hw_mode
== DRV_CIPHER_XCBC_MAC
) {
1384 key_len
= CC_AES_128_BIT_KEY_SIZE
;
1385 cc_setup_xcbc(req
, desc
, &idx
);
1387 key_len
= ctx
->key_params
.keylen
;
1388 cc_setup_cmac(req
, desc
, &idx
);
1391 if (req
->nbytes
== 0) {
1392 hw_desc_init(&desc
[idx
]);
1393 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1394 set_key_size_aes(&desc
[idx
], key_len
);
1395 set_cmac_size0_mode(&desc
[idx
]);
1396 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
1399 cc_set_desc(state
, ctx
, DIN_AES_DOUT
, desc
, false, &idx
);
1402 /* Get final MAC result */
1403 hw_desc_init(&desc
[idx
]);
1405 set_dout_dlli(&desc
[idx
], state
->digest_result_dma_addr
,
1406 digestsize
, NS_BIT
, 1);
1407 set_queue_last_ind(ctx
->drvdata
, &desc
[idx
]);
1408 set_flow_mode(&desc
[idx
], S_AES_to_DOUT
);
1409 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
1410 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1413 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
1414 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
1415 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
1416 cc_unmap_hash_request(dev
, state
, req
->src
, true);
1417 cc_unmap_result(dev
, state
, digestsize
, req
->result
);
1418 cc_unmap_req(dev
, state
, ctx
);
1423 static int cc_mac_digest(struct ahash_request
*req
)
1425 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
1426 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
1427 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
1428 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1429 u32 digestsize
= crypto_ahash_digestsize(tfm
);
1430 struct cc_crypto_req cc_req
= {};
1431 struct cc_hw_desc desc
[CC_MAX_HASH_SEQ_LEN
];
1433 unsigned int idx
= 0;
1435 gfp_t flags
= cc_gfp_flags(&req
->base
);
1437 dev_dbg(dev
, "===== -digest mac (%d) ====\n", req
->nbytes
);
1439 cc_init_req(dev
, state
, ctx
);
1441 if (cc_map_req(dev
, state
, ctx
)) {
1442 dev_err(dev
, "map_ahash_source() failed\n");
1445 if (cc_map_result(dev
, state
, digestsize
)) {
1446 dev_err(dev
, "map_ahash_digest() failed\n");
1447 cc_unmap_req(dev
, state
, ctx
);
1451 if (cc_map_hash_request_final(ctx
->drvdata
, state
, req
->src
,
1452 req
->nbytes
, 1, flags
)) {
1453 dev_err(dev
, "map_ahash_request_final() failed\n");
1454 cc_unmap_req(dev
, state
, ctx
);
1458 /* Setup request structure */
1459 cc_req
.user_cb
= (void *)cc_digest_complete
;
1460 cc_req
.user_arg
= (void *)req
;
1462 if (ctx
->hw_mode
== DRV_CIPHER_XCBC_MAC
) {
1463 key_len
= CC_AES_128_BIT_KEY_SIZE
;
1464 cc_setup_xcbc(req
, desc
, &idx
);
1466 key_len
= ctx
->key_params
.keylen
;
1467 cc_setup_cmac(req
, desc
, &idx
);
1470 if (req
->nbytes
== 0) {
1471 hw_desc_init(&desc
[idx
]);
1472 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1473 set_key_size_aes(&desc
[idx
], key_len
);
1474 set_cmac_size0_mode(&desc
[idx
]);
1475 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
1478 cc_set_desc(state
, ctx
, DIN_AES_DOUT
, desc
, false, &idx
);
1481 /* Get final MAC result */
1482 hw_desc_init(&desc
[idx
]);
1483 set_dout_dlli(&desc
[idx
], state
->digest_result_dma_addr
,
1484 CC_AES_BLOCK_SIZE
, NS_BIT
, 1);
1485 set_queue_last_ind(ctx
->drvdata
, &desc
[idx
]);
1486 set_flow_mode(&desc
[idx
], S_AES_to_DOUT
);
1487 set_setup_mode(&desc
[idx
], SETUP_WRITE_STATE0
);
1488 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
1489 set_cipher_mode(&desc
[idx
], ctx
->hw_mode
);
1492 rc
= cc_send_request(ctx
->drvdata
, &cc_req
, desc
, idx
, &req
->base
);
1493 if (rc
!= -EINPROGRESS
&& rc
!= -EBUSY
) {
1494 dev_err(dev
, "send_request() failed (rc=%d)\n", rc
);
1495 cc_unmap_hash_request(dev
, state
, req
->src
, true);
1496 cc_unmap_result(dev
, state
, digestsize
, req
->result
);
1497 cc_unmap_req(dev
, state
, ctx
);
1502 static int cc_hash_export(struct ahash_request
*req
, void *out
)
1504 struct crypto_ahash
*ahash
= crypto_ahash_reqtfm(req
);
1505 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(ahash
);
1506 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
1507 u8
*curr_buff
= cc_hash_buf(state
);
1508 u32 curr_buff_cnt
= *cc_hash_buf_cnt(state
);
1509 const u32 tmp
= CC_EXPORT_MAGIC
;
1511 memcpy(out
, &tmp
, sizeof(u32
));
1514 memcpy(out
, state
->digest_buff
, ctx
->inter_digestsize
);
1515 out
+= ctx
->inter_digestsize
;
1517 memcpy(out
, state
->digest_bytes_len
, ctx
->drvdata
->hash_len_sz
);
1518 out
+= ctx
->drvdata
->hash_len_sz
;
1520 memcpy(out
, &curr_buff_cnt
, sizeof(u32
));
1523 memcpy(out
, curr_buff
, curr_buff_cnt
);
1528 static int cc_hash_import(struct ahash_request
*req
, const void *in
)
1530 struct crypto_ahash
*ahash
= crypto_ahash_reqtfm(req
);
1531 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(ahash
);
1532 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
1533 struct ahash_req_ctx
*state
= ahash_request_ctx(req
);
1536 memcpy(&tmp
, in
, sizeof(u32
));
1537 if (tmp
!= CC_EXPORT_MAGIC
)
1541 cc_init_req(dev
, state
, ctx
);
1543 memcpy(state
->digest_buff
, in
, ctx
->inter_digestsize
);
1544 in
+= ctx
->inter_digestsize
;
1546 memcpy(state
->digest_bytes_len
, in
, ctx
->drvdata
->hash_len_sz
);
1547 in
+= ctx
->drvdata
->hash_len_sz
;
1549 /* Sanity check the data as much as possible */
1550 memcpy(&tmp
, in
, sizeof(u32
));
1551 if (tmp
> CC_MAX_HASH_BLCK_SIZE
)
1555 state
->buf_cnt
[0] = tmp
;
1556 memcpy(state
->buffers
[0], in
, tmp
);
1561 struct cc_hash_template
{
1562 char name
[CRYPTO_MAX_ALG_NAME
];
1563 char driver_name
[CRYPTO_MAX_ALG_NAME
];
1564 char mac_name
[CRYPTO_MAX_ALG_NAME
];
1565 char mac_driver_name
[CRYPTO_MAX_ALG_NAME
];
1566 unsigned int blocksize
;
1568 struct ahash_alg template_ahash
;
1571 int inter_digestsize
;
1572 struct cc_drvdata
*drvdata
;
1576 #define CC_STATE_SIZE(_x) \
1577 ((_x) + HASH_MAX_LEN_SIZE + CC_MAX_HASH_BLCK_SIZE + (2 * sizeof(u32)))
1579 /* hash descriptors */
1580 static struct cc_hash_template driver_hash
[] = {
1581 //Asynchronize hash template
1584 .driver_name
= "sha1-ccree",
1585 .mac_name
= "hmac(sha1)",
1586 .mac_driver_name
= "hmac-sha1-ccree",
1587 .blocksize
= SHA1_BLOCK_SIZE
,
1588 .synchronize
= false,
1590 .init
= cc_hash_init
,
1591 .update
= cc_hash_update
,
1592 .final
= cc_hash_final
,
1593 .finup
= cc_hash_finup
,
1594 .digest
= cc_hash_digest
,
1595 .export
= cc_hash_export
,
1596 .import
= cc_hash_import
,
1597 .setkey
= cc_hash_setkey
,
1599 .digestsize
= SHA1_DIGEST_SIZE
,
1600 .statesize
= CC_STATE_SIZE(SHA1_DIGEST_SIZE
),
1603 .hash_mode
= DRV_HASH_SHA1
,
1604 .hw_mode
= DRV_HASH_HW_SHA1
,
1605 .inter_digestsize
= SHA1_DIGEST_SIZE
,
1606 .min_hw_rev
= CC_HW_REV_630
,
1610 .driver_name
= "sha256-ccree",
1611 .mac_name
= "hmac(sha256)",
1612 .mac_driver_name
= "hmac-sha256-ccree",
1613 .blocksize
= SHA256_BLOCK_SIZE
,
1615 .init
= cc_hash_init
,
1616 .update
= cc_hash_update
,
1617 .final
= cc_hash_final
,
1618 .finup
= cc_hash_finup
,
1619 .digest
= cc_hash_digest
,
1620 .export
= cc_hash_export
,
1621 .import
= cc_hash_import
,
1622 .setkey
= cc_hash_setkey
,
1624 .digestsize
= SHA256_DIGEST_SIZE
,
1625 .statesize
= CC_STATE_SIZE(SHA256_DIGEST_SIZE
)
1628 .hash_mode
= DRV_HASH_SHA256
,
1629 .hw_mode
= DRV_HASH_HW_SHA256
,
1630 .inter_digestsize
= SHA256_DIGEST_SIZE
,
1631 .min_hw_rev
= CC_HW_REV_630
,
1635 .driver_name
= "sha224-ccree",
1636 .mac_name
= "hmac(sha224)",
1637 .mac_driver_name
= "hmac-sha224-ccree",
1638 .blocksize
= SHA224_BLOCK_SIZE
,
1640 .init
= cc_hash_init
,
1641 .update
= cc_hash_update
,
1642 .final
= cc_hash_final
,
1643 .finup
= cc_hash_finup
,
1644 .digest
= cc_hash_digest
,
1645 .export
= cc_hash_export
,
1646 .import
= cc_hash_import
,
1647 .setkey
= cc_hash_setkey
,
1649 .digestsize
= SHA224_DIGEST_SIZE
,
1650 .statesize
= CC_STATE_SIZE(SHA224_DIGEST_SIZE
),
1653 .hash_mode
= DRV_HASH_SHA224
,
1654 .hw_mode
= DRV_HASH_HW_SHA256
,
1655 .inter_digestsize
= SHA256_DIGEST_SIZE
,
1656 .min_hw_rev
= CC_HW_REV_630
,
1660 .driver_name
= "sha384-ccree",
1661 .mac_name
= "hmac(sha384)",
1662 .mac_driver_name
= "hmac-sha384-ccree",
1663 .blocksize
= SHA384_BLOCK_SIZE
,
1665 .init
= cc_hash_init
,
1666 .update
= cc_hash_update
,
1667 .final
= cc_hash_final
,
1668 .finup
= cc_hash_finup
,
1669 .digest
= cc_hash_digest
,
1670 .export
= cc_hash_export
,
1671 .import
= cc_hash_import
,
1672 .setkey
= cc_hash_setkey
,
1674 .digestsize
= SHA384_DIGEST_SIZE
,
1675 .statesize
= CC_STATE_SIZE(SHA384_DIGEST_SIZE
),
1678 .hash_mode
= DRV_HASH_SHA384
,
1679 .hw_mode
= DRV_HASH_HW_SHA512
,
1680 .inter_digestsize
= SHA512_DIGEST_SIZE
,
1681 .min_hw_rev
= CC_HW_REV_712
,
1685 .driver_name
= "sha512-ccree",
1686 .mac_name
= "hmac(sha512)",
1687 .mac_driver_name
= "hmac-sha512-ccree",
1688 .blocksize
= SHA512_BLOCK_SIZE
,
1690 .init
= cc_hash_init
,
1691 .update
= cc_hash_update
,
1692 .final
= cc_hash_final
,
1693 .finup
= cc_hash_finup
,
1694 .digest
= cc_hash_digest
,
1695 .export
= cc_hash_export
,
1696 .import
= cc_hash_import
,
1697 .setkey
= cc_hash_setkey
,
1699 .digestsize
= SHA512_DIGEST_SIZE
,
1700 .statesize
= CC_STATE_SIZE(SHA512_DIGEST_SIZE
),
1703 .hash_mode
= DRV_HASH_SHA512
,
1704 .hw_mode
= DRV_HASH_HW_SHA512
,
1705 .inter_digestsize
= SHA512_DIGEST_SIZE
,
1706 .min_hw_rev
= CC_HW_REV_712
,
1710 .driver_name
= "md5-ccree",
1711 .mac_name
= "hmac(md5)",
1712 .mac_driver_name
= "hmac-md5-ccree",
1713 .blocksize
= MD5_HMAC_BLOCK_SIZE
,
1715 .init
= cc_hash_init
,
1716 .update
= cc_hash_update
,
1717 .final
= cc_hash_final
,
1718 .finup
= cc_hash_finup
,
1719 .digest
= cc_hash_digest
,
1720 .export
= cc_hash_export
,
1721 .import
= cc_hash_import
,
1722 .setkey
= cc_hash_setkey
,
1724 .digestsize
= MD5_DIGEST_SIZE
,
1725 .statesize
= CC_STATE_SIZE(MD5_DIGEST_SIZE
),
1728 .hash_mode
= DRV_HASH_MD5
,
1729 .hw_mode
= DRV_HASH_HW_MD5
,
1730 .inter_digestsize
= MD5_DIGEST_SIZE
,
1731 .min_hw_rev
= CC_HW_REV_630
,
1734 .mac_name
= "xcbc(aes)",
1735 .mac_driver_name
= "xcbc-aes-ccree",
1736 .blocksize
= AES_BLOCK_SIZE
,
1738 .init
= cc_hash_init
,
1739 .update
= cc_mac_update
,
1740 .final
= cc_mac_final
,
1741 .finup
= cc_mac_finup
,
1742 .digest
= cc_mac_digest
,
1743 .setkey
= cc_xcbc_setkey
,
1744 .export
= cc_hash_export
,
1745 .import
= cc_hash_import
,
1747 .digestsize
= AES_BLOCK_SIZE
,
1748 .statesize
= CC_STATE_SIZE(AES_BLOCK_SIZE
),
1751 .hash_mode
= DRV_HASH_NULL
,
1752 .hw_mode
= DRV_CIPHER_XCBC_MAC
,
1753 .inter_digestsize
= AES_BLOCK_SIZE
,
1754 .min_hw_rev
= CC_HW_REV_630
,
1757 .mac_name
= "cmac(aes)",
1758 .mac_driver_name
= "cmac-aes-ccree",
1759 .blocksize
= AES_BLOCK_SIZE
,
1761 .init
= cc_hash_init
,
1762 .update
= cc_mac_update
,
1763 .final
= cc_mac_final
,
1764 .finup
= cc_mac_finup
,
1765 .digest
= cc_mac_digest
,
1766 .setkey
= cc_cmac_setkey
,
1767 .export
= cc_hash_export
,
1768 .import
= cc_hash_import
,
1770 .digestsize
= AES_BLOCK_SIZE
,
1771 .statesize
= CC_STATE_SIZE(AES_BLOCK_SIZE
),
1774 .hash_mode
= DRV_HASH_NULL
,
1775 .hw_mode
= DRV_CIPHER_CMAC
,
1776 .inter_digestsize
= AES_BLOCK_SIZE
,
1777 .min_hw_rev
= CC_HW_REV_630
,
1781 static struct cc_hash_alg
*cc_alloc_hash_alg(struct cc_hash_template
*template,
1782 struct device
*dev
, bool keyed
)
1784 struct cc_hash_alg
*t_crypto_alg
;
1785 struct crypto_alg
*alg
;
1786 struct ahash_alg
*halg
;
1788 t_crypto_alg
= kzalloc(sizeof(*t_crypto_alg
), GFP_KERNEL
);
1790 return ERR_PTR(-ENOMEM
);
1792 t_crypto_alg
->ahash_alg
= template->template_ahash
;
1793 halg
= &t_crypto_alg
->ahash_alg
;
1794 alg
= &halg
->halg
.base
;
1797 snprintf(alg
->cra_name
, CRYPTO_MAX_ALG_NAME
, "%s",
1798 template->mac_name
);
1799 snprintf(alg
->cra_driver_name
, CRYPTO_MAX_ALG_NAME
, "%s",
1800 template->mac_driver_name
);
1802 halg
->setkey
= NULL
;
1803 snprintf(alg
->cra_name
, CRYPTO_MAX_ALG_NAME
, "%s",
1805 snprintf(alg
->cra_driver_name
, CRYPTO_MAX_ALG_NAME
, "%s",
1806 template->driver_name
);
1808 alg
->cra_module
= THIS_MODULE
;
1809 alg
->cra_ctxsize
= sizeof(struct cc_hash_ctx
);
1810 alg
->cra_priority
= CC_CRA_PRIO
;
1811 alg
->cra_blocksize
= template->blocksize
;
1812 alg
->cra_alignmask
= 0;
1813 alg
->cra_exit
= cc_cra_exit
;
1815 alg
->cra_init
= cc_cra_init
;
1816 alg
->cra_flags
= CRYPTO_ALG_ASYNC
| CRYPTO_ALG_TYPE_AHASH
|
1817 CRYPTO_ALG_KERN_DRIVER_ONLY
;
1818 alg
->cra_type
= &crypto_ahash_type
;
1820 t_crypto_alg
->hash_mode
= template->hash_mode
;
1821 t_crypto_alg
->hw_mode
= template->hw_mode
;
1822 t_crypto_alg
->inter_digestsize
= template->inter_digestsize
;
1824 return t_crypto_alg
;
1827 int cc_init_hash_sram(struct cc_drvdata
*drvdata
)
1829 struct cc_hash_handle
*hash_handle
= drvdata
->hash_handle
;
1830 cc_sram_addr_t sram_buff_ofs
= hash_handle
->digest_len_sram_addr
;
1831 unsigned int larval_seq_len
= 0;
1832 struct cc_hw_desc larval_seq
[CC_DIGEST_SIZE_MAX
/ sizeof(u32
)];
1833 bool large_sha_supported
= (drvdata
->hw_rev
>= CC_HW_REV_712
);
1836 /* Copy-to-sram digest-len */
1837 cc_set_sram_desc(digest_len_init
, sram_buff_ofs
,
1838 ARRAY_SIZE(digest_len_init
), larval_seq
,
1840 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1842 goto init_digest_const_err
;
1844 sram_buff_ofs
+= sizeof(digest_len_init
);
1847 if (large_sha_supported
) {
1848 /* Copy-to-sram digest-len for sha384/512 */
1849 cc_set_sram_desc(digest_len_sha512_init
, sram_buff_ofs
,
1850 ARRAY_SIZE(digest_len_sha512_init
),
1851 larval_seq
, &larval_seq_len
);
1852 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1854 goto init_digest_const_err
;
1856 sram_buff_ofs
+= sizeof(digest_len_sha512_init
);
1860 /* The initial digests offset */
1861 hash_handle
->larval_digest_sram_addr
= sram_buff_ofs
;
1863 /* Copy-to-sram initial SHA* digests */
1864 cc_set_sram_desc(md5_init
, sram_buff_ofs
, ARRAY_SIZE(md5_init
),
1865 larval_seq
, &larval_seq_len
);
1866 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1868 goto init_digest_const_err
;
1869 sram_buff_ofs
+= sizeof(md5_init
);
1872 cc_set_sram_desc(sha1_init
, sram_buff_ofs
,
1873 ARRAY_SIZE(sha1_init
), larval_seq
,
1875 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1877 goto init_digest_const_err
;
1878 sram_buff_ofs
+= sizeof(sha1_init
);
1881 cc_set_sram_desc(sha224_init
, sram_buff_ofs
,
1882 ARRAY_SIZE(sha224_init
), larval_seq
,
1884 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1886 goto init_digest_const_err
;
1887 sram_buff_ofs
+= sizeof(sha224_init
);
1890 cc_set_sram_desc(sha256_init
, sram_buff_ofs
,
1891 ARRAY_SIZE(sha256_init
), larval_seq
,
1893 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1895 goto init_digest_const_err
;
1896 sram_buff_ofs
+= sizeof(sha256_init
);
1899 if (large_sha_supported
) {
1900 cc_set_sram_desc((u32
*)sha384_init
, sram_buff_ofs
,
1901 (ARRAY_SIZE(sha384_init
) * 2), larval_seq
,
1903 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1905 goto init_digest_const_err
;
1906 sram_buff_ofs
+= sizeof(sha384_init
);
1909 cc_set_sram_desc((u32
*)sha512_init
, sram_buff_ofs
,
1910 (ARRAY_SIZE(sha512_init
) * 2), larval_seq
,
1912 rc
= send_request_init(drvdata
, larval_seq
, larval_seq_len
);
1914 goto init_digest_const_err
;
1917 init_digest_const_err
:
1921 static void __init
cc_swap_dwords(u32
*buf
, unsigned long size
)
1926 for (i
= 0; i
< size
; i
+= 2) {
1928 buf
[i
] = buf
[i
+ 1];
1934 * Due to the way the HW works we need to swap every
1935 * double word in the SHA384 and SHA512 larval hashes
1937 void __init
cc_hash_global_init(void)
1939 cc_swap_dwords((u32
*)&sha384_init
, (ARRAY_SIZE(sha384_init
) * 2));
1940 cc_swap_dwords((u32
*)&sha512_init
, (ARRAY_SIZE(sha512_init
) * 2));
1943 int cc_hash_alloc(struct cc_drvdata
*drvdata
)
1945 struct cc_hash_handle
*hash_handle
;
1946 cc_sram_addr_t sram_buff
;
1947 u32 sram_size_to_alloc
;
1948 struct device
*dev
= drvdata_to_dev(drvdata
);
1952 hash_handle
= kzalloc(sizeof(*hash_handle
), GFP_KERNEL
);
1956 INIT_LIST_HEAD(&hash_handle
->hash_list
);
1957 drvdata
->hash_handle
= hash_handle
;
1959 sram_size_to_alloc
= sizeof(digest_len_init
) +
1962 sizeof(sha224_init
) +
1963 sizeof(sha256_init
);
1965 if (drvdata
->hw_rev
>= CC_HW_REV_712
)
1966 sram_size_to_alloc
+= sizeof(digest_len_sha512_init
) +
1967 sizeof(sha384_init
) + sizeof(sha512_init
);
1969 sram_buff
= cc_sram_alloc(drvdata
, sram_size_to_alloc
);
1970 if (sram_buff
== NULL_SRAM_ADDR
) {
1971 dev_err(dev
, "SRAM pool exhausted\n");
1976 /* The initial digest-len offset */
1977 hash_handle
->digest_len_sram_addr
= sram_buff
;
1979 /*must be set before the alg registration as it is being used there*/
1980 rc
= cc_init_hash_sram(drvdata
);
1982 dev_err(dev
, "Init digest CONST failed (rc=%d)\n", rc
);
1986 /* ahash registration */
1987 for (alg
= 0; alg
< ARRAY_SIZE(driver_hash
); alg
++) {
1988 struct cc_hash_alg
*t_alg
;
1989 int hw_mode
= driver_hash
[alg
].hw_mode
;
1991 /* We either support both HASH and MAC or none */
1992 if (driver_hash
[alg
].min_hw_rev
> drvdata
->hw_rev
)
1995 /* register hmac version */
1996 t_alg
= cc_alloc_hash_alg(&driver_hash
[alg
], dev
, true);
1997 if (IS_ERR(t_alg
)) {
1998 rc
= PTR_ERR(t_alg
);
1999 dev_err(dev
, "%s alg allocation failed\n",
2000 driver_hash
[alg
].driver_name
);
2003 t_alg
->drvdata
= drvdata
;
2005 rc
= crypto_register_ahash(&t_alg
->ahash_alg
);
2007 dev_err(dev
, "%s alg registration failed\n",
2008 driver_hash
[alg
].driver_name
);
2012 list_add_tail(&t_alg
->entry
, &hash_handle
->hash_list
);
2015 if (hw_mode
== DRV_CIPHER_XCBC_MAC
||
2016 hw_mode
== DRV_CIPHER_CMAC
)
2019 /* register hash version */
2020 t_alg
= cc_alloc_hash_alg(&driver_hash
[alg
], dev
, false);
2021 if (IS_ERR(t_alg
)) {
2022 rc
= PTR_ERR(t_alg
);
2023 dev_err(dev
, "%s alg allocation failed\n",
2024 driver_hash
[alg
].driver_name
);
2027 t_alg
->drvdata
= drvdata
;
2029 rc
= crypto_register_ahash(&t_alg
->ahash_alg
);
2031 dev_err(dev
, "%s alg registration failed\n",
2032 driver_hash
[alg
].driver_name
);
2036 list_add_tail(&t_alg
->entry
, &hash_handle
->hash_list
);
2043 kfree(drvdata
->hash_handle
);
2044 drvdata
->hash_handle
= NULL
;
2048 int cc_hash_free(struct cc_drvdata
*drvdata
)
2050 struct cc_hash_alg
*t_hash_alg
, *hash_n
;
2051 struct cc_hash_handle
*hash_handle
= drvdata
->hash_handle
;
2054 list_for_each_entry_safe(t_hash_alg
, hash_n
,
2055 &hash_handle
->hash_list
, entry
) {
2056 crypto_unregister_ahash(&t_hash_alg
->ahash_alg
);
2057 list_del(&t_hash_alg
->entry
);
2062 drvdata
->hash_handle
= NULL
;
2067 static void cc_setup_xcbc(struct ahash_request
*areq
, struct cc_hw_desc desc
[],
2068 unsigned int *seq_size
)
2070 unsigned int idx
= *seq_size
;
2071 struct ahash_req_ctx
*state
= ahash_request_ctx(areq
);
2072 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(areq
);
2073 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
2075 /* Setup XCBC MAC K1 */
2076 hw_desc_init(&desc
[idx
]);
2077 set_din_type(&desc
[idx
], DMA_DLLI
, (ctx
->opad_tmp_keys_dma_addr
+
2078 XCBC_MAC_K1_OFFSET
),
2079 CC_AES_128_BIT_KEY_SIZE
, NS_BIT
);
2080 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
2081 set_cipher_mode(&desc
[idx
], DRV_CIPHER_XCBC_MAC
);
2082 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
2083 set_key_size_aes(&desc
[idx
], CC_AES_128_BIT_KEY_SIZE
);
2084 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
2087 /* Setup XCBC MAC K2 */
2088 hw_desc_init(&desc
[idx
]);
2089 set_din_type(&desc
[idx
], DMA_DLLI
,
2090 (ctx
->opad_tmp_keys_dma_addr
+ XCBC_MAC_K2_OFFSET
),
2091 CC_AES_128_BIT_KEY_SIZE
, NS_BIT
);
2092 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE1
);
2093 set_cipher_mode(&desc
[idx
], DRV_CIPHER_XCBC_MAC
);
2094 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
2095 set_key_size_aes(&desc
[idx
], CC_AES_128_BIT_KEY_SIZE
);
2096 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
2099 /* Setup XCBC MAC K3 */
2100 hw_desc_init(&desc
[idx
]);
2101 set_din_type(&desc
[idx
], DMA_DLLI
,
2102 (ctx
->opad_tmp_keys_dma_addr
+ XCBC_MAC_K3_OFFSET
),
2103 CC_AES_128_BIT_KEY_SIZE
, NS_BIT
);
2104 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE2
);
2105 set_cipher_mode(&desc
[idx
], DRV_CIPHER_XCBC_MAC
);
2106 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
2107 set_key_size_aes(&desc
[idx
], CC_AES_128_BIT_KEY_SIZE
);
2108 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
2111 /* Loading MAC state */
2112 hw_desc_init(&desc
[idx
]);
2113 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_buff_dma_addr
,
2114 CC_AES_BLOCK_SIZE
, NS_BIT
);
2115 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
2116 set_cipher_mode(&desc
[idx
], DRV_CIPHER_XCBC_MAC
);
2117 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
2118 set_key_size_aes(&desc
[idx
], CC_AES_128_BIT_KEY_SIZE
);
2119 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
2124 static void cc_setup_cmac(struct ahash_request
*areq
, struct cc_hw_desc desc
[],
2125 unsigned int *seq_size
)
2127 unsigned int idx
= *seq_size
;
2128 struct ahash_req_ctx
*state
= ahash_request_ctx(areq
);
2129 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(areq
);
2130 struct cc_hash_ctx
*ctx
= crypto_ahash_ctx(tfm
);
2132 /* Setup CMAC Key */
2133 hw_desc_init(&desc
[idx
]);
2134 set_din_type(&desc
[idx
], DMA_DLLI
, ctx
->opad_tmp_keys_dma_addr
,
2135 ((ctx
->key_params
.keylen
== 24) ? AES_MAX_KEY_SIZE
:
2136 ctx
->key_params
.keylen
), NS_BIT
);
2137 set_setup_mode(&desc
[idx
], SETUP_LOAD_KEY0
);
2138 set_cipher_mode(&desc
[idx
], DRV_CIPHER_CMAC
);
2139 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
2140 set_key_size_aes(&desc
[idx
], ctx
->key_params
.keylen
);
2141 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
2144 /* Load MAC state */
2145 hw_desc_init(&desc
[idx
]);
2146 set_din_type(&desc
[idx
], DMA_DLLI
, state
->digest_buff_dma_addr
,
2147 CC_AES_BLOCK_SIZE
, NS_BIT
);
2148 set_setup_mode(&desc
[idx
], SETUP_LOAD_STATE0
);
2149 set_cipher_mode(&desc
[idx
], DRV_CIPHER_CMAC
);
2150 set_cipher_config0(&desc
[idx
], DESC_DIRECTION_ENCRYPT_ENCRYPT
);
2151 set_key_size_aes(&desc
[idx
], ctx
->key_params
.keylen
);
2152 set_flow_mode(&desc
[idx
], S_DIN_to_AES
);
2157 static void cc_set_desc(struct ahash_req_ctx
*areq_ctx
,
2158 struct cc_hash_ctx
*ctx
, unsigned int flow_mode
,
2159 struct cc_hw_desc desc
[], bool is_not_last_data
,
2160 unsigned int *seq_size
)
2162 unsigned int idx
= *seq_size
;
2163 struct device
*dev
= drvdata_to_dev(ctx
->drvdata
);
2165 if (areq_ctx
->data_dma_buf_type
== CC_DMA_BUF_DLLI
) {
2166 hw_desc_init(&desc
[idx
]);
2167 set_din_type(&desc
[idx
], DMA_DLLI
,
2168 sg_dma_address(areq_ctx
->curr_sg
),
2169 areq_ctx
->curr_sg
->length
, NS_BIT
);
2170 set_flow_mode(&desc
[idx
], flow_mode
);
2173 if (areq_ctx
->data_dma_buf_type
== CC_DMA_BUF_NULL
) {
2174 dev_dbg(dev
, " NULL mode\n");
2175 /* nothing to build */
2179 hw_desc_init(&desc
[idx
]);
2180 set_din_type(&desc
[idx
], DMA_DLLI
,
2181 areq_ctx
->mlli_params
.mlli_dma_addr
,
2182 areq_ctx
->mlli_params
.mlli_len
, NS_BIT
);
2183 set_dout_sram(&desc
[idx
], ctx
->drvdata
->mlli_sram_addr
,
2184 areq_ctx
->mlli_params
.mlli_len
);
2185 set_flow_mode(&desc
[idx
], BYPASS
);
2188 hw_desc_init(&desc
[idx
]);
2189 set_din_type(&desc
[idx
], DMA_MLLI
,
2190 ctx
->drvdata
->mlli_sram_addr
,
2191 areq_ctx
->mlli_nents
, NS_BIT
);
2192 set_flow_mode(&desc
[idx
], flow_mode
);
2195 if (is_not_last_data
)
2196 set_din_not_last_indication(&desc
[(idx
- 1)]);
2197 /* return updated desc sequence size */
2201 static const void *cc_larval_digest(struct device
*dev
, u32 mode
)
2208 case DRV_HASH_SHA224
:
2210 case DRV_HASH_SHA256
:
2212 case DRV_HASH_SHA384
:
2214 case DRV_HASH_SHA512
:
2217 dev_err(dev
, "Invalid hash mode (%d)\n", mode
);
2223 * Gets the address of the initial digest in SRAM
2224 * according to the given hash mode
2227 * \param mode The Hash mode. Supported modes: MD5/SHA1/SHA224/SHA256
2229 * \return u32 The address of the initial digest in SRAM
2231 cc_sram_addr_t
cc_larval_digest_addr(void *drvdata
, u32 mode
)
2233 struct cc_drvdata
*_drvdata
= (struct cc_drvdata
*)drvdata
;
2234 struct cc_hash_handle
*hash_handle
= _drvdata
->hash_handle
;
2235 struct device
*dev
= drvdata_to_dev(_drvdata
);
2241 return (hash_handle
->larval_digest_sram_addr
);
2243 return (hash_handle
->larval_digest_sram_addr
+
2245 case DRV_HASH_SHA224
:
2246 return (hash_handle
->larval_digest_sram_addr
+
2249 case DRV_HASH_SHA256
:
2250 return (hash_handle
->larval_digest_sram_addr
+
2253 sizeof(sha224_init
));
2254 case DRV_HASH_SHA384
:
2255 return (hash_handle
->larval_digest_sram_addr
+
2258 sizeof(sha224_init
) +
2259 sizeof(sha256_init
));
2260 case DRV_HASH_SHA512
:
2261 return (hash_handle
->larval_digest_sram_addr
+
2264 sizeof(sha224_init
) +
2265 sizeof(sha256_init
) +
2266 sizeof(sha384_init
));
2268 dev_err(dev
, "Invalid hash mode (%d)\n", mode
);
2271 /*This is valid wrong value to avoid kernel crash*/
2272 return hash_handle
->larval_digest_sram_addr
;
2276 cc_digest_len_addr(void *drvdata
, u32 mode
)
2278 struct cc_drvdata
*_drvdata
= (struct cc_drvdata
*)drvdata
;
2279 struct cc_hash_handle
*hash_handle
= _drvdata
->hash_handle
;
2280 cc_sram_addr_t digest_len_addr
= hash_handle
->digest_len_sram_addr
;
2284 case DRV_HASH_SHA224
:
2285 case DRV_HASH_SHA256
:
2287 return digest_len_addr
;
2288 #if (CC_DEV_SHA_MAX > 256)
2289 case DRV_HASH_SHA384
:
2290 case DRV_HASH_SHA512
:
2291 return digest_len_addr
+ sizeof(digest_len_init
);
2294 return digest_len_addr
; /*to avoid kernel crash*/