Skip to content

Commit

Permalink
Update CMake options of RDRND
Browse files Browse the repository at this point in the history
Separate CMake option of rdrand and rdseed. In some CPUs only rdrand is supported.
  • Loading branch information
guanzhi committed Sep 9, 2023
1 parent 5ca0d60 commit ac61cfa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
16 changes: 11 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions include/gmssl/rdrand.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/rdrand.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -49,3 +50,4 @@ int rdseed_bytes(uint8_t *buf, size_t buflen)
}
return 1;
}
#endif

0 comments on commit ac61cfa

Please sign in to comment.