Update CMake options of RDRND

Separate CMake option of rdrand and rdseed. In some CPUs only rdrand is supported.
This commit is contained in:
Zhi Guan
2023-09-09 16:56:52 +08:00
parent 5ca0d60781
commit ac61cfae02
3 changed files with 16 additions and 5 deletions

View File

@@ -256,15 +256,21 @@ if (ENABLE_BROKEN_CRYPTO)
endif()
option(ENABLE_RDRND "Enable Intel RDRND instructions" OFF)
option(ENABLE_INTEL_RDRAND "Enable Intel RDRAND instructions" OFF)
option(ENABLE_INTEL_RDSEED "Enable Intel RDSEED instructions" OFF)
if (${CMAKE_SYSTEM_PROCESSOR} MATCHES x86_64)
set(ENABLE_RDRND ON)
set(ENABLE_INTEL_RDRAND ON)
endif()
if (ENABLE_RDRND)
message(STATUS "ENABLE_RDRND")
if (ENABLE_INTEL_RDRAND)
message(STATUS "ENABLE_INTEL_RDRAND")
list(APPEND src src/rdrand.c)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mrdrnd -mrdseed")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mrdrnd")
if (ENABLE_INTEL_RDSEED)
add_definitions(-DINTEL_RDSEED)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mrdseed")
endif()
endif()
option(ENABLE_GMT_0105_RNG "Enable GM/T 0105 Software RNG" OFF)
if (ENABLE_GMT_0105_RNG)

View File

@@ -21,7 +21,10 @@ extern "C" {
int rdrand_bytes(uint8_t *buf, size_t buflen);
#ifdef INTEL_RDSEED
int rdseed_bytes(uint8_t *buf, size_t buflen);
#endif
#ifdef __cplusplus

View File

@@ -32,6 +32,7 @@ int rdrand_bytes(uint8_t *buf, size_t buflen)
return 1;
}
#ifdef INTEL_RDSEED
int rdseed_bytes(uint8_t *buf, size_t buflen)
{
unsigned long long val;
@@ -49,3 +50,4 @@ int rdseed_bytes(uint8_t *buf, size_t buflen)
}
return 1;
}
#endif