diff options
author | Longpeng(Mike) <longpeng2@huawei.com> | 2017-07-14 14:04:04 -0400 |
---|---|---|
committer | Daniel P. Berrange <berrange@redhat.com> | 2017-07-19 10:11:05 +0100 |
commit | 14a5a2aef47e27b6afd1f8855eb41c75b69440dc (patch) | |
tree | c8a273d9e48e5b6b4a50125238b96392f1e5481a /crypto/hmac.c | |
parent | d73c04e3ca3d4a1ac73da7f7952f769824417b47 (diff) |
crypto: hmac: add hmac driver framework
1) makes the public APIs in hmac-nettle/gcrypt/glib static,
and rename them with "nettle/gcrypt/glib" prefix.
2) introduces hmac framework, including QCryptoHmacDriver
and new public APIs.
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.c | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/crypto/hmac.c b/crypto/hmac.c index 5750405cfb..a4690e3f4a 100644 --- a/crypto/hmac.c +++ b/crypto/hmac.c @@ -12,9 +12,22 @@ #include "qemu/osdep.h" #include "qapi/error.h" #include "crypto/hmac.h" +#include "hmacpriv.h" static const char hex[] = "0123456789abcdef"; +int qcrypto_hmac_bytesv(QCryptoHmac *hmac, + const struct iovec *iov, + size_t niov, + uint8_t **result, + size_t *resultlen, + Error **errp) +{ + QCryptoHmacDriver *drv = hmac->driver; + + return drv->hmac_bytesv(hmac, iov, niov, result, resultlen, errp); +} + int qcrypto_hmac_bytes(QCryptoHmac *hmac, const char *buf, size_t len, @@ -70,3 +83,34 @@ int qcrypto_hmac_digest(QCryptoHmac *hmac, return qcrypto_hmac_digestv(hmac, &iov, 1, digest, errp); } + +QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, + const uint8_t *key, size_t nkey, + Error **errp) +{ + QCryptoHmac *hmac; + void *ctx; + + ctx = qcrypto_hmac_ctx_new(alg, key, nkey, errp); + if (!ctx) { + return NULL; + } + + hmac = g_new0(QCryptoHmac, 1); + hmac->alg = alg; + hmac->opaque = ctx; + hmac->driver = (void *)&qcrypto_hmac_lib_driver; + + return hmac; +} + +void qcrypto_hmac_free(QCryptoHmac *hmac) +{ + QCryptoHmacDriver *drv; + + if (hmac) { + drv = hmac->driver; + drv->hmac_free(hmac); + g_free(hmac); + } +} |