From 3bcc544610bf6a5974cfab7036261fedb8ad8b98 Mon Sep 17 00:00:00 2001 From: PartialVolume Date: Sun, 5 Jan 2020 03:28:28 +0000 Subject: [PATCH 1/2] Fix percentage complete calculation. Also fixes OPSII method. Place round_size calculation in the function calculate_round_size() --- src/gui.c | 52 +++++++------- src/method.c | 189 +++++++++++++++++++++++++++++++++++++++++++++------ src/method.h | 2 + src/pass.c | 1 + 4 files changed, 198 insertions(+), 46 deletions(-) diff --git a/src/gui.c b/src/gui.c index 564c157..9542671 100644 --- a/src/gui.c +++ b/src/gui.c @@ -1983,6 +1983,7 @@ void *nwipe_gui_status( void *ptr ) else { + nwipe_active = compute_stats(ptr); // compute the final percentage completion value. if( c[i]->result == 0 ) { mvwprintw( main_window, yy++, 4, "[%05.2f%% complete, SUCCESS! ", c[i]->round_percent); } else if( c[i]->signal ) { mvwprintw( main_window, yy++, 4, "(>>> FAILURE! <<<, signal %i) ", c[i]->signal ); } else { mvwprintw( main_window, yy++, 4, "(>>>FAILURE!<<<, code %i) ", c[i]->result ); } @@ -2146,7 +2147,6 @@ void *nwipe_gui_status( void *ptr ) /* Test for a thread cancellation request */ pthread_testcancel(); - } // while if (nwipe_options.logfile[0] == '\0') @@ -2190,41 +2190,41 @@ int compute_stats(void *ptr) for( i = 0 ; i < count ; i++ ) { /* Check whether the child process is still running the wipe. */ -// if( c[i]->thread > 0 ) if( c[i]->wipe_status == 1 ) { /* Increment the child counter. */ nwipe_active += 1; + } - /* Maintain a rolling average of throughput. */ - nwipe_update_speedring( &c[i]->speedring, c[i]->round_done, nwipe_time_now ); + /* Even if the wipe has finished ALWAYS run the stats one last time so the final SUCCESS percentage value is correct. + * Maintain a rolling average of throughput. */ + nwipe_update_speedring( &c[i]->speedring, c[i]->round_done, nwipe_time_now ); - if( c[i]->speedring.timestotal > 0 ) + if( c[i]->speedring.timestotal > 0 ) + { + /* Update the current average throughput in bytes-per-second. */ + c[i]->throughput = c[i]->speedring.bytestotal / c[i]->speedring.timestotal; + + /* Update the estimated remaining runtime. */ + /* Check that throughput is not zero (sometimes caused during a sync) */ + if (c[i]->throughput == 0) { - /* Update the current average throughput in bytes-per-second. */ - c[i]->throughput = c[i]->speedring.bytestotal / c[i]->speedring.timestotal; - - /* Update the estimated remaining runtime. */ - /* Check that throughput is not zero (sometimes caused during a sync) */ - if (c[i]->throughput == 0) - { - c[i]->throughput = 1; - } - - c[i]->eta = ( c[i]->round_size - c[i]->round_done ) / c[i]->throughput; - - if( c[i]->eta > nwipe_misc_thread_data->maxeta ) - { - nwipe_misc_thread_data->maxeta = c[i]->eta; - } + c[i]->throughput = 1; } - /* Update the percentage value. */ - c[i]->round_percent = (double) c[i]->round_done / (double) c[i]->round_size * 100; + c[i]->eta = ( c[i]->round_size - c[i]->round_done ) / c[i]->throughput; - /* Accumulate combined throughput. */ - nwipe_misc_thread_data->throughput += c[i]->throughput; - } /* child running */ + if( c[i]->eta > nwipe_misc_thread_data->maxeta ) + { + nwipe_misc_thread_data->maxeta = c[i]->eta; + } + } + + /* Update the percentage value. */ + c[i]->round_percent = (double) c[i]->round_done / (double) c[i]->round_size * 100; + + /* Accumulate combined throughput. */ + nwipe_misc_thread_data->throughput += c[i]->throughput; /* Accumulate the error count. */ nwipe_misc_thread_data->errors += c[i]->pass_errors; diff --git a/src/method.c b/src/method.c index 727c61a..18fadbc 100644 --- a/src/method.c +++ b/src/method.c @@ -28,6 +28,7 @@ * 4. Call nwipe_runmethod() with your array of patterns. * 5. Copy-and-paste within the 'options.c' file so that the new method can be invoked. * 6. Optionally try to plug your function into 'gui.c'. + * 7. Update the function 'calculate_round_size()' with the new method. * * * WARNING: Remember to pad all pattern arrays with { 0, NULL }. @@ -556,7 +557,7 @@ void *nwipe_ops2( void *ptr ) patterns[q-1].s = NULL; /* Run the TSSIT OPS-II method. */ - r = nwipe_runmethod( c, patterns ); + c->result = nwipe_runmethod( c, patterns ); /* Release the random character buffer. */ free( s ); @@ -568,7 +569,6 @@ void *nwipe_ops2( void *ptr ) free( patterns ); /* We're done. */ - c->result = nwipe_runmethod( c, patterns ); /* Finished. Set the wipe_status flag so that the GUI knows */ c->wipe_status = 0; @@ -641,6 +641,8 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns ) /* Variable to track if it is the last pass */ int lastpass = 0; + + i = 0; /* The zero-fill pattern for the final pass of most methods. */ nwipe_pattern_t pattern_zero = { 1, "\x00" }; @@ -673,29 +675,16 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns ) c->pass_size *= 2; } - /* Tell the parent the number of rounds that will be run. */ c->round_count = nwipe_options.rounds; /* Set the number of bytes that will be written across all rounds. */ c->round_size = c->round_count * c->pass_size; + + /* For the selected method, calculate the correct round_size value (for correct percentage calculation) */ + calculate_round_size( c ); - /* The final pass is always a zero fill, except ops2 which is random. */ - /* Do not add if there is no blanking pass. */ - if ( nwipe_options.method == &nwipe_zero || nwipe_options.noblank == 0 ) - { - c->round_size += c->device_size; - } - - /* Set the round total count down */ - c->result = c->round_size; - - if((nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL) - && (nwipe_options.method == &nwipe_zero || nwipe_options.noblank == 0) ) - { - /* We must read back the last pass to verify it. */ - c->round_size += c->device_size; - } + c->result = c->round_size; /* If only verifing then the round size is the device size */ if(nwipe_options.method == &nwipe_verify) @@ -977,6 +966,166 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns ) return 0; } /* nwipe_runmethod */ - + +void calculate_round_size( nwipe_context_t* c ) +{ + /* This is where the round size is adjusted. round_size is used in the running percentage completion + * calculation. Adjustment the round size as pass_size and pass_count are not sufficient in + * always calculating round size correctly. To hopefully make this adjustment more + * understanable I have itemised the adjustments under each method. This should make it easier + * to add a new method here without breaking the calculations for other methods. + */ + + /* Don't change the order of these values as the case statements use their index in the array */ + void * array_methods[] = {&nwipe_zero, &nwipe_ops2, &nwipe_dodshort, &nwipe_dod522022m, &nwipe_gutmann, &nwipe_random, &nwipe_is5enh, NULL }; + int i; + + /* This while loop allows us to effectively create a const so we can use a case statement rather than if statements. + * This is probably more readable as more methods may get added in the future. The code could be condensed as some + * methods have identical adjustments, however as there are only a few methods I felt it was easier to understand as it is, + * however this could be changed if necessary. + */ + + int selected_method; + i = 0; + while ( array_methods[i] != NULL ) + { + if ( nwipe_options.method == array_methods[i] ) + { + selected_method = i; + } + i++; + } + + /* For each method create the correct round_size value */ + switch ( selected_method ) + { + case 0: + /* NWIPE_ZERO + * ---------- */ + /* pass size and pass count are both zero, so increase by device size, while + * selecting blanking in the GUI has no affect on this method so no need to + * increase round_size by device size. */ + + c->round_size += c->device_size; + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + break; + + case 1: + /* NWIPE_OPS2 + * ---------- */ + + /* Required for the 9th and final random pass */ + c->round_size += c->device_size; + + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + break; + + case 2: + /* DoD Short + * --------- */ + + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 3: + /* DOD 522022m + * ----------- */ + + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 4: + /* GutMann + * ------- */ + + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 5: + /* PRNG (random) + * ------------- */ + + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 6: + /* NWIPE_IS5ENH + * ------------ */ + + /* This method ALWAYS verifies the 3rd pass so increase by device size, + * and does not need to be increased by device size for VERIFY_ALL*/ + + c->round_size += c->device_size; + + if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if ( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + } +} /* eof */ diff --git a/src/method.h b/src/method.h index 5096780..cc05db7 100644 --- a/src/method.h +++ b/src/method.h @@ -55,6 +55,8 @@ void *nwipe_random( void *ptr ); void *nwipe_zero( void *ptr ); void *nwipe_verify( void *ptr ); +void calculate_round_size( nwipe_context_t* ); + #endif /* METHOD_H_ */ /* eof */ diff --git a/src/pass.c b/src/pass.c index 3bf6fc4..515f1f9 100644 --- a/src/pass.c +++ b/src/pass.c @@ -30,6 +30,7 @@ #include "options.h" #include "pass.h" #include "logging.h" +#include "gui.h" int nwipe_random_verify( nwipe_context_t* c ) From bc8cfeb47809ad17315b22b6ba13f61ff430d21c Mon Sep 17 00:00:00 2001 From: louib Date: Sun, 5 Jan 2020 13:08:46 -0500 Subject: [PATCH 2/2] formatting method and version module. --- .github/workflows/ci.yml | 2 +- .github/workflows/ci_ubuntu-16.04.yml | 2 +- src/method.c | 1793 +++++++++++++------------ src/method.h | 40 +- src/version.c | 18 +- src/version.h | 14 +- 6 files changed, 969 insertions(+), 900 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d10d1bf..aa679ef 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,4 +23,4 @@ jobs: - name: verifying code style # TODO use check-format when all the code has been formatted. # run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && make check-format - run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/nwipe.c src/nwipe.h src/options.c src/options.h && git diff-index --quiet HEAD + run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/nwipe.c src/nwipe.h src/options.c src/options.h src/version.h src/version.c src/method.h src/method.c && git diff-index --quiet HEAD diff --git a/.github/workflows/ci_ubuntu-16.04.yml b/.github/workflows/ci_ubuntu-16.04.yml index beffee3..bd1038b 100644 --- a/.github/workflows/ci_ubuntu-16.04.yml +++ b/.github/workflows/ci_ubuntu-16.04.yml @@ -23,4 +23,4 @@ jobs: - name: verifying code style # TODO use check-format when all the code has been formatted. # run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && make check-format - run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/nwipe.c src/nwipe.h src/options.c src/options.h && git diff-index --quiet HEAD + run: export PATH=$PATH:/usr/lib/llvm-5.0/bin && clang-format -i -style=file src/nwipe.c src/nwipe.h src/options.c src/options.h src/version.h src/version.c src/method.h src/method.c && git diff-index --quiet HEAD diff --git a/src/method.c b/src/method.c index 18fadbc..04e54ff 100644 --- a/src/method.c +++ b/src/method.c @@ -2,9 +2,9 @@ * method.c: Method implementations for nwipe. * * Copyright Darik Horn . - * + * * Modifications to original dwipe Copyright Andy Beverley - * + * * This program is free software; you can redistribute it and/or modify it under * the terms of the GNU General Public License as published by the Free Software * Foundation, version 2. @@ -16,10 +16,9 @@ * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ - /* HOWTO: Add another wipe method. * * 1. Create a new function here and add the prototype to the 'method.h' file. @@ -49,7 +48,6 @@ #include "pass.h" #include "logging.h" - /* * Comment Legend * @@ -61,1071 +59,1146 @@ */ const char* nwipe_dod522022m_label = "DoD 5220.22-M"; -const char* nwipe_dodshort_label = "DoD Short"; -const char* nwipe_gutmann_label = "Gutmann Wipe"; -const char* nwipe_ops2_label = "RCMP TSSIT OPS-II"; -const char* nwipe_random_label = "PRNG Stream"; -const char* nwipe_zero_label = "Zero Fill"; -const char* nwipe_verify_label = "Verify Blank"; -const char* nwipe_is5enh_label = "HMG IS5 Enhanced"; +const char* nwipe_dodshort_label = "DoD Short"; +const char* nwipe_gutmann_label = "Gutmann Wipe"; +const char* nwipe_ops2_label = "RCMP TSSIT OPS-II"; +const char* nwipe_random_label = "PRNG Stream"; +const char* nwipe_zero_label = "Zero Fill"; +const char* nwipe_verify_label = "Verify Blank"; +const char* nwipe_is5enh_label = "HMG IS5 Enhanced"; -const char* nwipe_unknown_label = "Unknown Method (FIXME)"; +const char* nwipe_unknown_label = "Unknown Method (FIXME)"; const char* nwipe_method_label( void* method ) { -/** - * Returns a pointer to the name of the method function. - * - */ + /** + * Returns a pointer to the name of the method function. + * + */ - if( method == &nwipe_dod522022m ) { return nwipe_dod522022m_label; } - if( method == &nwipe_dodshort ) { return nwipe_dodshort_label; } - if( method == &nwipe_gutmann ) { return nwipe_gutmann_label; } - if( method == &nwipe_ops2 ) { return nwipe_ops2_label; } - if( method == &nwipe_random ) { return nwipe_random_label; } - if( method == &nwipe_zero ) { return nwipe_zero_label; } - if( method == &nwipe_verify ) { return nwipe_verify_label; } - if( method == &nwipe_is5enh ) { return nwipe_is5enh_label; } + if( method == &nwipe_dod522022m ) + { + return nwipe_dod522022m_label; + } + if( method == &nwipe_dodshort ) + { + return nwipe_dodshort_label; + } + if( method == &nwipe_gutmann ) + { + return nwipe_gutmann_label; + } + if( method == &nwipe_ops2 ) + { + return nwipe_ops2_label; + } + if( method == &nwipe_random ) + { + return nwipe_random_label; + } + if( method == &nwipe_zero ) + { + return nwipe_zero_label; + } + if( method == &nwipe_verify ) + { + return nwipe_verify_label; + } + if( method == &nwipe_is5enh ) + { + return nwipe_is5enh_label; + } - /* else */ - return nwipe_unknown_label; + /* else */ + return nwipe_unknown_label; } /* nwipe_method_label */ - -void *nwipe_zero( void *ptr ) +void* nwipe_zero( void* ptr ) { -/** - * Fill the device with zeroes. - * - */ + /** + * Fill the device with zeroes. + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; - - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* Do nothing because nwipe_runmethod appends a zero-fill. */ - nwipe_pattern_t patterns [] = - { - { 0, NULL } - }; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - /* Run the method. */ - c->result = nwipe_runmethod( c, patterns ); + /* Do nothing because nwipe_runmethod appends a zero-fill. */ + nwipe_pattern_t patterns[] = {{0, NULL}}; - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Run the method. */ + c->result = nwipe_runmethod( c, patterns ); + + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_zero */ - - -void *nwipe_verify( void *ptr ) +void* nwipe_verify( void* ptr ) { -/** - * Fill the device with zeroes. - * - */ + /** + * Fill the device with zeroes. + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; - - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* Do nothing because nwipe_runmethod appends a zero-fill. */ - nwipe_pattern_t patterns [] = - { - { 0, NULL } - }; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - /* Run the method. */ - c->result = nwipe_runmethod( c, patterns ); + /* Do nothing because nwipe_runmethod appends a zero-fill. */ + nwipe_pattern_t patterns[] = {{0, NULL}}; - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Run the method. */ + c->result = nwipe_runmethod( c, patterns ); + + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_verify */ - - -void *nwipe_dod522022m( void *ptr ) +void* nwipe_dod522022m( void* ptr ) { -/** - * United States Department of Defense 5220.22-M standard wipe. - * - */ + /** + * United States Department of Defense 5220.22-M standard wipe. + * + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; - - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* A result holder. */ - int r; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - /* Random characters. (Elements 2 and 6 are unused.) */ - char dod [7]; + /* A result holder. */ + int r; - nwipe_pattern_t patterns [] = - { - { 1, &dod[0] }, /* Pass 1: A random character. */ - { 1, &dod[1] }, /* Pass 2: The bitwise complement of pass 1. */ - { -1, "" }, /* Pass 3: A random stream. */ - { 1, &dod[3] }, /* Pass 4: A random character. */ - { 1, &dod[4] }, /* Pass 5: A random character. */ - { 1, &dod[5] }, /* Pass 6: The bitwise complement of pass 5. */ - { -1, "" }, /* Pass 7: A random stream. */ - { 0, NULL } - }; + /* Random characters. (Elements 2 and 6 are unused.) */ + char dod[7]; - /* Load the array with random characters. */ - r = read( c->entropy_fd, &dod, sizeof( dod ) ); + nwipe_pattern_t patterns[] = {{1, &dod[0]}, // Pass 1: A random character. + {1, &dod[1]}, // Pass 2: The bitwise complement of pass 1. + {-1, ""}, // Pass 3: A random stream. + {1, &dod[3]}, // Pass 4: A random character. + {1, &dod[4]}, // Pass 5: A random character. + {1, &dod[5]}, // Pass 6: The bitwise complement of pass 5. + {-1, ""}, // Pass 7: A random stream. + {0, NULL}}; - /* NOTE: Only the random data in dod[0], dod[3], and dod[4] is actually used. */ + /* Load the array with random characters. */ + r = read( c->entropy_fd, &dod, sizeof( dod ) ); - /* Check the result. */ - if( r != sizeof( dod ) ) - { - r = errno; - nwipe_perror( r, __FUNCTION__, "read" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dod522022m_label ); + /* NOTE: Only the random data in dod[0], dod[3], and dod[4] is actually used. */ - /* Ensure a negative return. */ - if( r < 0 ) { c->result = r; return NULL; } - else { c->result = -1; return NULL; } + /* Check the result. */ + if( r != sizeof( dod ) ) + { + r = errno; + nwipe_perror( r, __FUNCTION__, "read" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dod522022m_label ); - } + /* Ensure a negative return. */ + if( r < 0 ) + { + c->result = r; + return NULL; + } + else + { + c->result = -1; + return NULL; + } + } - /* Pass 2 is the bitwise complement of Pass 1. */ - dod[1] = ~ dod[0]; + /* Pass 2 is the bitwise complement of Pass 1. */ + dod[1] = ~dod[0]; - /* Pass 4 is the bitwise complement of Pass 3. */ - dod[5] = ~ dod[4]; + /* Pass 4 is the bitwise complement of Pass 3. */ + dod[5] = ~dod[4]; - /* Run the DoD 5220.22-M method. */ - c->result = nwipe_runmethod( c, patterns ); + /* Run the DoD 5220.22-M method. */ + c->result = nwipe_runmethod( c, patterns ); - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_dod522022m */ - - -void *nwipe_dodshort( void *ptr ) +void* nwipe_dodshort( void* ptr ) { -/** - * United States Department of Defense 5220.22-M short wipe. - * This method is comprised of passes 1,2,7 from the standard wipe. - * - */ + /** + * United States Department of Defense 5220.22-M short wipe. + * This method is comprised of passes 1,2,7 from the standard wipe. + * + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; - - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; - - /* A result holder. */ - int r; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* Random characters. (Element 3 is unused.) */ - char dod [3]; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - nwipe_pattern_t patterns [] = - { - { 1, &dod[0] }, /* Pass 1: A random character. */ - { 1, &dod[1] }, /* Pass 2: The bitwise complement of pass 1. */ - { -1, "" }, /* Pass 3: A random stream. */ - { 0, NULL } - }; + /* A result holder. */ + int r; - /* Load the array with random characters. */ - r = read( c->entropy_fd, &dod, sizeof( dod ) ); + /* Random characters. (Element 3 is unused.) */ + char dod[3]; - /* NOTE: Only the random data in dod[0] is actually used. */ + nwipe_pattern_t patterns[] = {{1, &dod[0]}, // Pass 1: A random character. + {1, &dod[1]}, // Pass 2: The bitwise complement of pass 1. + {-1, ""}, // Pass 3: A random stream. + {0, NULL}}; - /* Check the result. */ - if( r != sizeof( dod ) ) - { - r = errno; - nwipe_perror( r, __FUNCTION__, "read" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dodshort_label ); + /* Load the array with random characters. */ + r = read( c->entropy_fd, &dod, sizeof( dod ) ); - /* Ensure a negative return. */ - if( r < 0 ) { c->result = r; return NULL; } - else { c->result = -1; return NULL; } + /* NOTE: Only the random data in dod[0] is actually used. */ - } + /* Check the result. */ + if( r != sizeof( dod ) ) + { + r = errno; + nwipe_perror( r, __FUNCTION__, "read" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dodshort_label ); - /* Pass 2 is the bitwise complement of Pass 1. */ - dod[1] = ~ dod[0]; + /* Ensure a negative return. */ + if( r < 0 ) + { + c->result = r; + return NULL; + } + else + { + c->result = -1; + return NULL; + } + } - /* Run the DoD 5220.022-M short method. */ - c->result = nwipe_runmethod( c, patterns ); + /* Pass 2 is the bitwise complement of Pass 1. */ + dod[1] = ~dod[0]; - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Run the DoD 5220.022-M short method. */ + c->result = nwipe_runmethod( c, patterns ); + + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_dodshort */ - - -void *nwipe_gutmann( void *ptr ) +void* nwipe_gutmann( void* ptr ) { -/** - * Peter Gutmann's wipe. - * - */ + /** + * Peter Gutmann's wipe. + * + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; - - /* A result buffer. */ - int r; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - /* The number of patterns in the Guttman Wipe, also used to index the 'patterns' array. */ - int i = 35; + /* A result buffer. */ + int r; - /* An index into the 'book' array. */ - int j; + /* The number of patterns in the Guttman Wipe, also used to index the 'patterns' array. */ + int i = 35; - /* The N-th element that has not been used. */ - int n; + /* An index into the 'book' array. */ + int j; - /* Define the Gutmann method. */ - nwipe_pattern_t book [] = - { - { -1, "" }, /* Random pass. */ - { -1, "" }, /* Random pass. */ - { -1, "" }, /* Random pass. */ - { -1, "" }, /* Random pass. */ - { 3, "\x55\x55\x55" }, /* Static pass: 0x555555 01010101 01010101 01010101 */ - { 3, "\xAA\xAA\xAA" }, /* Static pass: 0XAAAAAA 10101010 10101010 10101010 */ - { 3, "\x92\x49\x24" }, /* Static pass: 0x924924 10010010 01001001 00100100 */ - { 3, "\x49\x24\x92" }, /* Static pass: 0x492492 01001001 00100100 10010010 */ - { 3, "\x24\x92\x49" }, /* Static pass: 0x249249 00100100 10010010 01001001 */ - { 3, "\x00\x00\x00" }, /* Static pass: 0x000000 00000000 00000000 00000000 */ - { 3, "\x11\x11\x11" }, /* Static pass: 0x111111 00010001 00010001 00010001 */ - { 3, "\x22\x22\x22" }, /* Static pass: 0x222222 00100010 00100010 00100010 */ - { 3, "\x33\x33\x33" }, /* Static pass: 0x333333 00110011 00110011 00110011 */ - { 3, "\x44\x44\x44" }, /* Static pass: 0x444444 01000100 01000100 01000100 */ - { 3, "\x55\x55\x55" }, /* Static pass: 0x555555 01010101 01010101 01010101 */ - { 3, "\x66\x66\x66" }, /* Static pass: 0x666666 01100110 01100110 01100110 */ - { 3, "\x77\x77\x77" }, /* Static pass: 0x777777 01110111 01110111 01110111 */ - { 3, "\x88\x88\x88" }, /* Static pass: 0x888888 10001000 10001000 10001000 */ - { 3, "\x99\x99\x99" }, /* Static pass: 0x999999 10011001 10011001 10011001 */ - { 3, "\xAA\xAA\xAA" }, /* Static pass: 0xAAAAAA 10101010 10101010 10101010 */ - { 3, "\xBB\xBB\xBB" }, /* Static pass: 0xBBBBBB 10111011 10111011 10111011 */ - { 3, "\xCC\xCC\xCC" }, /* Static pass: 0xCCCCCC 11001100 11001100 11001100 */ - { 3, "\xDD\xDD\xDD" }, /* Static pass: 0xDDDDDD 11011101 11011101 11011101 */ - { 3, "\xEE\xEE\xEE" }, /* Static pass: 0xEEEEEE 11101110 11101110 11101110 */ - { 3, "\xFF\xFF\xFF" }, /* Static pass: 0xFFFFFF 11111111 11111111 11111111 */ - { 3, "\x92\x49\x24" }, /* Static pass: 0x924924 10010010 01001001 00100100 */ - { 3, "\x49\x24\x92" }, /* Static pass: 0x492492 01001001 00100100 10010010 */ - { 3, "\x24\x92\x49" }, /* Static pass: 0x249249 00100100 10010010 01001001 */ - { 3, "\x6D\xB6\xDB" }, /* Static pass: 0x6DB6DB 01101101 10110110 11011011 */ - { 3, "\xB6\xDB\x6D" }, /* Static pass: 0xB6DB6D 10110110 11011011 01101101 */ - { 3, "\xDB\x6D\xB6" }, /* Static pass: 0XDB6DB6 11011011 01101101 10110110 */ - { -1, "" }, /* Random pass. */ - { -1, "" }, /* Random pass. */ - { -1, "" }, /* Random pass. */ - { -1, "" }, /* Random pass. */ - { 0, NULL } - }; + /* The N-th element that has not been used. */ + int n; - /* Put the book array into this array in random order. */ - nwipe_pattern_t patterns [36]; + /* Define the Gutmann method. */ + nwipe_pattern_t book[] = {{-1, ""}, // Random pass. + {-1, ""}, // Random pass. + {-1, ""}, // Random pass. + {-1, ""}, // Random pass. + {3, "\x55\x55\x55"}, // Static pass: 0x555555 01010101 01010101 01010101 + {3, "\xAA\xAA\xAA"}, // Static pass: 0XAAAAAA 10101010 10101010 10101010 + {3, "\x92\x49\x24"}, // Static pass: 0x924924 10010010 01001001 00100100 + {3, "\x49\x24\x92"}, // Static pass: 0x492492 01001001 00100100 10010010 + {3, "\x24\x92\x49"}, // Static pass: 0x249249 00100100 10010010 01001001 + {3, "\x00\x00\x00"}, // Static pass: 0x000000 00000000 00000000 00000000 + {3, "\x11\x11\x11"}, // Static pass: 0x111111 00010001 00010001 00010001 + {3, "\x22\x22\x22"}, // Static pass: 0x222222 00100010 00100010 00100010 + {3, "\x33\x33\x33"}, // Static pass: 0x333333 00110011 00110011 00110011 + {3, "\x44\x44\x44"}, // Static pass: 0x444444 01000100 01000100 01000100 + {3, "\x55\x55\x55"}, // Static pass: 0x555555 01010101 01010101 01010101 + {3, "\x66\x66\x66"}, // Static pass: 0x666666 01100110 01100110 01100110 + {3, "\x77\x77\x77"}, // Static pass: 0x777777 01110111 01110111 01110111 + {3, "\x88\x88\x88"}, // Static pass: 0x888888 10001000 10001000 10001000 + {3, "\x99\x99\x99"}, // Static pass: 0x999999 10011001 10011001 10011001 + {3, "\xAA\xAA\xAA"}, // Static pass: 0xAAAAAA 10101010 10101010 10101010 + {3, "\xBB\xBB\xBB"}, // Static pass: 0xBBBBBB 10111011 10111011 10111011 + {3, "\xCC\xCC\xCC"}, // Static pass: 0xCCCCCC 11001100 11001100 11001100 + {3, "\xDD\xDD\xDD"}, // Static pass: 0xDDDDDD 11011101 11011101 11011101 + {3, "\xEE\xEE\xEE"}, // Static pass: 0xEEEEEE 11101110 11101110 11101110 + {3, "\xFF\xFF\xFF"}, // Static pass: 0xFFFFFF 11111111 11111111 11111111 + {3, "\x92\x49\x24"}, // Static pass: 0x924924 10010010 01001001 00100100 + {3, "\x49\x24\x92"}, // Static pass: 0x492492 01001001 00100100 10010010 + {3, "\x24\x92\x49"}, // Static pass: 0x249249 00100100 10010010 01001001 + {3, "\x6D\xB6\xDB"}, // Static pass: 0x6DB6DB 01101101 10110110 11011011 + {3, "\xB6\xDB\x6D"}, // Static pass: 0xB6DB6D 10110110 11011011 01101101 + {3, "\xDB\x6D\xB6"}, // Static pass: 0XDB6DB6 11011011 01101101 10110110 + {-1, ""}, // Random pass. + {-1, ""}, // Random pass. + {-1, ""}, // Random pass. + {-1, ""}, // Random pass. + {0, NULL}}; - /* An entropy buffer. */ - u16 s [i]; + /* Put the book array into this array in random order. */ + nwipe_pattern_t patterns[36]; - /* Load the array with random characters. */ - r = read( c->entropy_fd, &s, sizeof( s ) ); + /* An entropy buffer. */ + u16 s[i]; - if( r != sizeof( s ) ) - { - r = errno; - nwipe_perror( r, __FUNCTION__, "read" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_gutmann_label ); - - /* Ensure a negative return. */ - if( r < 0 ) { c->result = r; return NULL; } - else { c->result = -1; return NULL; } - } + /* Load the array with random characters. */ + r = read( c->entropy_fd, &s, sizeof( s ) ); + if( r != sizeof( s ) ) + { + r = errno; + nwipe_perror( r, __FUNCTION__, "read" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_gutmann_label ); - while( --i >= 0 ) - { + /* Ensure a negative return. */ + if( r < 0 ) + { + c->result = r; + return NULL; + } + else + { + c->result = -1; + return NULL; + } + } - /* Get a random integer that is less than the first index 'i'. */ - n = (int)( (double)( s[i] ) / (double)( 0x0000FFFF + 1 ) * (double)( i + 1 ) ); + while( --i >= 0 ) + { - /* Initialize the secondary index. */ - j = -1; + /* Get a random integer that is less than the first index 'i'. */ + n = (int) ( (double) ( s[i] ) / (double) ( 0x0000FFFF + 1 ) * (double) ( i + 1 ) ); - while( n-- >= 0 ) - { - /* Advance 'j' by 'n' positions... */ - j += 1; + /* Initialize the secondary index. */ + j = -1; - /* ... but don't count 'book' elements that have already been copied. */ - while( book[j].length == 0 ) { j += 1; } - } + while( n-- >= 0 ) + { + /* Advance 'j' by 'n' positions... */ + j += 1; - /* Copy the element. */ - patterns[i] = book[j]; + /* ... but don't count 'book' elements that have already been copied. */ + while( book[j].length == 0 ) + { + j += 1; + } + } - /* Mark this element as having been used. */ - book[j].length = 0; + /* Copy the element. */ + patterns[i] = book[j]; - nwipe_log( NWIPE_LOG_DEBUG, "nwipe_gutmann: Set patterns[%i] = book[%i].", i, j ); - } + /* Mark this element as having been used. */ + book[j].length = 0; - /* Ensure that the array is terminated. */ - patterns[35].length = 0; - patterns[35].s = NULL; + nwipe_log( NWIPE_LOG_DEBUG, "nwipe_gutmann: Set patterns[%i] = book[%i].", i, j ); + } - /* Run the Gutmann method. */ - c->result = nwipe_runmethod( c, patterns ); + /* Ensure that the array is terminated. */ + patterns[35].length = 0; + patterns[35].s = NULL; - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Run the Gutmann method. */ + c->result = nwipe_runmethod( c, patterns ); + + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_gutmann */ - - -void *nwipe_ops2( void *ptr ) +void* nwipe_ops2( void* ptr ) { -/** - * Royal Canadian Mounted Police - * Technical Security Standard for Information Technology - * Appendix OPS-II: Media Sanitization - * - * NOTE: The last pass of this method is specially handled by nwipe_runmethod. - * - */ + /** + * Royal Canadian Mounted Police + * Technical Security Standard for Information Technology + * Appendix OPS-II: Media Sanitization + * + * NOTE: The last pass of this method is specially handled by nwipe_runmethod. + * + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; - - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* A generic array index. */ - int i; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - /* A generic result buffer. */ - int r; + /* A generic array index. */ + int i; - /* A buffer for random characters. */ - char* s; + /* A generic result buffer. */ + int r; - /* A buffer for the bitwise complements of 's'. */ - char* t; + /* A buffer for random characters. */ + char* s; - /* The element count of 's' and 't'. */ - u32 u; + /* A buffer for the bitwise complements of 's'. */ + char* t; - /* The pattern array for this method is dynamically allocated. */ - nwipe_pattern_t* patterns; + /* The element count of 's' and 't'. */ + u32 u; - /* The element count of 'patterns'. */ - u32 q; + /* The pattern array for this method is dynamically allocated. */ + nwipe_pattern_t* patterns; + /* The element count of 'patterns'. */ + u32 q; - /* We need one random character per round. */ - u = 1 * nwipe_options.rounds; + /* We need one random character per round. */ + u = 1 * nwipe_options.rounds; - /* Allocate the array of random characters. */ - s = malloc( sizeof( char ) * u ); + /* Allocate the array of random characters. */ + s = malloc( sizeof( char ) * u ); - if( s == NULL ) - { - nwipe_perror( errno, __FUNCTION__, "malloc" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the random character array." ); - c->result = -1; - return NULL; - } + if( s == NULL ) + { + nwipe_perror( errno, __FUNCTION__, "malloc" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the random character array." ); + c->result = -1; + return NULL; + } - /* Allocate the array of complement characters. */ - t = malloc( sizeof( char ) * u ); + /* Allocate the array of complement characters. */ + t = malloc( sizeof( char ) * u ); - if( t == NULL ) - { - nwipe_perror( errno, __FUNCTION__, "malloc" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the complement character array." ); - c->result = -1; - free(s); - return NULL; - } + if( t == NULL ) + { + nwipe_perror( errno, __FUNCTION__, "malloc" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the complement character array." ); + c->result = -1; + free( s ); + return NULL; + } + /* We need eight pattern elements per round, plus one for padding. */ + q = 8 * u + 1; - /* We need eight pattern elements per round, plus one for padding. */ - q = 8 * u + 1; + /* Allocate the pattern array. */ + patterns = malloc( sizeof( nwipe_pattern_t ) * q ); - /* Allocate the pattern array. */ - patterns = malloc( sizeof( nwipe_pattern_t ) * q ); + if( patterns == NULL ) + { + nwipe_perror( errno, __FUNCTION__, "malloc" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the pattern array." ); + c->result = -1; + free( s ); + free( t ); + return NULL; + } - if( patterns == NULL ) - { - nwipe_perror( errno, __FUNCTION__, "malloc" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate the pattern array." ); - c->result = -1; - free(s); - free(t); - return NULL; - } + /* Load the array of random characters. */ + r = read( c->entropy_fd, s, u ); + if( r != u ) + { + r = errno; + nwipe_perror( r, __FUNCTION__, "read" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_ops2_label ); - /* Load the array of random characters. */ - r = read( c->entropy_fd, s, u ); + if( r < 0 ) + { + c->result = r; + free( s ); + free( t ); + free( patterns ); + return NULL; + } + else + { + c->result = -1; + free( s ); + free( t ); + free( patterns ); + return NULL; + } + } - if( r != u ) - { - r = errno; - nwipe_perror( r, __FUNCTION__, "read" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_ops2_label ); + for( i = 0; i < u; i += 1 ) + { + /* Populate the array of complements. */ + t[i] = ~s[i]; + } - if( r < 0 ) - { - c->result = r; - free(s); - free(t); - free(patterns); - return NULL; - } - else - { - c->result = -1; - free(s); - free(t); - free(patterns); - return NULL; - } + for( i = 0; i < u; i += 8 ) + { + /* Populate the array of patterns. */ - } + /* Even elements point to the random characters. */ + patterns[i * 4 + 0].length = 1; + patterns[i * 4 + 0].s = &s[i]; + patterns[i * 4 + 2].length = 1; + patterns[i * 4 + 2].s = &s[i]; + patterns[i * 4 + 4].length = 1; + patterns[i * 4 + 4].s = &s[i]; + patterns[i * 4 + 6].length = 1; + patterns[i * 4 + 6].s = &s[i]; + /* Odd elements point to the complement characters. */ + patterns[i * 4 + 1].length = 1; + patterns[i * 4 + 1].s = &t[i]; + patterns[i * 4 + 3].length = 1; + patterns[i * 4 + 3].s = &t[i]; + patterns[i * 4 + 5].length = 1; + patterns[i * 4 + 5].s = &t[i]; + patterns[i * 4 + 7].length = 1; + patterns[i * 4 + 7].s = &t[i]; + } - for( i = 0 ; i < u ; i += 1 ) - { - /* Populate the array of complements. */ - t[i] = ~s[i]; - } + /* Ensure that the array is terminated. */ + patterns[q - 1].length = 0; + patterns[q - 1].s = NULL; + /* Run the TSSIT OPS-II method. */ + c->result = nwipe_runmethod( c, patterns ); - for( i = 0 ; i < u ; i += 8 ) - { - /* Populate the array of patterns. */ + /* Release the random character buffer. */ + free( s ); - /* Even elements point to the random characters. */ - patterns[i*4 +0].length = 1; - patterns[i*4 +0].s = &s[i]; - patterns[i*4 +2].length = 1; - patterns[i*4 +2].s = &s[i]; - patterns[i*4 +4].length = 1; - patterns[i*4 +4].s = &s[i]; - patterns[i*4 +6].length = 1; - patterns[i*4 +6].s = &s[i]; + /* Release the complement character buffer */ + free( t ); - /* Odd elements point to the complement characters. */ - patterns[i*4 +1].length = 1; - patterns[i*4 +1].s = &t[i]; - patterns[i*4 +3].length = 1; - patterns[i*4 +3].s = &t[i]; - patterns[i*4 +5].length = 1; - patterns[i*4 +5].s = &t[i]; - patterns[i*4 +7].length = 1; - patterns[i*4 +7].s = &t[i]; - } + /* Release the pattern buffer. */ + free( patterns ); - /* Ensure that the array is terminated. */ - patterns[q-1].length = 0; - patterns[q-1].s = NULL; - - /* Run the TSSIT OPS-II method. */ - c->result = nwipe_runmethod( c, patterns ); + /* We're done. */ - /* Release the random character buffer. */ - free( s ); - - /* Release the complement character buffer */ - free( t ); - - /* Release the pattern buffer. */ - free( patterns ); - - /* We're done. */ - - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_ops2 */ -void *nwipe_is5enh( void *ptr ) +void* nwipe_is5enh( void* ptr ) { - nwipe_context_t *c = (nwipe_context_t *) ptr; - c->wipe_status = 1; + nwipe_context_t* c = (nwipe_context_t*) ptr; + c->wipe_status = 1; - char is5enh[3] = {'\x00', '\xFF', '\x00'}; - nwipe_pattern_t patterns[] = - { - { 1, &is5enh[0] }, /* Pass 1: 0s */ - { 1, &is5enh[1] }, /* Pass 2: 1s */ - { -1, &is5enh[2] }, /* Pass 3: random bytes with verification */ - { 0, NULL } - }; - c->result = nwipe_runmethod( c, patterns ); + char is5enh[3] = {'\x00', '\xFF', '\x00'}; + nwipe_pattern_t patterns[] = {{1, &is5enh[0]}, // Pass 1: 0s + {1, &is5enh[1]}, // Pass 2: 1s + {-1, &is5enh[2]}, // Pass 3: random bytes with verification + {0, NULL}}; + c->result = nwipe_runmethod( c, patterns ); - c->wipe_status = 0; - return NULL; + c->wipe_status = 0; + return NULL; } /* nwipe_is5enh */ -void *nwipe_random( void *ptr ) +void* nwipe_random( void* ptr ) { -/** - * Fill the device with a stream from the PRNG. - * - */ + /** + * Fill the device with a stream from the PRNG. + * + */ - nwipe_context_t *c; - c = (nwipe_context_t *) ptr; + nwipe_context_t* c; + c = (nwipe_context_t*) ptr; - /* set wipe in progress flag for GUI */ - c->wipe_status = 1; - - /* Define the random method. */ - nwipe_pattern_t patterns [] = - { - { -1, "" }, - { 0, NULL } - }; + /* set wipe in progress flag for GUI */ + c->wipe_status = 1; - /* Run the method. */ - c->result = nwipe_runmethod( c, patterns ); + /* Define the random method. */ + nwipe_pattern_t patterns[] = {{-1, ""}, {0, NULL}}; - /* Finished. Set the wipe_status flag so that the GUI knows */ - c->wipe_status = 0; + /* Run the method. */ + c->result = nwipe_runmethod( c, patterns ); + + /* Finished. Set the wipe_status flag so that the GUI knows */ + c->wipe_status = 0; return NULL; } /* nwipe_random */ - - int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns ) { -/** - * Writes patterns to the device. - * - */ + /** + * Writes patterns to the device. + * + */ - /* The result holder. */ - int r; + /* The result holder. */ + int r; - /* An index variable. */ - int i = 0; - - /* Variable to track if it is the last pass */ - int lastpass = 0; - - i = 0; + /* An index variable. */ + int i = 0; - /* The zero-fill pattern for the final pass of most methods. */ - nwipe_pattern_t pattern_zero = { 1, "\x00" }; + /* Variable to track if it is the last pass */ + int lastpass = 0; + i = 0; - /* Create the PRNG state buffer. */ - c->prng_seed.length = NWIPE_KNOB_PRNG_STATE_LENGTH; - c->prng_seed.s = malloc( c->prng_seed.length ); + /* The zero-fill pattern for the final pass of most methods. */ + nwipe_pattern_t pattern_zero = {1, "\x00"}; - /* Check the memory allocation. */ - if( ! c->prng_seed.s ) - { - nwipe_perror( errno, __FUNCTION__, "malloc" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate memory for the prng seed buffer." ); - return -1; - } + /* Create the PRNG state buffer. */ + c->prng_seed.length = NWIPE_KNOB_PRNG_STATE_LENGTH; + c->prng_seed.s = malloc( c->prng_seed.length ); - /* Count the number of patterns in the array. */ - while( patterns[i].length ) { i += 1; } - - /* Tell the parent the number of device passes that will be run in one round. */ - c->pass_count = i; + /* Check the memory allocation. */ + if( !c->prng_seed.s ) + { + nwipe_perror( errno, __FUNCTION__, "malloc" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to allocate memory for the prng seed buffer." ); + return -1; + } - /* Set the number of bytes that will be written across all passes in one round. */ - c->pass_size = c->pass_count * c->device_size; + /* Count the number of patterns in the array. */ + while( patterns[i].length ) + { + i += 1; + } - if( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - /* We must read back all passes, so double the byte count. */ - c->pass_size *= 2; - } + /* Tell the parent the number of device passes that will be run in one round. */ + c->pass_count = i; - /* Tell the parent the number of rounds that will be run. */ - c->round_count = nwipe_options.rounds; + /* Set the number of bytes that will be written across all passes in one round. */ + c->pass_size = c->pass_count * c->device_size; - /* Set the number of bytes that will be written across all rounds. */ - c->round_size = c->round_count * c->pass_size; - - /* For the selected method, calculate the correct round_size value (for correct percentage calculation) */ - calculate_round_size( c ); - - c->result = c->round_size; - - /* If only verifing then the round size is the device size */ - if(nwipe_options.method == &nwipe_verify) - { - c->round_size = c->device_size; - } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + /* We must read back all passes, so double the byte count. */ + c->pass_size *= 2; + } + /* Tell the parent the number of rounds that will be run. */ + c->round_count = nwipe_options.rounds; - /* Initialize the working round counter. */ - c->round_working = 0; + /* Set the number of bytes that will be written across all rounds. */ + c->round_size = c->round_count * c->pass_size; - nwipe_log( NWIPE_LOG_NOTICE, "Invoking method '%s' on device '%s'.", \ - nwipe_method_label( nwipe_options.method ), c->device_name ); + /* For the selected method, calculate the correct round_size value (for correct percentage calculation) */ + calculate_round_size( c ); - while( c->round_working < c->round_count ) - { - /* Increment the round counter. */ - c->round_working += 1; + c->result = c->round_size; - nwipe_log( NWIPE_LOG_NOTICE, "Starting round %i of %i on device '%s'.", \ - c->round_working, c->round_count, c->device_name ); + /* If only verifing then the round size is the device size */ + if( nwipe_options.method == &nwipe_verify ) + { + c->round_size = c->device_size; + } - /* Initialize the working pass counter. */ - c->pass_working = 0; + /* Initialize the working round counter. */ + c->round_working = 0; - for( i = 0 ; i < c->pass_count ; i++ ) - { - /* Increment the working pass. */ - c->pass_working += 1; - - /* Check if this is the last pass. */ - if( nwipe_options.verify == NWIPE_VERIFY_LAST && nwipe_options.method != &nwipe_ops2 ) - { - if( nwipe_options.noblank == 1 && c->round_working == c->round_count && c->pass_working == c->pass_count ) - { - lastpass = 1; - } - } + nwipe_log( NWIPE_LOG_NOTICE, + "Invoking method '%s' on device '%s'.", + nwipe_method_label( nwipe_options.method ), + c->device_name ); - nwipe_log( NWIPE_LOG_NOTICE, "Starting pass %i of %i, round %i of %i, on device '%s'.", \ - c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); + while( c->round_working < c->round_count ) + { + /* Increment the round counter. */ + c->round_working += 1; - if( patterns[i].length == 0 ) - { - /* Caught insanity. */ - nwipe_log( NWIPE_LOG_SANITY, "nwipe_runmethod: A non-terminating pattern element has zero length." ); - return -1; - } - - if( patterns[i].length > 0 ) - { + nwipe_log( NWIPE_LOG_NOTICE, + "Starting round %i of %i on device '%s'.", + c->round_working, + c->round_count, + c->device_name ); - /* Write a static pass. */ - c->pass_type = NWIPE_PASS_WRITE; - r = nwipe_static_pass( c, &patterns[i] ); - c->pass_type = NWIPE_PASS_NONE; + /* Initialize the working pass counter. */ + c->pass_working = 0; - /* Log number of bytes written to disk */ - nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", \ - c->pass_done, c->device_name ); - - /* Check for a fatal error. */ - if( r < 0 ) { return r; } - - if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1) - { + for( i = 0; i < c->pass_count; i++ ) + { + /* Increment the working pass. */ + c->pass_working += 1; - nwipe_log( NWIPE_LOG_NOTICE, "Verifying pass %i of %i, round %i of %i, on device '%s'.", \ - c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); + /* Check if this is the last pass. */ + if( nwipe_options.verify == NWIPE_VERIFY_LAST && nwipe_options.method != &nwipe_ops2 ) + { + if( nwipe_options.noblank == 1 && c->round_working == c->round_count + && c->pass_working == c->pass_count ) + { + lastpass = 1; + } + } - /* Verify this pass. */ - c->pass_type = NWIPE_PASS_VERIFY; - r = nwipe_static_verify( c, &patterns[i] ); - c->pass_type = NWIPE_PASS_NONE; - - /* Check for a fatal error. */ - if( r < 0 ) { return r; } + nwipe_log( NWIPE_LOG_NOTICE, + "Starting pass %i of %i, round %i of %i, on device '%s'.", + c->pass_working, + c->pass_count, + c->round_working, + c->round_count, + c->device_name ); - nwipe_log( NWIPE_LOG_NOTICE, "Verified pass %i of %i, round %i of %i, on device '%s'.", \ - c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); - } - - } /* static pass */ - - else - { - c->pass_type = NWIPE_PASS_WRITE; + if( patterns[i].length == 0 ) + { + /* Caught insanity. */ + nwipe_log( NWIPE_LOG_SANITY, "nwipe_runmethod: A non-terminating pattern element has zero length." ); + return -1; + } - /* Seed the PRNG. */ - r = read( c->entropy_fd, c->prng_seed.s, c->prng_seed.length ); - - /* Check the result. */ - if( r < 0 ) - { - c->pass_type = NWIPE_PASS_NONE; - nwipe_perror( errno, __FUNCTION__, "read" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the PRNG." ); - return -1; - } - - /* Check for a partial read. */ - if( r != c->prng_seed.length ) - { - /* TODO: Handle partial reads. */ - nwipe_log( NWIPE_LOG_FATAL, "Insufficient entropy is available." ); - return -1; - } - - /* Write the random pass. */ - r = nwipe_random_pass( c ); - c->pass_type = NWIPE_PASS_NONE; + if( patterns[i].length > 0 ) + { - /* Log number of bytes written to disk */ - nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", \ - c->pass_done, c->device_name ); + /* Write a static pass. */ + c->pass_type = NWIPE_PASS_WRITE; + r = nwipe_static_pass( c, &patterns[i] ); + c->pass_type = NWIPE_PASS_NONE; - /* Check for a fatal error. */ - if( r < 0 ) { return r; } - - /* Make sure IS5 enhanced always verifies its PRNG pass regardless */ - /* of the current combination of the --noblank (which influences */ - /* the lastpass variable) and --verify options. */ - if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1 || nwipe_options.method == &nwipe_is5enh ) - { - nwipe_log( NWIPE_LOG_NOTICE, "Verifying pass %i of %i, round %i of %i, on device '%s'.", \ - c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); + /* Log number of bytes written to disk */ + nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", c->pass_done, c->device_name ); - /* Verify this pass. */ - c->pass_type = NWIPE_PASS_VERIFY; - r = nwipe_random_verify( c ); - c->pass_type = NWIPE_PASS_NONE; - - /* Check for a fatal error. */ - if( r < 0 ) { return r; } + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } - nwipe_log( NWIPE_LOG_NOTICE, "Verified pass %i of %i, round %i of %i, on device '%s'.", \ - c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); - } - - } /* random pass */ - - nwipe_log( NWIPE_LOG_NOTICE, "Finished pass %i of %i, round %i of %i, on device '%s'.", \ - c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); + if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1 ) + { - } /* for passes */ + nwipe_log( NWIPE_LOG_NOTICE, + "Verifying pass %i of %i, round %i of %i, on device '%s'.", + c->pass_working, + c->pass_count, + c->round_working, + c->round_count, + c->device_name ); - nwipe_log( NWIPE_LOG_NOTICE, "Finished round %i of %i on device '%s'.", \ - c->round_working, c->round_count, c->device_name ); - - } /* while rounds */ + /* Verify this pass. */ + c->pass_type = NWIPE_PASS_VERIFY; + r = nwipe_static_verify( c, &patterns[i] ); + c->pass_type = NWIPE_PASS_NONE; + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } - if( nwipe_options.method == &nwipe_ops2 ) - { - /* NOTE: The OPS-II method specifically requires that a random pattern be left on the device. */ + nwipe_log( NWIPE_LOG_NOTICE, + "Verified pass %i of %i, round %i of %i, on device '%s'.", + c->pass_working, + c->pass_count, + c->round_working, + c->round_count, + c->device_name ); + } - /* Tell the parent that we are running the final pass. */ - c->pass_type = NWIPE_PASS_FINAL_OPS2; + } /* static pass */ - /* Seed the PRNG. */ - r = read( c->entropy_fd, c->prng_seed.s, c->prng_seed.length ); - - /* Check the result. */ - if( r < 0 ) - { - nwipe_perror( errno, __FUNCTION__, "read" ); - nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the PRNG." ); - return -1; - } - - /* Check for a partial read. */ - if( r != c->prng_seed.length ) - { - /* TODO: Handle partial reads. */ - nwipe_log( NWIPE_LOG_FATAL, "Insufficient entropy is available." ); - return -1; - } - - nwipe_log( NWIPE_LOG_NOTICE, "Writing final random pattern to '%s'.", c->device_name ); + else + { + c->pass_type = NWIPE_PASS_WRITE; - /* The final ops2 pass. */ - r = nwipe_random_pass( c ); + /* Seed the PRNG. */ + r = read( c->entropy_fd, c->prng_seed.s, c->prng_seed.length ); - /* Check for a fatal error. */ - if( r < 0 ) { return r; } + /* Check the result. */ + if( r < 0 ) + { + c->pass_type = NWIPE_PASS_NONE; + nwipe_perror( errno, __FUNCTION__, "read" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the PRNG." ); + return -1; + } - if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - nwipe_log( NWIPE_LOG_NOTICE, "Verifying the final random pattern on '%s' is empty.", c->device_name ); + /* Check for a partial read. */ + if( r != c->prng_seed.length ) + { + /* TODO: Handle partial reads. */ + nwipe_log( NWIPE_LOG_FATAL, "Insufficient entropy is available." ); + return -1; + } - /* Verify the final zero pass. */ - r = nwipe_random_verify( c ); + /* Write the random pass. */ + r = nwipe_random_pass( c ); + c->pass_type = NWIPE_PASS_NONE; - /* Check for a fatal error. */ - if( r < 0 ) { return r; } + /* Log number of bytes written to disk */ + nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", c->pass_done, c->device_name ); - nwipe_log( NWIPE_LOG_NOTICE, "Verified the final random pattern on '%s' is empty.", c->device_name ); - } + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } - nwipe_log( NWIPE_LOG_NOTICE, "Wrote final random pattern to '%s'.", c->device_name ); + /* Make sure IS5 enhanced always verifies its PRNG pass regardless */ + /* of the current combination of the --noblank (which influences */ + /* the lastpass variable) and --verify options. */ + if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1 || nwipe_options.method == &nwipe_is5enh ) + { + nwipe_log( NWIPE_LOG_NOTICE, + "Verifying pass %i of %i, round %i of %i, on device '%s'.", + c->pass_working, + c->pass_count, + c->round_working, + c->round_count, + c->device_name ); - } /* final ops2 */ - - else if ( nwipe_options.method == &nwipe_verify ) - { - nwipe_log( NWIPE_LOG_NOTICE, "Verifying that '%s' is empty.", c->device_name ); - - /* Verify the final zero pass. */ - c->pass_type = NWIPE_PASS_VERIFY; - r = nwipe_static_verify( c, &pattern_zero ); - c->pass_type = NWIPE_PASS_NONE; - - /* Check for a fatal error. */ - if( r < 0 ) { return r; } - - nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name ); - - } /* verify */ + /* Verify this pass. */ + c->pass_type = NWIPE_PASS_VERIFY; + r = nwipe_random_verify( c ); + c->pass_type = NWIPE_PASS_NONE; - else if ( nwipe_options.method == &nwipe_zero || nwipe_options.noblank == 0 ) - { - /* Tell the user that we are on the final pass. */ - c->pass_type = NWIPE_PASS_FINAL_BLANK; + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } - nwipe_log( NWIPE_LOG_NOTICE, "Blanking device '%s'.", c->device_name ); + nwipe_log( NWIPE_LOG_NOTICE, + "Verified pass %i of %i, round %i of %i, on device '%s'.", + c->pass_working, + c->pass_count, + c->round_working, + c->round_count, + c->device_name ); + } - /* The final zero pass. */ - r = nwipe_static_pass( c, &pattern_zero ); - - /* Check for a fatal error. */ - if( r < 0 ) { return r; } - - - if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - nwipe_log( NWIPE_LOG_NOTICE, "Verifying that '%s' is empty.", c->device_name ); - - /* Verify the final zero pass. */ - r = nwipe_static_verify( c, &pattern_zero ); - - /* Check for a fatal error. */ - if( r < 0 ) { return r; } - - nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name ); - } + } /* random pass */ - nwipe_log( NWIPE_LOG_NOTICE, "Blanked device '%s'.", c->device_name ); + nwipe_log( NWIPE_LOG_NOTICE, + "Finished pass %i of %i, round %i of %i, on device '%s'.", + c->pass_working, + c->pass_count, + c->round_working, + c->round_count, + c->device_name ); - } /* final blank */ - - /* Release the state buffer. */ - c->prng_seed.length = 0; - free( c->prng_seed.s ); - - /* Tell the parent that we have fininshed the final pass. */ - c->pass_type = NWIPE_PASS_NONE; + } /* for passes */ - if( c->verify_errors > 0 ) - { - /* We finished, but with non-fatal verification errors. */ - nwipe_log( NWIPE_LOG_ERROR, "%llu verification errors on device '%s'.", c->verify_errors, c->device_name ); - } + nwipe_log( NWIPE_LOG_NOTICE, + "Finished round %i of %i on device '%s'.", + c->round_working, + c->round_count, + c->device_name ); - if( c->pass_errors > 0 ) - { - /* We finished, but with non-fatal wipe errors. */ - nwipe_log( NWIPE_LOG_ERROR, "%llu wipe errors on device '%s'.", c->pass_errors, c->device_name ); - } + } /* while rounds */ - /* FIXME: The 'round_errors' context member is not being used. */ + if( nwipe_options.method == &nwipe_ops2 ) + { + /* NOTE: The OPS-II method specifically requires that a random pattern be left on the device. */ - if( c->pass_errors > 0 || c->round_errors > 0 || c->verify_errors > 0 ) - { - /* We finished, but with non-fatal errors. */ - return 1; - } - - /* We finished successfully. */ - return 0; + /* Tell the parent that we are running the final pass. */ + c->pass_type = NWIPE_PASS_FINAL_OPS2; + + /* Seed the PRNG. */ + r = read( c->entropy_fd, c->prng_seed.s, c->prng_seed.length ); + + /* Check the result. */ + if( r < 0 ) + { + nwipe_perror( errno, __FUNCTION__, "read" ); + nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the PRNG." ); + return -1; + } + + /* Check for a partial read. */ + if( r != c->prng_seed.length ) + { + /* TODO: Handle partial reads. */ + nwipe_log( NWIPE_LOG_FATAL, "Insufficient entropy is available." ); + return -1; + } + + nwipe_log( NWIPE_LOG_NOTICE, "Writing final random pattern to '%s'.", c->device_name ); + + /* The final ops2 pass. */ + r = nwipe_random_pass( c ); + + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } + + if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + nwipe_log( NWIPE_LOG_NOTICE, "Verifying the final random pattern on '%s' is empty.", c->device_name ); + + /* Verify the final zero pass. */ + r = nwipe_random_verify( c ); + + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } + + nwipe_log( NWIPE_LOG_NOTICE, "Verified the final random pattern on '%s' is empty.", c->device_name ); + } + + nwipe_log( NWIPE_LOG_NOTICE, "Wrote final random pattern to '%s'.", c->device_name ); + + } /* final ops2 */ + + else if( nwipe_options.method == &nwipe_verify ) + { + nwipe_log( NWIPE_LOG_NOTICE, "Verifying that '%s' is empty.", c->device_name ); + + /* Verify the final zero pass. */ + c->pass_type = NWIPE_PASS_VERIFY; + r = nwipe_static_verify( c, &pattern_zero ); + c->pass_type = NWIPE_PASS_NONE; + + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } + + nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name ); + + } /* verify */ + + else if( nwipe_options.method == &nwipe_zero || nwipe_options.noblank == 0 ) + { + /* Tell the user that we are on the final pass. */ + c->pass_type = NWIPE_PASS_FINAL_BLANK; + + nwipe_log( NWIPE_LOG_NOTICE, "Blanking device '%s'.", c->device_name ); + + /* The final zero pass. */ + r = nwipe_static_pass( c, &pattern_zero ); + + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } + + if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + nwipe_log( NWIPE_LOG_NOTICE, "Verifying that '%s' is empty.", c->device_name ); + + /* Verify the final zero pass. */ + r = nwipe_static_verify( c, &pattern_zero ); + + /* Check for a fatal error. */ + if( r < 0 ) + { + return r; + } + + nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name ); + } + + nwipe_log( NWIPE_LOG_NOTICE, "Blanked device '%s'.", c->device_name ); + + } /* final blank */ + + /* Release the state buffer. */ + c->prng_seed.length = 0; + free( c->prng_seed.s ); + + /* Tell the parent that we have fininshed the final pass. */ + c->pass_type = NWIPE_PASS_NONE; + + if( c->verify_errors > 0 ) + { + /* We finished, but with non-fatal verification errors. */ + nwipe_log( NWIPE_LOG_ERROR, "%llu verification errors on device '%s'.", c->verify_errors, c->device_name ); + } + + if( c->pass_errors > 0 ) + { + /* We finished, but with non-fatal wipe errors. */ + nwipe_log( NWIPE_LOG_ERROR, "%llu wipe errors on device '%s'.", c->pass_errors, c->device_name ); + } + + /* FIXME: The 'round_errors' context member is not being used. */ + + if( c->pass_errors > 0 || c->round_errors > 0 || c->verify_errors > 0 ) + { + /* We finished, but with non-fatal errors. */ + return 1; + } + + /* We finished successfully. */ + return 0; } /* nwipe_runmethod */ void calculate_round_size( nwipe_context_t* c ) { - /* This is where the round size is adjusted. round_size is used in the running percentage completion - * calculation. Adjustment the round size as pass_size and pass_count are not sufficient in - * always calculating round size correctly. To hopefully make this adjustment more - * understanable I have itemised the adjustments under each method. This should make it easier - * to add a new method here without breaking the calculations for other methods. - */ - - /* Don't change the order of these values as the case statements use their index in the array */ - void * array_methods[] = {&nwipe_zero, &nwipe_ops2, &nwipe_dodshort, &nwipe_dod522022m, &nwipe_gutmann, &nwipe_random, &nwipe_is5enh, NULL }; - int i; - - /* This while loop allows us to effectively create a const so we can use a case statement rather than if statements. - * This is probably more readable as more methods may get added in the future. The code could be condensed as some - * methods have identical adjustments, however as there are only a few methods I felt it was easier to understand as it is, - * however this could be changed if necessary. - */ + /* This is where the round size is adjusted. round_size is used in the running percentage completion + * calculation. Adjustment the round size as pass_size and pass_count are not sufficient in + * always calculating round size correctly. To hopefully make this adjustment more + * understanable I have itemised the adjustments under each method. This should make it easier + * to add a new method here without breaking the calculations for other methods. + */ - int selected_method; - i = 0; - while ( array_methods[i] != NULL ) - { - if ( nwipe_options.method == array_methods[i] ) - { - selected_method = i; - } - i++; - } + /* Don't change the order of these values as the case statements use their index in the array */ + void* array_methods[] = {&nwipe_zero, + &nwipe_ops2, + &nwipe_dodshort, + &nwipe_dod522022m, + &nwipe_gutmann, + &nwipe_random, + &nwipe_is5enh, + NULL}; + int i; - /* For each method create the correct round_size value */ - switch ( selected_method ) - { - case 0: - /* NWIPE_ZERO - * ---------- */ - /* pass size and pass count are both zero, so increase by device size, while - * selecting blanking in the GUI has no affect on this method so no need to - * increase round_size by device size. */ + /* This while loop allows us to effectively create a const so we can use a case statement rather than if statements. + * This is probably more readable as more methods may get added in the future. The code could be condensed as some + * methods have identical adjustments, however as there are only a few methods I felt it was easier to understand as + * it is, however this could be changed if necessary. + */ - c->round_size += c->device_size; - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - c->round_size += c->device_size; - } - break; + int selected_method; + i = 0; + while( array_methods[i] != NULL ) + { + if( nwipe_options.method == array_methods[i] ) + { + selected_method = i; + } + i++; + } - case 1: - /* NWIPE_OPS2 - * ---------- */ + /* For each method create the correct round_size value */ + switch( selected_method ) + { + case 0: + /* NWIPE_ZERO + * ---------- */ + /* pass size and pass count are both zero, so increase by device size, while + * selecting blanking in the GUI has no affect on this method so no need to + * increase round_size by device size. */ - /* Required for the 9th and final random pass */ - c->round_size += c->device_size; + c->round_size += c->device_size; + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + break; - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - c->round_size += c->device_size; - } - break; - - case 2: - /* DoD Short - * --------- */ + case 1: + /* NWIPE_OPS2 + * ---------- */ - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { + /* Required for the 9th and final random pass */ c->round_size += c->device_size; - } - if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.noblank == 0 ) - { - c->round_size += c->device_size; - } - break; - - case 3: - /* DOD 522022m - * ----------- */ - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.noblank == 0 ) - { - c->round_size += c->device_size; - } - break; - - case 4: - /* GutMann - * ------- */ + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + break; - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.noblank == 0 ) - { - c->round_size += c->device_size; - } - break; - - case 5: - /* PRNG (random) - * ------------- */ + case 2: + /* DoD Short + * --------- */ + + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 3: + /* DOD 522022m + * ----------- */ + + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 4: + /* GutMann + * ------- */ + + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 5: + /* PRNG (random) + * ------------- */ + + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.verify == NWIPE_VERIFY_ALL ) + { + c->round_size += c->device_size; + } + if( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + + case 6: + /* NWIPE_IS5ENH + * ------------ */ + + /* This method ALWAYS verifies the 3rd pass so increase by device size, + * and does not need to be increased by device size for VERIFY_ALL*/ - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { c->round_size += c->device_size; - } - if ( nwipe_options.verify == NWIPE_VERIFY_ALL ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.noblank == 0 ) - { - c->round_size += c->device_size; - } - break; - - case 6: - /* NWIPE_IS5ENH - * ------------ */ - - /* This method ALWAYS verifies the 3rd pass so increase by device size, - * and does not need to be increased by device size for VERIFY_ALL*/ - - c->round_size += c->device_size; - - if ( nwipe_options.verify == NWIPE_VERIFY_LAST ) - { - c->round_size += c->device_size; - } - if ( nwipe_options.noblank == 0 ) - { - c->round_size += c->device_size; - } - break; - } + + if( nwipe_options.verify == NWIPE_VERIFY_LAST ) + { + c->round_size += c->device_size; + } + if( nwipe_options.noblank == 0 ) + { + c->round_size += c->device_size; + } + break; + } } /* eof */ diff --git a/src/method.h b/src/method.h index cc05db7..76ac2a8 100644 --- a/src/method.h +++ b/src/method.h @@ -2,7 +2,7 @@ * methods.c: Method implementations for nwipe. * * Copyright Darik Horn . - * + * * Modifications to original dwipe Copyright Andy Beverley * * This program is free software; you can redistribute it and/or modify it under @@ -16,47 +16,43 @@ * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * */ - #ifndef METHOD_H_ #define METHOD_H_ /* The argument list for nwipe methods. */ #define NWIPE_METHOD_SIGNATURE nwipe_context_t* c -typedef enum nwipe_verify_t_ -{ - NWIPE_VERIFY_NONE = 0, /* Do not read anything back from the device. */ - NWIPE_VERIFY_LAST, /* Check the last pass. */ - NWIPE_VERIFY_ALL, /* Check all passes. */ +typedef enum nwipe_verify_t_ { + NWIPE_VERIFY_NONE = 0, // Do not read anything back from the device. + NWIPE_VERIFY_LAST, // Check the last pass. + NWIPE_VERIFY_ALL, // Check all passes. } nwipe_verify_t; /* The typedef of the function that will do the wipe. */ -typedef int(*nwipe_method_t)( void *ptr ); +typedef int ( *nwipe_method_t )( void* ptr ); -typedef struct /* nwipe_pattern_t */ +typedef struct { - int length; /* Length of the pattern in bytes, -1 means random. */ - char* s; /* The actual bytes of the pattern. */ + int length; // Length of the pattern in bytes, -1 means random. + char* s; // The actual bytes of the pattern. } nwipe_pattern_t; const char* nwipe_method_label( void* method ); int nwipe_runmethod( NWIPE_METHOD_SIGNATURE, nwipe_pattern_t* patterns ); -void *nwipe_dod522022m( void *ptr ); -void *nwipe_dodshort( void *ptr ); -void *nwipe_gutmann( void *ptr ); -void *nwipe_ops2( void *ptr ); -void *nwipe_is5enh( void *ptr ); -void *nwipe_random( void *ptr ); -void *nwipe_zero( void *ptr ); -void *nwipe_verify( void *ptr ); +void* nwipe_dod522022m( void* ptr ); +void* nwipe_dodshort( void* ptr ); +void* nwipe_gutmann( void* ptr ); +void* nwipe_ops2( void* ptr ); +void* nwipe_is5enh( void* ptr ); +void* nwipe_random( void* ptr ); +void* nwipe_zero( void* ptr ); +void* nwipe_verify( void* ptr ); void calculate_round_size( nwipe_context_t* ); #endif /* METHOD_H_ */ - -/* eof */ diff --git a/src/version.c b/src/version.c index b8a153c..74aa381 100644 --- a/src/version.c +++ b/src/version.c @@ -1,17 +1,17 @@ /** * version_string and program_name are used by siege - * and configure; author_name and email_address are - * used by configure to dynamically assign those values + * and configure; author_name and email_address are + * used by configure to dynamically assign those values * to documentation files. */ -const char *version_string = "0.27rc1"; -const char *program_name = "nwipe"; -const char *author_name = "Martijn van Brummelen"; -const char *email_address = "git@brumit.nl"; -const char *years = "2019"; -const char *copyright = "Copyright Darik Horn \n\ +const char* version_string = "0.27rc1"; +const char* program_name = "nwipe"; +const char* author_name = "Martijn van Brummelen"; +const char* email_address = "git@brumit.nl"; +const char* years = "2019"; +const char* copyright = "Copyright Darik Horn \n\ 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.27rc1"; +const char* banner = "nwipe 0.27rc1"; diff --git a/src/version.h b/src/version.h index 48999f0..b1214b2 100644 --- a/src/version.h +++ b/src/version.h @@ -1,11 +1,11 @@ #ifndef __VERSION_H #define __VERSION_H -extern char *version_string; -extern char *program_name; -extern char *author_name; -extern char *email_address; -extern char *copyright; -extern char *banner; +extern char* version_string; +extern char* program_name; +extern char* author_name; +extern char* email_address; +extern char* copyright; +extern char* banner; -#endif/*__VERSION_H*/ +#endif /*__VERSION_H*/