-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathSlhDsaExample.pas
More file actions
112 lines (95 loc) · 4.47 KB
/
Copy pathSlhDsaExample.pas
File metadata and controls
112 lines (95 loc) · 4.47 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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
{ *********************************************************************************** }
{ * 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 SlhDsaExample;
interface
{$IFDEF FPC}
{$MODE DELPHI}
{$HINTS OFF}
{$WARNINGS OFF}
{$ENDIF FPC}
uses
SysUtils,
ClpIAsymmetricCipherKeyPair,
ClpConverters,
ExampleBase,
PqcExampleUtilities,
KeyEncodingExampleUtilities;
type
TSlhDsaExample = class(TExampleBase)
private
procedure RunSignVerify(const AParameterSetName, ASignatureAlgorithm, AMessageText: string);
procedure RunContextSignVerify(const AParameterSetName, ASignatureAlgorithm: string);
procedure RunDerRoundtrip(const AParameterSetName: string);
procedure RunPemRoundtrip(const AParameterSetName: string);
procedure RunParameterSetDemos(const AParameterSetName, AMessageText: string);
public
procedure Run; override;
end;
implementation
procedure TSlhDsaExample.RunSignVerify(const AParameterSetName, ASignatureAlgorithm, AMessageText: string);
var
LKp: IAsymmetricCipherKeyPair;
LMsg: TBytes;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
LMsg := TConverters.ConvertStringToBytes(AMessageText, TEncoding.UTF8);
TPqcExampleUtilities.RunSignVerify(ASignatureAlgorithm, LKp, LMsg);
end;
procedure TSlhDsaExample.RunContextSignVerify(const AParameterSetName, ASignatureAlgorithm: string);
var
LKp: IAsymmetricCipherKeyPair;
LMsg, LContext: TBytes;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
LMsg := TConverters.ConvertStringToBytes('PascalSlhDsaCtx', TEncoding.UTF8);
LContext := TConverters.ConvertStringToBytes('CryptoLib4Pascal-ctx', TEncoding.UTF8);
TPqcExampleUtilities.RunContextSignVerify(ASignatureAlgorithm, LKp, LMsg, LContext);
end;
procedure TSlhDsaExample.RunDerRoundtrip(const AParameterSetName: string);
var
LKp: IAsymmetricCipherKeyPair;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
TKeyEncodingExampleUtilities.VerifyDerRoundtrip(LKp, AParameterSetName);
end;
procedure TSlhDsaExample.RunPemRoundtrip(const AParameterSetName: string);
var
LKp: IAsymmetricCipherKeyPair;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
TKeyEncodingExampleUtilities.VerifyPemRoundtrip(LKp, AParameterSetName);
end;
procedure TSlhDsaExample.RunParameterSetDemos(const AParameterSetName, AMessageText: string);
begin
LogWithLineBreak(Format('--- SLH-DSA example: pure sign/verify (%s) ---', [AParameterSetName]));
RunSignVerify(AParameterSetName, AParameterSetName, AMessageText);
LogWithLineBreak(Format('--- SLH-DSA example: context sign/verify (%s) ---',
[AParameterSetName]));
RunContextSignVerify(AParameterSetName, AParameterSetName);
LogWithLineBreak(Format('--- SLH-DSA example: DER round-trip (%s) ---', [AParameterSetName]));
RunDerRoundtrip(AParameterSetName);
LogWithLineBreak(Format('--- SLH-DSA example: PEM round-trip (%s) ---', [AParameterSetName]));
RunPemRoundtrip(AParameterSetName);
end;
procedure TSlhDsaExample.Run;
begin
RunParameterSetDemos('SLH-DSA-SHA2-128F', 'PascalSlhDsa128f');
RunParameterSetDemos('SLH-DSA-SHA2-128F-WITH-SHA256', 'PascalHashSlhDsa128f');
end;
end.