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/qapi-types-crypto.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
);
68 G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoHmac
, qcrypto_hmac_free
)
71 * qcrypto_hmac_bytesv:
72 * @hmac: the hmac object
73 * @iov: the array of memory regions to hmac
74 * @niov: the length of @iov
75 * @result: pointer to hold output hmac
76 * @resultlen: pointer to hold length of @result
77 * @errp: pointer to a NULL-initialized error object
79 * Computes the hmac across all the memory regions
80 * present in @iov. The @result pointer will be
81 * filled with raw bytes representing the computed
82 * hmac, which will have length @resultlen. The
83 * memory pointer in @result must be released
84 * with a call to g_free() when no longer required.
87 * 0 on success, -1 on error
89 int qcrypto_hmac_bytesv(QCryptoHmac
*hmac
,
90 const struct iovec
*iov
,
98 * @hmac: the hmac object
99 * @buf: the memory region to hmac
100 * @len: the length of @buf
101 * @result: pointer to hold output hmac
102 * @resultlen: pointer to hold length of @result
103 * @errp: pointer to a NULL-initialized error object
105 * Computes the hmac across all the memory region
106 * @buf of length @len. The @result pointer will be
107 * filled with raw bytes representing the computed
108 * hmac, which will have length @resultlen. The
109 * memory pointer in @result must be released
110 * with a call to g_free() when no longer required.
113 * 0 on success, -1 on error
115 int qcrypto_hmac_bytes(QCryptoHmac
*hmac
,
123 * qcrypto_hmac_digestv:
124 * @hmac: the hmac object
125 * @iov: the array of memory regions to hmac
126 * @niov: the length of @iov
127 * @digest: pointer to hold output hmac
128 * @errp: pointer to a NULL-initialized error object
130 * Computes the hmac across all the memory regions
131 * present in @iov. The @digest pointer will be
132 * filled with the printable hex digest of the computed
133 * hmac, which will be terminated by '\0'. The
134 * memory pointer in @digest must be released
135 * with a call to g_free() when no longer required.
138 * 0 on success, -1 on error
140 int qcrypto_hmac_digestv(QCryptoHmac
*hmac
,
141 const struct iovec
*iov
,
147 * qcrypto_hmac_digest:
148 * @hmac: the hmac object
149 * @buf: the memory region to hmac
150 * @len: the length of @buf
151 * @digest: pointer to hold output hmac
152 * @errp: pointer to a NULL-initialized error object
154 * Computes the hmac across all the memory region
155 * @buf of length @len. The @digest pointer will be
156 * filled with the printable hex digest of the computed
157 * hmac, which will be terminated by '\0'. The
158 * memory pointer in @digest must be released
159 * with a call to g_free() when no longer required.
161 * Returns: 0 on success, -1 on error
163 int qcrypto_hmac_digest(QCryptoHmac
*hmac
,