From 76a7be696c27b3f5e4b809cd4316169a826835a7 Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Sun, 30 May 2021 22:22:55 +0100 Subject: [PATCH] Fix non functional isaac prng Since at least 2013 (the initial nwipe commit), isaac has never functioned. When the issac prng was selected in the GUI, nwipe used the mersenne twister prng instead. Not that you would ever have known, as there were no log entries saying which prng was being actively used. However, I don't believe this was just an nwipe issue, looking at the code for DBAN's dwipe the same function nwipe_isaac_read( NWIPE_PRNG_READ_SIGNATURE ) exists as it does in nwipe. In both cases the function has no code that actually does anything. This patch populates this function and brings isaac back to life ! This bug was also responsible for verification errors when the option prng=isaac was used on the command line. Worse still, if you used prng=isaac on the command line then wiped using method=prng, no verification and no blanking you would expect to see random data. You don't, instead you would see either all zeros or mainly zeros because the uninitialised buffer that should have contained random data instead contained initialised text data such as partial log entries. This patch and previously submitted patches fix all these problems related to the isaac implementation. A separate commit will fix the GUI prng selection which was leading everybody to believe isaac was being used when in fact it was mersenne all along. --- src/isaac_rand/isaac_rand.h | 2 +- src/prng.c | 35 ++++++++++++++++++++++++----------- src/prng.h | 3 +++ src/version.c | 4 ++-- 4 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/isaac_rand/isaac_rand.h b/src/isaac_rand/isaac_rand.h index 4931bea..21accbf 100644 --- a/src/isaac_rand/isaac_rand.h +++ b/src/isaac_rand/isaac_rand.h @@ -16,7 +16,7 @@ MODIFIED: #ifndef RAND #define RAND -#define RANDSIZL (8) /* I recommend 8 for crypto, 4 for simulations */ +#define RANDSIZL (4) /* I recommend 8 for crypto, 4 for simulations */ #define RANDSIZ (1<randrsl[0], SIZE_OF_ISAAC ); + i = i + SIZE_OF_ISAAC; + } + + /* If there is some remainder copy only relevant number of bytes to not overflow the buffer. */ + if( remain > 0 ) + { + /* get the next 32bit random number */ + isaac( isaac_state ); + + nwipe_u32tobuffer( (u8*) ( buffer + i ), isaac_state->randrsl[0], SIZE_OF_ISAAC ); + } return 0; } diff --git a/src/prng.h b/src/prng.h index fe4398b..34d152a 100644 --- a/src/prng.h +++ b/src/prng.h @@ -54,4 +54,7 @@ int nwipe_isaac_read( NWIPE_PRNG_READ_SIGNATURE ); /* Size of the twister is not derived from the architecture, but it is strictly 4 bytes */ #define SIZE_OF_TWISTER 4 +/* Size of the isaac is not derived from the architecture, but it is strictly 4 bytes */ +#define SIZE_OF_ISAAC 4 + #endif /* PRNG_H_ */ diff --git a/src/version.c b/src/version.c index 6b2aa37..ec7bc11 100644 --- a/src/version.c +++ b/src/version.c @@ -4,7 +4,7 @@ * used by configure to dynamically assign those values * to documentation files. */ -const char* version_string = "0.30.007"; +const char* version_string = "0.30.008"; const char* program_name = "nwipe"; const char* author_name = "Martijn van Brummelen"; const char* email_address = "git@brumit.nl"; @@ -14,4 +14,4 @@ Modifications to original dwipe Copyright Andy Beverley \n\ This is free software; see the source for copying conditions.\n\ There is NO warranty; not even for MERCHANTABILITY or FITNESS\n\ FOR A PARTICULAR PURPOSE.\n"; -const char* banner = "nwipe 0.30.007"; +const char* banner = "nwipe 0.30.008";