summaryrefslogtreecommitdiffstats
path: root/crypto/cipher.c
diff options
context:
space:
mode:
authorRichard Henderson2020-08-28 19:05:14 +0200
committerDaniel P. Berrangé2020-09-10 12:02:23 +0200
commit3eedf5cc9d45f94e2fd229f0a7aaca556a4ac734 (patch)
tree8295084987ae1c2929d684ce02a376ab8635939a /crypto/cipher.c
parentcrypto: Use the correct const type for driver (diff)
downloadqemu-3eedf5cc9d45f94e2fd229f0a7aaca556a4ac734.tar.gz
qemu-3eedf5cc9d45f94e2fd229f0a7aaca556a4ac734.tar.xz
qemu-3eedf5cc9d45f94e2fd229f0a7aaca556a4ac734.zip
crypto: Allocate QCryptoCipher with the subclass
Merge the allocation of "opaque" into the allocation of "cipher". This is step one in reducing the indirection in these classes. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Diffstat (limited to 'crypto/cipher.c')
-rw-r--r--crypto/cipher.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/crypto/cipher.c b/crypto/cipher.c
index 3ca4a7e662..737fc0735d 100644
--- a/crypto/cipher.c
+++ b/crypto/cipher.c
@@ -163,30 +163,27 @@ QCryptoCipher *qcrypto_cipher_new(QCryptoCipherAlgorithm alg,
const uint8_t *key, size_t nkey,
Error **errp)
{
- QCryptoCipher *cipher;
- void *ctx = NULL;
+ QCryptoCipher *cipher = NULL;
const QCryptoCipherDriver *drv = NULL;
#ifdef CONFIG_AF_ALG
- ctx = qcrypto_afalg_cipher_ctx_new(alg, mode, key, nkey, NULL);
- if (ctx) {
+ cipher = qcrypto_afalg_cipher_ctx_new(alg, mode, key, nkey, NULL);
+ if (cipher) {
drv = &qcrypto_cipher_afalg_driver;
}
#endif
- if (!ctx) {
- ctx = qcrypto_cipher_ctx_new(alg, mode, key, nkey, errp);
- if (!ctx) {
+ if (!cipher) {
+ cipher = qcrypto_cipher_ctx_new(alg, mode, key, nkey, errp);
+ if (!cipher) {
return NULL;
}
drv = &qcrypto_cipher_lib_driver;
}
- cipher = g_new0(QCryptoCipher, 1);
cipher->alg = alg;
cipher->mode = mode;
- cipher->opaque = ctx;
cipher->driver = drv;
return cipher;
@@ -226,10 +223,7 @@ int qcrypto_cipher_setiv(QCryptoCipher *cipher,
void qcrypto_cipher_free(QCryptoCipher *cipher)
{
- const QCryptoCipherDriver *drv;
if (cipher) {
- drv = cipher->driver;
- drv->cipher_free(cipher);
- g_free(cipher);
+ cipher->driver->cipher_free(cipher);
}
}