Skip to content

Commit 1601600

Browse files
committed
BREAKING: normalize enum member names (hash size/rounds, SHA3 mode, Gost, Argon2)
BREAKING CHANGE: many qualified enum identifiers changed; update call sites. - THashSize: Size128…Size512 (byte counts unchanged). - THashRounds: Rounds3…Rounds8 (values unchanged). - TSHA3.THashMode: Keccak, CShake, SHA3, Shake (numeric tags unchanged). - TGost.TSBoxType: TestParamSet, CryptoProParamSet (nested under TGost). - TArgon2Type: TypeD, TypeI, TypeID ($00/$01/$02). - TArgon2Version: Version10, Version13 ($10/$13). - Drop per-unit {$SCOPEDENUMS ON/OFF}; rely on HashLib.inc. Argon2/GOST factory and tests updated. Any external code using old enumerator names must be migrated; integer values for sized enums are preserved where set.
1 parent 8d68219 commit 1601600

16 files changed

Lines changed: 130 additions & 141 deletions

HashLib.Tests/src/CryptoTests.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ procedure TTestGost.TearDown;
937937
procedure TTestGost_CryptoProParamSet.SetUp;
938938
begin
939939
inherited;
940-
HashInstance := THashFactory.TCrypto.CreateGost(TGostSBox.gsbCryptoProParamSet);
940+
HashInstance := THashFactory.TCrypto.CreateGost(TGost.TSBoxType.CryptoProParamSet);
941941
HmacInstance := THashFactory.THMAC.CreateHMAC(HashInstance);
942942
HashOfEmptyData :=
943943
'981E5F3CA30C841487830F84FB433E13AC1101569B9C13584AC483234CD656C0';

HashLib.Tests/src/PBKDF_Argon2Tests.pas

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ procedure TTestPBKDF_Argon2FromInternetDraft.TestVectorsFromInternetDraft;
117117
LPassword :=
118118
'0101010101010101010101010101010101010101010101010101010101010101';
119119

120-
Argon2Version := TArgon2Version.a2vARGON2_VERSION_13;
120+
Argon2Version := TArgon2Version.Version13;
121121

122122
Argon2ParametersBuilder := TArgon2dParametersBuilder.Builder();
123123

@@ -185,7 +185,7 @@ procedure TTestPBKDF_Argon2Others.TestOthers;
185185
Argon2Version: TArgon2Version;
186186
begin
187187

188-
Argon2Version := TArgon2Version.a2vARGON2_VERSION_10;
188+
Argon2Version := TArgon2Version.Version10;
189189
Argon2ParametersBuilder := TArgon2iParametersBuilder.Builder();
190190
// Multiple test cases for various input values
191191
HashTestOthers(Argon2ParametersBuilder, Argon2Version, 2, 16, 1, 'password',
@@ -234,7 +234,7 @@ procedure TTestPBKDF_Argon2Others.TestOthers;
234234
+ '39FEBA4A9CD9CC5B4C798F2AAF70EB4BD044C8D148DECB569870DBD923430B82A083F284BEAE777812CCE18CDAC68EE8CCEF'
235235
+ 'C6EC9789F30A6B5A034591F51AF830F4', 112);
236236

237-
Argon2Version := TArgon2Version.a2vARGON2_VERSION_13;
237+
Argon2Version := TArgon2Version.Version13;
238238
Argon2ParametersBuilder := TArgon2iParametersBuilder.Builder();
239239
// Multiple test cases for various input values
240240

HashLib/src/Base/HlpHashFactory.pas

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,8 @@ TCrypto = class sealed(TObject)
371371
class function CreateHaval_4_256(): IHash; static;
372372
class function CreateHaval_5_256(): IHash; static;
373373

374-
class function CreateGost(ASBoxType: TGostSBox = TGostSBox.gsbTestParamSet)
375-
: IHash; static;
374+
class function CreateGost(
375+
ASBoxType: TGost.TSBoxType = TGost.TSBoxType.TestParamSet): IHash; static;
376376
class function CreateGost_CryptoProParamSet(): IHash; static;
377377

378378
// Streebog 256
@@ -878,14 +878,14 @@ class function THashFactory.THash128.CreateXXHash128: IHashWithKey;
878878

879879
{ THashFactory.TCrypto }
880880

881-
class function THashFactory.TCrypto.CreateGost(ASBoxType: TGostSBox): IHash;
881+
class function THashFactory.TCrypto.CreateGost(ASBoxType: TGost.TSBoxType): IHash;
882882
begin
883883
Result := TGost.Create(ASBoxType);
884884
end;
885885

886886
class function THashFactory.TCrypto.CreateGost_CryptoProParamSet: IHash;
887887
begin
888-
Result := TGost.Create(TGostSBox.gsbCryptoProParamSet);
888+
Result := TGost.Create(TGost.TSBoxType.CryptoProParamSet);
889889
end;
890890

891891
class function THashFactory.TCrypto.CreateGOST3411_2012_256: IHash;
@@ -917,49 +917,49 @@ class function THashFactory.TCrypto.CreateHaval(ARounds: THashRounds;
917917
AHashSize: THashSize): IHash;
918918
begin
919919
case ARounds of
920-
THashRounds.hrRounds3:
920+
THashRounds.Rounds3:
921921
case AHashSize of
922-
THashSize.hsHashSize128:
922+
THashSize.Size128:
923923
Result := CreateHaval_3_128();
924-
THashSize.hsHashSize160:
924+
THashSize.Size160:
925925
Result := CreateHaval_3_160();
926-
THashSize.hsHashSize192:
926+
THashSize.Size192:
927927
Result := CreateHaval_3_192();
928-
THashSize.hsHashSize224:
928+
THashSize.Size224:
929929
Result := CreateHaval_3_224();
930-
THashSize.hsHashSize256:
930+
THashSize.Size256:
931931
Result := CreateHaval_3_256();
932932
else
933933
raise EArgumentHashLibException.CreateRes(@SInvalidHavalHashSize);
934934
end;
935935

936-
THashRounds.hrRounds4:
936+
THashRounds.Rounds4:
937937
case AHashSize of
938-
THashSize.hsHashSize128:
938+
THashSize.Size128:
939939
Result := CreateHaval_4_128();
940-
THashSize.hsHashSize160:
940+
THashSize.Size160:
941941
Result := CreateHaval_4_160();
942-
THashSize.hsHashSize192:
942+
THashSize.Size192:
943943
Result := CreateHaval_4_192();
944-
THashSize.hsHashSize224:
944+
THashSize.Size224:
945945
Result := CreateHaval_4_224();
946-
THashSize.hsHashSize256:
946+
THashSize.Size256:
947947
Result := CreateHaval_4_256();
948948
else
949949
raise EArgumentHashLibException.CreateRes(@SInvalidHavalHashSize);
950950
end;
951951

952-
THashRounds.hrRounds5:
952+
THashRounds.Rounds5:
953953
case AHashSize of
954-
THashSize.hsHashSize128:
954+
THashSize.Size128:
955955
Result := CreateHaval_5_128();
956-
THashSize.hsHashSize160:
956+
THashSize.Size160:
957957
Result := CreateHaval_5_160();
958-
THashSize.hsHashSize192:
958+
THashSize.Size192:
959959
Result := CreateHaval_5_192();
960-
THashSize.hsHashSize224:
960+
THashSize.Size224:
961961
Result := CreateHaval_5_224();
962-
THashSize.hsHashSize256:
962+
THashSize.Size256:
963963
Result := CreateHaval_5_256();
964964
else
965965
raise EArgumentHashLibException.CreateRes(@SInvalidHavalHashSize);
@@ -1201,25 +1201,25 @@ class function THashFactory.TCrypto.CreateBlake2B(const AConfig: IBlake2BConfig;
12011201
class function THashFactory.TCrypto.CreateBlake2B_160: IHash;
12021202
begin
12031203
Result := THashFactory.TCrypto.CreateBlake2B
1204-
(TBlake2BConfig.Create(THashSize.hsHashSize160) as IBlake2BConfig);
1204+
(TBlake2BConfig.Create(THashSize.Size160) as IBlake2BConfig);
12051205
end;
12061206

12071207
class function THashFactory.TCrypto.CreateBlake2B_256: IHash;
12081208
begin
12091209
Result := THashFactory.TCrypto.CreateBlake2B
1210-
(TBlake2BConfig.Create(THashSize.hsHashSize256) as IBlake2BConfig);
1210+
(TBlake2BConfig.Create(THashSize.Size256) as IBlake2BConfig);
12111211
end;
12121212

12131213
class function THashFactory.TCrypto.CreateBlake2B_384: IHash;
12141214
begin
12151215
Result := THashFactory.TCrypto.CreateBlake2B
1216-
(TBlake2BConfig.Create(THashSize.hsHashSize384) as IBlake2BConfig);
1216+
(TBlake2BConfig.Create(THashSize.Size384) as IBlake2BConfig);
12171217
end;
12181218

12191219
class function THashFactory.TCrypto.CreateBlake2B_512: IHash;
12201220
begin
12211221
Result := THashFactory.TCrypto.CreateBlake2B
1222-
(TBlake2BConfig.Create(THashSize.hsHashSize512) as IBlake2BConfig);
1222+
(TBlake2BConfig.Create(THashSize.Size512) as IBlake2BConfig);
12231223
end;
12241224

12251225
class function THashFactory.TCrypto.CreateBlake2S(const AConfig: IBlake2SConfig;
@@ -1238,25 +1238,25 @@ class function THashFactory.TCrypto.CreateBlake2S(const AConfig: IBlake2SConfig;
12381238
class function THashFactory.TCrypto.CreateBlake2S_128: IHash;
12391239
begin
12401240
Result := THashFactory.TCrypto.CreateBlake2S
1241-
(TBlake2SConfig.Create(THashSize.hsHashSize128) as IBlake2SConfig);
1241+
(TBlake2SConfig.Create(THashSize.Size128) as IBlake2SConfig);
12421242
end;
12431243

12441244
class function THashFactory.TCrypto.CreateBlake2S_160: IHash;
12451245
begin
12461246
Result := THashFactory.TCrypto.CreateBlake2S
1247-
(TBlake2SConfig.Create(THashSize.hsHashSize160) as IBlake2SConfig);
1247+
(TBlake2SConfig.Create(THashSize.Size160) as IBlake2SConfig);
12481248
end;
12491249

12501250
class function THashFactory.TCrypto.CreateBlake2S_224: IHash;
12511251
begin
12521252
Result := THashFactory.TCrypto.CreateBlake2S
1253-
(TBlake2SConfig.Create(THashSize.hsHashSize224) as IBlake2SConfig);
1253+
(TBlake2SConfig.Create(THashSize.Size224) as IBlake2SConfig);
12541254
end;
12551255

12561256
class function THashFactory.TCrypto.CreateBlake2S_256: IHash;
12571257
begin
12581258
Result := THashFactory.TCrypto.CreateBlake2S
1259-
(TBlake2SConfig.Create(THashSize.hsHashSize256) as IBlake2SConfig);
1259+
(TBlake2SConfig.Create(THashSize.Size256) as IBlake2SConfig);
12601260
end;
12611261

12621262
class function THashFactory.TCrypto.CreateBlake2BP(AHashSize: Int32;
@@ -1274,7 +1274,7 @@ class function THashFactory.TCrypto.CreateBlake2SP(AHashSize: Int32;
12741274
class function THashFactory.TCrypto.CreateBlake3_256
12751275
(const AKey: THashLibByteArray): IHash;
12761276
begin
1277-
Result := TBlake3.Create(THashSize.hsHashSize256, AKey);
1277+
Result := TBlake3.Create(THashSize.Size256, AKey);
12781278
end;
12791279

12801280
class function THashFactory.TCrypto.CreateSnefru(ASecurityLevel: Int32;
@@ -1284,7 +1284,7 @@ class function THashFactory.TCrypto.CreateSnefru(ASecurityLevel: Int32;
12841284
raise EArgumentHashLibException.CreateRes(@SInvalidSnefruLevel);
12851285

12861286
case AHashSize of
1287-
THashSize.hsHashSize128, THashSize.hsHashSize256:
1287+
THashSize.Size128, THashSize.Size256:
12881288
Result := TSnefru.Create(ASecurityLevel, AHashSize);
12891289
else
12901290
raise EArgumentHashLibException.CreateRes(@SInvalidSnefruHashSize);
@@ -1294,12 +1294,12 @@ class function THashFactory.TCrypto.CreateSnefru(ASecurityLevel: Int32;
12941294

12951295
class function THashFactory.TCrypto.CreateSnefru_8_128: IHash;
12961296
begin
1297-
Result := CreateSnefru(8, THashSize.hsHashSize128);
1297+
Result := CreateSnefru(8, THashSize.Size128);
12981298
end;
12991299

13001300
class function THashFactory.TCrypto.CreateSnefru_8_256: IHash;
13011301
begin
1302-
Result := CreateSnefru(8, THashSize.hsHashSize256);
1302+
Result := CreateSnefru(8, THashSize.Size256);
13031303
end;
13041304

13051305
class function THashFactory.TCrypto.CreateTiger_3_128: IHash;

HashLib/src/Base/HlpHashRounds.pas

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
interface
66

77
type
8-
{$SCOPEDENUMS ON}
9-
THashRounds = (hrRounds3 = 3, hrRounds4 = 4, hrRounds5 = 5, hrRounds8 = 8);
10-
{$SCOPEDENUMS OFF}
8+
THashRounds = (Rounds3 = 3, Rounds4 = 4, Rounds5 = 5, Rounds8 = 8);
119

1210
implementation
1311

HashLib/src/Base/HlpHashSize.pas

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@
55
interface
66

77
type
8-
{$SCOPEDENUMS ON}
9-
THashSize = (hsHashSize128 = 16, hsHashSize160 = 20, hsHashSize192 = 24,
10-
hsHashSize224 = 28, hsHashSize256 = 32, hsHashSize288 = 36,
11-
hsHashSize384 = 48, hsHashSize512 = 64);
12-
{$SCOPEDENUMS OFF}
8+
THashSize = (Size128 = 16, Size160 = 20, Size192 = 24, Size224 = 28,
9+
Size256 = 32, Size288 = 36, Size384 = 48, Size512 = 64);
1310

1411
implementation
1512

HashLib/src/Crypto/Blake2BParams/HlpBlake2BParams.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ TBlake2BConfig = class sealed(TInterfacedObject, IBlake2BConfig)
6464
procedure SetHashSize(AValue: Int32); inline;
6565

6666
public
67-
constructor Create(AHashSize: THashSize = THashSize.hsHashSize512);
67+
constructor Create(AHashSize: THashSize = THashSize.Size512);
6868
overload;
6969
constructor Create(AHashSize: Int32); overload;
7070
destructor Destroy; override;

HashLib/src/Crypto/Blake2SParams/HlpBlake2SParams.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ TBlake2SConfig = class sealed(TInterfacedObject, IBlake2SConfig)
6464
procedure SetHashSize(AValue: Int32); inline;
6565

6666
public
67-
constructor Create(AHashSize: THashSize = THashSize.hsHashSize256);
67+
constructor Create(AHashSize: THashSize = THashSize.Size256);
6868
overload;
6969
constructor Create(AHashSize: Int32); overload;
7070
destructor Destroy; override;

HashLib/src/Crypto/HlpBlake3.pas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ TBlake3OutputReader = record
177177
AKeyWords: PCardinal; AFlags: UInt32);
178178

179179
public
180-
constructor Create(AHashSize: THashSize = THashSize.hsHashSize256;
180+
constructor Create(AHashSize: THashSize = THashSize.Size256;
181181
const AKey: THashLibByteArray = nil); overload;
182182
procedure Initialize; override;
183183
procedure TransformBytes(const AData: THashLibByteArray;

HashLib/src/Crypto/HlpGost.pas

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ interface
1515

1616
type
1717

18-
{$SCOPEDENUMS ON}
19-
TGostSBox = (gsbTestParamSet, gsbCryptoProParamSet);
20-
{$SCOPEDENUMS OFF}
21-
2218
TGost = class sealed(TBlockHash, ICryptoNotBuildIn, ITransformBlock)
2319

20+
type
21+
TSBoxType = (TestParamSet, CryptoProParamSet);
2422
strict private
2523

2624
class var
@@ -32,7 +30,7 @@ TGost = class sealed(TBlockHash, ICryptoNotBuildIn, ITransformBlock)
3230
var
3331
FState, FHash: THashLibUInt32Array;
3432
FSBox1, FSBox2, FSBox3, FSBox4: THashLibUInt32Array;
35-
FSBoxType: TGostSBox;
33+
FSBoxType: TSBoxType;
3634

3735
procedure Compress(APtr: PCardinal);
3836
class procedure ComputeSBoxes(const ASBox: THashLibMatrixUInt32Array;
@@ -46,7 +44,7 @@ TGost = class sealed(TBlockHash, ICryptoNotBuildIn, ITransformBlock)
4644
AIndex: Int32); override;
4745

4846
public
49-
constructor Create(ASBoxType: TGostSBox = TGostSBox.gsbTestParamSet);
47+
constructor Create(ASBoxType: TSBoxType = TSBoxType.TestParamSet);
5048
procedure Initialize(); override;
5149
function Clone(): IHash; override;
5250

@@ -378,21 +376,21 @@ class procedure TGost.ComputeSBoxes(const ASBox: THashLibMatrixUInt32Array;
378376
end;
379377
end;
380378

381-
constructor TGost.Create(ASBoxType: TGostSBox);
379+
constructor TGost.Create(ASBoxType: TGost.TSBoxType);
382380
begin
383381
inherited Create(32, 32);
384382
System.SetLength(FState, 8);
385383
System.SetLength(FHash, 8);
386384
FSBoxType := ASBoxType;
387385
case ASBoxType of
388-
TGostSBox.gsbTestParamSet:
386+
TGost.TSBoxType.TestParamSet:
389387
begin
390388
FSBox1 := FSBox1_Test;
391389
FSBox2 := FSBox2_Test;
392390
FSBox3 := FSBox3_Test;
393391
FSBox4 := FSBox4_Test;
394392
end;
395-
TGostSBox.gsbCryptoProParamSet:
393+
TGost.TSBoxType.CryptoProParamSet:
396394
begin
397395
FSBox1 := FSBox1_CryptoPro;
398396
FSBox2 := FSBox2_CryptoPro;

0 commit comments

Comments
 (0)