summary refs log tree commit diff stats
path: root/crypto/hmac.c
diff options
context:
space:
mode:
authorLongpeng(Mike) <longpeng2@huawei.com>2017-07-14 14:04:08 -0400
committerDaniel P. Berrange <berrange@redhat.com>2017-07-19 10:11:05 +0100
commit42e7e15f99e1c78b2d3e7e7a1cb923e472ef8e9f (patch)
tree6d4342f29f741985741a1932cd0e6c2d5819ae88 /crypto/hmac.c
parent9a0597734876682480851376a98202a84073b715 (diff)
downloadfocaccia-qemu-42e7e15f99e1c78b2d3e7e7a1cb923e472ef8e9f.tar.gz
focaccia-qemu-42e7e15f99e1c78b2d3e7e7a1cb923e472ef8e9f.zip
crypto: hmac: add af_alg-backend hmac support
Adds afalg-backend hmac support: introduces some private APIs
firstly, and then intergrates them into qcrypto_hmac_afalg_driver.

Signed-off-by: Longpeng(Mike) <longpeng2@huawei.com>
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
Diffstat (limited to 'crypto/hmac.c')
-rw-r--r--crypto/hmac.c22
1 files changed, 18 insertions, 4 deletions
diff --git a/crypto/hmac.c b/crypto/hmac.c
index a4690e3f4a..82b0055adf 100644
--- a/crypto/hmac.c
+++ b/crypto/hmac.c
@@ -89,17 +89,31 @@ QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg,
                               Error **errp)
 {
     QCryptoHmac *hmac;
-    void *ctx;
+    void *ctx = NULL;
+    Error *err2 = NULL;
+    QCryptoHmacDriver *drv = NULL;
+
+#ifdef CONFIG_AF_ALG
+    ctx = qcrypto_afalg_hmac_ctx_new(alg, key, nkey, &err2);
+    if (ctx) {
+        drv = &qcrypto_hmac_afalg_driver;
+    }
+#endif
 
-    ctx = qcrypto_hmac_ctx_new(alg, key, nkey, errp);
     if (!ctx) {
-        return NULL;
+        ctx = qcrypto_hmac_ctx_new(alg, key, nkey, errp);
+        if (!ctx) {
+            return NULL;
+        }
+
+        drv = &qcrypto_hmac_lib_driver;
+        error_free(err2);
     }
 
     hmac = g_new0(QCryptoHmac, 1);
     hmac->alg = alg;
     hmac->opaque = ctx;
-    hmac->driver = (void *)&qcrypto_hmac_lib_driver;
+    hmac->driver = (void *)drv;
 
     return hmac;
 }