Skip to content

Commit

Permalink
Add additional error message for prng
Browse files Browse the repository at this point in the history
Prior to this update any error produced by the nwipe_random_verify() or
nwipe_random_pass functions would be displayed in the GUI with a generic
message "IOERROR", while the details of the error would be displayed in
log file.

With this patch the GUI now displayes "I/O ERROR" for any read/write
errors, "PRNG ERROR" for all errors returned by the prng generators and
"FAILURE" for any signal errors.

The nwipe_random_verify() and nwipe_random_pass() functions previously
only returned a -1 to indicate some failure. They now return -1 for
read/write I/O errors and -2 for prng errors.

Identifing a prng error will be particulary important for an upcoming
commit related to the aes-ctr prng which calls external libraries.
  • Loading branch information
PartialVolume committed May 8, 2024
1 parent 9400ff5 commit 66b56f3
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 15 deletions.
24 changes: 21 additions & 3 deletions src/gui.c
Original file line number Diff line number Diff line change
Expand Up @@ -6598,9 +6598,27 @@ void* nwipe_gui_status( void* ptr )
}
else
{
wattron( main_window, COLOR_PAIR( 9 ) );
mvwprintw( main_window, yy++, 4, "(>>> IOERROR! <<<, code %i) ", c[i]->result );
wattroff( main_window, COLOR_PAIR( 9 ) );
switch( c[i]->result )
{
case -1:
wattron( main_window, COLOR_PAIR( 9 ) );
mvwprintw( main_window, yy++, 4, "(>>> I/O ERROR! <<<, code %i) ", c[i]->result );
wattroff( main_window, COLOR_PAIR( 9 ) );
break;

case -2:
wattron( main_window, COLOR_PAIR( 9 ) );
mvwprintw( main_window, yy++, 4, "(>>> PRNG ERROR! <<<, code %i) ", c[i]->result );
wattroff( main_window, COLOR_PAIR( 9 ) );
break;

default:
wattron( main_window, COLOR_PAIR( 9 ) );
mvwprintw(
main_window, yy++, 4, "(>>> SANITY ERROR! <<<, code %i) ", c[i]->result );
wattroff( main_window, COLOR_PAIR( 9 ) );
break;
}
}

} /* child returned */
Expand Down
44 changes: 32 additions & 12 deletions src/pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ int nwipe_random_verify( nwipe_context_t* c )
/**
* Verifies that a random pass was correctly written to the device.
*
* returns:
* 0 = Success
* -1 = I/O error
* -2 = PRNG error
*/

/* The result holder. */
Expand All @@ -59,14 +63,14 @@ int nwipe_random_verify( nwipe_context_t* c )

if( c->prng_seed.s == NULL )
{
nwipe_log( NWIPE_LOG_SANITY, "Null seed pointer." );
return -1;
nwipe_log( NWIPE_LOG_SANITY, "Null seed pointer on verification." );
return -2;
}

if( c->prng_seed.length <= 0 )
{
nwipe_log( NWIPE_LOG_SANITY, "The entropy length member is %i.", c->prng_seed.length );
return -1;
nwipe_log( NWIPE_LOG_SANITY, "On verification the entropy length member is %i.", c->prng_seed.length );
return -2;
}

/* Create the input buffer. */
Expand Down Expand Up @@ -133,7 +137,11 @@ int nwipe_random_verify( nwipe_context_t* c )
}

/* Reseed the PRNG. */
c->prng->init( &c->prng_state, &c->prng_seed );
if( c->prng->init( &c->prng_state, &c->prng_seed ) )
{
nwipe_log( NWIPE_LOG_ERROR, "Initialising PRNG failed on verification" );
return -2;
}

while( z > 0 )
{
Expand All @@ -154,7 +162,11 @@ int nwipe_random_verify( nwipe_context_t* c )
}

/* Fill the output buffer with the random pattern. */
c->prng->read( &c->prng_state, d, blocksize );
if( c->prng->read( &c->prng_state, d, blocksize ) )
{
nwipe_log( NWIPE_LOG_ERROR, "Reading PRNG failed on verification" );
return -2;
}

/* Read the buffer in from the device. */
r = read( c->device_fd, b, blocksize );
Expand Down Expand Up @@ -253,14 +265,14 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )

if( c->prng_seed.s == NULL )
{
nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: Null seed pointer." );
return -1;
nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: Null seed pointer on erasure" );
return -2;
}

if( c->prng_seed.length <= 0 )
{
nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: The entropy length member is %i.", c->prng_seed.length );
return -1;
nwipe_log( NWIPE_LOG_SANITY, "__FUNCTION__: On erasure the entropy length member is %i.", c->prng_seed.length );
return -2;
}

/* Create the initialised output buffer. Initialised because we don't want memory leaks
Expand All @@ -276,7 +288,11 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )
}

/* Seed the PRNG. */
c->prng->init( &c->prng_state, &c->prng_seed );
if( c->prng->init( &c->prng_state, &c->prng_seed ) )
{
nwipe_log( NWIPE_LOG_ERROR, "Initialising PRNG failed on erasure" );
return -2;
}

/* Reset the file pointer. */
offset = lseek( c->device_fd, 0, SEEK_SET );
Expand Down Expand Up @@ -319,7 +335,11 @@ int nwipe_random_pass( NWIPE_METHOD_SIGNATURE )
}

/* Fill the output buffer with the random pattern. */
c->prng->read( &c->prng_state, b, blocksize );
if( c->prng->read( &c->prng_state, b, blocksize ) )
{
nwipe_log( NWIPE_LOG_ERROR, "Reading PRNG failed during erasure" );
return -2;
}

/* For the first block only, check the prng actually wrote something to the buffer */
if( z == c->device_size )
Expand Down

0 comments on commit 66b56f3

Please sign in to comment.