Lines Matching +full:assoc +full:- +full:select
1 // SPDX-License-Identifier: GPL-2.0-only
81 /* A type 3 BCM header, expected to precede the SPU header for SPU-M.
83 * 0x60 - ring 0
84 * 0x68 - ring 1
85 * 0x70 - ring 2
86 * 0x78 - ring 3
100 * select_channel() - Select a SPU channel to handle a crypto request. Selects
113 * spu_skcipher_rx_sg_create() - Build up the scatterlist of buffers used to
122 * a 4-byte boundary
140 struct iproc_ctx_s *ctx = rctx->ctx; in spu_skcipher_rx_sg_create()
143 mssg->spu.dst = kcalloc(rx_frag_num, sizeof(struct scatterlist), in spu_skcipher_rx_sg_create()
144 rctx->gfp); in spu_skcipher_rx_sg_create()
145 if (!mssg->spu.dst) in spu_skcipher_rx_sg_create()
146 return -ENOMEM; in spu_skcipher_rx_sg_create()
148 sg = mssg->spu.dst; in spu_skcipher_rx_sg_create()
151 sg_set_buf(sg++, rctx->msg_buf.spu_resp_hdr, ctx->spu_resp_hdr_len); in spu_skcipher_rx_sg_create()
154 if ((ctx->cipher.mode == CIPHER_MODE_XTS) && in spu_skcipher_rx_sg_create()
155 spu->spu_xts_tweak_in_payload()) in spu_skcipher_rx_sg_create()
156 sg_set_buf(sg++, rctx->msg_buf.c.supdt_tweak, in spu_skcipher_rx_sg_create()
160 datalen = spu_msg_sg_add(&sg, &rctx->dst_sg, &rctx->dst_skip, in spu_skcipher_rx_sg_create()
161 rctx->dst_nents, chunksize); in spu_skcipher_rx_sg_create()
165 return -EFAULT; in spu_skcipher_rx_sg_create()
169 sg_set_buf(sg++, rctx->msg_buf.rx_stat_pad, stat_pad_len); in spu_skcipher_rx_sg_create()
171 memset(rctx->msg_buf.rx_stat, 0, SPU_RX_STATUS_LEN); in spu_skcipher_rx_sg_create()
172 sg_set_buf(sg, rctx->msg_buf.rx_stat, spu->spu_rx_status_len()); in spu_skcipher_rx_sg_create()
178 * spu_skcipher_tx_sg_create() - Build up the scatterlist of buffers used to
203 struct iproc_ctx_s *ctx = rctx->ctx; in spu_skcipher_tx_sg_create()
207 mssg->spu.src = kcalloc(tx_frag_num, sizeof(struct scatterlist), in spu_skcipher_tx_sg_create()
208 rctx->gfp); in spu_skcipher_tx_sg_create()
209 if (unlikely(!mssg->spu.src)) in spu_skcipher_tx_sg_create()
210 return -ENOMEM; in spu_skcipher_tx_sg_create()
212 sg = mssg->spu.src; in spu_skcipher_tx_sg_create()
215 sg_set_buf(sg++, rctx->msg_buf.bcm_spu_req_hdr, in spu_skcipher_tx_sg_create()
216 BCM_HDR_LEN + ctx->spu_req_hdr_len); in spu_skcipher_tx_sg_create()
219 if ((ctx->cipher.mode == CIPHER_MODE_XTS) && in spu_skcipher_tx_sg_create()
220 spu->spu_xts_tweak_in_payload()) in spu_skcipher_tx_sg_create()
221 sg_set_buf(sg++, rctx->msg_buf.iv_ctr, SPU_XTS_TWEAK_SIZE); in spu_skcipher_tx_sg_create()
224 datalen = spu_msg_sg_add(&sg, &rctx->src_sg, &rctx->src_skip, in spu_skcipher_tx_sg_create()
225 rctx->src_nents, chunksize); in spu_skcipher_tx_sg_create()
229 return -EFAULT; in spu_skcipher_tx_sg_create()
233 sg_set_buf(sg++, rctx->msg_buf.spu_req_pad, pad_len); in spu_skcipher_tx_sg_create()
235 stat_len = spu->spu_tx_status_len(); in spu_skcipher_tx_sg_create()
237 memset(rctx->msg_buf.tx_stat, 0, stat_len); in spu_skcipher_tx_sg_create()
238 sg_set_buf(sg, rctx->msg_buf.tx_stat, stat_len); in spu_skcipher_tx_sg_create()
248 struct device *dev = &(iproc_priv.pdev->dev); in mailbox_send_message()
252 while ((err == -ENOBUFS) && (retry_cnt < SPU_MB_RETRY_MAX)) { in mailbox_send_message()
270 err = mssg->error; in mailbox_send_message()
282 * handle_skcipher_req() - Submit as much of a block cipher request as fits in
295 * Return: -EINPROGRESS: request has been accepted and result will be returned
302 struct crypto_async_request *areq = rctx->parent; in handle_skcipher_req()
305 struct iproc_ctx_s *ctx = rctx->ctx; in handle_skcipher_req()
324 cipher_parms.alg = ctx->cipher.alg; in handle_skcipher_req()
325 cipher_parms.mode = ctx->cipher.mode; in handle_skcipher_req()
326 cipher_parms.type = ctx->cipher_type; in handle_skcipher_req()
327 cipher_parms.key_len = ctx->enckeylen; in handle_skcipher_req()
328 cipher_parms.key_buf = ctx->enckey; in handle_skcipher_req()
330 cipher_parms.iv_len = rctx->iv_ctr_len; in handle_skcipher_req()
332 mssg = &rctx->mb_mssg; in handle_skcipher_req()
333 chunk_start = rctx->src_sent; in handle_skcipher_req()
334 remaining = rctx->total_todo - chunk_start; in handle_skcipher_req()
337 if ((ctx->max_payload != SPU_MAX_PAYLOAD_INF) && in handle_skcipher_req()
338 (remaining > ctx->max_payload)) in handle_skcipher_req()
339 chunksize = ctx->max_payload; in handle_skcipher_req()
343 rctx->src_sent += chunksize; in handle_skcipher_req()
344 rctx->total_sent = rctx->src_sent; in handle_skcipher_req()
347 rctx->src_nents = spu_sg_count(rctx->src_sg, rctx->src_skip, chunksize); in handle_skcipher_req()
348 rctx->dst_nents = spu_sg_count(rctx->dst_sg, rctx->dst_skip, chunksize); in handle_skcipher_req()
350 if ((ctx->cipher.mode == CIPHER_MODE_CBC) && in handle_skcipher_req()
351 rctx->is_encrypt && chunk_start) in handle_skcipher_req()
353 * Encrypting non-first first chunk. Copy last block of in handle_skcipher_req()
356 sg_copy_part_to_buf(req->dst, rctx->msg_buf.iv_ctr, in handle_skcipher_req()
357 rctx->iv_ctr_len, in handle_skcipher_req()
358 chunk_start - rctx->iv_ctr_len); in handle_skcipher_req()
360 if (rctx->iv_ctr_len) { in handle_skcipher_req()
362 __builtin_memcpy(local_iv_ctr, rctx->msg_buf.iv_ctr, in handle_skcipher_req()
363 rctx->iv_ctr_len); in handle_skcipher_req()
366 if ((ctx->cipher.mode == CIPHER_MODE_CBC) && in handle_skcipher_req()
367 !rctx->is_encrypt) { in handle_skcipher_req()
372 sg_copy_part_to_buf(req->src, rctx->msg_buf.iv_ctr, in handle_skcipher_req()
373 rctx->iv_ctr_len, in handle_skcipher_req()
374 rctx->src_sent - rctx->iv_ctr_len); in handle_skcipher_req()
375 } else if (ctx->cipher.mode == CIPHER_MODE_CTR) { in handle_skcipher_req()
385 add_to_ctr(rctx->msg_buf.iv_ctr, chunksize >> 4); in handle_skcipher_req()
389 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in handle_skcipher_req()
392 flow_log("max_payload %u\n", ctx->max_payload); in handle_skcipher_req()
395 rctx->src_sent, chunk_start, remaining, chunksize); in handle_skcipher_req()
398 memcpy(rctx->msg_buf.bcm_spu_req_hdr, ctx->bcm_spu_req_hdr, in handle_skcipher_req()
399 sizeof(rctx->msg_buf.bcm_spu_req_hdr)); in handle_skcipher_req()
401 spu->spu_cipher_req_finish(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN, in handle_skcipher_req()
402 ctx->spu_req_hdr_len, !(rctx->is_encrypt), in handle_skcipher_req()
407 stat_pad_len = spu->spu_wordalign_padlen(chunksize); in handle_skcipher_req()
413 spu->spu_request_pad(rctx->msg_buf.spu_req_pad, 0, in handle_skcipher_req()
414 0, ctx->auth.alg, ctx->auth.mode, in handle_skcipher_req()
415 rctx->total_sent, stat_pad_len); in handle_skcipher_req()
418 spu->spu_dump_msg_hdr(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN, in handle_skcipher_req()
419 ctx->spu_req_hdr_len); in handle_skcipher_req()
421 dump_sg(rctx->src_sg, rctx->src_skip, chunksize); in handle_skcipher_req()
422 packet_dump(" pad: ", rctx->msg_buf.spu_req_pad, pad_len); in handle_skcipher_req()
429 mssg->type = BRCM_MESSAGE_SPU; in handle_skcipher_req()
430 mssg->ctx = rctx; /* Will be returned in response */ in handle_skcipher_req()
433 rx_frag_num += rctx->dst_nents; in handle_skcipher_req()
435 if ((ctx->cipher.mode == CIPHER_MODE_XTS) && in handle_skcipher_req()
436 spu->spu_xts_tweak_in_payload()) in handle_skcipher_req()
445 tx_frag_num += rctx->src_nents; in handle_skcipher_req()
446 if (spu->spu_tx_status_len()) in handle_skcipher_req()
449 if ((ctx->cipher.mode == CIPHER_MODE_XTS) && in handle_skcipher_req()
450 spu->spu_xts_tweak_in_payload()) in handle_skcipher_req()
458 err = mailbox_send_message(mssg, req->base.flags, rctx->chan_idx); in handle_skcipher_req()
462 return -EINPROGRESS; in handle_skcipher_req()
466 * handle_skcipher_resp() - Process a block cipher SPU response. Updates the
474 struct crypto_async_request *areq = rctx->parent; in handle_skcipher_resp()
477 struct iproc_ctx_s *ctx = rctx->ctx; in handle_skcipher_resp()
481 payload_len = spu->spu_payload_length(rctx->msg_buf.spu_resp_hdr); in handle_skcipher_resp()
487 if ((ctx->cipher.mode == CIPHER_MODE_XTS) && in handle_skcipher_resp()
488 spu->spu_xts_tweak_in_payload() && in handle_skcipher_resp()
490 payload_len -= SPU_XTS_TWEAK_SIZE; in handle_skcipher_resp()
495 __func__, rctx->total_received, payload_len); in handle_skcipher_resp()
497 dump_sg(req->dst, rctx->total_received, payload_len); in handle_skcipher_resp()
499 rctx->total_received += payload_len; in handle_skcipher_resp()
500 if (rctx->total_received == rctx->total_todo) { in handle_skcipher_resp()
503 &iproc_priv.cipher_cnt[ctx->cipher.alg][ctx->cipher.mode]); in handle_skcipher_resp()
508 * spu_ahash_rx_sg_create() - Build up the scatterlist of buffers used to
516 * a 4-byte boundary
534 struct iproc_ctx_s *ctx = rctx->ctx; in spu_ahash_rx_sg_create()
536 mssg->spu.dst = kcalloc(rx_frag_num, sizeof(struct scatterlist), in spu_ahash_rx_sg_create()
537 rctx->gfp); in spu_ahash_rx_sg_create()
538 if (!mssg->spu.dst) in spu_ahash_rx_sg_create()
539 return -ENOMEM; in spu_ahash_rx_sg_create()
541 sg = mssg->spu.dst; in spu_ahash_rx_sg_create()
544 sg_set_buf(sg++, rctx->msg_buf.spu_resp_hdr, ctx->spu_resp_hdr_len); in spu_ahash_rx_sg_create()
547 sg_set_buf(sg++, rctx->msg_buf.digest, digestsize); in spu_ahash_rx_sg_create()
550 sg_set_buf(sg++, rctx->msg_buf.rx_stat_pad, stat_pad_len); in spu_ahash_rx_sg_create()
552 memset(rctx->msg_buf.rx_stat, 0, SPU_RX_STATUS_LEN); in spu_ahash_rx_sg_create()
553 sg_set_buf(sg, rctx->msg_buf.rx_stat, spu->spu_rx_status_len()); in spu_ahash_rx_sg_create()
558 * spu_ahash_tx_sg_create() - Build up the scatterlist of buffers used to send
591 mssg->spu.src = kcalloc(tx_frag_num, sizeof(struct scatterlist), in spu_ahash_tx_sg_create()
592 rctx->gfp); in spu_ahash_tx_sg_create()
593 if (!mssg->spu.src) in spu_ahash_tx_sg_create()
594 return -ENOMEM; in spu_ahash_tx_sg_create()
596 sg = mssg->spu.src; in spu_ahash_tx_sg_create()
599 sg_set_buf(sg++, rctx->msg_buf.bcm_spu_req_hdr, in spu_ahash_tx_sg_create()
603 sg_set_buf(sg++, rctx->hash_carry, hash_carry_len); in spu_ahash_tx_sg_create()
607 datalen = spu_msg_sg_add(&sg, &rctx->src_sg, &rctx->src_skip, in spu_ahash_tx_sg_create()
608 rctx->src_nents, new_data_len); in spu_ahash_tx_sg_create()
612 return -EFAULT; in spu_ahash_tx_sg_create()
617 sg_set_buf(sg++, rctx->msg_buf.spu_req_pad, pad_len); in spu_ahash_tx_sg_create()
619 stat_len = spu->spu_tx_status_len(); in spu_ahash_tx_sg_create()
621 memset(rctx->msg_buf.tx_stat, 0, stat_len); in spu_ahash_tx_sg_create()
622 sg_set_buf(sg, rctx->msg_buf.tx_stat, stat_len); in spu_ahash_tx_sg_create()
629 * handle_ahash_req() - Process an asynchronous hash request from the crypto
647 * -EINPROGRESS: request has been submitted to SPU and response will be
649 * -EAGAIN: non-final request included a small amount of data, which for
657 struct crypto_async_request *areq = rctx->parent; in handle_ahash_req()
662 struct iproc_ctx_s *ctx = rctx->ctx; in handle_ahash_req()
697 rctx->total_todo, rctx->total_sent); in handle_ahash_req()
705 hash_parms.alg = ctx->auth.alg; in handle_ahash_req()
706 hash_parms.mode = ctx->auth.mode; in handle_ahash_req()
708 hash_parms.key_buf = (u8 *)ctx->authkey; in handle_ahash_req()
709 hash_parms.key_len = ctx->authkeylen; in handle_ahash_req()
713 * it's needed for AES-XCBC and AES-CMAC hash algorithms in handle_ahash_req()
716 * For example for 128 bit key, hash algorithm is AES-128. in handle_ahash_req()
718 cipher_parms.type = ctx->cipher_type; in handle_ahash_req()
720 mssg = &rctx->mb_mssg; in handle_ahash_req()
721 chunk_start = rctx->src_sent; in handle_ahash_req()
727 nbytes_to_hash = rctx->total_todo - rctx->total_sent; in handle_ahash_req()
729 if ((ctx->max_payload != SPU_MAX_PAYLOAD_INF) && in handle_ahash_req()
730 (chunksize > ctx->max_payload)) in handle_ahash_req()
731 chunksize = ctx->max_payload; in handle_ahash_req()
738 if (!rctx->is_final) { in handle_ahash_req()
739 u8 *dest = rctx->hash_carry + rctx->hash_carry_len; in handle_ahash_req()
745 chunksize -= rem; in handle_ahash_req()
748 new_len = rem - rctx->hash_carry_len; in handle_ahash_req()
749 sg_copy_part_to_buf(req->src, dest, new_len, in handle_ahash_req()
750 rctx->src_sent); in handle_ahash_req()
751 rctx->hash_carry_len = rem; in handle_ahash_req()
753 rctx->hash_carry_len); in handle_ahash_req()
755 rctx->hash_carry, in handle_ahash_req()
756 rctx->hash_carry_len); in handle_ahash_req()
757 return -EAGAIN; in handle_ahash_req()
763 local_nbuf = rctx->hash_carry_len; in handle_ahash_req()
764 rctx->hash_carry_len = 0; in handle_ahash_req()
767 new_data_len = chunksize - local_nbuf; in handle_ahash_req()
770 rctx->src_nents = spu_sg_count(rctx->src_sg, rctx->src_skip, in handle_ahash_req()
777 hash_parms.type = spu->spu_hash_type(rctx->total_sent); in handle_ahash_req()
779 digestsize = spu->spu_digest_size(ctx->digestsize, ctx->auth.alg, in handle_ahash_req()
784 rctx->total_sent += chunksize; in handle_ahash_req()
785 /* if you sent a prebuf then that wasn't from this req->src */ in handle_ahash_req()
786 rctx->src_sent += new_data_len; in handle_ahash_req()
788 if ((rctx->total_sent == rctx->total_todo) && rctx->is_final) in handle_ahash_req()
789 hash_parms.pad_len = spu->spu_hash_pad_len(hash_parms.alg, in handle_ahash_req()
795 * If a non-first chunk, then include the digest returned from the in handle_ahash_req()
800 hash_parms.key_buf = rctx->incr_hash; in handle_ahash_req()
807 __func__, rctx->is_final, local_nbuf); in handle_ahash_req()
809 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in handle_ahash_req()
812 flow_log("max_payload %u\n", ctx->max_payload); in handle_ahash_req()
817 memcpy(rctx->msg_buf.bcm_spu_req_hdr, BCMHEADER, BCM_HDR_LEN); in handle_ahash_req()
820 spu_hdr_len = spu->spu_create_request(rctx->msg_buf.bcm_spu_req_hdr + in handle_ahash_req()
828 return -EFAULT; in handle_ahash_req()
835 data_pad_len = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, chunksize); in handle_ahash_req()
838 if (spu->spu_tx_status_len()) in handle_ahash_req()
839 stat_pad_len = spu->spu_wordalign_padlen(db_size); in handle_ahash_req()
845 spu->spu_request_pad(rctx->msg_buf.spu_req_pad, data_pad_len, in handle_ahash_req()
846 hash_parms.pad_len, ctx->auth.alg, in handle_ahash_req()
847 ctx->auth.mode, rctx->total_sent, in handle_ahash_req()
851 spu->spu_dump_msg_hdr(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN, in handle_ahash_req()
853 packet_dump(" prebuf: ", rctx->hash_carry, local_nbuf); in handle_ahash_req()
855 dump_sg(rctx->src_sg, rctx->src_skip, new_data_len); in handle_ahash_req()
856 packet_dump(" pad: ", rctx->msg_buf.spu_req_pad, pad_len); in handle_ahash_req()
863 mssg->type = BRCM_MESSAGE_SPU; in handle_ahash_req()
864 mssg->ctx = rctx; /* Will be returned in response */ in handle_ahash_req()
873 tx_frag_num += rctx->src_nents; in handle_ahash_req()
874 if (spu->spu_tx_status_len()) in handle_ahash_req()
881 err = mailbox_send_message(mssg, req->base.flags, rctx->chan_idx); in handle_ahash_req()
885 return -EINPROGRESS; in handle_ahash_req()
889 * spu_hmac_outer_hash() - Request synchonous software compute of the outer hash
895 * -EINVAL if the hash algo is unrecognized
906 switch (ctx->auth.alg) { in spu_hmac_outer_hash()
908 rc = do_shash("md5", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
909 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
912 rc = do_shash("sha1", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
913 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
916 rc = do_shash("sha224", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
917 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
920 rc = do_shash("sha256", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
921 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
924 rc = do_shash("sha384", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
925 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
928 rc = do_shash("sha512", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
929 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
933 rc = -EINVAL; in spu_hmac_outer_hash()
939 * ahash_req_done() - Process a hash result from the SPU hardware.
948 struct crypto_async_request *areq = rctx->parent; in ahash_req_done()
950 struct iproc_ctx_s *ctx = rctx->ctx; in ahash_req_done()
953 memcpy(req->result, rctx->msg_buf.digest, ctx->digestsize); in ahash_req_done()
955 if (spu->spu_type == SPU_TYPE_SPUM) { in ahash_req_done()
959 if (ctx->auth.alg == HASH_ALG_MD5) { in ahash_req_done()
960 __swab32s((u32 *)req->result); in ahash_req_done()
961 __swab32s(((u32 *)req->result) + 1); in ahash_req_done()
962 __swab32s(((u32 *)req->result) + 2); in ahash_req_done()
963 __swab32s(((u32 *)req->result) + 3); in ahash_req_done()
964 __swab32s(((u32 *)req->result) + 4); in ahash_req_done()
968 flow_dump(" digest ", req->result, ctx->digestsize); in ahash_req_done()
971 if (rctx->is_sw_hmac) { in ahash_req_done()
975 flow_dump(" hmac: ", req->result, ctx->digestsize); in ahash_req_done()
978 if (rctx->is_sw_hmac || ctx->auth.mode == HASH_MODE_HMAC) { in ahash_req_done()
980 atomic_inc(&iproc_priv.hmac_cnt[ctx->auth.alg]); in ahash_req_done()
983 atomic_inc(&iproc_priv.hash_cnt[ctx->auth.alg]); in ahash_req_done()
990 * handle_ahash_resp() - Process a SPU response message for a hash request.
997 struct iproc_ctx_s *ctx = rctx->ctx; in handle_ahash_resp()
999 struct crypto_async_request *areq = rctx->parent; in handle_ahash_resp()
1009 memcpy(rctx->incr_hash, rctx->msg_buf.digest, MAX_DIGEST_SIZE); in handle_ahash_resp()
1012 __func__, blocksize, ctx->digestsize); in handle_ahash_resp()
1014 atomic64_add(ctx->digestsize, &iproc_priv.bytes_in); in handle_ahash_resp()
1016 if (rctx->is_final && (rctx->total_sent == rctx->total_todo)) in handle_ahash_resp()
1021 * spu_aead_rx_sg_create() - Build up the scatterlist of buffers used to receive
1034 * a 4-byte boundary
1054 struct iproc_ctx_s *ctx = rctx->ctx; in spu_aead_rx_sg_create()
1059 if (ctx->is_rfc4543) { in spu_aead_rx_sg_create()
1061 data_padlen = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in spu_aead_rx_sg_create()
1065 data_padlen = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in spu_aead_rx_sg_create()
1067 assoc_buf_len = spu->spu_assoc_resp_len(ctx->cipher.mode, in spu_aead_rx_sg_create()
1069 rctx->is_encrypt); in spu_aead_rx_sg_create()
1072 if (ctx->cipher.mode == CIPHER_MODE_CCM) in spu_aead_rx_sg_create()
1073 /* ICV (after data) must be in the next 32-bit word for CCM */ in spu_aead_rx_sg_create()
1074 data_padlen += spu->spu_wordalign_padlen(assoc_buf_len + in spu_aead_rx_sg_create()
1082 mssg->spu.dst = kcalloc(rx_frag_num, sizeof(struct scatterlist), in spu_aead_rx_sg_create()
1083 rctx->gfp); in spu_aead_rx_sg_create()
1084 if (!mssg->spu.dst) in spu_aead_rx_sg_create()
1085 return -ENOMEM; in spu_aead_rx_sg_create()
1087 sg = mssg->spu.dst; in spu_aead_rx_sg_create()
1091 sg_set_buf(sg++, rctx->msg_buf.spu_resp_hdr, ctx->spu_resp_hdr_len); in spu_aead_rx_sg_create()
1095 * Don't write directly to req->dst, because SPU may pad the in spu_aead_rx_sg_create()
1096 * assoc data in the response in spu_aead_rx_sg_create()
1098 memset(rctx->msg_buf.a.resp_aad, 0, assoc_buf_len); in spu_aead_rx_sg_create()
1099 sg_set_buf(sg++, rctx->msg_buf.a.resp_aad, assoc_buf_len); in spu_aead_rx_sg_create()
1107 datalen = spu_msg_sg_add(&sg, &rctx->dst_sg, &rctx->dst_skip, in spu_aead_rx_sg_create()
1108 rctx->dst_nents, resp_len); in spu_aead_rx_sg_create()
1112 return -EFAULT; in spu_aead_rx_sg_create()
1118 memset(rctx->msg_buf.a.gcmpad, 0, data_padlen); in spu_aead_rx_sg_create()
1119 sg_set_buf(sg++, rctx->msg_buf.a.gcmpad, data_padlen); in spu_aead_rx_sg_create()
1123 sg_set_buf(sg++, rctx->msg_buf.digest, digestsize); in spu_aead_rx_sg_create()
1127 memset(rctx->msg_buf.rx_stat_pad, 0, stat_pad_len); in spu_aead_rx_sg_create()
1128 sg_set_buf(sg++, rctx->msg_buf.rx_stat_pad, stat_pad_len); in spu_aead_rx_sg_create()
1131 memset(rctx->msg_buf.rx_stat, 0, SPU_RX_STATUS_LEN); in spu_aead_rx_sg_create()
1132 sg_set_buf(sg, rctx->msg_buf.rx_stat, spu->spu_rx_status_len()); in spu_aead_rx_sg_create()
1138 * spu_aead_tx_sg_create() - Build up the scatterlist of buffers used to send a
1146 * @assoc: crypto API associated data scatterlist
1148 * @assoc_nents: number of scatterlist entries containing assoc data
1168 struct scatterlist *assoc, in spu_aead_tx_sg_create() argument
1177 struct scatterlist *assoc_sg = assoc; in spu_aead_tx_sg_create()
1178 struct iproc_ctx_s *ctx = rctx->ctx; in spu_aead_tx_sg_create()
1184 mssg->spu.src = kcalloc(tx_frag_num, sizeof(struct scatterlist), in spu_aead_tx_sg_create()
1185 rctx->gfp); in spu_aead_tx_sg_create()
1186 if (!mssg->spu.src) in spu_aead_tx_sg_create()
1187 return -ENOMEM; in spu_aead_tx_sg_create()
1189 sg = mssg->spu.src; in spu_aead_tx_sg_create()
1192 sg_set_buf(sg++, rctx->msg_buf.bcm_spu_req_hdr, in spu_aead_tx_sg_create()
1200 pr_err("%s(): failed to copy assoc sg to mbox msg", in spu_aead_tx_sg_create()
1202 return -EFAULT; in spu_aead_tx_sg_create()
1207 sg_set_buf(sg++, rctx->msg_buf.iv_ctr, aead_iv_len); in spu_aead_tx_sg_create()
1210 memset(rctx->msg_buf.a.req_aad_pad, 0, aad_pad_len); in spu_aead_tx_sg_create()
1211 sg_set_buf(sg++, rctx->msg_buf.a.req_aad_pad, aad_pad_len); in spu_aead_tx_sg_create()
1215 if ((chunksize > ctx->digestsize) && incl_icv) in spu_aead_tx_sg_create()
1216 datalen -= ctx->digestsize; in spu_aead_tx_sg_create()
1219 written = spu_msg_sg_add(&sg, &rctx->src_sg, &rctx->src_skip, in spu_aead_tx_sg_create()
1220 rctx->src_nents, datalen); in spu_aead_tx_sg_create()
1224 return -EFAULT; in spu_aead_tx_sg_create()
1229 memset(rctx->msg_buf.spu_req_pad, 0, pad_len); in spu_aead_tx_sg_create()
1230 sg_set_buf(sg++, rctx->msg_buf.spu_req_pad, pad_len); in spu_aead_tx_sg_create()
1234 sg_set_buf(sg++, rctx->msg_buf.digest, ctx->digestsize); in spu_aead_tx_sg_create()
1236 stat_len = spu->spu_tx_status_len(); in spu_aead_tx_sg_create()
1238 memset(rctx->msg_buf.tx_stat, 0, stat_len); in spu_aead_tx_sg_create()
1239 sg_set_buf(sg, rctx->msg_buf.tx_stat, stat_len); in spu_aead_tx_sg_create()
1245 * handle_aead_req() - Submit a SPU request message for the next chunk of the
1254 * truncated algs like sha-224, the SPU returns just the truncated hash in
1255 * response to aead requests. So digestsize is always ctx->digestsize here.
1257 * Return: -EINPROGRESS: crypto request has been accepted and result will be
1264 struct crypto_async_request *areq = rctx->parent; in handle_aead_req()
1267 struct iproc_ctx_s *ctx = rctx->ctx; in handle_aead_req()
1282 unsigned int digestsize = ctx->digestsize; in handle_aead_req()
1290 chunksize = rctx->total_todo; in handle_aead_req()
1298 req_opts.is_inbound = !(rctx->is_encrypt); in handle_aead_req()
1299 req_opts.auth_first = ctx->auth_first; in handle_aead_req()
1301 req_opts.is_esp = ctx->is_esp; in handle_aead_req()
1303 cipher_parms.alg = ctx->cipher.alg; in handle_aead_req()
1304 cipher_parms.mode = ctx->cipher.mode; in handle_aead_req()
1305 cipher_parms.type = ctx->cipher_type; in handle_aead_req()
1306 cipher_parms.key_buf = ctx->enckey; in handle_aead_req()
1307 cipher_parms.key_len = ctx->enckeylen; in handle_aead_req()
1308 cipher_parms.iv_buf = rctx->msg_buf.iv_ctr; in handle_aead_req()
1309 cipher_parms.iv_len = rctx->iv_ctr_len; in handle_aead_req()
1311 hash_parms.alg = ctx->auth.alg; in handle_aead_req()
1312 hash_parms.mode = ctx->auth.mode; in handle_aead_req()
1314 hash_parms.key_buf = (u8 *)ctx->authkey; in handle_aead_req()
1315 hash_parms.key_len = ctx->authkeylen; in handle_aead_req()
1318 if ((ctx->auth.alg == HASH_ALG_SHA224) && in handle_aead_req()
1319 (ctx->authkeylen < SHA224_DIGEST_SIZE)) in handle_aead_req()
1322 aead_parms.assoc_size = req->assoclen; in handle_aead_req()
1323 if (ctx->is_esp && !ctx->is_rfc4543) { in handle_aead_req()
1325 * 8-byte IV is included assoc data in request. SPU2 in handle_aead_req()
1329 aead_parms.assoc_size -= GCM_RFC4106_IV_SIZE; in handle_aead_req()
1331 if (rctx->is_encrypt) { in handle_aead_req()
1346 rctx->src_nents = spu_sg_count(rctx->src_sg, rctx->src_skip, chunksize); in handle_aead_req()
1347 rctx->dst_nents = spu_sg_count(rctx->dst_sg, rctx->dst_skip, chunksize); in handle_aead_req()
1349 assoc_nents = spu_sg_count(rctx->assoc, 0, in handle_aead_req()
1352 mssg = &rctx->mb_mssg; in handle_aead_req()
1354 rctx->total_sent = chunksize; in handle_aead_req()
1355 rctx->src_sent = chunksize; in handle_aead_req()
1356 if (spu->spu_assoc_resp_len(ctx->cipher.mode, in handle_aead_req()
1359 rctx->is_encrypt)) in handle_aead_req()
1362 aead_parms.iv_len = spu->spu_aead_ivlen(ctx->cipher.mode, in handle_aead_req()
1363 rctx->iv_ctr_len); in handle_aead_req()
1365 if (ctx->auth.alg == HASH_ALG_AES) in handle_aead_req()
1366 hash_parms.type = (enum hash_type)ctx->cipher_type; in handle_aead_req()
1369 aead_parms.aad_pad_len = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in handle_aead_req()
1373 aead_parms.data_pad_len = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in handle_aead_req()
1376 if (ctx->cipher.mode == CIPHER_MODE_CCM) { in handle_aead_req()
1379 * 128-bit aligned in handle_aead_req()
1381 aead_parms.aad_pad_len = spu->spu_gcm_ccm_pad_len( in handle_aead_req()
1382 ctx->cipher.mode, in handle_aead_req()
1389 if (!rctx->is_encrypt) in handle_aead_req()
1391 spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in handle_aead_req()
1392 chunksize - digestsize); in handle_aead_req()
1395 spu->spu_ccm_update_iv(digestsize, &cipher_parms, req->assoclen, in handle_aead_req()
1396 chunksize, rctx->is_encrypt, in handle_aead_req()
1397 ctx->is_esp); in handle_aead_req()
1400 if (ctx->is_rfc4543) { in handle_aead_req()
1406 if (!rctx->is_encrypt) in handle_aead_req()
1407 aead_parms.data_pad_len = spu->spu_gcm_ccm_pad_len( in handle_aead_req()
1408 ctx->cipher.mode, in handle_aead_req()
1409 aead_parms.assoc_size + chunksize - in handle_aead_req()
1412 aead_parms.data_pad_len = spu->spu_gcm_ccm_pad_len( in handle_aead_req()
1413 ctx->cipher.mode, in handle_aead_req()
1419 if (spu_req_incl_icv(ctx->cipher.mode, rctx->is_encrypt)) { in handle_aead_req()
1423 sg_copy_part_to_buf(req->src, rctx->msg_buf.digest, digestsize, in handle_aead_req()
1424 req->assoclen + rctx->total_sent - in handle_aead_req()
1430 flow_log("%s()-sent chunksize:%u\n", __func__, chunksize); in handle_aead_req()
1433 memcpy(rctx->msg_buf.bcm_spu_req_hdr, BCMHEADER, BCM_HDR_LEN); in handle_aead_req()
1435 spu_hdr_len = spu->spu_create_request(rctx->msg_buf.bcm_spu_req_hdr + in handle_aead_req()
1445 stat_pad_len = spu->spu_wordalign_padlen(db_size); in handle_aead_req()
1452 spu->spu_request_pad(rctx->msg_buf.spu_req_pad, in handle_aead_req()
1454 ctx->auth.alg, ctx->auth.mode, in handle_aead_req()
1455 rctx->total_sent, stat_pad_len); in handle_aead_req()
1458 spu->spu_dump_msg_hdr(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN, in handle_aead_req()
1460 dump_sg(rctx->assoc, 0, aead_parms.assoc_size); in handle_aead_req()
1461 packet_dump(" aead iv: ", rctx->msg_buf.iv_ctr, aead_parms.iv_len); in handle_aead_req()
1463 dump_sg(rctx->src_sg, rctx->src_skip, chunksize); in handle_aead_req()
1464 packet_dump(" pad: ", rctx->msg_buf.spu_req_pad, pad_len); in handle_aead_req()
1471 mssg->type = BRCM_MESSAGE_SPU; in handle_aead_req()
1472 mssg->ctx = rctx; /* Will be returned in response */ in handle_aead_req()
1475 rx_frag_num += rctx->dst_nents; in handle_aead_req()
1480 * padding. Have to for SHA-224 and other truncated SHAs because SPU in handle_aead_req()
1485 if (((ctx->cipher.mode == CIPHER_MODE_GCM) || in handle_aead_req()
1486 (ctx->cipher.mode == CIPHER_MODE_CCM)) && !rctx->is_encrypt) { in handle_aead_req()
1491 resp_len -= ctx->digestsize; in handle_aead_req()
1494 rx_frag_num -= rctx->dst_nents; in handle_aead_req()
1505 tx_frag_num += rctx->src_nents; in handle_aead_req()
1511 if (spu->spu_tx_status_len()) in handle_aead_req()
1514 rctx->assoc, aead_parms.assoc_size, in handle_aead_req()
1520 err = mailbox_send_message(mssg, req->base.flags, rctx->chan_idx); in handle_aead_req()
1524 return -EINPROGRESS; in handle_aead_req()
1528 * handle_aead_resp() - Process a SPU response message for an AEAD request.
1534 struct crypto_async_request *areq = rctx->parent; in handle_aead_resp()
1537 struct iproc_ctx_s *ctx = rctx->ctx; in handle_aead_resp()
1543 payload_len = spu->spu_payload_length(rctx->msg_buf.spu_resp_hdr); in handle_aead_resp()
1549 if (req->assoclen) in handle_aead_resp()
1550 packet_dump(" assoc_data ", rctx->msg_buf.a.resp_aad, in handle_aead_resp()
1551 req->assoclen); in handle_aead_resp()
1558 result_len = req->cryptlen; in handle_aead_resp()
1559 if (rctx->is_encrypt) { in handle_aead_resp()
1560 icv_offset = req->assoclen + rctx->total_sent; in handle_aead_resp()
1561 packet_dump(" ICV: ", rctx->msg_buf.digest, ctx->digestsize); in handle_aead_resp()
1563 sg_copy_part_from_buf(req->dst, rctx->msg_buf.digest, in handle_aead_resp()
1564 ctx->digestsize, icv_offset); in handle_aead_resp()
1565 result_len += ctx->digestsize; in handle_aead_resp()
1569 dump_sg(req->dst, req->assoclen, result_len); in handle_aead_resp()
1572 if (ctx->cipher.alg == CIPHER_ALG_AES) { in handle_aead_resp()
1573 if (ctx->cipher.mode == CIPHER_MODE_CCM) in handle_aead_resp()
1575 else if (ctx->cipher.mode == CIPHER_MODE_GCM) in handle_aead_resp()
1585 * spu_chunk_cleanup() - Do cleanup after processing one chunk of a request
1594 struct brcm_message *mssg = &rctx->mb_mssg; in spu_chunk_cleanup()
1596 kfree(mssg->spu.src); in spu_chunk_cleanup()
1597 kfree(mssg->spu.dst); in spu_chunk_cleanup()
1602 * finish_req() - Used to invoke the complete callback from the requester when
1611 struct crypto_async_request *areq = rctx->parent; in finish_req()
1619 areq->complete(areq, err); in finish_req()
1623 * spu_rx_callback() - Callback from mailbox framework with a SPU response.
1634 rctx = mssg->ctx; in spu_rx_callback()
1638 err = -EFAULT; in spu_rx_callback()
1643 err = spu->spu_status_process(rctx->msg_buf.rx_stat); in spu_rx_callback()
1647 err = -EBADMSG; in spu_rx_callback()
1652 switch (rctx->ctx->alg->type) { in spu_rx_callback()
1663 err = -EINVAL; in spu_rx_callback()
1671 if (rctx->total_sent < rctx->total_todo) { in spu_rx_callback()
1675 switch (rctx->ctx->alg->type) { in spu_rx_callback()
1681 if (err == -EAGAIN) in spu_rx_callback()
1692 err = -EINVAL; in spu_rx_callback()
1695 if (err == -EINPROGRESS) in spu_rx_callback()
1707 * skcipher_enqueue() - Handle skcipher encrypt or decrypt request.
1711 * Return: -EINPROGRESS if request accepted and result will be returned
1724 rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in skcipher_enqueue()
1726 rctx->parent = &req->base; in skcipher_enqueue()
1727 rctx->is_encrypt = encrypt; in skcipher_enqueue()
1728 rctx->bd_suppress = false; in skcipher_enqueue()
1729 rctx->total_todo = req->cryptlen; in skcipher_enqueue()
1730 rctx->src_sent = 0; in skcipher_enqueue()
1731 rctx->total_sent = 0; in skcipher_enqueue()
1732 rctx->total_received = 0; in skcipher_enqueue()
1733 rctx->ctx = ctx; in skcipher_enqueue()
1736 rctx->src_sg = req->src; in skcipher_enqueue()
1737 rctx->src_nents = 0; in skcipher_enqueue()
1738 rctx->src_skip = 0; in skcipher_enqueue()
1739 rctx->dst_sg = req->dst; in skcipher_enqueue()
1740 rctx->dst_nents = 0; in skcipher_enqueue()
1741 rctx->dst_skip = 0; in skcipher_enqueue()
1743 if (ctx->cipher.mode == CIPHER_MODE_CBC || in skcipher_enqueue()
1744 ctx->cipher.mode == CIPHER_MODE_CTR || in skcipher_enqueue()
1745 ctx->cipher.mode == CIPHER_MODE_OFB || in skcipher_enqueue()
1746 ctx->cipher.mode == CIPHER_MODE_XTS || in skcipher_enqueue()
1747 ctx->cipher.mode == CIPHER_MODE_GCM || in skcipher_enqueue()
1748 ctx->cipher.mode == CIPHER_MODE_CCM) { in skcipher_enqueue()
1749 rctx->iv_ctr_len = in skcipher_enqueue()
1751 memcpy(rctx->msg_buf.iv_ctr, req->iv, rctx->iv_ctr_len); in skcipher_enqueue()
1753 rctx->iv_ctr_len = 0; in skcipher_enqueue()
1757 rctx->chan_idx = select_channel(); in skcipher_enqueue()
1759 if (err != -EINPROGRESS) in skcipher_enqueue()
1776 ctx->cipher_type = CIPHER_TYPE_DES; in des_setkey()
1790 ctx->cipher_type = CIPHER_TYPE_3DES; in threedes_setkey()
1799 if (ctx->cipher.mode == CIPHER_MODE_XTS) in aes_setkey()
1805 ctx->cipher_type = CIPHER_TYPE_AES128; in aes_setkey()
1808 ctx->cipher_type = CIPHER_TYPE_AES192; in aes_setkey()
1811 ctx->cipher_type = CIPHER_TYPE_AES256; in aes_setkey()
1814 return -EINVAL; in aes_setkey()
1816 WARN_ON((ctx->max_payload != SPU_MAX_PAYLOAD_INF) && in aes_setkey()
1817 ((ctx->max_payload % AES_BLOCK_SIZE) != 0)); in aes_setkey()
1833 switch (ctx->cipher.alg) { in skcipher_setkey()
1845 err = -EINVAL; in skcipher_setkey()
1850 memcpy(ctx->enckey, key, keylen); in skcipher_setkey()
1851 ctx->enckeylen = keylen; in skcipher_setkey()
1854 if ((ctx->cipher.alg == CIPHER_ALG_AES) && in skcipher_setkey()
1855 (ctx->cipher.mode == CIPHER_MODE_XTS)) { in skcipher_setkey()
1858 memcpy(ctx->enckey, key + xts_keylen, xts_keylen); in skcipher_setkey()
1859 memcpy(ctx->enckey + xts_keylen, key, xts_keylen); in skcipher_setkey()
1862 if (spu->spu_type == SPU_TYPE_SPUM) in skcipher_setkey()
1864 else if (spu->spu_type == SPU_TYPE_SPU2) in skcipher_setkey()
1866 memset(ctx->bcm_spu_req_hdr, 0, alloc_len); in skcipher_setkey()
1871 cipher_parms.alg = ctx->cipher.alg; in skcipher_setkey()
1872 cipher_parms.mode = ctx->cipher.mode; in skcipher_setkey()
1873 cipher_parms.type = ctx->cipher_type; in skcipher_setkey()
1874 cipher_parms.key_buf = ctx->enckey; in skcipher_setkey()
1875 cipher_parms.key_len = ctx->enckeylen; in skcipher_setkey()
1878 memcpy(ctx->bcm_spu_req_hdr, BCMHEADER, BCM_HDR_LEN); in skcipher_setkey()
1879 ctx->spu_req_hdr_len = in skcipher_setkey()
1880 spu->spu_cipher_req_init(ctx->bcm_spu_req_hdr + BCM_HDR_LEN, in skcipher_setkey()
1883 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, in skcipher_setkey()
1884 ctx->enckeylen, in skcipher_setkey()
1894 flow_log("skcipher_encrypt() nbytes:%u\n", req->cryptlen); in skcipher_encrypt()
1901 flow_log("skcipher_decrypt() nbytes:%u\n", req->cryptlen); in skcipher_decrypt()
1913 flow_log("ahash_enqueue() nbytes:%u\n", req->nbytes); in ahash_enqueue()
1915 rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_enqueue()
1917 rctx->parent = &req->base; in ahash_enqueue()
1918 rctx->ctx = ctx; in ahash_enqueue()
1919 rctx->bd_suppress = true; in ahash_enqueue()
1920 memset(&rctx->mb_mssg, 0, sizeof(struct brcm_message)); in ahash_enqueue()
1923 rctx->src_sg = req->src; in ahash_enqueue()
1924 rctx->src_skip = 0; in ahash_enqueue()
1925 rctx->src_nents = 0; in ahash_enqueue()
1926 rctx->dst_sg = NULL; in ahash_enqueue()
1927 rctx->dst_skip = 0; in ahash_enqueue()
1928 rctx->dst_nents = 0; in ahash_enqueue()
1931 if ((rctx->is_final == 1) && (rctx->total_todo == 0) && in ahash_enqueue()
1934 flow_log("Doing %sfinal %s zero-len hash request in software\n", in ahash_enqueue()
1935 rctx->is_final ? "" : "non-", alg_name); in ahash_enqueue()
1936 err = do_shash((unsigned char *)alg_name, req->result, in ahash_enqueue()
1937 NULL, 0, NULL, 0, ctx->authkey, in ahash_enqueue()
1938 ctx->authkeylen); in ahash_enqueue()
1944 rctx->chan_idx = select_channel(); in ahash_enqueue()
1947 if (err != -EINPROGRESS) in ahash_enqueue()
1951 if (err == -EAGAIN) in ahash_enqueue()
1971 rctx->hash_carry_len = 0; in __ahash_init()
1972 rctx->is_final = 0; in __ahash_init()
1974 rctx->total_todo = 0; in __ahash_init()
1975 rctx->src_sent = 0; in __ahash_init()
1976 rctx->total_sent = 0; in __ahash_init()
1977 rctx->total_received = 0; in __ahash_init()
1979 ctx->digestsize = crypto_ahash_digestsize(tfm); in __ahash_init()
1981 WARN_ON(ctx->digestsize > MAX_DIGEST_SIZE); in __ahash_init()
1983 rctx->is_sw_hmac = false; in __ahash_init()
1985 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, 0, in __ahash_init()
1992 * spu_no_incr_hash() - Determine whether incremental hashing is supported.
1995 * SPU-2 does not support incremental hashing (we'll have to revisit and
1999 * SPU-M also doesn't support incremental hashing of AES-XCBC
2008 if (spu->spu_type == SPU_TYPE_SPU2) in spu_no_incr_hash()
2011 if ((ctx->auth.alg == HASH_ALG_AES) && in spu_no_incr_hash()
2012 (ctx->auth.mode == HASH_MODE_XCBC)) in spu_no_incr_hash()
2041 gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_init()
2043 ctx->shash = kmalloc(sizeof(*ctx->shash) + in ahash_init()
2045 if (!ctx->shash) { in ahash_init()
2046 ret = -ENOMEM; in ahash_init()
2049 ctx->shash->tfm = hash; in ahash_init()
2052 if (ctx->authkeylen > 0) { in ahash_init()
2053 ret = crypto_shash_setkey(hash, ctx->authkey, in ahash_init()
2054 ctx->authkeylen); in ahash_init()
2060 ret = crypto_shash_init(ctx->shash); in ahash_init()
2071 kfree(ctx->shash); in ahash_init()
2082 flow_log("ahash_update() nbytes:%u\n", req->nbytes); in __ahash_update()
2084 if (!req->nbytes) in __ahash_update()
2086 rctx->total_todo += req->nbytes; in __ahash_update()
2087 rctx->src_sent = 0; in __ahash_update()
2107 if (req->src) in ahash_update()
2108 nents = sg_nents(req->src); in ahash_update()
2110 return -EINVAL; in ahash_update()
2113 gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_update()
2115 tmpbuf = kmalloc(req->nbytes, gfp); in ahash_update()
2117 return -ENOMEM; in ahash_update()
2119 if (sg_copy_to_buffer(req->src, nents, tmpbuf, req->nbytes) != in ahash_update()
2120 req->nbytes) { in ahash_update()
2122 return -EINVAL; in ahash_update()
2126 ret = crypto_shash_update(ctx->shash, tmpbuf, req->nbytes); in ahash_update()
2140 flow_log("ahash_final() nbytes:%u\n", req->nbytes); in __ahash_final()
2142 rctx->is_final = 1; in __ahash_final()
2159 ret = crypto_shash_final(ctx->shash, req->result); in ahash_final()
2162 crypto_free_shash(ctx->shash->tfm); in ahash_final()
2163 kfree(ctx->shash); in ahash_final()
2177 flow_log("ahash_finup() nbytes:%u\n", req->nbytes); in __ahash_finup()
2179 rctx->total_todo += req->nbytes; in __ahash_finup()
2180 rctx->src_sent = 0; in __ahash_finup()
2181 rctx->is_final = 1; in __ahash_finup()
2201 if (req->src) { in ahash_finup()
2202 nents = sg_nents(req->src); in ahash_finup()
2204 ret = -EINVAL; in ahash_finup()
2209 gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_finup()
2211 tmpbuf = kmalloc(req->nbytes, gfp); in ahash_finup()
2213 ret = -ENOMEM; in ahash_finup()
2217 if (sg_copy_to_buffer(req->src, nents, tmpbuf, req->nbytes) != in ahash_finup()
2218 req->nbytes) { in ahash_finup()
2219 ret = -EINVAL; in ahash_finup()
2224 ret = crypto_shash_finup(ctx->shash, tmpbuf, req->nbytes, in ahash_finup()
2225 req->result); in ahash_finup()
2235 crypto_free_shash(ctx->shash->tfm); in ahash_finup()
2236 kfree(ctx->shash); in ahash_finup()
2244 flow_log("ahash_digest() nbytes:%u\n", req->nbytes); in ahash_digest()
2263 if (ctx->auth.alg == HASH_ALG_AES) { in ahash_setkey()
2266 ctx->cipher_type = CIPHER_TYPE_AES128; in ahash_setkey()
2269 ctx->cipher_type = CIPHER_TYPE_AES192; in ahash_setkey()
2272 ctx->cipher_type = CIPHER_TYPE_AES256; in ahash_setkey()
2276 return -EINVAL; in ahash_setkey()
2280 return -EINVAL; in ahash_setkey()
2282 memcpy(ctx->authkey, key, keylen); in ahash_setkey()
2283 ctx->authkeylen = keylen; in ahash_setkey()
2293 spu_exp->total_todo = rctx->total_todo; in ahash_export()
2294 spu_exp->total_sent = rctx->total_sent; in ahash_export()
2295 spu_exp->is_sw_hmac = rctx->is_sw_hmac; in ahash_export()
2296 memcpy(spu_exp->hash_carry, rctx->hash_carry, sizeof(rctx->hash_carry)); in ahash_export()
2297 spu_exp->hash_carry_len = rctx->hash_carry_len; in ahash_export()
2298 memcpy(spu_exp->incr_hash, rctx->incr_hash, sizeof(rctx->incr_hash)); in ahash_export()
2308 rctx->total_todo = spu_exp->total_todo; in ahash_import()
2309 rctx->total_sent = spu_exp->total_sent; in ahash_import()
2310 rctx->is_sw_hmac = spu_exp->is_sw_hmac; in ahash_import()
2311 memcpy(rctx->hash_carry, spu_exp->hash_carry, sizeof(rctx->hash_carry)); in ahash_import()
2312 rctx->hash_carry_len = spu_exp->hash_carry_len; in ahash_import()
2313 memcpy(rctx->incr_hash, spu_exp->incr_hash, sizeof(rctx->incr_hash)); in ahash_import()
2333 switch (ctx->auth.alg) { in ahash_hmac_setkey()
2335 rc = do_shash("md5", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2339 rc = do_shash("sha1", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2343 rc = do_shash("sha224", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2347 rc = do_shash("sha256", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2351 rc = do_shash("sha384", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2355 rc = do_shash("sha512", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2359 rc = do_shash("sha3-224", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2363 rc = do_shash("sha3-256", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2367 rc = do_shash("sha3-384", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2371 rc = do_shash("sha3-512", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2376 return -EINVAL; in ahash_hmac_setkey()
2380 __func__, rc, hash_alg_name[ctx->auth.alg]); in ahash_hmac_setkey()
2383 ctx->authkeylen = digestsize; in ahash_hmac_setkey()
2386 flow_dump(" newkey: ", ctx->authkey, ctx->authkeylen); in ahash_hmac_setkey()
2388 memcpy(ctx->authkey, key, keylen); in ahash_hmac_setkey()
2389 ctx->authkeylen = keylen; in ahash_hmac_setkey()
2398 memcpy(ctx->ipad, ctx->authkey, ctx->authkeylen); in ahash_hmac_setkey()
2399 memset(ctx->ipad + ctx->authkeylen, 0, in ahash_hmac_setkey()
2400 blocksize - ctx->authkeylen); in ahash_hmac_setkey()
2401 ctx->authkeylen = 0; in ahash_hmac_setkey()
2402 memcpy(ctx->opad, ctx->ipad, blocksize); in ahash_hmac_setkey()
2405 ctx->ipad[index] ^= HMAC_IPAD_VALUE; in ahash_hmac_setkey()
2406 ctx->opad[index] ^= HMAC_OPAD_VALUE; in ahash_hmac_setkey()
2409 flow_dump(" ipad: ", ctx->ipad, blocksize); in ahash_hmac_setkey()
2410 flow_dump(" opad: ", ctx->opad, blocksize); in ahash_hmac_setkey()
2412 ctx->digestsize = digestsize; in ahash_hmac_setkey()
2432 /* SPU-M can do incr hashing but needs sw for outer HMAC */ in ahash_hmac_init()
2433 rctx->is_sw_hmac = true; in ahash_hmac_init()
2434 ctx->auth.mode = HASH_MODE_HASH; in ahash_hmac_init()
2436 memcpy(rctx->hash_carry, ctx->ipad, blocksize); in ahash_hmac_init()
2437 rctx->hash_carry_len = blocksize; in ahash_hmac_init()
2438 rctx->total_todo += blocksize; in ahash_hmac_init()
2446 flow_log("ahash_hmac_update() nbytes:%u\n", req->nbytes); in ahash_hmac_update()
2448 if (!req->nbytes) in ahash_hmac_update()
2456 flow_log("ahash_hmac_final() nbytes:%u\n", req->nbytes); in ahash_hmac_final()
2463 flow_log("ahash_hmac_finupl() nbytes:%u\n", req->nbytes); in ahash_hmac_finup()
2476 flow_log("ahash_hmac_digest() nbytes:%u\n", req->nbytes); in ahash_hmac_digest()
2490 rctx->is_sw_hmac = false; in ahash_hmac_digest()
2491 ctx->auth.mode = HASH_MODE_HMAC; in ahash_hmac_digest()
2493 rctx->is_sw_hmac = true; in ahash_hmac_digest()
2494 ctx->auth.mode = HASH_MODE_HASH; in ahash_hmac_digest()
2496 memcpy(rctx->hash_carry, ctx->ipad, blocksize); in ahash_hmac_digest()
2497 rctx->hash_carry_len = blocksize; in ahash_hmac_digest()
2498 rctx->total_todo += blocksize; in ahash_hmac_digest()
2515 * SPU hardware cannot handle the AES-GCM/CCM case where plaintext in aead_need_fallback()
2518 if (((ctx->cipher.mode == CIPHER_MODE_GCM) || in aead_need_fallback()
2519 (ctx->cipher.mode == CIPHER_MODE_CCM)) && in aead_need_fallback()
2520 (req->assoclen == 0)) { in aead_need_fallback()
2521 if ((rctx->is_encrypt && (req->cryptlen == 0)) || in aead_need_fallback()
2522 (!rctx->is_encrypt && (req->cryptlen == ctx->digestsize))) { in aead_need_fallback()
2528 /* SPU-M hardware only supports CCM digest size of 8, 12, or 16 bytes */ in aead_need_fallback()
2529 if ((ctx->cipher.mode == CIPHER_MODE_CCM) && in aead_need_fallback()
2530 (spu->spu_type == SPU_TYPE_SPUM) && in aead_need_fallback()
2531 (ctx->digestsize != 8) && (ctx->digestsize != 12) && in aead_need_fallback()
2532 (ctx->digestsize != 16)) { in aead_need_fallback()
2534 __func__, ctx->digestsize); in aead_need_fallback()
2539 * SPU-M on NSP has an issue where AES-CCM hash is not correct in aead_need_fallback()
2542 if ((ctx->cipher.mode == CIPHER_MODE_CCM) && in aead_need_fallback()
2543 (spu->spu_subtype == SPU_SUBTYPE_SPUM_NSP) && in aead_need_fallback()
2544 (req->assoclen == 0)) { in aead_need_fallback()
2554 if (ctx->cipher.mode == CIPHER_MODE_GCM && in aead_need_fallback()
2555 ctx->cipher.alg == CIPHER_ALG_AES && in aead_need_fallback()
2556 rctx->iv_ctr_len == GCM_RFC4106_IV_SIZE && in aead_need_fallback()
2557 req->assoclen != 16 && req->assoclen != 20) { in aead_need_fallback()
2563 payload_len = req->cryptlen; in aead_need_fallback()
2564 if (spu->spu_type == SPU_TYPE_SPUM) in aead_need_fallback()
2565 payload_len += req->assoclen; in aead_need_fallback()
2569 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in aead_need_fallback()
2572 return payload_len > ctx->max_payload; in aead_need_fallback()
2584 areq->tfm = crypto_aead_tfm(aead); in aead_complete()
2586 areq->complete = rctx->old_complete; in aead_complete()
2587 areq->data = rctx->old_data; in aead_complete()
2589 areq->complete(areq, err); in aead_complete()
2603 if (ctx->fallback_cipher) { in aead_do_fallback()
2605 rctx->old_tfm = tfm; in aead_do_fallback()
2606 aead_request_set_tfm(req, ctx->fallback_cipher); in aead_do_fallback()
2611 rctx->old_complete = req->base.complete; in aead_do_fallback()
2612 rctx->old_data = req->base.data; in aead_do_fallback()
2621 * -EINPROGRESS). So restore request state here. in aead_do_fallback()
2624 rctx->old_complete, req); in aead_do_fallback()
2625 req->base.data = rctx->old_data; in aead_do_fallback()
2631 err = -EINVAL; in aead_do_fallback()
2646 if (req->assoclen > MAX_ASSOC_SIZE) { in aead_enqueue()
2649 __func__, req->assoclen, MAX_ASSOC_SIZE); in aead_enqueue()
2650 return -EINVAL; in aead_enqueue()
2653 rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in aead_enqueue()
2655 rctx->parent = &req->base; in aead_enqueue()
2656 rctx->is_encrypt = is_encrypt; in aead_enqueue()
2657 rctx->bd_suppress = false; in aead_enqueue()
2658 rctx->total_todo = req->cryptlen; in aead_enqueue()
2659 rctx->src_sent = 0; in aead_enqueue()
2660 rctx->total_sent = 0; in aead_enqueue()
2661 rctx->total_received = 0; in aead_enqueue()
2662 rctx->is_sw_hmac = false; in aead_enqueue()
2663 rctx->ctx = ctx; in aead_enqueue()
2664 memset(&rctx->mb_mssg, 0, sizeof(struct brcm_message)); in aead_enqueue()
2666 /* assoc data is at start of src sg */ in aead_enqueue()
2667 rctx->assoc = req->src; in aead_enqueue()
2670 * Init current position in src scatterlist to be after assoc data. in aead_enqueue()
2671 * src_skip set to buffer offset where data begins. (Assoc data could in aead_enqueue()
2674 if (spu_sg_at_offset(req->src, req->assoclen, &rctx->src_sg, in aead_enqueue()
2675 &rctx->src_skip) < 0) { in aead_enqueue()
2678 return -EINVAL; in aead_enqueue()
2681 rctx->src_nents = 0; in aead_enqueue()
2682 rctx->dst_nents = 0; in aead_enqueue()
2683 if (req->dst == req->src) { in aead_enqueue()
2684 rctx->dst_sg = rctx->src_sg; in aead_enqueue()
2685 rctx->dst_skip = rctx->src_skip; in aead_enqueue()
2688 * Expect req->dst to have room for assoc data followed by in aead_enqueue()
2690 * to point beyond assoc len offset. in aead_enqueue()
2692 if (spu_sg_at_offset(req->dst, req->assoclen, &rctx->dst_sg, in aead_enqueue()
2693 &rctx->dst_skip) < 0) { in aead_enqueue()
2696 return -EINVAL; in aead_enqueue()
2700 if (ctx->cipher.mode == CIPHER_MODE_CBC || in aead_enqueue()
2701 ctx->cipher.mode == CIPHER_MODE_CTR || in aead_enqueue()
2702 ctx->cipher.mode == CIPHER_MODE_OFB || in aead_enqueue()
2703 ctx->cipher.mode == CIPHER_MODE_XTS || in aead_enqueue()
2704 ctx->cipher.mode == CIPHER_MODE_GCM) { in aead_enqueue()
2705 rctx->iv_ctr_len = in aead_enqueue()
2706 ctx->salt_len + in aead_enqueue()
2708 } else if (ctx->cipher.mode == CIPHER_MODE_CCM) { in aead_enqueue()
2709 rctx->iv_ctr_len = CCM_AES_IV_SIZE; in aead_enqueue()
2711 rctx->iv_ctr_len = 0; in aead_enqueue()
2714 rctx->hash_carry_len = 0; in aead_enqueue()
2716 flow_log(" src sg: %p\n", req->src); in aead_enqueue()
2717 flow_log(" rctx->src_sg: %p, src_skip %u\n", in aead_enqueue()
2718 rctx->src_sg, rctx->src_skip); in aead_enqueue()
2719 flow_log(" assoc: %p, assoclen %u\n", rctx->assoc, req->assoclen); in aead_enqueue()
2720 flow_log(" dst sg: %p\n", req->dst); in aead_enqueue()
2721 flow_log(" rctx->dst_sg: %p, dst_skip %u\n", in aead_enqueue()
2722 rctx->dst_sg, rctx->dst_skip); in aead_enqueue()
2723 flow_log(" iv_ctr_len:%u\n", rctx->iv_ctr_len); in aead_enqueue()
2724 flow_dump(" iv: ", req->iv, rctx->iv_ctr_len); in aead_enqueue()
2725 flow_log(" authkeylen:%u\n", ctx->authkeylen); in aead_enqueue()
2726 flow_log(" is_esp: %s\n", ctx->is_esp ? "yes" : "no"); in aead_enqueue()
2728 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in aead_enqueue()
2731 flow_log(" max_payload: %u\n", ctx->max_payload); in aead_enqueue()
2740 if (rctx->iv_ctr_len) { in aead_enqueue()
2741 if (ctx->salt_len) in aead_enqueue()
2742 memcpy(rctx->msg_buf.iv_ctr + ctx->salt_offset, in aead_enqueue()
2743 ctx->salt, ctx->salt_len); in aead_enqueue()
2744 memcpy(rctx->msg_buf.iv_ctr + ctx->salt_offset + ctx->salt_len, in aead_enqueue()
2745 req->iv, in aead_enqueue()
2746 rctx->iv_ctr_len - ctx->salt_len - ctx->salt_offset); in aead_enqueue()
2749 rctx->chan_idx = select_channel(); in aead_enqueue()
2751 if (err != -EINPROGRESS) in aead_enqueue()
2779 ctx->enckeylen = keys.enckeylen; in aead_authenc_setkey()
2780 ctx->authkeylen = keys.authkeylen; in aead_authenc_setkey()
2782 memcpy(ctx->enckey, keys.enckey, keys.enckeylen); in aead_authenc_setkey()
2784 memset(ctx->authkey, 0, sizeof(ctx->authkey)); in aead_authenc_setkey()
2785 memcpy(ctx->authkey, keys.authkey, keys.authkeylen); in aead_authenc_setkey()
2787 switch (ctx->alg->cipher_info.alg) { in aead_authenc_setkey()
2790 return -EINVAL; in aead_authenc_setkey()
2792 ctx->cipher_type = CIPHER_TYPE_DES; in aead_authenc_setkey()
2796 return -EINVAL; in aead_authenc_setkey()
2798 ctx->cipher_type = CIPHER_TYPE_3DES; in aead_authenc_setkey()
2801 switch (ctx->enckeylen) { in aead_authenc_setkey()
2803 ctx->cipher_type = CIPHER_TYPE_AES128; in aead_authenc_setkey()
2806 ctx->cipher_type = CIPHER_TYPE_AES192; in aead_authenc_setkey()
2809 ctx->cipher_type = CIPHER_TYPE_AES256; in aead_authenc_setkey()
2817 return -EINVAL; in aead_authenc_setkey()
2820 flow_log(" enckeylen:%u authkeylen:%u\n", ctx->enckeylen, in aead_authenc_setkey()
2821 ctx->authkeylen); in aead_authenc_setkey()
2822 flow_dump(" enc: ", ctx->enckey, ctx->enckeylen); in aead_authenc_setkey()
2823 flow_dump(" auth: ", ctx->authkey, ctx->authkeylen); in aead_authenc_setkey()
2826 if (ctx->fallback_cipher) { in aead_authenc_setkey()
2829 ctx->fallback_cipher->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; in aead_authenc_setkey()
2830 ctx->fallback_cipher->base.crt_flags |= in aead_authenc_setkey()
2831 tfm->crt_flags & CRYPTO_TFM_REQ_MASK; in aead_authenc_setkey()
2832 ret = crypto_aead_setkey(ctx->fallback_cipher, key, keylen); in aead_authenc_setkey()
2837 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, in aead_authenc_setkey()
2838 ctx->enckeylen, in aead_authenc_setkey()
2846 ctx->enckeylen = 0; in aead_authenc_setkey()
2847 ctx->authkeylen = 0; in aead_authenc_setkey()
2848 ctx->digestsize = 0; in aead_authenc_setkey()
2850 return -EINVAL; in aead_authenc_setkey()
2865 if (!ctx->is_esp) in aead_gcm_ccm_setkey()
2866 ctx->digestsize = keylen; in aead_gcm_ccm_setkey()
2868 ctx->enckeylen = keylen; in aead_gcm_ccm_setkey()
2869 ctx->authkeylen = 0; in aead_gcm_ccm_setkey()
2871 switch (ctx->enckeylen) { in aead_gcm_ccm_setkey()
2873 ctx->cipher_type = CIPHER_TYPE_AES128; in aead_gcm_ccm_setkey()
2876 ctx->cipher_type = CIPHER_TYPE_AES192; in aead_gcm_ccm_setkey()
2879 ctx->cipher_type = CIPHER_TYPE_AES256; in aead_gcm_ccm_setkey()
2885 memcpy(ctx->enckey, key, ctx->enckeylen); in aead_gcm_ccm_setkey()
2887 flow_log(" enckeylen:%u authkeylen:%u\n", ctx->enckeylen, in aead_gcm_ccm_setkey()
2888 ctx->authkeylen); in aead_gcm_ccm_setkey()
2889 flow_dump(" enc: ", ctx->enckey, ctx->enckeylen); in aead_gcm_ccm_setkey()
2890 flow_dump(" auth: ", ctx->authkey, ctx->authkeylen); in aead_gcm_ccm_setkey()
2893 if (ctx->fallback_cipher) { in aead_gcm_ccm_setkey()
2896 ctx->fallback_cipher->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; in aead_gcm_ccm_setkey()
2897 ctx->fallback_cipher->base.crt_flags |= in aead_gcm_ccm_setkey()
2898 tfm->crt_flags & CRYPTO_TFM_REQ_MASK; in aead_gcm_ccm_setkey()
2899 ret = crypto_aead_setkey(ctx->fallback_cipher, key, in aead_gcm_ccm_setkey()
2900 keylen + ctx->salt_len); in aead_gcm_ccm_setkey()
2905 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, in aead_gcm_ccm_setkey()
2906 ctx->enckeylen, in aead_gcm_ccm_setkey()
2911 flow_log(" enckeylen:%u authkeylen:%u\n", ctx->enckeylen, in aead_gcm_ccm_setkey()
2912 ctx->authkeylen); in aead_gcm_ccm_setkey()
2917 ctx->enckeylen = 0; in aead_gcm_ccm_setkey()
2918 ctx->authkeylen = 0; in aead_gcm_ccm_setkey()
2919 ctx->digestsize = 0; in aead_gcm_ccm_setkey()
2921 return -EINVAL; in aead_gcm_ccm_setkey()
2925 * aead_gcm_esp_setkey() - setkey() operation for ESP variant of GCM AES.
2943 return -EINVAL; in aead_gcm_esp_setkey()
2945 ctx->salt_len = GCM_ESP_SALT_SIZE; in aead_gcm_esp_setkey()
2946 ctx->salt_offset = GCM_ESP_SALT_OFFSET; in aead_gcm_esp_setkey()
2947 memcpy(ctx->salt, key + keylen - GCM_ESP_SALT_SIZE, GCM_ESP_SALT_SIZE); in aead_gcm_esp_setkey()
2948 keylen -= GCM_ESP_SALT_SIZE; in aead_gcm_esp_setkey()
2949 ctx->digestsize = GCM_ESP_DIGESTSIZE; in aead_gcm_esp_setkey()
2950 ctx->is_esp = true; in aead_gcm_esp_setkey()
2951 flow_dump("salt: ", ctx->salt, GCM_ESP_SALT_SIZE); in aead_gcm_esp_setkey()
2957 * rfc4543_gcm_esp_setkey() - setkey operation for RFC4543 variant of GCM/GMAC.
2975 return -EINVAL; in rfc4543_gcm_esp_setkey()
2977 ctx->salt_len = GCM_ESP_SALT_SIZE; in rfc4543_gcm_esp_setkey()
2978 ctx->salt_offset = GCM_ESP_SALT_OFFSET; in rfc4543_gcm_esp_setkey()
2979 memcpy(ctx->salt, key + keylen - GCM_ESP_SALT_SIZE, GCM_ESP_SALT_SIZE); in rfc4543_gcm_esp_setkey()
2980 keylen -= GCM_ESP_SALT_SIZE; in rfc4543_gcm_esp_setkey()
2981 ctx->digestsize = GCM_ESP_DIGESTSIZE; in rfc4543_gcm_esp_setkey()
2982 ctx->is_esp = true; in rfc4543_gcm_esp_setkey()
2983 ctx->is_rfc4543 = true; in rfc4543_gcm_esp_setkey()
2984 flow_dump("salt: ", ctx->salt, GCM_ESP_SALT_SIZE); in rfc4543_gcm_esp_setkey()
2990 * aead_ccm_esp_setkey() - setkey() operation for ESP variant of CCM AES.
3008 return -EINVAL; in aead_ccm_esp_setkey()
3010 ctx->salt_len = CCM_ESP_SALT_SIZE; in aead_ccm_esp_setkey()
3011 ctx->salt_offset = CCM_ESP_SALT_OFFSET; in aead_ccm_esp_setkey()
3012 memcpy(ctx->salt, key + keylen - CCM_ESP_SALT_SIZE, CCM_ESP_SALT_SIZE); in aead_ccm_esp_setkey()
3013 keylen -= CCM_ESP_SALT_SIZE; in aead_ccm_esp_setkey()
3014 ctx->is_esp = true; in aead_ccm_esp_setkey()
3015 flow_dump("salt: ", ctx->salt, CCM_ESP_SALT_SIZE); in aead_ccm_esp_setkey()
3026 __func__, ctx->authkeylen, authsize); in aead_setauthsize()
3028 ctx->digestsize = authsize; in aead_setauthsize()
3031 if (ctx->fallback_cipher) { in aead_setauthsize()
3034 ret = crypto_aead_setauthsize(ctx->fallback_cipher, authsize); in aead_setauthsize()
3044 flow_log("%s() cryptlen:%u %08x\n", __func__, req->cryptlen, in aead_encrypt()
3045 req->cryptlen); in aead_encrypt()
3046 dump_sg(req->src, 0, req->cryptlen + req->assoclen); in aead_encrypt()
3047 flow_log(" assoc_len:%u\n", req->assoclen); in aead_encrypt()
3054 flow_log("%s() cryptlen:%u\n", __func__, req->cryptlen); in aead_decrypt()
3055 dump_sg(req->src, 0, req->cryptlen + req->assoclen); in aead_decrypt()
3056 flow_log(" assoc_len:%u\n", req->assoclen); in aead_decrypt()
3069 .cra_driver_name = "gcm-aes-iproc",
3092 .cra_driver_name = "ccm-aes-iproc",
3115 .cra_driver_name = "gcm-aes-esp-iproc",
3138 .cra_driver_name = "ccm-aes-esp-iproc",
3161 .cra_driver_name = "gmac-aes-esp-iproc",
3184 .cra_driver_name = "authenc-hmac-md5-cbc-aes-iproc",
3209 .cra_driver_name = "authenc-hmac-sha1-cbc-aes-iproc",
3234 .cra_driver_name = "authenc-hmac-sha256-cbc-aes-iproc",
3259 .cra_driver_name = "authenc-hmac-md5-cbc-des-iproc",
3284 .cra_driver_name = "authenc-hmac-sha1-cbc-des-iproc",
3309 .cra_driver_name = "authenc-hmac-sha224-cbc-des-iproc",
3334 .cra_driver_name = "authenc-hmac-sha256-cbc-des-iproc",
3359 .cra_driver_name = "authenc-hmac-sha384-cbc-des-iproc",
3384 .cra_driver_name = "authenc-hmac-sha512-cbc-des-iproc",
3409 .cra_driver_name = "authenc-hmac-md5-cbc-des3-iproc",
3434 .cra_driver_name = "authenc-hmac-sha1-cbc-des3-iproc",
3459 .cra_driver_name = "authenc-hmac-sha224-cbc-des3-iproc",
3484 .cra_driver_name = "authenc-hmac-sha256-cbc-des3-iproc",
3509 .cra_driver_name = "authenc-hmac-sha384-cbc-des3-iproc",
3534 .cra_driver_name = "authenc-hmac-sha512-cbc-des3-iproc",
3560 .base.cra_driver_name = "ofb-des-iproc",
3579 .base.cra_driver_name = "cbc-des-iproc",
3598 .base.cra_driver_name = "ecb-des-iproc",
3617 .base.cra_driver_name = "ofb-des3-iproc",
3636 .base.cra_driver_name = "cbc-des3-iproc",
3655 .base.cra_driver_name = "ecb-des3-iproc",
3674 .base.cra_driver_name = "ofb-aes-iproc",
3693 .base.cra_driver_name = "cbc-aes-iproc",
3712 .base.cra_driver_name = "ecb-aes-iproc",
3731 .base.cra_driver_name = "ctr-aes-iproc",
3750 .base.cra_driver_name = "xts-aes-iproc",
3773 .cra_driver_name = "md5-iproc",
3794 .cra_driver_name = "hmac-md5-iproc",
3812 .cra_driver_name = "sha1-iproc",
3830 .cra_driver_name = "hmac-sha1-iproc",
3848 .cra_driver_name = "sha224-iproc",
3866 .cra_driver_name = "hmac-sha224-iproc",
3884 .cra_driver_name = "sha256-iproc",
3902 .cra_driver_name = "hmac-sha256-iproc",
3921 .cra_driver_name = "sha384-iproc",
3940 .cra_driver_name = "hmac-sha384-iproc",
3959 .cra_driver_name = "sha512-iproc",
3978 .cra_driver_name = "hmac-sha512-iproc",
3996 .cra_name = "sha3-224",
3997 .cra_driver_name = "sha3-224-iproc",
4015 .cra_name = "hmac(sha3-224)",
4016 .cra_driver_name = "hmac-sha3-224-iproc",
4034 .cra_name = "sha3-256",
4035 .cra_driver_name = "sha3-256-iproc",
4053 .cra_name = "hmac(sha3-256)",
4054 .cra_driver_name = "hmac-sha3-256-iproc",
4072 .cra_name = "sha3-384",
4073 .cra_driver_name = "sha3-384-iproc",
4091 .cra_name = "hmac(sha3-384)",
4092 .cra_driver_name = "hmac-sha3-384-iproc",
4110 .cra_name = "sha3-512",
4111 .cra_driver_name = "sha3-512-iproc",
4129 .cra_name = "hmac(sha3-512)",
4130 .cra_driver_name = "hmac-sha3-512-iproc",
4149 .cra_driver_name = "xcbc-aes-iproc",
4168 .cra_driver_name = "cmac-aes-iproc",
4192 ctx->alg = cipher_alg; in generic_cra_init()
4193 ctx->cipher = cipher_alg->cipher_info; in generic_cra_init()
4194 ctx->auth = cipher_alg->auth_info; in generic_cra_init()
4195 ctx->auth_first = cipher_alg->auth_first; in generic_cra_init()
4196 ctx->max_payload = spu->spu_ctx_max_payload(ctx->cipher.alg, in generic_cra_init()
4197 ctx->cipher.mode, in generic_cra_init()
4199 ctx->fallback_cipher = NULL; in generic_cra_init()
4201 ctx->enckeylen = 0; in generic_cra_init()
4202 ctx->authkeylen = 0; in generic_cra_init()
4227 struct crypto_alg *alg = tfm->__crt_alg; in ahash_cra_init()
4250 struct crypto_alg *alg = tfm->__crt_alg; in aead_cra_init()
4260 ctx->is_esp = false; in aead_cra_init()
4261 ctx->salt_len = 0; in aead_cra_init()
4262 ctx->salt_offset = 0; in aead_cra_init()
4265 get_random_bytes(ctx->iv, MAX_IV_SIZE); in aead_cra_init()
4266 flow_dump(" iv: ", ctx->iv, MAX_IV_SIZE); in aead_cra_init()
4269 if (alg->cra_flags & CRYPTO_ALG_NEED_FALLBACK) { in aead_cra_init()
4272 ctx->fallback_cipher = in aead_cra_init()
4273 crypto_alloc_aead(alg->cra_name, 0, in aead_cra_init()
4276 if (IS_ERR(ctx->fallback_cipher)) { in aead_cra_init()
4278 __func__, alg->cra_name); in aead_cra_init()
4279 return PTR_ERR(ctx->fallback_cipher); in aead_cra_init()
4304 if (ctx->fallback_cipher) { in aead_cra_exit()
4305 crypto_free_aead(ctx->fallback_cipher); in aead_cra_exit()
4306 ctx->fallback_cipher = NULL; in aead_cra_exit()
4311 * spu_functions_register() - Specify hardware-specific SPU functions based on
4325 spu->spu_dump_msg_hdr = spum_dump_msg_hdr; in spu_functions_register()
4326 spu->spu_payload_length = spum_payload_length; in spu_functions_register()
4327 spu->spu_response_hdr_len = spum_response_hdr_len; in spu_functions_register()
4328 spu->spu_hash_pad_len = spum_hash_pad_len; in spu_functions_register()
4329 spu->spu_gcm_ccm_pad_len = spum_gcm_ccm_pad_len; in spu_functions_register()
4330 spu->spu_assoc_resp_len = spum_assoc_resp_len; in spu_functions_register()
4331 spu->spu_aead_ivlen = spum_aead_ivlen; in spu_functions_register()
4332 spu->spu_hash_type = spum_hash_type; in spu_functions_register()
4333 spu->spu_digest_size = spum_digest_size; in spu_functions_register()
4334 spu->spu_create_request = spum_create_request; in spu_functions_register()
4335 spu->spu_cipher_req_init = spum_cipher_req_init; in spu_functions_register()
4336 spu->spu_cipher_req_finish = spum_cipher_req_finish; in spu_functions_register()
4337 spu->spu_request_pad = spum_request_pad; in spu_functions_register()
4338 spu->spu_tx_status_len = spum_tx_status_len; in spu_functions_register()
4339 spu->spu_rx_status_len = spum_rx_status_len; in spu_functions_register()
4340 spu->spu_status_process = spum_status_process; in spu_functions_register()
4341 spu->spu_xts_tweak_in_payload = spum_xts_tweak_in_payload; in spu_functions_register()
4342 spu->spu_ccm_update_iv = spum_ccm_update_iv; in spu_functions_register()
4343 spu->spu_wordalign_padlen = spum_wordalign_padlen; in spu_functions_register()
4345 spu->spu_ctx_max_payload = spum_ns2_ctx_max_payload; in spu_functions_register()
4347 spu->spu_ctx_max_payload = spum_nsp_ctx_max_payload; in spu_functions_register()
4350 spu->spu_dump_msg_hdr = spu2_dump_msg_hdr; in spu_functions_register()
4351 spu->spu_ctx_max_payload = spu2_ctx_max_payload; in spu_functions_register()
4352 spu->spu_payload_length = spu2_payload_length; in spu_functions_register()
4353 spu->spu_response_hdr_len = spu2_response_hdr_len; in spu_functions_register()
4354 spu->spu_hash_pad_len = spu2_hash_pad_len; in spu_functions_register()
4355 spu->spu_gcm_ccm_pad_len = spu2_gcm_ccm_pad_len; in spu_functions_register()
4356 spu->spu_assoc_resp_len = spu2_assoc_resp_len; in spu_functions_register()
4357 spu->spu_aead_ivlen = spu2_aead_ivlen; in spu_functions_register()
4358 spu->spu_hash_type = spu2_hash_type; in spu_functions_register()
4359 spu->spu_digest_size = spu2_digest_size; in spu_functions_register()
4360 spu->spu_create_request = spu2_create_request; in spu_functions_register()
4361 spu->spu_cipher_req_init = spu2_cipher_req_init; in spu_functions_register()
4362 spu->spu_cipher_req_finish = spu2_cipher_req_finish; in spu_functions_register()
4363 spu->spu_request_pad = spu2_request_pad; in spu_functions_register()
4364 spu->spu_tx_status_len = spu2_tx_status_len; in spu_functions_register()
4365 spu->spu_rx_status_len = spu2_rx_status_len; in spu_functions_register()
4366 spu->spu_status_process = spu2_status_process; in spu_functions_register()
4367 spu->spu_xts_tweak_in_payload = spu2_xts_tweak_in_payload; in spu_functions_register()
4368 spu->spu_ccm_update_iv = spu2_ccm_update_iv; in spu_functions_register()
4369 spu->spu_wordalign_padlen = spu2_wordalign_padlen; in spu_functions_register()
4374 * spu_mb_init() - Initialize mailbox client. Request ownership of a mailbox
4389 return -ENOMEM; in spu_mb_init()
4391 mcl->dev = dev; in spu_mb_init()
4392 mcl->tx_block = false; in spu_mb_init()
4393 mcl->tx_tout = 0; in spu_mb_init()
4394 mcl->knows_txdone = true; in spu_mb_init()
4395 mcl->rx_callback = spu_rx_callback; in spu_mb_init()
4396 mcl->tx_done = NULL; in spu_mb_init()
4460 struct skcipher_alg *crypto = &driver_alg->alg.skcipher; in spu_register_skcipher()
4463 crypto->base.cra_module = THIS_MODULE; in spu_register_skcipher()
4464 crypto->base.cra_priority = cipher_pri; in spu_register_skcipher()
4465 crypto->base.cra_alignmask = 0; in spu_register_skcipher()
4466 crypto->base.cra_ctxsize = sizeof(struct iproc_ctx_s); in spu_register_skcipher()
4467 crypto->base.cra_flags = CRYPTO_ALG_ASYNC | in spu_register_skcipher()
4471 crypto->init = skcipher_init_tfm; in spu_register_skcipher()
4472 crypto->exit = skcipher_exit_tfm; in spu_register_skcipher()
4473 crypto->setkey = skcipher_setkey; in spu_register_skcipher()
4474 crypto->encrypt = skcipher_encrypt; in spu_register_skcipher()
4475 crypto->decrypt = skcipher_decrypt; in spu_register_skcipher()
4480 driver_alg->registered = true; in spu_register_skcipher()
4481 pr_debug(" registered skcipher %s\n", crypto->base.cra_driver_name); in spu_register_skcipher()
4488 struct ahash_alg *hash = &driver_alg->alg.hash; in spu_register_ahash()
4491 /* AES-XCBC is the only AES hash type currently supported on SPU-M */ in spu_register_ahash()
4492 if ((driver_alg->auth_info.alg == HASH_ALG_AES) && in spu_register_ahash()
4493 (driver_alg->auth_info.mode != HASH_MODE_XCBC) && in spu_register_ahash()
4494 (spu->spu_type == SPU_TYPE_SPUM)) in spu_register_ahash()
4497 /* SHA3 algorithm variants are not registered for SPU-M or SPU2. */ in spu_register_ahash()
4498 if ((driver_alg->auth_info.alg >= HASH_ALG_SHA3_224) && in spu_register_ahash()
4499 (spu->spu_subtype != SPU_SUBTYPE_SPU2_V2)) in spu_register_ahash()
4502 hash->halg.base.cra_module = THIS_MODULE; in spu_register_ahash()
4503 hash->halg.base.cra_priority = hash_pri; in spu_register_ahash()
4504 hash->halg.base.cra_alignmask = 0; in spu_register_ahash()
4505 hash->halg.base.cra_ctxsize = sizeof(struct iproc_ctx_s); in spu_register_ahash()
4506 hash->halg.base.cra_init = ahash_cra_init; in spu_register_ahash()
4507 hash->halg.base.cra_exit = generic_cra_exit; in spu_register_ahash()
4508 hash->halg.base.cra_flags = CRYPTO_ALG_ASYNC | in spu_register_ahash()
4510 hash->halg.statesize = sizeof(struct spu_hash_export_s); in spu_register_ahash()
4512 if (driver_alg->auth_info.mode != HASH_MODE_HMAC) { in spu_register_ahash()
4513 hash->init = ahash_init; in spu_register_ahash()
4514 hash->update = ahash_update; in spu_register_ahash()
4515 hash->final = ahash_final; in spu_register_ahash()
4516 hash->finup = ahash_finup; in spu_register_ahash()
4517 hash->digest = ahash_digest; in spu_register_ahash()
4518 if ((driver_alg->auth_info.alg == HASH_ALG_AES) && in spu_register_ahash()
4519 ((driver_alg->auth_info.mode == HASH_MODE_XCBC) || in spu_register_ahash()
4520 (driver_alg->auth_info.mode == HASH_MODE_CMAC))) { in spu_register_ahash()
4521 hash->setkey = ahash_setkey; in spu_register_ahash()
4524 hash->setkey = ahash_hmac_setkey; in spu_register_ahash()
4525 hash->init = ahash_hmac_init; in spu_register_ahash()
4526 hash->update = ahash_hmac_update; in spu_register_ahash()
4527 hash->final = ahash_hmac_final; in spu_register_ahash()
4528 hash->finup = ahash_hmac_finup; in spu_register_ahash()
4529 hash->digest = ahash_hmac_digest; in spu_register_ahash()
4531 hash->export = ahash_export; in spu_register_ahash()
4532 hash->import = ahash_import; in spu_register_ahash()
4537 driver_alg->registered = true; in spu_register_ahash()
4539 hash->halg.base.cra_driver_name); in spu_register_ahash()
4545 struct aead_alg *aead = &driver_alg->alg.aead; in spu_register_aead()
4548 aead->base.cra_module = THIS_MODULE; in spu_register_aead()
4549 aead->base.cra_priority = aead_pri; in spu_register_aead()
4550 aead->base.cra_alignmask = 0; in spu_register_aead()
4551 aead->base.cra_ctxsize = sizeof(struct iproc_ctx_s); in spu_register_aead()
4553 aead->base.cra_flags |= CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY; in spu_register_aead()
4555 aead->setauthsize = aead_setauthsize; in spu_register_aead()
4556 aead->encrypt = aead_encrypt; in spu_register_aead()
4557 aead->decrypt = aead_decrypt; in spu_register_aead()
4558 aead->init = aead_cra_init; in spu_register_aead()
4559 aead->exit = aead_cra_exit; in spu_register_aead()
4564 driver_alg->registered = true; in spu_register_aead()
4565 pr_debug(" registered aead %s\n", aead->base.cra_driver_name); in spu_register_aead()
4588 "iproc-crypto: unknown alg type: %d", in spu_algs_register()
4590 err = -EINVAL; in spu_algs_register()
4645 .compatible = "brcm,spum-crypto",
4649 .compatible = "brcm,spum-nsp-crypto",
4653 .compatible = "brcm,spu2-crypto",
4657 .compatible = "brcm,spu2-v2-crypto",
4667 struct device *dev = &pdev->dev; in spu_dt_read()
4671 struct device_node *dn = pdev->dev.of_node; in spu_dt_read()
4675 spu->num_chan = of_count_phandle_with_args(dn, "mboxes", "#mbox-cells"); in spu_dt_read()
4680 return -ENODEV; in spu_dt_read()
4683 spu->spu_type = matched_spu_type->type; in spu_dt_read()
4684 spu->spu_subtype = matched_spu_type->subtype; in spu_dt_read()
4689 spu->reg_vbase[i] = devm_ioremap_resource(dev, spu_ctrl_regs); in spu_dt_read()
4690 if (IS_ERR(spu->reg_vbase[i])) { in spu_dt_read()
4691 err = PTR_ERR(spu->reg_vbase[i]); in spu_dt_read()
4694 spu->reg_vbase[i] = NULL; in spu_dt_read()
4698 spu->num_spu = i; in spu_dt_read()
4699 dev_dbg(dev, "Device has %d SPUs", spu->num_spu); in spu_dt_read()
4706 struct device *dev = &pdev->dev; in bcm_spu_probe()
4722 if (spu->spu_type == SPU_TYPE_SPUM) in bcm_spu_probe()
4724 else if (spu->spu_type == SPU_TYPE_SPU2) in bcm_spu_probe()
4727 spu_functions_register(dev, spu->spu_type, spu->spu_subtype); in bcm_spu_probe()
4751 struct device *dev = &pdev->dev; in bcm_spu_remove()
4793 .name = "brcm-spu-crypto",