Skip to content

Commit c2ebefd

Browse files
committed
Merge remote-tracking branch 'origin/development'
# Conflicts: # Source/DECHashBase.pas # Unit Tests/Tests/TestDECHash.pas
2 parents e7d84f7 + 9e74163 commit c2ebefd

33 files changed

+6582
-783
lines changed

Demos/HashBenchmark_FMX/MainForm.pas

Lines changed: 48 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,17 @@ implementation
9595

9696
uses
9797
Generics.Collections,
98-
DECBaseClass, DECHashBase, DECHash;
98+
DECBaseClass, DECHashBase, DECHashAUthentication, DECHash;
9999

100100
const
101101
/// <summary>
102102
/// Number of times the buffer will be calculated a hash over
103103
/// </summary>
104104
cIterations = 10;
105+
/// <summary>
106+
/// Size of the buffer for one single calculation pass of one algorithm
107+
/// </summary>
108+
cBufferSize = 1024 * 1024;
105109

106110
{$R *.fmx}
107111

@@ -152,7 +156,7 @@ procedure TFormMain.b_StartClick(Sender: TObject);
152156
b_CopyToClipboard.Enabled := false;
153157
sg_Results.RowCount := 0;
154158
// Create 1 MB Buffer
155-
SetLength(FBenchmarkBuffer, 1024*1024);
159+
SetLength(FBenchmarkBuffer, cBufferSize);
156160

157161
n := 0;
158162
for i := 0 to Length(FBenchmarkBuffer)-1 do
@@ -209,23 +213,61 @@ procedure TFormMain.RunBenchmark(ClassName: string; RowIndex: Integer);
209213
var
210214
Hash : TDECHash;
211215
HashResult : TBytes;
212-
i : Integer;
216+
i, n : Integer;
217+
Iterations : UInt32;
218+
BufferSize : UInt32;
219+
Salt : TBytes;
213220
begin
214221
Hash := TDECHash.ClassByName(ClassName).Create;
215222

216223
try
224+
Iterations := cIterations;
225+
BufferSize := cBufferSize;
226+
227+
// Some special password hash algorithms only allow for a low number of
228+
// bytes to be hashed. If such an algorithm is to be tested we adjust the
229+
// parameters in order to not run into exceptions but still test the aprox.
230+
// same amount of data
231+
if Hash.IsPasswordHash and
232+
(TDECPasswordHash(Hash).MaxPasswordLength < BufferSize) then
233+
begin
234+
BufferSize := TDECPasswordHash(Hash).MaxPasswordLength;
235+
236+
// Since password hashes take quite long time to calculate limit that time
237+
// by limiting the number of iterations calculated but in such a way that
238+
// all special password hashes calculate aprox. the same amount of data
239+
Iterations := (cIterations * cBufferSize);
240+
if (Iterations > 18000) then
241+
Iterations := 18000;
242+
Iterations := Iterations div BufferSize;
243+
244+
SetLength(Salt, TDECPasswordHash(Hash).MaxSaltLength);
245+
n := 0;
246+
247+
for i := 0 to length(Salt)-1 do
248+
begin
249+
Salt[i] := n;
250+
inc(n);
251+
if (n > 255) then
252+
n := 0;
253+
end;
254+
255+
TDECPasswordHash(Hash).Salt := Salt;
256+
end;
257+
217258
FStopwatch.Reset;
218259
FStopwatch.Start;
219260

220-
for i := 0 to cIterations - 1 do
261+
for i := 0 to Iterations - 1 do
221262
begin
222-
HashResult := Hash.CalcBytes(FBenchmarkBuffer);
263+
// HashResult := Hash.CalcBytes(FBenchmarkBuffer);
264+
HashResult := Hash.CalcBuffer(@FBenchmarkBuffer[0], BufferSize);
223265
end;
224266

225267
FStopwatch.Stop;
226268

227269
sg_Results.Cells[1, RowIndex] :=
228-
Format('%0:f', [cIterations / (FStopwatch.ElapsedMilliseconds/1000)]);
270+
Format('%0:f', [Iterations / (FStopwatch.ElapsedMilliseconds/1000)]);
229271
sg_Results.Cells[2, RowIndex] := FStopwatch.Elapsed;
230272
finally
231273
Hash.Free;

Demos/Hash_FMX/MainForm.fmx

Lines changed: 108 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ object FormMain: TFormMain
33
Top = 0
44
BorderStyle = Single
55
Caption = 'DEC hash demo'
6-
ClientHeight = 790
6+
ClientHeight = 970
77
ClientWidth = 452
88
FormFactor.Width = 320
99
FormFactor.Height = 480
1010
FormFactor.Devices = [Desktop]
1111
OnCreate = FormCreate
12-
DesignerMasterStyle = 0
12+
DesignerMasterStyle = 3
1313
object VertScrollBox1: TVertScrollBox
1414
Align = Client
1515
Size.Width = 452.000000000000000000
16-
Size.Height = 790.000000000000000000
16+
Size.Height = 970.000000000000000000
1717
Size.PlatformDefault = False
1818
StyleLookup = 'scrollboxstyle'
1919
TabOrder = 0
2020
OnCalcContentBounds = VertScrollBox1CalcContentBounds
21-
Viewport.Width = 436.000000000000000000
22-
Viewport.Height = 790.000000000000000000
21+
Viewport.Width = 447.000000000000000000
22+
Viewport.Height = 970.000000000000000000
2323
object LayoutBottom: TLayout
24-
Position.Y = 520.000000000000000000
24+
Position.Y = 740.000000000000000000
2525
Size.Width = 425.000000000000000000
2626
Size.Height = 450.000000000000000000
2727
Size.PlatformDefault = False
@@ -30,8 +30,8 @@ object FormMain: TFormMain
3030
AutoSize = True
3131
Position.X = 16.000000000000000000
3232
Position.Y = 8.000000000000000000
33-
Size.Width = 28.000000000000000000
34-
Size.Height = 16.000000000000000000
33+
Size.Width = 42.000000000000000000
34+
Size.Height = 22.000000000000000000
3535
Size.PlatformDefault = False
3636
StyleLookup = 'labelstyle'
3737
TextSettings.WordWrap = False
@@ -41,8 +41,8 @@ object FormMain: TFormMain
4141
AutoSize = True
4242
Position.X = 16.000000000000000000
4343
Position.Y = 80.000000000000000000
44-
Size.Width = 97.000000000000000000
45-
Size.Height = 16.000000000000000000
44+
Size.Width = 150.000000000000000000
45+
Size.Height = 22.000000000000000000
4646
Size.PlatformDefault = False
4747
StyleLookup = 'labelstyle'
4848
TextSettings.WordWrap = False
@@ -87,12 +87,12 @@ object FormMain: TFormMain
8787
AutoSize = True
8888
Position.X = 16.000000000000000000
8989
Position.Y = 192.000000000000000000
90-
Size.Width = 178.000000000000000000
91-
Size.Height = 16.000000000000000000
90+
Size.Width = 272.000000000000000000
91+
Size.Height = 22.000000000000000000
9292
Size.PlatformDefault = False
9393
StyleLookup = 'labelstyle'
9494
TextSettings.WordWrap = False
95-
Text = #169' 2018-2021 by Team DEC V%0:s'
95+
Text = #169' 2018-2022 by Team DEC V%0:s'
9696
end
9797
end
9898
object LayoutTop: TLayout
@@ -136,8 +136,8 @@ object FormMain: TFormMain
136136
AutoSize = True
137137
Position.X = 16.000000000000000000
138138
Position.Y = 16.000000000000000000
139-
Size.Width = 74.000000000000000000
140-
Size.Height = 16.000000000000000000
139+
Size.Width = 114.000000000000000000
140+
Size.Height = 22.000000000000000000
141141
Size.PlatformDefault = False
142142
StyleLookup = 'labelstyle'
143143
TextSettings.WordWrap = False
@@ -147,8 +147,8 @@ object FormMain: TFormMain
147147
AutoSize = True
148148
Position.X = 16.000000000000000000
149149
Position.Y = 88.000000000000000000
150-
Size.Width = 91.000000000000000000
151-
Size.Height = 16.000000000000000000
150+
Size.Width = 139.000000000000000000
151+
Size.Height = 22.000000000000000000
152152
Size.PlatformDefault = False
153153
StyleLookup = 'labelstyle'
154154
TextSettings.WordWrap = False
@@ -158,8 +158,8 @@ object FormMain: TFormMain
158158
AutoSize = True
159159
Position.X = 16.000000000000000000
160160
Position.Y = 160.000000000000000000
161-
Size.Width = 119.000000000000000000
162-
Size.Height = 16.000000000000000000
161+
Size.Width = 178.000000000000000000
162+
Size.Height = 22.000000000000000000
163163
Size.PlatformDefault = False
164164
StyleLookup = 'labelstyle'
165165
TextSettings.WordWrap = False
@@ -203,9 +203,9 @@ object FormMain: TFormMain
203203
object LabelHashLength: TLabel
204204
AutoSize = True
205205
Position.X = 16.000000000000000000
206-
Position.Y = 484.000000000000000000
206+
Position.Y = 496.000000000000000000
207207
Size.Width = 242.000000000000000000
208-
Size.Height = 16.000000000000000000
208+
Size.Height = 22.000000000000000000
209209
Size.PlatformDefault = False
210210
StyleLookup = 'labelstyle'
211211
Text = 'Generated hash length (byte)'
@@ -221,7 +221,7 @@ object FormMain: TFormMain
221221
Text = '64'
222222
TextSettings.HorzAlign = Trailing
223223
Position.X = 317.000000000000000000
224-
Position.Y = 468.000000000000000000
224+
Position.Y = 484.000000000000000000
225225
Size.Width = 100.000000000000000000
226226
Size.Height = 32.000000000000000000
227227
Size.PlatformDefault = False
@@ -232,7 +232,7 @@ object FormMain: TFormMain
232232
Position.X = 16.000000000000000000
233233
Position.Y = 332.000000000000000000
234234
Size.Width = 242.000000000000000000
235-
Size.Height = 16.000000000000000000
235+
Size.Height = 22.000000000000000000
236236
Size.PlatformDefault = False
237237
StyleLookup = 'labelstyle'
238238
Text = 'Number of rounds'
@@ -282,9 +282,9 @@ object FormMain: TFormMain
282282
Anchors = [akLeft, akTop, akRight]
283283
AutoSize = True
284284
Position.X = 16.000000000000000000
285-
Position.Y = 390.000000000000000000
285+
Position.Y = 406.000000000000000000
286286
Size.Width = 293.000000000000000000
287-
Size.Height = 32.000000000000000000
287+
Size.Height = 44.000000000000000000
288288
Size.PlatformDefault = False
289289
StyleLookup = 'labelstyle'
290290
TextSettings.VertAlign = Leading
@@ -302,10 +302,92 @@ object FormMain: TFormMain
302302
Text = '0'
303303
TextSettings.HorzAlign = Trailing
304304
Position.X = 317.000000000000000000
305-
Position.Y = 381.000000000000000000
305+
Position.Y = 417.000000000000000000
306+
Size.Width = 100.000000000000000000
307+
Size.Height = 32.000000000000000000
308+
Size.PlatformDefault = False
309+
end
310+
end
311+
object LayoutSalt: TLayout
312+
Position.Y = 520.000000000000000000
313+
Size.Width = 425.000000000000000000
314+
Size.Height = 220.000000000000000000
315+
Size.PlatformDefault = False
316+
TabOrder = 14
317+
object Label1: TLabel
318+
AutoSize = True
319+
Position.X = 16.000000000000000000
320+
Position.Y = 104.000000000000000000
321+
Size.Width = 32.000000000000000000
322+
Size.Height = 22.000000000000000000
323+
Size.PlatformDefault = False
324+
StyleLookup = 'labelstyle'
325+
TextSettings.WordWrap = False
326+
Text = 'Salt'
327+
TabOrder = 1
328+
end
329+
object EditSalt: TEdit
330+
Touch.InteractiveGestures = [LongTap, DoubleTap]
331+
Anchors = [akLeft, akTop, akRight]
332+
StyleLookup = 'editstyle'
333+
TabOrder = 4
334+
Position.X = 16.000000000000000000
335+
Position.Y = 128.000000000000000000
336+
Size.Width = 401.000000000000000000
337+
Size.Height = 32.000000000000000000
338+
Size.PlatformDefault = False
339+
OnChangeTracking = EditInputChangeTracking
340+
OnKeyUp = EditInputKeyUp
341+
end
342+
object Label7: TLabel
343+
AutoSize = True
344+
Position.X = 16.000000000000000000
345+
Position.Y = 16.000000000000000000
346+
Size.Width = 155.000000000000000000
347+
Size.Height = 22.000000000000000000
348+
Size.PlatformDefault = False
349+
StyleLookup = 'labelstyle'
350+
TextSettings.WordWrap = False
351+
Text = 'Desired salt format'
352+
TabOrder = 5
353+
end
354+
object ComboBoxSaltFormatting: TComboBox
355+
Anchors = [akLeft, akTop, akRight]
356+
Position.X = 16.000000000000000000
357+
Position.Y = 52.000000000000000000
358+
Size.Width = 400.000000000000000000
359+
Size.Height = 32.000000000000000000
360+
Size.PlatformDefault = False
361+
StyleLookup = 'comboboxstyle'
362+
TabOrder = 3
363+
end
364+
object Label8: TLabel
365+
AutoSize = True
366+
Position.X = 16.000000000000000000
367+
Position.Y = 184.000000000000000000
368+
Size.Width = 38.000000000000000000
369+
Size.Height = 22.000000000000000000
370+
Size.PlatformDefault = False
371+
StyleLookup = 'labelstyle'
372+
TextSettings.WordWrap = False
373+
Text = 'Cost'
374+
TabOrder = 0
375+
end
376+
object EditCost: TEdit
377+
Touch.InteractiveGestures = [LongTap, DoubleTap]
378+
Anchors = [akTop, akRight]
379+
StyleLookup = 'editstyle'
380+
TabOrder = 13
381+
MaxLength = 3
382+
FilterChar = '0123456789'
383+
Text = '10'
384+
TextSettings.HorzAlign = Trailing
385+
Position.X = 317.000000000000000000
386+
Position.Y = 180.000000000000000000
306387
Size.Width = 100.000000000000000000
307388
Size.Height = 32.000000000000000000
308389
Size.PlatformDefault = False
390+
OnChange = EditCostChange
309391
end
310392
end
311393
end

0 commit comments

Comments
 (0)