diff --git a/CMakeLists.txt b/CMakeLists.txt index 056e83cdc..e7d6b8437 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -256,16 +256,22 @@ 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) message(STATUS "ENABLE_GMT_0105_RNG") diff --git a/include/gmssl/rdrand.h b/include/gmssl/rdrand.h index b8930f420..61e034a1a 100644 --- a/include/gmssl/rdrand.h +++ b/include/gmssl/rdrand.h @@ -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 diff --git a/src/rdrand.c b/src/rdrand.c index 1dc3f8e1d..708ca6eba 100644 --- a/src/rdrand.c +++ b/src/rdrand.c @@ -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