Annotation of truecrypt/common/wipe.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  Copyright (c) 2008 TrueCrypt Foundation. All rights reserved.
                      3: 
1.1.1.2 ! root        4:  Governed by the TrueCrypt License 2.5 the full text of which is contained
1.1       root        5:  in the file License.txt included in TrueCrypt binary and source code
                      6:  distribution packages.
                      7: */
                      8: 
                      9: #include "Tcdefs.h"
                     10: #include "Wipe.h"
                     11: 
                     12: 
                     13: // Fill buffer with wipe patterns defined in "National Industrial Security Program Operating Manual", US DoD 5220.22-M.
                     14: // Return: FALSE = buffer must be filled with random data
                     15: 
                     16: static BOOL Wipe3Dod5220 (int pass, byte *buffer, size_t size)
                     17: {
                     18:        byte wipeChar;
                     19: 
                     20:        switch (pass)
                     21:        {
                     22:        case 1:
                     23:                wipeChar = 0;
                     24:                break;
                     25: 
                     26:        case 2:
                     27:                wipeChar = 0xff;
                     28:                break;
                     29: 
                     30:        default:
                     31:                return FALSE;
                     32:        }
                     33: 
                     34:        memset (buffer, wipeChar, size);
                     35:        return TRUE;
                     36: }
                     37: 
                     38: 
                     39: static BOOL Wipe7Dod5220 (int pass, byte randChars[TC_WIPE_RAND_CHAR_COUNT], byte *buffer, size_t size)
                     40: {
                     41:        byte wipeChar;
                     42: 
                     43:        switch (pass)
                     44:        {
                     45:        case 1:
                     46:                wipeChar = randChars[0];
                     47:                break;
                     48: 
                     49:        case 2:
                     50:                wipeChar = ~randChars[0];
                     51:                break;
                     52: 
                     53:        case 4:
                     54:                wipeChar = randChars[1];
                     55:                break;
                     56: 
                     57:        case 5:
                     58:                wipeChar = randChars[2];
                     59:                break;
                     60: 
                     61:        case 6:
                     62:                wipeChar = ~randChars[2];
                     63:                break;
                     64: 
                     65:        default:
                     66:                return FALSE;
                     67:        }
                     68: 
                     69:        memset (buffer, wipeChar, size);
                     70:        return TRUE;
                     71: }
                     72: 
                     73: 
                     74: // Fill the buffer with wipe patterns defined in the paper "Secure Deletion of Data from Magnetic and Solid-State Memory" by Peter Gutmann.
                     75: // Return: FALSE = buffer must be filled with random data
                     76: 
                     77: static BOOL Wipe35Gutmann (int pass, byte *buffer, size_t size)
                     78: {
                     79:        byte wipePat3[] = { 0x92, 0x49, 0x24 };
                     80:        int wipePat3Pos;
                     81:        size_t i;
                     82: 
                     83:        switch (pass)
                     84:        {
                     85:        case 5:
                     86:                memset (buffer, 0x55, size);
                     87:                break;
                     88: 
                     89:        case 6:
                     90:                memset (buffer, 0xaa, size);
                     91:                break;
                     92: 
                     93:        case 7:
                     94:        case 26:
                     95:        case 29:
                     96:                wipePat3Pos = 0;
                     97:                goto wipe3;
                     98: 
                     99:        case 8:
                    100:        case 27:
                    101:        case 30:
                    102:                wipePat3Pos = 1;
                    103:                goto wipe3;
                    104: 
                    105:        case 9:
                    106:        case 28:
                    107:        case 31:
                    108:                wipePat3Pos = 2;
                    109:                goto wipe3;
                    110: 
                    111: wipe3:
                    112:                if (pass >= 29)
                    113:                {
                    114:                        wipePat3[0] = ~wipePat3[0];
                    115:                        wipePat3[1] = ~wipePat3[1];
                    116:                        wipePat3[2] = ~wipePat3[2];
                    117:                }
                    118: 
                    119:                for (i = 0; i < size; ++i)
                    120:                {
                    121:                        buffer[i] = wipePat3[wipePat3Pos++ % 3];
                    122:                }
                    123:                break;
                    124: 
                    125:        default:
                    126:                if (pass >= 10 && pass <= 25)
                    127:                        memset (buffer, (pass - 10) * 0x11, size);
                    128:                else
                    129:                        return FALSE;
                    130:        }
                    131: 
                    132:        return TRUE;
                    133: }
                    134: 
                    135: 
                    136: size_t GetWipePassCount (WipeAlgorithmId algorithm)
                    137: {
                    138:        switch (algorithm)
                    139:        {
                    140:        case TC_WIPE_3_DOD_5220:
                    141:                return 3;
                    142: 
                    143:        case TC_WIPE_7_DOD_5220:
                    144:                return 7;
                    145: 
                    146:        case TC_WIPE_35_GUTMANN:
                    147:                return 35;
                    148: 
                    149:        default:
                    150:                TC_THROW_FATAL_EXCEPTION;
                    151:        }
                    152: }
                    153: 
                    154: 
                    155: BOOL WipeBuffer (WipeAlgorithmId algorithm, byte randChars[TC_WIPE_RAND_CHAR_COUNT], int pass, byte *buffer, size_t size)
                    156: {
                    157:        switch (algorithm)
                    158:        {
                    159:        case TC_WIPE_3_DOD_5220:
                    160:                return Wipe3Dod5220 (pass, buffer, size);
                    161: 
                    162:        case TC_WIPE_7_DOD_5220:
                    163:                return Wipe7Dod5220 (pass, randChars, buffer, size);
                    164: 
                    165:        case TC_WIPE_35_GUTMANN:
                    166:                return Wipe35Gutmann (pass, buffer, size);
                    167: 
                    168:        default:
                    169:                TC_THROW_FATAL_EXCEPTION;
                    170:        }
                    171: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.