summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorOrr Toledano <otoledan@amazon.com>2021-05-06 18:46:27 +0000
committerTomas Mraz <tomas@openssl.org>2022-11-09 15:30:08 +0100
commitf716af3484c5bc543b4a9d9ee99d819d017fec20 (patch)
treeb7e3d2f048786838569e641febb2044ee275015d /test
parent42ffe7812ca7be00bc24c1b06ffd5878f69fcf08 (diff)
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 <pauli@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15361) (cherry picked from commit 1f8ce0c9faee59ac51a5db7a8ec42c38866be090)
Diffstat (limited to 'test')
-rw-r--r--test/build.info8
-rw-r--r--test/rdcpu_sanitytest.c (renamed from test/rdrand_sanitytest.c)48
-rw-r--r--test/recipes/06-test_rdcpu_sanity.t (renamed from test/recipes/06-test_rdrand_sanity.t)4
3 files changed, 44 insertions, 16 deletions
diff --git a/test/build.info b/test/build.info
index 638f215da6..4b3b5efe67 100644
--- a/test/build.info
+++ b/test/build.info
@@ -593,7 +593,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 \
@@ -746,9 +746,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
index dcc9d2800a..df1858ae9b 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
index a20e09e778..9907abc7c0 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");