From 8c0a6dc96cd14c48da4a61fe35431f36d6e6e467 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Mon, 28 Aug 2017 08:37:37 -0300 Subject: [PATCH 1/2] tests: fix incorrect size_t format in benchmark-crypto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $ make check-speed tests/benchmark-crypto-hash.c: In function 'test_hash_speed': tests/benchmark-crypto-hash.c:44:5: error: format '%ld' expects argument of type 'long int', but argument 2 has type 'size_t' [-Werror=format=] g_print("Testing chunk_size %ld bytes ", chunk_size); ^ tests/benchmark-crypto-hash.c: In function 'main': tests/benchmark-crypto-hash.c:62:9: error: format '%lu' expects argument of type 'long unsigned int', but argument 4 has type 'size_t' [-Werror=format=] snprintf(name, sizeof(name), "/crypto/hash/speed-%lu", i); ^ cc1: all warnings being treated as errors rules.mak:66: recipe for target 'tests/benchmark-crypto-hash.o' failed make: *** [tests/benchmark-crypto-hash.o] Error 1 Reviewed-by: Longpeng(Mike) Reviewed-by: Marc-André Lureau Signed-off-by: Philippe Mathieu-Daudé Signed-off-by: Daniel P. Berrange --- tests/benchmark-crypto-cipher.c | 4 ++-- tests/benchmark-crypto-hash.c | 4 ++-- tests/benchmark-crypto-hmac.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/benchmark-crypto-cipher.c b/tests/benchmark-crypto-cipher.c index c6a40929e4e6..cf984434680d 100644 --- a/tests/benchmark-crypto-cipher.c +++ b/tests/benchmark-crypto-cipher.c @@ -59,7 +59,7 @@ static void test_cipher_speed(const void *opaque) total /= 1024 * 1024; /* to MB */ g_print("cbc(aes128): "); - g_print("Testing chunk_size %ld bytes ", chunk_size); + g_print("Testing chunk_size %zu bytes ", chunk_size); g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last()); g_print("%.2f MB/sec\n", total / g_test_timer_last()); @@ -80,7 +80,7 @@ int main(int argc, char **argv) for (i = 512; i <= (64 * 1204); i *= 2) { memset(name, 0 , sizeof(name)); - snprintf(name, sizeof(name), "/crypto/cipher/speed-%lu", i); + snprintf(name, sizeof(name), "/crypto/cipher/speed-%zu", i); g_test_add_data_func(name, (void *)i, test_cipher_speed); } diff --git a/tests/benchmark-crypto-hash.c b/tests/benchmark-crypto-hash.c index 6769d2a11bc5..122bfb6b85c7 100644 --- a/tests/benchmark-crypto-hash.c +++ b/tests/benchmark-crypto-hash.c @@ -41,7 +41,7 @@ static void test_hash_speed(const void *opaque) total /= 1024 * 1024; /* to MB */ g_print("sha256: "); - g_print("Testing chunk_size %ld bytes ", chunk_size); + g_print("Testing chunk_size %zu bytes ", chunk_size); g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last()); g_print("%.2f MB/sec\n", total / g_test_timer_last()); @@ -59,7 +59,7 @@ int main(int argc, char **argv) for (i = 512; i <= (64 * 1204); i *= 2) { memset(name, 0 , sizeof(name)); - snprintf(name, sizeof(name), "/crypto/hash/speed-%lu", i); + snprintf(name, sizeof(name), "/crypto/hash/speed-%zu", i); g_test_add_data_func(name, (void *)i, test_hash_speed); } diff --git a/tests/benchmark-crypto-hmac.c b/tests/benchmark-crypto-hmac.c index 72408be9875b..c30250df3ec2 100644 --- a/tests/benchmark-crypto-hmac.c +++ b/tests/benchmark-crypto-hmac.c @@ -56,7 +56,7 @@ static void test_hmac_speed(const void *opaque) total /= 1024 * 1024; /* to MB */ g_print("hmac(sha256): "); - g_print("Testing chunk_size %ld bytes ", chunk_size); + g_print("Testing chunk_size %zu bytes ", chunk_size); g_print("done: %.2f MB in %.2f secs: ", total, g_test_timer_last()); g_print("%.2f MB/sec\n", total / g_test_timer_last()); @@ -74,7 +74,7 @@ int main(int argc, char **argv) for (i = 512; i <= (64 * 1204); i *= 2) { memset(name, 0 , sizeof(name)); - snprintf(name, sizeof(name), "/crypto/hmac/speed-%lu", i); + snprintf(name, sizeof(name), "/crypto/hmac/speed-%zu", i); g_test_add_data_func(name, (void *)i, test_hmac_speed); } From 23c1595b0297e6ca8f37559af6f0b8533aa1fd99 Mon Sep 17 00:00:00 2001 From: "Daniel P. Berrange" Date: Tue, 29 Aug 2017 17:03:30 +0100 Subject: [PATCH 2/2] crypto: fix test cert generation to not use SHA1 algorithm GNUTLS 3.6.0 marked SHA1 as untrusted for certificates. Unfortunately the gnutls_x509_crt_sign() method we are using to create certificates in the test suite is fixed to always use SHA1. We must switch to a different method and explicitly ask for SHA256. Reviewed-by: Eric Blake Signed-off-by: Daniel P. Berrange --- tests/crypto-tls-x509-helpers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/crypto-tls-x509-helpers.c b/tests/crypto-tls-x509-helpers.c index 64073d3bd317..173d4e28fb40 100644 --- a/tests/crypto-tls-x509-helpers.c +++ b/tests/crypto-tls-x509-helpers.c @@ -406,7 +406,8 @@ test_tls_generate_cert(QCryptoTLSTestCertReq *req, * If no 'ca' is set then we are self signing * the cert. This is done for the root CA certs */ - err = gnutls_x509_crt_sign(crt, ca ? ca : crt, privkey); + err = gnutls_x509_crt_sign2(crt, ca ? ca : crt, privkey, + GNUTLS_DIG_SHA256, 0); if (err < 0) { g_critical("Failed to sign certificate %s", gnutls_strerror(err));