Lines Matching +full:op +full:- +full:mode
4 * SPDX-License-Identifier: Apache-2.0
28 static int do_cbc_encrypt(struct cipher_ctx *ctx, struct cipher_pkt *op, in do_cbc_encrypt() argument
31 struct tc_shim_drv_state *data = ctx->drv_sessn_state; in do_cbc_encrypt()
33 if (tc_cbc_mode_encrypt(op->out_buf, in do_cbc_encrypt()
34 op->out_buf_max, in do_cbc_encrypt()
35 op->in_buf, op->in_len, in do_cbc_encrypt()
37 &data->session_key) == TC_CRYPTO_FAIL) { in do_cbc_encrypt()
39 return -EIO; in do_cbc_encrypt()
42 /* out_len is the same as in_len in CBC mode */ in do_cbc_encrypt()
43 op->out_len = op->in_len; in do_cbc_encrypt()
48 static int do_cbc_decrypt(struct cipher_ctx *ctx, struct cipher_pkt *op, in do_cbc_decrypt() argument
51 struct tc_shim_drv_state *data = ctx->drv_sessn_state; in do_cbc_decrypt()
56 if (iv != op->in_buf) { in do_cbc_decrypt()
58 return -EIO; in do_cbc_decrypt()
61 if (tc_cbc_mode_decrypt(op->out_buf, in do_cbc_decrypt()
62 op->out_buf_max, in do_cbc_decrypt()
63 op->in_buf + TC_AES_BLOCK_SIZE, in do_cbc_decrypt()
64 op->in_len - TC_AES_BLOCK_SIZE, in do_cbc_decrypt()
65 op->in_buf, &data->session_key) == TC_CRYPTO_FAIL) { in do_cbc_decrypt()
67 return -EIO; in do_cbc_decrypt()
70 /* out_len is the same as in_len in CBC mode */ in do_cbc_decrypt()
71 op->out_len = op->in_len; in do_cbc_decrypt()
76 static int do_ctr_op(struct cipher_ctx *ctx, struct cipher_pkt *op, in do_ctr_op() argument
79 struct tc_shim_drv_state *data = ctx->drv_sessn_state; in do_ctr_op()
80 uint8_t ctr[16] = {0}; /* CTR mode Counter = iv:ctr */ in do_ctr_op()
81 int ivlen = ctx->keylen - (ctx->mode_params.ctr_info.ctr_len >> 3); in do_ctr_op()
88 if (tc_ctr_mode(op->out_buf, op->out_buf_max, op->in_buf, in do_ctr_op()
89 op->in_len, ctr, in do_ctr_op()
90 &data->session_key) == TC_CRYPTO_FAIL) { in do_ctr_op()
91 LOG_ERR("TC internal error during CTR OP"); in do_ctr_op()
92 return -EIO; in do_ctr_op()
95 /* out_len is the same as in_len in CTR mode */ in do_ctr_op()
96 op->out_len = op->in_len; in do_ctr_op()
105 struct tc_shim_drv_state *data = ctx->drv_sessn_state; in do_ccm_encrypt_mac()
106 struct ccm_params *ccm_param = &ctx->mode_params.ccm_info; in do_ccm_encrypt_mac()
107 struct cipher_pkt *op = aead_op->pkt; in do_ccm_encrypt_mac() local
109 if (tc_ccm_config(&ccm, &data->session_key, nonce, in do_ccm_encrypt_mac()
110 ccm_param->nonce_len, in do_ccm_encrypt_mac()
111 ccm_param->tag_len) == TC_CRYPTO_FAIL) { in do_ccm_encrypt_mac()
113 return -EIO; in do_ccm_encrypt_mac()
116 if (tc_ccm_generation_encryption(op->out_buf, op->out_buf_max, in do_ccm_encrypt_mac()
117 aead_op->ad, aead_op->ad_len, op->in_buf, in do_ccm_encrypt_mac()
118 op->in_len, &ccm) == TC_CRYPTO_FAIL) { in do_ccm_encrypt_mac()
119 LOG_ERR("TC internal error during CCM Encryption OP"); in do_ccm_encrypt_mac()
120 return -EIO; in do_ccm_encrypt_mac()
128 if (aead_op->tag) { in do_ccm_encrypt_mac()
129 memcpy(aead_op->tag, op->out_buf + op->in_len, ccm.mlen); in do_ccm_encrypt_mac()
133 * will advance the output buffer pointer by op->in_len bytes, in do_ccm_encrypt_mac()
136 op->out_len = op->in_len + ccm.mlen; in do_ccm_encrypt_mac()
145 struct tc_shim_drv_state *data = ctx->drv_sessn_state; in do_ccm_decrypt_auth()
146 struct ccm_params *ccm_param = &ctx->mode_params.ccm_info; in do_ccm_decrypt_auth()
147 struct cipher_pkt *op = aead_op->pkt; in do_ccm_decrypt_auth() local
149 if (tc_ccm_config(&ccm, &data->session_key, nonce, in do_ccm_decrypt_auth()
150 ccm_param->nonce_len, in do_ccm_decrypt_auth()
151 ccm_param->tag_len) == TC_CRYPTO_FAIL) { in do_ccm_decrypt_auth()
153 return -EIO; in do_ccm_decrypt_auth()
160 if (aead_op->tag != op->in_buf + op->in_len) { in do_ccm_decrypt_auth()
162 return -EIO; in do_ccm_decrypt_auth()
165 if (tc_ccm_decryption_verification(op->out_buf, op->out_buf_max, in do_ccm_decrypt_auth()
166 aead_op->ad, aead_op->ad_len, in do_ccm_decrypt_auth()
167 op->in_buf, in do_ccm_decrypt_auth()
168 op->in_len + ccm_param->tag_len, in do_ccm_decrypt_auth()
170 LOG_ERR("TC internal error during CCM decryption OP"); in do_ccm_decrypt_auth()
171 return -EIO; in do_ccm_decrypt_auth()
174 op->out_len = op->in_len + ccm_param->tag_len; in do_ccm_decrypt_auth()
194 enum cipher_algo algo, enum cipher_mode mode, in tc_session_setup() argument
202 /* The shim currently supports only CBC or CTR mode for AES */ in tc_session_setup()
205 return -EINVAL; in tc_session_setup()
211 if (!(ctx->flags & CAP_SYNC_OPS)) { in tc_session_setup()
213 return -EINVAL; in tc_session_setup()
216 if (ctx->keylen != TC_AES_KEY_SIZE) { in tc_session_setup()
219 return -EINVAL; in tc_session_setup()
223 switch (mode) { in tc_session_setup()
225 ctx->ops.cbc_crypt_hndlr = do_cbc_encrypt; in tc_session_setup()
228 if (ctx->mode_params.ctr_info.ctr_len != 32U) { in tc_session_setup()
231 return -EINVAL; in tc_session_setup()
233 ctx->ops.ctr_crypt_hndlr = do_ctr_op; in tc_session_setup()
236 ctx->ops.ccm_crypt_hndlr = do_ccm_encrypt_mac; in tc_session_setup()
239 LOG_ERR("TC Shim Unsupported mode"); in tc_session_setup()
240 return -EINVAL; in tc_session_setup()
243 switch (mode) { in tc_session_setup()
245 ctx->ops.cbc_crypt_hndlr = do_cbc_decrypt; in tc_session_setup()
249 if (ctx->mode_params.ctr_info.ctr_len != 32U) { in tc_session_setup()
252 return -EINVAL; in tc_session_setup()
254 ctx->ops.ctr_crypt_hndlr = do_ctr_op; in tc_session_setup()
257 ctx->ops.ccm_crypt_hndlr = do_ccm_decrypt_auth; in tc_session_setup()
260 LOG_ERR("TC Shim Unsupported mode"); in tc_session_setup()
261 return -EINVAL; in tc_session_setup()
266 ctx->ops.cipher_mode = mode; in tc_session_setup()
271 return -ENOSPC; in tc_session_setup()
276 if (tc_aes128_set_encrypt_key(&data->session_key, ctx->key.bit_stream) in tc_session_setup()
281 return -EIO; in tc_session_setup()
284 ctx->drv_sessn_state = data; in tc_session_setup()
296 struct tc_shim_drv_state *data = sessn->drv_sessn_state; in tc_session_free()
300 data->in_use = 0; in tc_session_free()