-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathDigestExample.pas
More file actions
80 lines (69 loc) · 3.31 KB
/
Copy pathDigestExample.pas
File metadata and controls
80 lines (69 loc) · 3.31 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
{ *********************************************************************************** }
{ * CryptoLib Library * }
{ * Author - Ugochukwu Mmaduekwe * }
{ * Github Repository <https://github.com/Xor-el> * }
{ * * }
{ * Distributed under the MIT software license, see the accompanying file LICENSE * }
{ * or visit http://www.opensource.org/licenses/mit-license.php. * }
{ * * }
{ * Acknowledgements: * }
{ * * }
{ * Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring * }
{ * the development of this library * }
{ * ******************************************************************************* * }
(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
unit DigestExample;
interface
{$IFDEF FPC}
{$MODE DELPHI}
{$HINTS OFF}
{$WARNINGS OFF}
{$ENDIF FPC}
uses
SysUtils,
ClpConverters,
ClpIArgon2ParametersGenerator,
ExampleBase,
DigestExampleUtilities;
type
TDigestExample = class(TExampleBase)
private
procedure RunDigestDemos;
public
procedure Run; override;
end;
implementation
procedure TDigestExample.RunDigestDemos;
var
LInput, LKey, LMsg, LPassword, LSalt: TBytes;
begin
LInput := TConverters.ConvertStringToBytes('Hello CryptoLib', TEncoding.UTF8);
LKey := TConverters.ConvertStringToBytes('secret-key', TEncoding.UTF8);
LMsg := TConverters.ConvertStringToBytes('message to authenticate', TEncoding.UTF8);
LPassword := TConverters.ConvertStringToBytes('password', TEncoding.UTF8);
LSalt := TConverters.ConvertStringToBytes('salt', TEncoding.UTF8);
LogWithLineBreak('--- Digest example: Hash ---');
TDigestExampleUtilities.RunHash('SHA-256', LInput);
LogWithLineBreak('--- Digest example: HMAC ---');
TDigestExampleUtilities.RunHmac('HMAC-SHA256', LKey, LMsg);
LogWithLineBreak('--- Digest example: Key derivation (PBKDF2) ---');
TDigestExampleUtilities.RunPbkdf2('SHA-256', LPassword, LSalt, 10000, 256,
'PBKDF2-HMAC-SHA-256 (10000 iters)');
LogWithLineBreak('--- Digest example: Key derivation (Argon2d) ---');
TDigestExampleUtilities.RunArgon2(TCryptoLibArgon2Type.Argon2D, LPassword, LSalt,
2, 65536, 1, 256, 'Argon2d (2 iters, 64 MiB, 1 lane)');
LogWithLineBreak('--- Digest example: Key derivation (Argon2i) ---');
TDigestExampleUtilities.RunArgon2(TCryptoLibArgon2Type.Argon2I, LPassword, LSalt,
2, 65536, 1, 256, 'Argon2i (2 iters, 64 MiB, 1 lane)');
LogWithLineBreak('--- Digest example: Key derivation (Argon2id) ---');
TDigestExampleUtilities.RunArgon2(TCryptoLibArgon2Type.Argon2ID, LPassword, LSalt,
2, 65536, 1, 256, 'Argon2id (2 iters, 64 MiB, 1 lane)');
LogWithLineBreak('--- Digest example: Key derivation (Scrypt) ---');
TDigestExampleUtilities.RunScrypt(LPassword, LSalt, 16384, 8, 1, 256,
'Scrypt (N=16384, r=8, p=1)');
end;
procedure TDigestExample.Run;
begin
RunDigestDemos;
end;
end.