2 * vircryptotest.c: cryptographic helper test suite
4 * Copyright (C) 2014 Red Hat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library. If not, see
18 * <http://www.gnu.org/licenses/>.
23 #include "vircrypto.h"
25 #include "testutils.h"
28 struct testCryptoHashData {
35 testCryptoHash(const void *opaque)
37 const struct testCryptoHashData *data = opaque;
41 if (virCryptoHashString(data->hash, data->input, &actual) < 0) {
42 fprintf(stderr, "Failed to generate crypto hash\n");
46 if (STRNEQ_NULLABLE(data->output, actual)) {
47 fprintf(stderr, "Expected hash '%s' but got '%s'\n",
48 data->output, NULLSTR(actual));
64 #define VIR_CRYPTO_HASH(h, i, o) \
66 struct testCryptoHashData data = { \
71 if (virtTestRun("Hash " i, testCryptoHash, &data) < 0) \
75 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_MD5, "", "d41d8cd98f00b204e9800998ecf8427e");
76 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_SHA256, "", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
78 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_MD5, " ", "7215ee9c7d9dc229d2921a40e899ec5f");
79 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_SHA256, " ", "36a9e7f1c95b82ffb99743e0c5c4ce95d83c9a430aac59f84ef3cbfab6145068");
81 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_MD5, "\n", "68b329da9893e34099c7d8ad5cb9c940");
82 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_SHA256, "\n", "01ba4719c80b6fe911b091a7c05124b64eeece964e09c058ef8f9805daca546b");
84 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_MD5, "The quick brown fox", "a2004f37730b9445670a738fa0fc9ee5");
85 VIR_CRYPTO_HASH(VIR_CRYPTO_HASH_SHA256, "The quick brown fox", "5cac4f980fedc3d3f1f99b4be3472c9b30d56523e632d151237ec9309048bda9");
87 return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
90 VIRT_TEST_MAIN(mymain)