|
@@ -107,6 +107,9 @@ void cryptodev_backend_cleanup(
|
|
|
if (bc->cleanup) {
|
|
|
bc->cleanup(backend, errp);
|
|
|
}
|
|
|
+
|
|
|
+ g_free(backend->sym_stat);
|
|
|
+ g_free(backend->asym_stat);
|
|
|
}
|
|
|
|
|
|
int cryptodev_backend_create_session(
|
|
@@ -154,16 +157,61 @@ static int cryptodev_backend_operation(
|
|
|
return -VIRTIO_CRYPTO_NOTSUPP;
|
|
|
}
|
|
|
|
|
|
+static int cryptodev_backend_account(CryptoDevBackend *backend,
|
|
|
+ CryptoDevBackendOpInfo *op_info)
|
|
|
+{
|
|
|
+ enum QCryptodevBackendAlgType algtype = op_info->algtype;
|
|
|
+ int len;
|
|
|
+
|
|
|
+ if (algtype == QCRYPTODEV_BACKEND_ALG_ASYM) {
|
|
|
+ CryptoDevBackendAsymOpInfo *asym_op_info = op_info->u.asym_op_info;
|
|
|
+ len = asym_op_info->src_len;
|
|
|
+ switch (op_info->op_code) {
|
|
|
+ case VIRTIO_CRYPTO_AKCIPHER_ENCRYPT:
|
|
|
+ CryptodevAsymStatIncEncrypt(backend, len);
|
|
|
+ break;
|
|
|
+ case VIRTIO_CRYPTO_AKCIPHER_DECRYPT:
|
|
|
+ CryptodevAsymStatIncDecrypt(backend, len);
|
|
|
+ break;
|
|
|
+ case VIRTIO_CRYPTO_AKCIPHER_SIGN:
|
|
|
+ CryptodevAsymStatIncSign(backend, len);
|
|
|
+ break;
|
|
|
+ case VIRTIO_CRYPTO_AKCIPHER_VERIFY:
|
|
|
+ CryptodevAsymStatIncVerify(backend, len);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return -VIRTIO_CRYPTO_NOTSUPP;
|
|
|
+ }
|
|
|
+ } else if (algtype == QCRYPTODEV_BACKEND_ALG_SYM) {
|
|
|
+ CryptoDevBackendSymOpInfo *sym_op_info = op_info->u.sym_op_info;
|
|
|
+ len = sym_op_info->src_len;
|
|
|
+ switch (op_info->op_code) {
|
|
|
+ case VIRTIO_CRYPTO_CIPHER_ENCRYPT:
|
|
|
+ CryptodevSymStatIncEncrypt(backend, len);
|
|
|
+ break;
|
|
|
+ case VIRTIO_CRYPTO_CIPHER_DECRYPT:
|
|
|
+ CryptodevSymStatIncDecrypt(backend, len);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ return -VIRTIO_CRYPTO_NOTSUPP;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype);
|
|
|
+ return -VIRTIO_CRYPTO_NOTSUPP;
|
|
|
+ }
|
|
|
+
|
|
|
+ return len;
|
|
|
+}
|
|
|
+
|
|
|
int cryptodev_backend_crypto_operation(
|
|
|
CryptoDevBackend *backend,
|
|
|
CryptoDevBackendOpInfo *op_info)
|
|
|
{
|
|
|
- QCryptodevBackendAlgType algtype = op_info->algtype;
|
|
|
+ int ret;
|
|
|
|
|
|
- if ((algtype != QCRYPTODEV_BACKEND_ALG_SYM)
|
|
|
- && (algtype != QCRYPTODEV_BACKEND_ALG_ASYM)) {
|
|
|
- error_report("Unsupported cryptodev alg type: %" PRIu32 "", algtype);
|
|
|
- return -VIRTIO_CRYPTO_NOTSUPP;
|
|
|
+ ret = cryptodev_backend_account(backend, op_info);
|
|
|
+ if (ret < 0) {
|
|
|
+ return ret;
|
|
|
}
|
|
|
|
|
|
return cryptodev_backend_operation(backend, op_info);
|
|
@@ -202,10 +250,20 @@ cryptodev_backend_complete(UserCreatable *uc, Error **errp)
|
|
|
{
|
|
|
CryptoDevBackend *backend = CRYPTODEV_BACKEND(uc);
|
|
|
CryptoDevBackendClass *bc = CRYPTODEV_BACKEND_GET_CLASS(uc);
|
|
|
+ uint32_t services;
|
|
|
|
|
|
if (bc->init) {
|
|
|
bc->init(backend, errp);
|
|
|
}
|
|
|
+
|
|
|
+ services = backend->conf.crypto_services;
|
|
|
+ if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_CIPHER)) {
|
|
|
+ backend->sym_stat = g_new0(CryptodevBackendSymStat, 1);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (services & (1 << QCRYPTODEV_BACKEND_SERVICE_AKCIPHER)) {
|
|
|
+ backend->asym_stat = g_new0(CryptodevBackendAsymStat, 1);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void cryptodev_backend_set_used(CryptoDevBackend *backend, bool used)
|