mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-04 08:13:54 -06:00
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>
This commit is contained in:
parent
d73c04e3ca
commit
14a5a2aef4
6 changed files with 145 additions and 114 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue