| 236 | }; |
| 237 | |
| 238 | static int |
| 239 | transform_cipher_param(struct rte_crypto_sym_xform *xform, |
| 240 | VhostUserCryptoSessionParam *param) |
| 241 | { |
| 242 | int ret; |
| 243 | |
| 244 | ret = cipher_algo_transform(param->cipher_algo, &xform->cipher.algo); |
| 245 | if (unlikely(ret < 0)) |
| 246 | return ret; |
| 247 | |
| 248 | if (param->cipher_key_len > VHOST_USER_CRYPTO_MAX_CIPHER_KEY_LENGTH) { |
| 249 | VC_LOG_DBG("Invalid cipher key length"); |
| 250 | return -VIRTIO_CRYPTO_BADMSG; |
| 251 | } |
| 252 | |
| 253 | xform->type = RTE_CRYPTO_SYM_XFORM_CIPHER; |
| 254 | xform->cipher.key.length = param->cipher_key_len; |
| 255 | if (xform->cipher.key.length > 0) |
| 256 | xform->cipher.key.data = param->cipher_key_buf; |
| 257 | if (param->dir == VIRTIO_CRYPTO_OP_ENCRYPT) |
| 258 | xform->cipher.op = RTE_CRYPTO_CIPHER_OP_ENCRYPT; |
| 259 | else if (param->dir == VIRTIO_CRYPTO_OP_DECRYPT) |
| 260 | xform->cipher.op = RTE_CRYPTO_CIPHER_OP_DECRYPT; |
| 261 | else { |
| 262 | VC_LOG_DBG("Bad operation type"); |
| 263 | return -VIRTIO_CRYPTO_BADMSG; |
| 264 | } |
| 265 | |
| 266 | ret = get_iv_len(xform->cipher.algo); |
| 267 | if (unlikely(ret < 0)) |
| 268 | return ret; |
| 269 | xform->cipher.iv.length = (uint16_t)ret; |
| 270 | xform->cipher.iv.offset = IV_OFFSET; |
| 271 | return 0; |
| 272 | } |
| 273 | |
| 274 | static int |
| 275 | transform_chain_param(struct rte_crypto_sym_xform *xforms, |
no test coverage detected