Skip to content

Commit 1f8ce0c

Browse files
otoledant8m
authored andcommitted
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 <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from #15361)
1 parent eb28fda commit 1f8ce0c

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

test/build.info

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ IF[{- !$disabled{tests} -}]
584584
IF[1]
585585
PROGRAMS{noinst}=asn1_internal_test modes_internal_test x509_internal_test \
586586
tls13encryptiontest wpackettest ctype_internal_test \
587-
rdrand_sanitytest property_test ideatest rsa_mp_test \
587+
rdcpu_sanitytest property_test ideatest rsa_mp_test \
588588
rsa_sp800_56b_test bn_internal_test ecdsatest rsa_test \
589589
rc2test rc4test rc5test hmactest ffc_internal_test \
590590
asn1_dsa_internal_test dsatest dsa_no_digest_size_test \
@@ -737,9 +737,9 @@ IF[{- !$disabled{tests} -}]
737737
INCLUDE[rc4test]=../include ../apps/include
738738
DEPEND[rc4test]=../libcrypto.a libtestutil.a
739739

740-
SOURCE[rdrand_sanitytest]=rdrand_sanitytest.c
741-
INCLUDE[rdrand_sanitytest]=../include ../apps/include
742-
DEPEND[rdrand_sanitytest]=../libcrypto.a libtestutil.a
740+
SOURCE[rdcpu_sanitytest]=rdcpu_sanitytest.c
741+
INCLUDE[rdcpu_sanitytest]=../include ../apps/include ../crypto
742+
DEPEND[rdcpu_sanitytest]=../libcrypto.a libtestutil.a
743743

744744
SOURCE[rsa_sp800_56b_test]=rsa_sp800_56b_test.c
745745
INCLUDE[rsa_sp800_56b_test]=.. ../include ../crypto/rsa ../apps/include
Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,24 @@
1616
#if (defined(__i386) || defined(__i386__) || defined(_M_IX86) || \
1717
defined(__x86_64) || defined(__x86_64__) || \
1818
defined(_M_AMD64) || defined (_M_X64)) && defined(OPENSSL_CPUID_OBJ)
19-
19+
# define IS_X_86 1
2020
size_t OPENSSL_ia32_rdrand_bytes(unsigned char *buf, size_t len);
2121
size_t OPENSSL_ia32_rdseed_bytes(unsigned char *buf, size_t len);
22+
#else
23+
# define IS_X_86 0
24+
#endif
25+
26+
#if defined(__aarch64__)
27+
# define IS_AARCH_64 1
28+
# include "arm_arch.h"
29+
30+
size_t OPENSSL_rndr_bytes(unsigned char *buf, size_t len);
31+
size_t OPENSSL_rndrrs_bytes(unsigned char *buf, size_t len);
32+
#else
33+
# define IS_AARCH_64 0
34+
#endif
2235

36+
#if (IS_X_86 || IS_AARCH_64)
2337
static int sanity_check_bytes(size_t (*rng)(unsigned char *, size_t),
2438
int rounds, int min_failures, int max_retries, int max_zero_words)
2539
{
@@ -76,7 +90,9 @@ static int sanity_check_bytes(size_t (*rng)(unsigned char *, size_t),
7690
end:
7791
return testresult;
7892
}
93+
#endif
7994

95+
#if IS_X_86
8096
static int sanity_check_rdrand_bytes(void)
8197
{
8298
return sanity_check_bytes(OPENSSL_ia32_rdrand_bytes, 1000, 0, 10, 10);
@@ -92,11 +108,24 @@ static int sanity_check_rdseed_bytes(void)
92108
*/
93109
return sanity_check_bytes(OPENSSL_ia32_rdseed_bytes, 1000, 1, 10000, 10);
94110
}
111+
#elif IS_AARCH_64
112+
static int sanity_check_rndr_bytes(void)
113+
{
114+
return sanity_check_bytes(OPENSSL_rndr_bytes, 1000, 0, 10, 10);
115+
}
116+
117+
static int sanity_check_rndrrs_bytes(void)
118+
{
119+
return sanity_check_bytes(OPENSSL_rndrrs_bytes, 1000, 0, 10000, 10);
120+
}
121+
#endif
95122

96123
int setup_tests(void)
97124
{
125+
#if (IS_X_86 || IS_AARCH_64)
98126
OPENSSL_cpuid_setup();
99127

128+
# if IS_X_86
100129
int have_rdseed = (OPENSSL_ia32cap_P[2] & (1 << 18)) != 0;
101130
int have_rdrand = (OPENSSL_ia32cap_P[1] & (1 << (62 - 32))) != 0;
102131

@@ -107,16 +136,15 @@ int setup_tests(void)
107136
if (have_rdseed) {
108137
ADD_TEST(sanity_check_rdseed_bytes);
109138
}
139+
# elif IS_AARCH_64
140+
int have_rndr_rndrrs = (OPENSSL_armcap_P & (1 << 8)) != 0;
110141

111-
return 1;
112-
}
113-
114-
115-
#else
142+
if (have_rndr_rndrrs) {
143+
ADD_TEST(sanity_check_rndr_bytes);
144+
ADD_TEST(sanity_check_rndrrs_bytes);
145+
}
146+
# endif
147+
#endif
116148

117-
int setup_tests(void)
118-
{
119149
return 1;
120150
}
121-
122-
#endif
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use OpenSSL::Test; # get 'plan'
1313
use OpenSSL::Test::Simple;
1414
use OpenSSL::Test::Utils;
1515

16-
setup("test_rdrand_sanity");
16+
setup("test_rdcpu_sanity");
1717

1818
# We also need static builds to be enabled even on linux
1919
plan skip_all => "This test is unsupported if static builds are not enabled"
2020
if disabled("static");
2121

22-
simple_test("test_rdrand_sanity", "rdrand_sanitytest");
22+
simple_test("test_rdcpu_sanity", "rdcpu_sanitytest");

0 commit comments

Comments
 (0)