mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 16:53:55 -06:00
Introduce new cryptography hashing APIs
-----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEE2vOm/bJrYpEtDo4/vobrtBUQT98FAmcH/iIACgkQvobrtBUQ T9+Yjg/+NReYV5BDjOLk6vfgTsK6Ku0/hdis2cf9OS8Ud1VXzKaxfhwkchtw9QVI kuAthesQNocEPfQfl2K4+f4oaKfysO7awDwYto/JhY/m1iCZ8iqofZWehOITszvM EvWlNBr83NtpGFIwQWIxFEVZo42gaUnA69iAjBo7YQnE5xufJuPIbgMjB/O4/zar Xlo15A69TP9dBJTvIDdrhkt3Quiysa7a68BW+piAAKvplOjOfugCEo3ebLwlZYOh dK0Cg9v24+BMAqQ7kDMroS4uHC+OEs2AOvfYh01QqWxNkk7RsPjb9VAA60Ng89eC 6BU4jw17zUAqL67of+M1cTTX4UPGBWGIUXt8CtO1DpByxiGXXfEkBrBmIyDJvxn9 EzB4WpAXpVo2AG6vYpYSBGyxycWQs33ljfBb/qR6xu5PnA+Jc/jfJkVv5iYP96wW F6pJm6FoK69aTJU7K4kAJPjD2fZum+iHVWc283NIkq9HQJLz2EYE0LIfOOY5feJK S0tjEE5ZLqKG5JAdpsaCe5V/vExc512/D56Xb5fY4mC2DPb/b6fM66Oc5M7DTuK1 LxCgnEuqm1Lo3CMR0k4W8Xezs7hWp+u3tr+i705l5qFxklYkmFeVAzTWdQ56JOGk Z1XKUbcPUnweormPMxMQXyxXpey4DBwUGbjC98iqE8tjUg6NA3o= =yVgk -----END PGP SIGNATURE----- Merge tag 'crypto-fixes-pull-request' of https://gitlab.com/berrange/qemu into staging Introduce new cryptography hashing APIs # -----BEGIN PGP SIGNATURE----- # # iQIzBAABCAAdFiEE2vOm/bJrYpEtDo4/vobrtBUQT98FAmcH/iIACgkQvobrtBUQ # T9+Yjg/+NReYV5BDjOLk6vfgTsK6Ku0/hdis2cf9OS8Ud1VXzKaxfhwkchtw9QVI # kuAthesQNocEPfQfl2K4+f4oaKfysO7awDwYto/JhY/m1iCZ8iqofZWehOITszvM # EvWlNBr83NtpGFIwQWIxFEVZo42gaUnA69iAjBo7YQnE5xufJuPIbgMjB/O4/zar # Xlo15A69TP9dBJTvIDdrhkt3Quiysa7a68BW+piAAKvplOjOfugCEo3ebLwlZYOh # dK0Cg9v24+BMAqQ7kDMroS4uHC+OEs2AOvfYh01QqWxNkk7RsPjb9VAA60Ng89eC # 6BU4jw17zUAqL67of+M1cTTX4UPGBWGIUXt8CtO1DpByxiGXXfEkBrBmIyDJvxn9 # EzB4WpAXpVo2AG6vYpYSBGyxycWQs33ljfBb/qR6xu5PnA+Jc/jfJkVv5iYP96wW # F6pJm6FoK69aTJU7K4kAJPjD2fZum+iHVWc283NIkq9HQJLz2EYE0LIfOOY5feJK # S0tjEE5ZLqKG5JAdpsaCe5V/vExc512/D56Xb5fY4mC2DPb/b6fM66Oc5M7DTuK1 # LxCgnEuqm1Lo3CMR0k4W8Xezs7hWp+u3tr+i705l5qFxklYkmFeVAzTWdQ56JOGk # Z1XKUbcPUnweormPMxMQXyxXpey4DBwUGbjC98iqE8tjUg6NA3o= # =yVgk # -----END PGP SIGNATURE----- # gpg: Signature made Thu 10 Oct 2024 17:17:38 BST # gpg: using RSA key DAF3A6FDB26B62912D0E8E3FBE86EBB415104FDF # gpg: Good signature from "Daniel P. Berrange <dan@berrange.com>" [full] # gpg: aka "Daniel P. Berrange <berrange@redhat.com>" [full] # Primary key fingerprint: DAF3 A6FD B26B 6291 2D0E 8E3F BE86 EBB4 1510 4FDF * tag 'crypto-fixes-pull-request' of https://gitlab.com/berrange/qemu: tests/unit: Add a assert for test_io_channel_unix_listen_cleanup crypto: drop obsolete back compat logic for old nettle crypto/hashpriv: Remove old hash API function crypto/hash-afalg: Remove old hash API functions crypto/hash-nettle: Remove old hash API functions crypto/hash-gnutls: Remove old hash API functions crypto/hash-gcrypt: Remove old hash API functions crypto/hash-glib: Remove old hash API functions tests/unit/test-crypto-hash: accumulative hashing crypto/hash: Implement and use new hash API crypto/hash-afalg: Implement new hash API util/iov: Introduce iov_send_recv_with_flags() crypto/hash-nettle: Implement new hash API crypto/hash-gnutls: Implement new hash API crypto/hash-gcrypt: Implement new hash API crypto/hash-glib: Implement new hash API crypto: accumulative hashing API Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
7e3b6d8063
12 changed files with 733 additions and 282 deletions
|
@ -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
|
||||
|
@ -241,6 +242,50 @@ static void test_hash_base64(void)
|
|||
}
|
||||
}
|
||||
|
||||
static void test_hash_accumulate(void)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS(expected_outputs) ; i++) {
|
||||
g_autoptr(QCryptoHash) hash = NULL;
|
||||
struct iovec iov[] = {
|
||||
{ .iov_base = (char *)INPUT_TEXT1, .iov_len = strlen(INPUT_TEXT1) },
|
||||
{ .iov_base = (char *)INPUT_TEXT2, .iov_len = strlen(INPUT_TEXT2) },
|
||||
{ .iov_base = (char *)INPUT_TEXT3, .iov_len = strlen(INPUT_TEXT3) },
|
||||
};
|
||||
g_autofree uint8_t *result = NULL;
|
||||
size_t resultlen = 0;
|
||||
int ret;
|
||||
size_t j;
|
||||
|
||||
if (!qcrypto_hash_supports(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
hash = qcrypto_hash_new(i, &error_fatal);
|
||||
g_assert(hash != NULL);
|
||||
|
||||
/* Add each iovec to the hash context separately */
|
||||
for (j = 0; j < G_N_ELEMENTS(iov); j++) {
|
||||
ret = qcrypto_hash_updatev(hash,
|
||||
&iov[j], 1,
|
||||
&error_fatal);
|
||||
|
||||
g_assert(ret == 0);
|
||||
}
|
||||
|
||||
ret = qcrypto_hash_finalize_bytes(hash, &result, &resultlen,
|
||||
&error_fatal);
|
||||
|
||||
g_assert(ret == 0);
|
||||
g_assert(resultlen == expected_lens[i]);
|
||||
for (j = 0; j < resultlen; j++) {
|
||||
g_assert(expected_outputs[i][j * 2] == hex[(result[j] >> 4) & 0xf]);
|
||||
g_assert(expected_outputs[i][j * 2 + 1] == hex[result[j] & 0xf]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int ret = qcrypto_init(&error_fatal);
|
||||
|
@ -252,5 +297,6 @@ int main(int argc, char **argv)
|
|||
g_test_add_func("/crypto/hash/prealloc", test_hash_prealloc);
|
||||
g_test_add_func("/crypto/hash/digest", test_hash_digest);
|
||||
g_test_add_func("/crypto/hash/base64", test_hash_base64);
|
||||
g_test_add_func("/crypto/hash/accumulate", test_hash_accumulate);
|
||||
return g_test_run();
|
||||
}
|
||||
|
|
|
@ -506,7 +506,7 @@ static void test_io_channel_unix_listen_cleanup(void)
|
|||
{
|
||||
QIOChannelSocket *ioc;
|
||||
struct sockaddr_un un;
|
||||
int sock;
|
||||
int sock, ret = 0;
|
||||
|
||||
#define TEST_SOCKET "test-io-channel-socket.sock"
|
||||
|
||||
|
@ -519,7 +519,9 @@ static void test_io_channel_unix_listen_cleanup(void)
|
|||
un.sun_family = AF_UNIX;
|
||||
snprintf(un.sun_path, sizeof(un.sun_path), "%s", TEST_SOCKET);
|
||||
unlink(TEST_SOCKET);
|
||||
bind(sock, (struct sockaddr *)&un, sizeof(un));
|
||||
ret = bind(sock, (struct sockaddr *)&un, sizeof(un));
|
||||
g_assert_cmpint(ret, ==, 0);
|
||||
|
||||
ioc->fd = sock;
|
||||
ioc->localAddrLen = sizeof(ioc->localAddr);
|
||||
getsockname(sock, (struct sockaddr *)&ioc->localAddr,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue