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 #ifndef QCRYPTO_HMAC_H
13 #define QCRYPTO_HMAC_H
15 #include "qapi-types.h"
17 typedef struct QCryptoHmac QCryptoHmac
;
19 QCryptoHashAlgorithm alg
;
25 * qcrypto_hmac_supports:
26 * @alg: the hmac algorithm
28 * Determine if @alg hmac algorithm is supported by
29 * the current configured build
32 * true if the algorithm is supported, false otherwise
34 bool qcrypto_hmac_supports(QCryptoHashAlgorithm alg
);
38 * @alg: the hmac algorithm
40 * @nkey: the length of @key
41 * @errp: pointer to a NULL-initialized error object
43 * Creates a new hmac object with the algorithm @alg
45 * The @key parameter provides the bytes representing
46 * the secret key to use. The @nkey parameter specifies
47 * the length of @key in bytes
49 * Note: must use qcrypto_hmac_free() to release the
50 * returned hmac object when no longer required
53 * a new hmac object, or NULL on error
55 QCryptoHmac
*qcrypto_hmac_new(QCryptoHashAlgorithm alg
,
56 const uint8_t *key
, size_t nkey
,
61 * @hmac: the hmac object
63 * Release the memory associated with @hmac that was
64 * previously allocated by qcrypto_hmac_new()
66 void qcrypto_hmac_free(QCryptoHmac
*hmac
);
69 * qcrypto_hmac_bytesv:
70 * @hmac: the hmac object
71 * @iov: the array of memory regions to hmac
72 * @niov: the length of @iov
73 * @result: pointer to hold output hmac
74 * @resultlen: pointer to hold length of @result
75 * @errp: pointer to a NULL-initialized error object
77 * Computes the hmac across all the memory regions
78 * present in @iov. The @result pointer will be
79 * filled with raw bytes representing the computed
80 * hmac, which will have length @resultlen. The
81 * memory pointer in @result must be released
82 * with a call to g_free() when no longer required.
85 * 0 on success, -1 on error
87 int qcrypto_hmac_bytesv(QCryptoHmac
*hmac
,
88 const struct iovec
*iov
,
96 * @hmac: the hmac object
97 * @buf: the memory region to hmac
98 * @len: the length of @buf
99 * @result: pointer to hold output hmac
100 * @resultlen: pointer to hold length of @result
101 * @errp: pointer to a NULL-initialized error object
103 * Computes the hmac across all the memory region
104 * @buf of length @len. The @result pointer will be
105 * filled with raw bytes representing the computed
106 * hmac, which will have length @resultlen. The
107 * memory pointer in @result must be released
108 * with a call to g_free() when no longer required.
111 * 0 on success, -1 on error
113 int qcrypto_hmac_bytes(QCryptoHmac
*hmac
,
121 * qcrypto_hmac_digestv:
122 * @hmac: the hmac object
123 * @iov: the array of memory regions to hmac
124 * @niov: the length of @iov
125 * @digest: pointer to hold output hmac
126 * @errp: pointer to a NULL-initialized error object
128 * Computes the hmac across all the memory regions
129 * present in @iov. The @digest pointer will be
130 * filled with the printable hex digest of the computed
131 * hmac, which will be terminated by '\0'. The
132 * memory pointer in @digest must be released
133 * with a call to g_free() when no longer required.
136 * 0 on success, -1 on error
138 int qcrypto_hmac_digestv(QCryptoHmac
*hmac
,
139 const struct iovec
*iov
,
145 * qcrypto_hmac_digest:
146 * @hmac: the hmac object
147 * @buf: the memory region to hmac
148 * @len: the length of @buf
149 * @digest: pointer to hold output hmac
150 * @errp: pointer to a NULL-initialized error object
152 * Computes the hmac across all the memory region
153 * @buf of length @len. The @digest pointer will be
154 * filled with the printable hex digest of the computed
155 * hmac, which will be terminated by '\0'. The
156 * memory pointer in @digest must be released
157 * with a call to g_free() when no longer required.
159 * Returns: 0 on success, -1 on error
161 int qcrypto_hmac_digest(QCryptoHmac
*hmac
,