Browse Source

some refactorings.

Ugochukwu Mmaduekwe 7 years ago
parent
commit
c08e63a4fb

+ 1 - 1
CryptoLib.Samples/Delphi.Samples/UsageSamples.dpr

@@ -7,8 +7,8 @@ program UsageSamples;
 
 uses
   SysUtils,
-  ClpCryptoProObjectIdentifiers in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpCryptoProObjectIdentifiers.pas',
   ClpECGost3410NamedCurves in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpECGost3410NamedCurves.pas',
+  ClpCryptoProObjectIdentifiers in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpCryptoProObjectIdentifiers.pas',
   ClpNistObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Nist\ClpNistObjectIdentifiers.pas',
   ClpOiwObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Oiw\ClpOiwObjectIdentifiers.pas',
   ClpPkcsObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Pkcs\ClpPkcsObjectIdentifiers.pas',

+ 1 - 1
CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr

@@ -20,8 +20,8 @@ uses
   TestFramework,
   GUITestRunner,
   TextTestRunner,
-  ClpCryptoProObjectIdentifiers in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpCryptoProObjectIdentifiers.pas',
   ClpECGost3410NamedCurves in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpECGost3410NamedCurves.pas',
+  ClpCryptoProObjectIdentifiers in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpCryptoProObjectIdentifiers.pas',
   ClpNistObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Nist\ClpNistObjectIdentifiers.pas',
   ClpOiwObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Oiw\ClpOiwObjectIdentifiers.pas',
   ClpPkcsObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Pkcs\ClpPkcsObjectIdentifiers.pas',

+ 57 - 56
CryptoLib/src/Asn1/CryptoPro/ClpCryptoProObjectIdentifiers.pas

@@ -26,9 +26,15 @@ uses
   ClpIDerObjectIdentifier;
 
 type
-  TCryptoProObjectIdentifiers = class abstract(TObject)
+  TCryptoProObjectIdentifiers = class sealed(TObject)
 
   strict private
+
+  const
+    // GOST Algorithms OBJECT IDENTIFIERS :
+    // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2)}
+    GostID: String = '1.2.643.2.2';
+
     class var
 
       FGostR3411, FGostR3410x2001, FGostR3410x94, FGostR28147Cbc,
@@ -42,8 +48,6 @@ type
       FGostR3410x2001CryptoProXchA, FGostR3410x2001CryptoProB,
       FGostR3410x2001CryptoProC, FGostElSgDH3410x1: IDerObjectIdentifier;
 
-    class constructor CryptoProObjectIdentifiers();
-
     class function GetGostR3411: IDerObjectIdentifier; static; inline;
 
     class function GetGostR28147Cbc: IDerObjectIdentifier; static; inline;
@@ -89,12 +93,9 @@ type
     class function GetGostR3411x94CryptoProParamSet: IDerObjectIdentifier;
       static; inline;
 
-  public
+    class constructor CryptoProObjectIdentifiers();
 
-    const
-    // GOST Algorithms OBJECT IDENTIFIERS :
-    // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2)}
-    GostID: String = '1.2.643.2.2';
+  public
 
     class property GostR3411: IDerObjectIdentifier read GetGostR3411;
     class property GostR3411Hmac: IDerObjectIdentifier read GetGostR3411Hmac;
@@ -157,54 +158,6 @@ implementation
 
 { TCryptoProObjectIdentifiers }
 
-class procedure TCryptoProObjectIdentifiers.Boot;
-begin
-  FGostR3411 := TDerObjectIdentifier.Create(GostID + '.9');
-  FGostR3411Hmac := TDerObjectIdentifier.Create(GostID + '.10');
-
-  FGostR28147Cbc := TDerObjectIdentifier.Create(GostID + '.21');
-
-  FID_Gost28147_89_CryptoPro_A_ParamSet := TDerObjectIdentifier.Create
-    (GostID + '.31.1');
-
-  FGostR3410x94 := TDerObjectIdentifier.Create(GostID + '.20');
-  FGostR3410x2001 := TDerObjectIdentifier.Create(GostID + '.19');
-  FGostR3411x94WithGostR3410x94 := TDerObjectIdentifier.Create(GostID + '.4');
-  FGostR3411x94WithGostR3410x2001 := TDerObjectIdentifier.Create(GostID + '.3');
-
-  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) hashes(30) }
-  FGostR3411x94CryptoProParamSet := TDerObjectIdentifier.Create
-    (GostID + '.30.1');
-
-  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) signs(32) }
-  FGostR3410x94CryptoProA := TDerObjectIdentifier.Create(GostID + '.32.2');
-  FGostR3410x94CryptoProB := TDerObjectIdentifier.Create(GostID + '.32.3');
-  FGostR3410x94CryptoProC := TDerObjectIdentifier.Create(GostID + '.32.4');
-  FGostR3410x94CryptoProD := TDerObjectIdentifier.Create(GostID + '.32.5');
-
-  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) exchanges(33) }
-  FGostR3410x94CryptoProXchA := TDerObjectIdentifier.Create(GostID + '.33.1');
-  FGostR3410x94CryptoProXchB := TDerObjectIdentifier.Create(GostID + '.33.2');
-  FGostR3410x94CryptoProXchC := TDerObjectIdentifier.Create(GostID + '.33.3');
-
-  // { iso(1) member-body(2)ru(643) rans(2) cryptopro(2) ecc-signs(35) }
-  FGostR3410x2001CryptoProA := TDerObjectIdentifier.Create(GostID + '.35.1');
-  FGostR3410x2001CryptoProB := TDerObjectIdentifier.Create(GostID + '.35.2');
-  FGostR3410x2001CryptoProC := TDerObjectIdentifier.Create(GostID + '.35.3');
-
-  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) ecc-exchanges(36) }
-  FGostR3410x2001CryptoProXchA := TDerObjectIdentifier.Create(GostID + '.36.0');
-  FGostR3410x2001CryptoProXchB := TDerObjectIdentifier.Create(GostID + '.36.1');
-
-  FGostElSgDH3410Default := TDerObjectIdentifier.Create(GostID + '.36.0');
-  FGostElSgDH3410x1 := TDerObjectIdentifier.Create(GostID + '.36.1');
-end;
-
-class constructor TCryptoProObjectIdentifiers.CryptoProObjectIdentifiers;
-begin
-  TCryptoProObjectIdentifiers.Boot;
-end;
-
 class function TCryptoProObjectIdentifiers.GetGostR3411: IDerObjectIdentifier;
 begin
   result := FGostR3411;
@@ -348,4 +301,52 @@ begin
   result := FID_Gost28147_89_CryptoPro_A_ParamSet;
 end;
 
+class procedure TCryptoProObjectIdentifiers.Boot;
+begin
+  FGostR3411 := TDerObjectIdentifier.Create(GostID + '.9');
+  FGostR3411Hmac := TDerObjectIdentifier.Create(GostID + '.10');
+
+  FGostR28147Cbc := TDerObjectIdentifier.Create(GostID + '.21');
+
+  FID_Gost28147_89_CryptoPro_A_ParamSet := TDerObjectIdentifier.Create
+    (GostID + '.31.1');
+
+  FGostR3410x94 := TDerObjectIdentifier.Create(GostID + '.20');
+  FGostR3410x2001 := TDerObjectIdentifier.Create(GostID + '.19');
+  FGostR3411x94WithGostR3410x94 := TDerObjectIdentifier.Create(GostID + '.4');
+  FGostR3411x94WithGostR3410x2001 := TDerObjectIdentifier.Create(GostID + '.3');
+
+  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) hashes(30) }
+  FGostR3411x94CryptoProParamSet := TDerObjectIdentifier.Create
+    (GostID + '.30.1');
+
+  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) signs(32) }
+  FGostR3410x94CryptoProA := TDerObjectIdentifier.Create(GostID + '.32.2');
+  FGostR3410x94CryptoProB := TDerObjectIdentifier.Create(GostID + '.32.3');
+  FGostR3410x94CryptoProC := TDerObjectIdentifier.Create(GostID + '.32.4');
+  FGostR3410x94CryptoProD := TDerObjectIdentifier.Create(GostID + '.32.5');
+
+  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) exchanges(33) }
+  FGostR3410x94CryptoProXchA := TDerObjectIdentifier.Create(GostID + '.33.1');
+  FGostR3410x94CryptoProXchB := TDerObjectIdentifier.Create(GostID + '.33.2');
+  FGostR3410x94CryptoProXchC := TDerObjectIdentifier.Create(GostID + '.33.3');
+
+  // { iso(1) member-body(2)ru(643) rans(2) cryptopro(2) ecc-signs(35) }
+  FGostR3410x2001CryptoProA := TDerObjectIdentifier.Create(GostID + '.35.1');
+  FGostR3410x2001CryptoProB := TDerObjectIdentifier.Create(GostID + '.35.2');
+  FGostR3410x2001CryptoProC := TDerObjectIdentifier.Create(GostID + '.35.3');
+
+  // { iso(1) member-body(2) ru(643) rans(2) cryptopro(2) ecc-exchanges(36) }
+  FGostR3410x2001CryptoProXchA := TDerObjectIdentifier.Create(GostID + '.36.0');
+  FGostR3410x2001CryptoProXchB := TDerObjectIdentifier.Create(GostID + '.36.1');
+
+  FGostElSgDH3410Default := TDerObjectIdentifier.Create(GostID + '.36.0');
+  FGostElSgDH3410x1 := TDerObjectIdentifier.Create(GostID + '.36.1');
+end;
+
+class constructor TCryptoProObjectIdentifiers.CryptoProObjectIdentifiers;
+begin
+  TCryptoProObjectIdentifiers.Boot;
+end;
+
 end.

+ 1 - 1
CryptoLib/src/Asn1/CryptoPro/ClpECGost3410NamedCurves.pas

@@ -96,7 +96,7 @@ var
   curve: IFPCurve;
   ecParams: IECDomainParameters;
 begin
-  TBigInteger.Boot;
+ // TBigInteger.Boot;
   Fparameters := TDictionary<IDerObjectIdentifier,
     IECDomainParameters>.Create();
   FobjIds := TDictionary<String, IDerObjectIdentifier>.Create();

+ 1 - 1
CryptoLib/src/Asn1/Sec/ClpSecNamedCurves.pas

@@ -823,7 +823,7 @@ begin
   Fnames := TDictionary<IDerObjectIdentifier, String>.Create();
   Fcurves := TDictionary<IDerObjectIdentifier, IX9ECParametersHolder>.Create();
 
-  TSecObjectIdentifiers.Boot;
+ // TSecObjectIdentifiers.Boot;
 
   DefineCurve('secp112r1', TSecObjectIdentifiers.SecP112r1,
     TSecp112r1Holder.Instance);

+ 1 - 1
CryptoLib/src/Asn1/Sec/ClpSecObjectIdentifiers.pas

@@ -336,7 +336,7 @@ begin
   FSecT571k1 := TDerObjectIdentifier.Create(EllipticCurve.Id + '.38');
   FSecT571r1 := TDerObjectIdentifier.Create(EllipticCurve.Id + '.39');
 
-  TX9ObjectIdentifiers.Boot;
+ // TX9ObjectIdentifiers.Boot;
 
   FSecP192r1 := TX9ObjectIdentifiers.Prime192v1;
 

+ 1 - 1
CryptoLib/src/Crypto/Signers/ClpECDsaSigner.pas

@@ -166,7 +166,7 @@ end;
 
 class constructor TECDsaSigner.ECDsaSigner;
 begin
-  TBigInteger.Boot;
+ // TBigInteger.Boot;
   FEight := TBigInteger.ValueOf(8);
 end;
 

+ 1 - 1
CryptoLib/src/Math/ClpBigInteger.pas

@@ -871,7 +871,7 @@ begin
     TCryptoLibInt32Array.Create(1249, 1259, 1277),
     TCryptoLibInt32Array.Create(1279, 1283, 1289));
 
-  TSecureRandom.Boot;
+  //TSecureRandom.Boot;
 
   FRandomSource := TSecureRandom.Create();
 

+ 1 - 1
CryptoLib/src/Math/EC/Abc/ClpTnaf.pas

@@ -1114,7 +1114,7 @@ end;
 
 class constructor TTnaf.Tnaf;
 begin
-  TBigInteger.Boot;
+ // TBigInteger.Boot;
   FMinusOne := TBigInteger.One.Negate();
   FMinusTwo := TBigInteger.Two.Negate();
   FMinusThree := TBigInteger.Three.Negate();

+ 1 - 1
CryptoLib/src/Math/Field/ClpFiniteFields.pas

@@ -62,7 +62,7 @@ implementation
 
 class constructor TFiniteFields.FiniteFields;
 begin
-  TBigInteger.Boot;
+ // TBigInteger.Boot;
   FGF_2 := TPrimeField.Create(TBigInteger.ValueOf(2));
   FGF_3 := TPrimeField.Create(TBigInteger.ValueOf(3));
 end;

+ 1 - 1
CryptoLib/src/Math/Raw/ClpMod.pas

@@ -231,7 +231,7 @@ end;
 
 class constructor TMod.&Mod;
 begin
-  TSecureRandom.Boot;
+ // TSecureRandom.Boot;
   FRandomSource := TSecureRandom.Create();
 end;
 

+ 1 - 1
CryptoLib/src/Security/ClpCipherUtilities.pas

@@ -123,7 +123,7 @@ begin
   Falgorithms := TDictionary<string, string>.Create();
   Foids := TDictionary<string, IDerObjectIdentifier>.Create();
 
-  TNistObjectIdentifiers.Boot;
+ // TNistObjectIdentifiers.Boot;
 
   // TODO Flesh out the list of aliases
 

+ 7 - 7
CryptoLib/src/Security/ClpDigestUtilities.pas

@@ -371,18 +371,18 @@ begin
 
   Falgorithms.Add('NULL', 'NULL'); // Null Digest
 
-  TPkcsObjectIdentifiers.Boot;
+ // TPkcsObjectIdentifiers.Boot;
 
   Falgorithms.Add(TPkcsObjectIdentifiers.MD2.id, 'MD2');
   Falgorithms.Add(TPkcsObjectIdentifiers.MD4.id, 'MD4');
   Falgorithms.Add(TPkcsObjectIdentifiers.MD5.id, 'MD5');
 
-  TOiwObjectIdentifiers.Boot;
+ // TOiwObjectIdentifiers.Boot;
 
   Falgorithms.Add('SHA1', 'SHA-1');
   Falgorithms.Add(TOiwObjectIdentifiers.IdSha1.id, 'SHA-1');
 
-  TNistObjectIdentifiers.Boot;
+ // TNistObjectIdentifiers.Boot;
 
   Falgorithms.Add('SHA224', 'SHA-224');
   Falgorithms.Add(TNistObjectIdentifiers.IdSha224.id, 'SHA-224');
@@ -397,7 +397,7 @@ begin
   Falgorithms.Add('SHA512/256', 'SHA-512/256');
   Falgorithms.Add(TNistObjectIdentifiers.IdSha512_256.id, 'SHA-512/256');
 
-  TTeleTrusTObjectIdentifiers.Boot;
+ // TTeleTrusTObjectIdentifiers.Boot;
 
   Falgorithms.Add('RIPEMD-128', 'RIPEMD128');
   Falgorithms.Add(TTeleTrusTObjectIdentifiers.RIPEMD128.id, 'RIPEMD128');
@@ -408,7 +408,7 @@ begin
   Falgorithms.Add('RIPEMD-320', 'RIPEMD320');
   // Falgorithms.Add(TTeleTrusTObjectIdentifiers.RipeMD320.Id,'RIPEMD320');
 
-  TCryptoProObjectIdentifiers.Boot;
+ // TCryptoProObjectIdentifiers.Boot;
 
   Falgorithms.Add(TCryptoProObjectIdentifiers.GostR3411.id, 'GOST3411');
 
@@ -417,7 +417,7 @@ begin
   Falgorithms.Add(TNistObjectIdentifiers.IdSha3_384.id, 'SHA3-384');
   Falgorithms.Add(TNistObjectIdentifiers.IdSha3_512.id, 'SHA3-512');
 
-  TMiscObjectIdentifiers.Boot;
+ // TMiscObjectIdentifiers.Boot;
 
   Falgorithms.Add(TMiscObjectIdentifiers.id_blake2b160.id, 'BLAKE2B-160');
   Falgorithms.Add(TMiscObjectIdentifiers.id_blake2b256.id, 'BLAKE2B-256');
@@ -428,7 +428,7 @@ begin
   Falgorithms.Add(TMiscObjectIdentifiers.id_blake2s224.id, 'BLAKE2S-224');
   Falgorithms.Add(TMiscObjectIdentifiers.id_blake2s256.id, 'BLAKE2S-256');
 
-  TRosstandartObjectIdentifiers.Boot;
+ // TRosstandartObjectIdentifiers.Boot;
 
   Falgorithms.Add(TRosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_256.
     id, 'HMAC-GOST3411-2012-256');

+ 4 - 4
CryptoLib/src/Security/ClpGeneratorUtilities.pas

@@ -170,7 +170,7 @@ begin
   FkpgAlgorithms := TDictionary<String, String>.Create();
   FdefaultKeySizes := TDictionary<String, Int32>.Create();
 
-  TNistObjectIdentifiers.Boot;
+ // TNistObjectIdentifiers.Boot;
 
   //
   // key generators.
@@ -197,13 +197,13 @@ begin
   //
   // HMac key generators
   //
-  TIanaObjectIdentifiers.Boot;
+ // TIanaObjectIdentifiers.Boot;
 
   AddHMacKeyGenerator('MD2', []);
   AddHMacKeyGenerator('MD4', []);
   AddHMacKeyGenerator('MD5', [TIanaObjectIdentifiers.HmacMD5.ID]);
 
-  TPkcsObjectIdentifiers.Boot;
+ // TPkcsObjectIdentifiers.Boot;
 
   AddHMacKeyGenerator('SHA1', [TPkcsObjectIdentifiers.IdHmacWithSha1.ID,
     TIanaObjectIdentifiers.HmacSha1.ID]);
@@ -226,7 +226,7 @@ begin
   AddHMacKeyGenerator('RIPEMD160', [TIanaObjectIdentifiers.HmacRipeMD160.ID]);
   AddHMacKeyGenerator('TIGER', [TIanaObjectIdentifiers.HmacTiger.ID]);
 
-  TRosstandartObjectIdentifiers.Boot;
+ // TRosstandartObjectIdentifiers.Boot;
 
   AddHMacKeyGenerator('GOST3411-2012-256',
     [TRosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_256.ID]);

+ 4 - 4
CryptoLib/src/Security/ClpMacUtilities.pas

@@ -82,14 +82,14 @@ class procedure TMacUtilities.Boot;
 begin
   Falgorithms := TDictionary<string, string>.Create();
 
-  TIanaObjectIdentifiers.Boot;
+ // TIanaObjectIdentifiers.Boot;
 
   Falgorithms.Add(TIanaObjectIdentifiers.HmacMD5.id, 'HMAC-MD5');
   Falgorithms.Add(TIanaObjectIdentifiers.HmacRipeMD160.id, 'HMAC-RIPEMD160');
   Falgorithms.Add(TIanaObjectIdentifiers.HmacSha1.id, 'HMAC-SHA1');
   Falgorithms.Add(TIanaObjectIdentifiers.HmacTiger.id, 'HMAC-TIGER');
 
-  TPkcsObjectIdentifiers.Boot;
+ // TPkcsObjectIdentifiers.Boot;
 
   Falgorithms.Add(TPkcsObjectIdentifiers.IdHmacWithSha1.id, 'HMAC-SHA1');
   Falgorithms.Add(TPkcsObjectIdentifiers.IdHmacWithSha224.id, 'HMAC-SHA224');
@@ -97,7 +97,7 @@ begin
   Falgorithms.Add(TPkcsObjectIdentifiers.IdHmacWithSha384.id, 'HMAC-SHA384');
   Falgorithms.Add(TPkcsObjectIdentifiers.IdHmacWithSha512.id, 'HMAC-SHA512');
 
-  TNistObjectIdentifiers.Boot;
+ // TNistObjectIdentifiers.Boot;
 
   Falgorithms.Add(TNistObjectIdentifiers.IdHMacWithSha3_224.id,
     'HMAC-SHA3-224');
@@ -108,7 +108,7 @@ begin
   Falgorithms.Add(TNistObjectIdentifiers.IdHMacWithSha3_512.id,
     'HMAC-SHA3-512');
 
-  TRosstandartObjectIdentifiers.Boot;
+//  TRosstandartObjectIdentifiers.Boot;
 
   Falgorithms.Add(TRosstandartObjectIdentifiers.id_tc26_hmac_gost_3411_12_256.
     id, 'HMAC-GOST3411-2012-256');

+ 1 - 1
CryptoLib/src/Security/ClpParameterUtilities.pas

@@ -107,7 +107,7 @@ begin
   Falgorithms := TDictionary<String, String>.Create();
   FbasicIVSizes := TDictionary<string, Integer>.Create();
 
-  TNistObjectIdentifiers.Boot;
+ // TNistObjectIdentifiers.Boot;
 
   AddAlgorithm('AES', []);
   AddAlgorithm('AES128', ['2.16.840.1.101.3.4.2',

+ 10 - 10
CryptoLib/src/Security/ClpSignerUtilities.pas

@@ -108,11 +108,11 @@ begin
   Falgorithms := TDictionary<String, String>.Create();
   Foids := TDictionary<String, IDerObjectIdentifier>.Create();
 
-  TX9ObjectIdentifiers.Boot;
-  TOiwObjectIdentifiers.Boot;
-  TNistObjectIdentifiers.Boot;
-  TTeleTrusTObjectIdentifiers.Boot;
-  TCryptoProObjectIdentifiers.Boot;
+ // TX9ObjectIdentifiers.Boot;
+ // TOiwObjectIdentifiers.Boot;
+ // TNistObjectIdentifiers.Boot;
+ // TTeleTrusTObjectIdentifiers.Boot;
+ // TCryptoProObjectIdentifiers.Boot;
 
   Falgorithms.Add('NONEWITHDSA', 'NONEwithDSA');
   Falgorithms.Add('DSAWITHNONE', 'NONEwithDSA');
@@ -213,11 +213,11 @@ begin
   Falgorithms.Add(TTeleTrusTObjectIdentifiers.ECSignWithRipeMD160.id,
     'RIPEMD160withECDSA');
 
-  // Falgorithms.Add('GOST-3410', 'GOST3410');
-  // Falgorithms.Add('GOST-3410-94', 'GOST3410');
-  // Falgorithms.Add('GOST3411WITHGOST3410', 'GOST3410');
-  // Falgorithms.Add(TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94.id,
-  // 'GOST3410');
+//   Falgorithms.Add('GOST-3410', 'GOST3410');
+//   Falgorithms.Add('GOST-3410-94', 'GOST3410');
+//   Falgorithms.Add('GOST3411WITHGOST3410', 'GOST3410');
+//   Falgorithms.Add(TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94.id,
+//   'GOST3410');
 
   // Falgorithms.Add('ECGOST-3410', 'ECGOST3410');
   // Falgorithms.Add('ECGOST-3410-2001', 'ECGOST3410');