hmac.c (c76904ef2fc920bc6f73a827412cedac0aa167ad) | hmac.c (14a5a2aef47e27b6afd1f8855eb41c75b69440dc) |
---|---|
1/* 2 * QEMU Crypto hmac algorithms 3 * 4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. 5 * 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 8 * top-level directory. 9 * 10 */ 11 12#include "qemu/osdep.h" 13#include "qapi/error.h" 14#include "crypto/hmac.h" | 1/* 2 * QEMU Crypto hmac algorithms 3 * 4 * Copyright (c) 2016 HUAWEI TECHNOLOGIES CO., LTD. 5 * 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 8 * top-level directory. 9 * 10 */ 11 12#include "qemu/osdep.h" 13#include "qapi/error.h" 14#include "crypto/hmac.h" |
15#include "hmacpriv.h" |
|
15 16static const char hex[] = "0123456789abcdef"; 17 | 16 17static const char hex[] = "0123456789abcdef"; 18 |
19int qcrypto_hmac_bytesv(QCryptoHmac *hmac, 20 const struct iovec *iov, 21 size_t niov, 22 uint8_t **result, 23 size_t *resultlen, 24 Error **errp) 25{ 26 QCryptoHmacDriver *drv = hmac->driver; 27 28 return drv->hmac_bytesv(hmac, iov, niov, result, resultlen, errp); 29} 30 |
|
18int qcrypto_hmac_bytes(QCryptoHmac *hmac, 19 const char *buf, 20 size_t len, 21 uint8_t **result, 22 size_t *resultlen, 23 Error **errp) 24{ 25 struct iovec iov = { --- 39 unchanged lines hidden (view full) --- 65{ 66 struct iovec iov = { 67 .iov_base = (char *)buf, 68 .iov_len = len 69 }; 70 71 return qcrypto_hmac_digestv(hmac, &iov, 1, digest, errp); 72} | 31int qcrypto_hmac_bytes(QCryptoHmac *hmac, 32 const char *buf, 33 size_t len, 34 uint8_t **result, 35 size_t *resultlen, 36 Error **errp) 37{ 38 struct iovec iov = { --- 39 unchanged lines hidden (view full) --- 78{ 79 struct iovec iov = { 80 .iov_base = (char *)buf, 81 .iov_len = len 82 }; 83 84 return qcrypto_hmac_digestv(hmac, &iov, 1, digest, errp); 85} |
86 87QCryptoHmac *qcrypto_hmac_new(QCryptoHashAlgorithm alg, 88 const uint8_t *key, size_t nkey, 89 Error **errp) 90{ 91 QCryptoHmac *hmac; 92 void *ctx; 93 94 ctx = qcrypto_hmac_ctx_new(alg, key, nkey, errp); 95 if (!ctx) { 96 return NULL; 97 } 98 99 hmac = g_new0(QCryptoHmac, 1); 100 hmac->alg = alg; 101 hmac->opaque = ctx; 102 hmac->driver = (void *)&qcrypto_hmac_lib_driver; 103 104 return hmac; 105} 106 107void qcrypto_hmac_free(QCryptoHmac *hmac) 108{ 109 QCryptoHmacDriver *drv; 110 111 if (hmac) { 112 drv = hmac->driver; 113 drv->hmac_free(hmac); 114 g_free(hmac); 115 } 116} |
|