static int cryptodev_builtin_create_cipher_session(

                    CryptoDevBackendBuiltin *builtin,

                    CryptoDevBackendSymSessionInfo *sess_info,

                    Error **errp)

{

    int algo;

    int mode;

    QCryptoCipher *cipher;

    int index;

    CryptoDevBackendBuiltinSession *sess;



    if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) {

        error_setg(errp, "Unsupported optype :%u", sess_info->op_type);

        return -1;

    }



    index = cryptodev_builtin_get_unused_session_index(builtin);

    if (index < 0) {

        error_setg(errp, "Total number of sessions created exceeds %u",

                  MAX_NUM_SESSIONS);

        return -1;

    }



    switch (sess_info->cipher_alg) {

    case VIRTIO_CRYPTO_CIPHER_AES_ECB:

        algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,

                                                          errp);

        if (algo < 0)  {

            return -1;

        }

        mode = QCRYPTO_CIPHER_MODE_ECB;

        break;

    case VIRTIO_CRYPTO_CIPHER_AES_CBC:

        algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,

                                                          errp);

        if (algo < 0)  {

            return -1;

        }

        mode = QCRYPTO_CIPHER_MODE_CBC;

        break;

    case VIRTIO_CRYPTO_CIPHER_AES_CTR:

        algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,

                                                          errp);

        if (algo < 0)  {

            return -1;

        }

        mode = QCRYPTO_CIPHER_MODE_CTR;

        break;

    case VIRTIO_CRYPTO_CIPHER_DES_ECB:

        algo = QCRYPTO_CIPHER_ALG_DES_RFB;

        mode = QCRYPTO_CIPHER_MODE_ECB;

        break;

    default:

        error_setg(errp, "Unsupported cipher alg :%u",

                   sess_info->cipher_alg);

        return -1;

    }



    cipher = qcrypto_cipher_new(algo, mode,

                               sess_info->cipher_key,

                               sess_info->key_len,

                               errp);

    if (!cipher) {

        return -1;

    }



    sess = g_new0(CryptoDevBackendBuiltinSession, 1);

    sess->cipher = cipher;

    sess->direction = sess_info->direction;

    sess->type = sess_info->op_type;



    builtin->sessions[index] = sess;



    return index;

}

static int cryptodev_builtin_create_cipher_session(

                    CryptoDevBackendBuiltin *builtin,

                    CryptoDevBackendSymSessionInfo *sess_info,

                    Error **errp)

{

    int algo;

    int mode;

    QCryptoCipher *cipher;

    int index;

    CryptoDevBackendBuiltinSession *sess;



    if (sess_info->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) {

        error_setg(errp, "Unsupported optype :%u", sess_info->op_type);

        return -1;

    }



    index = cryptodev_builtin_get_unused_session_index(builtin);

    if (index < 0) {

        error_setg(errp, "Total number of sessions created exceeds %u",

                  MAX_NUM_SESSIONS);

        return -1;

    }



    switch (sess_info->cipher_alg) {

    case VIRTIO_CRYPTO_CIPHER_AES_ECB:

        algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,

                                                          errp);

        if (algo < 0)  {

            return -1;

        }

        mode = QCRYPTO_CIPHER_MODE_ECB;

        break;

    case VIRTIO_CRYPTO_CIPHER_AES_CBC:

        algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,

                                                          errp);

        if (algo < 0)  {

            return -1;

        }

        mode = QCRYPTO_CIPHER_MODE_CBC;

        break;

    case VIRTIO_CRYPTO_CIPHER_AES_CTR:

        algo = cryptodev_builtin_get_aes_algo(sess_info->key_len,

                                                          errp);

        if (algo < 0)  {

            return -1;

        }

        mode = QCRYPTO_CIPHER_MODE_CTR;

        break;

    case VIRTIO_CRYPTO_CIPHER_DES_ECB:

        algo = QCRYPTO_CIPHER_ALG_DES_RFB;

        mode = QCRYPTO_CIPHER_MODE_ECB;

        break;

    default:

        error_setg(errp, "Unsupported cipher alg :%u",

                   sess_info->cipher_alg);

        return -1;

    }



    cipher = qcrypto_cipher_new(algo, mode,

                               sess_info->cipher_key,

                               sess_info->key_len,

                               errp);

    if (!cipher) {

        return -1;

    }



    sess = g_new0(CryptoDevBackendBuiltinSession, 1);

    sess->cipher = cipher;

    sess->direction = sess_info->direction;

    sess->type = sess_info->op_type;



    builtin->sessions[index] = sess;



    return index;

}

static int FUNC_0(

                    CryptoDevBackendBuiltin *VAR_0,

                    CryptoDevBackendSymSessionInfo *VAR_1,

                    Error **VAR_2)

{

    int VAR_3;

    int VAR_4;

    QCryptoCipher *cipher;

    int VAR_5;

    CryptoDevBackendBuiltinSession *sess;



    if (VAR_1->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) {

        error_setg(VAR_2, "Unsupported optype :%u", VAR_1->op_type);

        return -1;

    }



    VAR_5 = cryptodev_builtin_get_unused_session_index(VAR_0);

    if (VAR_5 < 0) {

        error_setg(VAR_2, "Total number of sessions created exceeds %u",

                  MAX_NUM_SESSIONS);

        return -1;

    }



    switch (VAR_1->cipher_alg) {

    case VIRTIO_CRYPTO_CIPHER_AES_ECB:

        VAR_3 = cryptodev_builtin_get_aes_algo(VAR_1->key_len,

                                                          VAR_2);

        if (VAR_3 < 0)  {

            return -1;

        }

        VAR_4 = QCRYPTO_CIPHER_MODE_ECB;

        break;

    case VIRTIO_CRYPTO_CIPHER_AES_CBC:

        VAR_3 = cryptodev_builtin_get_aes_algo(VAR_1->key_len,

                                                          VAR_2);

        if (VAR_3 < 0)  {

            return -1;

        }

        VAR_4 = QCRYPTO_CIPHER_MODE_CBC;

        break;

    case VIRTIO_CRYPTO_CIPHER_AES_CTR:

        VAR_3 = cryptodev_builtin_get_aes_algo(VAR_1->key_len,

                                                          VAR_2);

        if (VAR_3 < 0)  {

            return -1;

        }

        VAR_4 = QCRYPTO_CIPHER_MODE_CTR;

        break;

    case VIRTIO_CRYPTO_CIPHER_DES_ECB:

        VAR_3 = QCRYPTO_CIPHER_ALG_DES_RFB;

        VAR_4 = QCRYPTO_CIPHER_MODE_ECB;

        break;

    default:

        error_setg(VAR_2, "Unsupported cipher alg :%u",

                   VAR_1->cipher_alg);

        return -1;

    }



    cipher = qcrypto_cipher_new(VAR_3, VAR_4,

                               VAR_1->cipher_key,

                               VAR_1->key_len,

                               VAR_2);

    if (!cipher) {

        return -1;

    }



    sess = g_new0(CryptoDevBackendBuiltinSession, 1);

    sess->cipher = cipher;

    sess->direction = VAR_1->direction;

    sess->type = VAR_1->op_type;



    VAR_0->sessions[VAR_5] = sess;



    return VAR_5;

}

static int FUNC_0(
CryptoDevBackendBuiltin *VAR_0,
CryptoDevBackendSymSessionInfo *VAR_1,
Error **VAR_2)
{ int VAR_3; int VAR_4; QCryptoCipher *cipher; int VAR_5; CryptoDevBackendBuiltinSession *sess; if (VAR_1->op_type != VIRTIO_CRYPTO_SYM_OP_CIPHER) { error_setg(VAR_2, "Unsupported optype :%u", VAR_1->op_type); return -1; } VAR_5 = cryptodev_builtin_get_unused_session_index(VAR_0); if (VAR_5 < 0) { error_setg(VAR_2, "Total number of sessions created exceeds %u",
MAX_NUM_SESSIONS); return -1; } switch (VAR_1->cipher_alg) { case VIRTIO_CRYPTO_CIPHER_AES_ECB:
VAR_3 = cryptodev_builtin_get_aes_algo(VAR_1->key_len,
VAR_2); if (VAR_3 < 0)  { return -1; } VAR_4 = QCRYPTO_CIPHER_MODE_ECB; break; case VIRTIO_CRYPTO_CIPHER_AES_CBC:
VAR_3 = cryptodev_builtin_get_aes_algo(VAR_1->key_len,
VAR_2); if (VAR_3 < 0)  { return -1; } VAR_4 = QCRYPTO_CIPHER_MODE_CBC; break; case VIRTIO_CRYPTO_CIPHER_AES_CTR:
VAR_3 = cryptodev_builtin_get_aes_algo(VAR_1->key_len,
VAR_2); if (VAR_3 < 0)  { return -1; } VAR_4 = QCRYPTO_CIPHER_MODE_CTR; break; case VIRTIO_CRYPTO_CIPHER_DES_ECB:
VAR_3 = QCRYPTO_CIPHER_ALG_DES_RFB; VAR_4 = QCRYPTO_CIPHER_MODE_ECB; break; default:
error_setg(VAR_2, "Unsupported cipher alg :%u",
VAR_1->cipher_alg); return -1; } cipher = qcrypto_cipher_new(VAR_3, VAR_4,
VAR_1->cipher_key,
VAR_1->key_len,
VAR_2); if (!cipher) { return -1; } sess = g_new0(CryptoDevBackendBuiltinSession, 1); sess->cipher = cipher; sess->direction = VAR_1->direction; sess->type = VAR_1->op_type; VAR_0->sessions[VAR_5] = sess; return VAR_5; }