crypto/hash: Have hashing functions take void * buffer argument

Cryptographic hash function can operate on any area of memory,
regardless of the content their represent. Do not restrict to
array of char, use the void* type, which is also the type of
the underlying iovec::iov_base field.

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé
2025-10-31 10:09:30 +01:00
committed by Daniel P. Berrangé
parent b433ca56e1
commit abf6e02dfb
4 changed files with 18 additions and 18 deletions

View File

@@ -67,13 +67,13 @@ int qcrypto_hash_bytesv(QCryptoHashAlgo alg,
int qcrypto_hash_bytes(QCryptoHashAlgo alg, int qcrypto_hash_bytes(QCryptoHashAlgo alg,
const char *buf, const void *buf,
size_t len, size_t len,
uint8_t **result, uint8_t **result,
size_t *resultlen, size_t *resultlen,
Error **errp) Error **errp)
{ {
struct iovec iov = { .iov_base = (char *)buf, struct iovec iov = { .iov_base = (void *)buf,
.iov_len = len }; .iov_len = len };
return qcrypto_hash_bytesv(alg, &iov, 1, result, resultlen, errp); return qcrypto_hash_bytesv(alg, &iov, 1, result, resultlen, errp);
} }
@@ -89,11 +89,11 @@ int qcrypto_hash_updatev(QCryptoHash *hash,
} }
int qcrypto_hash_update(QCryptoHash *hash, int qcrypto_hash_update(QCryptoHash *hash,
const char *buf, const void *buf,
size_t len, size_t len,
Error **errp) Error **errp)
{ {
struct iovec iov = { .iov_base = (char *)buf, .iov_len = len }; struct iovec iov = { .iov_base = (void *)buf, .iov_len = len };
return qcrypto_hash_updatev(hash, &iov, 1, errp); return qcrypto_hash_updatev(hash, &iov, 1, errp);
} }
@@ -206,12 +206,12 @@ int qcrypto_hash_digestv(QCryptoHashAlgo alg,
} }
int qcrypto_hash_digest(QCryptoHashAlgo alg, int qcrypto_hash_digest(QCryptoHashAlgo alg,
const char *buf, const void *buf,
size_t len, size_t len,
char **digest, char **digest,
Error **errp) Error **errp)
{ {
struct iovec iov = { .iov_base = (char *)buf, .iov_len = len }; struct iovec iov = { .iov_base = (void *)buf, .iov_len = len };
return qcrypto_hash_digestv(alg, &iov, 1, digest, errp); return qcrypto_hash_digestv(alg, &iov, 1, digest, errp);
} }
@@ -237,12 +237,12 @@ int qcrypto_hash_base64v(QCryptoHashAlgo alg,
} }
int qcrypto_hash_base64(QCryptoHashAlgo alg, int qcrypto_hash_base64(QCryptoHashAlgo alg,
const char *buf, const void *buf,
size_t len, size_t len,
char **base64, char **base64,
Error **errp) Error **errp)
{ {
struct iovec iov = { .iov_base = (char *)buf, .iov_len = len }; struct iovec iov = { .iov_base = (void *)buf, .iov_len = len };
return qcrypto_hash_base64v(alg, &iov, 1, base64, errp); return qcrypto_hash_base64v(alg, &iov, 1, base64, errp);
} }

View File

@@ -28,14 +28,14 @@ int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
} }
int qcrypto_hmac_bytes(QCryptoHmac *hmac, int qcrypto_hmac_bytes(QCryptoHmac *hmac,
const char *buf, const void *buf,
size_t len, size_t len,
uint8_t **result, uint8_t **result,
size_t *resultlen, size_t *resultlen,
Error **errp) Error **errp)
{ {
struct iovec iov = { struct iovec iov = {
.iov_base = (char *)buf, .iov_base = (void *)buf,
.iov_len = len .iov_len = len
}; };
@@ -70,13 +70,13 @@ int qcrypto_hmac_digestv(QCryptoHmac *hmac,
} }
int qcrypto_hmac_digest(QCryptoHmac *hmac, int qcrypto_hmac_digest(QCryptoHmac *hmac,
const char *buf, const void *buf,
size_t len, size_t len,
char **digest, char **digest,
Error **errp) Error **errp)
{ {
struct iovec iov = { struct iovec iov = {
.iov_base = (char *)buf, .iov_base = (void *)buf,
.iov_len = len .iov_len = len
}; };

View File

@@ -122,7 +122,7 @@ int qcrypto_hash_bytesv(QCryptoHashAlgo alg,
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */
int qcrypto_hash_bytes(QCryptoHashAlgo alg, int qcrypto_hash_bytes(QCryptoHashAlgo alg,
const char *buf, const void *buf,
size_t len, size_t len,
uint8_t **result, uint8_t **result,
size_t *resultlen, size_t *resultlen,
@@ -180,7 +180,7 @@ int qcrypto_hash_updatev(QCryptoHash *hash,
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */
int qcrypto_hash_update(QCryptoHash *hash, int qcrypto_hash_update(QCryptoHash *hash,
const char *buf, const void *buf,
size_t len, size_t len,
Error **errp); Error **errp);
@@ -289,7 +289,7 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(QCryptoHash, qcrypto_hash_free)
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */
int qcrypto_hash_digest(QCryptoHashAlgo alg, int qcrypto_hash_digest(QCryptoHashAlgo alg,
const char *buf, const void *buf,
size_t len, size_t len,
char **digest, char **digest,
Error **errp); Error **errp);
@@ -335,7 +335,7 @@ int qcrypto_hash_base64v(QCryptoHashAlgo alg,
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */
int qcrypto_hash_base64(QCryptoHashAlgo alg, int qcrypto_hash_base64(QCryptoHashAlgo alg,
const char *buf, const void *buf,
size_t len, size_t len,
char **base64, char **base64,
Error **errp); Error **errp);

View File

@@ -139,7 +139,7 @@ int qcrypto_hmac_bytesv(QCryptoHmac *hmac,
* 0 on success, -1 on error * 0 on success, -1 on error
*/ */
int qcrypto_hmac_bytes(QCryptoHmac *hmac, int qcrypto_hmac_bytes(QCryptoHmac *hmac,
const char *buf, const void *buf,
size_t len, size_t len,
uint8_t **result, uint8_t **result,
size_t *resultlen, size_t *resultlen,
@@ -187,7 +187,7 @@ int qcrypto_hmac_digestv(QCryptoHmac *hmac,
* Returns: 0 on success, -1 on error * Returns: 0 on success, -1 on error
*/ */
int qcrypto_hmac_digest(QCryptoHmac *hmac, int qcrypto_hmac_digest(QCryptoHmac *hmac,
const char *buf, const void *buf,
size_t len, size_t len,
char **digest, char **digest,
Error **errp); Error **errp);