| 3710 | } |
| 3711 | |
| 3712 | static struct rte_crypto_sym_xform * |
| 3713 | parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p, |
| 3714 | uint8_t *key, uint32_t max_key_len, char **tokens, |
| 3715 | uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens) |
| 3716 | { |
| 3717 | struct rte_crypto_sym_xform *xform_cipher; |
| 3718 | int status; |
| 3719 | size_t len; |
| 3720 | |
| 3721 | if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") || |
| 3722 | strcmp(tokens[3], "cipher_key") || |
| 3723 | strcmp(tokens[5], "cipher_iv")) |
| 3724 | return NULL; |
| 3725 | |
| 3726 | xform_cipher = calloc(1, sizeof(*xform_cipher)); |
| 3727 | if (xform_cipher == NULL) |
| 3728 | return NULL; |
| 3729 | |
| 3730 | xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER; |
| 3731 | xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT : |
| 3732 | RTE_CRYPTO_CIPHER_OP_DECRYPT; |
| 3733 | |
| 3734 | /* cipher_algo */ |
| 3735 | status = rte_cryptodev_get_cipher_algo_enum( |
| 3736 | &xform_cipher->cipher.algo, tokens[2]); |
| 3737 | if (status < 0) |
| 3738 | goto error_exit; |
| 3739 | |
| 3740 | /* cipher_key */ |
| 3741 | len = strlen(tokens[4]); |
| 3742 | if (len / 2 > max_key_len) { |
| 3743 | status = -ENOMEM; |
| 3744 | goto error_exit; |
| 3745 | } |
| 3746 | |
| 3747 | status = parse_hex_string(tokens[4], key, (uint32_t *)&len); |
| 3748 | if (status < 0) |
| 3749 | goto error_exit; |
| 3750 | |
| 3751 | xform_cipher->cipher.key.data = key; |
| 3752 | xform_cipher->cipher.key.length = (uint16_t)len; |
| 3753 | |
| 3754 | /* cipher_iv */ |
| 3755 | len = strlen(tokens[6]); |
| 3756 | |
| 3757 | p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1); |
| 3758 | if (p->cipher_auth.cipher_iv.val == NULL) |
| 3759 | goto error_exit; |
| 3760 | |
| 3761 | status = parse_hex_string(tokens[6], |
| 3762 | p->cipher_auth.cipher_iv.val, |
| 3763 | (uint32_t *)&len); |
| 3764 | if (status < 0) |
| 3765 | goto error_exit; |
| 3766 | |
| 3767 | xform_cipher->cipher.iv.length = (uint16_t)len; |
| 3768 | xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET; |
| 3769 | p->cipher_auth.cipher_iv.length = (uint32_t)len; |
no test coverage detected