1 // SPDX-License-Identifier: GPL-2.0 2 /* 3 * Hash function and HMAC support for StarFive driver 4 * 5 * Copyright (c) 2022 StarFive Technology 6 * 7 */ 8 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> 23 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) 35 36 #define STARFIVE_HASH_BUFLEN SHA512_BLOCK_SIZE 37 #define STARFIVE_HASH_RESET 0x2 38 39 static inline int starfive_hash_wait_busy(struct starfive_cryp_dev *cryp) 40 { 41 u32 status; 42 43 return readl_relaxed_poll_timeout(cryp->base + STARFIVE_HASH_SHACSR, status, 44 !(status & STARFIVE_HASH_BUSY), 10, 100000); 45 } 46 47 static inline int starfive_hash_wait_hmac_done(struct starfive_cryp_dev *cryp) 48 { 49 u32 status; 50 51 return readl_relaxed_poll_timeout(cryp->base + STARFIVE_HASH_SHACSR, status, 52 (status & STARFIVE_HASH_HMAC_DONE), 10, 100000); 53 } 54 55 static inline int starfive_hash_wait_key_done(struct starfive_cryp_ctx *ctx) 56 { 57 struct starfive_cryp_dev *cryp = ctx->cryp; 58 u32 status; 59 60 return readl_relaxed_poll_timeout(cryp->base + STARFIVE_HASH_SHACSR, status, 61 (status & STARFIVE_HASH_KEY_DONE), 10, 100000); 62 } 63 64 static int starfive_hash_hmac_key(struct starfive_cryp_ctx *ctx) 65 { 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; 70 unsigned char *cl; 71 72 writel(ctx->keylen, cryp->base + STARFIVE_HASH_SHAWKLEN); 73 74 rctx->csr.hash.hmac = 1; 75 rctx->csr.hash.key_flag = 1; 76 77 writel(rctx->csr.hash.v, cryp->base + STARFIVE_HASH_SHACSR); 78 79 for (loop = 0; loop < klen / sizeof(unsigned int); loop++, key++) 80 writel(*key, cryp->base + STARFIVE_HASH_SHAWKR); 81 82 if (klen & 0x3) { 83 cl = (unsigned char *)key; 84 for (loop = 0; loop < (klen & 0x3); loop++, cl++) 85 writeb(*cl, cryp->base + STARFIVE_HASH_SHAWKR); 86 } 87 88 if (starfive_hash_wait_key_done(ctx)) 89 return dev_err_probe(cryp->dev, -ETIMEDOUT, "starfive_hash_wait_key_done error\n"); 90 91 return 0; 92 } 93 94 static void starfive_hash_start(struct starfive_cryp_dev *cryp) 95 { 96 union starfive_hash_csr csr; 97 98 csr.v = readl(cryp->base + STARFIVE_HASH_SHACSR); 99 csr.firstb = 0; 100 csr.final = 1; 101 writel(csr.v, cryp->base + STARFIVE_HASH_SHACSR); 102 } 103 104 static void starfive_hash_dma_callback(void *param) 105 { 106 struct starfive_cryp_dev *cryp = param; 107 108 complete(&cryp->dma_done); 109 } 110 111 static void starfive_hash_dma_init(struct starfive_cryp_dev *cryp) 112 { 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; 118 119 dmaengine_slave_config(cryp->tx, &cryp->cfg_in); 120 121 init_completion(&cryp->dma_done); 122 } 123 124 static int starfive_hash_dma_xfer(struct starfive_cryp_dev *cryp, 125 struct scatterlist *sg) 126 { 127 struct dma_async_tx_descriptor *in_desc; 128 union starfive_alg_cr alg_cr; 129 int ret = 0; 130 131 alg_cr.v = 0; 132 alg_cr.start = 1; 133 alg_cr.hash_dma_en = 1; 134 writel(alg_cr.v, cryp->base + STARFIVE_ALG_CR_OFFSET); 135 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)); 138 139 in_desc = dmaengine_prep_slave_sg(cryp->tx, sg, 1, DMA_MEM_TO_DEV, 140 DMA_PREP_INTERRUPT | DMA_CTRL_ACK); 141 if (!in_desc) { 142 ret = -EINVAL; 143 goto end; 144 } 145 146 reinit_completion(&cryp->dma_done); 147 in_desc->callback = starfive_hash_dma_callback; 148 in_desc->callback_param = cryp; 149 150 dmaengine_submit(in_desc); 151 dma_async_issue_pending(cryp->tx); 152 153 if (!wait_for_completion_timeout(&cryp->dma_done, 154 msecs_to_jiffies(1000))) 155 ret = -ETIMEDOUT; 156 157 end: 158 alg_cr.v = 0; 159 alg_cr.clear = 1; 160 writel(alg_cr.v, cryp->base + STARFIVE_ALG_CR_OFFSET); 161 162 return ret; 163 } 164 165 static int starfive_hash_copy_hash(struct ahash_request *req) 166 { 167 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 168 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(crypto_ahash_reqtfm(req)); 169 int count, *data; 170 int mlen; 171 172 if (!req->result) 173 return 0; 174 175 mlen = rctx->digsize / sizeof(u32); 176 data = (u32 *)req->result; 177 178 for (count = 0; count < mlen; count++) 179 put_unaligned(readl(ctx->cryp->base + STARFIVE_HASH_SHARDR), 180 &data[count]); 181 182 return 0; 183 } 184 185 static void starfive_hash_done_task(struct starfive_cryp_dev *cryp) 186 { 187 int err = cryp->err; 188 189 if (!err) 190 err = starfive_hash_copy_hash(cryp->req.hreq); 191 192 crypto_finalize_hash_request(cryp->engine, cryp->req.hreq, err); 193 } 194 195 static int starfive_hash_one_request(struct crypto_engine *engine, void *areq) 196 { 197 struct ahash_request *req = container_of(areq, struct ahash_request, 198 base); 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; 204 205 writel(STARFIVE_HASH_RESET, cryp->base + STARFIVE_HASH_SHACSR); 206 207 if (starfive_hash_wait_busy(cryp)) 208 return dev_err_probe(cryp->dev, -ETIMEDOUT, "Error resetting hardware\n"); 209 210 rctx->csr.hash.v = 0; 211 rctx->csr.hash.mode = ctx->hash_mode; 212 213 if (ctx->is_hmac) { 214 ret = starfive_hash_hmac_key(ctx); 215 if (ret) 216 return ret; 217 } else { 218 rctx->csr.hash.start = 1; 219 rctx->csr.hash.firstb = 1; 220 writel(rctx->csr.hash.v, cryp->base + STARFIVE_HASH_SHACSR); 221 } 222 223 /* No input message, get digest and end. */ 224 if (!rctx->total) 225 goto hash_start; 226 227 starfive_hash_dma_init(cryp); 228 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); 231 if (src_nents == 0) 232 return -ENOMEM; 233 234 ret = starfive_hash_dma_xfer(cryp, tsg); 235 dma_unmap_sg(cryp->dev, tsg, 1, DMA_TO_DEVICE); 236 if (ret) 237 return ret; 238 } 239 240 hash_start: 241 starfive_hash_start(cryp); 242 243 if (starfive_hash_wait_busy(cryp)) 244 return dev_err_probe(cryp->dev, -ETIMEDOUT, "Error generating digest\n"); 245 246 if (ctx->is_hmac) 247 cryp->err = starfive_hash_wait_hmac_done(cryp); 248 249 starfive_hash_done_task(cryp); 250 251 return 0; 252 } 253 254 static int starfive_hash_init(struct ahash_request *req) 255 { 256 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 257 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 258 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 259 260 ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk); 261 ahash_request_set_callback(&rctx->ahash_fbk_req, 262 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 263 req->base.complete, req->base.data); 264 265 ahash_request_set_crypt(&rctx->ahash_fbk_req, req->src, 266 req->result, req->nbytes); 267 268 return crypto_ahash_init(&rctx->ahash_fbk_req); 269 } 270 271 static int starfive_hash_update(struct ahash_request *req) 272 { 273 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 274 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 275 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 276 277 ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk); 278 ahash_request_set_callback(&rctx->ahash_fbk_req, 279 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 280 req->base.complete, req->base.data); 281 282 ahash_request_set_crypt(&rctx->ahash_fbk_req, req->src, 283 req->result, req->nbytes); 284 285 return crypto_ahash_update(&rctx->ahash_fbk_req); 286 } 287 288 static int starfive_hash_final(struct ahash_request *req) 289 { 290 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 291 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 292 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 293 294 ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk); 295 ahash_request_set_callback(&rctx->ahash_fbk_req, 296 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 297 req->base.complete, req->base.data); 298 299 ahash_request_set_crypt(&rctx->ahash_fbk_req, req->src, 300 req->result, req->nbytes); 301 302 return crypto_ahash_final(&rctx->ahash_fbk_req); 303 } 304 305 static int starfive_hash_finup(struct ahash_request *req) 306 { 307 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 308 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 309 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 310 311 ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk); 312 ahash_request_set_callback(&rctx->ahash_fbk_req, 313 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 314 req->base.complete, req->base.data); 315 316 ahash_request_set_crypt(&rctx->ahash_fbk_req, req->src, 317 req->result, req->nbytes); 318 319 return crypto_ahash_finup(&rctx->ahash_fbk_req); 320 } 321 322 static int starfive_hash_digest(struct ahash_request *req) 323 { 324 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 325 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 326 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 327 struct starfive_cryp_dev *cryp = ctx->cryp; 328 int sg_len; 329 330 memset(rctx, 0, sizeof(struct starfive_cryp_request_ctx)); 331 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 sg_len = sg_nents_for_len(rctx->in_sg, rctx->total); 338 if (sg_len < 0) 339 return sg_len; 340 rctx->in_sg_len = sg_len; 341 ctx->rctx = rctx; 342 343 return crypto_transfer_hash_request_to_engine(cryp->engine, req); 344 } 345 346 static int starfive_hash_export(struct ahash_request *req, void *out) 347 { 348 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 349 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 350 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 351 352 ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk); 353 ahash_request_set_callback(&rctx->ahash_fbk_req, 354 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 355 req->base.complete, req->base.data); 356 357 return crypto_ahash_export(&rctx->ahash_fbk_req, out); 358 } 359 360 static int starfive_hash_import(struct ahash_request *req, const void *in) 361 { 362 struct starfive_cryp_request_ctx *rctx = ahash_request_ctx(req); 363 struct crypto_ahash *tfm = crypto_ahash_reqtfm(req); 364 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(tfm); 365 366 ahash_request_set_tfm(&rctx->ahash_fbk_req, ctx->ahash_fbk); 367 ahash_request_set_callback(&rctx->ahash_fbk_req, 368 req->base.flags & CRYPTO_TFM_REQ_MAY_SLEEP, 369 req->base.complete, req->base.data); 370 371 return crypto_ahash_import(&rctx->ahash_fbk_req, in); 372 } 373 374 static int starfive_hash_init_tfm(struct crypto_ahash *hash, 375 const char *alg_name, 376 unsigned int mode, 377 bool is_hmac) 378 { 379 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(hash); 380 381 ctx->cryp = starfive_cryp_find_dev(ctx); 382 383 if (!ctx->cryp) 384 return -ENODEV; 385 386 ctx->ahash_fbk = crypto_alloc_ahash(alg_name, 0, 387 CRYPTO_ALG_NEED_FALLBACK); 388 389 if (IS_ERR(ctx->ahash_fbk)) 390 return dev_err_probe(ctx->cryp->dev, PTR_ERR(ctx->ahash_fbk), 391 "starfive_hash: Could not load fallback driver.\n"); 392 393 crypto_ahash_set_statesize(hash, crypto_ahash_statesize(ctx->ahash_fbk)); 394 crypto_ahash_set_reqsize(hash, sizeof(struct starfive_cryp_request_ctx) + 395 crypto_ahash_reqsize(ctx->ahash_fbk)); 396 397 ctx->is_hmac = is_hmac; 398 ctx->hash_mode = mode; 399 400 return 0; 401 } 402 403 static void starfive_hash_exit_tfm(struct crypto_ahash *hash) 404 { 405 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(hash); 406 407 crypto_free_ahash(ctx->ahash_fbk); 408 } 409 410 static int starfive_hash_long_setkey(struct starfive_cryp_ctx *ctx, 411 const u8 *key, unsigned int keylen, 412 const char *alg_name) 413 { 414 struct crypto_wait wait; 415 struct ahash_request *req; 416 struct scatterlist sg; 417 struct crypto_ahash *ahash_tfm; 418 u8 *buf; 419 int ret; 420 421 ahash_tfm = crypto_alloc_ahash(alg_name, 0, 0); 422 if (IS_ERR(ahash_tfm)) 423 return PTR_ERR(ahash_tfm); 424 425 req = ahash_request_alloc(ahash_tfm, GFP_KERNEL); 426 if (!req) { 427 ret = -ENOMEM; 428 goto err_free_ahash; 429 } 430 431 crypto_init_wait(&wait); 432 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG, 433 crypto_req_done, &wait); 434 crypto_ahash_clear_flags(ahash_tfm, ~0); 435 436 buf = kzalloc(keylen + STARFIVE_HASH_BUFLEN, GFP_KERNEL); 437 if (!buf) { 438 ret = -ENOMEM; 439 goto err_free_req; 440 } 441 442 memcpy(buf, key, keylen); 443 sg_init_one(&sg, buf, keylen); 444 ahash_request_set_crypt(req, &sg, ctx->key, keylen); 445 446 ret = crypto_wait_req(crypto_ahash_digest(req), &wait); 447 448 kfree(buf); 449 err_free_req: 450 ahash_request_free(req); 451 err_free_ahash: 452 crypto_free_ahash(ahash_tfm); 453 return ret; 454 } 455 456 static int starfive_hash_setkey(struct crypto_ahash *hash, 457 const u8 *key, unsigned int keylen) 458 { 459 struct starfive_cryp_ctx *ctx = crypto_ahash_ctx(hash); 460 unsigned int digestsize = crypto_ahash_digestsize(hash); 461 unsigned int blocksize = crypto_ahash_blocksize(hash); 462 const char *alg_name; 463 464 crypto_ahash_setkey(ctx->ahash_fbk, key, keylen); 465 466 if (keylen <= blocksize) { 467 memcpy(ctx->key, key, keylen); 468 ctx->keylen = keylen; 469 return 0; 470 } 471 472 ctx->keylen = digestsize; 473 474 switch (digestsize) { 475 case SHA224_DIGEST_SIZE: 476 alg_name = "sha224-starfive"; 477 break; 478 case SHA256_DIGEST_SIZE: 479 if (ctx->hash_mode == STARFIVE_HASH_SM3) 480 alg_name = "sm3-starfive"; 481 else 482 alg_name = "sha256-starfive"; 483 break; 484 case SHA384_DIGEST_SIZE: 485 alg_name = "sha384-starfive"; 486 break; 487 case SHA512_DIGEST_SIZE: 488 alg_name = "sha512-starfive"; 489 break; 490 default: 491 return -EINVAL; 492 } 493 494 return starfive_hash_long_setkey(ctx, key, keylen, alg_name); 495 } 496 497 static int starfive_sha224_init_tfm(struct crypto_ahash *hash) 498 { 499 return starfive_hash_init_tfm(hash, "sha224-lib", 500 STARFIVE_HASH_SHA224, 0); 501 } 502 503 static int starfive_sha256_init_tfm(struct crypto_ahash *hash) 504 { 505 return starfive_hash_init_tfm(hash, "sha256-lib", 506 STARFIVE_HASH_SHA256, 0); 507 } 508 509 static int starfive_sha384_init_tfm(struct crypto_ahash *hash) 510 { 511 return starfive_hash_init_tfm(hash, "sha384-lib", 512 STARFIVE_HASH_SHA384, 0); 513 } 514 515 static int starfive_sha512_init_tfm(struct crypto_ahash *hash) 516 { 517 return starfive_hash_init_tfm(hash, "sha512-lib", 518 STARFIVE_HASH_SHA512, 0); 519 } 520 521 static int starfive_sm3_init_tfm(struct crypto_ahash *hash) 522 { 523 return starfive_hash_init_tfm(hash, "sm3-generic", 524 STARFIVE_HASH_SM3, 0); 525 } 526 527 static int starfive_hmac_sha224_init_tfm(struct crypto_ahash *hash) 528 { 529 return starfive_hash_init_tfm(hash, "hmac-sha224-lib", 530 STARFIVE_HASH_SHA224, 1); 531 } 532 533 static int starfive_hmac_sha256_init_tfm(struct crypto_ahash *hash) 534 { 535 return starfive_hash_init_tfm(hash, "hmac-sha256-lib", 536 STARFIVE_HASH_SHA256, 1); 537 } 538 539 static int starfive_hmac_sha384_init_tfm(struct crypto_ahash *hash) 540 { 541 return starfive_hash_init_tfm(hash, "hmac-sha384-lib", 542 STARFIVE_HASH_SHA384, 1); 543 } 544 545 static int starfive_hmac_sha512_init_tfm(struct crypto_ahash *hash) 546 { 547 return starfive_hash_init_tfm(hash, "hmac-sha512-lib", 548 STARFIVE_HASH_SHA512, 1); 549 } 550 551 static int starfive_hmac_sm3_init_tfm(struct crypto_ahash *hash) 552 { 553 return starfive_hash_init_tfm(hash, "hmac(sm3-generic)", 554 STARFIVE_HASH_SM3, 1); 555 } 556 557 static struct ahash_engine_alg algs_sha2_sm3[] = { 558 { 559 .base.init = starfive_hash_init, 560 .base.update = starfive_hash_update, 561 .base.final = starfive_hash_final, 562 .base.finup = starfive_hash_finup, 563 .base.digest = starfive_hash_digest, 564 .base.export = starfive_hash_export, 565 .base.import = starfive_hash_import, 566 .base.init_tfm = starfive_sha224_init_tfm, 567 .base.exit_tfm = starfive_hash_exit_tfm, 568 .base.halg = { 569 .digestsize = SHA224_DIGEST_SIZE, 570 .statesize = sizeof(struct sha256_state), 571 .base = { 572 .cra_name = "sha224", 573 .cra_driver_name = "sha224-starfive", 574 .cra_priority = 200, 575 .cra_flags = CRYPTO_ALG_ASYNC | 576 CRYPTO_ALG_TYPE_AHASH | 577 CRYPTO_ALG_NEED_FALLBACK, 578 .cra_blocksize = SHA224_BLOCK_SIZE, 579 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 580 .cra_module = THIS_MODULE, 581 } 582 }, 583 .op = { 584 .do_one_request = starfive_hash_one_request, 585 }, 586 }, { 587 .base.init = starfive_hash_init, 588 .base.update = starfive_hash_update, 589 .base.final = starfive_hash_final, 590 .base.finup = starfive_hash_finup, 591 .base.digest = starfive_hash_digest, 592 .base.export = starfive_hash_export, 593 .base.import = starfive_hash_import, 594 .base.init_tfm = starfive_hmac_sha224_init_tfm, 595 .base.exit_tfm = starfive_hash_exit_tfm, 596 .base.setkey = starfive_hash_setkey, 597 .base.halg = { 598 .digestsize = SHA224_DIGEST_SIZE, 599 .statesize = sizeof(struct sha256_state), 600 .base = { 601 .cra_name = "hmac(sha224)", 602 .cra_driver_name = "sha224-hmac-starfive", 603 .cra_priority = 200, 604 .cra_flags = CRYPTO_ALG_ASYNC | 605 CRYPTO_ALG_TYPE_AHASH | 606 CRYPTO_ALG_NEED_FALLBACK, 607 .cra_blocksize = SHA224_BLOCK_SIZE, 608 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 609 .cra_module = THIS_MODULE, 610 } 611 }, 612 .op = { 613 .do_one_request = starfive_hash_one_request, 614 }, 615 }, { 616 .base.init = starfive_hash_init, 617 .base.update = starfive_hash_update, 618 .base.final = starfive_hash_final, 619 .base.finup = starfive_hash_finup, 620 .base.digest = starfive_hash_digest, 621 .base.export = starfive_hash_export, 622 .base.import = starfive_hash_import, 623 .base.init_tfm = starfive_sha256_init_tfm, 624 .base.exit_tfm = starfive_hash_exit_tfm, 625 .base.halg = { 626 .digestsize = SHA256_DIGEST_SIZE, 627 .statesize = sizeof(struct sha256_state), 628 .base = { 629 .cra_name = "sha256", 630 .cra_driver_name = "sha256-starfive", 631 .cra_priority = 200, 632 .cra_flags = CRYPTO_ALG_ASYNC | 633 CRYPTO_ALG_TYPE_AHASH | 634 CRYPTO_ALG_NEED_FALLBACK, 635 .cra_blocksize = SHA256_BLOCK_SIZE, 636 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 637 .cra_module = THIS_MODULE, 638 } 639 }, 640 .op = { 641 .do_one_request = starfive_hash_one_request, 642 }, 643 }, { 644 .base.init = starfive_hash_init, 645 .base.update = starfive_hash_update, 646 .base.final = starfive_hash_final, 647 .base.finup = starfive_hash_finup, 648 .base.digest = starfive_hash_digest, 649 .base.export = starfive_hash_export, 650 .base.import = starfive_hash_import, 651 .base.init_tfm = starfive_hmac_sha256_init_tfm, 652 .base.exit_tfm = starfive_hash_exit_tfm, 653 .base.setkey = starfive_hash_setkey, 654 .base.halg = { 655 .digestsize = SHA256_DIGEST_SIZE, 656 .statesize = sizeof(struct sha256_state), 657 .base = { 658 .cra_name = "hmac(sha256)", 659 .cra_driver_name = "sha256-hmac-starfive", 660 .cra_priority = 200, 661 .cra_flags = CRYPTO_ALG_ASYNC | 662 CRYPTO_ALG_TYPE_AHASH | 663 CRYPTO_ALG_NEED_FALLBACK, 664 .cra_blocksize = SHA256_BLOCK_SIZE, 665 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 666 .cra_module = THIS_MODULE, 667 } 668 }, 669 .op = { 670 .do_one_request = starfive_hash_one_request, 671 }, 672 }, { 673 .base.init = starfive_hash_init, 674 .base.update = starfive_hash_update, 675 .base.final = starfive_hash_final, 676 .base.finup = starfive_hash_finup, 677 .base.digest = starfive_hash_digest, 678 .base.export = starfive_hash_export, 679 .base.import = starfive_hash_import, 680 .base.init_tfm = starfive_sha384_init_tfm, 681 .base.exit_tfm = starfive_hash_exit_tfm, 682 .base.halg = { 683 .digestsize = SHA384_DIGEST_SIZE, 684 .statesize = sizeof(struct sha512_state), 685 .base = { 686 .cra_name = "sha384", 687 .cra_driver_name = "sha384-starfive", 688 .cra_priority = 200, 689 .cra_flags = CRYPTO_ALG_ASYNC | 690 CRYPTO_ALG_TYPE_AHASH | 691 CRYPTO_ALG_NEED_FALLBACK, 692 .cra_blocksize = SHA384_BLOCK_SIZE, 693 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 694 .cra_module = THIS_MODULE, 695 } 696 }, 697 .op = { 698 .do_one_request = starfive_hash_one_request, 699 }, 700 }, { 701 .base.init = starfive_hash_init, 702 .base.update = starfive_hash_update, 703 .base.final = starfive_hash_final, 704 .base.finup = starfive_hash_finup, 705 .base.digest = starfive_hash_digest, 706 .base.export = starfive_hash_export, 707 .base.import = starfive_hash_import, 708 .base.init_tfm = starfive_hmac_sha384_init_tfm, 709 .base.exit_tfm = starfive_hash_exit_tfm, 710 .base.setkey = starfive_hash_setkey, 711 .base.halg = { 712 .digestsize = SHA384_DIGEST_SIZE, 713 .statesize = sizeof(struct sha512_state), 714 .base = { 715 .cra_name = "hmac(sha384)", 716 .cra_driver_name = "sha384-hmac-starfive", 717 .cra_priority = 200, 718 .cra_flags = CRYPTO_ALG_ASYNC | 719 CRYPTO_ALG_TYPE_AHASH | 720 CRYPTO_ALG_NEED_FALLBACK, 721 .cra_blocksize = SHA384_BLOCK_SIZE, 722 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 723 .cra_module = THIS_MODULE, 724 } 725 }, 726 .op = { 727 .do_one_request = starfive_hash_one_request, 728 }, 729 }, { 730 .base.init = starfive_hash_init, 731 .base.update = starfive_hash_update, 732 .base.final = starfive_hash_final, 733 .base.finup = starfive_hash_finup, 734 .base.digest = starfive_hash_digest, 735 .base.export = starfive_hash_export, 736 .base.import = starfive_hash_import, 737 .base.init_tfm = starfive_sha512_init_tfm, 738 .base.exit_tfm = starfive_hash_exit_tfm, 739 .base.halg = { 740 .digestsize = SHA512_DIGEST_SIZE, 741 .statesize = sizeof(struct sha512_state), 742 .base = { 743 .cra_name = "sha512", 744 .cra_driver_name = "sha512-starfive", 745 .cra_priority = 200, 746 .cra_flags = CRYPTO_ALG_ASYNC | 747 CRYPTO_ALG_TYPE_AHASH | 748 CRYPTO_ALG_NEED_FALLBACK, 749 .cra_blocksize = SHA512_BLOCK_SIZE, 750 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 751 .cra_module = THIS_MODULE, 752 } 753 }, 754 .op = { 755 .do_one_request = starfive_hash_one_request, 756 }, 757 }, { 758 .base.init = starfive_hash_init, 759 .base.update = starfive_hash_update, 760 .base.final = starfive_hash_final, 761 .base.finup = starfive_hash_finup, 762 .base.digest = starfive_hash_digest, 763 .base.export = starfive_hash_export, 764 .base.import = starfive_hash_import, 765 .base.init_tfm = starfive_hmac_sha512_init_tfm, 766 .base.exit_tfm = starfive_hash_exit_tfm, 767 .base.setkey = starfive_hash_setkey, 768 .base.halg = { 769 .digestsize = SHA512_DIGEST_SIZE, 770 .statesize = sizeof(struct sha512_state), 771 .base = { 772 .cra_name = "hmac(sha512)", 773 .cra_driver_name = "sha512-hmac-starfive", 774 .cra_priority = 200, 775 .cra_flags = CRYPTO_ALG_ASYNC | 776 CRYPTO_ALG_TYPE_AHASH | 777 CRYPTO_ALG_NEED_FALLBACK, 778 .cra_blocksize = SHA512_BLOCK_SIZE, 779 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 780 .cra_module = THIS_MODULE, 781 } 782 }, 783 .op = { 784 .do_one_request = starfive_hash_one_request, 785 }, 786 }, { 787 .base.init = starfive_hash_init, 788 .base.update = starfive_hash_update, 789 .base.final = starfive_hash_final, 790 .base.finup = starfive_hash_finup, 791 .base.digest = starfive_hash_digest, 792 .base.export = starfive_hash_export, 793 .base.import = starfive_hash_import, 794 .base.init_tfm = starfive_sm3_init_tfm, 795 .base.exit_tfm = starfive_hash_exit_tfm, 796 .base.halg = { 797 .digestsize = SM3_DIGEST_SIZE, 798 .statesize = sizeof(struct sm3_state), 799 .base = { 800 .cra_name = "sm3", 801 .cra_driver_name = "sm3-starfive", 802 .cra_priority = 200, 803 .cra_flags = CRYPTO_ALG_ASYNC | 804 CRYPTO_ALG_TYPE_AHASH | 805 CRYPTO_ALG_NEED_FALLBACK, 806 .cra_blocksize = SM3_BLOCK_SIZE, 807 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 808 .cra_module = THIS_MODULE, 809 } 810 }, 811 .op = { 812 .do_one_request = starfive_hash_one_request, 813 }, 814 }, { 815 .base.init = starfive_hash_init, 816 .base.update = starfive_hash_update, 817 .base.final = starfive_hash_final, 818 .base.finup = starfive_hash_finup, 819 .base.digest = starfive_hash_digest, 820 .base.export = starfive_hash_export, 821 .base.import = starfive_hash_import, 822 .base.init_tfm = starfive_hmac_sm3_init_tfm, 823 .base.exit_tfm = starfive_hash_exit_tfm, 824 .base.setkey = starfive_hash_setkey, 825 .base.halg = { 826 .digestsize = SM3_DIGEST_SIZE, 827 .statesize = sizeof(struct sm3_state), 828 .base = { 829 .cra_name = "hmac(sm3)", 830 .cra_driver_name = "sm3-hmac-starfive", 831 .cra_priority = 200, 832 .cra_flags = CRYPTO_ALG_ASYNC | 833 CRYPTO_ALG_TYPE_AHASH | 834 CRYPTO_ALG_NEED_FALLBACK, 835 .cra_blocksize = SM3_BLOCK_SIZE, 836 .cra_ctxsize = sizeof(struct starfive_cryp_ctx), 837 .cra_module = THIS_MODULE, 838 } 839 }, 840 .op = { 841 .do_one_request = starfive_hash_one_request, 842 }, 843 }, 844 }; 845 846 int starfive_hash_register_algs(void) 847 { 848 return crypto_engine_register_ahashes(algs_sha2_sm3, ARRAY_SIZE(algs_sha2_sm3)); 849 } 850 851 void starfive_hash_unregister_algs(void) 852 { 853 crypto_engine_unregister_ahashes(algs_sha2_sm3, ARRAY_SIZE(algs_sha2_sm3)); 854 } 855