From dcc41ce5c432a8641cdd278cc3ffb4eeb5fd5d8a Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 21 Apr 2015 09:28:15 +0200 Subject: [PATCH] build: avoid code breaking the aliasing regularly Upstream: no Just use libcrypto already. aes_prng.c: In function 'AES_SetKey': aes_prng.c:693:9: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] *((uint32_t*)tk[j]) = *((uint32_t*)k[j]); --- configure.ac | 1 + src/Makefile.am | 6 +++--- src/aes_prng.c | 18 +++++++++--------- 3 files changed, 13 insertions(+), 12 deletions(-) Index: chocolate-doom-2.1.0/configure.ac =================================================================== --- chocolate-doom-2.1.0.orig/configure.ac +++ chocolate-doom-2.1.0/configure.ac @@ -55,6 +55,7 @@ LDFLAGS="$LDFLAGS $SDL_LIBS" AC_SDL_MAIN_WORKAROUND([ + PKG_CHECK_MODULES([crypto], [libcrypto >= 0.9.7]) # Check for SDL_mixer. AC_CHECK_LIB(SDL_mixer,Mix_LoadMUS,[ Index: chocolate-doom-2.1.0/src/Makefile.am =================================================================== --- chocolate-doom-2.1.0.orig/src/Makefile.am +++ chocolate-doom-2.1.0/src/Makefile.am @@ -18,10 +18,10 @@ SETUP_BINARIES = @PROGRAM_PREFIX@doom-se execgames_SCRIPTS = $(SETUP_BINARIES) -AM_CFLAGS = -I$(top_builddir)/textscreen \ +AM_CPPFLAGS = -I$(top_builddir)/textscreen \ -I$(top_builddir)/opl \ -I$(top_builddir)/pcsound \ - @SDLMIXER_CFLAGS@ @SDLNET_CFLAGS@ + @SDLMIXER_CFLAGS@ @SDLNET_CFLAGS@ ${crypto_CFLAGS} # Common source files used by absolutely everything: @@ -150,7 +150,7 @@ EXTRA_LIBS = @LDFLAGS@ \ @SDL_LIBS@ \ @SDLMIXER_LIBS@ \ - @SDLNET_LIBS@ + @SDLNET_LIBS@ ${crypto_LIBS} if HAVE_WINDRES @PROGRAM_PREFIX@doom_SOURCES=$(SOURCE_FILES_WITH_DEH) resource.rc Index: chocolate-doom-2.1.0/src/aes_prng.c =================================================================== --- chocolate-doom-2.1.0.orig/src/aes_prng.c +++ chocolate-doom-2.1.0/src/aes_prng.c @@ -64,7 +64,9 @@ #include "aes_prng.h" #include "doomtype.h" #include "i_system.h" +#include +#ifdef AESPRNG #define MAXKC (256/32) #define MAXROUNDS 14 @@ -929,10 +931,11 @@ static char *AES_SelfTest(void) return NULL; } +#endif /* AESPRNG */ #ifndef TEST - static boolean prng_enabled = false; +#ifdef AESPRNG static RIJNDAEL_context prng_context; static uint32_t prng_input_counter; static uint32_t prng_values[4]; @@ -992,6 +995,7 @@ static void PRNG_Generate(void) prng_value_index = 0; } +#endif /* AESPRNG */ // Read a random 32-bit integer from the PRNG. @@ -1004,14 +1008,7 @@ unsigned int PRNG_Random(void) return 0; } - if (prng_value_index >= 4) - { - PRNG_Generate(); - } - - result = prng_values[prng_value_index]; - ++prng_value_index; - + RAND_pseudo_bytes((unsigned char *)&result, sizeof(result)); return result; } @@ -1020,6 +1017,7 @@ unsigned int PRNG_Random(void) int main(int argc, char *argv[]) { +#ifdef AESPRNG char *errormsg; errormsg = AES_SelfTest(); @@ -1034,6 +1032,8 @@ int main(int argc, char *argv[]) fprintf(stderr, "AES self test failed: %s\n", errormsg); return 1; } +#endif + return 0; } #endif