From: Orr Toledano Date: Thu, 6 May 2021 18:46:27 +0000 (+0000) Subject: Add tests for RNDR and combine tests with RDRAND X-Git-Tag: openssl-3.2.0-alpha1~3191 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1f8ce0c9faee59ac51a5db7a8ec42c38866be090;p=thirdparty%2Fopenssl.git Add tests for RNDR and combine tests with RDRAND Add test cases for RNDR and RNDRRS. Combine tests for RDRAND and RNDR to share common logic. Reviewed-by: Paul Dale Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/15361) --- diff --git a/test/build.info b/test/build.info index bc8d4002322..ec4bd8d5db5 100644 --- a/test/build.info +++ b/test/build.info @@ -584,7 +584,7 @@ IF[{- !$disabled{tests} -}] IF[1] PROGRAMS{noinst}=asn1_internal_test modes_internal_test x509_internal_test \ tls13encryptiontest wpackettest ctype_internal_test \ - rdrand_sanitytest property_test ideatest rsa_mp_test \ + rdcpu_sanitytest property_test ideatest rsa_mp_test \ rsa_sp800_56b_test bn_internal_test ecdsatest rsa_test \ rc2test rc4test rc5test hmactest ffc_internal_test \ asn1_dsa_internal_test dsatest dsa_no_digest_size_test \ @@ -737,9 +737,9 @@ IF[{- !$disabled{tests} -}] INCLUDE[rc4test]=../include ../apps/include DEPEND[rc4test]=../libcrypto.a libtestutil.a - SOURCE[rdrand_sanitytest]=rdrand_sanitytest.c - INCLUDE[rdrand_sanitytest]=../include ../apps/include - DEPEND[rdrand_sanitytest]=../libcrypto.a libtestutil.a + SOURCE[rdcpu_sanitytest]=rdcpu_sanitytest.c + INCLUDE[rdcpu_sanitytest]=../include ../apps/include ../crypto + DEPEND[rdcpu_sanitytest]=../libcrypto.a libtestutil.a SOURCE[rsa_sp800_56b_test]=rsa_sp800_56b_test.c INCLUDE[rsa_sp800_56b_test]=.. ../include ../crypto/rsa ../apps/include diff --git a/test/rdrand_sanitytest.c b/test/rdcpu_sanitytest.c similarity index 80% rename from test/rdrand_sanitytest.c rename to test/rdcpu_sanitytest.c index dcc9d2800ae..df1858ae9b8 100644 --- a/test/rdrand_sanitytest.c +++ b/test/rdcpu_sanitytest.c @@ -16,10 +16,24 @@ #if (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \ defined(__x86_64) || defined(__x86_64__) || \ defined(_M_AMD64) || defined (_M_X64)) && defined(OPENSSL_CPUID_OBJ) - +# define IS_X_86 1 size_t OPENSSL_ia32_rdrand_bytes(unsigned char *buf, size_t len); size_t OPENSSL_ia32_rdseed_bytes(unsigned char *buf, size_t len); +#else +# define IS_X_86 0 +#endif + +#if defined(__aarch64__) +# define IS_AARCH_64 1 +# include "arm_arch.h" + +size_t OPENSSL_rndr_bytes(unsigned char *buf, size_t len); +size_t OPENSSL_rndrrs_bytes(unsigned char *buf, size_t len); +#else +# define IS_AARCH_64 0 +#endif +#if (IS_X_86 || IS_AARCH_64) static int sanity_check_bytes(size_t (*rng)(unsigned char *, size_t), int rounds, int min_failures, int max_retries, int max_zero_words) { @@ -76,7 +90,9 @@ static int sanity_check_bytes(size_t (*rng)(unsigned char *, size_t), end: return testresult; } +#endif +#if IS_X_86 static int sanity_check_rdrand_bytes(void) { return sanity_check_bytes(OPENSSL_ia32_rdrand_bytes, 1000, 0, 10, 10); @@ -92,11 +108,24 @@ static int sanity_check_rdseed_bytes(void) */ return sanity_check_bytes(OPENSSL_ia32_rdseed_bytes, 1000, 1, 10000, 10); } +#elif IS_AARCH_64 +static int sanity_check_rndr_bytes(void) +{ + return sanity_check_bytes(OPENSSL_rndr_bytes, 1000, 0, 10, 10); +} + +static int sanity_check_rndrrs_bytes(void) +{ + return sanity_check_bytes(OPENSSL_rndrrs_bytes, 1000, 0, 10000, 10); +} +#endif int setup_tests(void) { +#if (IS_X_86 || IS_AARCH_64) OPENSSL_cpuid_setup(); +# if IS_X_86 int have_rdseed = (OPENSSL_ia32cap_P[2] & (1 << 18)) != 0; int have_rdrand = (OPENSSL_ia32cap_P[1] & (1 << (62 - 32))) != 0; @@ -107,16 +136,15 @@ int setup_tests(void) if (have_rdseed) { ADD_TEST(sanity_check_rdseed_bytes); } +# elif IS_AARCH_64 + int have_rndr_rndrrs = (OPENSSL_armcap_P & (1 << 8)) != 0; - return 1; -} - - -#else + if (have_rndr_rndrrs) { + ADD_TEST(sanity_check_rndr_bytes); + ADD_TEST(sanity_check_rndrrs_bytes); + } +# endif +#endif -int setup_tests(void) -{ return 1; } - -#endif diff --git a/test/recipes/06-test_rdrand_sanity.t b/test/recipes/06-test_rdcpu_sanity.t similarity index 87% rename from test/recipes/06-test_rdrand_sanity.t rename to test/recipes/06-test_rdcpu_sanity.t index a20e09e7780..9907abc7c09 100644 --- a/test/recipes/06-test_rdrand_sanity.t +++ b/test/recipes/06-test_rdcpu_sanity.t @@ -13,10 +13,10 @@ use OpenSSL::Test; # get 'plan' use OpenSSL::Test::Simple; use OpenSSL::Test::Utils; -setup("test_rdrand_sanity"); +setup("test_rdcpu_sanity"); # We also need static builds to be enabled even on linux plan skip_all => "This test is unsupported if static builds are not enabled" if disabled("static"); -simple_test("test_rdrand_sanity", "rdrand_sanitytest"); +simple_test("test_rdcpu_sanity", "rdcpu_sanitytest");