1 // SPDX-License-Identifier: GPL-2.0
3 * Hash function and HMAC support for StarFive driver
5 * Copyright (c) 2022 StarFive Technology
9 #include <crypto/engine.h>
10 #include <crypto/internal/hash.h>
11 #include <crypto/scatterwalk.h>
12 #include "jh7110-cryp.h"
13 #include <linux/amba/pl080.h>
14 #include <linux/clk.h>
15 #include <linux/dma-direct.h>
16 #include <linux/interrupt.h>
17 #include <linux/iopoll.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/platform_device.h>
21 #include <linux/pm_runtime.h>
22 #include <linux/reset.h>
24 #define STARFIVE_HASH_REGS_OFFSET 0x300
25 #define STARFIVE_HASH_SHACSR (STARFIVE_HASH_REGS_OFFSET + 0x0)
26 #define STARFIVE_HASH_SHAWDR (STARFIVE_HASH_REGS_OFFSET + 0x4)
27 #define STARFIVE_HASH_SHARDR (STARFIVE_HASH_REGS_OFFSET + 0x8)
28 #define STARFIVE_HASH_SHAWSR (STARFIVE_HASH_REGS_OFFSET + 0xC)
29 #define STARFIVE_HASH_SHAWLEN3 (STARFIVE_HASH_REGS_OFFSET + 0x10)
30 #define STARFIVE_HASH_SHAWLEN2 (STARFIVE_HASH_REGS_OFFSET + 0x14)
31 #define STARFIVE_HASH_SHAWLEN1 (STARFIVE_HASH_REGS_OFFSET + 0x18)
32 #define STARFIVE_HASH_SHAWLEN0 (STARFIVE_HASH_REGS_OFFSET + 0x1C)
33 #define STARFIVE_HASH_SHAWKR (STARFIVE_HASH_REGS_OFFSET + 0x20)
34 #define STARFIVE_HASH_SHAWKLEN (STARFIVE_HASH_REGS_OFFSET + 0x24)
36 #define STARFIVE_HASH_BUFLEN SHA512_BLOCK_SIZE
37 #define STARFIVE_HASH_RESET 0x2
39 static inline int starfive_hash_wait_busy(struct starfive_cryp_dev
*cryp
)
43 return readl_relaxed_poll_timeout(cryp
->base
+ STARFIVE_HASH_SHACSR
, status
,
44 !(status
& STARFIVE_HASH_BUSY
), 10, 100000);
47 static inline int starfive_hash_wait_hmac_done(struct starfive_cryp_dev
*cryp
)
51 return readl_relaxed_poll_timeout(cryp
->base
+ STARFIVE_HASH_SHACSR
, status
,
52 (status
& STARFIVE_HASH_HMAC_DONE
), 10, 100000);
55 static inline int starfive_hash_wait_key_done(struct starfive_cryp_ctx
*ctx
)
57 struct starfive_cryp_dev
*cryp
= ctx
->cryp
;
60 return readl_relaxed_poll_timeout(cryp
->base
+ STARFIVE_HASH_SHACSR
, status
,
61 (status
& STARFIVE_HASH_KEY_DONE
), 10, 100000);
64 static int starfive_hash_hmac_key(struct starfive_cryp_ctx
*ctx
)
66 struct starfive_cryp_request_ctx
*rctx
= ctx
->rctx
;
67 struct starfive_cryp_dev
*cryp
= ctx
->cryp
;
68 int klen
= ctx
->keylen
, loop
;
69 unsigned int *key
= (unsigned int *)ctx
->key
;
72 writel(ctx
->keylen
, cryp
->base
+ STARFIVE_HASH_SHAWKLEN
);
74 rctx
->csr
.hash
.hmac
= 1;
75 rctx
->csr
.hash
.key_flag
= 1;
77 writel(rctx
->csr
.hash
.v
, cryp
->base
+ STARFIVE_HASH_SHACSR
);
79 for (loop
= 0; loop
< klen
/ sizeof(unsigned int); loop
++, key
++)
80 writel(*key
, cryp
->base
+ STARFIVE_HASH_SHAWKR
);
83 cl
= (unsigned char *)key
;
84 for (loop
= 0; loop
< (klen
& 0x3); loop
++, cl
++)
85 writeb(*cl
, cryp
->base
+ STARFIVE_HASH_SHAWKR
);
88 if (starfive_hash_wait_key_done(ctx
))
89 return dev_err_probe(cryp
->dev
, -ETIMEDOUT
, "starfive_hash_wait_key_done error\n");
94 static void starfive_hash_start(struct starfive_cryp_dev
*cryp
)
96 union starfive_hash_csr csr
;
98 csr
.v
= readl(cryp
->base
+ STARFIVE_HASH_SHACSR
);
101 writel(csr
.v
, cryp
->base
+ STARFIVE_HASH_SHACSR
);
104 static void starfive_hash_dma_callback(void *param
)
106 struct starfive_cryp_dev
*cryp
= param
;
108 complete(&cryp
->dma_done
);
111 static void starfive_hash_dma_init(struct starfive_cryp_dev
*cryp
)
113 cryp
->cfg_in
.src_addr_width
= DMA_SLAVE_BUSWIDTH_16_BYTES
;
114 cryp
->cfg_in
.dst_addr_width
= DMA_SLAVE_BUSWIDTH_4_BYTES
;
115 cryp
->cfg_in
.src_maxburst
= cryp
->dma_maxburst
;
116 cryp
->cfg_in
.dst_maxburst
= cryp
->dma_maxburst
;
117 cryp
->cfg_in
.dst_addr
= cryp
->phys_base
+ STARFIVE_ALG_FIFO_OFFSET
;
119 dmaengine_slave_config(cryp
->tx
, &cryp
->cfg_in
);
121 init_completion(&cryp
->dma_done
);
124 static int starfive_hash_dma_xfer(struct starfive_cryp_dev
*cryp
,
125 struct scatterlist
*sg
)
127 struct dma_async_tx_descriptor
*in_desc
;
128 union starfive_alg_cr alg_cr
;
133 alg_cr
.hash_dma_en
= 1;
134 writel(alg_cr
.v
, cryp
->base
+ STARFIVE_ALG_CR_OFFSET
);
136 writel(sg_dma_len(sg
), cryp
->base
+ STARFIVE_DMA_IN_LEN_OFFSET
);
137 sg_dma_len(sg
) = ALIGN(sg_dma_len(sg
), sizeof(u32
));
139 in_desc
= dmaengine_prep_slave_sg(cryp
->tx
, sg
, 1, DMA_MEM_TO_DEV
,
140 DMA_PREP_INTERRUPT
| DMA_CTRL_ACK
);
146 reinit_completion(&cryp
->dma_done
);
147 in_desc
->callback
= starfive_hash_dma_callback
;
148 in_desc
->callback_param
= cryp
;
150 dmaengine_submit(in_desc
);
151 dma_async_issue_pending(cryp
->tx
);
153 if (!wait_for_completion_timeout(&cryp
->dma_done
,
154 msecs_to_jiffies(1000)))
160 writel(alg_cr
.v
, cryp
->base
+ STARFIVE_ALG_CR_OFFSET
);
165 static int starfive_hash_copy_hash(struct ahash_request
*req
)
167 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
168 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(crypto_ahash_reqtfm(req
));
175 mlen
= rctx
->digsize
/ sizeof(u32
);
176 data
= (u32
*)req
->result
;
178 for (count
= 0; count
< mlen
; count
++)
179 put_unaligned(readl(ctx
->cryp
->base
+ STARFIVE_HASH_SHARDR
),
185 static void starfive_hash_done_task(struct starfive_cryp_dev
*cryp
)
190 err
= starfive_hash_copy_hash(cryp
->req
.hreq
);
192 crypto_finalize_hash_request(cryp
->engine
, cryp
->req
.hreq
, err
);
195 static int starfive_hash_one_request(struct crypto_engine
*engine
, void *areq
)
197 struct ahash_request
*req
= container_of(areq
, struct ahash_request
,
199 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(crypto_ahash_reqtfm(req
));
200 struct starfive_cryp_request_ctx
*rctx
= ctx
->rctx
;
201 struct starfive_cryp_dev
*cryp
= ctx
->cryp
;
202 struct scatterlist
*tsg
;
203 int ret
, src_nents
, i
;
205 writel(STARFIVE_HASH_RESET
, cryp
->base
+ STARFIVE_HASH_SHACSR
);
207 if (starfive_hash_wait_busy(cryp
))
208 return dev_err_probe(cryp
->dev
, -ETIMEDOUT
, "Error resetting hardware\n");
210 rctx
->csr
.hash
.v
= 0;
211 rctx
->csr
.hash
.mode
= ctx
->hash_mode
;
214 ret
= starfive_hash_hmac_key(ctx
);
218 rctx
->csr
.hash
.start
= 1;
219 rctx
->csr
.hash
.firstb
= 1;
220 writel(rctx
->csr
.hash
.v
, cryp
->base
+ STARFIVE_HASH_SHACSR
);
223 /* No input message, get digest and end. */
227 starfive_hash_dma_init(cryp
);
229 for_each_sg(rctx
->in_sg
, tsg
, rctx
->in_sg_len
, i
) {
230 src_nents
= dma_map_sg(cryp
->dev
, tsg
, 1, DMA_TO_DEVICE
);
232 return dev_err_probe(cryp
->dev
, -ENOMEM
,
233 "dma_map_sg error\n");
235 ret
= starfive_hash_dma_xfer(cryp
, tsg
);
236 dma_unmap_sg(cryp
->dev
, tsg
, 1, DMA_TO_DEVICE
);
242 starfive_hash_start(cryp
);
244 if (starfive_hash_wait_busy(cryp
))
245 return dev_err_probe(cryp
->dev
, -ETIMEDOUT
, "Error generating digest\n");
248 cryp
->err
= starfive_hash_wait_hmac_done(cryp
);
250 starfive_hash_done_task(cryp
);
255 static int starfive_hash_init(struct ahash_request
*req
)
257 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
258 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
259 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
261 ahash_request_set_tfm(&rctx
->ahash_fbk_req
, ctx
->ahash_fbk
);
262 ahash_request_set_callback(&rctx
->ahash_fbk_req
,
263 req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
,
264 req
->base
.complete
, req
->base
.data
);
266 ahash_request_set_crypt(&rctx
->ahash_fbk_req
, req
->src
,
267 req
->result
, req
->nbytes
);
269 return crypto_ahash_init(&rctx
->ahash_fbk_req
);
272 static int starfive_hash_update(struct ahash_request
*req
)
274 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
275 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
276 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
278 ahash_request_set_tfm(&rctx
->ahash_fbk_req
, ctx
->ahash_fbk
);
279 ahash_request_set_callback(&rctx
->ahash_fbk_req
,
280 req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
,
281 req
->base
.complete
, req
->base
.data
);
283 ahash_request_set_crypt(&rctx
->ahash_fbk_req
, req
->src
,
284 req
->result
, req
->nbytes
);
286 return crypto_ahash_update(&rctx
->ahash_fbk_req
);
289 static int starfive_hash_final(struct ahash_request
*req
)
291 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
292 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
293 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
295 ahash_request_set_tfm(&rctx
->ahash_fbk_req
, ctx
->ahash_fbk
);
296 ahash_request_set_callback(&rctx
->ahash_fbk_req
,
297 req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
,
298 req
->base
.complete
, req
->base
.data
);
300 ahash_request_set_crypt(&rctx
->ahash_fbk_req
, req
->src
,
301 req
->result
, req
->nbytes
);
303 return crypto_ahash_final(&rctx
->ahash_fbk_req
);
306 static int starfive_hash_finup(struct ahash_request
*req
)
308 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
309 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
310 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
312 ahash_request_set_tfm(&rctx
->ahash_fbk_req
, ctx
->ahash_fbk
);
313 ahash_request_set_callback(&rctx
->ahash_fbk_req
,
314 req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
,
315 req
->base
.complete
, req
->base
.data
);
317 ahash_request_set_crypt(&rctx
->ahash_fbk_req
, req
->src
,
318 req
->result
, req
->nbytes
);
320 return crypto_ahash_finup(&rctx
->ahash_fbk_req
);
323 static int starfive_hash_digest(struct ahash_request
*req
)
325 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
326 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
327 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
328 struct starfive_cryp_dev
*cryp
= ctx
->cryp
;
330 memset(rctx
, 0, sizeof(struct starfive_cryp_request_ctx
));
332 cryp
->req
.hreq
= req
;
333 rctx
->total
= req
->nbytes
;
334 rctx
->in_sg
= req
->src
;
335 rctx
->blksize
= crypto_tfm_alg_blocksize(crypto_ahash_tfm(tfm
));
336 rctx
->digsize
= crypto_ahash_digestsize(tfm
);
337 rctx
->in_sg_len
= sg_nents_for_len(rctx
->in_sg
, rctx
->total
);
340 return crypto_transfer_hash_request_to_engine(cryp
->engine
, req
);
343 static int starfive_hash_export(struct ahash_request
*req
, void *out
)
345 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
346 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
347 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
349 ahash_request_set_tfm(&rctx
->ahash_fbk_req
, ctx
->ahash_fbk
);
350 ahash_request_set_callback(&rctx
->ahash_fbk_req
,
351 req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
,
352 req
->base
.complete
, req
->base
.data
);
354 return crypto_ahash_export(&rctx
->ahash_fbk_req
, out
);
357 static int starfive_hash_import(struct ahash_request
*req
, const void *in
)
359 struct starfive_cryp_request_ctx
*rctx
= ahash_request_ctx(req
);
360 struct crypto_ahash
*tfm
= crypto_ahash_reqtfm(req
);
361 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(tfm
);
363 ahash_request_set_tfm(&rctx
->ahash_fbk_req
, ctx
->ahash_fbk
);
364 ahash_request_set_callback(&rctx
->ahash_fbk_req
,
365 req
->base
.flags
& CRYPTO_TFM_REQ_MAY_SLEEP
,
366 req
->base
.complete
, req
->base
.data
);
368 return crypto_ahash_import(&rctx
->ahash_fbk_req
, in
);
371 static int starfive_hash_init_tfm(struct crypto_ahash
*hash
,
372 const char *alg_name
,
376 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(hash
);
378 ctx
->cryp
= starfive_cryp_find_dev(ctx
);
383 ctx
->ahash_fbk
= crypto_alloc_ahash(alg_name
, 0,
384 CRYPTO_ALG_NEED_FALLBACK
);
386 if (IS_ERR(ctx
->ahash_fbk
))
387 return dev_err_probe(ctx
->cryp
->dev
, PTR_ERR(ctx
->ahash_fbk
),
388 "starfive_hash: Could not load fallback driver.\n");
390 crypto_ahash_set_statesize(hash
, crypto_ahash_statesize(ctx
->ahash_fbk
));
391 crypto_ahash_set_reqsize(hash
, sizeof(struct starfive_cryp_request_ctx
) +
392 crypto_ahash_reqsize(ctx
->ahash_fbk
));
394 ctx
->is_hmac
= is_hmac
;
395 ctx
->hash_mode
= mode
;
400 static void starfive_hash_exit_tfm(struct crypto_ahash
*hash
)
402 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(hash
);
404 crypto_free_ahash(ctx
->ahash_fbk
);
407 static int starfive_hash_long_setkey(struct starfive_cryp_ctx
*ctx
,
408 const u8
*key
, unsigned int keylen
,
409 const char *alg_name
)
411 struct crypto_wait wait
;
412 struct ahash_request
*req
;
413 struct scatterlist sg
;
414 struct crypto_ahash
*ahash_tfm
;
418 ahash_tfm
= crypto_alloc_ahash(alg_name
, 0, 0);
419 if (IS_ERR(ahash_tfm
))
420 return PTR_ERR(ahash_tfm
);
422 req
= ahash_request_alloc(ahash_tfm
, GFP_KERNEL
);
428 crypto_init_wait(&wait
);
429 ahash_request_set_callback(req
, CRYPTO_TFM_REQ_MAY_BACKLOG
,
430 crypto_req_done
, &wait
);
431 crypto_ahash_clear_flags(ahash_tfm
, ~0);
433 buf
= kzalloc(keylen
+ STARFIVE_HASH_BUFLEN
, GFP_KERNEL
);
439 memcpy(buf
, key
, keylen
);
440 sg_init_one(&sg
, buf
, keylen
);
441 ahash_request_set_crypt(req
, &sg
, ctx
->key
, keylen
);
443 ret
= crypto_wait_req(crypto_ahash_digest(req
), &wait
);
447 ahash_request_free(req
);
449 crypto_free_ahash(ahash_tfm
);
453 static int starfive_hash_setkey(struct crypto_ahash
*hash
,
454 const u8
*key
, unsigned int keylen
)
456 struct starfive_cryp_ctx
*ctx
= crypto_ahash_ctx(hash
);
457 unsigned int digestsize
= crypto_ahash_digestsize(hash
);
458 unsigned int blocksize
= crypto_ahash_blocksize(hash
);
459 const char *alg_name
;
461 crypto_ahash_setkey(ctx
->ahash_fbk
, key
, keylen
);
463 if (keylen
<= blocksize
) {
464 memcpy(ctx
->key
, key
, keylen
);
465 ctx
->keylen
= keylen
;
469 ctx
->keylen
= digestsize
;
471 switch (digestsize
) {
472 case SHA224_DIGEST_SIZE
:
473 alg_name
= "sha224-starfive";
475 case SHA256_DIGEST_SIZE
:
476 if (ctx
->hash_mode
== STARFIVE_HASH_SM3
)
477 alg_name
= "sm3-starfive";
479 alg_name
= "sha256-starfive";
481 case SHA384_DIGEST_SIZE
:
482 alg_name
= "sha384-starfive";
484 case SHA512_DIGEST_SIZE
:
485 alg_name
= "sha512-starfive";
491 return starfive_hash_long_setkey(ctx
, key
, keylen
, alg_name
);
494 static int starfive_sha224_init_tfm(struct crypto_ahash
*hash
)
496 return starfive_hash_init_tfm(hash
, "sha224-generic",
497 STARFIVE_HASH_SHA224
, 0);
500 static int starfive_sha256_init_tfm(struct crypto_ahash
*hash
)
502 return starfive_hash_init_tfm(hash
, "sha256-generic",
503 STARFIVE_HASH_SHA256
, 0);
506 static int starfive_sha384_init_tfm(struct crypto_ahash
*hash
)
508 return starfive_hash_init_tfm(hash
, "sha384-generic",
509 STARFIVE_HASH_SHA384
, 0);
512 static int starfive_sha512_init_tfm(struct crypto_ahash
*hash
)
514 return starfive_hash_init_tfm(hash
, "sha512-generic",
515 STARFIVE_HASH_SHA512
, 0);
518 static int starfive_sm3_init_tfm(struct crypto_ahash
*hash
)
520 return starfive_hash_init_tfm(hash
, "sm3-generic",
521 STARFIVE_HASH_SM3
, 0);
524 static int starfive_hmac_sha224_init_tfm(struct crypto_ahash
*hash
)
526 return starfive_hash_init_tfm(hash
, "hmac(sha224-generic)",
527 STARFIVE_HASH_SHA224
, 1);
530 static int starfive_hmac_sha256_init_tfm(struct crypto_ahash
*hash
)
532 return starfive_hash_init_tfm(hash
, "hmac(sha256-generic)",
533 STARFIVE_HASH_SHA256
, 1);
536 static int starfive_hmac_sha384_init_tfm(struct crypto_ahash
*hash
)
538 return starfive_hash_init_tfm(hash
, "hmac(sha384-generic)",
539 STARFIVE_HASH_SHA384
, 1);
542 static int starfive_hmac_sha512_init_tfm(struct crypto_ahash
*hash
)
544 return starfive_hash_init_tfm(hash
, "hmac(sha512-generic)",
545 STARFIVE_HASH_SHA512
, 1);
548 static int starfive_hmac_sm3_init_tfm(struct crypto_ahash
*hash
)
550 return starfive_hash_init_tfm(hash
, "hmac(sm3-generic)",
551 STARFIVE_HASH_SM3
, 1);
554 static struct ahash_engine_alg algs_sha2_sm3
[] = {
556 .base
.init
= starfive_hash_init
,
557 .base
.update
= starfive_hash_update
,
558 .base
.final
= starfive_hash_final
,
559 .base
.finup
= starfive_hash_finup
,
560 .base
.digest
= starfive_hash_digest
,
561 .base
.export
= starfive_hash_export
,
562 .base
.import
= starfive_hash_import
,
563 .base
.init_tfm
= starfive_sha224_init_tfm
,
564 .base
.exit_tfm
= starfive_hash_exit_tfm
,
566 .digestsize
= SHA224_DIGEST_SIZE
,
567 .statesize
= sizeof(struct sha256_state
),
569 .cra_name
= "sha224",
570 .cra_driver_name
= "sha224-starfive",
572 .cra_flags
= CRYPTO_ALG_ASYNC
|
573 CRYPTO_ALG_TYPE_AHASH
|
574 CRYPTO_ALG_NEED_FALLBACK
,
575 .cra_blocksize
= SHA224_BLOCK_SIZE
,
576 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
577 .cra_module
= THIS_MODULE
,
581 .do_one_request
= starfive_hash_one_request
,
584 .base
.init
= starfive_hash_init
,
585 .base
.update
= starfive_hash_update
,
586 .base
.final
= starfive_hash_final
,
587 .base
.finup
= starfive_hash_finup
,
588 .base
.digest
= starfive_hash_digest
,
589 .base
.export
= starfive_hash_export
,
590 .base
.import
= starfive_hash_import
,
591 .base
.init_tfm
= starfive_hmac_sha224_init_tfm
,
592 .base
.exit_tfm
= starfive_hash_exit_tfm
,
593 .base
.setkey
= starfive_hash_setkey
,
595 .digestsize
= SHA224_DIGEST_SIZE
,
596 .statesize
= sizeof(struct sha256_state
),
598 .cra_name
= "hmac(sha224)",
599 .cra_driver_name
= "sha224-hmac-starfive",
601 .cra_flags
= CRYPTO_ALG_ASYNC
|
602 CRYPTO_ALG_TYPE_AHASH
|
603 CRYPTO_ALG_NEED_FALLBACK
,
604 .cra_blocksize
= SHA224_BLOCK_SIZE
,
605 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
606 .cra_module
= THIS_MODULE
,
610 .do_one_request
= starfive_hash_one_request
,
613 .base
.init
= starfive_hash_init
,
614 .base
.update
= starfive_hash_update
,
615 .base
.final
= starfive_hash_final
,
616 .base
.finup
= starfive_hash_finup
,
617 .base
.digest
= starfive_hash_digest
,
618 .base
.export
= starfive_hash_export
,
619 .base
.import
= starfive_hash_import
,
620 .base
.init_tfm
= starfive_sha256_init_tfm
,
621 .base
.exit_tfm
= starfive_hash_exit_tfm
,
623 .digestsize
= SHA256_DIGEST_SIZE
,
624 .statesize
= sizeof(struct sha256_state
),
626 .cra_name
= "sha256",
627 .cra_driver_name
= "sha256-starfive",
629 .cra_flags
= CRYPTO_ALG_ASYNC
|
630 CRYPTO_ALG_TYPE_AHASH
|
631 CRYPTO_ALG_NEED_FALLBACK
,
632 .cra_blocksize
= SHA256_BLOCK_SIZE
,
633 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
634 .cra_module
= THIS_MODULE
,
638 .do_one_request
= starfive_hash_one_request
,
641 .base
.init
= starfive_hash_init
,
642 .base
.update
= starfive_hash_update
,
643 .base
.final
= starfive_hash_final
,
644 .base
.finup
= starfive_hash_finup
,
645 .base
.digest
= starfive_hash_digest
,
646 .base
.export
= starfive_hash_export
,
647 .base
.import
= starfive_hash_import
,
648 .base
.init_tfm
= starfive_hmac_sha256_init_tfm
,
649 .base
.exit_tfm
= starfive_hash_exit_tfm
,
650 .base
.setkey
= starfive_hash_setkey
,
652 .digestsize
= SHA256_DIGEST_SIZE
,
653 .statesize
= sizeof(struct sha256_state
),
655 .cra_name
= "hmac(sha256)",
656 .cra_driver_name
= "sha256-hmac-starfive",
658 .cra_flags
= CRYPTO_ALG_ASYNC
|
659 CRYPTO_ALG_TYPE_AHASH
|
660 CRYPTO_ALG_NEED_FALLBACK
,
661 .cra_blocksize
= SHA256_BLOCK_SIZE
,
662 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
663 .cra_module
= THIS_MODULE
,
667 .do_one_request
= starfive_hash_one_request
,
670 .base
.init
= starfive_hash_init
,
671 .base
.update
= starfive_hash_update
,
672 .base
.final
= starfive_hash_final
,
673 .base
.finup
= starfive_hash_finup
,
674 .base
.digest
= starfive_hash_digest
,
675 .base
.export
= starfive_hash_export
,
676 .base
.import
= starfive_hash_import
,
677 .base
.init_tfm
= starfive_sha384_init_tfm
,
678 .base
.exit_tfm
= starfive_hash_exit_tfm
,
680 .digestsize
= SHA384_DIGEST_SIZE
,
681 .statesize
= sizeof(struct sha512_state
),
683 .cra_name
= "sha384",
684 .cra_driver_name
= "sha384-starfive",
686 .cra_flags
= CRYPTO_ALG_ASYNC
|
687 CRYPTO_ALG_TYPE_AHASH
|
688 CRYPTO_ALG_NEED_FALLBACK
,
689 .cra_blocksize
= SHA384_BLOCK_SIZE
,
690 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
691 .cra_module
= THIS_MODULE
,
695 .do_one_request
= starfive_hash_one_request
,
698 .base
.init
= starfive_hash_init
,
699 .base
.update
= starfive_hash_update
,
700 .base
.final
= starfive_hash_final
,
701 .base
.finup
= starfive_hash_finup
,
702 .base
.digest
= starfive_hash_digest
,
703 .base
.export
= starfive_hash_export
,
704 .base
.import
= starfive_hash_import
,
705 .base
.init_tfm
= starfive_hmac_sha384_init_tfm
,
706 .base
.exit_tfm
= starfive_hash_exit_tfm
,
707 .base
.setkey
= starfive_hash_setkey
,
709 .digestsize
= SHA384_DIGEST_SIZE
,
710 .statesize
= sizeof(struct sha512_state
),
712 .cra_name
= "hmac(sha384)",
713 .cra_driver_name
= "sha384-hmac-starfive",
715 .cra_flags
= CRYPTO_ALG_ASYNC
|
716 CRYPTO_ALG_TYPE_AHASH
|
717 CRYPTO_ALG_NEED_FALLBACK
,
718 .cra_blocksize
= SHA384_BLOCK_SIZE
,
719 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
720 .cra_module
= THIS_MODULE
,
724 .do_one_request
= starfive_hash_one_request
,
727 .base
.init
= starfive_hash_init
,
728 .base
.update
= starfive_hash_update
,
729 .base
.final
= starfive_hash_final
,
730 .base
.finup
= starfive_hash_finup
,
731 .base
.digest
= starfive_hash_digest
,
732 .base
.export
= starfive_hash_export
,
733 .base
.import
= starfive_hash_import
,
734 .base
.init_tfm
= starfive_sha512_init_tfm
,
735 .base
.exit_tfm
= starfive_hash_exit_tfm
,
737 .digestsize
= SHA512_DIGEST_SIZE
,
738 .statesize
= sizeof(struct sha512_state
),
740 .cra_name
= "sha512",
741 .cra_driver_name
= "sha512-starfive",
743 .cra_flags
= CRYPTO_ALG_ASYNC
|
744 CRYPTO_ALG_TYPE_AHASH
|
745 CRYPTO_ALG_NEED_FALLBACK
,
746 .cra_blocksize
= SHA512_BLOCK_SIZE
,
747 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
748 .cra_module
= THIS_MODULE
,
752 .do_one_request
= starfive_hash_one_request
,
755 .base
.init
= starfive_hash_init
,
756 .base
.update
= starfive_hash_update
,
757 .base
.final
= starfive_hash_final
,
758 .base
.finup
= starfive_hash_finup
,
759 .base
.digest
= starfive_hash_digest
,
760 .base
.export
= starfive_hash_export
,
761 .base
.import
= starfive_hash_import
,
762 .base
.init_tfm
= starfive_hmac_sha512_init_tfm
,
763 .base
.exit_tfm
= starfive_hash_exit_tfm
,
764 .base
.setkey
= starfive_hash_setkey
,
766 .digestsize
= SHA512_DIGEST_SIZE
,
767 .statesize
= sizeof(struct sha512_state
),
769 .cra_name
= "hmac(sha512)",
770 .cra_driver_name
= "sha512-hmac-starfive",
772 .cra_flags
= CRYPTO_ALG_ASYNC
|
773 CRYPTO_ALG_TYPE_AHASH
|
774 CRYPTO_ALG_NEED_FALLBACK
,
775 .cra_blocksize
= SHA512_BLOCK_SIZE
,
776 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
777 .cra_module
= THIS_MODULE
,
781 .do_one_request
= starfive_hash_one_request
,
784 .base
.init
= starfive_hash_init
,
785 .base
.update
= starfive_hash_update
,
786 .base
.final
= starfive_hash_final
,
787 .base
.finup
= starfive_hash_finup
,
788 .base
.digest
= starfive_hash_digest
,
789 .base
.export
= starfive_hash_export
,
790 .base
.import
= starfive_hash_import
,
791 .base
.init_tfm
= starfive_sm3_init_tfm
,
792 .base
.exit_tfm
= starfive_hash_exit_tfm
,
794 .digestsize
= SM3_DIGEST_SIZE
,
795 .statesize
= sizeof(struct sm3_state
),
798 .cra_driver_name
= "sm3-starfive",
800 .cra_flags
= CRYPTO_ALG_ASYNC
|
801 CRYPTO_ALG_TYPE_AHASH
|
802 CRYPTO_ALG_NEED_FALLBACK
,
803 .cra_blocksize
= SM3_BLOCK_SIZE
,
804 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
805 .cra_module
= THIS_MODULE
,
809 .do_one_request
= starfive_hash_one_request
,
812 .base
.init
= starfive_hash_init
,
813 .base
.update
= starfive_hash_update
,
814 .base
.final
= starfive_hash_final
,
815 .base
.finup
= starfive_hash_finup
,
816 .base
.digest
= starfive_hash_digest
,
817 .base
.export
= starfive_hash_export
,
818 .base
.import
= starfive_hash_import
,
819 .base
.init_tfm
= starfive_hmac_sm3_init_tfm
,
820 .base
.exit_tfm
= starfive_hash_exit_tfm
,
821 .base
.setkey
= starfive_hash_setkey
,
823 .digestsize
= SM3_DIGEST_SIZE
,
824 .statesize
= sizeof(struct sm3_state
),
826 .cra_name
= "hmac(sm3)",
827 .cra_driver_name
= "sm3-hmac-starfive",
829 .cra_flags
= CRYPTO_ALG_ASYNC
|
830 CRYPTO_ALG_TYPE_AHASH
|
831 CRYPTO_ALG_NEED_FALLBACK
,
832 .cra_blocksize
= SM3_BLOCK_SIZE
,
833 .cra_ctxsize
= sizeof(struct starfive_cryp_ctx
),
834 .cra_module
= THIS_MODULE
,
838 .do_one_request
= starfive_hash_one_request
,
843 int starfive_hash_register_algs(void)
845 return crypto_engine_register_ahashes(algs_sha2_sm3
, ARRAY_SIZE(algs_sha2_sm3
));
848 void starfive_hash_unregister_algs(void)
850 crypto_engine_unregister_ahashes(algs_sha2_sm3
, ARRAY_SIZE(algs_sha2_sm3
));