2 * QEMU Crypto hmac algorithms
4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD.
6 * This work is licensed under the terms of the GNU GPL, version 2 or
7 * (at your option) any later version. See the COPYING file in the
12 #include "qemu/osdep.h"
13 #include "qapi/error.h"
14 #include "crypto/hmac.h"
16 static const char hex[] = "0123456789abcdef";
18 int qcrypto_hmac_bytes(QCryptoHmac *hmac,
26 .iov_base = (char *)buf,
30 return qcrypto_hmac_bytesv(hmac, &iov, 1, result, resultlen, errp);
33 int qcrypto_hmac_digestv(QCryptoHmac *hmac,
34 const struct iovec *iov,
39 uint8_t *result = NULL;
43 if (qcrypto_hmac_bytesv(hmac, iov, niov, &result, &resultlen, errp) < 0) {
47 *digest = g_new0(char, (resultlen * 2) + 1);
49 for (i = 0 ; i < resultlen ; i++) {
50 (*digest)[(i * 2)] = hex[(result[i] >> 4) & 0xf];
51 (*digest)[(i * 2) + 1] = hex[result[i] & 0xf];
54 (*digest)[resultlen * 2] = '\0';
60 int qcrypto_hmac_digest(QCryptoHmac *hmac,
67 .iov_base = (char *)buf,
71 return qcrypto_hmac_digestv(hmac, &iov, 1, digest, errp);