]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
Add tests for RNDR and combine tests with RDRAND
authorOrr Toledano <otoledan@amazon.com>
Thu, 6 May 2021 18:46:27 +0000 (18:46 +0000)
committerTomas Mraz <tomas@openssl.org>
Thu, 16 Dec 2021 11:38:09 +0000 (12:38 +0100)
Add test cases for RNDR and RNDRRS. Combine tests for RDRAND and RNDR to
share common logic.

Reviewed-by: Paul Dale <pauli@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/15361)

test/build.info
test/rdcpu_sanitytest.c [moved from test/rdrand_sanitytest.c with 80% similarity]
test/recipes/06-test_rdcpu_sanity.t [moved from test/recipes/06-test_rdrand_sanity.t with 87% similarity]

index bc8d4002322beabd7d880bf435a546e4c04aa425..ec4bd8d5db50c6f58c27cf8b1375b65f7de30f89 100644 (file)
@@ -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
similarity index 80%
rename from test/rdrand_sanitytest.c
rename to test/rdcpu_sanitytest.c
index dcc9d2800ae0d436ef6ed8ece7484193ad973306..df1858ae9b89d8427fadcd564932f950d5b7fcb5 100644 (file)
 #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
similarity index 87%
rename from test/recipes/06-test_rdrand_sanity.t
rename to test/recipes/06-test_rdcpu_sanity.t
index a20e09e77804974935467fd0d4cefba0b4150449..9907abc7c094a6b6d6aee1240dd6cfa437da81be 100644 (file)
@@ -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");