commit 0d7839637a8c887d2a687f06f0a00a6b10d87a61
parent 0edb9ff9550500eb8f19385a5a8a8a815b887f01
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Sun, 14 May 2023 19:23:24 +0200
Use only internally the macro WITH_R123_AES
The macro was used in the public API header to conditionally set the
SSP_RNG_AES constant in the ssp_rng_type enumeration. Therefore, the
value of the following entries depended on this pre-processor constant
which could be activated/deactivated per file and moreover independently
of the fact that the library was compiled or not with the support of
this random generator. Consequently, the value of SSP_RNG_NULL could
vary within the same program.
In this commit, we completely suppress the use of this macro outside the
library and let the library itself return an error if the caller wants
to create an AES random number generator when it does not support it.
Diffstat:
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/src/ssp.h b/src/ssp.h
@@ -88,10 +88,8 @@ enum ssp_rng_type {
SSP_RNG_RANDOM_DEVICE,
/* Counter Based RNG threefry of Salmon, Moraes, Dror & Shaw */
SSP_RNG_THREEFRY,
-#ifdef WITH_R123_AES
/* Counter Based RNG aes of Salmon, Moraes, Dror & Shaw */
SSP_RNG_AES,
-#endif
SSP_RNG_TYPES_COUNT__,
SSP_RNG_TYPE_NULL = SSP_RNG_TYPES_COUNT__
};
diff --git a/src/test_ssp_rng.c b/src/test_ssp_rng.c
@@ -70,14 +70,18 @@ test_rng(const enum ssp_rng_type type)
CHK(ssp_rng_create(NULL, -1, &rng) == RES_BAD_ARG);
CHK(ssp_rng_create(&allocator, -1, &rng) == RES_BAD_ARG);
r = ssp_rng_create(NULL, type, &rng);
-#ifdef WITH_R123_AES
- if(r == RES_BAD_OP && type == SSP_RNG_AES) {
- printf("AES-NI instructions not available on this CPU and system.\n");
- mem_shutdown_proxy_allocator(&allocator);
- check_memory_allocator(&allocator);
- return;
+ if(type == SSP_RNG_AES) {
+ switch(r) {
+ case RES_BAD_ARG:
+ fprintf(stderr, "AES not supported\n");
+ break;
+ case RES_OK: /* Do nohting */ break;
+ case RES_BAD_OP:
+ fprintf(stderr, "AES-NI instructions not available.\n");
+ break;
+ default: FATAL("Unreachable code\n"); break;
+ }
}
-#endif
CHK(r == RES_OK);
CHK(ssp_rng_get_type(NULL, NULL) == RES_BAD_ARG);
@@ -222,9 +226,9 @@ test_rng(const enum ssp_rng_type type)
CHK(rn == datai0[i]);
}
}
-
+
/* Read the second state of the stream */
- CHK(ssp_rng_read(rng, stream) == (can_rw ? RES_OK : RES_BAD_OP));
+ CHK(ssp_rng_read(rng, stream) == (can_rw ? RES_OK : RES_BAD_OP));
if(can_rw) {
FOR_EACH(i, 0, NRAND) {
uint64_t rn = ssp_rng_get(rng);
@@ -258,11 +262,9 @@ int
main(int argc, char** argv)
{
if (argc <= 1) {
-#ifdef WITH_R123_AES
- fprintf(stderr, "Usage: %s <kiss|mt19937_64|ranlux48|random_device|threefry|aes>\n", argv[0]);
-#else
- fprintf(stderr, "Usage: %s <kiss|mt19937_64|ranlux48|random_device|threefry>\n", argv[0]);
-#endif
+ fprintf(stderr,
+ "Usage: %s <kiss|mt19937_64|ranlux48|random_device|threefry|aes>\n",
+ argv[0]);
exit(0);
}
if(!strcmp(argv[1], "kiss")) {
@@ -275,10 +277,8 @@ main(int argc, char** argv)
test_rng(SSP_RNG_RANDOM_DEVICE);
} else if(!strcmp(argv[1], "threefry")) {
test_rng(SSP_RNG_THREEFRY);
-#ifdef WITH_R123_AES
} else if(!strcmp(argv[1], "aes")) {
test_rng(SSP_RNG_AES);
-#endif
} else {
fprintf(stderr, "Unknown RNG `%s'\n", argv[1]);
ASSERT(0);