-
-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathMlKemExample.pas
More file actions
92 lines (77 loc) · 3.35 KB
/
Copy pathMlKemExample.pas
File metadata and controls
92 lines (77 loc) · 3.35 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
{ *********************************************************************************** }
{ * 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 MlKemExample;
interface
{$IFDEF FPC}
{$MODE DELPHI}
{$HINTS OFF}
{$WARNINGS OFF}
{$ENDIF FPC}
uses
SysUtils,
ClpIAsymmetricCipherKeyPair,
ExampleBase,
PqcExampleUtilities,
KeyEncodingExampleUtilities;
type
TMlKemExample = class(TExampleBase)
private
procedure RunKemRoundtrip(const AParameterSetName: string);
procedure RunDerRoundtrip(const AParameterSetName: string);
procedure RunPemRoundtrip(const AParameterSetName: string);
procedure RunParameterSetDemos(const AParameterSetName: string);
public
procedure Run; override;
end;
implementation
procedure TMlKemExample.RunKemRoundtrip(const AParameterSetName: string);
var
LKp: IAsymmetricCipherKeyPair;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
TPqcExampleUtilities.RunKemRoundtrip(AParameterSetName, LKp);
end;
procedure TMlKemExample.RunDerRoundtrip(const AParameterSetName: string);
var
LKp: IAsymmetricCipherKeyPair;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
TKeyEncodingExampleUtilities.VerifyDerRoundtrip(LKp, AParameterSetName);
end;
procedure TMlKemExample.RunPemRoundtrip(const AParameterSetName: string);
var
LKp: IAsymmetricCipherKeyPair;
begin
LKp := TPqcExampleUtilities.GenerateKeyPair(AParameterSetName);
Logger.LogInformation('Parameter set: {0}', [AParameterSetName]);
TKeyEncodingExampleUtilities.VerifyPemRoundtrip(LKp, AParameterSetName);
end;
procedure TMlKemExample.RunParameterSetDemos(const AParameterSetName: string);
begin
LogWithLineBreak(Format('--- ML-KEM example: encaps/decaps (%s) ---', [AParameterSetName]));
RunKemRoundtrip(AParameterSetName);
LogWithLineBreak(Format('--- ML-KEM example: DER round-trip (%s) ---', [AParameterSetName]));
RunDerRoundtrip(AParameterSetName);
LogWithLineBreak(Format('--- ML-KEM example: PEM round-trip (%s) ---', [AParameterSetName]));
RunPemRoundtrip(AParameterSetName);
end;
procedure TMlKemExample.Run;
begin
RunParameterSetDemos('ML-KEM-768');
RunParameterSetDemos('ML-KEM-512');
end;
end.