Use C99 designated initializers in a couple places
Some portions of libhcrypto are reused by other projects in diverse environments, including within operating system kernel modules. In some such build environments, hardening measures such as grsecurity can (randomly) reorder structure elements, so as to make it harder for an attacker to determine the offset from a known field's address to a different field that is needed for an attack. However, doing so requires the use of C99 designated initializers to make the source code compatible with such structure rearrangement, as opposed to the "traditional" C aggregate type initializers, which just list fields in order. This feature is also available as a GCC extension since early versions of GCC. However, it is not provided by many common versions of visual studio (and presumably also not by the vendor compiler for various commercial Unixes), so the traditional initializers must remain, behind a conditional. __GNUC__ or __STDC_VERSION__ >= 199901 should be enough to get most cases with support for designated initializers, at least for now. Signed-off-by: Nicolas Williams <nico@twosigma.com>
This commit is contained in:

committed by
Nicolas Williams

parent
44dec510fd
commit
aa87e08cc7
@@ -183,6 +183,16 @@ timer_status(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__GUNC__) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901)
|
||||
const RAND_METHOD hc_rand_timer_method = {
|
||||
.seed = timer_seed,
|
||||
.bytes = timer_bytes,
|
||||
.cleanup = timer_cleanup,
|
||||
.add = timer_add,
|
||||
.pseudorand = timer_pseudorand,
|
||||
.status = timer_status
|
||||
};
|
||||
#else
|
||||
const RAND_METHOD hc_rand_timer_method = {
|
||||
timer_seed,
|
||||
timer_bytes,
|
||||
@@ -191,6 +201,7 @@ const RAND_METHOD hc_rand_timer_method = {
|
||||
timer_pseudorand,
|
||||
timer_status
|
||||
};
|
||||
#endif
|
||||
|
||||
const RAND_METHOD *
|
||||
RAND_timer_method(void)
|
||||
|
Reference in New Issue
Block a user