formatting method and version module.

This commit is contained in:
louib
2020-01-05 13:08:46 -05:00
parent cb4d411b05
commit bc8cfeb478
6 changed files with 969 additions and 900 deletions

View File

@@ -23,4 +23,4 @@ jobs:
- name: verifying code style - name: verifying code style
# TODO use check-format when all the code has been formatted. # 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 && 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

View File

@@ -23,4 +23,4 @@ jobs:
- name: verifying code style - name: verifying code style
# TODO use check-format when all the code has been formatted. # 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 && 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

View File

@@ -19,7 +19,6 @@
* 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. /* HOWTO: Add another wipe method.
* *
* 1. Create a new function here and add the prototype to the 'method.h' file. * 1. Create a new function here and add the prototype to the 'method.h' file.
@@ -49,7 +48,6 @@
#include "pass.h" #include "pass.h"
#include "logging.h" #include "logging.h"
/* /*
* Comment Legend * Comment Legend
* *
@@ -78,26 +76,48 @@ const char* nwipe_method_label( void* method )
* *
*/ */
if( method == &nwipe_dod522022m ) { return nwipe_dod522022m_label; } if( method == &nwipe_dod522022m )
if( method == &nwipe_dodshort ) { return nwipe_dodshort_label; } {
if( method == &nwipe_gutmann ) { return nwipe_gutmann_label; } return nwipe_dod522022m_label;
if( method == &nwipe_ops2 ) { return nwipe_ops2_label; } }
if( method == &nwipe_random ) { return nwipe_random_label; } if( method == &nwipe_dodshort )
if( method == &nwipe_zero ) { return nwipe_zero_label; } {
if( method == &nwipe_verify ) { return nwipe_verify_label; } return nwipe_dodshort_label;
if( method == &nwipe_is5enh ) { return nwipe_is5enh_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 */ /* else */
return nwipe_unknown_label; return nwipe_unknown_label;
} /* nwipe_method_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; nwipe_context_t* c;
@@ -107,10 +127,7 @@ void *nwipe_zero( void *ptr )
c->wipe_status = 1; c->wipe_status = 1;
/* Do nothing because nwipe_runmethod appends a zero-fill. */ /* Do nothing because nwipe_runmethod appends a zero-fill. */
nwipe_pattern_t patterns [] = nwipe_pattern_t patterns[] = {{0, NULL}};
{
{ 0, NULL }
};
/* Run the method. */ /* Run the method. */
c->result = nwipe_runmethod( c, patterns ); c->result = nwipe_runmethod( c, patterns );
@@ -121,13 +138,10 @@ void *nwipe_zero( void *ptr )
return NULL; return NULL;
} /* nwipe_zero */ } /* 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; nwipe_context_t* c;
@@ -137,10 +151,7 @@ void *nwipe_verify( void *ptr )
c->wipe_status = 1; c->wipe_status = 1;
/* Do nothing because nwipe_runmethod appends a zero-fill. */ /* Do nothing because nwipe_runmethod appends a zero-fill. */
nwipe_pattern_t patterns [] = nwipe_pattern_t patterns[] = {{0, NULL}};
{
{ 0, NULL }
};
/* Run the method. */ /* Run the method. */
c->result = nwipe_runmethod( c, patterns ); c->result = nwipe_runmethod( c, patterns );
@@ -151,8 +162,6 @@ void *nwipe_verify( void *ptr )
return NULL; return NULL;
} /* nwipe_verify */ } /* nwipe_verify */
void* nwipe_dod522022m( void* ptr ) void* nwipe_dod522022m( void* ptr )
{ {
/** /**
@@ -172,17 +181,14 @@ void *nwipe_dod522022m( void *ptr )
/* Random characters. (Elements 2 and 6 are unused.) */ /* Random characters. (Elements 2 and 6 are unused.) */
char dod[7]; char dod[7];
nwipe_pattern_t patterns [] = nwipe_pattern_t patterns[] = {{1, &dod[0]}, // Pass 1: A random character.
{ {1, &dod[1]}, // Pass 2: The bitwise complement of pass 1.
{ 1, &dod[0] }, /* Pass 1: A random character. */ {-1, ""}, // Pass 3: A random stream.
{ 1, &dod[1] }, /* Pass 2: The bitwise complement of pass 1. */ {1, &dod[3]}, // Pass 4: A random character.
{ -1, "" }, /* Pass 3: A random stream. */ {1, &dod[4]}, // Pass 5: A random character.
{ 1, &dod[3] }, /* Pass 4: A random character. */ {1, &dod[5]}, // Pass 6: The bitwise complement of pass 5.
{ 1, &dod[4] }, /* Pass 5: A random character. */ {-1, ""}, // Pass 7: A random stream.
{ 1, &dod[5] }, /* Pass 6: The bitwise complement of pass 5. */ {0, NULL}};
{ -1, "" }, /* Pass 7: A random stream. */
{ 0, NULL }
};
/* Load the array with random characters. */ /* Load the array with random characters. */
r = read( c->entropy_fd, &dod, sizeof( dod ) ); r = read( c->entropy_fd, &dod, sizeof( dod ) );
@@ -197,9 +203,16 @@ void *nwipe_dod522022m( void *ptr )
nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dod522022m_label ); nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dod522022m_label );
/* Ensure a negative return. */ /* Ensure a negative return. */
if( r < 0 ) { c->result = r; return NULL; } if( r < 0 )
else { c->result = -1; return NULL; } {
c->result = r;
return NULL;
}
else
{
c->result = -1;
return NULL;
}
} }
/* Pass 2 is the bitwise complement of Pass 1. */ /* Pass 2 is the bitwise complement of Pass 1. */
@@ -217,8 +230,6 @@ void *nwipe_dod522022m( void *ptr )
return NULL; return NULL;
} /* nwipe_dod522022m */ } /* nwipe_dod522022m */
void* nwipe_dodshort( void* ptr ) void* nwipe_dodshort( void* ptr )
{ {
/** /**
@@ -239,13 +250,10 @@ void *nwipe_dodshort( void *ptr )
/* Random characters. (Element 3 is unused.) */ /* Random characters. (Element 3 is unused.) */
char dod[3]; char dod[3];
nwipe_pattern_t patterns [] = nwipe_pattern_t patterns[] = {{1, &dod[0]}, // Pass 1: A random character.
{ {1, &dod[1]}, // Pass 2: The bitwise complement of pass 1.
{ 1, &dod[0] }, /* Pass 1: A random character. */ {-1, ""}, // Pass 3: A random stream.
{ 1, &dod[1] }, /* Pass 2: The bitwise complement of pass 1. */ {0, NULL}};
{ -1, "" }, /* Pass 3: A random stream. */
{ 0, NULL }
};
/* Load the array with random characters. */ /* Load the array with random characters. */
r = read( c->entropy_fd, &dod, sizeof( dod ) ); r = read( c->entropy_fd, &dod, sizeof( dod ) );
@@ -260,9 +268,16 @@ void *nwipe_dodshort( void *ptr )
nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dodshort_label ); nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_dodshort_label );
/* Ensure a negative return. */ /* Ensure a negative return. */
if( r < 0 ) { c->result = r; return NULL; } if( r < 0 )
else { c->result = -1; return NULL; } {
c->result = r;
return NULL;
}
else
{
c->result = -1;
return NULL;
}
} }
/* Pass 2 is the bitwise complement of Pass 1. */ /* Pass 2 is the bitwise complement of Pass 1. */
@@ -277,8 +292,6 @@ void *nwipe_dodshort( void *ptr )
return NULL; return NULL;
} /* nwipe_dodshort */ } /* nwipe_dodshort */
void* nwipe_gutmann( void* ptr ) void* nwipe_gutmann( void* ptr )
{ {
/** /**
@@ -305,45 +318,42 @@ void *nwipe_gutmann( void *ptr )
int n; int n;
/* Define the Gutmann method. */ /* Define the Gutmann method. */
nwipe_pattern_t book [] = nwipe_pattern_t book[] = {{-1, ""}, // Random pass.
{ {-1, ""}, // Random pass.
{ -1, "" }, /* Random pass. */ {-1, ""}, // Random pass.
{ -1, "" }, /* Random pass. */ {-1, ""}, // Random pass.
{ -1, "" }, /* Random pass. */ {3, "\x55\x55\x55"}, // Static pass: 0x555555 01010101 01010101 01010101
{ -1, "" }, /* Random pass. */ {3, "\xAA\xAA\xAA"}, // Static pass: 0XAAAAAA 10101010 10101010 10101010
{ 3, "\x55\x55\x55" }, /* Static pass: 0x555555 01010101 01010101 01010101 */ {3, "\x92\x49\x24"}, // Static pass: 0x924924 10010010 01001001 00100100
{ 3, "\xAA\xAA\xAA" }, /* Static pass: 0XAAAAAA 10101010 10101010 10101010 */ {3, "\x49\x24\x92"}, // Static pass: 0x492492 01001001 00100100 10010010
{ 3, "\x92\x49\x24" }, /* Static pass: 0x924924 10010010 01001001 00100100 */ {3, "\x24\x92\x49"}, // Static pass: 0x249249 00100100 10010010 01001001
{ 3, "\x49\x24\x92" }, /* Static pass: 0x492492 01001001 00100100 10010010 */ {3, "\x00\x00\x00"}, // Static pass: 0x000000 00000000 00000000 00000000
{ 3, "\x24\x92\x49" }, /* Static pass: 0x249249 00100100 10010010 01001001 */ {3, "\x11\x11\x11"}, // Static pass: 0x111111 00010001 00010001 00010001
{ 3, "\x00\x00\x00" }, /* Static pass: 0x000000 00000000 00000000 00000000 */ {3, "\x22\x22\x22"}, // Static pass: 0x222222 00100010 00100010 00100010
{ 3, "\x11\x11\x11" }, /* Static pass: 0x111111 00010001 00010001 00010001 */ {3, "\x33\x33\x33"}, // Static pass: 0x333333 00110011 00110011 00110011
{ 3, "\x22\x22\x22" }, /* Static pass: 0x222222 00100010 00100010 00100010 */ {3, "\x44\x44\x44"}, // Static pass: 0x444444 01000100 01000100 01000100
{ 3, "\x33\x33\x33" }, /* Static pass: 0x333333 00110011 00110011 00110011 */ {3, "\x55\x55\x55"}, // Static pass: 0x555555 01010101 01010101 01010101
{ 3, "\x44\x44\x44" }, /* Static pass: 0x444444 01000100 01000100 01000100 */ {3, "\x66\x66\x66"}, // Static pass: 0x666666 01100110 01100110 01100110
{ 3, "\x55\x55\x55" }, /* Static pass: 0x555555 01010101 01010101 01010101 */ {3, "\x77\x77\x77"}, // Static pass: 0x777777 01110111 01110111 01110111
{ 3, "\x66\x66\x66" }, /* Static pass: 0x666666 01100110 01100110 01100110 */ {3, "\x88\x88\x88"}, // Static pass: 0x888888 10001000 10001000 10001000
{ 3, "\x77\x77\x77" }, /* Static pass: 0x777777 01110111 01110111 01110111 */ {3, "\x99\x99\x99"}, // Static pass: 0x999999 10011001 10011001 10011001
{ 3, "\x88\x88\x88" }, /* Static pass: 0x888888 10001000 10001000 10001000 */ {3, "\xAA\xAA\xAA"}, // Static pass: 0xAAAAAA 10101010 10101010 10101010
{ 3, "\x99\x99\x99" }, /* Static pass: 0x999999 10011001 10011001 10011001 */ {3, "\xBB\xBB\xBB"}, // Static pass: 0xBBBBBB 10111011 10111011 10111011
{ 3, "\xAA\xAA\xAA" }, /* Static pass: 0xAAAAAA 10101010 10101010 10101010 */ {3, "\xCC\xCC\xCC"}, // Static pass: 0xCCCCCC 11001100 11001100 11001100
{ 3, "\xBB\xBB\xBB" }, /* Static pass: 0xBBBBBB 10111011 10111011 10111011 */ {3, "\xDD\xDD\xDD"}, // Static pass: 0xDDDDDD 11011101 11011101 11011101
{ 3, "\xCC\xCC\xCC" }, /* Static pass: 0xCCCCCC 11001100 11001100 11001100 */ {3, "\xEE\xEE\xEE"}, // Static pass: 0xEEEEEE 11101110 11101110 11101110
{ 3, "\xDD\xDD\xDD" }, /* Static pass: 0xDDDDDD 11011101 11011101 11011101 */ {3, "\xFF\xFF\xFF"}, // Static pass: 0xFFFFFF 11111111 11111111 11111111
{ 3, "\xEE\xEE\xEE" }, /* Static pass: 0xEEEEEE 11101110 11101110 11101110 */ {3, "\x92\x49\x24"}, // Static pass: 0x924924 10010010 01001001 00100100
{ 3, "\xFF\xFF\xFF" }, /* Static pass: 0xFFFFFF 11111111 11111111 11111111 */ {3, "\x49\x24\x92"}, // Static pass: 0x492492 01001001 00100100 10010010
{ 3, "\x92\x49\x24" }, /* Static pass: 0x924924 10010010 01001001 00100100 */ {3, "\x24\x92\x49"}, // Static pass: 0x249249 00100100 10010010 01001001
{ 3, "\x49\x24\x92" }, /* Static pass: 0x492492 01001001 00100100 10010010 */ {3, "\x6D\xB6\xDB"}, // Static pass: 0x6DB6DB 01101101 10110110 11011011
{ 3, "\x24\x92\x49" }, /* Static pass: 0x249249 00100100 10010010 01001001 */ {3, "\xB6\xDB\x6D"}, // Static pass: 0xB6DB6D 10110110 11011011 01101101
{ 3, "\x6D\xB6\xDB" }, /* Static pass: 0x6DB6DB 01101101 10110110 11011011 */ {3, "\xDB\x6D\xB6"}, // Static pass: 0XDB6DB6 11011011 01101101 10110110
{ 3, "\xB6\xDB\x6D" }, /* Static pass: 0xB6DB6D 10110110 11011011 01101101 */ {-1, ""}, // Random pass.
{ 3, "\xDB\x6D\xB6" }, /* Static pass: 0XDB6DB6 11011011 01101101 10110110 */ {-1, ""}, // Random pass.
{ -1, "" }, /* Random pass. */ {-1, ""}, // Random pass.
{ -1, "" }, /* Random pass. */ {-1, ""}, // Random pass.
{ -1, "" }, /* Random pass. */ {0, NULL}};
{ -1, "" }, /* Random pass. */
{ 0, NULL }
};
/* Put the book array into this array in random order. */ /* Put the book array into this array in random order. */
nwipe_pattern_t patterns[36]; nwipe_pattern_t patterns[36];
@@ -361,10 +371,17 @@ void *nwipe_gutmann( void *ptr )
nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_gutmann_label ); nwipe_log( NWIPE_LOG_FATAL, "Unable to seed the %s method.", nwipe_gutmann_label );
/* Ensure a negative return. */ /* Ensure a negative return. */
if( r < 0 ) { c->result = r; return NULL; } if( r < 0 )
else { c->result = -1; return NULL; } {
c->result = r;
return NULL;
}
else
{
c->result = -1;
return NULL;
}
} }
while( --i >= 0 ) while( --i >= 0 )
{ {
@@ -381,7 +398,10 @@ void *nwipe_gutmann( void *ptr )
j += 1; j += 1;
/* ... but don't count 'book' elements that have already been copied. */ /* ... but don't count 'book' elements that have already been copied. */
while( book[j].length == 0 ) { j += 1; } while( book[j].length == 0 )
{
j += 1;
}
} }
/* Copy the element. */ /* Copy the element. */
@@ -406,8 +426,6 @@ void *nwipe_gutmann( void *ptr )
return NULL; return NULL;
} /* nwipe_gutmann */ } /* nwipe_gutmann */
void* nwipe_ops2( void* ptr ) void* nwipe_ops2( void* ptr )
{ {
/** /**
@@ -446,7 +464,6 @@ void *nwipe_ops2( void *ptr )
/* The element count of 'patterns'. */ /* The element count of 'patterns'. */
u32 q; u32 q;
/* We need one random character per round. */ /* We need one random character per round. */
u = 1 * nwipe_options.rounds; u = 1 * nwipe_options.rounds;
@@ -473,7 +490,6 @@ void *nwipe_ops2( void *ptr )
return NULL; return NULL;
} }
/* We need eight pattern elements per round, plus one for padding. */ /* We need eight pattern elements per round, plus one for padding. */
q = 8 * u + 1; q = 8 * u + 1;
@@ -490,7 +506,6 @@ void *nwipe_ops2( void *ptr )
return NULL; return NULL;
} }
/* Load the array of random characters. */ /* Load the array of random characters. */
r = read( c->entropy_fd, s, u ); r = read( c->entropy_fd, s, u );
@@ -516,17 +531,14 @@ void *nwipe_ops2( void *ptr )
free( patterns ); free( patterns );
return NULL; return NULL;
} }
} }
for( i = 0; i < u; i += 1 ) for( i = 0; i < u; i += 1 )
{ {
/* Populate the array of complements. */ /* Populate the array of complements. */
t[i] = ~s[i]; t[i] = ~s[i];
} }
for( i = 0; i < u; i += 8 ) for( i = 0; i < u; i += 8 )
{ {
/* Populate the array of patterns. */ /* Populate the array of patterns. */
@@ -582,13 +594,10 @@ void *nwipe_is5enh( void *ptr )
c->wipe_status = 1; c->wipe_status = 1;
char is5enh[3] = {'\x00', '\xFF', '\x00'}; char is5enh[3] = {'\x00', '\xFF', '\x00'};
nwipe_pattern_t patterns[] = nwipe_pattern_t patterns[] = {{1, &is5enh[0]}, // Pass 1: 0s
{ {1, &is5enh[1]}, // Pass 2: 1s
{ 1, &is5enh[0] }, /* Pass 1: 0s */ {-1, &is5enh[2]}, // Pass 3: random bytes with verification
{ 1, &is5enh[1] }, /* Pass 2: 1s */ {0, NULL}};
{ -1, &is5enh[2] }, /* Pass 3: random bytes with verification */
{ 0, NULL }
};
c->result = nwipe_runmethod( c, patterns ); c->result = nwipe_runmethod( c, patterns );
c->wipe_status = 0; c->wipe_status = 0;
@@ -609,11 +618,7 @@ void *nwipe_random( void *ptr )
c->wipe_status = 1; c->wipe_status = 1;
/* Define the random method. */ /* Define the random method. */
nwipe_pattern_t patterns [] = nwipe_pattern_t patterns[] = {{-1, ""}, {0, NULL}};
{
{ -1, "" },
{ 0, NULL }
};
/* Run the method. */ /* Run the method. */
c->result = nwipe_runmethod( c, patterns ); c->result = nwipe_runmethod( c, patterns );
@@ -624,8 +629,6 @@ void *nwipe_random( void *ptr )
return NULL; return NULL;
} /* nwipe_random */ } /* nwipe_random */
int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns ) int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
{ {
/** /**
@@ -647,7 +650,6 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
/* The zero-fill pattern for the final pass of most methods. */ /* The zero-fill pattern for the final pass of most methods. */
nwipe_pattern_t pattern_zero = {1, "\x00"}; nwipe_pattern_t pattern_zero = {1, "\x00"};
/* Create the PRNG state buffer. */ /* Create the PRNG state buffer. */
c->prng_seed.length = NWIPE_KNOB_PRNG_STATE_LENGTH; c->prng_seed.length = NWIPE_KNOB_PRNG_STATE_LENGTH;
c->prng_seed.s = malloc( c->prng_seed.length ); c->prng_seed.s = malloc( c->prng_seed.length );
@@ -661,7 +663,10 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
} }
/* Count the number of patterns in the array. */ /* Count the number of patterns in the array. */
while( patterns[i].length ) { i += 1; } while( patterns[i].length )
{
i += 1;
}
/* Tell the parent the number of device passes that will be run in one round. */ /* Tell the parent the number of device passes that will be run in one round. */
c->pass_count = i; c->pass_count = i;
@@ -692,20 +697,24 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
c->round_size = c->device_size; c->round_size = c->device_size;
} }
/* Initialize the working round counter. */ /* Initialize the working round counter. */
c->round_working = 0; c->round_working = 0;
nwipe_log( NWIPE_LOG_NOTICE, "Invoking method '%s' on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
nwipe_method_label( nwipe_options.method ), c->device_name ); "Invoking method '%s' on device '%s'.",
nwipe_method_label( nwipe_options.method ),
c->device_name );
while( c->round_working < c->round_count ) while( c->round_working < c->round_count )
{ {
/* Increment the round counter. */ /* Increment the round counter. */
c->round_working += 1; c->round_working += 1;
nwipe_log( NWIPE_LOG_NOTICE, "Starting round %i of %i on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->round_working, c->round_count, c->device_name ); "Starting round %i of %i on device '%s'.",
c->round_working,
c->round_count,
c->device_name );
/* Initialize the working pass counter. */ /* Initialize the working pass counter. */
c->pass_working = 0; c->pass_working = 0;
@@ -718,14 +727,20 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
/* Check if this is the last pass. */ /* Check if this is the last pass. */
if( nwipe_options.verify == NWIPE_VERIFY_LAST && nwipe_options.method != &nwipe_ops2 ) 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 ) if( nwipe_options.noblank == 1 && c->round_working == c->round_count
&& c->pass_working == c->pass_count )
{ {
lastpass = 1; lastpass = 1;
} }
} }
nwipe_log( NWIPE_LOG_NOTICE, "Starting pass %i of %i, round %i of %i, on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); "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 );
if( patterns[i].length == 0 ) if( patterns[i].length == 0 )
{ {
@@ -743,17 +758,24 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
c->pass_type = NWIPE_PASS_NONE; c->pass_type = NWIPE_PASS_NONE;
/* Log number of bytes written to disk */ /* Log number of bytes written to disk */
nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", c->pass_done, c->device_name );
c->pass_done, c->device_name );
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1 ) if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1 )
{ {
nwipe_log( NWIPE_LOG_NOTICE, "Verifying pass %i of %i, round %i of %i, on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); "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 );
/* Verify this pass. */ /* Verify this pass. */
c->pass_type = NWIPE_PASS_VERIFY; c->pass_type = NWIPE_PASS_VERIFY;
@@ -761,10 +783,18 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
c->pass_type = NWIPE_PASS_NONE; c->pass_type = NWIPE_PASS_NONE;
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
nwipe_log( NWIPE_LOG_NOTICE, "Verified pass %i of %i, round %i of %i, on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); "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 */ } /* static pass */
@@ -798,19 +828,26 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
c->pass_type = NWIPE_PASS_NONE; c->pass_type = NWIPE_PASS_NONE;
/* Log number of bytes written to disk */ /* Log number of bytes written to disk */
nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE, "%llu bytes written to device '%s'.", c->pass_done, c->device_name );
c->pass_done, c->device_name );
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
/* Make sure IS5 enhanced always verifies its PRNG pass regardless */ /* Make sure IS5 enhanced always verifies its PRNG pass regardless */
/* of the current combination of the --noblank (which influences */ /* of the current combination of the --noblank (which influences */
/* the lastpass variable) and --verify options. */ /* the lastpass variable) and --verify options. */
if( nwipe_options.verify == NWIPE_VERIFY_ALL || lastpass == 1 || nwipe_options.method == &nwipe_is5enh ) 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'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); "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 );
/* Verify this pass. */ /* Verify this pass. */
c->pass_type = NWIPE_PASS_VERIFY; c->pass_type = NWIPE_PASS_VERIFY;
@@ -818,25 +855,40 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
c->pass_type = NWIPE_PASS_NONE; c->pass_type = NWIPE_PASS_NONE;
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
nwipe_log( NWIPE_LOG_NOTICE, "Verified pass %i of %i, round %i of %i, on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); "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 */ } /* random pass */
nwipe_log( NWIPE_LOG_NOTICE, "Finished pass %i of %i, round %i of %i, on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->pass_working, c->pass_count, c->round_working, c->round_count, c->device_name ); "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 );
} /* for passes */ } /* for passes */
nwipe_log( NWIPE_LOG_NOTICE, "Finished round %i of %i on device '%s'.", \ nwipe_log( NWIPE_LOG_NOTICE,
c->round_working, c->round_count, c->device_name ); "Finished round %i of %i on device '%s'.",
c->round_working,
c->round_count,
c->device_name );
} /* while rounds */ } /* while rounds */
if( nwipe_options.method == &nwipe_ops2 ) if( nwipe_options.method == &nwipe_ops2 )
{ {
/* NOTE: The OPS-II method specifically requires that a random pattern be left on the device. */ /* NOTE: The OPS-II method specifically requires that a random pattern be left on the device. */
@@ -869,7 +921,10 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
r = nwipe_random_pass( c ); r = nwipe_random_pass( c );
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL ) if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL )
{ {
@@ -879,7 +934,10 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
r = nwipe_random_verify( c ); r = nwipe_random_verify( c );
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } 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, "Verified the final random pattern on '%s' is empty.", c->device_name );
} }
@@ -898,7 +956,10 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
c->pass_type = NWIPE_PASS_NONE; c->pass_type = NWIPE_PASS_NONE;
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name ); nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name );
@@ -915,8 +976,10 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
r = nwipe_static_pass( c, &pattern_zero ); r = nwipe_static_pass( c, &pattern_zero );
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL ) if( nwipe_options.verify == NWIPE_VERIFY_LAST || nwipe_options.verify == NWIPE_VERIFY_ALL )
{ {
@@ -926,7 +989,10 @@ int nwipe_runmethod( nwipe_context_t* c, nwipe_pattern_t* patterns )
r = nwipe_static_verify( c, &pattern_zero ); r = nwipe_static_verify( c, &pattern_zero );
/* Check for a fatal error. */ /* Check for a fatal error. */
if( r < 0 ) { return r; } if( r < 0 )
{
return r;
}
nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name ); nwipe_log( NWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name );
} }
@@ -977,13 +1043,20 @@ void calculate_round_size( nwipe_context_t* c )
*/ */
/* Don't change the order of these values as the case statements use their index in the array */ /* 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 }; void* array_methods[] = {&nwipe_zero,
&nwipe_ops2,
&nwipe_dodshort,
&nwipe_dod522022m,
&nwipe_gutmann,
&nwipe_random,
&nwipe_is5enh,
NULL};
int i; int i;
/* This while loop allows us to effectively create a const so we can use a case statement rather than if statements. /* 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 * 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, * methods have identical adjustments, however as there are only a few methods I felt it was easier to understand as
* however this could be changed if necessary. * it is, however this could be changed if necessary.
*/ */
int selected_method; int selected_method;

View File

@@ -20,27 +20,25 @@
* *
*/ */
#ifndef METHOD_H_ #ifndef METHOD_H_
#define METHOD_H_ #define METHOD_H_
/* The argument list for nwipe methods. */ /* The argument list for nwipe methods. */
#define NWIPE_METHOD_SIGNATURE nwipe_context_t* c #define NWIPE_METHOD_SIGNATURE nwipe_context_t* c
typedef enum nwipe_verify_t_ typedef enum nwipe_verify_t_ {
{ NWIPE_VERIFY_NONE = 0, // Do not read anything back from the device.
NWIPE_VERIFY_NONE = 0, /* Do not read anything back from the device. */ NWIPE_VERIFY_LAST, // Check the last pass.
NWIPE_VERIFY_LAST, /* Check the last pass. */ NWIPE_VERIFY_ALL, // Check all passes.
NWIPE_VERIFY_ALL, /* Check all passes. */
} nwipe_verify_t; } nwipe_verify_t;
/* The typedef of the function that will do the wipe. */ /* 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. */ int length; // Length of the pattern in bytes, -1 means random.
char* s; /* The actual bytes of the pattern. */ char* s; // The actual bytes of the pattern.
} nwipe_pattern_t; } nwipe_pattern_t;
const char* nwipe_method_label( void* method ); const char* nwipe_method_label( void* method );
@@ -58,5 +56,3 @@ void *nwipe_verify( void *ptr );
void calculate_round_size( nwipe_context_t* ); void calculate_round_size( nwipe_context_t* );
#endif /* METHOD_H_ */ #endif /* METHOD_H_ */
/* eof */