Lines Matching refs:ctx_p
69 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_key_type() local
71 return ctx_p->key_type; in cc_key_type()
74 static int validate_keys_sizes(struct cc_cipher_ctx *ctx_p, u32 size) in validate_keys_sizes() argument
76 switch (ctx_p->flow_mode) { in validate_keys_sizes()
81 if (ctx_p->cipher_mode != DRV_CIPHER_XTS && in validate_keys_sizes()
82 ctx_p->cipher_mode != DRV_CIPHER_ESSIV && in validate_keys_sizes()
83 ctx_p->cipher_mode != DRV_CIPHER_BITLOCKER) in validate_keys_sizes()
90 if (ctx_p->cipher_mode == DRV_CIPHER_XTS || in validate_keys_sizes()
91 ctx_p->cipher_mode == DRV_CIPHER_ESSIV || in validate_keys_sizes()
92 ctx_p->cipher_mode == DRV_CIPHER_BITLOCKER) in validate_keys_sizes()
112 static int validate_data_size(struct cc_cipher_ctx *ctx_p, in validate_data_size() argument
115 switch (ctx_p->flow_mode) { in validate_data_size()
117 switch (ctx_p->cipher_mode) { in validate_data_size()
142 switch (ctx_p->cipher_mode) { in validate_data_size()
160 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_cipher_init() local
168 dev_dbg(dev, "Initializing context @%p for %s\n", ctx_p, in cc_cipher_init()
174 ctx_p->cipher_mode = cc_alg->cipher_mode; in cc_cipher_init()
175 ctx_p->flow_mode = cc_alg->flow_mode; in cc_cipher_init()
176 ctx_p->drvdata = cc_alg->drvdata; in cc_cipher_init()
179 ctx_p->user.key = kmalloc(max_key_buf_size, GFP_KERNEL); in cc_cipher_init()
180 if (!ctx_p->user.key) in cc_cipher_init()
184 ctx_p->user.key); in cc_cipher_init()
187 ctx_p->user.key_dma_addr = dma_map_single(dev, (void *)ctx_p->user.key, in cc_cipher_init()
190 if (dma_mapping_error(dev, ctx_p->user.key_dma_addr)) { in cc_cipher_init()
192 max_key_buf_size, ctx_p->user.key); in cc_cipher_init()
196 max_key_buf_size, ctx_p->user.key, &ctx_p->user.key_dma_addr); in cc_cipher_init()
198 if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { in cc_cipher_init()
200 ctx_p->shash_tfm = crypto_alloc_shash("sha256-generic", 0, 0); in cc_cipher_init()
201 if (IS_ERR(ctx_p->shash_tfm)) { in cc_cipher_init()
203 return PTR_ERR(ctx_p->shash_tfm); in cc_cipher_init()
217 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_cipher_exit() local
218 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_cipher_exit()
223 if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { in cc_cipher_exit()
225 crypto_free_shash(ctx_p->shash_tfm); in cc_cipher_exit()
226 ctx_p->shash_tfm = NULL; in cc_cipher_exit()
230 dma_unmap_single(dev, ctx_p->user.key_dma_addr, max_key_buf_size, in cc_cipher_exit()
233 &ctx_p->user.key_dma_addr); in cc_cipher_exit()
236 kzfree(ctx_p->user.key); in cc_cipher_exit()
237 dev_dbg(dev, "Free key buffer in context. key=@%p\n", ctx_p->user.key); in cc_cipher_exit()
281 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_cipher_sethkey() local
282 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_cipher_sethkey()
286 ctx_p, crypto_tfm_alg_name(tfm), keylen); in cc_cipher_sethkey()
305 if (validate_keys_sizes(ctx_p, keylen)) { in cc_cipher_sethkey()
311 ctx_p->keylen = keylen; in cc_cipher_sethkey()
315 if (ctx_p->flow_mode == S_DIN_to_SM4) { in cc_cipher_sethkey()
320 ctx_p->hw.key1_slot = cc_slot_to_hw_key(hki.hw_key1); in cc_cipher_sethkey()
321 if (ctx_p->hw.key1_slot == END_OF_KEYS) { in cc_cipher_sethkey()
327 if (ctx_p->cipher_mode == DRV_CIPHER_XTS || in cc_cipher_sethkey()
328 ctx_p->cipher_mode == DRV_CIPHER_ESSIV || in cc_cipher_sethkey()
329 ctx_p->cipher_mode == DRV_CIPHER_BITLOCKER) { in cc_cipher_sethkey()
336 ctx_p->hw.key2_slot = cc_slot_to_hw_key(hki.hw_key2); in cc_cipher_sethkey()
337 if (ctx_p->hw.key2_slot == END_OF_KEYS) { in cc_cipher_sethkey()
344 ctx_p->key_type = CC_HW_PROTECTED_KEY; in cc_cipher_sethkey()
346 ctx_p->hw.key1_slot, ctx_p->hw.key2_slot); in cc_cipher_sethkey()
350 if (ctx_p->drvdata->hw_rev < CC_HW_REV_713) { in cc_cipher_sethkey()
355 if (ctx_p->cipher_mode != DRV_CIPHER_CBC && in cc_cipher_sethkey()
356 ctx_p->cipher_mode != DRV_CIPHER_CTR) { in cc_cipher_sethkey()
361 ctx_p->cpp.slot = cc_slot_to_cpp_key(hki.hw_key1); in cc_cipher_sethkey()
362 if (ctx_p->flow_mode == S_DIN_to_AES) in cc_cipher_sethkey()
363 ctx_p->cpp.alg = CC_CPP_AES; in cc_cipher_sethkey()
365 ctx_p->cpp.alg = CC_CPP_SM4; in cc_cipher_sethkey()
366 ctx_p->key_type = CC_POLICY_PROTECTED_KEY; in cc_cipher_sethkey()
368 ctx_p->cpp.alg, ctx_p->cpp.slot); in cc_cipher_sethkey()
383 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_cipher_setkey() local
384 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_cipher_setkey()
391 ctx_p, crypto_tfm_alg_name(tfm), keylen); in cc_cipher_setkey()
396 if (validate_keys_sizes(ctx_p, keylen)) { in cc_cipher_setkey()
402 ctx_p->key_type = CC_UNPROTECTED_KEY; in cc_cipher_setkey()
409 if (ctx_p->flow_mode == S_DIN_to_DES) { in cc_cipher_setkey()
418 if (ctx_p->cipher_mode == DRV_CIPHER_XTS && in cc_cipher_setkey()
425 dma_sync_single_for_cpu(dev, ctx_p->user.key_dma_addr, in cc_cipher_setkey()
428 memcpy(ctx_p->user.key, key, keylen); in cc_cipher_setkey()
430 memset(ctx_p->user.key + 24, 0, CC_AES_KEY_SIZE_MAX - 24); in cc_cipher_setkey()
432 if (ctx_p->cipher_mode == DRV_CIPHER_ESSIV) { in cc_cipher_setkey()
437 SHASH_DESC_ON_STACK(desc, ctx_p->shash_tfm); in cc_cipher_setkey()
439 desc->tfm = ctx_p->shash_tfm; in cc_cipher_setkey()
441 err = crypto_shash_digest(desc, ctx_p->user.key, key_len, in cc_cipher_setkey()
442 ctx_p->user.key + key_len); in cc_cipher_setkey()
448 dma_sync_single_for_device(dev, ctx_p->user.key_dma_addr, in cc_cipher_setkey()
450 ctx_p->keylen = keylen; in cc_cipher_setkey()
456 static int cc_out_setup_mode(struct cc_cipher_ctx *ctx_p) in cc_out_setup_mode() argument
458 switch (ctx_p->flow_mode) { in cc_out_setup_mode()
466 return ctx_p->flow_mode; in cc_out_setup_mode()
475 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_setup_readiv_desc() local
476 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_setup_readiv_desc()
477 int cipher_mode = ctx_p->cipher_mode; in cc_setup_readiv_desc()
478 int flow_mode = cc_out_setup_mode(ctx_p); in cc_setup_readiv_desc()
482 if (ctx_p->key_type == CC_POLICY_PROTECTED_KEY) in cc_setup_readiv_desc()
504 set_queue_last_ind(ctx_p->drvdata, &desc[*seq_size]); in cc_setup_readiv_desc()
518 set_queue_last_ind(ctx_p->drvdata, &desc[*seq_size]); in cc_setup_readiv_desc()
532 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_setup_state_desc() local
533 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_setup_state_desc()
534 int cipher_mode = ctx_p->cipher_mode; in cc_setup_state_desc()
535 int flow_mode = ctx_p->flow_mode; in cc_setup_state_desc()
537 dma_addr_t key_dma_addr = ctx_p->user.key_dma_addr; in cc_setup_state_desc()
538 unsigned int key_len = ctx_p->keylen; in cc_setup_state_desc()
580 ctx_p->hw.key2_slot); in cc_setup_state_desc()
608 static int cc_out_flow_mode(struct cc_cipher_ctx *ctx_p) in cc_out_flow_mode() argument
610 switch (ctx_p->flow_mode) { in cc_out_flow_mode()
618 return ctx_p->flow_mode; in cc_out_flow_mode()
627 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_setup_key_desc() local
628 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_setup_key_desc()
629 int cipher_mode = ctx_p->cipher_mode; in cc_setup_key_desc()
630 int flow_mode = ctx_p->flow_mode; in cc_setup_key_desc()
632 dma_addr_t key_dma_addr = ctx_p->user.key_dma_addr; in cc_setup_key_desc()
633 unsigned int key_len = ctx_p->keylen; in cc_setup_key_desc()
650 set_cpp_crypto_key(&desc[*seq_size], ctx_p->cpp.slot); in cc_setup_key_desc()
651 flow_mode = cc_out_flow_mode(ctx_p); in cc_setup_key_desc()
656 ctx_p->hw.key1_slot); in cc_setup_key_desc()
690 ctx_p->hw.key1_slot); in cc_setup_key_desc()
711 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_setup_mlli_desc() local
712 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_setup_mlli_desc()
719 (unsigned int)ctx_p->drvdata->mlli_sram_addr); in cc_setup_mlli_desc()
725 ctx_p->drvdata->mlli_sram_addr, in cc_setup_mlli_desc()
738 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_setup_flow_desc() local
739 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_setup_flow_desc()
740 unsigned int flow_mode = cc_out_flow_mode(ctx_p); in cc_setup_flow_desc()
741 bool last_desc = (ctx_p->key_type == CC_POLICY_PROTECTED_KEY || in cc_setup_flow_desc()
742 ctx_p->cipher_mode == DRV_CIPHER_ECB); in cc_setup_flow_desc()
756 set_queue_last_ind(ctx_p->drvdata, &desc[*seq_size]); in cc_setup_flow_desc()
763 ctx_p->drvdata->mlli_sram_addr, in cc_setup_flow_desc()
767 (unsigned int)ctx_p->drvdata->mlli_sram_addr, in cc_setup_flow_desc()
768 (unsigned int)ctx_p->drvdata->mlli_sram_addr); in cc_setup_flow_desc()
770 ctx_p->drvdata->mlli_sram_addr, in cc_setup_flow_desc()
775 (unsigned int)ctx_p->drvdata->mlli_sram_addr, in cc_setup_flow_desc()
776 (unsigned int)ctx_p->drvdata->mlli_sram_addr + in cc_setup_flow_desc()
779 (ctx_p->drvdata->mlli_sram_addr + in cc_setup_flow_desc()
786 set_queue_last_ind(ctx_p->drvdata, &desc[*seq_size]); in cc_setup_flow_desc()
823 struct cc_cipher_ctx *ctx_p = crypto_tfm_ctx(tfm); in cc_cipher_process() local
824 struct device *dev = drvdata_to_dev(ctx_p->drvdata); in cc_cipher_process()
838 if (validate_data_size(ctx_p, nbytes)) { in cc_cipher_process()
864 if (ctx_p->key_type == CC_POLICY_PROTECTED_KEY) { in cc_cipher_process()
866 cc_req.cpp.alg = ctx_p->cpp.alg; in cc_cipher_process()
867 cc_req.cpp.slot = ctx_p->cpp.slot; in cc_cipher_process()
875 rc = cc_map_cipher_request(ctx_p->drvdata, req_ctx, ivsize, nbytes, in cc_cipher_process()
897 rc = cc_send_request(ctx_p->drvdata, &cc_req, desc, seq_len, in cc_cipher_process()