;
18 | FCount: Integer;
19 | procedure AddDispose(P: Pointer);
20 | procedure Flush;
21 | public
22 | destructor Destroy; override;
23 | end;
24 |
25 | private
26 | FPtr: MarshaledAString;
27 | FLength: integer;
28 | FDisposer: TDisposer;
29 |
30 | procedure AddDispose(P: Pointer);
31 | function GetChars(Index: Integer): MarshaledAString; inline;
32 | procedure SetChars(Index: Integer; Value: MarshaledAString); inline;
33 | procedure SetPtr(Value: MarshaledAString);
34 | public
35 | procedure SetLength(NewLength: integer);
36 | function Length: integer; inline;
37 |
38 | class operator Equal(const Left, Right: AnsiString): Boolean;
39 | class operator NotEqual(const Left, Right: AnsiString): Boolean; inline;
40 |
41 | class operator Implicit(const Val: AnsiString): MarshaledAString;
42 | class operator Explicit(const Ptr: MarshaledAString): AnsiString;
43 |
44 | class operator Implicit(const Val: AnsiString): string;
45 | class operator Implicit(const Str: string): AnsiString;
46 |
47 | class operator Implicit(const Val: AnsiString): Variant;
48 | class operator Explicit(const v: Variant): AnsiString;
49 |
50 | class operator Implicit(const Val: AnsiString): TBytes;
51 | class operator Explicit(const b: TBytes): AnsiString;
52 |
53 | property Chars[index: Integer]: MarshaledAString read GetChars write SetChars; default;
54 | property Ptr: MarshaledAString read FPtr write SetPtr;
55 | end;
56 |
57 | WideString = string;
58 |
59 | AnsiChar = byte;
60 | PAnsiChar = MarshaledAString;
61 | {$ENDIF NEXTGEN}
62 |
63 | implementation
64 |
65 | {$IFDEF NEXTGEN}
66 | uses
67 | Math;
68 | {$ENDIF}
69 |
70 | {$IFDEF NEXTGEN}
71 |
72 | { AnsiString.TDisposer }
73 |
74 | destructor AnsiString.TDisposer.Destroy;
75 | begin
76 | Flush;
77 | inherited;
78 | end;
79 |
80 | procedure AnsiString.TDisposer.AddDispose(P: Pointer);
81 | var
82 | c: Integer;
83 | begin
84 | if FCount < System.Length(FInline) then
85 | FInline[FCount] := P
86 | else begin
87 | c := FCount - System.Length(FInline);
88 | if c = System.Length(FOverflow) then begin
89 | if System.Length(FOverflow) < 4 then
90 | System.SetLength(FOverflow, 4)
91 | else
92 | System.SetLength(FOverflow, System.Length(FOverflow) * 2);
93 | end;
94 | FOverflow[c] := P;
95 | end;
96 |
97 | Inc(FCount);
98 | end;
99 |
100 | procedure AnsiString.TDisposer.Flush;
101 | var
102 | i: Integer;
103 | begin
104 | if FCount <= System.Length(FInline) then begin
105 | for i := 0 to FCount - 1 do
106 | System.FreeMem(FInline[i]);
107 | end
108 | else begin
109 | for i := 0 to System.Length(FInline) - 1 do
110 | System.FreeMem(FInline[i]);
111 | for i := 0 to FCount - System.Length(FInline) - 1 do
112 | System.FreeMem(FOverflow[i]);
113 | end;
114 | FCount := 0;
115 | System.SetLength(FOverflow, 0);
116 | end;
117 |
118 | { AnsiString }
119 |
120 | procedure AnsiString.AddDispose(P: Pointer);
121 | begin
122 | if FDisposer = nil then
123 | FDisposer := TDisposer.Create;
124 | FDisposer.AddDispose(P);
125 | end;
126 |
127 | procedure AnsiString.SetLength(NewLength: integer);
128 | var
129 | NewPtr: Pointer;
130 | begin
131 | if NewLength <= 0 then begin
132 | FPtr := nil;
133 | FLength := 0;
134 | Exit;
135 | end;
136 |
137 | NewPtr := System.AllocMem(NewLength + 1);
138 | if (FDisposer <> nil) and (FPtr <> nil) then
139 | Move(FPtr^, NewPtr^, Min(FLength, NewLength));
140 |
141 | AddDispose(NewPtr);
142 | FPtr := NewPtr;
143 | FPtr[NewLength] := #0;
144 | FLength := NewLength;
145 | end;
146 |
147 | function AnsiString.Length: integer;
148 | begin
149 | if (FDisposer <> nil) and (FPtr <> nil) then
150 | Result := FLength
151 | else
152 | Result := 0;
153 | end;
154 |
155 | class operator AnsiString.Equal(const Left, Right: AnsiString): Boolean;
156 | var
157 | Len: integer;
158 | P1, P2: PAnsiChar;
159 | begin
160 | Len := Left.Length;
161 | Result := Len = Right.Length;
162 | if Result then begin
163 | P1 := Left.FPtr;
164 | P2 := Right.Ptr;
165 | while Len > 0 do begin
166 | if P1^ <> P2^ then
167 | Exit(False);
168 | Inc(P1);
169 | Inc(P2);
170 | Dec(Len);
171 | end;
172 | end;
173 | end;
174 |
175 | class operator AnsiString.NotEqual(const Left, Right: AnsiString): Boolean;
176 | begin
177 | Result := not (Left = Right);
178 | end;
179 |
180 | class operator AnsiString.Implicit(const Val: AnsiString): MarshaledAString;
181 | begin
182 | if Val.FPtr = nil then
183 | Result := #0
184 | else
185 | Result := Val.FPtr;
186 | end;
187 |
188 | class operator AnsiString.Explicit(const Ptr: MarshaledAString): AnsiString;
189 | begin
190 | if Result.FPtr <> Ptr then begin
191 | Result.FLength := System.Length(Ptr);
192 |
193 | if Result.FLength = 0 then
194 | Result.FPtr := nil
195 | else begin
196 | Result.FPtr := System.AllocMem(Result.FLength + 1);
197 | Result.AddDispose(Result.FPtr);
198 |
199 | Move(Ptr^, Result.FPtr^, Result.FLength);
200 | Result.FPtr[Result.FLength] := #0;
201 | end;
202 | end;
203 | end;
204 |
205 | class operator AnsiString.Implicit(const Val: AnsiString): string;
206 | begin
207 | Result := string(Val.FPtr);
208 | end;
209 |
210 | class operator AnsiString.Implicit(const Str: string): AnsiString;
211 | begin
212 | Result.FLength := LocaleCharsFromUnicode(DefaultSystemCodePage, 0, PWideChar(Str), System.Length(Str) + 1, nil, 0, nil, nil);
213 | if Result.FLength > 0 then begin
214 | Result.FPtr := System.AllocMem(Result.FLength);
215 | Result.AddDispose(Result.FPtr);
216 | LocaleCharsFromUnicode(DefaultSystemCodePage, 0, PWideChar(Str), System.Length(Str) + 1,
217 | Result.FPtr, Result.FLength, nil, nil);
218 | Dec(Result.FLength);
219 | end
220 | else
221 | Result.FPtr := nil;
222 | end;
223 |
224 | class operator AnsiString.Implicit(const Val: AnsiString): Variant;
225 | begin
226 | Result := string(Val.FPtr);
227 | end;
228 |
229 | class operator AnsiString.Explicit(const v: Variant): AnsiString;
230 | begin
231 | Result := AnsiString(string(v));
232 | end;
233 |
234 | class operator AnsiString.Implicit(const Val: AnsiString): TBytes;
235 | var
236 | Len: integer;
237 | begin
238 | Len := Val.Length;
239 | System.SetLength(Result, Len);
240 | if Len > 0 then
241 | Move(Val.FPtr^, Result[0], Len);
242 | end;
243 |
244 | class operator AnsiString.Explicit(const b: TBytes): AnsiString;
245 | begin
246 | Result.FLength := System.Length(b);
247 |
248 | if Result.FLength = 0 then
249 | Result.FPtr := nil
250 | else begin
251 | Result.FPtr := System.AllocMem(Result.FLength + 1);
252 | Result.AddDispose(Result.FPtr);
253 |
254 | Move(b[0], Result.FPtr^, Result.FLength);
255 | Result.FPtr[Result.FLength] := #0;
256 | end;
257 | end;
258 |
259 | function AnsiString.GetChars(Index: Integer): MarshaledAString;
260 | begin
261 | Result := @FPtr[Index - 1];
262 | end;
263 |
264 | procedure AnsiString.SetChars(Index: Integer; Value: MarshaledAString);
265 | begin
266 | FPtr[Index - 1] := Value[0];
267 | end;
268 |
269 | procedure AnsiString.SetPtr(Value: MarshaledAString);
270 | begin
271 | if FDisposer = nil then
272 | FDisposer := TDisposer.Create;
273 |
274 | FPtr := Value;
275 | FLength := System.Length(Value);
276 | end;
277 |
278 | {$ENDIF}
279 |
280 | end.
281 |
--------------------------------------------------------------------------------
/Demos/FileEncrypt/FileEncrypt.dpr:
--------------------------------------------------------------------------------
1 | program FileEncrypt;
2 |
3 | uses
4 | Forms,
5 | uMain in 'uMain.pas' {frmMain};
6 |
7 | {$R *.res}
8 |
9 | begin
10 | Application.Initialize;
11 | Application.CreateForm(TfrmMain, frmMain);
12 | Application.Run;
13 | end.
14 |
--------------------------------------------------------------------------------
/Demos/FileEncrypt/FileEncrypt.dproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {986FD9F6-2061-4F9F-8320-8CD861AC6D8F}
4 | FileEncrypt.dpr
5 | True
6 | Release
7 | 3
8 | Application
9 | VCL
10 | 13.4
11 | Win64
12 |
13 |
14 | true
15 |
16 |
17 | true
18 | Base
19 | true
20 |
21 |
22 | true
23 | Base
24 | true
25 |
26 |
27 | true
28 | Base
29 | true
30 |
31 |
32 | true
33 | Cfg_1
34 | true
35 | true
36 |
37 |
38 | true
39 | Cfg_1
40 | true
41 | true
42 |
43 |
44 | true
45 | Base
46 | true
47 |
48 |
49 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=
50 | 1049
51 | Vcl;Vcl.Imaging;Vcl.Touch;Vcl.Samples;Vcl.Shell;System;Xml;Data;Datasnap;Web;Soap;Winapi;$(DCC_Namespace)
52 | 00400000
53 | false
54 | false
55 | false
56 | false
57 | false
58 |
59 |
60 | System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;$(DCC_Namespace)
61 | FileEncrypt_Icon.ico
62 | true
63 | 1033
64 | $(BDS)\bin\default_app.manifest
65 |
66 |
67 | true
68 | FileEncrypt_Icon.ico
69 | Winapi;System.Win;Data.Win;Datasnap.Win;Web.Win;Soap.Win;Xml.Win;Bde;$(DCC_Namespace)
70 | 1033
71 | $(BDS)\bin\default_app.manifest
72 | CompanyName=;FileDescription=;FileVersion=1.0.0.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=
73 |
74 |
75 | false
76 | false
77 | 0
78 | RELEASE;$(DCC_Define)
79 |
80 |
81 | true
82 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\FileEncrypt_Icon.ico
83 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\x64\
84 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\x64\
85 | 1033
86 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\x64\
87 |
88 |
89 | true
90 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\FileEncrypt_Icon.ico
91 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\x86\
92 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\x86\
93 | 1033
94 | $(BDS)\Neo\DCPcrypt\Demos\FileEncrypt\x86\
95 |
96 |
97 | DEBUG;$(DCC_Define)
98 | false
99 | true
100 |
101 |
102 |
103 | MainSource
104 |
105 |
106 |
107 |
108 |
109 | Cfg_2
110 | Base
111 |
112 |
113 | Base
114 |
115 |
116 | Cfg_1
117 | Base
118 |
119 |
120 |
121 | Delphi.Personality.12
122 |
123 |
124 |
125 |
126 | FileEncrypt.dpr
127 |
128 |
129 | False
130 | False
131 | 1
132 | 0
133 | 0
134 | 0
135 | False
136 | False
137 | False
138 | False
139 | False
140 | 1049
141 | 1251
142 |
143 |
144 |
145 |
146 | 1.0.0.0
147 |
148 |
149 |
150 |
151 |
152 | 1.0.0.0
153 |
154 |
155 |
156 | Embarcadero C++Builder Office 2000 Servers Package
157 | Embarcadero C++Builder Office XP Servers Package
158 | Microsoft Office 2000 Sample Automation Server Wrapper Components
159 | Microsoft Office XP Sample Automation Server Wrapper Components
160 |
161 |
162 |
163 | True
164 | True
165 |
166 |
167 | 12
168 |
169 |
170 |
171 |
172 |
--------------------------------------------------------------------------------
/Demos/FileEncrypt/FileEncrypt.identcache:
--------------------------------------------------------------------------------
1 | ZC:\Program Files\Embarcadero\RAD Studio\9.0\Neo\DCPcrypt\Demos\FileEncrypt\FileEncrypt.dpr TC:\Program Files\Embarcadero\RAD Studio\9.0\Neo\DCPcrypt\Demos\FileEncrypt\uMain.pas
--------------------------------------------------------------------------------
/Demos/FileEncrypt/FileEncrypt.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CHERTS/DCPcrypt/6bafdd9981f0c716303d0c0558d250314aeffa58/Demos/FileEncrypt/FileEncrypt.res
--------------------------------------------------------------------------------
/Demos/FileEncrypt/FileEncrypt_Icon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CHERTS/DCPcrypt/6bafdd9981f0c716303d0c0558d250314aeffa58/Demos/FileEncrypt/FileEncrypt_Icon.ico
--------------------------------------------------------------------------------
/Demos/FileHash/FileHash.dpr:
--------------------------------------------------------------------------------
1 | program FileHash;
2 |
3 | uses
4 | Forms,
5 | uMain in 'uMain.pas' {frmMain};
6 |
7 | {$R *.res}
8 |
9 | begin
10 | Application.Initialize;
11 | Application.CreateForm(TfrmMain, frmMain);
12 | Application.Run;
13 | end.
14 |
--------------------------------------------------------------------------------
/Demos/FileHash/FileHash.dproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | {5BA5D14A-6176-4D91-A652-F1239E46C5D9}
4 | FileHash.dpr
5 | True
6 | Debug
7 | Win32
8 | Application
9 | VCL
10 | DCC32
11 | 12.3
12 |
13 |
14 | true
15 |
16 |
17 | true
18 | Base
19 | true
20 |
21 |
22 | true
23 | Base
24 | true
25 |
26 |
27 | false
28 | 00400000
29 | WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;WinTypes=Windows;WinProcs=Windows;$(DCC_UnitAlias)
30 | false
31 | false
32 | false
33 | false
34 |
35 |
36 | false
37 | RELEASE;$(DCC_Define)
38 | 0
39 | false
40 |
41 |
42 | DEBUG;$(DCC_Define)
43 | false
44 | true
45 |
46 |
47 |
48 | MainSource
49 |
50 |
51 |
52 |
53 |
54 | Cfg_2
55 | Base
56 |
57 |
58 | Base
59 |
60 |
61 | Cfg_1
62 | Base
63 |
64 |
65 |
66 |
67 |
68 | Delphi.Personality.12
69 | VCLApplication
70 |
71 |
72 |
73 | FileHash.dpr
74 |
75 |
76 | False
77 | False
78 | 1
79 | 0
80 | 0
81 | 0
82 | False
83 | False
84 | False
85 | False
86 | False
87 | 1049
88 | 1251
89 |
90 |
91 |
92 |
93 | 1.0.0.0
94 |
95 |
96 |
97 |
98 |
99 | 1.0.0.0
100 |
101 |
102 |
103 |
104 | True
105 |
106 |
107 | 12
108 |
109 |
110 |
--------------------------------------------------------------------------------
/Demos/FileHash/FileHash.res:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CHERTS/DCPcrypt/6bafdd9981f0c716303d0c0558d250314aeffa58/Demos/FileHash/FileHash.res
--------------------------------------------------------------------------------
/Demos/FileHash/uMain.dfm:
--------------------------------------------------------------------------------
1 | object frmMain: TfrmMain
2 | Left = 224
3 | Top = 110
4 | Width = 416
5 | Height = 450
6 | BorderIcons = [biSystemMenu, biMinimize]
7 | Caption = 'DCPcrypt File Hashing Demo'
8 | Color = clBtnFace
9 | Font.Charset = ANSI_CHARSET
10 | Font.Color = clWindowText
11 | Font.Height = -13
12 | Font.Name = 'Arial'
13 | Font.Style = []
14 | OldCreateOrder = False
15 | OnCreate = FormCreate
16 | DesignSize = (
17 | 408
18 | 416)
19 | PixelsPerInch = 96
20 | TextHeight = 16
21 | object grpInputFile: TGroupBox
22 | Left = 8
23 | Top = 8
24 | Width = 393
25 | Height = 57
26 | Anchors = [akLeft, akTop, akRight]
27 | Caption = 'Input File'
28 | TabOrder = 0
29 | DesignSize = (
30 | 393
31 | 57)
32 | object btnBrowseFiles: TSpeedButton
33 | Left = 360
34 | Top = 24
35 | Width = 24
36 | Height = 24
37 | Anchors = [akTop, akRight]
38 | Glyph.Data = {
39 | 76010000424D7601000000000000760000002800000020000000100000000100
40 | 04000000000000010000120B0000120B00001000000000000000000000000000
41 | 800000800000008080008000000080008000808000007F7F7F00BFBFBF000000
42 | FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF00555555555555
43 | 5555555555555555555555555555555555555555555555555555555555555555
44 | 555555555555555555555555555555555555555FFFFFFFFFF555550000000000
45 | 55555577777777775F55500B8B8B8B8B05555775F555555575F550F0B8B8B8B8
46 | B05557F75F555555575F50BF0B8B8B8B8B0557F575FFFFFFFF7F50FBF0000000
47 | 000557F557777777777550BFBFBFBFB0555557F555555557F55550FBFBFBFBF0
48 | 555557F555555FF7555550BFBFBF00055555575F555577755555550BFBF05555
49 | 55555575FFF75555555555700007555555555557777555555555555555555555
50 | 5555555555555555555555555555555555555555555555555555}
51 | NumGlyphs = 2
52 | OnClick = btnBrowseFilesClick
53 | end
54 | object boxInputFile: TEdit
55 | Left = 8
56 | Top = 24
57 | Width = 345
58 | Height = 24
59 | Anchors = [akLeft, akTop, akRight]
60 | TabOrder = 0
61 | end
62 | end
63 | object grpHashes: TGroupBox
64 | Left = 8
65 | Top = 72
66 | Width = 393
67 | Height = 153
68 | Anchors = [akLeft, akTop, akRight]
69 | Caption = 'Hashes'
70 | TabOrder = 1
71 | DesignSize = (
72 | 393
73 | 153)
74 | object lstHashes: TCheckListBox
75 | Left = 8
76 | Top = 24
77 | Width = 289
78 | Height = 121
79 | Anchors = [akLeft, akTop, akRight]
80 | ItemHeight = 16
81 | Sorted = True
82 | TabOrder = 0
83 | end
84 | object btnHash: TButton
85 | Left = 304
86 | Top = 120
87 | Width = 81
88 | Height = 25
89 | Anchors = [akTop, akRight]
90 | Caption = 'Hash Files'
91 | TabOrder = 1
92 | OnClick = btnHashClick
93 | end
94 | end
95 | object grpOutput: TGroupBox
96 | Left = 8
97 | Top = 232
98 | Width = 393
99 | Height = 177
100 | Anchors = [akLeft, akTop, akRight, akBottom]
101 | Caption = 'Output'
102 | TabOrder = 2
103 | DesignSize = (
104 | 393
105 | 177)
106 | object txtOutput: TMemo
107 | Left = 8
108 | Top = 24
109 | Width = 377
110 | Height = 145
111 | Anchors = [akLeft, akTop, akRight, akBottom]
112 | Font.Charset = ANSI_CHARSET
113 | Font.Color = clWindowText
114 | Font.Height = -13
115 | Font.Name = 'Courier New'
116 | Font.Style = []
117 | ParentFont = False
118 | ReadOnly = True
119 | ScrollBars = ssBoth
120 | TabOrder = 0
121 | end
122 | end
123 | object DCP_haval1: TDCP_haval
124 | Id = 14
125 | Algorithm = 'Haval (256bit, 5 passes)'
126 | HashSize = 256
127 | Left = 24
128 | Top = 104
129 | end
130 | object DCP_md41: TDCP_md4
131 | Id = 17
132 | Algorithm = 'MD4'
133 | HashSize = 128
134 | Left = 56
135 | Top = 104
136 | end
137 | object DCP_md51: TDCP_md5
138 | Id = 16
139 | Algorithm = 'MD5'
140 | HashSize = 128
141 | Left = 88
142 | Top = 104
143 | end
144 | object DCP_ripemd1281: TDCP_ripemd128
145 | Id = 27
146 | Algorithm = 'RipeMD-128'
147 | HashSize = 128
148 | Left = 120
149 | Top = 104
150 | end
151 | object DCP_ripemd1601: TDCP_ripemd160
152 | Id = 10
153 | Algorithm = 'RipeMD-160'
154 | HashSize = 160
155 | Left = 152
156 | Top = 104
157 | end
158 | object DCP_sha11: TDCP_sha1
159 | Id = 2
160 | Algorithm = 'SHA1'
161 | HashSize = 160
162 | Left = 24
163 | Top = 136
164 | end
165 | object DCP_sha2561: TDCP_sha256
166 | Id = 28
167 | Algorithm = 'SHA256'
168 | HashSize = 256
169 | Left = 56
170 | Top = 136
171 | end
172 | object DCP_sha3841: TDCP_sha384
173 | Id = 29
174 | Algorithm = 'SHA384'
175 | HashSize = 384
176 | Left = 88
177 | Top = 136
178 | end
179 | object DCP_sha5121: TDCP_sha512
180 | Id = 30
181 | Algorithm = 'SHA512'
182 | HashSize = 512
183 | Left = 120
184 | Top = 136
185 | end
186 | object DCP_tiger1: TDCP_tiger
187 | Id = 18
188 | Algorithm = 'Tiger'
189 | HashSize = 192
190 | Left = 152
191 | Top = 136
192 | end
193 | object dlgOpen: TOpenDialog
194 | Filter = 'All Files (*.*)|*.*'
195 | Title = 'Choose input file'
196 | Left = 24
197 | Top = 168
198 | end
199 | end
200 |
--------------------------------------------------------------------------------
/Demos/FileHash/uMain.pas:
--------------------------------------------------------------------------------
1 | {******************************************************************************}
2 | {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
3 | {******************************************************************************}
4 | {* A file hashing demo ********************************************************}
5 | {******************************************************************************}
6 | {* Copyright (c) 2003 David Barton *}
7 | {* Permission is hereby granted, free of charge, to any person obtaining a *}
8 | {* copy of this software and associated documentation files (the "Software"), *}
9 | {* to deal in the Software without restriction, including without limitation *}
10 | {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
11 | {* and/or sell copies of the Software, and to permit persons to whom the *}
12 | {* Software is furnished to do so, subject to the following conditions: *}
13 | {* *}
14 | {* The above copyright notice and this permission notice shall be included in *}
15 | {* all copies or substantial portions of the Software. *}
16 | {* *}
17 | {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
18 | {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
19 | {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
20 | {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
21 | {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
22 | {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
23 | {* DEALINGS IN THE SOFTWARE. *}
24 | {******************************************************************************}
25 | unit uMain;
26 |
27 | interface
28 |
29 | uses
30 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
31 | Dialogs, Buttons, StdCtrls, CheckLst, DCPtiger, DCPsha512, DCPsha256,
32 | DCPsha1, DCPripemd160, DCPripemd128, DCPmd5, DCPmd4, DCPcrypt2, DCPhaval;
33 |
34 | type
35 | TfrmMain = class(TForm)
36 | DCP_haval1: TDCP_haval;
37 | DCP_md41: TDCP_md4;
38 | DCP_md51: TDCP_md5;
39 | DCP_ripemd1281: TDCP_ripemd128;
40 | DCP_ripemd1601: TDCP_ripemd160;
41 | DCP_sha11: TDCP_sha1;
42 | DCP_sha2561: TDCP_sha256;
43 | DCP_sha3841: TDCP_sha384;
44 | DCP_sha5121: TDCP_sha512;
45 | DCP_tiger1: TDCP_tiger;
46 | grpInputFile: TGroupBox;
47 | boxInputFile: TEdit;
48 | grpHashes: TGroupBox;
49 | lstHashes: TCheckListBox;
50 | grpOutput: TGroupBox;
51 | txtOutput: TMemo;
52 | btnHash: TButton;
53 | btnBrowseFiles: TSpeedButton;
54 | dlgOpen: TOpenDialog;
55 | procedure FormCreate(Sender: TObject);
56 | procedure btnBrowseFilesClick(Sender: TObject);
57 | procedure btnHashClick(Sender: TObject);
58 | private
59 | { Private declarations }
60 | public
61 | { Public declarations }
62 | end;
63 |
64 | var
65 | frmMain: TfrmMain;
66 |
67 | implementation
68 |
69 | {$R *.dfm}
70 |
71 | procedure TfrmMain.FormCreate(Sender: TObject);
72 | var
73 | i: integer;
74 | Hash: TDCP_hash;
75 | begin
76 | ClientHeight := 416;
77 | ClientWidth := 408;
78 | MessageDlg('This is a file hashing demo using the DCPcrypt component set.'+#13+'For more information see http://www.cityinthesky.co.uk/cryptography.html',mtInformation,[mbOK],0);
79 |
80 | // find all the hash algorithms on the form
81 | for i := 0 to ComponentCount - 1 do
82 | begin
83 | if Components[i] is TDCP_hash then
84 | begin
85 | Hash := TDCP_hash(Components[i]);
86 | lstHashes.Items.AddObject(Hash.Algorithm + ' (Digest size: ' + IntToStr(Hash.HashSize) + ' bits)',Components[i]);
87 | end;
88 | end;
89 | end;
90 |
91 | procedure TfrmMain.btnBrowseFilesClick(Sender: TObject);
92 | begin
93 | if dlgOpen.Execute then
94 | boxInputFile.Text := dlgOpen.FileName;
95 | end;
96 |
97 | procedure TfrmMain.btnHashClick(Sender: TObject);
98 | var
99 | Hashes: array of TDCP_hash;
100 | HashDigest: array of byte;
101 | i, j, read: integer;
102 | s: string;
103 | buffer: array[0..16383] of byte;
104 | strmInput: TFileStream;
105 | begin
106 | txtOutput.Clear;
107 | if not FileExists(boxInputFile.Text) then
108 | begin
109 | MessageDlg('File does not exist',mtInformation,[mbOK],0);
110 | Exit;
111 | end;
112 | Hashes := nil;
113 | // make a list of all the hash algorithms to use
114 | for i := 0 to lstHashes.Items.Count - 1 do
115 | begin
116 | if lstHashes.Checked[i] then
117 | begin
118 | // yes I know this is inefficient but it's also easy ;-)
119 | SetLength(Hashes,Length(Hashes) + 1);
120 | Hashes[Length(Hashes) - 1] := TDCP_hash(lstHashes.Items.Objects[i]);
121 | TDCP_hash(lstHashes.Items.Objects[i]).Init;
122 | end;
123 | end;
124 | strmInput := nil;
125 | try
126 | strmInput := TFileStream.Create(boxInputFile.Text,fmOpenRead);
127 | repeat
128 | // read into the buffer
129 | read := strmInput.Read(buffer,Sizeof(buffer));
130 | // hash the buffer with each of the selected hashes
131 | for i := 0 to Length(Hashes) - 1 do
132 | Hashes[i].Update(buffer,read);
133 | until read <> Sizeof(buffer);
134 | strmInput.Free;
135 | // iterate through the selected hashes
136 | for i := 0 to Length(Hashes) - 1 do
137 | begin
138 | SetLength(HashDigest,Hashes[i].HashSize div 8);
139 | Hashes[i].Final(HashDigest[0]); // get the output
140 | s := '';
141 | for j := 0 to Length(HashDigest) - 1 do // convert it into a hex string
142 | s := s + IntToHex(HashDigest[j],2);
143 | txtOutput.Lines.Add(Hashes[i].Algorithm + ': ' + s);
144 | end;
145 | except
146 | strmInput.Free;
147 | MessageDlg('An error occurred while reading the file',mtError,[mbOK],0);
148 | end;
149 | end;
150 |
151 | end.
152 |
--------------------------------------------------------------------------------
/Docs/BlockCiphers.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | DCPcrypt v2: Users Guide - Block Ciphers
4 |
5 |
6 | DCPcrypt Cryptographic Component Library v2
7 | Copyright © 1999-2002 David Barton
8 | http://www.cityinthesky.co.uk/
9 | crypto@cityinthesky.co.uk
10 |
Block Ciphers - TDCP_blockcipher
11 |
All block ciphers are inherited from the TDCP_blockcipher component via either the TDCP_blockcipher64 and TDCP_blockcipher128 components (the latter implement the block size specific code).
12 |
The TDCP_blockcipher component extends the TDCP_cipher component to provide chaining mode functions. Functions available are:
13 |
14 | property Initialized : boolean;
15 | property Id : integer;
16 | property Algorithm : string;
17 | property MaxKeySize : integer;
18 | property BlockSize : integer;
19 | property CipherMode : TDCP_ciphermode;
20 |
21 | class function SelfTest : boolean;
22 |
23 | procedure SetIV (const Value);
24 | procedure GetIV (var Value);
25 |
26 | procedure Init (const Key; Size: longword; InitVector: pointer);
27 | procedure InitStr (const Key: string; HashType: TDCP_hashclass);
28 | procedure Burn ;
29 | procedure Reset ;
30 | procedure Encrypt (const Indata; var Outdata; Size: longword);
31 | procedure Decrypt (const Indata; var Outdata; Size: longword);
32 | function EncryptStream (InStream, OutStream: TStream; Size: longword): longword;
33 | function DecryptStream (InStream, OutStream: TStream; Size: longword): longword;
34 | function EncryptString (const Str: string): string;
35 | function DecryptString (const Str: string): string;
36 | procedure EncryptECB (const Indata; var Outdata);
37 | procedure DecryptECB (const Indata; var Outdata);
38 | procedure EncryptCBC (const Indata; var Outdata; Size: longword);
39 | procedure DecryptCBC (const Indata; var Outdata; Size: longword);
40 | procedure EncryptCFB8bit (const Indata; var Outdata; Size: longword);
41 | procedure DecryptCFB8bit (const Indata; var Outdata; Size: longword);
42 | procedure EncryptCFBblock (const Indata; var Outdata; Size: longword);
43 | procedure DecryptCFBblock (const Indata; var Outdata; Size: longword);
44 | procedure EncryptOFB (const Indata; var Outdata; Size: longword);
45 | procedure DecryptOFB (const Indata; var Outdata; Size: longword);
46 | procedure EncryptCTR (const Indata; var Outdata; Size: longword);
47 | procedure DecryptCTR (const Indata; var Outdata; Size: longword);
48 |
49 |
50 | Function descriptions
51 |
property BlockSize: integer;
52 |
This contains the block size of the cipher in BITS.
53 |
property CipherMode: TDCP_ciphermode;
54 |
This is the current chaining mode used when Encrypt is called. The available modes are:
55 |
56 | cmCBC - Cipher block chaining.
57 | cmCFB8bit - 8bit cipher feedback.
58 | cmCFBblock - Cipher feedback (using the block size of the algorithm).
59 | cmOFB - Output feedback.
60 | cmCTR - Counter.
61 |
62 | Each chaining mode has it's own pro's and cons. See any good book on cryptography or the NIST publication SP800-38A for details on each.
63 |
procedure SetIV(const Value);
64 |
Use this procedure to set the current chaining mode information to Value. This variable should be the same size as the block size. When Reset is called subsequent to this, the chaining information will be set back to Value.
65 |
procedure GetIV(var Value);
66 |
This returns in Value the current chaining mode information, to get the initial chaining mode information you need to call Reset before calling GetIV. The variable passed in Value must be at least the same size as the block size otherwise you will get a buffer overflow.
67 |
procedure EncryptCBC(const Indata; var Outdata; Size: longword);
68 | procedure DecryptCBC(const Indata; var Outdata; Size: longword);
69 | procedure EncryptCFB8bit(const Indata; var Outdata; Size: longword);
70 | procedure DecryptCFB8bit(const Indata; var Outdata; Size: longword);
71 | procedure EncryptCFBblock(const Indata; var Outdata; Size: longword);
72 | procedure DecryptCFBblock(const Indata; var Outdata; Size: longword);
73 | procedure EncryptOFB(const Indata; var Outdata; Size: longword);
74 | procedure DecryptOFB(const Indata; var Outdata; Size: longword);
75 | procedure EncryptCTR(const Indata; var Outdata; Size: longword);
76 | procedure DecryptCTR(const Indata; var Outdata; Size: longword);
77 |
These procedures encrypt/decrypt Size bytes of data from Indata and places the result in Outdata. These all employ chaining mode methods of encryption/decryption and so may need to be used inconjunction with Reset . The CBC method uses short block encryption as specified in Bruce Schneier's "Applied Cryptography" for data blocks that are not multiples of the block size.
78 |
79 |
Index , Ciphers , Hashes
80 |
81 |
DCPcrypt is copyrighted © 1999-2002 David Barton.
82 | All trademarks are property of their respective owners.
83 |
84 |
85 |
--------------------------------------------------------------------------------
/Docs/Hashes.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | DCPcrypt v2: Users Guide - Hash Algorithms
4 |
5 |
6 | DCPcrypt Cryptographic Component Library v2
7 | Copyright © 1999-2002 David Barton
8 | http://www.cityinthesky.co.uk/
9 | crypto@cityinthesky.co.uk
10 |
Hash Algorithms - TDCP_hash
11 |
All hashes are derived from the TDCP_hash component. It provides a range of functions to allow the hashing of virtually every type of data.
12 |
Functions available are:
13 |
14 | property Initialized : boolean;
15 | property Id: integer ;
16 | property Algorithm : string;
17 | property HashSize : integer;
18 |
19 | class function SelfTest : boolean;
20 |
21 | procedure Init ;
22 | procedure Final (var Digest);
23 | procedure Burn ;
24 |
25 | procedure Update (const Buffer; Size: longword);
26 | procedure UpdateStream (Stream: TStream; Size: longword);
27 | procedure UpdateStr (const Str: string);
28 |
29 | Example usage:
30 |
33 |
34 | property Initialized: boolean;
35 |
This is set to true after Init has been called.
36 |
property Id: integer;
37 |
Every algorithm I implement gets given a unique ID number so that if I use several different algorithms within a program I can determine which one was used. This is a purely arbitrary numbering system.
38 |
property Algorithm: string;
39 |
This is the name of the algorithm implemented in the component.
40 |
property HashSize: integer;
41 |
This is the size of the output of the hash algorithm in BITS.
42 |
class function SelfTest: boolean;
43 |
In order to test whether the implementations have all been compiled correctly you can call the SelfTest function. This compares the results of several hash operations with known results for the algorithms (so called test vectors). If all the tests are passed then true is returned. If ANY of the tests are failed then false is returned. You may want to run this function for all the components when you first install the DCPcrypt package and again if you modify any of the source files, you don't need to run this everytime your program is run. Note: this only performs a selection of tests, it is not exhaustive.
44 |
procedure Init;
45 |
Call this procedure to initialize the hash algorithm, this must be called before using the Update procedure.
46 |
procedure Final(var Digest);
47 |
This procedure returns the final message digest (hash) in Digest. This variable must be the same size as the hash size. This procedure also calls Burn to clear any stored information.
48 |
procedure Burn;
49 |
Call this procedure if you want to abort the hashing operation (normally Final is used). This clears all information stored within the hash. Before the hash can be used again Init must be called.
50 |
procedure Update(const Buffer; Size: longword);
51 |
This procedure hashes Size bytes of Buffer. To get the hash result call Final .
52 |
Update example:
53 |
54 | procedure HashBuffer(const Buffer; Size: longint ; var Output);
55 | var
56 | Hash: TDCP_ripemd160;
57 | begin
58 | Hash:= TDCP_ripemd160.Create(nil );
59 | Hash.Init;
60 | Hash.Update(Buffer,Size);
61 | Hash.Final(Output);
62 | Hash.Free;
63 | end ;
64 |
65 | procedure UpdateStream(Stream: TStream; Size: longword);
66 |
This procedure hashes Size bytes from Stream. To get the hash result call Final .
67 |
procedure UpdateStr(const Str: string);
68 |
This procedure hashes the string Str. To get the hash result call Final .
69 |
70 | Example 1 - File hashing
71 |
This example shows how you can hash the contents of a file
72 |
73 | procedure TForm1.Button1Click(Sender: TObject);
74 | var
75 | Hash: TDCP_ripemd160;
76 | Digest: array [0..19] of byte ; // RipeMD-160 produces a 160bit digest (20bytes)
77 | Source: TFileStream;
78 | i: integer ;
79 | s: string;
80 | begin
81 | Source:= nil ;
82 | try
83 | Source:= TFileStream.Create(Edit1.Text,fmOpenRead); // open the file specified by Edit1
84 | except
85 | MessageDlg('Unable to open file',mtError,[mbOK],0);
86 | end ;
87 | if Source <> nil then
88 | begin
89 | Hash:= TDCP_ripemd160.Create(Self); // create the hash
90 | Hash.Init; // initialize it
91 | Hash.UpdateStream(Source,Source.Size); // hash the stream contents
92 | Hash.Final(Digest); // produce the digest
93 | Source.Free;
94 | s:= '';
95 | for i:= 0 to 19 do
96 | s:= s + IntToHex(Digest[i],2);
97 | Edit2.Text:= s; // display the digest
98 | end ;
99 | end ;
100 |
101 |
102 |
Index , Ciphers , Block Ciphers
103 |
104 |
DCPcrypt is copyrighted © 1999-2002 David Barton.
105 | All trademarks are property of their respective owners.
106 |
107 |
108 |
--------------------------------------------------------------------------------
/Docs/MIT_license.txt:
--------------------------------------------------------------------------------
1 | The MIT License
2 |
3 | Copyright (c)
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a
6 | copy of this software and associated documentation files (the "Software"),
7 | to deal in the Software without restriction, including without limitation
8 | the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 | and/or sell copies of the Software, and to permit persons to whom the
10 | Software is furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 | THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 | DEALINGS IN THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Docs/osi-certified-120x100.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/CHERTS/DCPcrypt/6bafdd9981f0c716303d0c0558d250314aeffa58/Docs/osi-certified-120x100.png
--------------------------------------------------------------------------------
/Hashes/DCPmd4.pas:
--------------------------------------------------------------------------------
1 | {******************************************************************************}
2 | {* DCPcrypt v2.0 written by David Barton (crypto@cityinthesky.co.uk) **********}
3 | {******************************************************************************}
4 | {* A binary compatible implementation of MD4 **********************************}
5 | {******************************************************************************}
6 | {* Copyright (c) 1999-2002 David Barton *}
7 | {* Permission is hereby granted, free of charge, to any person obtaining a *}
8 | {* copy of this software and associated documentation files (the "Software"), *}
9 | {* to deal in the Software without restriction, including without limitation *}
10 | {* the rights to use, copy, modify, merge, publish, distribute, sublicense, *}
11 | {* and/or sell copies of the Software, and to permit persons to whom the *}
12 | {* Software is furnished to do so, subject to the following conditions: *}
13 | {* *}
14 | {* The above copyright notice and this permission notice shall be included in *}
15 | {* all copies or substantial portions of the Software. *}
16 | {* *}
17 | {* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *}
18 | {* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *}
19 | {* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *}
20 | {* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *}
21 | {* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *}
22 | {* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *}
23 | {* DEALINGS IN THE SOFTWARE. *}
24 | {******************************************************************************}
25 | unit DCPmd4;
26 |
27 | interface
28 | uses
29 | Classes, Sysutils, DCPcrypt2, DCPconst;
30 |
31 | type
32 | TDCP_md4= class(TDCP_hash)
33 | protected
34 | LenHi, LenLo: longword;
35 | Index: DWord;
36 | CurrentHash: array[0..3] of DWord;
37 | HashBuffer: array[0..63] of byte;
38 | procedure Compress;
39 | public
40 | class function GetId: integer; override;
41 | class function GetAlgorithm: string; override;
42 | class function GetHashSize: integer; override;
43 | class function SelfTest: boolean; override;
44 | procedure Init; override;
45 | procedure Burn; override;
46 | procedure Update(const Buffer; Size: longword); override;
47 | procedure Final(var Digest); override;
48 | end;
49 |
50 |
51 |
52 | {******************************************************************************}
53 | {******************************************************************************}
54 | implementation
55 | {$R-}{$Q-}
56 |
57 | function LRot32(a, b: longword): longword;
58 | begin
59 | Result:= (a shl b) or (a shr (32-b));
60 | end;
61 |
62 | procedure TDCP_md4.Compress;
63 | var
64 | Data: array[0..15] of dword;
65 | A, B, C, D: dword;
66 | begin
67 | Move(HashBuffer,Data,Sizeof(Data));
68 | A:= CurrentHash[0];
69 | B:= CurrentHash[1];
70 | C:= CurrentHash[2];
71 | D:= CurrentHash[3];
72 |
73 | A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 0],3);
74 | D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 1],7);
75 | C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 2],11);
76 | B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 3],19);
77 | A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 4],3);
78 | D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 5],7);
79 | C:= LRot32(C + (B xor (D and (A xor B))) + Data[ 6],11);
80 | B:= LRot32(B + (A xor (C and (D xor A))) + Data[ 7],19);
81 | A:= LRot32(A + (D xor (B and (C xor D))) + Data[ 8],3);
82 | D:= LRot32(D + (C xor (A and (B xor C))) + Data[ 9],7);
83 | C:= LRot32(C + (B xor (D and (A xor B))) + Data[10],11);
84 | B:= LRot32(B + (A xor (C and (D xor A))) + Data[11],19);
85 | A:= LRot32(A + (D xor (B and (C xor D))) + Data[12],3);
86 | D:= LRot32(D + (C xor (A and (B xor C))) + Data[13],7);
87 | C:= LRot32(C + (B xor (D and (A xor B))) + Data[14],11);
88 | B:= LRot32(B + (A xor (C and (D xor A))) + Data[15],19);
89 |
90 | A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 0] + $5a827999,3);
91 | D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 4] + $5a827999,5);
92 | C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 8] + $5a827999,9);
93 | B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[12] + $5a827999,13);
94 | A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 1] + $5a827999,3);
95 | D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 5] + $5a827999,5);
96 | C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[ 9] + $5a827999,9);
97 | B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[13] + $5a827999,13);
98 | A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 2] + $5a827999,3);
99 | D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 6] + $5a827999,5);
100 | C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[10] + $5a827999,9);
101 | B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[14] + $5a827999,13);
102 | A:= LRot32(A + ((B and C) or (B and D) or (C and D)) + Data[ 3] + $5a827999,3);
103 | D:= LRot32(D + ((A and B) or (A and C) or (B and C)) + Data[ 7] + $5a827999,5);
104 | C:= LRot32(C + ((D and A) or (D and B) or (A and B)) + Data[11] + $5a827999,9);
105 | B:= LRot32(B + ((C and D) or (C and A) or (D and A)) + Data[15] + $5a827999,13);
106 |
107 | A:= LRot32(A + (B xor C xor D) + Data[ 0] + $6ed9eba1,3);
108 | D:= LRot32(D + (A xor B xor C) + Data[ 8] + $6ed9eba1,9);
109 | C:= LRot32(C + (D xor A xor B) + Data[ 4] + $6ed9eba1,11);
110 | B:= LRot32(B + (C xor D xor A) + Data[12] + $6ed9eba1,15);
111 | A:= LRot32(A + (B xor C xor D) + Data[ 2] + $6ed9eba1,3);
112 | D:= LRot32(D + (A xor B xor C) + Data[10] + $6ed9eba1,9);
113 | C:= LRot32(C + (D xor A xor B) + Data[ 6] + $6ed9eba1,11);
114 | B:= LRot32(B + (C xor D xor A) + Data[14] + $6ed9eba1,15);
115 | A:= LRot32(A + (B xor C xor D) + Data[ 1] + $6ed9eba1,3);
116 | D:= LRot32(D + (A xor B xor C) + Data[ 9] + $6ed9eba1,9);
117 | C:= LRot32(C + (D xor A xor B) + Data[ 5] + $6ed9eba1,11);
118 | B:= LRot32(B + (C xor D xor A) + Data[13] + $6ed9eba1,15);
119 | A:= LRot32(A + (B xor C xor D) + Data[ 3] + $6ed9eba1,3);
120 | D:= LRot32(D + (A xor B xor C) + Data[11] + $6ed9eba1,9);
121 | C:= LRot32(C + (D xor A xor B) + Data[ 7] + $6ed9eba1,11);
122 | B:= LRot32(B + (C xor D xor A) + Data[15] + $6ed9eba1,15);
123 |
124 | Inc(CurrentHash[0],A);
125 | Inc(CurrentHash[1],B);
126 | Inc(CurrentHash[2],C);
127 | Inc(CurrentHash[3],D);
128 | Index:= 0;
129 | FillChar(HashBuffer,Sizeof(HashBuffer),0);
130 | end;
131 |
132 | class function TDCP_md4.GetHashSize: integer;
133 | begin
134 | Result:= 128;
135 | end;
136 |
137 | class function TDCP_md4.GetId: integer;
138 | begin
139 | Result:= DCP_md4;
140 | end;
141 |
142 | class function TDCP_md4.GetAlgorithm: string;
143 | begin
144 | Result:= 'MD4';
145 | end;
146 |
147 | class function TDCP_md4.SelfTest: boolean;
148 | const
149 | Test1Out: array[0..15] of byte=
150 | ($a4,$48,$01,$7a,$af,$21,$d8,$52,$5f,$c1,$0a,$e8,$7a,$a6,$72,$9d);
151 | Test2Out: array[0..15] of byte=
152 | ($d7,$9e,$1c,$30,$8a,$a5,$bb,$cd,$ee,$a8,$ed,$63,$df,$41,$2d,$a9);
153 | var
154 | TestHash: TDCP_md4;
155 | TestOut: array[0..19] of byte;
156 | begin
157 | TestHash:= TDCP_md4.Create(nil);
158 | TestHash.Init;
159 | TestHash.UpdateStr('abc');
160 | TestHash.Final(TestOut);
161 | Result:= CompareMem(@TestOut,@Test1Out,Sizeof(Test1Out));
162 | TestHash.Init;
163 | TestHash.UpdateStr('abcdefghijklmnopqrstuvwxyz');
164 | TestHash.Final(TestOut);
165 | Result:= CompareMem(@TestOut,@Test2Out,Sizeof(Test2Out)) and Result;
166 | TestHash.Free;
167 | end;
168 |
169 | procedure TDCP_md4.Init;
170 | begin
171 | Burn;
172 | CurrentHash[0]:= $67452301;
173 | CurrentHash[1]:= $efcdab89;
174 | CurrentHash[2]:= $98badcfe;
175 | CurrentHash[3]:= $10325476;
176 | fInitialized:= true;
177 | end;
178 |
179 | procedure TDCP_md4.Burn;
180 | begin
181 | LenHi:= 0; LenLo:= 0;
182 | Index:= 0;
183 | FillChar(HashBuffer,Sizeof(HashBuffer),0);
184 | FillChar(CurrentHash,Sizeof(CurrentHash),0);
185 | fInitialized:= false;
186 | end;
187 |
188 | procedure TDCP_md4.Update(const Buffer; Size: longword);
189 | var
190 | PBuf: ^byte;
191 | begin
192 | if not fInitialized then
193 | raise EDCP_hash.Create('Hash not initialized');
194 |
195 | Inc(LenHi,Size shr 29);
196 | Inc(LenLo,Size*8);
197 | if LenLo< (Size*8) then
198 | Inc(LenHi);
199 |
200 | PBuf:= @Buffer;
201 | while Size> 0 do
202 | begin
203 | if (Sizeof(HashBuffer)-Index)<= DWord(Size) then
204 | begin
205 | Move(PBuf^,HashBuffer[Index],Sizeof(HashBuffer)-Index);
206 | Dec(Size,Sizeof(HashBuffer)-Index);
207 | Inc(PBuf,Sizeof(HashBuffer)-Index);
208 | Compress;
209 | end
210 | else
211 | begin
212 | Move(PBuf^,HashBuffer[Index],Size);
213 | Inc(Index,Size);
214 | Size:= 0;
215 | end;
216 | end;
217 | end;
218 |
219 | procedure TDCP_md4.Final(var Digest);
220 | begin
221 | if not fInitialized then
222 | raise EDCP_hash.Create('Hash not initialized');
223 | HashBuffer[Index]:= $80;
224 | if Index>= 56 then
225 | Compress;
226 | PDWord(@HashBuffer[56])^:= LenLo;
227 | PDWord(@HashBuffer[60])^:= LenHi;
228 | Compress;
229 | Move(CurrentHash,Digest,Sizeof(CurrentHash));
230 | Burn;
231 | end;
232 |
233 | end.
234 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # DCPcrypt
2 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
3 | = DCPcrypt Cryptographic Component Library v2 =
4 | = Copyright (c) 1999-2009 David Barton =
5 | = http://www.cityinthesky.co.uk/ =
6 | = crypto@cityinthesky.co.uk =
7 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
8 |
9 |
--------------------------------------------------------------------------------
/Readme.txt:
--------------------------------------------------------------------------------
1 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2 | = DCPcrypt Cryptographic Component Library v2 =
3 | = Copyright (c) 1999-2009 David Barton =
4 | = http://www.cityinthesky.co.uk/ =
5 | = crypto@cityinthesky.co.uk =
6 | =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 |
8 | UPDATE:
9 |
10 | Included is an update for Delphi 2009 by Henri Gourvest. Note: I have
11 | not tested this myself (I don't have Delphi 2009)
12 |
13 |
14 | Introduction:
15 |
16 | DCPcrypt is a collection of cryptographic components for the Borland
17 | Delphi(tm), C++ Builder(tm) and Kylix(tm) programming languages. The
18 | supported versions are Delphi 4, 5, 6, 7, 2005, C++ Builder (3?), 4,
19 | 5, (6?) and Kylix 1 (untested), 2 and 3 (untested).
20 |
21 | Thanks to Manuel C. for the modifications to make DCPcrypt work under
22 | Delphi 2005!
23 |
24 | The idea behind DCPcrypt is that it should be possible to "drop in"
25 | any algorithm implementation to replace another with minimum or no
26 | code changes. To aid in this goal all cryptographic components are
27 | descended from one of several base classes, TDCP_cipher for encryption
28 | algorithms and TDCP_hash for message digest algorithms.
29 |
30 | DCPcrypt is open source software (released under the MIT license) and
31 | as such there is no charge for inclusion in other software. However, I
32 | am currently a student and if you are making money from my software I
33 | would really appreciate a donation of some sort, whether financial or
34 | a license for the software you develop (or if anyone wants to sponsor
35 | a Mathematical Modelling (Masters) student for their final year...).
36 | Please note THIS IS NOT COMPULSORY IN ANY WAY. See
37 | http://www.cityinthesky.co.uk/cryptography.html for details on
38 | financial donations.
39 |
40 | This software is OSI Certified Open Source Software.
41 | OSI Certified is a certification mark of the Open Source Initiative.
42 |
43 | If you maintain a website then a link to my page at
44 | http://www.cityinthesky.co.uk/ would be great!
45 |
46 |
47 |
48 | What's New:
49 |
50 | Changes since DCPcrypt v2 Beta 2 include
51 |
52 | * Corrected C++ Builder compilation problem.
53 |
54 |
55 | Changes since DCPcrypt v2 Beta 1 include
56 |
57 | * Renamed source code files for hashes and ciphers to DCPxxx.pas
58 |
59 | * Change the format of Cipher.InitStr so that the hash algorithm
60 | used to generate the key is explicitly specified. In order to
61 | get the same functionality as before, use TDCP_sha1.
62 | e.g. Cipher.InitStr('Hello World',TDCP_sha1);
63 |
64 | * Block ciphers are now inherited from an intermediate component
65 | that implements the block size specific chaining mode encryption
66 | routines.
67 |
68 | * Remove the internal component registration, it was more hassle
69 | than it was worth. If there is a demand for this to be put back
70 | then I might...
71 |
72 | * Added the full range of operation modes for Haval. By changing
73 | the defines at the top of DCPhaval.pas you can specify the
74 | number of passes and the output hash size.
75 |
76 | * Added the Tiger hash algorithm (192bit digest).
77 |
78 | * Changed the name of the file containing TDCP_ripemd160 for
79 | consistency to DCPripemd160 from DCPrmd160.
80 |
81 | * GOST no longer appears on the component palette pending verifying
82 | what the actual standard is (the code is still included however).
83 |
84 | * Added the RipeMD-128 hash algorithm (128bit digest).
85 |
86 | * Added the Serpent block cipher (AES finalist).
87 |
88 | * Added the SHA-256,384,512 hash algorithms (256, 384, 512bit digest
89 | respectively).
90 |
91 | * Added CTR chaining mode to all block ciphers.
92 |
93 |
94 |
95 | Installation:
96 |
97 | Delphi: Open the appropriate package, DCPdelphiX.dpk where X is
98 | your version of Delphi (either 4, 5 or 6). Then press the
99 | install button.
100 |
101 | C++ Builder: Create a new design time package and add all the .pas
102 | files from the DCPcrypt2.zip archive including all those
103 | in the Ciphers and Hashes subdirectories. Then press the
104 | install button.
105 |
106 | Kylix: Open the DCPkylix.dpk package and then press the install
107 | button (note: Kylix 1 users may need to create a new
108 | package as with C++ Builder as this is a Kylix 2 package).
109 |
110 | You may need to add the directory containing DCPcrypt (and the Ciphers
111 | and Hashes subdirectories) to your library search path (found under
112 | Environment Options).
113 |
114 | Once installed you will find two extra pages of components on your
115 | component palette, namely DCPciphers and DCPhashes. You can now place
116 | these components onto the form of your application to start using the
117 | algorithms.
118 |
119 |
120 |
121 | Usage:
122 |
123 | See the main html documentation in the Docs subdirectory.
124 |
125 |
126 |
127 | Contact:
128 |
129 | I appreciate knowing what DCPcrypt is being used for and also if you
130 | have any queries or bug reports please email me at crypto@cityinthesky.co.uk.
131 |
132 |
133 |
134 | DCPcrypt is copyrighted (c) 1999-2003 David Barton.
135 | All trademarks are property of their respective owners.
136 |
--------------------------------------------------------------------------------