source: trunk/EraserDll/Pass.h @ 53

Revision 53, 7.2 KB checked in by lowjoel, 7 years ago (diff)

-Document the Schneider pass for eraser launcher
-More warning fixes

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1// Pass.h
2// Tools for handling overwriting passes and pass shuffling
3//
4// Eraser. Secure data removal. For Windows.
5// Copyright © 1997-2001  Sami Tolvanen (sami@tolvanen.com).
6//
7// This program is free software; you can redistribute it and/or
8// modify it under the terms of the GNU General Public License
9// as published by the Free Software Foundation; either version 2
10// of the License, or (at your option) any later version.
11//
12// This program is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU General Public License
18// along with this program; if not, write to the Free Software
19// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20// 02111-1307, USA.
21
22#ifndef PASS_H
23#define PASS_H
24#ifdef DMARS
25#define WIPEFUNCTION bool
26#endif
27#include "Random.h"
28#include "FillMemoryWith.h"
29
30///////////////////////////////////////////////////////////////////////////////
31// definitions
32
33// method IDs
34#define BUILTIN_METHOD_ID       0x80
35#define CUSTOM_METHOD_ID        0x00
36
37#define MAX_CUSTOM_METHODS      (BUILTIN_METHOD_ID - 1)
38#define MAX_CUSTOM_METHOD_ID    (MAX_CUSTOM_METHODS | CUSTOM_METHOD_ID)
39
40#define MAX_BUILTIN_METHODS     MAX_CUSTOM_METHODS
41#define MAX_BUILTIN_METHOD_ID   (MAX_BUILTIN_METHODS | BUILTIN_METHOD_ID)
42
43// special data
44#define RND_DATA                ((E_UINT16)-1)
45#define RND_CHAR                (RND_DATA - 1)
46
47// pass definitions
48#define passThree(x, y, z)      { 3, (x), (y), (z) }
49#define passTwo(x, y)           { 2, (x), (y),  0  }
50#define passOne(x)              { 1, (x),  0,   0  }
51#define passRandom              passOne(RND_DATA)
52
53#define setPassThree(pass, x, y, z) \
54    { (pass).bytes = 3; (pass).byte1 = (x); (pass).byte2 = (y); (pass).byte3 = (z); }
55#define setPassTwo(pass, x, y) \
56    { (pass).bytes = 2; (pass).byte1 = (x); (pass).byte2 = (y); (pass).byte3 = 0; }
57#define setPassOne(pass, x) \
58    { (pass).bytes = 1; (pass).byte1 = (x); (pass).byte2 = (pass).byte3 = 0; }
59#define setPassRandom(pass, x) \
60    setPassOne(pass, RND_DATA)
61
62#define isRandomPass(pass) \
63    ((pass).byte1 == RND_DATA)
64
65///////////////////////////////////////////////////////////////////////////////
66// structures
67
68#pragma pack(1)
69
70// pass structure - we'll settle for at most three adjacent bytes
71typedef struct _ThreeBytePass {
72    E_UINT8  bytes;                  // number of bytes used
73    E_UINT16 byte1;
74    E_UINT16 byte2;
75    E_UINT16 byte3;
76} PASS, *LPPASS;
77
78#define DESCRIPTION_SIZE    (80+1)
79
80typedef class _MethodBase {
81public:
82    E_UINT8      m_nMethodID;                        // ID
83    TCHAR        m_szDescription[DESCRIPTION_SIZE];  // description
84    E_UINT16     m_nPasses;                          // number of PASSes
85    WIPEFUNCTION m_pwfFunction;                      // the wipe function
86
87    E_UINT8      m_bShuffle;                         // shuffle passes
88    LPPASS       m_lpPasses;                         // pointer to PASSes
89} BMETHOD, *LPBMETHOD;
90
91#pragma pack()
92
93#define bmEntry(a, b, c, d, e, f)   { a, b, c, d, e, (LPPASS)f }
94
95// method definition - everything needed to save pass data
96typedef class _Method : public _MethodBase {
97public:
98    _Method() {
99        ZeroMemory(this, sizeof(_Method));
100    }
101
102    ~_Method() {
103        if (m_lpPasses) {
104            try {
105                if (m_nPasses > 0) {
106                    ZeroMemory(m_lpPasses, m_nPasses * sizeof(PASS));
107                }
108                delete[] m_lpPasses;
109                m_lpPasses = 0;
110            } catch (...) {
111                ASSERT(0);
112            }
113        }
114        ZeroMemory(this, sizeof(_Method));
115    }
116
117    _Method& operator=(const _MethodBase& rs) {
118        return copy(*(const _Method*)&rs); // way ugly
119    }
120
121    _Method& operator=(const _Method& rs) {
122        return copy(rs);
123    }
124    /*void Serialize(CArchive& ar)
125    {
126        int i=0;
127        if (ar.IsStoring())
128        {
129            ar << (BYTE)m_nMethodID;
130            for (i=0; i<DESCRIPTION_SIZE; i++)  ar << (char)m_szDescription[i];
131            ar << (WORD)m_nPasses;
132           
133            ar << (BYTE)m_bShuffle;
134            for (i=0; i<m_nPasses; i++)
135            {
136                ar << (BYTE)m_lpPasses[i].bytes;
137                ar << (WORD)m_lpPasses[i].byte1;
138                ar << (WORD)m_lpPasses[i].byte2;
139                ar << (WORD)m_lpPasses[i].byte3;
140            }
141        }
142        else
143        {           
144            ar >> (BYTE)m_nMethodID;
145            for (i=0; i<DESCRIPTION_SIZE; i++)  ar >> (char)m_szDescription[i];
146            ar >> (WORD)m_nPasses;
147           
148            ar >> (BYTE)m_bShuffle;
149            m_lpPasses = new PASS[m_nPasses];
150            for (i=0; i<m_nPasses; i++)
151            {
152                ar >> (BYTE)m_lpPasses[i].bytes;
153                ar >> (WORD)m_lpPasses[i].byte1;
154                ar >> (WORD)m_lpPasses[i].byte2;
155                ar >> (WORD)m_lpPasses[i].byte3;
156            }
157            //m_pwfFunction = 0;
158        }
159    }*/
160
161private:
162    _Method& copy(const _Method& rs) {
163        if (this != &rs) {
164            try {
165                if (m_lpPasses) {
166                    if (m_nPasses > 0) {
167                        ZeroMemory(m_lpPasses, m_nPasses * sizeof(PASS));
168                    }
169                    delete[] m_lpPasses;
170                    m_lpPasses = 0;
171                    m_nPasses = 0;
172                }
173
174                m_nMethodID = rs.m_nMethodID;
175                lstrcpyn(m_szDescription, rs.m_szDescription, DESCRIPTION_SIZE);
176
177                m_nPasses = rs.m_nPasses;
178                m_pwfFunction = rs.m_pwfFunction;
179
180                if (rs.m_lpPasses && rs.m_nPasses > 0) {
181                    m_lpPasses = new PASS[rs.m_nPasses];
182                    for (E_UINT16 i = 0; i < rs.m_nPasses; i++) {
183                        m_lpPasses[i] = rs.m_lpPasses[i];
184                    }
185                }
186
187                m_bShuffle = rs.m_bShuffle;
188            } catch (...) {
189                ASSERT(0);
190            }
191        }
192        return *this;
193    }
194} METHOD, *LPMETHOD;
195
196ERASER_API const BMETHOD*  GetBMethods() ;
197///////////////////////////////////////////////////////////////////////////////
198// built-in methods
199
200const E_UINT8 nBuiltinMethods       = 6;
201
202// maximum number of passes allowed
203#define PASSES_MAX                  ((E_UINT16)-1)
204
205#define GUTMANN_METHOD_ID           ((1 << 0) | BUILTIN_METHOD_ID)
206#define PASSES_GUTMANN              35
207#define PASSES_GUTMANN_RANDOM       4
208
209#define DOD_METHOD_ID               ((1 << 1) | BUILTIN_METHOD_ID)
210#define PASSES_DOD                  7
211
212#define DOD_E_METHOD_ID             ((1 << 2) | BUILTIN_METHOD_ID)
213#define PASSES_DOD_E                3
214
215#define RANDOM_METHOD_ID            ((1 << 3) | BUILTIN_METHOD_ID)
216#define PASSES_RND                  1
217#define PASSES_RND_MAX              PASSES_MAX
218
219#define FL2KB_METHOD_ID            ((1 << 4) | BUILTIN_METHOD_ID)
220#define PASSES_FL2KB                  1
221#define PASSES_FL2KB_MAX              2
222
223#define SCHNEIER_METHOD_ID            ((1 << 5) | BUILTIN_METHOD_ID)
224#define PASSES_SCHNEIER                  7
225#define PASSES_SCHNEIER_MAX              7
226
227// default for files
228#define DEFAULT_FILE_METHOD_ID      GUTMANN_METHOD_ID
229#define DEFAULT_FILE_PASSES         PASSES_GUTMANN
230// default for unused disk space
231#define DEFAULT_UDS_METHOD_ID       RANDOM_METHOD_ID
232#define DEFAULT_UDS_PASSES          PASSES_RND
233
234// global array of built-in methods
235extern const BMETHOD bmMethods[nBuiltinMethods];
236
237#endif // PASS_H
Note: See TracBrowser for help on using the repository browser.