Add ABI tests for rdrand. This one is easy. For others we may wish to get in the habit of pulling assembly declarations into headers. Bug: 181 Change-Id: I24c774e3c9b1f983585b9828b0783ceddd08f0e7 Reviewed-on: https://boringssl-review.googlesource.com/c/33967 Commit-Queue: David Benjamin <davidben@google.com> Reviewed-by: Adam Langley <agl@google.com>
diff --git a/crypto/rand_extra/rand_test.cc b/crypto/rand_extra/rand_test.cc index 9ee3f26..9bc5d97 100644 --- a/crypto/rand_extra/rand_test.cc +++ b/crypto/rand_extra/rand_test.cc
@@ -14,10 +14,14 @@ #include <openssl/rand.h> +#include <stdio.h> + #include <gtest/gtest.h> +#include <openssl/cpu.h> #include <openssl/span.h> +#include "../test/abi_test.h" #include "../test/test_util.h" #if defined(OPENSSL_THREADS) @@ -28,7 +32,6 @@ #if !defined(OPENSSL_WINDOWS) #include <errno.h> -#include <stdio.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> @@ -183,4 +186,26 @@ // Draw entropy in parallel with lower concurrency than the previous maximum. RunConcurrentRands(kFewerThreads); } -#endif +#endif // OPENSSL_THREADS + +#if defined(OPENSSL_X86_64) && defined(SUPPORTS_ABI_TEST) +extern "C" { +int CRYPTO_rdrand(uint8_t out[8]); +int CRYPTO_rdrand_multiple8_buf(uint8_t *buf, size_t len); +} // extern "C" + +TEST(RandTest, RdrandABI) { + if ((OPENSSL_ia32cap_P[1] & (1u << 30)) == 0) { + fprintf(stderr, "rdrand not supported. Skipping.\n"); + return; + } + + uint8_t buf[32]; + CHECK_ABI(CRYPTO_rdrand, buf); + CHECK_ABI(CRYPTO_rdrand_multiple8_buf, nullptr, 0); + CHECK_ABI(CRYPTO_rdrand_multiple8_buf, buf, 8); + CHECK_ABI(CRYPTO_rdrand_multiple8_buf, buf, 16); + CHECK_ABI(CRYPTO_rdrand_multiple8_buf, buf, 24); + CHECK_ABI(CRYPTO_rdrand_multiple8_buf, buf, 32); +} +#endif // OPENSSL_X86_64 && SUPPORTS_ABI_TEST