mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-07 00:46:17 +08:00
Update CMakeLists.txt
Check RDRAND symbols
This commit is contained in:
20
tools/rand.c
20
tools/rand.c
@@ -17,7 +17,7 @@
|
||||
#include <gmssl/rand.h>
|
||||
|
||||
|
||||
static const char *options = "[-hex] [-rdrand] -outlen num [-out file]";
|
||||
static const char *options = "[-hex] [-rdrand|-rdseed] -outlen num [-out file]";
|
||||
|
||||
int rand_main(int argc, char **argv)
|
||||
{
|
||||
@@ -25,6 +25,7 @@ int rand_main(int argc, char **argv)
|
||||
char *prog = argv[0];
|
||||
int hex = 0;
|
||||
int rdrand = 0;
|
||||
int rdseed = 0;
|
||||
int outlen = 0;
|
||||
char *outfile = NULL;
|
||||
FILE *outfp = stdout;
|
||||
@@ -47,6 +48,8 @@ int rand_main(int argc, char **argv)
|
||||
hex = 1;
|
||||
} else if (!strcmp(*argv, "-rdrand")) {
|
||||
rdrand = 1;
|
||||
} else if (!strcmp(*argv, "-rdseed")) {
|
||||
rdseed = 1;
|
||||
} else if (!strcmp(*argv, "-outlen")) {
|
||||
if (--argc < 1) goto bad;
|
||||
outlen = atoi(*(++argv));
|
||||
@@ -82,12 +85,23 @@ bad:
|
||||
size_t len = outlen < sizeof(buf) ? outlen : sizeof(buf);
|
||||
|
||||
if (rdrand) {
|
||||
/*
|
||||
#ifdef INTEL_RDRAND
|
||||
if (rdrand_bytes(buf, len) != 1) {
|
||||
fprintf(stderr, "%s: inner error\n", prog);
|
||||
goto end;
|
||||
}
|
||||
*/
|
||||
#else
|
||||
fprintf(stderr, "%s: `-rdrand` is not supported on your platform\n", prog);
|
||||
#endif
|
||||
} else if (rdseed) {
|
||||
#ifdef INTEL_RDSEED
|
||||
if (rdseed_bytes(buf, len) != 1) {
|
||||
fprintf(stderr, "%s: inner error\n", prog);
|
||||
goto end;
|
||||
}
|
||||
#else
|
||||
fprintf(stderr, "%s: `-rdseed` is not supported on your platform\n", prog);
|
||||
#endif
|
||||
} else {
|
||||
if (rand_bytes(buf, len) != 1) {
|
||||
fprintf(stderr, "%s: inner error\n", prog);
|
||||
|
||||
Reference in New Issue
Block a user