Daniel P. Berrangé <berra...@redhat.com> writes: > On Wed, Aug 07, 2024 at 07:51:08PM +0000, Alejandro Zeise wrote: >> Changes the hash API to support accumulative hashing. >> Hash objects are created with "qcrypto_hash_new", >> updated with data with "qcrypto_hash_update", and >> the hash obtained with "qcrypto_hash_finalize". >> >> These changes bring the hashing API more in line with the >> hmac API. >> >> Signed-off-by: Alejandro Zeise <alejandro.ze...@seagate.com>
[...] >> diff --git a/include/crypto/hash.h b/include/crypto/hash.h >> index 54d87aa2a1..6d7222867e 100644 >> --- a/include/crypto/hash.h >> +++ b/include/crypto/hash.h >> @@ -1,6 +1,7 @@ >> /* >> * QEMU Crypto hash algorithms >> * >> + * Copyright (c) 2024 Seagate Technology LLC and/or its Affiliates >> * Copyright (c) 2015 Red Hat, Inc. >> * >> * This library is free software; you can redistribute it and/or >> @@ -25,6 +26,13 @@ >> >> /* See also "QCryptoHashAlgorithm" defined in qapi/crypto.json */ >> >> +typedef struct QCryptoHash QCryptoHash; >> +struct QCryptoHash { >> + QCryptoHashAlgorithm alg; >> + void *opaque; >> + void *driver; >> +}; >> + >> /** >> * qcrypto_hash_supports: >> * @alg: the hash algorithm >> @@ -120,6 +128,117 @@ int qcrypto_hash_digestv(QCryptoHashAlgorithm alg, >> char **digest, >> Error **errp); >> >> +/** >> + * qcrypto_hash_updatev: >> + * @hash: hash object from qcrypto_hash_new >> + * @iov: the array of memory regions to hash >> + * @niov: the length of @iov >> + * @errp: pointer to a NULL-initialized error object >> + * >> + * Updates the given hash object with all the memory regions >> + * present in @iov. >> + * >> + * Returns: 0 on success, non-zero on error > > Minor point, this and all the other APIs should be saying > 'or -1 on error' to follow QEMU's error reporting standards. Specifically, qapi/error.h: * - Whenever practical, also return a value that indicates success / * failure. This can make the error checking more concise, and can * avoid useless error object creation and destruction. Note that * we still have many functions returning void. We recommend * • bool-valued functions return true on success / false on failure, * • pointer-valued functions return non-null / null pointer, and * • integer-valued functions return non-negative / negative.