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
473 struct crypto_async_request *areq = rctx->parent; in handle_skcipher_resp()
475 struct iproc_ctx_s *ctx = rctx->ctx; in handle_skcipher_resp()
479 payload_len = spu->spu_payload_length(rctx->msg_buf.spu_resp_hdr); in handle_skcipher_resp()
485 if ((ctx->cipher.mode == CIPHER_MODE_XTS) && in handle_skcipher_resp()
486 spu->spu_xts_tweak_in_payload() && in handle_skcipher_resp()
488 payload_len -= SPU_XTS_TWEAK_SIZE; in handle_skcipher_resp()
493 __func__, rctx->total_received, payload_len); in handle_skcipher_resp()
495 dump_sg(req->dst, rctx->total_received, payload_len); in handle_skcipher_resp()
497 rctx->total_received += payload_len; in handle_skcipher_resp()
498 if (rctx->total_received == rctx->total_todo) { in handle_skcipher_resp()
501 &iproc_priv.cipher_cnt[ctx->cipher.alg][ctx->cipher.mode]); in handle_skcipher_resp()
506 * spu_ahash_rx_sg_create() - Build up the scatterlist of buffers used to
514 * a 4-byte boundary
532 struct iproc_ctx_s *ctx = rctx->ctx; in spu_ahash_rx_sg_create()
534 mssg->spu.dst = kcalloc(rx_frag_num, sizeof(struct scatterlist), in spu_ahash_rx_sg_create()
535 rctx->gfp); in spu_ahash_rx_sg_create()
536 if (!mssg->spu.dst) in spu_ahash_rx_sg_create()
537 return -ENOMEM; in spu_ahash_rx_sg_create()
539 sg = mssg->spu.dst; in spu_ahash_rx_sg_create()
542 sg_set_buf(sg++, rctx->msg_buf.spu_resp_hdr, ctx->spu_resp_hdr_len); in spu_ahash_rx_sg_create()
545 sg_set_buf(sg++, rctx->msg_buf.digest, digestsize); in spu_ahash_rx_sg_create()
548 sg_set_buf(sg++, rctx->msg_buf.rx_stat_pad, stat_pad_len); in spu_ahash_rx_sg_create()
550 memset(rctx->msg_buf.rx_stat, 0, SPU_RX_STATUS_LEN); in spu_ahash_rx_sg_create()
551 sg_set_buf(sg, rctx->msg_buf.rx_stat, spu->spu_rx_status_len()); in spu_ahash_rx_sg_create()
556 * spu_ahash_tx_sg_create() - Build up the scatterlist of buffers used to send
589 mssg->spu.src = kcalloc(tx_frag_num, sizeof(struct scatterlist), in spu_ahash_tx_sg_create()
590 rctx->gfp); in spu_ahash_tx_sg_create()
591 if (!mssg->spu.src) in spu_ahash_tx_sg_create()
592 return -ENOMEM; in spu_ahash_tx_sg_create()
594 sg = mssg->spu.src; in spu_ahash_tx_sg_create()
597 sg_set_buf(sg++, rctx->msg_buf.bcm_spu_req_hdr, in spu_ahash_tx_sg_create()
601 sg_set_buf(sg++, rctx->hash_carry, hash_carry_len); in spu_ahash_tx_sg_create()
605 datalen = spu_msg_sg_add(&sg, &rctx->src_sg, &rctx->src_skip, in spu_ahash_tx_sg_create()
606 rctx->src_nents, new_data_len); in spu_ahash_tx_sg_create()
610 return -EFAULT; in spu_ahash_tx_sg_create()
615 sg_set_buf(sg++, rctx->msg_buf.spu_req_pad, pad_len); in spu_ahash_tx_sg_create()
617 stat_len = spu->spu_tx_status_len(); in spu_ahash_tx_sg_create()
619 memset(rctx->msg_buf.tx_stat, 0, stat_len); in spu_ahash_tx_sg_create()
620 sg_set_buf(sg, rctx->msg_buf.tx_stat, stat_len); in spu_ahash_tx_sg_create()
627 * handle_ahash_req() - Process an asynchronous hash request from the crypto
645 * -EINPROGRESS: request has been submitted to SPU and response will be
647 * -EAGAIN: non-final request included a small amount of data, which for
655 struct crypto_async_request *areq = rctx->parent; in handle_ahash_req()
660 struct iproc_ctx_s *ctx = rctx->ctx; in handle_ahash_req()
695 rctx->total_todo, rctx->total_sent); in handle_ahash_req()
703 hash_parms.alg = ctx->auth.alg; in handle_ahash_req()
704 hash_parms.mode = ctx->auth.mode; in handle_ahash_req()
706 hash_parms.key_buf = (u8 *)ctx->authkey; in handle_ahash_req()
707 hash_parms.key_len = ctx->authkeylen; in handle_ahash_req()
711 * it's needed for AES-XCBC and AES-CMAC hash algorithms in handle_ahash_req()
714 * For example for 128 bit key, hash algorithm is AES-128. in handle_ahash_req()
716 cipher_parms.type = ctx->cipher_type; in handle_ahash_req()
718 mssg = &rctx->mb_mssg; in handle_ahash_req()
719 chunk_start = rctx->src_sent; in handle_ahash_req()
725 nbytes_to_hash = rctx->total_todo - rctx->total_sent; in handle_ahash_req()
727 if ((ctx->max_payload != SPU_MAX_PAYLOAD_INF) && in handle_ahash_req()
728 (chunksize > ctx->max_payload)) in handle_ahash_req()
729 chunksize = ctx->max_payload; in handle_ahash_req()
736 if (!rctx->is_final) { in handle_ahash_req()
737 u8 *dest = rctx->hash_carry + rctx->hash_carry_len; in handle_ahash_req()
743 chunksize -= rem; in handle_ahash_req()
746 new_len = rem - rctx->hash_carry_len; in handle_ahash_req()
747 sg_copy_part_to_buf(req->src, dest, new_len, in handle_ahash_req()
748 rctx->src_sent); in handle_ahash_req()
749 rctx->hash_carry_len = rem; in handle_ahash_req()
751 rctx->hash_carry_len); in handle_ahash_req()
753 rctx->hash_carry, in handle_ahash_req()
754 rctx->hash_carry_len); in handle_ahash_req()
755 return -EAGAIN; in handle_ahash_req()
761 local_nbuf = rctx->hash_carry_len; in handle_ahash_req()
762 rctx->hash_carry_len = 0; in handle_ahash_req()
765 new_data_len = chunksize - local_nbuf; in handle_ahash_req()
768 rctx->src_nents = spu_sg_count(rctx->src_sg, rctx->src_skip, in handle_ahash_req()
775 hash_parms.type = spu->spu_hash_type(rctx->total_sent); in handle_ahash_req()
777 digestsize = spu->spu_digest_size(ctx->digestsize, ctx->auth.alg, in handle_ahash_req()
782 rctx->total_sent += chunksize; in handle_ahash_req()
783 /* if you sent a prebuf then that wasn't from this req->src */ in handle_ahash_req()
784 rctx->src_sent += new_data_len; in handle_ahash_req()
786 if ((rctx->total_sent == rctx->total_todo) && rctx->is_final) in handle_ahash_req()
787 hash_parms.pad_len = spu->spu_hash_pad_len(hash_parms.alg, in handle_ahash_req()
793 * If a non-first chunk, then include the digest returned from the in handle_ahash_req()
798 hash_parms.key_buf = rctx->incr_hash; in handle_ahash_req()
805 __func__, rctx->is_final, local_nbuf); in handle_ahash_req()
807 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in handle_ahash_req()
810 flow_log("max_payload %u\n", ctx->max_payload); in handle_ahash_req()
815 memcpy(rctx->msg_buf.bcm_spu_req_hdr, BCMHEADER, BCM_HDR_LEN); in handle_ahash_req()
818 spu_hdr_len = spu->spu_create_request(rctx->msg_buf.bcm_spu_req_hdr + in handle_ahash_req()
826 return -EFAULT; in handle_ahash_req()
833 data_pad_len = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, chunksize); in handle_ahash_req()
836 if (spu->spu_tx_status_len()) in handle_ahash_req()
837 stat_pad_len = spu->spu_wordalign_padlen(db_size); in handle_ahash_req()
843 spu->spu_request_pad(rctx->msg_buf.spu_req_pad, data_pad_len, in handle_ahash_req()
844 hash_parms.pad_len, ctx->auth.alg, in handle_ahash_req()
845 ctx->auth.mode, rctx->total_sent, in handle_ahash_req()
849 spu->spu_dump_msg_hdr(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN, in handle_ahash_req()
851 packet_dump(" prebuf: ", rctx->hash_carry, local_nbuf); in handle_ahash_req()
853 dump_sg(rctx->src_sg, rctx->src_skip, new_data_len); in handle_ahash_req()
854 packet_dump(" pad: ", rctx->msg_buf.spu_req_pad, pad_len); in handle_ahash_req()
861 mssg->type = BRCM_MESSAGE_SPU; in handle_ahash_req()
862 mssg->ctx = rctx; /* Will be returned in response */ in handle_ahash_req()
871 tx_frag_num += rctx->src_nents; in handle_ahash_req()
872 if (spu->spu_tx_status_len()) in handle_ahash_req()
879 err = mailbox_send_message(mssg, req->base.flags, rctx->chan_idx); in handle_ahash_req()
883 return -EINPROGRESS; in handle_ahash_req()
887 * spu_hmac_outer_hash() - Request synchonous software compute of the outer hash
893 * -EINVAL if the hash algo is unrecognized
904 switch (ctx->auth.alg) { in spu_hmac_outer_hash()
906 rc = do_shash("md5", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
907 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
910 rc = do_shash("sha1", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
911 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
914 rc = do_shash("sha224", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
915 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
918 rc = do_shash("sha256", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
919 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
922 rc = do_shash("sha384", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
923 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
926 rc = do_shash("sha512", req->result, ctx->opad, blocksize, in spu_hmac_outer_hash()
927 req->result, ctx->digestsize, NULL, 0); in spu_hmac_outer_hash()
931 rc = -EINVAL; in spu_hmac_outer_hash()
937 * ahash_req_done() - Process a hash result from the SPU hardware.
946 struct crypto_async_request *areq = rctx->parent; in ahash_req_done()
948 struct iproc_ctx_s *ctx = rctx->ctx; in ahash_req_done()
951 memcpy(req->result, rctx->msg_buf.digest, ctx->digestsize); in ahash_req_done()
953 if (spu->spu_type == SPU_TYPE_SPUM) { in ahash_req_done()
957 if (ctx->auth.alg == HASH_ALG_MD5) { in ahash_req_done()
958 __swab32s((u32 *)req->result); in ahash_req_done()
959 __swab32s(((u32 *)req->result) + 1); in ahash_req_done()
960 __swab32s(((u32 *)req->result) + 2); in ahash_req_done()
961 __swab32s(((u32 *)req->result) + 3); in ahash_req_done()
962 __swab32s(((u32 *)req->result) + 4); in ahash_req_done()
966 flow_dump(" digest ", req->result, ctx->digestsize); in ahash_req_done()
969 if (rctx->is_sw_hmac) { in ahash_req_done()
973 flow_dump(" hmac: ", req->result, ctx->digestsize); in ahash_req_done()
976 if (rctx->is_sw_hmac || ctx->auth.mode == HASH_MODE_HMAC) { in ahash_req_done()
978 atomic_inc(&iproc_priv.hmac_cnt[ctx->auth.alg]); in ahash_req_done()
981 atomic_inc(&iproc_priv.hash_cnt[ctx->auth.alg]); in ahash_req_done()
988 * handle_ahash_resp() - Process a SPU response message for a hash request.
995 struct iproc_ctx_s *ctx = rctx->ctx; in handle_ahash_resp()
996 struct crypto_async_request *areq = rctx->parent; in handle_ahash_resp()
1005 memcpy(rctx->incr_hash, rctx->msg_buf.digest, MAX_DIGEST_SIZE); in handle_ahash_resp()
1008 __func__, blocksize, ctx->digestsize); in handle_ahash_resp()
1010 atomic64_add(ctx->digestsize, &iproc_priv.bytes_in); in handle_ahash_resp()
1012 if (rctx->is_final && (rctx->total_sent == rctx->total_todo)) in handle_ahash_resp()
1017 * spu_aead_rx_sg_create() - Build up the scatterlist of buffers used to receive
1031 * a 4-byte boundary
1051 struct iproc_ctx_s *ctx = rctx->ctx; in spu_aead_rx_sg_create()
1056 if (ctx->is_rfc4543) { in spu_aead_rx_sg_create()
1058 data_padlen = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in spu_aead_rx_sg_create()
1062 data_padlen = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in spu_aead_rx_sg_create()
1064 assoc_buf_len = spu->spu_assoc_resp_len(ctx->cipher.mode, in spu_aead_rx_sg_create()
1066 rctx->is_encrypt); in spu_aead_rx_sg_create()
1069 if (ctx->cipher.mode == CIPHER_MODE_CCM) in spu_aead_rx_sg_create()
1070 /* ICV (after data) must be in the next 32-bit word for CCM */ in spu_aead_rx_sg_create()
1071 data_padlen += spu->spu_wordalign_padlen(assoc_buf_len + in spu_aead_rx_sg_create()
1079 mssg->spu.dst = kcalloc(rx_frag_num, sizeof(struct scatterlist), in spu_aead_rx_sg_create()
1080 rctx->gfp); in spu_aead_rx_sg_create()
1081 if (!mssg->spu.dst) in spu_aead_rx_sg_create()
1082 return -ENOMEM; in spu_aead_rx_sg_create()
1084 sg = mssg->spu.dst; in spu_aead_rx_sg_create()
1088 sg_set_buf(sg++, rctx->msg_buf.spu_resp_hdr, ctx->spu_resp_hdr_len); in spu_aead_rx_sg_create()
1092 * Don't write directly to req->dst, because SPU may pad the in spu_aead_rx_sg_create()
1093 * assoc data in the response in spu_aead_rx_sg_create()
1095 memset(rctx->msg_buf.a.resp_aad, 0, assoc_buf_len); in spu_aead_rx_sg_create()
1096 sg_set_buf(sg++, rctx->msg_buf.a.resp_aad, assoc_buf_len); in spu_aead_rx_sg_create()
1104 datalen = spu_msg_sg_add(&sg, &rctx->dst_sg, &rctx->dst_skip, in spu_aead_rx_sg_create()
1105 rctx->dst_nents, resp_len); in spu_aead_rx_sg_create()
1109 return -EFAULT; in spu_aead_rx_sg_create()
1115 memset(rctx->msg_buf.a.gcmpad, 0, data_padlen); in spu_aead_rx_sg_create()
1116 sg_set_buf(sg++, rctx->msg_buf.a.gcmpad, data_padlen); in spu_aead_rx_sg_create()
1120 sg_set_buf(sg++, rctx->msg_buf.digest, digestsize); in spu_aead_rx_sg_create()
1124 memset(rctx->msg_buf.rx_stat_pad, 0, stat_pad_len); in spu_aead_rx_sg_create()
1125 sg_set_buf(sg++, rctx->msg_buf.rx_stat_pad, stat_pad_len); in spu_aead_rx_sg_create()
1128 memset(rctx->msg_buf.rx_stat, 0, SPU_RX_STATUS_LEN); in spu_aead_rx_sg_create()
1129 sg_set_buf(sg, rctx->msg_buf.rx_stat, spu->spu_rx_status_len()); in spu_aead_rx_sg_create()
1135 * spu_aead_tx_sg_create() - Build up the scatterlist of buffers used to send a
1143 * @assoc: crypto API associated data scatterlist
1145 * @assoc_nents: number of scatterlist entries containing assoc data
1165 struct scatterlist *assoc, in spu_aead_tx_sg_create() argument
1174 struct scatterlist *assoc_sg = assoc; in spu_aead_tx_sg_create()
1175 struct iproc_ctx_s *ctx = rctx->ctx; in spu_aead_tx_sg_create()
1181 mssg->spu.src = kcalloc(tx_frag_num, sizeof(struct scatterlist), in spu_aead_tx_sg_create()
1182 rctx->gfp); in spu_aead_tx_sg_create()
1183 if (!mssg->spu.src) in spu_aead_tx_sg_create()
1184 return -ENOMEM; in spu_aead_tx_sg_create()
1186 sg = mssg->spu.src; in spu_aead_tx_sg_create()
1189 sg_set_buf(sg++, rctx->msg_buf.bcm_spu_req_hdr, in spu_aead_tx_sg_create()
1197 pr_err("%s(): failed to copy assoc sg to mbox msg", in spu_aead_tx_sg_create()
1199 return -EFAULT; in spu_aead_tx_sg_create()
1204 sg_set_buf(sg++, rctx->msg_buf.iv_ctr, aead_iv_len); in spu_aead_tx_sg_create()
1207 memset(rctx->msg_buf.a.req_aad_pad, 0, aad_pad_len); in spu_aead_tx_sg_create()
1208 sg_set_buf(sg++, rctx->msg_buf.a.req_aad_pad, aad_pad_len); in spu_aead_tx_sg_create()
1212 if ((chunksize > ctx->digestsize) && incl_icv) in spu_aead_tx_sg_create()
1213 datalen -= ctx->digestsize; in spu_aead_tx_sg_create()
1216 written = spu_msg_sg_add(&sg, &rctx->src_sg, &rctx->src_skip, in spu_aead_tx_sg_create()
1217 rctx->src_nents, datalen); in spu_aead_tx_sg_create()
1221 return -EFAULT; in spu_aead_tx_sg_create()
1226 memset(rctx->msg_buf.spu_req_pad, 0, pad_len); in spu_aead_tx_sg_create()
1227 sg_set_buf(sg++, rctx->msg_buf.spu_req_pad, pad_len); in spu_aead_tx_sg_create()
1231 sg_set_buf(sg++, rctx->msg_buf.digest, ctx->digestsize); in spu_aead_tx_sg_create()
1233 stat_len = spu->spu_tx_status_len(); in spu_aead_tx_sg_create()
1235 memset(rctx->msg_buf.tx_stat, 0, stat_len); in spu_aead_tx_sg_create()
1236 sg_set_buf(sg, rctx->msg_buf.tx_stat, stat_len); in spu_aead_tx_sg_create()
1242 * handle_aead_req() - Submit a SPU request message for the next chunk of the
1251 * truncated algs like sha-224, the SPU returns just the truncated hash in
1252 * response to aead requests. So digestsize is always ctx->digestsize here.
1254 * Return: -EINPROGRESS: crypto request has been accepted and result will be
1261 struct crypto_async_request *areq = rctx->parent; in handle_aead_req()
1264 struct iproc_ctx_s *ctx = rctx->ctx; in handle_aead_req()
1279 unsigned int digestsize = ctx->digestsize; in handle_aead_req()
1287 chunksize = rctx->total_todo; in handle_aead_req()
1295 req_opts.is_inbound = !(rctx->is_encrypt); in handle_aead_req()
1296 req_opts.auth_first = ctx->auth_first; in handle_aead_req()
1298 req_opts.is_esp = ctx->is_esp; in handle_aead_req()
1300 cipher_parms.alg = ctx->cipher.alg; in handle_aead_req()
1301 cipher_parms.mode = ctx->cipher.mode; in handle_aead_req()
1302 cipher_parms.type = ctx->cipher_type; in handle_aead_req()
1303 cipher_parms.key_buf = ctx->enckey; in handle_aead_req()
1304 cipher_parms.key_len = ctx->enckeylen; in handle_aead_req()
1305 cipher_parms.iv_buf = rctx->msg_buf.iv_ctr; in handle_aead_req()
1306 cipher_parms.iv_len = rctx->iv_ctr_len; in handle_aead_req()
1308 hash_parms.alg = ctx->auth.alg; in handle_aead_req()
1309 hash_parms.mode = ctx->auth.mode; in handle_aead_req()
1311 hash_parms.key_buf = (u8 *)ctx->authkey; in handle_aead_req()
1312 hash_parms.key_len = ctx->authkeylen; in handle_aead_req()
1315 if ((ctx->auth.alg == HASH_ALG_SHA224) && in handle_aead_req()
1316 (ctx->authkeylen < SHA224_DIGEST_SIZE)) in handle_aead_req()
1319 aead_parms.assoc_size = req->assoclen; in handle_aead_req()
1320 if (ctx->is_esp && !ctx->is_rfc4543) { in handle_aead_req()
1322 * 8-byte IV is included assoc data in request. SPU2 in handle_aead_req()
1326 aead_parms.assoc_size -= GCM_RFC4106_IV_SIZE; in handle_aead_req()
1328 if (rctx->is_encrypt) { in handle_aead_req()
1343 rctx->src_nents = spu_sg_count(rctx->src_sg, rctx->src_skip, chunksize); in handle_aead_req()
1344 rctx->dst_nents = spu_sg_count(rctx->dst_sg, rctx->dst_skip, chunksize); in handle_aead_req()
1346 assoc_nents = spu_sg_count(rctx->assoc, 0, in handle_aead_req()
1349 mssg = &rctx->mb_mssg; in handle_aead_req()
1351 rctx->total_sent = chunksize; in handle_aead_req()
1352 rctx->src_sent = chunksize; in handle_aead_req()
1353 if (spu->spu_assoc_resp_len(ctx->cipher.mode, in handle_aead_req()
1356 rctx->is_encrypt)) in handle_aead_req()
1359 aead_parms.iv_len = spu->spu_aead_ivlen(ctx->cipher.mode, in handle_aead_req()
1360 rctx->iv_ctr_len); in handle_aead_req()
1362 if (ctx->auth.alg == HASH_ALG_AES) in handle_aead_req()
1363 hash_parms.type = (enum hash_type)ctx->cipher_type; in handle_aead_req()
1366 aead_parms.aad_pad_len = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in handle_aead_req()
1370 aead_parms.data_pad_len = spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in handle_aead_req()
1373 if (ctx->cipher.mode == CIPHER_MODE_CCM) { in handle_aead_req()
1376 * 128-bit aligned in handle_aead_req()
1378 aead_parms.aad_pad_len = spu->spu_gcm_ccm_pad_len( in handle_aead_req()
1379 ctx->cipher.mode, in handle_aead_req()
1386 if (!rctx->is_encrypt) in handle_aead_req()
1388 spu->spu_gcm_ccm_pad_len(ctx->cipher.mode, in handle_aead_req()
1389 chunksize - digestsize); in handle_aead_req()
1392 spu->spu_ccm_update_iv(digestsize, &cipher_parms, req->assoclen, in handle_aead_req()
1393 chunksize, rctx->is_encrypt, in handle_aead_req()
1394 ctx->is_esp); in handle_aead_req()
1397 if (ctx->is_rfc4543) { in handle_aead_req()
1403 if (!rctx->is_encrypt) in handle_aead_req()
1404 aead_parms.data_pad_len = spu->spu_gcm_ccm_pad_len( in handle_aead_req()
1405 ctx->cipher.mode, in handle_aead_req()
1406 aead_parms.assoc_size + chunksize - in handle_aead_req()
1409 aead_parms.data_pad_len = spu->spu_gcm_ccm_pad_len( in handle_aead_req()
1410 ctx->cipher.mode, in handle_aead_req()
1416 if (spu_req_incl_icv(ctx->cipher.mode, rctx->is_encrypt)) { in handle_aead_req()
1420 sg_copy_part_to_buf(req->src, rctx->msg_buf.digest, digestsize, in handle_aead_req()
1421 req->assoclen + rctx->total_sent - in handle_aead_req()
1427 flow_log("%s()-sent chunksize:%u\n", __func__, chunksize); in handle_aead_req()
1430 memcpy(rctx->msg_buf.bcm_spu_req_hdr, BCMHEADER, BCM_HDR_LEN); in handle_aead_req()
1432 spu_hdr_len = spu->spu_create_request(rctx->msg_buf.bcm_spu_req_hdr + in handle_aead_req()
1442 stat_pad_len = spu->spu_wordalign_padlen(db_size); in handle_aead_req()
1449 spu->spu_request_pad(rctx->msg_buf.spu_req_pad, in handle_aead_req()
1451 ctx->auth.alg, ctx->auth.mode, in handle_aead_req()
1452 rctx->total_sent, stat_pad_len); in handle_aead_req()
1455 spu->spu_dump_msg_hdr(rctx->msg_buf.bcm_spu_req_hdr + BCM_HDR_LEN, in handle_aead_req()
1457 dump_sg(rctx->assoc, 0, aead_parms.assoc_size); in handle_aead_req()
1458 packet_dump(" aead iv: ", rctx->msg_buf.iv_ctr, aead_parms.iv_len); in handle_aead_req()
1460 dump_sg(rctx->src_sg, rctx->src_skip, chunksize); in handle_aead_req()
1461 packet_dump(" pad: ", rctx->msg_buf.spu_req_pad, pad_len); in handle_aead_req()
1468 mssg->type = BRCM_MESSAGE_SPU; in handle_aead_req()
1469 mssg->ctx = rctx; /* Will be returned in response */ in handle_aead_req()
1472 rx_frag_num += rctx->dst_nents; in handle_aead_req()
1477 * padding. Have to for SHA-224 and other truncated SHAs because SPU in handle_aead_req()
1482 if (((ctx->cipher.mode == CIPHER_MODE_GCM) || in handle_aead_req()
1483 (ctx->cipher.mode == CIPHER_MODE_CCM)) && !rctx->is_encrypt) { in handle_aead_req()
1488 resp_len -= ctx->digestsize; in handle_aead_req()
1491 rx_frag_num -= rctx->dst_nents; in handle_aead_req()
1502 tx_frag_num += rctx->src_nents; in handle_aead_req()
1508 if (spu->spu_tx_status_len()) in handle_aead_req()
1511 rctx->assoc, aead_parms.assoc_size, in handle_aead_req()
1517 err = mailbox_send_message(mssg, req->base.flags, rctx->chan_idx); in handle_aead_req()
1521 return -EINPROGRESS; in handle_aead_req()
1525 * handle_aead_resp() - Process a SPU response message for an AEAD request.
1531 struct crypto_async_request *areq = rctx->parent; in handle_aead_resp()
1534 struct iproc_ctx_s *ctx = rctx->ctx; in handle_aead_resp()
1540 payload_len = spu->spu_payload_length(rctx->msg_buf.spu_resp_hdr); in handle_aead_resp()
1546 if (req->assoclen) in handle_aead_resp()
1547 packet_dump(" assoc_data ", rctx->msg_buf.a.resp_aad, in handle_aead_resp()
1548 req->assoclen); in handle_aead_resp()
1555 result_len = req->cryptlen; in handle_aead_resp()
1556 if (rctx->is_encrypt) { in handle_aead_resp()
1557 icv_offset = req->assoclen + rctx->total_sent; in handle_aead_resp()
1558 packet_dump(" ICV: ", rctx->msg_buf.digest, ctx->digestsize); in handle_aead_resp()
1560 sg_copy_part_from_buf(req->dst, rctx->msg_buf.digest, in handle_aead_resp()
1561 ctx->digestsize, icv_offset); in handle_aead_resp()
1562 result_len += ctx->digestsize; in handle_aead_resp()
1566 dump_sg(req->dst, req->assoclen, result_len); in handle_aead_resp()
1569 if (ctx->cipher.alg == CIPHER_ALG_AES) { in handle_aead_resp()
1570 if (ctx->cipher.mode == CIPHER_MODE_CCM) in handle_aead_resp()
1572 else if (ctx->cipher.mode == CIPHER_MODE_GCM) in handle_aead_resp()
1582 * spu_chunk_cleanup() - Do cleanup after processing one chunk of a request
1591 struct brcm_message *mssg = &rctx->mb_mssg; in spu_chunk_cleanup()
1593 kfree(mssg->spu.src); in spu_chunk_cleanup()
1594 kfree(mssg->spu.dst); in spu_chunk_cleanup()
1599 * finish_req() - Used to invoke the complete callback from the requester when
1608 struct crypto_async_request *areq = rctx->parent; in finish_req()
1620 * spu_rx_callback() - Callback from mailbox framework with a SPU response.
1631 rctx = mssg->ctx; in spu_rx_callback()
1635 err = -EFAULT; in spu_rx_callback()
1640 err = spu->spu_status_process(rctx->msg_buf.rx_stat); in spu_rx_callback()
1644 err = -EBADMSG; in spu_rx_callback()
1649 switch (rctx->ctx->alg->type) { in spu_rx_callback()
1660 err = -EINVAL; in spu_rx_callback()
1668 if (rctx->total_sent < rctx->total_todo) { in spu_rx_callback()
1672 switch (rctx->ctx->alg->type) { in spu_rx_callback()
1678 if (err == -EAGAIN) in spu_rx_callback()
1689 err = -EINVAL; in spu_rx_callback()
1692 if (err == -EINPROGRESS) in spu_rx_callback()
1704 * skcipher_enqueue() - Handle skcipher encrypt or decrypt request.
1708 * Return: -EINPROGRESS if request accepted and result will be returned
1721 rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in skcipher_enqueue()
1723 rctx->parent = &req->base; in skcipher_enqueue()
1724 rctx->is_encrypt = encrypt; in skcipher_enqueue()
1725 rctx->bd_suppress = false; in skcipher_enqueue()
1726 rctx->total_todo = req->cryptlen; in skcipher_enqueue()
1727 rctx->src_sent = 0; in skcipher_enqueue()
1728 rctx->total_sent = 0; in skcipher_enqueue()
1729 rctx->total_received = 0; in skcipher_enqueue()
1730 rctx->ctx = ctx; in skcipher_enqueue()
1733 rctx->src_sg = req->src; in skcipher_enqueue()
1734 rctx->src_nents = 0; in skcipher_enqueue()
1735 rctx->src_skip = 0; in skcipher_enqueue()
1736 rctx->dst_sg = req->dst; in skcipher_enqueue()
1737 rctx->dst_nents = 0; in skcipher_enqueue()
1738 rctx->dst_skip = 0; in skcipher_enqueue()
1740 if (ctx->cipher.mode == CIPHER_MODE_CBC || in skcipher_enqueue()
1741 ctx->cipher.mode == CIPHER_MODE_CTR || in skcipher_enqueue()
1742 ctx->cipher.mode == CIPHER_MODE_OFB || in skcipher_enqueue()
1743 ctx->cipher.mode == CIPHER_MODE_XTS || in skcipher_enqueue()
1744 ctx->cipher.mode == CIPHER_MODE_GCM || in skcipher_enqueue()
1745 ctx->cipher.mode == CIPHER_MODE_CCM) { in skcipher_enqueue()
1746 rctx->iv_ctr_len = in skcipher_enqueue()
1748 memcpy(rctx->msg_buf.iv_ctr, req->iv, rctx->iv_ctr_len); in skcipher_enqueue()
1750 rctx->iv_ctr_len = 0; in skcipher_enqueue()
1754 rctx->chan_idx = select_channel(); in skcipher_enqueue()
1756 if (err != -EINPROGRESS) in skcipher_enqueue()
1773 ctx->cipher_type = CIPHER_TYPE_DES; in des_setkey()
1787 ctx->cipher_type = CIPHER_TYPE_3DES; in threedes_setkey()
1796 if (ctx->cipher.mode == CIPHER_MODE_XTS) in aes_setkey()
1802 ctx->cipher_type = CIPHER_TYPE_AES128; in aes_setkey()
1805 ctx->cipher_type = CIPHER_TYPE_AES192; in aes_setkey()
1808 ctx->cipher_type = CIPHER_TYPE_AES256; in aes_setkey()
1811 return -EINVAL; in aes_setkey()
1813 WARN_ON((ctx->max_payload != SPU_MAX_PAYLOAD_INF) && in aes_setkey()
1814 ((ctx->max_payload % AES_BLOCK_SIZE) != 0)); in aes_setkey()
1830 switch (ctx->cipher.alg) { in skcipher_setkey()
1842 err = -EINVAL; in skcipher_setkey()
1847 memcpy(ctx->enckey, key, keylen); in skcipher_setkey()
1848 ctx->enckeylen = keylen; in skcipher_setkey()
1851 if ((ctx->cipher.alg == CIPHER_ALG_AES) && in skcipher_setkey()
1852 (ctx->cipher.mode == CIPHER_MODE_XTS)) { in skcipher_setkey()
1855 memcpy(ctx->enckey, key + xts_keylen, xts_keylen); in skcipher_setkey()
1856 memcpy(ctx->enckey + xts_keylen, key, xts_keylen); in skcipher_setkey()
1859 if (spu->spu_type == SPU_TYPE_SPUM) in skcipher_setkey()
1861 else if (spu->spu_type == SPU_TYPE_SPU2) in skcipher_setkey()
1863 memset(ctx->bcm_spu_req_hdr, 0, alloc_len); in skcipher_setkey()
1868 cipher_parms.alg = ctx->cipher.alg; in skcipher_setkey()
1869 cipher_parms.mode = ctx->cipher.mode; in skcipher_setkey()
1870 cipher_parms.type = ctx->cipher_type; in skcipher_setkey()
1871 cipher_parms.key_buf = ctx->enckey; in skcipher_setkey()
1872 cipher_parms.key_len = ctx->enckeylen; in skcipher_setkey()
1875 memcpy(ctx->bcm_spu_req_hdr, BCMHEADER, BCM_HDR_LEN); in skcipher_setkey()
1876 ctx->spu_req_hdr_len = in skcipher_setkey()
1877 spu->spu_cipher_req_init(ctx->bcm_spu_req_hdr + BCM_HDR_LEN, in skcipher_setkey()
1880 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, in skcipher_setkey()
1881 ctx->enckeylen, in skcipher_setkey()
1891 flow_log("skcipher_encrypt() nbytes:%u\n", req->cryptlen); in skcipher_encrypt()
1898 flow_log("skcipher_decrypt() nbytes:%u\n", req->cryptlen); in skcipher_decrypt()
1910 flow_log("ahash_enqueue() nbytes:%u\n", req->nbytes); in ahash_enqueue()
1912 rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_enqueue()
1914 rctx->parent = &req->base; in ahash_enqueue()
1915 rctx->ctx = ctx; in ahash_enqueue()
1916 rctx->bd_suppress = true; in ahash_enqueue()
1917 memset(&rctx->mb_mssg, 0, sizeof(struct brcm_message)); in ahash_enqueue()
1920 rctx->src_sg = req->src; in ahash_enqueue()
1921 rctx->src_skip = 0; in ahash_enqueue()
1922 rctx->src_nents = 0; in ahash_enqueue()
1923 rctx->dst_sg = NULL; in ahash_enqueue()
1924 rctx->dst_skip = 0; in ahash_enqueue()
1925 rctx->dst_nents = 0; in ahash_enqueue()
1928 if ((rctx->is_final == 1) && (rctx->total_todo == 0) && in ahash_enqueue()
1931 flow_log("Doing %sfinal %s zero-len hash request in software\n", in ahash_enqueue()
1932 rctx->is_final ? "" : "non-", alg_name); in ahash_enqueue()
1933 err = do_shash((unsigned char *)alg_name, req->result, in ahash_enqueue()
1934 NULL, 0, NULL, 0, ctx->authkey, in ahash_enqueue()
1935 ctx->authkeylen); in ahash_enqueue()
1941 rctx->chan_idx = select_channel(); in ahash_enqueue()
1944 if (err != -EINPROGRESS) in ahash_enqueue()
1948 if (err == -EAGAIN) in ahash_enqueue()
1968 rctx->hash_carry_len = 0; in __ahash_init()
1969 rctx->is_final = 0; in __ahash_init()
1971 rctx->total_todo = 0; in __ahash_init()
1972 rctx->src_sent = 0; in __ahash_init()
1973 rctx->total_sent = 0; in __ahash_init()
1974 rctx->total_received = 0; in __ahash_init()
1976 ctx->digestsize = crypto_ahash_digestsize(tfm); in __ahash_init()
1978 WARN_ON(ctx->digestsize > MAX_DIGEST_SIZE); in __ahash_init()
1980 rctx->is_sw_hmac = false; in __ahash_init()
1982 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, 0, in __ahash_init()
1989 * spu_no_incr_hash() - Determine whether incremental hashing is supported.
1992 * SPU-2 does not support incremental hashing (we'll have to revisit and
1996 * SPU-M also doesn't support incremental hashing of AES-XCBC
2005 if (spu->spu_type == SPU_TYPE_SPU2) in spu_no_incr_hash()
2008 if ((ctx->auth.alg == HASH_ALG_AES) && in spu_no_incr_hash()
2009 (ctx->auth.mode == HASH_MODE_XCBC)) in spu_no_incr_hash()
2038 gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_init()
2040 ctx->shash = kmalloc(sizeof(*ctx->shash) + in ahash_init()
2042 if (!ctx->shash) { in ahash_init()
2043 ret = -ENOMEM; in ahash_init()
2046 ctx->shash->tfm = hash; in ahash_init()
2049 if (ctx->authkeylen > 0) { in ahash_init()
2050 ret = crypto_shash_setkey(hash, ctx->authkey, in ahash_init()
2051 ctx->authkeylen); in ahash_init()
2057 ret = crypto_shash_init(ctx->shash); in ahash_init()
2068 kfree(ctx->shash); in ahash_init()
2079 flow_log("ahash_update() nbytes:%u\n", req->nbytes); in __ahash_update()
2081 if (!req->nbytes) in __ahash_update()
2083 rctx->total_todo += req->nbytes; in __ahash_update()
2084 rctx->src_sent = 0; in __ahash_update()
2104 if (req->src) in ahash_update()
2105 nents = sg_nents(req->src); in ahash_update()
2107 return -EINVAL; in ahash_update()
2110 gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_update()
2112 tmpbuf = kmalloc(req->nbytes, gfp); in ahash_update()
2114 return -ENOMEM; in ahash_update()
2116 if (sg_copy_to_buffer(req->src, nents, tmpbuf, req->nbytes) != in ahash_update()
2117 req->nbytes) { in ahash_update()
2119 return -EINVAL; in ahash_update()
2123 ret = crypto_shash_update(ctx->shash, tmpbuf, req->nbytes); in ahash_update()
2137 flow_log("ahash_final() nbytes:%u\n", req->nbytes); in __ahash_final()
2139 rctx->is_final = 1; in __ahash_final()
2156 ret = crypto_shash_final(ctx->shash, req->result); in ahash_final()
2159 crypto_free_shash(ctx->shash->tfm); in ahash_final()
2160 kfree(ctx->shash); in ahash_final()
2174 flow_log("ahash_finup() nbytes:%u\n", req->nbytes); in __ahash_finup()
2176 rctx->total_todo += req->nbytes; in __ahash_finup()
2177 rctx->src_sent = 0; in __ahash_finup()
2178 rctx->is_final = 1; in __ahash_finup()
2198 if (req->src) { in ahash_finup()
2199 nents = sg_nents(req->src); in ahash_finup()
2201 ret = -EINVAL; in ahash_finup()
2206 gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in ahash_finup()
2208 tmpbuf = kmalloc(req->nbytes, gfp); in ahash_finup()
2210 ret = -ENOMEM; in ahash_finup()
2214 if (sg_copy_to_buffer(req->src, nents, tmpbuf, req->nbytes) != in ahash_finup()
2215 req->nbytes) { in ahash_finup()
2216 ret = -EINVAL; in ahash_finup()
2221 ret = crypto_shash_finup(ctx->shash, tmpbuf, req->nbytes, in ahash_finup()
2222 req->result); in ahash_finup()
2232 crypto_free_shash(ctx->shash->tfm); in ahash_finup()
2233 kfree(ctx->shash); in ahash_finup()
2241 flow_log("ahash_digest() nbytes:%u\n", req->nbytes); in ahash_digest()
2260 if (ctx->auth.alg == HASH_ALG_AES) { in ahash_setkey()
2263 ctx->cipher_type = CIPHER_TYPE_AES128; in ahash_setkey()
2266 ctx->cipher_type = CIPHER_TYPE_AES192; in ahash_setkey()
2269 ctx->cipher_type = CIPHER_TYPE_AES256; in ahash_setkey()
2273 return -EINVAL; in ahash_setkey()
2277 return -EINVAL; in ahash_setkey()
2279 memcpy(ctx->authkey, key, keylen); in ahash_setkey()
2280 ctx->authkeylen = keylen; in ahash_setkey()
2290 spu_exp->total_todo = rctx->total_todo; in ahash_export()
2291 spu_exp->total_sent = rctx->total_sent; in ahash_export()
2292 spu_exp->is_sw_hmac = rctx->is_sw_hmac; in ahash_export()
2293 memcpy(spu_exp->hash_carry, rctx->hash_carry, sizeof(rctx->hash_carry)); in ahash_export()
2294 spu_exp->hash_carry_len = rctx->hash_carry_len; in ahash_export()
2295 memcpy(spu_exp->incr_hash, rctx->incr_hash, sizeof(rctx->incr_hash)); in ahash_export()
2305 rctx->total_todo = spu_exp->total_todo; in ahash_import()
2306 rctx->total_sent = spu_exp->total_sent; in ahash_import()
2307 rctx->is_sw_hmac = spu_exp->is_sw_hmac; in ahash_import()
2308 memcpy(rctx->hash_carry, spu_exp->hash_carry, sizeof(rctx->hash_carry)); in ahash_import()
2309 rctx->hash_carry_len = spu_exp->hash_carry_len; in ahash_import()
2310 memcpy(rctx->incr_hash, spu_exp->incr_hash, sizeof(rctx->incr_hash)); in ahash_import()
2330 switch (ctx->auth.alg) { in ahash_hmac_setkey()
2332 rc = do_shash("md5", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2336 rc = do_shash("sha1", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2340 rc = do_shash("sha224", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2344 rc = do_shash("sha256", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2348 rc = do_shash("sha384", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2352 rc = do_shash("sha512", ctx->authkey, key, keylen, NULL, in ahash_hmac_setkey()
2356 rc = do_shash("sha3-224", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2360 rc = do_shash("sha3-256", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2364 rc = do_shash("sha3-384", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2368 rc = do_shash("sha3-512", ctx->authkey, key, keylen, in ahash_hmac_setkey()
2373 return -EINVAL; in ahash_hmac_setkey()
2377 __func__, rc, hash_alg_name[ctx->auth.alg]); in ahash_hmac_setkey()
2380 ctx->authkeylen = digestsize; in ahash_hmac_setkey()
2383 flow_dump(" newkey: ", ctx->authkey, ctx->authkeylen); in ahash_hmac_setkey()
2385 memcpy(ctx->authkey, key, keylen); in ahash_hmac_setkey()
2386 ctx->authkeylen = keylen; in ahash_hmac_setkey()
2395 memcpy(ctx->ipad, ctx->authkey, ctx->authkeylen); in ahash_hmac_setkey()
2396 memset(ctx->ipad + ctx->authkeylen, 0, in ahash_hmac_setkey()
2397 blocksize - ctx->authkeylen); in ahash_hmac_setkey()
2398 ctx->authkeylen = 0; in ahash_hmac_setkey()
2399 unsafe_memcpy(ctx->opad, ctx->ipad, blocksize, in ahash_hmac_setkey()
2400 "fortified memcpy causes -Wrestrict warning"); in ahash_hmac_setkey()
2403 ctx->ipad[index] ^= HMAC_IPAD_VALUE; in ahash_hmac_setkey()
2404 ctx->opad[index] ^= HMAC_OPAD_VALUE; in ahash_hmac_setkey()
2407 flow_dump(" ipad: ", ctx->ipad, blocksize); in ahash_hmac_setkey()
2408 flow_dump(" opad: ", ctx->opad, blocksize); in ahash_hmac_setkey()
2410 ctx->digestsize = digestsize; in ahash_hmac_setkey()
2430 /* SPU-M can do incr hashing but needs sw for outer HMAC */ in ahash_hmac_init()
2431 rctx->is_sw_hmac = true; in ahash_hmac_init()
2432 ctx->auth.mode = HASH_MODE_HASH; in ahash_hmac_init()
2434 memcpy(rctx->hash_carry, ctx->ipad, blocksize); in ahash_hmac_init()
2435 rctx->hash_carry_len = blocksize; in ahash_hmac_init()
2436 rctx->total_todo += blocksize; in ahash_hmac_init()
2444 flow_log("ahash_hmac_update() nbytes:%u\n", req->nbytes); in ahash_hmac_update()
2446 if (!req->nbytes) in ahash_hmac_update()
2454 flow_log("ahash_hmac_final() nbytes:%u\n", req->nbytes); in ahash_hmac_final()
2461 flow_log("ahash_hmac_finupl() nbytes:%u\n", req->nbytes); in ahash_hmac_finup()
2474 flow_log("ahash_hmac_digest() nbytes:%u\n", req->nbytes); in ahash_hmac_digest()
2488 rctx->is_sw_hmac = false; in ahash_hmac_digest()
2489 ctx->auth.mode = HASH_MODE_HMAC; in ahash_hmac_digest()
2491 rctx->is_sw_hmac = true; in ahash_hmac_digest()
2492 ctx->auth.mode = HASH_MODE_HASH; in ahash_hmac_digest()
2494 memcpy(rctx->hash_carry, ctx->ipad, blocksize); in ahash_hmac_digest()
2495 rctx->hash_carry_len = blocksize; in ahash_hmac_digest()
2496 rctx->total_todo += blocksize; in ahash_hmac_digest()
2513 * SPU hardware cannot handle the AES-GCM/CCM case where plaintext in aead_need_fallback()
2516 if (((ctx->cipher.mode == CIPHER_MODE_GCM) || in aead_need_fallback()
2517 (ctx->cipher.mode == CIPHER_MODE_CCM)) && in aead_need_fallback()
2518 (req->assoclen == 0)) { in aead_need_fallback()
2519 if ((rctx->is_encrypt && (req->cryptlen == 0)) || in aead_need_fallback()
2520 (!rctx->is_encrypt && (req->cryptlen == ctx->digestsize))) { in aead_need_fallback()
2526 /* SPU-M hardware only supports CCM digest size of 8, 12, or 16 bytes */ in aead_need_fallback()
2527 if ((ctx->cipher.mode == CIPHER_MODE_CCM) && in aead_need_fallback()
2528 (spu->spu_type == SPU_TYPE_SPUM) && in aead_need_fallback()
2529 (ctx->digestsize != 8) && (ctx->digestsize != 12) && in aead_need_fallback()
2530 (ctx->digestsize != 16)) { in aead_need_fallback()
2532 __func__, ctx->digestsize); in aead_need_fallback()
2537 * SPU-M on NSP has an issue where AES-CCM hash is not correct in aead_need_fallback()
2540 if ((ctx->cipher.mode == CIPHER_MODE_CCM) && in aead_need_fallback()
2541 (spu->spu_subtype == SPU_SUBTYPE_SPUM_NSP) && in aead_need_fallback()
2542 (req->assoclen == 0)) { in aead_need_fallback()
2552 if (ctx->cipher.mode == CIPHER_MODE_GCM && in aead_need_fallback()
2553 ctx->cipher.alg == CIPHER_ALG_AES && in aead_need_fallback()
2554 rctx->iv_ctr_len == GCM_RFC4106_IV_SIZE && in aead_need_fallback()
2555 req->assoclen != 16 && req->assoclen != 20) { in aead_need_fallback()
2561 payload_len = req->cryptlen; in aead_need_fallback()
2562 if (spu->spu_type == SPU_TYPE_SPUM) in aead_need_fallback()
2563 payload_len += req->assoclen; in aead_need_fallback()
2567 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in aead_need_fallback()
2570 return payload_len > ctx->max_payload; in aead_need_fallback()
2583 if (!ctx->fallback_cipher) in aead_do_fallback()
2584 return -EINVAL; in aead_do_fallback()
2586 subreq = &rctx->req; in aead_do_fallback()
2587 aead_request_set_tfm(subreq, ctx->fallback_cipher); in aead_do_fallback()
2589 req->base.complete, req->base.data); in aead_do_fallback()
2590 aead_request_set_crypt(subreq, req->src, req->dst, req->cryptlen, in aead_do_fallback()
2591 req->iv); in aead_do_fallback()
2592 aead_request_set_ad(subreq, req->assoclen); in aead_do_fallback()
2607 if (req->assoclen > MAX_ASSOC_SIZE) { in aead_enqueue()
2610 __func__, req->assoclen, MAX_ASSOC_SIZE); in aead_enqueue()
2611 return -EINVAL; in aead_enqueue()
2614 rctx->gfp = (req->base.flags & (CRYPTO_TFM_REQ_MAY_BACKLOG | in aead_enqueue()
2616 rctx->parent = &req->base; in aead_enqueue()
2617 rctx->is_encrypt = is_encrypt; in aead_enqueue()
2618 rctx->bd_suppress = false; in aead_enqueue()
2619 rctx->total_todo = req->cryptlen; in aead_enqueue()
2620 rctx->src_sent = 0; in aead_enqueue()
2621 rctx->total_sent = 0; in aead_enqueue()
2622 rctx->total_received = 0; in aead_enqueue()
2623 rctx->is_sw_hmac = false; in aead_enqueue()
2624 rctx->ctx = ctx; in aead_enqueue()
2625 memset(&rctx->mb_mssg, 0, sizeof(struct brcm_message)); in aead_enqueue()
2627 /* assoc data is at start of src sg */ in aead_enqueue()
2628 rctx->assoc = req->src; in aead_enqueue()
2631 * Init current position in src scatterlist to be after assoc data. in aead_enqueue()
2632 * src_skip set to buffer offset where data begins. (Assoc data could in aead_enqueue()
2635 if (spu_sg_at_offset(req->src, req->assoclen, &rctx->src_sg, in aead_enqueue()
2636 &rctx->src_skip) < 0) { in aead_enqueue()
2639 return -EINVAL; in aead_enqueue()
2642 rctx->src_nents = 0; in aead_enqueue()
2643 rctx->dst_nents = 0; in aead_enqueue()
2644 if (req->dst == req->src) { in aead_enqueue()
2645 rctx->dst_sg = rctx->src_sg; in aead_enqueue()
2646 rctx->dst_skip = rctx->src_skip; in aead_enqueue()
2649 * Expect req->dst to have room for assoc data followed by in aead_enqueue()
2651 * to point beyond assoc len offset. in aead_enqueue()
2653 if (spu_sg_at_offset(req->dst, req->assoclen, &rctx->dst_sg, in aead_enqueue()
2654 &rctx->dst_skip) < 0) { in aead_enqueue()
2657 return -EINVAL; in aead_enqueue()
2661 if (ctx->cipher.mode == CIPHER_MODE_CBC || in aead_enqueue()
2662 ctx->cipher.mode == CIPHER_MODE_CTR || in aead_enqueue()
2663 ctx->cipher.mode == CIPHER_MODE_OFB || in aead_enqueue()
2664 ctx->cipher.mode == CIPHER_MODE_XTS || in aead_enqueue()
2665 ctx->cipher.mode == CIPHER_MODE_GCM) { in aead_enqueue()
2666 rctx->iv_ctr_len = in aead_enqueue()
2667 ctx->salt_len + in aead_enqueue()
2669 } else if (ctx->cipher.mode == CIPHER_MODE_CCM) { in aead_enqueue()
2670 rctx->iv_ctr_len = CCM_AES_IV_SIZE; in aead_enqueue()
2672 rctx->iv_ctr_len = 0; in aead_enqueue()
2675 rctx->hash_carry_len = 0; in aead_enqueue()
2677 flow_log(" src sg: %p\n", req->src); in aead_enqueue()
2678 flow_log(" rctx->src_sg: %p, src_skip %u\n", in aead_enqueue()
2679 rctx->src_sg, rctx->src_skip); in aead_enqueue()
2680 flow_log(" assoc: %p, assoclen %u\n", rctx->assoc, req->assoclen); in aead_enqueue()
2681 flow_log(" dst sg: %p\n", req->dst); in aead_enqueue()
2682 flow_log(" rctx->dst_sg: %p, dst_skip %u\n", in aead_enqueue()
2683 rctx->dst_sg, rctx->dst_skip); in aead_enqueue()
2684 flow_log(" iv_ctr_len:%u\n", rctx->iv_ctr_len); in aead_enqueue()
2685 flow_dump(" iv: ", req->iv, rctx->iv_ctr_len); in aead_enqueue()
2686 flow_log(" authkeylen:%u\n", ctx->authkeylen); in aead_enqueue()
2687 flow_log(" is_esp: %s\n", ctx->is_esp ? "yes" : "no"); in aead_enqueue()
2689 if (ctx->max_payload == SPU_MAX_PAYLOAD_INF) in aead_enqueue()
2692 flow_log(" max_payload: %u\n", ctx->max_payload); in aead_enqueue()
2701 if (rctx->iv_ctr_len) { in aead_enqueue()
2702 if (ctx->salt_len) in aead_enqueue()
2703 memcpy(rctx->msg_buf.iv_ctr + ctx->salt_offset, in aead_enqueue()
2704 ctx->salt, ctx->salt_len); in aead_enqueue()
2705 memcpy(rctx->msg_buf.iv_ctr + ctx->salt_offset + ctx->salt_len, in aead_enqueue()
2706 req->iv, in aead_enqueue()
2707 rctx->iv_ctr_len - ctx->salt_len - ctx->salt_offset); in aead_enqueue()
2710 rctx->chan_idx = select_channel(); in aead_enqueue()
2712 if (err != -EINPROGRESS) in aead_enqueue()
2740 ctx->enckeylen = keys.enckeylen; in aead_authenc_setkey()
2741 ctx->authkeylen = keys.authkeylen; in aead_authenc_setkey()
2743 memcpy(ctx->enckey, keys.enckey, keys.enckeylen); in aead_authenc_setkey()
2745 memset(ctx->authkey, 0, sizeof(ctx->authkey)); in aead_authenc_setkey()
2746 memcpy(ctx->authkey, keys.authkey, keys.authkeylen); in aead_authenc_setkey()
2748 switch (ctx->alg->cipher_info.alg) { in aead_authenc_setkey()
2751 return -EINVAL; in aead_authenc_setkey()
2753 ctx->cipher_type = CIPHER_TYPE_DES; in aead_authenc_setkey()
2757 return -EINVAL; in aead_authenc_setkey()
2759 ctx->cipher_type = CIPHER_TYPE_3DES; in aead_authenc_setkey()
2762 switch (ctx->enckeylen) { in aead_authenc_setkey()
2764 ctx->cipher_type = CIPHER_TYPE_AES128; in aead_authenc_setkey()
2767 ctx->cipher_type = CIPHER_TYPE_AES192; in aead_authenc_setkey()
2770 ctx->cipher_type = CIPHER_TYPE_AES256; in aead_authenc_setkey()
2778 return -EINVAL; in aead_authenc_setkey()
2781 flow_log(" enckeylen:%u authkeylen:%u\n", ctx->enckeylen, in aead_authenc_setkey()
2782 ctx->authkeylen); in aead_authenc_setkey()
2783 flow_dump(" enc: ", ctx->enckey, ctx->enckeylen); in aead_authenc_setkey()
2784 flow_dump(" auth: ", ctx->authkey, ctx->authkeylen); in aead_authenc_setkey()
2787 if (ctx->fallback_cipher) { in aead_authenc_setkey()
2790 ctx->fallback_cipher->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; in aead_authenc_setkey()
2791 ctx->fallback_cipher->base.crt_flags |= in aead_authenc_setkey()
2792 tfm->crt_flags & CRYPTO_TFM_REQ_MASK; in aead_authenc_setkey()
2793 ret = crypto_aead_setkey(ctx->fallback_cipher, key, keylen); in aead_authenc_setkey()
2798 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, in aead_authenc_setkey()
2799 ctx->enckeylen, in aead_authenc_setkey()
2807 ctx->enckeylen = 0; in aead_authenc_setkey()
2808 ctx->authkeylen = 0; in aead_authenc_setkey()
2809 ctx->digestsize = 0; in aead_authenc_setkey()
2811 return -EINVAL; in aead_authenc_setkey()
2826 if (!ctx->is_esp) in aead_gcm_ccm_setkey()
2827 ctx->digestsize = keylen; in aead_gcm_ccm_setkey()
2829 ctx->enckeylen = keylen; in aead_gcm_ccm_setkey()
2830 ctx->authkeylen = 0; in aead_gcm_ccm_setkey()
2832 switch (ctx->enckeylen) { in aead_gcm_ccm_setkey()
2834 ctx->cipher_type = CIPHER_TYPE_AES128; in aead_gcm_ccm_setkey()
2837 ctx->cipher_type = CIPHER_TYPE_AES192; in aead_gcm_ccm_setkey()
2840 ctx->cipher_type = CIPHER_TYPE_AES256; in aead_gcm_ccm_setkey()
2846 memcpy(ctx->enckey, key, ctx->enckeylen); in aead_gcm_ccm_setkey()
2848 flow_log(" enckeylen:%u authkeylen:%u\n", ctx->enckeylen, in aead_gcm_ccm_setkey()
2849 ctx->authkeylen); in aead_gcm_ccm_setkey()
2850 flow_dump(" enc: ", ctx->enckey, ctx->enckeylen); in aead_gcm_ccm_setkey()
2851 flow_dump(" auth: ", ctx->authkey, ctx->authkeylen); in aead_gcm_ccm_setkey()
2854 if (ctx->fallback_cipher) { in aead_gcm_ccm_setkey()
2857 ctx->fallback_cipher->base.crt_flags &= ~CRYPTO_TFM_REQ_MASK; in aead_gcm_ccm_setkey()
2858 ctx->fallback_cipher->base.crt_flags |= in aead_gcm_ccm_setkey()
2859 tfm->crt_flags & CRYPTO_TFM_REQ_MASK; in aead_gcm_ccm_setkey()
2860 ret = crypto_aead_setkey(ctx->fallback_cipher, key, in aead_gcm_ccm_setkey()
2861 keylen + ctx->salt_len); in aead_gcm_ccm_setkey()
2866 ctx->spu_resp_hdr_len = spu->spu_response_hdr_len(ctx->authkeylen, in aead_gcm_ccm_setkey()
2867 ctx->enckeylen, in aead_gcm_ccm_setkey()
2872 flow_log(" enckeylen:%u authkeylen:%u\n", ctx->enckeylen, in aead_gcm_ccm_setkey()
2873 ctx->authkeylen); in aead_gcm_ccm_setkey()
2878 ctx->enckeylen = 0; in aead_gcm_ccm_setkey()
2879 ctx->authkeylen = 0; in aead_gcm_ccm_setkey()
2880 ctx->digestsize = 0; in aead_gcm_ccm_setkey()
2882 return -EINVAL; in aead_gcm_ccm_setkey()
2886 * aead_gcm_esp_setkey() - setkey() operation for ESP variant of GCM AES.
2904 return -EINVAL; in aead_gcm_esp_setkey()
2906 ctx->salt_len = GCM_ESP_SALT_SIZE; in aead_gcm_esp_setkey()
2907 ctx->salt_offset = GCM_ESP_SALT_OFFSET; in aead_gcm_esp_setkey()
2908 memcpy(ctx->salt, key + keylen - GCM_ESP_SALT_SIZE, GCM_ESP_SALT_SIZE); in aead_gcm_esp_setkey()
2909 keylen -= GCM_ESP_SALT_SIZE; in aead_gcm_esp_setkey()
2910 ctx->digestsize = GCM_ESP_DIGESTSIZE; in aead_gcm_esp_setkey()
2911 ctx->is_esp = true; in aead_gcm_esp_setkey()
2912 flow_dump("salt: ", ctx->salt, GCM_ESP_SALT_SIZE); in aead_gcm_esp_setkey()
2918 * rfc4543_gcm_esp_setkey() - setkey operation for RFC4543 variant of GCM/GMAC.
2936 return -EINVAL; in rfc4543_gcm_esp_setkey()
2938 ctx->salt_len = GCM_ESP_SALT_SIZE; in rfc4543_gcm_esp_setkey()
2939 ctx->salt_offset = GCM_ESP_SALT_OFFSET; in rfc4543_gcm_esp_setkey()
2940 memcpy(ctx->salt, key + keylen - GCM_ESP_SALT_SIZE, GCM_ESP_SALT_SIZE); in rfc4543_gcm_esp_setkey()
2941 keylen -= GCM_ESP_SALT_SIZE; in rfc4543_gcm_esp_setkey()
2942 ctx->digestsize = GCM_ESP_DIGESTSIZE; in rfc4543_gcm_esp_setkey()
2943 ctx->is_esp = true; in rfc4543_gcm_esp_setkey()
2944 ctx->is_rfc4543 = true; in rfc4543_gcm_esp_setkey()
2945 flow_dump("salt: ", ctx->salt, GCM_ESP_SALT_SIZE); in rfc4543_gcm_esp_setkey()
2951 * aead_ccm_esp_setkey() - setkey() operation for ESP variant of CCM AES.
2969 return -EINVAL; in aead_ccm_esp_setkey()
2971 ctx->salt_len = CCM_ESP_SALT_SIZE; in aead_ccm_esp_setkey()
2972 ctx->salt_offset = CCM_ESP_SALT_OFFSET; in aead_ccm_esp_setkey()
2973 memcpy(ctx->salt, key + keylen - CCM_ESP_SALT_SIZE, CCM_ESP_SALT_SIZE); in aead_ccm_esp_setkey()
2974 keylen -= CCM_ESP_SALT_SIZE; in aead_ccm_esp_setkey()
2975 ctx->is_esp = true; in aead_ccm_esp_setkey()
2976 flow_dump("salt: ", ctx->salt, CCM_ESP_SALT_SIZE); in aead_ccm_esp_setkey()
2987 __func__, ctx->authkeylen, authsize); in aead_setauthsize()
2989 ctx->digestsize = authsize; in aead_setauthsize()
2992 if (ctx->fallback_cipher) { in aead_setauthsize()
2995 ret = crypto_aead_setauthsize(ctx->fallback_cipher, authsize); in aead_setauthsize()
3005 flow_log("%s() cryptlen:%u %08x\n", __func__, req->cryptlen, in aead_encrypt()
3006 req->cryptlen); in aead_encrypt()
3007 dump_sg(req->src, 0, req->cryptlen + req->assoclen); in aead_encrypt()
3008 flow_log(" assoc_len:%u\n", req->assoclen); in aead_encrypt()
3015 flow_log("%s() cryptlen:%u\n", __func__, req->cryptlen); in aead_decrypt()
3016 dump_sg(req->src, 0, req->cryptlen + req->assoclen); in aead_decrypt()
3017 flow_log(" assoc_len:%u\n", req->assoclen); in aead_decrypt()
3030 .cra_driver_name = "gcm-aes-iproc",
3053 .cra_driver_name = "ccm-aes-iproc",
3076 .cra_driver_name = "gcm-aes-esp-iproc",
3099 .cra_driver_name = "ccm-aes-esp-iproc",
3122 .cra_driver_name = "gmac-aes-esp-iproc",
3145 .cra_driver_name = "authenc-hmac-md5-cbc-aes-iproc",
3170 .cra_driver_name = "authenc-hmac-sha1-cbc-aes-iproc",
3195 .cra_driver_name = "authenc-hmac-sha256-cbc-aes-iproc",
3220 .cra_driver_name = "authenc-hmac-md5-cbc-des-iproc",
3245 .cra_driver_name = "authenc-hmac-sha1-cbc-des-iproc",
3270 .cra_driver_name = "authenc-hmac-sha224-cbc-des-iproc",
3295 .cra_driver_name = "authenc-hmac-sha256-cbc-des-iproc",
3320 .cra_driver_name = "authenc-hmac-sha384-cbc-des-iproc",
3345 .cra_driver_name = "authenc-hmac-sha512-cbc-des-iproc",
3370 .cra_driver_name = "authenc-hmac-md5-cbc-des3-iproc",
3395 .cra_driver_name = "authenc-hmac-sha1-cbc-des3-iproc",
3420 .cra_driver_name = "authenc-hmac-sha224-cbc-des3-iproc",
3445 .cra_driver_name = "authenc-hmac-sha256-cbc-des3-iproc",
3470 .cra_driver_name = "authenc-hmac-sha384-cbc-des3-iproc",
3495 .cra_driver_name = "authenc-hmac-sha512-cbc-des3-iproc",
3521 .base.cra_driver_name = "cbc-des-iproc",
3540 .base.cra_driver_name = "ecb-des-iproc",
3559 .base.cra_driver_name = "cbc-des3-iproc",
3578 .base.cra_driver_name = "ecb-des3-iproc",
3597 .base.cra_driver_name = "cbc-aes-iproc",
3616 .base.cra_driver_name = "ecb-aes-iproc",
3635 .base.cra_driver_name = "ctr-aes-iproc",
3654 .base.cra_driver_name = "xts-aes-iproc",
3677 .cra_driver_name = "md5-iproc",
3698 .cra_driver_name = "hmac-md5-iproc",
3716 .cra_driver_name = "sha1-iproc",
3734 .cra_driver_name = "hmac-sha1-iproc",
3752 .cra_driver_name = "sha224-iproc",
3770 .cra_driver_name = "hmac-sha224-iproc",
3788 .cra_driver_name = "sha256-iproc",
3806 .cra_driver_name = "hmac-sha256-iproc",
3825 .cra_driver_name = "sha384-iproc",
3844 .cra_driver_name = "hmac-sha384-iproc",
3863 .cra_driver_name = "sha512-iproc",
3882 .cra_driver_name = "hmac-sha512-iproc",
3900 .cra_name = "sha3-224",
3901 .cra_driver_name = "sha3-224-iproc",
3919 .cra_name = "hmac(sha3-224)",
3920 .cra_driver_name = "hmac-sha3-224-iproc",
3938 .cra_name = "sha3-256",
3939 .cra_driver_name = "sha3-256-iproc",
3957 .cra_name = "hmac(sha3-256)",
3958 .cra_driver_name = "hmac-sha3-256-iproc",
3976 .cra_name = "sha3-384",
3977 .cra_driver_name = "sha3-384-iproc",
3995 .cra_name = "hmac(sha3-384)",
3996 .cra_driver_name = "hmac-sha3-384-iproc",
4014 .cra_name = "sha3-512",
4015 .cra_driver_name = "sha3-512-iproc",
4033 .cra_name = "hmac(sha3-512)",
4034 .cra_driver_name = "hmac-sha3-512-iproc",
4053 .cra_driver_name = "xcbc-aes-iproc",
4072 .cra_driver_name = "cmac-aes-iproc",
4096 ctx->alg = cipher_alg; in generic_cra_init()
4097 ctx->cipher = cipher_alg->cipher_info; in generic_cra_init()
4098 ctx->auth = cipher_alg->auth_info; in generic_cra_init()
4099 ctx->auth_first = cipher_alg->auth_first; in generic_cra_init()
4100 ctx->max_payload = spu->spu_ctx_max_payload(ctx->cipher.alg, in generic_cra_init()
4101 ctx->cipher.mode, in generic_cra_init()
4103 ctx->fallback_cipher = NULL; in generic_cra_init()
4105 ctx->enckeylen = 0; in generic_cra_init()
4106 ctx->authkeylen = 0; in generic_cra_init()
4131 struct crypto_alg *alg = tfm->__crt_alg; in ahash_cra_init()
4155 struct crypto_alg *alg = tfm->__crt_alg; in aead_cra_init()
4164 ctx->is_esp = false; in aead_cra_init()
4165 ctx->salt_len = 0; in aead_cra_init()
4166 ctx->salt_offset = 0; in aead_cra_init()
4169 get_random_bytes(ctx->iv, MAX_IV_SIZE); in aead_cra_init()
4170 flow_dump(" iv: ", ctx->iv, MAX_IV_SIZE); in aead_cra_init()
4175 if (!(alg->cra_flags & CRYPTO_ALG_NEED_FALLBACK)) in aead_cra_init()
4180 ctx->fallback_cipher = crypto_alloc_aead(alg->cra_name, 0, in aead_cra_init()
4183 if (IS_ERR(ctx->fallback_cipher)) { in aead_cra_init()
4185 __func__, alg->cra_name); in aead_cra_init()
4186 return PTR_ERR(ctx->fallback_cipher); in aead_cra_init()
4189 reqsize += crypto_aead_reqsize(ctx->fallback_cipher); in aead_cra_init()
4215 if (ctx->fallback_cipher) { in aead_cra_exit()
4216 crypto_free_aead(ctx->fallback_cipher); in aead_cra_exit()
4217 ctx->fallback_cipher = NULL; in aead_cra_exit()
4222 * spu_functions_register() - Specify hardware-specific SPU functions based on
4236 spu->spu_dump_msg_hdr = spum_dump_msg_hdr; in spu_functions_register()
4237 spu->spu_payload_length = spum_payload_length; in spu_functions_register()
4238 spu->spu_response_hdr_len = spum_response_hdr_len; in spu_functions_register()
4239 spu->spu_hash_pad_len = spum_hash_pad_len; in spu_functions_register()
4240 spu->spu_gcm_ccm_pad_len = spum_gcm_ccm_pad_len; in spu_functions_register()
4241 spu->spu_assoc_resp_len = spum_assoc_resp_len; in spu_functions_register()
4242 spu->spu_aead_ivlen = spum_aead_ivlen; in spu_functions_register()
4243 spu->spu_hash_type = spum_hash_type; in spu_functions_register()
4244 spu->spu_digest_size = spum_digest_size; in spu_functions_register()
4245 spu->spu_create_request = spum_create_request; in spu_functions_register()
4246 spu->spu_cipher_req_init = spum_cipher_req_init; in spu_functions_register()
4247 spu->spu_cipher_req_finish = spum_cipher_req_finish; in spu_functions_register()
4248 spu->spu_request_pad = spum_request_pad; in spu_functions_register()
4249 spu->spu_tx_status_len = spum_tx_status_len; in spu_functions_register()
4250 spu->spu_rx_status_len = spum_rx_status_len; in spu_functions_register()
4251 spu->spu_status_process = spum_status_process; in spu_functions_register()
4252 spu->spu_xts_tweak_in_payload = spum_xts_tweak_in_payload; in spu_functions_register()
4253 spu->spu_ccm_update_iv = spum_ccm_update_iv; in spu_functions_register()
4254 spu->spu_wordalign_padlen = spum_wordalign_padlen; in spu_functions_register()
4256 spu->spu_ctx_max_payload = spum_ns2_ctx_max_payload; in spu_functions_register()
4258 spu->spu_ctx_max_payload = spum_nsp_ctx_max_payload; in spu_functions_register()
4261 spu->spu_dump_msg_hdr = spu2_dump_msg_hdr; in spu_functions_register()
4262 spu->spu_ctx_max_payload = spu2_ctx_max_payload; in spu_functions_register()
4263 spu->spu_payload_length = spu2_payload_length; in spu_functions_register()
4264 spu->spu_response_hdr_len = spu2_response_hdr_len; in spu_functions_register()
4265 spu->spu_hash_pad_len = spu2_hash_pad_len; in spu_functions_register()
4266 spu->spu_gcm_ccm_pad_len = spu2_gcm_ccm_pad_len; in spu_functions_register()
4267 spu->spu_assoc_resp_len = spu2_assoc_resp_len; in spu_functions_register()
4268 spu->spu_aead_ivlen = spu2_aead_ivlen; in spu_functions_register()
4269 spu->spu_hash_type = spu2_hash_type; in spu_functions_register()
4270 spu->spu_digest_size = spu2_digest_size; in spu_functions_register()
4271 spu->spu_create_request = spu2_create_request; in spu_functions_register()
4272 spu->spu_cipher_req_init = spu2_cipher_req_init; in spu_functions_register()
4273 spu->spu_cipher_req_finish = spu2_cipher_req_finish; in spu_functions_register()
4274 spu->spu_request_pad = spu2_request_pad; in spu_functions_register()
4275 spu->spu_tx_status_len = spu2_tx_status_len; in spu_functions_register()
4276 spu->spu_rx_status_len = spu2_rx_status_len; in spu_functions_register()
4277 spu->spu_status_process = spu2_status_process; in spu_functions_register()
4278 spu->spu_xts_tweak_in_payload = spu2_xts_tweak_in_payload; in spu_functions_register()
4279 spu->spu_ccm_update_iv = spu2_ccm_update_iv; in spu_functions_register()
4280 spu->spu_wordalign_padlen = spu2_wordalign_padlen; in spu_functions_register()
4285 * spu_mb_init() - Initialize mailbox client. Request ownership of a mailbox
4300 return -ENOMEM; in spu_mb_init()
4302 mcl->dev = dev; in spu_mb_init()
4303 mcl->tx_block = false; in spu_mb_init()
4304 mcl->tx_tout = 0; in spu_mb_init()
4305 mcl->knows_txdone = true; in spu_mb_init()
4306 mcl->rx_callback = spu_rx_callback; in spu_mb_init()
4307 mcl->tx_done = NULL; in spu_mb_init()
4371 struct skcipher_alg *crypto = &driver_alg->alg.skcipher; in spu_register_skcipher()
4374 crypto->base.cra_module = THIS_MODULE; in spu_register_skcipher()
4375 crypto->base.cra_priority = cipher_pri; in spu_register_skcipher()
4376 crypto->base.cra_alignmask = 0; in spu_register_skcipher()
4377 crypto->base.cra_ctxsize = sizeof(struct iproc_ctx_s); in spu_register_skcipher()
4378 crypto->base.cra_flags = CRYPTO_ALG_ASYNC | in spu_register_skcipher()
4382 crypto->init = skcipher_init_tfm; in spu_register_skcipher()
4383 crypto->exit = skcipher_exit_tfm; in spu_register_skcipher()
4384 crypto->setkey = skcipher_setkey; in spu_register_skcipher()
4385 crypto->encrypt = skcipher_encrypt; in spu_register_skcipher()
4386 crypto->decrypt = skcipher_decrypt; in spu_register_skcipher()
4391 driver_alg->registered = true; in spu_register_skcipher()
4392 pr_debug(" registered skcipher %s\n", crypto->base.cra_driver_name); in spu_register_skcipher()
4399 struct ahash_alg *hash = &driver_alg->alg.hash; in spu_register_ahash()
4402 /* AES-XCBC is the only AES hash type currently supported on SPU-M */ in spu_register_ahash()
4403 if ((driver_alg->auth_info.alg == HASH_ALG_AES) && in spu_register_ahash()
4404 (driver_alg->auth_info.mode != HASH_MODE_XCBC) && in spu_register_ahash()
4405 (spu->spu_type == SPU_TYPE_SPUM)) in spu_register_ahash()
4408 /* SHA3 algorithm variants are not registered for SPU-M or SPU2. */ in spu_register_ahash()
4409 if ((driver_alg->auth_info.alg >= HASH_ALG_SHA3_224) && in spu_register_ahash()
4410 (spu->spu_subtype != SPU_SUBTYPE_SPU2_V2)) in spu_register_ahash()
4413 hash->halg.base.cra_module = THIS_MODULE; in spu_register_ahash()
4414 hash->halg.base.cra_priority = hash_pri; in spu_register_ahash()
4415 hash->halg.base.cra_alignmask = 0; in spu_register_ahash()
4416 hash->halg.base.cra_ctxsize = sizeof(struct iproc_ctx_s); in spu_register_ahash()
4417 hash->halg.base.cra_init = ahash_cra_init; in spu_register_ahash()
4418 hash->halg.base.cra_exit = generic_cra_exit; in spu_register_ahash()
4419 hash->halg.base.cra_flags = CRYPTO_ALG_ASYNC | in spu_register_ahash()
4421 hash->halg.statesize = sizeof(struct spu_hash_export_s); in spu_register_ahash()
4423 if (driver_alg->auth_info.mode != HASH_MODE_HMAC) { in spu_register_ahash()
4424 hash->init = ahash_init; in spu_register_ahash()
4425 hash->update = ahash_update; in spu_register_ahash()
4426 hash->final = ahash_final; in spu_register_ahash()
4427 hash->finup = ahash_finup; in spu_register_ahash()
4428 hash->digest = ahash_digest; in spu_register_ahash()
4429 if ((driver_alg->auth_info.alg == HASH_ALG_AES) && in spu_register_ahash()
4430 ((driver_alg->auth_info.mode == HASH_MODE_XCBC) || in spu_register_ahash()
4431 (driver_alg->auth_info.mode == HASH_MODE_CMAC))) { in spu_register_ahash()
4432 hash->setkey = ahash_setkey; in spu_register_ahash()
4435 hash->setkey = ahash_hmac_setkey; in spu_register_ahash()
4436 hash->init = ahash_hmac_init; in spu_register_ahash()
4437 hash->update = ahash_hmac_update; in spu_register_ahash()
4438 hash->final = ahash_hmac_final; in spu_register_ahash()
4439 hash->finup = ahash_hmac_finup; in spu_register_ahash()
4440 hash->digest = ahash_hmac_digest; in spu_register_ahash()
4442 hash->export = ahash_export; in spu_register_ahash()
4443 hash->import = ahash_import; in spu_register_ahash()
4448 driver_alg->registered = true; in spu_register_ahash()
4450 hash->halg.base.cra_driver_name); in spu_register_ahash()
4456 struct aead_alg *aead = &driver_alg->alg.aead; in spu_register_aead()
4459 aead->base.cra_module = THIS_MODULE; in spu_register_aead()
4460 aead->base.cra_priority = aead_pri; in spu_register_aead()
4461 aead->base.cra_alignmask = 0; in spu_register_aead()
4462 aead->base.cra_ctxsize = sizeof(struct iproc_ctx_s); in spu_register_aead()
4464 aead->base.cra_flags |= CRYPTO_ALG_ASYNC | CRYPTO_ALG_ALLOCATES_MEMORY; in spu_register_aead()
4466 aead->setauthsize = aead_setauthsize; in spu_register_aead()
4467 aead->encrypt = aead_encrypt; in spu_register_aead()
4468 aead->decrypt = aead_decrypt; in spu_register_aead()
4469 aead->init = aead_cra_init; in spu_register_aead()
4470 aead->exit = aead_cra_exit; in spu_register_aead()
4475 driver_alg->registered = true; in spu_register_aead()
4476 pr_debug(" registered aead %s\n", aead->base.cra_driver_name); in spu_register_aead()
4499 "iproc-crypto: unknown alg type: %d", in spu_algs_register()
4501 err = -EINVAL; in spu_algs_register()
4556 .compatible = "brcm,spum-crypto",
4560 .compatible = "brcm,spum-nsp-crypto",
4564 .compatible = "brcm,spu2-crypto",
4568 .compatible = "brcm,spu2-v2-crypto",
4578 struct device *dev = &pdev->dev; in spu_dt_read()
4582 struct device_node *dn = pdev->dev.of_node; in spu_dt_read()
4586 spu->num_chan = of_count_phandle_with_args(dn, "mboxes", "#mbox-cells"); in spu_dt_read()
4591 return -ENODEV; in spu_dt_read()
4594 spu->spu_type = matched_spu_type->type; in spu_dt_read()
4595 spu->spu_subtype = matched_spu_type->subtype; in spu_dt_read()
4600 spu->reg_vbase[i] = devm_ioremap_resource(dev, spu_ctrl_regs); in spu_dt_read()
4601 if (IS_ERR(spu->reg_vbase[i])) { in spu_dt_read()
4602 err = PTR_ERR(spu->reg_vbase[i]); in spu_dt_read()
4605 spu->reg_vbase[i] = NULL; in spu_dt_read()
4609 spu->num_spu = i; in spu_dt_read()
4610 dev_dbg(dev, "Device has %d SPUs", spu->num_spu); in spu_dt_read()
4617 struct device *dev = &pdev->dev; in bcm_spu_probe()
4633 if (spu->spu_type == SPU_TYPE_SPUM) in bcm_spu_probe()
4635 else if (spu->spu_type == SPU_TYPE_SPU2) in bcm_spu_probe()
4638 spu_functions_register(dev, spu->spu_type, spu->spu_subtype); in bcm_spu_probe()
4662 struct device *dev = &pdev->dev; in bcm_spu_remove()
4703 .name = "brcm-spu-crypto",