-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmethod.c
More file actions
797 lines (594 loc) · 21.9 KB
/
method.c
File metadata and controls
797 lines (594 loc) · 21.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
/*
* method.c: Method implementations for dwipe.
*
* Copyright Darik Horn <dajhorn-dban@vanadac.com>.
*
* 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.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* 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., 675 Mass
* Ave, Cambridge, MA 02139, USA.
*/
/* HOWTO: Add another wipe method.
*
* 1. Create a new function here and add the prototype to the 'dwipe.h' file.
* 2. Update dwipe_method_label() appropriately.
* 3. Put the passes that you wish to run into a dwipe_patterns_t array.
* 4. Call dwipe_runmethod() with your array of patterns.
* 5. Cut-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'.
*
*
* WARNING: Remember to pad all pattern arrays with { 0, NULL }.
*
* WARNING: Never change dwipe_options after calling a method.
*
* NOTE: The dwipe_runmethod function appends a final pass to all methods.
*
*/
#include "dwipe.h"
#include "context.h"
#include "method.h"
#include "prng.h"
#include "options.h"
#include "pass.h"
#include "logging.h"
/*
* Comment Legend
*
* "method" An ordered set of patterns.
* "pattern" The magic bits that will be written to a device.
* "pass" Reading or writing one pattern to an entire device.
* "rounds" The number of times that a method will be applied to a device.
*
*/
const char* dwipe_dod522022m_label = "DoD 5220.22-M";
const char* dwipe_dodshort_label = "DoD Short";
const char* dwipe_gutmann_label = "Gutmann Wipe";
const char* dwipe_ops2_label = "RCMP TSSIT OPS-II";
const char* dwipe_random_label = "PRNG Stream";
const char* dwipe_zero_label = "Quick Erase";
const char* dwipe_unknown_label = "Unknown Method (FIXME)";
const char* dwipe_method_label( dwipe_method_t method )
{
/**
* Returns a pointer to the name of the method function.
*
*/
if( method == &dwipe_dod522022m ) { return dwipe_dod522022m_label; }
if( method == &dwipe_dodshort ) { return dwipe_dodshort_label; }
if( method == &dwipe_gutmann ) { return dwipe_gutmann_label; }
if( method == &dwipe_ops2 ) { return dwipe_ops2_label; }
if( method == &dwipe_random ) { return dwipe_random_label; }
if( method == &dwipe_zero ) { return dwipe_zero_label; }
/* else */
return dwipe_unknown_label;
} /* dwipe_method_label */
int dwipe_zero( DWIPE_METHOD_SIGNATURE )
{
/**
* Fill the device with zeroes.
*
*/
/* Do nothing because dwipe_runmethod appends a zero-fill. */
dwipe_pattern_t patterns [] =
{
{ 0, NULL }
};
/* Run the method. */
return dwipe_runmethod( c, patterns );
} /* dwipe_zero */
int dwipe_dod522022m( DWIPE_METHOD_SIGNATURE )
{
/**
* United States Department of Defense 5220.22-M standard wipe.
*
*/
/* A result holder. */
int r;
/* Random characters. (Elements 2 and 6 are unused.) */
char dod [7];
dwipe_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 }
};
/* Load the array with random characters. */
r = read( c->entropy_fd, &dod, sizeof( dod ) );
/* NOTE: Only the random data in dod[0], dod[3], and dod[4] is actually used. */
/* Check the result. */
if( r != sizeof( dod ) )
{
r = errno;
dwipe_perror( r, __FUNCTION__, "read" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the %s method.", dwipe_dod522022m_label );
/* Ensure a negative return. */
if( r < 0 ) { return r; }
else { return -1; }
}
/* 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];
/* Run the DoD 5220.22-M method. */
return dwipe_runmethod( c, patterns );
} /* dwipe_dod522022m */
int dwipe_dodshort( DWIPE_METHOD_SIGNATURE )
{
/**
* United States Department of Defense 5220.22-M short wipe.
* This method is comprised of passes 1,2,7 from the standard wipe.
*
*/
/* A result holder. */
int r;
/* Random characters. (Element 3 is unused.) */
char dod [3];
dwipe_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 }
};
/* Load the array with random characters. */
r = read( c->entropy_fd, &dod, sizeof( dod ) );
/* NOTE: Only the random data in dod[0] is actually used. */
/* Check the result. */
if( r != sizeof( dod ) )
{
r = errno;
dwipe_perror( r, __FUNCTION__, "read" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the %s method.", dwipe_dodshort_label );
/* Ensure a negative return. */
if( r < 0 ) { return r; }
else { return -1; }
}
/* Pass 2 is the bitwise complement of Pass 1. */
dod[1] = ~ dod[0];
/* Run the DoD 5220.022-M short method. */
return dwipe_runmethod( c, patterns );
} /* dwipe_dodshort */
int dwipe_gutmann( DWIPE_METHOD_SIGNATURE )
{
/**
* Peter Gutmann's wipe.
*
*/
/* A result buffer. */
int r;
/* The number of patterns in the Guttman Wipe, also used to index the 'patterns' array. */
int i = 35;
/* An index into the 'book' array. */
int j;
/* The N-th element that has not been used. */
int n;
/* Define the Gutmann method. */
dwipe_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 }
};
/* Put the book array into this array in random order. */
dwipe_pattern_t patterns [36];
/* An entropy buffer. */
u16 s [i];
/* Load the array with random characters. */
r = read( c->entropy_fd, &s, sizeof( s ) );
if( r != sizeof( s ) )
{
r = errno;
dwipe_perror( r, __FUNCTION__, "read" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the %s method.", dwipe_gutmann_label );
/* Ensure a negative return. */
if( r < 0 ) { return r; }
else { return -1; }
}
while( --i >= 0 )
{
/* Get a random integer that is less than the first index 'i'. */
n = (int)( (double)( s[i] ) / (double)( 0x0000FFFF + 1 ) * (double)( i + 1 ) );
/* Initialize the secondary index. */
j = -1;
while( n-- >= 0 )
{
/* Advance 'j' by 'n' positions... */
j += 1;
/* ... but don't count 'book' elements that have already been copied. */
while( book[j].length == 0 ) { j += 1; }
}
/* Copy the element. */
patterns[i] = book[j];
/* Mark this element as having been used. */
book[j].length = 0;
dwipe_log( DWIPE_LOG_DEBUG, "dwipe_gutmann: Set patterns[%i] = book[%i].", i, j );
}
/* Ensure that the array is terminated. */
patterns[35].length = 0;
patterns[35].s = NULL;
/* Run the Gutmann method. */
return dwipe_runmethod( c, patterns );
} /* dwipe_gutmann */
int dwipe_ops2( DWIPE_METHOD_SIGNATURE )
{
/**
* 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 dwipe_runmethod.
*
*/
/* A generic array index. */
int i;
/* A generic result buffer. */
int r;
/* A buffer for random characters. */
char* s;
/* A buffer for the bitwise complements of 's'. */
char* t;
/* The element count of 's' and 't'. */
u32 u;
/* The pattern array for this method is dynamically allocated. */
dwipe_pattern_t* patterns;
/* The element count of 'patterns'. */
u32 q;
/* We need one random character per round. */
u = 1 * dwipe_options.rounds;
/* Allocate the array of random characters. */
s = malloc( sizeof( char ) * u );
if( s == NULL )
{
dwipe_perror( errno, __FUNCTION__, "malloc" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate the random character array." );
return -1;
}
/* Allocate the array of complement characters. */
t = malloc( sizeof( char ) * u );
if( s == NULL )
{
dwipe_perror( errno, __FUNCTION__, "malloc" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate the complement character array." );
return -1;
}
/* We need eight pattern elements per round, plus one for padding. */
q = 8 * u + 1;
/* Allocate the pattern array. */
patterns = malloc( sizeof( dwipe_pattern_t ) * q );
if( patterns == NULL )
{
dwipe_perror( errno, __FUNCTION__, "malloc" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate the pattern array." );
return -1;
}
/* Load the array of random characters. */
r = read( c->entropy_fd, s, u );
if( r != u )
{
r = errno;
dwipe_perror( r, __FUNCTION__, "read" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the %s method.", dwipe_ops2_label );
/* Ensure a negative return. */
if( r < 0 ) { return r; }
else { return -1; }
}
for( i = 0 ; i < u ; i += 1 )
{
/* Populate the array of complements. */
t[i] = ~s[i];
}
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];
}
/* Ensure that the array is terminated. */
patterns[q-1].length = 0;
patterns[q-1].s = NULL;
/* Run the TSSIT OPS-II method. */
r = dwipe_runmethod( c, patterns );
/* Release the random character buffer. */
free( s );
/* Release the complement character buffer */
free( t );
/* Release the pattern buffer. */
free( patterns );
/* We're done. */
return r;
} /* dwipe_ops2 */
int dwipe_random( DWIPE_METHOD_SIGNATURE )
{
/**
* Fill the device with a stream from the PRNG.
*
*/
/* Define the random method. */
dwipe_pattern_t patterns [] =
{
{ -1, "" },
{ 0, NULL }
};
/* Run the method. */
return dwipe_runmethod( c, patterns );
} /* dwipe_zero */
int dwipe_runmethod( DWIPE_METHOD_SIGNATURE, dwipe_pattern_t* patterns )
{
/**
* Writes patterns to the device.
*
*/
/* The result holder. */
int r;
/* An index variable. */
int i = 0;
/* The zero-fill pattern for the final pass of most methods. */
dwipe_pattern_t pattern_zero = { 1, "\x00" };
/* Create the PRNG state buffer. */
c->prng_seed.length = DWIPE_KNOB_PRNG_STATE_LENGTH;
c->prng_seed.s = malloc( c->prng_seed.length );
/* Check the memory allocation. */
if( ! c->prng_seed.s )
{
dwipe_perror( errno, __FUNCTION__, "malloc" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to allocate memory for the prng seed buffer." );
return -1;
}
/* 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;
/* Set the number of bytes that will be written across all passes in one round. */
c->pass_size = c->pass_count * c->device_size;
if( dwipe_options.verify == DWIPE_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 = dwipe_options.rounds;
/* Set the number of bytes that will be written across all rounds. */
c->round_size = c->round_count * c->pass_size;
/* The final pass is always a zero fill, except ops2 which is random. */
c->round_size += c->device_size;
if( dwipe_options.verify == DWIPE_VERIFY_LAST || dwipe_options.verify == DWIPE_VERIFY_ALL )
{
/* We must read back the last pass to verify it. */
c->round_size += c->device_size;
}
/* Initialize the working round counter. */
c->round_working = 0;
dwipe_log( DWIPE_LOG_NOTICE, "Invoking method '%s' on device '%s'.", \
dwipe_method_label( dwipe_options.method ), c->device_name );
while( c->round_working < c->round_count )
{
/* Increment the round counter. */
c->round_working += 1;
dwipe_log( DWIPE_LOG_NOTICE, "Starting round %i of %i on device '%s'.", \
c->round_working, c->round_count, c->device_name );
/* Initialize the working pass counter. */
c->pass_working = 0;
for( i = 0 ; i < c->pass_count ; i++ )
{
/* Increment the working pass. */
c->pass_working += 1;
dwipe_log( DWIPE_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 );
if( patterns[i].length == 0 )
{
/* Caught insanity. */
dwipe_log( DWIPE_LOG_SANITY, "dwipe_runmethod: A non-terminating pattern element has zero length." );
return -1;
}
if( patterns[i].length > 0 )
{
/* Write a static pass. */
c->pass_type = DWIPE_PASS_WRITE;
r = dwipe_static_pass( c, &patterns[i] );
c->pass_type = DWIPE_PASS_NONE;
/* Check for a fatal error. */
if( r < 0 ) { return r; }
if( dwipe_options.verify == DWIPE_VERIFY_ALL )
{
dwipe_log( DWIPE_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 );
/* Verify this pass. */
c->pass_type = DWIPE_PASS_VERIFY;
r = dwipe_static_verify( c, &patterns[i] );
c->pass_type = DWIPE_PASS_NONE;
/* Check for a fatal error. */
if( r < 0 ) { return r; }
dwipe_log( DWIPE_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 = DWIPE_PASS_WRITE;
/* 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 = DWIPE_PASS_NONE;
dwipe_perror( errno, __FUNCTION__, "read" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the PRNG." );
return -1;
}
/* Check for a partial read. */
if( r != c->prng_seed.length )
{
/* TODO: Handle partial reads. */
dwipe_log( DWIPE_LOG_FATAL, "Insufficient entropy is available." );
return -1;
}
/* Write the random pass. */
r = dwipe_random_pass( c );
c->pass_type = DWIPE_PASS_NONE;
/* Check for a fatal error. */
if( r < 0 ) { return r; }
if( dwipe_options.verify == DWIPE_VERIFY_ALL )
{
dwipe_log( DWIPE_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 );
/* Verify this pass. */
c->pass_type = DWIPE_PASS_VERIFY;
r = dwipe_random_verify( c );
c->pass_type = DWIPE_PASS_NONE;
/* Check for a fatal error. */
if( r < 0 ) { return r; }
dwipe_log( DWIPE_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, dwipe_method_label( dwipe_options.method ) );
}
} /* random pass */
dwipe_log( DWIPE_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 );
} /* for passes */
dwipe_log( DWIPE_LOG_NOTICE, "Finished round %i of %i on device '%s'.", \
c->round_working, c->round_count, c->device_name );
} /* while rounds */
if( dwipe_options.method == &dwipe_ops2 )
{
/* NOTE: The OPS-II method specifically requires that a random pattern be left on the device. */
/* Tell the parent that we are running the final pass. */
c->pass_type = DWIPE_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 )
{
dwipe_perror( errno, __FUNCTION__, "read" );
dwipe_log( DWIPE_LOG_FATAL, "Unable to seed the PRNG." );
return -1;
}
/* Check for a partial read. */
if( r != c->prng_seed.length )
{
/* TODO: Handle partial reads. */
dwipe_log( DWIPE_LOG_FATAL, "Insufficient entropy is available." );
return -1;
}
dwipe_log( DWIPE_LOG_NOTICE, "Writing final random pattern to '%s'.", c->device_name );
/* The final ops2 pass. */
r = dwipe_random_pass( c );
/* Check for a fatal error. */
if( r < 0 ) { return r; }
if( dwipe_options.verify == DWIPE_VERIFY_LAST || dwipe_options.verify == DWIPE_VERIFY_ALL )
{
dwipe_log( DWIPE_LOG_NOTICE, "Verifying the final random pattern on '%s' is empty.", c->device_name );
/* Verify the final zero pass. */
r = dwipe_random_verify( c );
/* Check for a fatal error. */
if( r < 0 ) { return r; }
dwipe_log( DWIPE_LOG_NOTICE, "Verified the final random pattern on '%s' is empty.", c->device_name );
}
dwipe_log( DWIPE_LOG_NOTICE, "Wrote final random pattern to '%s'.", c->device_name );
} /* final ops2 */
else
{
/* Tell the user that we are on the final pass. */
c->pass_type = DWIPE_PASS_FINAL_BLANK;
dwipe_log( DWIPE_LOG_NOTICE, "Blanking device '%s'.", c->device_name );
/* The final zero pass. */
r = dwipe_static_pass( c, &pattern_zero );
/* Check for a fatal error. */
if( r < 0 ) { return r; }
if( dwipe_options.verify == DWIPE_VERIFY_LAST || dwipe_options.verify == DWIPE_VERIFY_ALL )
{
dwipe_log( DWIPE_LOG_NOTICE, "Verifying that '%s' is empty.", c->device_name );
/* Verify the final zero pass. */
r = dwipe_static_verify( c, &pattern_zero );
/* Check for a fatal error. */
if( r < 0 ) { return r; }
dwipe_log( DWIPE_LOG_NOTICE, "Verified that '%s' is empty.", c->device_name );
}
dwipe_log( DWIPE_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 = DWIPE_PASS_NONE;
if( c->verify_errors > 0 )
{
/* We finished, but with non-fatal verification errors. */
dwipe_log( DWIPE_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. */
dwipe_log( DWIPE_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;
} /* dwipe_runmethod */
/* eof */