cryptodev: fix session init return value

When calling rte_cryptodev_sym_session_init(),
if there was an error, it returned -1, instead
of returning the specific error code, which can
be valuable for the application for error handling.

Fixes: b3bbd9e5f2 ("cryptodev: support device independent sessions")

Signed-off-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Acked-by: Akhil Goyal <akhil.goyal@nxp.com>
Acked-by: Fiona Trahe <fiona.trahe@intel.com>
This commit is contained in:
Pablo de Lara 2017-07-25 07:16:50 +01:00
parent b5b047aa44
commit 27391b53b3
23 changed files with 222 additions and 161 deletions

View File

@ -63,7 +63,7 @@ aesni_gcm_set_session_parameters(const struct aesni_gcm_ops *gcm_ops,
if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_AES_GMAC) {
GCM_LOG_ERR("Only AES GMAC is supported as an "
"authentication only algorithm");
return -EINVAL;
return -ENOTSUP;
}
/* Set IV parameters */
sess->iv.offset = auth_xform->auth.iv.offset;
@ -86,7 +86,7 @@ aesni_gcm_set_session_parameters(const struct aesni_gcm_ops *gcm_ops,
if (aead_xform->aead.algo != RTE_CRYPTO_AEAD_AES_GCM) {
GCM_LOG_ERR("The only combined operation "
"supported is AES GCM");
return -EINVAL;
return -ENOTSUP;
}
/* Set IV parameters */
@ -106,7 +106,7 @@ aesni_gcm_set_session_parameters(const struct aesni_gcm_ops *gcm_ops,
digest_length = aead_xform->aead.digest_length;
} else {
GCM_LOG_ERR("Wrong xform type, has to be AEAD or authentication");
return -EINVAL;
return -ENOTSUP;
}
@ -129,7 +129,7 @@ aesni_gcm_set_session_parameters(const struct aesni_gcm_ops *gcm_ops,
sess->key = AESNI_GCM_KEY_256;
break;
default:
GCM_LOG_ERR("Unsupported key length");
GCM_LOG_ERR("Invalid key length");
return -EINVAL;
}

View File

@ -308,25 +308,27 @@ aesni_gcm_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
struct aesni_gcm_private *internals = dev->data->dev_private;
if (unlikely(sess == NULL)) {
GCM_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (aesni_gcm_set_session_parameters(gcm_ops[internals->vector_mode],
sess_private_data, xform) != 0) {
ret = aesni_gcm_set_session_parameters(gcm_ops[internals->vector_mode],
sess_private_data, xform);
if (ret != 0) {
GCM_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -169,7 +169,7 @@ aesni_mb_set_session_auth_parameters(const struct aesni_mb_op_fns *mb_ops,
break;
default:
MB_LOG_ERR("Unsupported authentication algorithm selection");
return -1;
return -ENOTSUP;
}
/* Calculate Authentication precomputes */
@ -197,7 +197,7 @@ aesni_mb_set_session_cipher_parameters(const struct aesni_mb_op_fns *mb_ops,
if (xform->type != RTE_CRYPTO_SYM_XFORM_CIPHER) {
MB_LOG_ERR("Crypto xform struct not of type cipher");
return -1;
return -EINVAL;
}
/* Select cipher direction */
@ -209,8 +209,8 @@ aesni_mb_set_session_cipher_parameters(const struct aesni_mb_op_fns *mb_ops,
sess->cipher.direction = DECRYPT;
break;
default:
MB_LOG_ERR("Unsupported cipher operation parameter");
return -1;
MB_LOG_ERR("Invalid cipher operation parameter");
return -EINVAL;
}
/* Select cipher mode */
@ -226,7 +226,7 @@ aesni_mb_set_session_cipher_parameters(const struct aesni_mb_op_fns *mb_ops,
break;
default:
MB_LOG_ERR("Unsupported cipher mode parameter");
return -1;
return -ENOTSUP;
}
/* Check key length and choose key expansion function */
@ -244,8 +244,8 @@ aesni_mb_set_session_cipher_parameters(const struct aesni_mb_op_fns *mb_ops,
aes_keyexp_fn = mb_ops->aux.keyexp.aes256;
break;
default:
MB_LOG_ERR("Unsupported cipher key length");
return -1;
MB_LOG_ERR("Invalid cipher key length");
return -EINVAL;
}
/* Set IV parameters */
@ -268,6 +268,7 @@ aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
{
const struct rte_crypto_sym_xform *auth_xform = NULL;
const struct rte_crypto_sym_xform *cipher_xform = NULL;
int ret;
/* Select Crypto operation - hash then cipher / cipher then hash */
switch (aesni_mb_get_chain_order(xform)) {
@ -303,22 +304,25 @@ aesni_mb_set_session_parameters(const struct aesni_mb_op_fns *mb_ops,
case AESNI_MB_OP_NOT_SUPPORTED:
default:
MB_LOG_ERR("Unsupported operation chain order parameter");
return -1;
return -ENOTSUP;
}
/* Default IV length = 0 */
sess->iv.length = 0;
if (aesni_mb_set_session_auth_parameters(mb_ops, sess, auth_xform)) {
ret = aesni_mb_set_session_auth_parameters(mb_ops, sess, auth_xform);
if (ret != 0) {
MB_LOG_ERR("Invalid/unsupported authentication parameters");
return -1;
return ret;
}
if (aesni_mb_set_session_cipher_parameters(mb_ops, sess,
cipher_xform)) {
ret = aesni_mb_set_session_cipher_parameters(mb_ops, sess,
cipher_xform);
if (ret != 0) {
MB_LOG_ERR("Invalid/unsupported cipher parameters");
return -1;
return ret;
}
return 0;
}

View File

@ -480,25 +480,27 @@ aesni_mb_pmd_session_configure(struct rte_cryptodev *dev,
{
void *sess_private_data;
struct aesni_mb_private *internals = dev->data->dev_private;
int ret;
if (unlikely(sess == NULL)) {
MB_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (aesni_mb_set_session_parameters(&job_ops[internals->vector_mode],
sess_private_data, xform) != 0) {
ret = aesni_mb_set_session_parameters(&job_ops[internals->vector_mode],
sess_private_data, xform);
if (ret != 0) {
MB_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -417,7 +417,7 @@ armv8_crypto_set_session_chained_parameters(struct armv8_crypto_session *sess,
order = sess->chain_order;
break;
default:
return -EINVAL;
return -ENOTSUP;
}
/* Select cipher direction */
sess->cipher.direction = cipher_xform->cipher.op;
@ -437,7 +437,7 @@ armv8_crypto_set_session_chained_parameters(struct armv8_crypto_session *sess,
sess->cipher.iv.length = 16;
break;
default:
return -EINVAL;
return -ENOTSUP;
}
/* Select auth generate/verify */
sess->auth.operation = auth_xform->auth.op;
@ -451,7 +451,7 @@ armv8_crypto_set_session_chained_parameters(struct armv8_crypto_session *sess,
sess->auth.mode = ARMV8_CRYPTO_AUTH_AS_HMAC;
break;
default:
return -EINVAL;
return -ENOTSUP;
}
/* Set the digest length */
@ -471,7 +471,7 @@ armv8_crypto_set_session_chained_parameters(struct armv8_crypto_session *sess,
default: /* Fall through */
sess->crypto_func = NULL;
sess->cipher.key_sched = NULL;
return -EINVAL;
return -ENOTSUP;
}
if (unlikely(sess->crypto_func == NULL)) {
@ -525,7 +525,7 @@ armv8_crypto_set_session_parameters(struct armv8_crypto_session *sess,
break;
default:
is_chained_op = false;
return -EINVAL;
return -ENOTSUP;
}
/* Set IV offset */
@ -537,11 +537,11 @@ armv8_crypto_set_session_parameters(struct armv8_crypto_session *sess,
if (unlikely(ret != 0)) {
ARMV8_CRYPTO_LOG_ERR(
"Invalid/unsupported chained (cipher/auth) parameters");
return -EINVAL;
return ret;
}
} else {
ARMV8_CRYPTO_LOG_ERR("Invalid/unsupported operation");
return -EINVAL;
return -ENOTSUP;
}
return 0;

View File

@ -323,24 +323,26 @@ armv8_crypto_pmd_session_configure(struct rte_cryptodev *dev,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (unlikely(sess == NULL)) {
ARMV8_CRYPTO_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (armv8_crypto_set_session_parameters(sess_private_data, xform) != 0) {
ret = armv8_crypto_set_session_parameters(sess_private_data, xform);
if (ret != 0) {
ARMV8_CRYPTO_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -1540,7 +1540,7 @@ dpaa2_sec_set_session_parameters(struct rte_cryptodev *dev,
} else {
RTE_LOG(ERR, PMD, "Invalid crypto type\n");
return -1;
return -EINVAL;
}
return 0;
@ -1553,20 +1553,22 @@ dpaa2_sec_session_configure(struct rte_cryptodev *dev,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (dpaa2_sec_set_session_parameters(dev, xform, sess_private_data) != 0) {
ret = dpaa2_sec_set_session_parameters(dev, xform, sess_private_data);
if (ret != 0) {
PMD_DRV_LOG(ERR, "DPAA2 PMD: failed to configure "
"session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -111,13 +111,13 @@ kasumi_set_session_parameters(struct kasumi_session *sess,
case KASUMI_OP_NOT_SUPPORTED:
default:
KASUMI_LOG_ERR("Unsupported operation chain order parameter");
return -EINVAL;
return -ENOTSUP;
}
if (cipher_xform) {
/* Only KASUMI F8 supported */
if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_KASUMI_F8)
return -EINVAL;
return -ENOTSUP;
sess->cipher_iv_offset = cipher_xform->cipher.iv.offset;
if (cipher_xform->cipher.iv.length != KASUMI_IV_LENGTH) {
@ -133,7 +133,7 @@ kasumi_set_session_parameters(struct kasumi_session *sess,
if (auth_xform) {
/* Only KASUMI F9 supported */
if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_KASUMI_F9)
return -EINVAL;
return -ENOTSUP;
if (auth_xform->auth.digest_length != KASUMI_DIGEST_LENGTH) {
KASUMI_LOG_ERR("Wrong digest length");

View File

@ -294,24 +294,26 @@ kasumi_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (unlikely(sess == NULL)) {
KASUMI_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (kasumi_set_session_parameters(sess_private_data, xform) != 0) {
ret = kasumi_set_session_parameters(sess_private_data, xform);
if (ret != 0) {
KASUMI_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -48,7 +48,7 @@ null_crypto_set_session_parameters(
const struct rte_crypto_sym_xform *xform)
{
if (xform == NULL) {
return -1;
return -EINVAL;
} else if (xform->type == RTE_CRYPTO_SYM_XFORM_AUTH &&
xform->next == NULL) {
/* Authentication Only */
@ -73,7 +73,7 @@ null_crypto_set_session_parameters(
return 0;
}
return -1;
return -ENOTSUP;
}
/** Process crypto operation for mbuf */

View File

@ -305,24 +305,26 @@ null_crypto_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
struct rte_mempool *mp)
{
void *sess_private_data;
int ret;
if (unlikely(sess == NULL)) {
NULL_CRYPTO_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mp, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (null_crypto_set_session_parameters(sess_private_data, xform) != 0) {
ret = null_crypto_set_session_parameters(sess_private_data, xform);
if (ret != 0) {
NULL_CRYPTO_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mp, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -336,7 +336,7 @@ openssl_set_session_cipher_parameters(struct openssl_session *sess,
break;
default:
sess->cipher.algo = RTE_CRYPTO_CIPHER_NULL;
return -EINVAL;
return -ENOTSUP;
}
return 0;
@ -412,7 +412,7 @@ openssl_set_session_auth_parameters(struct openssl_session *sess,
break;
default:
return -EINVAL;
return -ENOTSUP;
}
sess->auth.digest_length = xform->auth.digest_length;
@ -455,7 +455,7 @@ openssl_set_session_aead_parameters(struct openssl_session *sess,
sess->chain_order = OPENSSL_CHAIN_COMBINED;
break;
default:
return -EINVAL;
return -ENOTSUP;
}
sess->auth.aad_length = xform->aead.aad_length;
@ -472,6 +472,7 @@ openssl_set_session_parameters(struct openssl_session *sess,
const struct rte_crypto_sym_xform *cipher_xform = NULL;
const struct rte_crypto_sym_xform *auth_xform = NULL;
const struct rte_crypto_sym_xform *aead_xform = NULL;
int ret;
sess->chain_order = openssl_get_chain_order(xform);
switch (sess->chain_order) {
@ -501,27 +502,30 @@ openssl_set_session_parameters(struct openssl_session *sess,
/* cipher_xform must be check before auth_xform */
if (cipher_xform) {
if (openssl_set_session_cipher_parameters(
sess, cipher_xform)) {
ret = openssl_set_session_cipher_parameters(
sess, cipher_xform);
if (ret != 0) {
OPENSSL_LOG_ERR(
"Invalid/unsupported cipher parameters");
return -EINVAL;
return ret;
}
}
if (auth_xform) {
if (openssl_set_session_auth_parameters(sess, auth_xform)) {
ret = openssl_set_session_auth_parameters(sess, auth_xform);
if (ret != 0) {
OPENSSL_LOG_ERR(
"Invalid/unsupported auth parameters");
return -EINVAL;
return ret;
}
}
if (aead_xform) {
if (openssl_set_session_aead_parameters(sess, aead_xform)) {
ret = openssl_set_session_aead_parameters(sess, aead_xform);
if (ret != 0) {
OPENSSL_LOG_ERR(
"Invalid/unsupported AEAD parameters");
return -EINVAL;
return ret;
}
}

View File

@ -663,25 +663,26 @@ openssl_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (unlikely(sess == NULL)) {
OPENSSL_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (openssl_set_session_parameters(
sess_private_data, xform) != 0) {
ret = openssl_set_session_parameters(sess_private_data, xform);
if (ret != 0) {
OPENSSL_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -171,16 +171,19 @@ bpi_cipher_decrypt(uint8_t *src, uint8_t *dst,
/** Creates a context in either AES or DES in ECB mode
* Depends on openssl libcrypto
*/
static void *
static int
bpi_cipher_ctx_init(enum rte_crypto_cipher_algorithm cryptodev_algo,
enum rte_crypto_cipher_operation direction __rte_unused,
uint8_t *key)
uint8_t *key, void **ctx)
{
const EVP_CIPHER *algo = NULL;
EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
int ret;
*ctx = EVP_CIPHER_CTX_new();
if (ctx == NULL)
if (*ctx == NULL) {
ret = -ENOMEM;
goto ctx_init_err;
}
if (cryptodev_algo == RTE_CRYPTO_CIPHER_DES_DOCSISBPI)
algo = EVP_des_ecb();
@ -188,15 +191,17 @@ bpi_cipher_ctx_init(enum rte_crypto_cipher_algorithm cryptodev_algo,
algo = EVP_aes_128_ecb();
/* IV will be ECB encrypted whether direction is encrypt or decrypt*/
if (EVP_EncryptInit_ex(ctx, algo, NULL, key, 0) != 1)
if (EVP_EncryptInit_ex(*ctx, algo, NULL, key, 0) != 1) {
ret = -EINVAL;
goto ctx_init_err;
}
return ctx;
return 0;
ctx_init_err:
if (ctx != NULL)
EVP_CIPHER_CTX_free(ctx);
return NULL;
if (*ctx != NULL)
EVP_CIPHER_CTX_free(*ctx);
return ret;
}
/** Frees a context previously created
@ -303,6 +308,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
{
struct qat_pmd_private *internals = dev->data->dev_private;
struct rte_crypto_cipher_xform *cipher_xform = NULL;
int ret;
/* Get cipher xform from crypto xform chain */
cipher_xform = qat_get_cipher_xform(xform);
@ -315,6 +321,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_aes_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
@ -323,6 +330,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_aes_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid AES cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
@ -331,6 +339,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_snow3g_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid SNOW 3G cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_ECB_MODE;
@ -342,6 +351,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_kasumi_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid KASUMI cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_F8_MODE;
@ -350,6 +360,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_3des_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid 3DES cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
@ -358,6 +369,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_des_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid DES cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
@ -366,38 +378,43 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_validate_3des_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid 3DES cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
break;
case RTE_CRYPTO_CIPHER_DES_DOCSISBPI:
session->bpi_ctx = bpi_cipher_ctx_init(
ret = bpi_cipher_ctx_init(
cipher_xform->algo,
cipher_xform->op,
cipher_xform->key.data);
if (session->bpi_ctx == NULL) {
cipher_xform->key.data,
&session->bpi_ctx);
if (ret != 0) {
PMD_DRV_LOG(ERR, "failed to create DES BPI ctx");
goto error_out;
}
if (qat_alg_validate_des_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid DES cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
break;
case RTE_CRYPTO_CIPHER_AES_DOCSISBPI:
session->bpi_ctx = bpi_cipher_ctx_init(
ret = bpi_cipher_ctx_init(
cipher_xform->algo,
cipher_xform->op,
cipher_xform->key.data);
if (session->bpi_ctx == NULL) {
cipher_xform->key.data,
&session->bpi_ctx);
if (ret != 0) {
PMD_DRV_LOG(ERR, "failed to create AES BPI ctx");
goto error_out;
}
if (qat_alg_validate_aes_docsisbpi_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid AES DOCSISBPI key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CBC_MODE;
@ -408,11 +425,13 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
PMD_DRV_LOG(ERR, "%s not supported on this device",
rte_crypto_cipher_algorithm_strings
[cipher_xform->algo]);
ret = -ENOTSUP;
goto error_out;
}
if (qat_alg_validate_zuc_key(cipher_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid ZUC cipher key size");
ret = -EINVAL;
goto error_out;
}
session->qat_mode = ICP_QAT_HW_CIPHER_ECB_MODE;
@ -424,10 +443,12 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
case RTE_CRYPTO_CIPHER_ARC4:
PMD_DRV_LOG(ERR, "Crypto QAT PMD: Unsupported Cipher alg %u",
cipher_xform->algo);
ret = -ENOTSUP;
goto error_out;
default:
PMD_DRV_LOG(ERR, "Crypto: Undefined Cipher specified %u\n",
cipher_xform->algo);
ret = -EINVAL;
goto error_out;
}
@ -438,8 +459,10 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
if (qat_alg_aead_session_create_content_desc_cipher(session,
cipher_xform->key.data,
cipher_xform->key.length))
cipher_xform->key.length)) {
ret = -EINVAL;
goto error_out;
}
return 0;
@ -448,7 +471,7 @@ qat_crypto_sym_configure_session_cipher(struct rte_cryptodev *dev,
bpi_cipher_ctx_free(session->bpi_ctx);
session->bpi_ctx = NULL;
}
return -1;
return ret;
}
int
@ -458,20 +481,22 @@ qat_crypto_sym_configure_session(struct rte_cryptodev *dev,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (qat_crypto_set_session_parameters(dev, xform, sess_private_data) != 0) {
ret = qat_crypto_set_session_parameters(dev, xform, sess_private_data);
if (ret != 0) {
PMD_DRV_LOG(ERR, "Crypto QAT PMD: failed to configure "
"session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,
@ -485,6 +510,7 @@ qat_crypto_set_session_parameters(struct rte_cryptodev *dev,
struct rte_crypto_sym_xform *xform, void *session_private)
{
struct qat_session *session = session_private;
int ret;
int qat_cmd_id;
PMD_INIT_FUNC_TRACE();
@ -499,44 +525,52 @@ qat_crypto_set_session_parameters(struct rte_cryptodev *dev,
qat_cmd_id = qat_get_cmd_id(xform);
if (qat_cmd_id < 0 || qat_cmd_id >= ICP_QAT_FW_LA_CMD_DELIMITER) {
PMD_DRV_LOG(ERR, "Unsupported xform chain requested");
return -1;
return -ENOTSUP;
}
session->qat_cmd = (enum icp_qat_fw_la_cmd_id)qat_cmd_id;
switch (session->qat_cmd) {
case ICP_QAT_FW_LA_CMD_CIPHER:
if (qat_crypto_sym_configure_session_cipher(dev, xform, session) < 0)
return -1;
ret = qat_crypto_sym_configure_session_cipher(dev, xform, session);
if (ret < 0)
return ret;
break;
case ICP_QAT_FW_LA_CMD_AUTH:
if (qat_crypto_sym_configure_session_auth(dev, xform, session) < 0)
return -1;
ret = qat_crypto_sym_configure_session_auth(dev, xform, session);
if (ret < 0)
return ret;
break;
case ICP_QAT_FW_LA_CMD_CIPHER_HASH:
if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
if (qat_crypto_sym_configure_session_aead(xform,
session) < 0)
return -1;
ret = qat_crypto_sym_configure_session_aead(xform,
session);
if (ret < 0)
return ret;
} else {
if (qat_crypto_sym_configure_session_cipher(dev,
xform, session) < 0)
return -1;
if (qat_crypto_sym_configure_session_auth(dev,
xform, session) < 0)
return -1;
ret = qat_crypto_sym_configure_session_cipher(dev,
xform, session);
if (ret < 0)
return ret;
ret = qat_crypto_sym_configure_session_auth(dev,
xform, session);
if (ret < 0)
return ret;
}
break;
case ICP_QAT_FW_LA_CMD_HASH_CIPHER:
if (xform->type == RTE_CRYPTO_SYM_XFORM_AEAD) {
if (qat_crypto_sym_configure_session_aead(xform,
session) < 0)
return -1;
ret = qat_crypto_sym_configure_session_aead(xform,
session);
if (ret < 0)
return ret;
} else {
if (qat_crypto_sym_configure_session_auth(dev,
xform, session) < 0)
return -1;
if (qat_crypto_sym_configure_session_cipher(dev,
xform, session) < 0)
return -1;
ret = qat_crypto_sym_configure_session_auth(dev,
xform, session);
if (ret < 0)
return ret;
ret = qat_crypto_sym_configure_session_cipher(dev,
xform, session);
if (ret < 0)
return ret;
}
break;
case ICP_QAT_FW_LA_CMD_TRNG_GET_RANDOM:
@ -550,11 +584,11 @@ qat_crypto_set_session_parameters(struct rte_cryptodev *dev,
case ICP_QAT_FW_LA_CMD_DELIMITER:
PMD_DRV_LOG(ERR, "Unsupported Service %u",
session->qat_cmd);
return -1;
return -ENOTSUP;
default:
PMD_DRV_LOG(ERR, "Unsupported Service %u",
session->qat_cmd);
return -1;
return -ENOTSUP;
}
return 0;
@ -594,7 +628,7 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
if (qat_alg_validate_aes_key(auth_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid AES key size");
goto error_out;
return -EINVAL;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_GALOIS_128;
@ -617,7 +651,7 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
PMD_DRV_LOG(ERR, "%s not supported on this device",
rte_crypto_auth_algorithm_strings
[auth_xform->algo]);
goto error_out;
return -ENOTSUP;
}
session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_ZUC_3G_128_EIA3;
break;
@ -631,11 +665,11 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
case RTE_CRYPTO_AUTH_AES_CBC_MAC:
PMD_DRV_LOG(ERR, "Crypto: Unsupported hash alg %u",
auth_xform->algo);
goto error_out;
return -ENOTSUP;
default:
PMD_DRV_LOG(ERR, "Crypto: Undefined Hash algo %u specified",
auth_xform->algo);
goto error_out;
return -EINVAL;
}
session->auth_iv.offset = auth_xform->iv.offset;
@ -652,7 +686,7 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
if (qat_alg_aead_session_create_content_desc_cipher(session,
auth_xform->key.data,
auth_xform->key.length))
goto error_out;
return -EINVAL;
if (qat_alg_aead_session_create_content_desc_auth(session,
key_data,
@ -660,7 +694,7 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
0,
auth_xform->digest_length,
auth_xform->op))
goto error_out;
return -EINVAL;
} else {
session->qat_cmd = ICP_QAT_FW_LA_CMD_HASH_CIPHER;
session->qat_dir = ICP_QAT_HW_CIPHER_DECRYPT;
@ -674,12 +708,12 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
0,
auth_xform->digest_length,
auth_xform->op))
goto error_out;
return -EINVAL;
if (qat_alg_aead_session_create_content_desc_cipher(session,
auth_xform->key.data,
auth_xform->key.length))
goto error_out;
return -EINVAL;
}
/* Restore to authentication only only */
session->qat_cmd = ICP_QAT_FW_LA_CMD_AUTH;
@ -690,14 +724,11 @@ qat_crypto_sym_configure_session_auth(struct rte_cryptodev *dev,
0,
auth_xform->digest_length,
auth_xform->op))
goto error_out;
return -EINVAL;
}
session->digest_length = auth_xform->digest_length;
return 0;
error_out:
return -1;
}
int
@ -718,7 +749,7 @@ qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
if (qat_alg_validate_aes_key(aead_xform->key.length,
&session->qat_cipher_alg) != 0) {
PMD_DRV_LOG(ERR, "Invalid AES key size");
goto error_out;
return -EINVAL;
}
session->qat_mode = ICP_QAT_HW_CIPHER_CTR_MODE;
session->qat_hash_alg = ICP_QAT_HW_AUTH_ALGO_GALOIS_128;
@ -726,11 +757,11 @@ qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
case RTE_CRYPTO_AEAD_AES_CCM:
PMD_DRV_LOG(ERR, "Crypto QAT PMD: Unsupported AEAD alg %u",
aead_xform->algo);
goto error_out;
return -ENOTSUP;
default:
PMD_DRV_LOG(ERR, "Crypto: Undefined AEAD specified %u\n",
aead_xform->algo);
goto error_out;
return -EINVAL;
}
if (aead_xform->op == RTE_CRYPTO_AEAD_OP_ENCRYPT) {
@ -742,7 +773,7 @@ qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
if (qat_alg_aead_session_create_content_desc_cipher(session,
aead_xform->key.data,
aead_xform->key.length))
goto error_out;
return -EINVAL;
if (qat_alg_aead_session_create_content_desc_auth(session,
aead_xform->key.data,
@ -750,7 +781,7 @@ qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
aead_xform->aad_length,
aead_xform->digest_length,
RTE_CRYPTO_AUTH_OP_GENERATE))
goto error_out;
return -EINVAL;
} else {
session->qat_dir = ICP_QAT_HW_CIPHER_DECRYPT;
/*
@ -763,19 +794,16 @@ qat_crypto_sym_configure_session_aead(struct rte_crypto_sym_xform *xform,
aead_xform->aad_length,
aead_xform->digest_length,
RTE_CRYPTO_AUTH_OP_VERIFY))
goto error_out;
return -EINVAL;
if (qat_alg_aead_session_create_content_desc_cipher(session,
aead_xform->key.data,
aead_xform->key.length))
goto error_out;
return -EINVAL;
}
session->digest_length = aead_xform->digest_length;
return 0;
error_out:
return -1;
}
unsigned qat_crypto_sym_get_session_private_size(

View File

@ -515,14 +515,16 @@ scheduler_pmd_session_configure(struct rte_cryptodev *dev,
{
struct scheduler_ctx *sched_ctx = dev->data->dev_private;
uint32_t i;
int ret;
for (i = 0; i < sched_ctx->nb_slaves; i++) {
struct scheduler_slave *slave = &sched_ctx->slaves[i];
if (rte_cryptodev_sym_session_init(slave->dev_id, sess,
xform, mempool) < 0) {
ret = rte_cryptodev_sym_session_init(slave->dev_id, sess,
xform, mempool);
if (ret < 0) {
CS_LOG_ERR("unabled to config sym session");
return -1;
return ret;
}
}

View File

@ -111,13 +111,13 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
case SNOW3G_OP_NOT_SUPPORTED:
default:
SNOW3G_LOG_ERR("Unsupported operation chain order parameter");
return -EINVAL;
return -ENOTSUP;
}
if (cipher_xform) {
/* Only SNOW 3G UEA2 supported */
if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_SNOW3G_UEA2)
return -EINVAL;
return -ENOTSUP;
if (cipher_xform->cipher.iv.length != SNOW3G_IV_LENGTH) {
SNOW3G_LOG_ERR("Wrong IV length");
@ -133,7 +133,7 @@ snow3g_set_session_parameters(struct snow3g_session *sess,
if (auth_xform) {
/* Only SNOW 3G UIA2 supported */
if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_SNOW3G_UIA2)
return -EINVAL;
return -ENOTSUP;
if (auth_xform->auth.digest_length != SNOW3G_DIGEST_LENGTH) {
SNOW3G_LOG_ERR("Wrong digest length");

View File

@ -296,24 +296,26 @@ snow3g_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (unlikely(sess == NULL)) {
SNOW3G_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (snow3g_set_session_parameters(sess_private_data, xform) != 0) {
ret = snow3g_set_session_parameters(sess_private_data, xform);
if (ret != 0) {
SNOW3G_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -110,13 +110,13 @@ zuc_set_session_parameters(struct zuc_session *sess,
case ZUC_OP_NOT_SUPPORTED:
default:
ZUC_LOG_ERR("Unsupported operation chain order parameter");
return -EINVAL;
return -ENOTSUP;
}
if (cipher_xform) {
/* Only ZUC EEA3 supported */
if (cipher_xform->cipher.algo != RTE_CRYPTO_CIPHER_ZUC_EEA3)
return -EINVAL;
return -ENOTSUP;
if (cipher_xform->cipher.iv.length != ZUC_IV_KEY_LENGTH) {
ZUC_LOG_ERR("Wrong IV length");
@ -132,7 +132,7 @@ zuc_set_session_parameters(struct zuc_session *sess,
if (auth_xform) {
/* Only ZUC EIA3 supported */
if (auth_xform->auth.algo != RTE_CRYPTO_AUTH_ZUC_EIA3)
return -EINVAL;
return -ENOTSUP;
if (auth_xform->auth.digest_length != ZUC_DIGEST_LENGTH) {
ZUC_LOG_ERR("Wrong digest length");

View File

@ -296,24 +296,26 @@ zuc_pmd_session_configure(struct rte_cryptodev *dev __rte_unused,
struct rte_mempool *mempool)
{
void *sess_private_data;
int ret;
if (unlikely(sess == NULL)) {
ZUC_LOG_ERR("invalid session struct");
return -1;
return -EINVAL;
}
if (rte_mempool_get(mempool, &sess_private_data)) {
CDEV_LOG_ERR(
"Couldn't get object from session mempool");
return -1;
return -ENOMEM;
}
if (zuc_set_session_parameters(sess_private_data, xform) != 0) {
ret = zuc_set_session_parameters(sess_private_data, xform);
if (ret != 0) {
ZUC_LOG_ERR("failed configure session parameters");
/* Return session to mempool */
rte_mempool_put(mempool, sess_private_data);
return -1;
return ret;
}
set_session_private_data(sess, dev->driver_id,

View File

@ -1085,20 +1085,22 @@ rte_cryptodev_sym_session_init(uint8_t dev_id,
{
struct rte_cryptodev *dev;
uint8_t index;
int ret;
dev = rte_cryptodev_pmd_get_dev(dev_id);
if (sess == NULL || xforms == NULL || dev == NULL)
return -1;
return -EINVAL;
index = dev->driver_id;
if (sess->sess_private_data[index] == NULL) {
if (dev->dev_ops->session_configure(dev, xforms, sess, mp) < 0) {
ret = dev->dev_ops->session_configure(dev, xforms, sess, mp);
if (ret < 0) {
CDEV_LOG_ERR(
"dev_id %d failed to configure session details",
dev_id);
return -1;
return ret;
}
}

View File

@ -924,7 +924,9 @@ rte_cryptodev_sym_session_free(struct rte_cryptodev_sym_session *sess);
*
* @return
* - On success, zero.
* - On failure, a negative value.
* - -EINVAL if input parameters are invalid.
* - -ENOTSUP if crypto device does not support the crypto transform.
* - -ENOMEM if the private session could not be allocated.
*/
int
rte_cryptodev_sym_session_init(uint8_t dev_id,

View File

@ -276,7 +276,9 @@ typedef unsigned (*cryptodev_sym_get_session_private_size_t)(
*
* @return
* - Returns 0 if private session structure have been created successfully.
* - Returns -1 on failure.
* - Returns -EINVAL if input parameters are invalid.
* - Returns -ENOTSUP if crypto device does not support the crypto transform.
* - Returns -ENOMEM if the private session could not be allocated.
*/
typedef int (*cryptodev_sym_configure_session_t)(struct rte_cryptodev *dev,
struct rte_crypto_sym_xform *xform,

View File

@ -6415,7 +6415,7 @@ test_null_invalid_operation(void)
ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess, &ut_params->cipher_xform,
ts_params->session_mpool);
TEST_ASSERT(ret == -1,
TEST_ASSERT(ret < 0,
"Session creation succeeded unexpectedly");
@ -6433,7 +6433,7 @@ test_null_invalid_operation(void)
ret = rte_cryptodev_sym_session_init(ts_params->valid_devs[0],
ut_params->sess, &ut_params->auth_xform,
ts_params->session_mpool);
TEST_ASSERT(ret == -1,
TEST_ASSERT(ret < 0,
"Session creation succeeded unexpectedly");
return TEST_SUCCESS;