Browse Source

refactor UnitTests

Ugochukwu Mmaduekwe 6 years ago
parent
commit
d74f16c16a
69 changed files with 1198 additions and 1516 deletions
  1. 2 1
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.TestInsight.dpr
  2. 2 1
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr
  3. 7 3
      CryptoLib.Tests/FreePascal.Tests/CryptoLib.Tests.lpi
  4. 1 0
      CryptoLib.Tests/FreePascal.Tests/CryptoLib.lpr
  5. 6 2
      CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.Tests.lpi
  6. 1 0
      CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpr
  7. 40 52
      CryptoLib.Tests/src/Asn1/Asn1SequenceParserTests.pas
  8. 15 28
      CryptoLib.Tests/src/Asn1/DerApplicationSpecificTests.pas
  9. 5 11
      CryptoLib.Tests/src/Asn1/EnumeratedTests.pas
  10. 9 14
      CryptoLib.Tests/src/Asn1/EqualsAndHashCodeTests.pas
  11. 53 60
      CryptoLib.Tests/src/Asn1/OIDTests.pas
  12. 4 10
      CryptoLib.Tests/src/Asn1/ParseTests.pas
  13. 5 11
      CryptoLib.Tests/src/Asn1/ParsingTests.pas
  14. 3 8
      CryptoLib.Tests/src/Asn1/StringTests.pas
  15. 5 12
      CryptoLib.Tests/src/Asn1/TagTests.pas
  16. 36 44
      CryptoLib.Tests/src/Crypto/AESSICTests.pas
  17. 32 39
      CryptoLib.Tests/src/Crypto/AESTests.pas
  18. 3 8
      CryptoLib.Tests/src/Crypto/Argon2Tests.pas
  19. 13 23
      CryptoLib.Tests/src/Crypto/BlockCipherMonteCarloTests.pas
  20. 27 36
      CryptoLib.Tests/src/Crypto/BlockCipherVectorTests.pas
  21. 18 26
      CryptoLib.Tests/src/Crypto/CTSTests.pas
  22. 31 40
      CryptoLib.Tests/src/Crypto/ChaChaTests.pas
  23. 3 8
      CryptoLib.Tests/src/Crypto/DHTests.pas
  24. 95 94
      CryptoLib.Tests/src/Crypto/DSATests.pas
  25. 10 16
      CryptoLib.Tests/src/Crypto/DeterministicDsaTests.pas
  26. 22 28
      CryptoLib.Tests/src/Crypto/DigestRandomNumberTests.pas
  27. 56 57
      CryptoLib.Tests/src/Crypto/HMacTests.pas
  28. 30 39
      CryptoLib.Tests/src/Crypto/HkdfGeneratorTests.pas
  29. 15 22
      CryptoLib.Tests/src/Crypto/Kdf1GeneratorTests.pas
  30. 22 28
      CryptoLib.Tests/src/Crypto/Kdf2GeneratorTests.pas
  31. 9 16
      CryptoLib.Tests/src/Crypto/MD5HMacTests.pas
  32. 17 25
      CryptoLib.Tests/src/Crypto/PaddingTests.pas
  33. 37 45
      CryptoLib.Tests/src/Crypto/Pkcs5Tests.pas
  34. 9 16
      CryptoLib.Tests/src/Crypto/RIPEMD128HMacTests.pas
  35. 9 16
      CryptoLib.Tests/src/Crypto/RIPEMD160HMacTests.pas
  36. 9 16
      CryptoLib.Tests/src/Crypto/SHA1HMacTests.pas
  37. 9 16
      CryptoLib.Tests/src/Crypto/SHA224HMacTests.pas
  38. 9 16
      CryptoLib.Tests/src/Crypto/SHA256HMacTests.pas
  39. 9 16
      CryptoLib.Tests/src/Crypto/SHA384HMacTests.pas
  40. 9 16
      CryptoLib.Tests/src/Crypto/SHA512HMacTests.pas
  41. 26 39
      CryptoLib.Tests/src/Crypto/SPECKTests.pas
  42. 31 40
      CryptoLib.Tests/src/Crypto/Salsa20Tests.pas
  43. 2 8
      CryptoLib.Tests/src/Crypto/ScryptTests.pas
  44. 11 13
      CryptoLib.Tests/src/Crypto/StreamCipherResetTests.pas
  45. 10 17
      CryptoLib.Tests/src/Crypto/XSalsa20Tests.pas
  46. 76 0
      CryptoLib.Tests/src/CryptoLibTestBase.pas
  47. 11 19
      CryptoLib.Tests/src/Math/BigIntegerTests.pas
  48. 6 10
      CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP256R1FieldTests.pas
  49. 6 10
      CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP384R1FieldTests.pas
  50. 3 8
      CryptoLib.Tests/src/Math/EC/FixedPointTests.pas
  51. 19 28
      CryptoLib.Tests/src/Math/EC/Rfc7748/X25519Tests.pas
  52. 36 44
      CryptoLib.Tests/src/Math/EC/Rfc8032/Ed25519Tests.pas
  53. 3 8
      CryptoLib.Tests/src/Math/ECAlgorithmsTests.pas
  54. 41 47
      CryptoLib.Tests/src/Math/ECIESTests.pas
  55. 30 31
      CryptoLib.Tests/src/Math/ECNRTests.pas
  56. 6 14
      CryptoLib.Tests/src/Math/ECPointTests.pas
  57. 5 12
      CryptoLib.Tests/src/Math/IESCipherTests.pas
  58. 6 13
      CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas
  59. 13 20
      CryptoLib.Tests/src/Others/DigestTests.pas
  60. 28 32
      CryptoLib.Tests/src/Others/ECDsa5Tests.pas
  61. 11 18
      CryptoLib.Tests/src/Others/ECSchnorrTests.pas
  62. 42 39
      CryptoLib.Tests/src/Others/ECTests.pas
  63. 30 39
      CryptoLib.Tests/src/Others/Ed25519HigherLevelTests.pas
  64. 3 9
      CryptoLib.Tests/src/Others/NamedCurveTests.pas
  65. 6 12
      CryptoLib.Tests/src/Others/ShortenedDigestTests.pas
  66. 17 25
      CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas
  67. 6 12
      CryptoLib.Tests/src/Others/X25519HigherLevelTests.pas
  68. 12 20
      CryptoLib.Tests/src/Security/DigestUtilitiesTests.pas
  69. 5 10
      CryptoLib.Tests/src/Security/SecureRandomTests.pas

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

@@ -453,7 +453,8 @@ uses
   DigestUtilitiesTests in '..\src\Security\DigestUtilitiesTests.pas',
   DigestUtilitiesTests in '..\src\Security\DigestUtilitiesTests.pas',
   DigestTests in '..\src\Others\DigestTests.pas',
   DigestTests in '..\src\Others\DigestTests.pas',
   ScryptTests in '..\src\Crypto\ScryptTests.pas',
   ScryptTests in '..\src\Crypto\ScryptTests.pas',
-  DHTests in '..\src\Crypto\DHTests.pas';
+  DHTests in '..\src\Crypto\DHTests.pas',
+  CryptoLibTestBase in '..\src\CryptoLibTestBase.pas';
 
 
 begin
 begin
 
 

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

@@ -456,7 +456,8 @@ uses
   DigestUtilitiesTests in '..\src\Security\DigestUtilitiesTests.pas',
   DigestUtilitiesTests in '..\src\Security\DigestUtilitiesTests.pas',
   DigestTests in '..\src\Others\DigestTests.pas',
   DigestTests in '..\src\Others\DigestTests.pas',
   ScryptTests in '..\src\Crypto\ScryptTests.pas',
   ScryptTests in '..\src\Crypto\ScryptTests.pas',
-  DHTests in '..\src\Crypto\DHTests.pas';
+  DHTests in '..\src\Crypto\DHTests.pas',
+  CryptoLibTestBase in '..\src\CryptoLibTestBase.pas';
 
 
 begin
 begin
 
 

+ 7 - 3
CryptoLib.Tests/FreePascal.Tests/CryptoLib.Tests.lpi

@@ -21,7 +21,7 @@
           </Target>
           </Target>
           <SearchPaths>
           <SearchPaths>
             <IncludeFiles Value="$(ProjOutDir)"/>
             <IncludeFiles Value="$(ProjOutDir)"/>
-            <OtherUnitFiles Value="..\src\Asn1;..\src\Math;..\src\Math\EC\Custom\Sec;..\src\Others;..\src\Security;..\src\Utils;..\src\Crypto;..\src\Math\EC;..\src\Math\EC\Rfc7748;..\src\Math\EC\Rfc8032"/>
+            <OtherUnitFiles Value="..\src\Asn1;..\src\Math;..\src\Math\EC\Custom\Sec;..\src\Others;..\src\Security;..\src\Utils;..\src\Crypto;..\src\Math\EC;..\src\Math\EC\Rfc7748;..\src\Math\EC\Rfc8032;..\src"/>
             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
             <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
           </SearchPaths>
           </SearchPaths>
           <Parsing>
           <Parsing>
@@ -77,7 +77,7 @@
         <PackageName Value="FCL"/>
         <PackageName Value="FCL"/>
       </Item4>
       </Item4>
     </RequiredPackages>
     </RequiredPackages>
-    <Units Count="71">
+    <Units Count="72">
       <Unit0>
       <Unit0>
         <Filename Value="CryptoLib.lpr"/>
         <Filename Value="CryptoLib.lpr"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
@@ -363,6 +363,10 @@
         <Filename Value="..\src\Crypto\DHTests.pas"/>
         <Filename Value="..\src\Crypto\DHTests.pas"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
       </Unit70>
       </Unit70>
+      <Unit71>
+        <Filename Value="..\src\CryptoLibTestBase.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit71>
     </Units>
     </Units>
   </ProjectOptions>
   </ProjectOptions>
   <CompilerOptions>
   <CompilerOptions>
@@ -373,7 +377,7 @@
     </Target>
     </Target>
     <SearchPaths>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
       <IncludeFiles Value="$(ProjOutDir)"/>
-      <OtherUnitFiles Value="..\src\Asn1;..\src\Math;..\src\Math\EC\Custom\Sec;..\src\Others;..\src\Security;..\src\Utils;..\src\Crypto;..\src\Math\EC;..\src\Math\EC\Rfc7748;..\src\Math\EC\Rfc8032"/>
+      <OtherUnitFiles Value="..\src\Asn1;..\src\Math;..\src\Math\EC\Custom\Sec;..\src\Others;..\src\Security;..\src\Utils;..\src\Crypto;..\src\Math\EC;..\src\Math\EC\Rfc7748;..\src\Math\EC\Rfc8032;..\src"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     </SearchPaths>
     <CodeGeneration>
     <CodeGeneration>

+ 1 - 0
CryptoLib.Tests/FreePascal.Tests/CryptoLib.lpr

@@ -72,6 +72,7 @@ uses
   DigestTests,
   DigestTests,
   DigestUtilitiesTests,
   DigestUtilitiesTests,
   DHTests,
   DHTests,
+  CryptoLibTestBase,
   ClpFixedSecureRandom,
   ClpFixedSecureRandom,
   ClpIFixedSecureRandom,
   ClpIFixedSecureRandom,
   ClpShortenedDigest,
   ClpShortenedDigest,

+ 6 - 2
CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.Tests.lpi

@@ -37,7 +37,7 @@
         <PackageName Value="FCL"/>
         <PackageName Value="FCL"/>
       </Item2>
       </Item2>
     </RequiredPackages>
     </RequiredPackages>
-    <Units Count="71">
+    <Units Count="72">
       <Unit0>
       <Unit0>
         <Filename Value="CryptoLibConsole.lpr"/>
         <Filename Value="CryptoLibConsole.lpr"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
@@ -322,6 +322,10 @@
         <Filename Value="..\src\Crypto\DHTests.pas"/>
         <Filename Value="..\src\Crypto\DHTests.pas"/>
         <IsPartOfProject Value="True"/>
         <IsPartOfProject Value="True"/>
       </Unit70>
       </Unit70>
+      <Unit71>
+        <Filename Value="..\src\CryptoLibTestBase.pas"/>
+        <IsPartOfProject Value="True"/>
+      </Unit71>
     </Units>
     </Units>
   </ProjectOptions>
   </ProjectOptions>
   <CompilerOptions>
   <CompilerOptions>
@@ -332,7 +336,7 @@
     </Target>
     </Target>
     <SearchPaths>
     <SearchPaths>
       <IncludeFiles Value="$(ProjOutDir)"/>
       <IncludeFiles Value="$(ProjOutDir)"/>
-      <OtherUnitFiles Value="..\src\Others;..\src\Asn1;..\src\Math\EC\Custom\Sec;..\src\Math;..\src\Security;..\src\Utils;..\src\Crypto;..\src\Math\EC;..\src\Math\EC\Rfc7748;..\src\Math\EC\Rfc8032"/>
+      <OtherUnitFiles Value="..\src\Others;..\src\Asn1;..\src\Math\EC\Custom\Sec;..\src\Math;..\src\Security;..\src\Utils;..\src\Crypto;..\src\Math\EC;..\src\Math\EC\Rfc7748;..\src\Math\EC\Rfc8032;..\src"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
       <UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
     </SearchPaths>
     </SearchPaths>
   </CompilerOptions>
   </CompilerOptions>

+ 1 - 0
CryptoLib.Tests/FreePascal.Tests/CryptoLibConsole.lpr

@@ -70,6 +70,7 @@ uses
   DigestTests,
   DigestTests,
   DigestUtilitiesTests,
   DigestUtilitiesTests,
   DHTests,
   DHTests,
+  CryptoLibTestBase,
   ClpFixedSecureRandom,
   ClpFixedSecureRandom,
   ClpIFixedSecureRandom,
   ClpIFixedSecureRandom,
   ClpShortenedDigest,
   ClpShortenedDigest,

+ 40 - 52
CryptoLib.Tests/src/Asn1/Asn1SequenceParserTests.pas

@@ -33,31 +33,23 @@ uses
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpBigInteger,
   ClpBigInteger,
-  ClpEncoders,
-  ClpCryptoLibTypes,
-  ClpArrayUtils,
   ClpAsn1Objects,
   ClpAsn1Objects,
-  ClpIAsn1Objects;
+  ClpIAsn1Objects,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestAsn1SequenceParser = class(TCryptoLibTestCase)
+  TTestAsn1SequenceParser = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
     FseqData, FnestedSeqData, FexpTagSeqData, FimplTagSeqData,
     FseqData, FnestedSeqData, FexpTagSeqData, FimplTagSeqData,
       FnestedSeqExpTagData, FnestedSeqImpTagData, FberSeqData,
       FnestedSeqExpTagData, FnestedSeqImpTagData, FberSeqData,
       FberDerNestedSeqData, FberNestedSeqData, FberExpTagSeqData,
       FberDerNestedSeqData, FberNestedSeqData, FberExpTagSeqData,
-      FberSeqWithDERNullData: TCryptoLibByteArray;
+      FberSeqWithDERNullData: TBytes;
 
 
-    procedure doTestNestedReading(const data: TCryptoLibByteArray);
-    procedure doTestParseWithNull(const data: TCryptoLibByteArray);
+    procedure doTestNestedReading(const data: TBytes);
+    procedure doTestParseWithNull(const data: TBytes);
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -86,8 +78,7 @@ implementation
 
 
 { TTestAsn1SequenceParser }
 { TTestAsn1SequenceParser }
 
 
-procedure TTestAsn1SequenceParser.doTestNestedReading
-  (const data: TCryptoLibByteArray);
+procedure TTestAsn1SequenceParser.doTestNestedReading(const data: TBytes);
 var
 var
   aIn: IAsn1StreamParser;
   aIn: IAsn1StreamParser;
   seq, s: IAsn1SequenceParser;
   seq, s: IAsn1SequenceParser;
@@ -136,8 +127,7 @@ begin
   CheckEquals(3, count, 'wrong number of objects in sequence');
   CheckEquals(3, count, 'wrong number of objects in sequence');
 end;
 end;
 
 
-procedure TTestAsn1SequenceParser.doTestParseWithNull
-  (const data: TCryptoLibByteArray);
+procedure TTestAsn1SequenceParser.doTestParseWithNull(const data: TBytes);
 var
 var
   aIn: IAsn1StreamParser;
   aIn: IAsn1StreamParser;
   seq: IAsn1SequenceParser;
   seq: IAsn1SequenceParser;
@@ -180,18 +170,18 @@ end;
 procedure TTestAsn1SequenceParser.SetUp;
 procedure TTestAsn1SequenceParser.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FseqData := THex.Decode('3006020100060129');
-  FnestedSeqData := THex.Decode('300b0201000601293003020101');
-  FexpTagSeqData := THex.Decode('a1083006020100060129');
-  FimplTagSeqData := THex.Decode('a106020100060129');
-  FnestedSeqExpTagData := THex.Decode('300d020100060129a1053003020101');
-  FnestedSeqImpTagData := THex.Decode('300b020100060129a103020101');
-
-  FberSeqData := THex.Decode('30800201000601290000');
-  FberDerNestedSeqData := THex.Decode('308002010006012930030201010000');
-  FberNestedSeqData := THex.Decode('3080020100060129308002010100000000');
-  FberExpTagSeqData := THex.Decode('a180308002010006012900000000');
-  FberSeqWithDERNullData := THex.Decode('308005000201000601290000');
+  FseqData := DecodeHex('3006020100060129');
+  FnestedSeqData := DecodeHex('300b0201000601293003020101');
+  FexpTagSeqData := DecodeHex('a1083006020100060129');
+  FimplTagSeqData := DecodeHex('a106020100060129');
+  FnestedSeqExpTagData := DecodeHex('300d020100060129a1053003020101');
+  FnestedSeqImpTagData := DecodeHex('300b020100060129a103020101');
+
+  FberSeqData := DecodeHex('30800201000601290000');
+  FberDerNestedSeqData := DecodeHex('308002010006012930030201010000');
+  FberNestedSeqData := DecodeHex('3080020100060129308002010100000000');
+  FberExpTagSeqData := DecodeHex('a180308002010006012900000000');
+  FberSeqWithDERNullData := DecodeHex('308005000201000601290000');
 end;
 end;
 
 
 procedure TTestAsn1SequenceParser.TearDown;
 procedure TTestAsn1SequenceParser.TearDown;
@@ -204,7 +194,7 @@ procedure TTestAsn1SequenceParser.TestBerExplicitTaggedSequenceWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen: IBerSequenceGenerator;
   seqGen: IBerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -221,7 +211,7 @@ begin
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
 
 
-    CheckTrue(TArrayUtils.AreEqual(FberExpTagSeqData, temp),
+    CheckTrue(AreEqual(FberExpTagSeqData, temp),
       'explicit BER tag writing test failed.');
       'explicit BER tag writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -270,7 +260,7 @@ procedure TTestAsn1SequenceParser.TestBerWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen: IBerSequenceGenerator;
   seqGen: IBerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -285,8 +275,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FberSeqData, temp),
-      'basic BER writing test failed.');
+    CheckTrue(AreEqual(FberSeqData, temp), 'basic BER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
   end;
   end;
@@ -295,7 +284,7 @@ end;
 procedure TTestAsn1SequenceParser.TestDerExplicitTaggedSequenceWriting;
 procedure TTestAsn1SequenceParser.TestDerExplicitTaggedSequenceWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
   seqGen: IDerSequenceGenerator;
   seqGen: IDerSequenceGenerator;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
@@ -313,7 +302,7 @@ begin
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
 
 
-    CheckTrue(TArrayUtils.AreEqual(FexpTagSeqData, temp),
+    CheckTrue(AreEqual(FexpTagSeqData, temp),
       'explicit tag writing test failed.');
       'explicit tag writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -324,7 +313,7 @@ procedure TTestAsn1SequenceParser.TestDerImplicitTaggedSequenceWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen: IDerSequenceGenerator;
   seqGen: IDerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -341,7 +330,7 @@ begin
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
 
 
-    CheckTrue(TArrayUtils.AreEqual(FimplTagSeqData, temp),
+    CheckTrue(AreEqual(FimplTagSeqData, temp),
       'implicit tag writing test failed.');
       'implicit tag writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -390,7 +379,7 @@ procedure TTestAsn1SequenceParser.TestDerWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen: IDerSequenceGenerator;
   seqGen: IDerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -405,8 +394,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FseqData, temp),
-      'basic DER writing test failed.');
+    CheckTrue(AreEqual(FseqData, temp), 'basic DER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
   end;
   end;
@@ -422,7 +410,7 @@ var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen1: IBerSequenceGenerator;
   seqGen1: IBerSequenceGenerator;
   seqGen2: IDerSequenceGenerator;
   seqGen2: IDerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -445,7 +433,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FberDerNestedSeqData, temp),
+    CheckTrue(AreEqual(FberDerNestedSeqData, temp),
       'nested BER/DER writing test failed.');
       'nested BER/DER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -461,7 +449,7 @@ procedure TTestAsn1SequenceParser.TestNestedBerWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen1, seqGen2: IBerSequenceGenerator;
   seqGen1, seqGen2: IBerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -483,7 +471,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FberNestedSeqData, temp),
+    CheckTrue(AreEqual(FberNestedSeqData, temp),
       'nested BER writing test failed.');
       'nested BER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -499,7 +487,7 @@ procedure TTestAsn1SequenceParser.TestNestedDerWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen1, seqGen2: IDerSequenceGenerator;
   seqGen1, seqGen2: IDerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -521,7 +509,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FnestedSeqData, temp),
+    CheckTrue(AreEqual(FnestedSeqData, temp),
       'nested DER writing test failed.');
       'nested DER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -532,7 +520,7 @@ procedure TTestAsn1SequenceParser.TestNestedExplicitTagDerWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen1, seqGen2: IDerSequenceGenerator;
   seqGen1, seqGen2: IDerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -556,7 +544,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FnestedSeqExpTagData, temp),
+    CheckTrue(AreEqual(FnestedSeqExpTagData, temp),
       'nested explicit tagged DER writing test failed.');
       'nested explicit tagged DER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;
@@ -567,7 +555,7 @@ procedure TTestAsn1SequenceParser.TestNestedImplicitTagDerWriting;
 var
 var
   bOut: TMemoryStream;
   bOut: TMemoryStream;
   seqGen1, seqGen2: IDerSequenceGenerator;
   seqGen1, seqGen2: IDerSequenceGenerator;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();
   try
   try
@@ -591,7 +579,7 @@ begin
     bOut.Position := 0;
     bOut.Position := 0;
     System.SetLength(temp, bOut.Size);
     System.SetLength(temp, bOut.Size);
     bOut.Read(temp[0], bOut.Size);
     bOut.Read(temp[0], bOut.Size);
-    CheckTrue(TArrayUtils.AreEqual(FnestedSeqImpTagData, temp),
+    CheckTrue(AreEqual(FnestedSeqImpTagData, temp),
       'nested implicit tagged DER writing test failed.');
       'nested implicit tagged DER writing test failed.');
   finally
   finally
     bOut.Free;
     bOut.Free;

+ 15 - 28
CryptoLib.Tests/src/Asn1/DerApplicationSpecificTests.pas

@@ -32,25 +32,17 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes,
   ClpAsn1Objects,
   ClpAsn1Objects,
-  ClpIAsn1Objects;
+  ClpIAsn1Objects,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestDerApplicationSpecific = class(TCryptoLibTestCase)
+  TTestDerApplicationSpecific = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
-    FimpData, FcertData, FsampleData: TCryptoLibByteArray;
+    FimpData, FcertData, FsampleData: TBytes;
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -68,9 +60,9 @@ implementation
 procedure TTestDerApplicationSpecific.SetUp;
 procedure TTestDerApplicationSpecific.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FimpData := THex.Decode('430109');
+  FimpData := DecodeHex('430109');
 
 
-  FcertData := THex.Decode
+  FcertData := DecodeHex
     ('7F218201897F4E8201495F290100420E44454356434145504153533030317F49' +
     ('7F218201897F4E8201495F290100420E44454356434145504153533030317F49' +
     '81FD060A04007F00070202020202811CD7C134AA264366862A18302575D1D787' +
     '81FD060A04007F00070202020202811CD7C134AA264366862A18302575D1D787' +
     'B09F075797DA89F57EC8C0FF821C68A5E62CA9CE6C1C299803A6C1530B514E18' +
     'B09F075797DA89F57EC8C0FF821C68A5E62CA9CE6C1C299803A6C1530B514E18' +
@@ -85,7 +77,7 @@ begin
     '75F6C5F2E2D21F0395683B532A26E4C189B71EFE659C3F26E0EB9AEAE9986310' +
     '75F6C5F2E2D21F0395683B532A26E4C189B71EFE659C3F26E0EB9AEAE9986310' +
     '7F9B0DADA16414FFA204516AEE2B');
     '7F9B0DADA16414FFA204516AEE2B');
 
 
-  FsampleData := THex.Decode
+  FsampleData := DecodeHex
     ('613280020780a106060456000104a203020101a305a103020101be80288006025101020109a080b2800a01000000000000000000');
     ('613280020780a106060456000104a203020101a305a103020101be80288006025101020109a080b2800a01000000000000000000');
 end;
 end;
 
 
@@ -97,7 +89,7 @@ end;
 
 
 procedure TTestDerApplicationSpecific.TestDerApplicationSpecific;
 procedure TTestDerApplicationSpecific.TestDerApplicationSpecific;
 var
 var
-  encoded: TCryptoLibByteArray;
+  encoded: TBytes;
   appSpec, tagged, certObj: IDerApplicationSpecific;
   appSpec, tagged, certObj: IDerApplicationSpecific;
   recVal, val: IDerInteger;
   recVal, val: IDerInteger;
 begin
 begin
@@ -113,7 +105,7 @@ begin
 
 
   tagged := TDerApplicationSpecific.Create(false, 3, val);
   tagged := TDerApplicationSpecific.Create(false, 3, val);
 
 
-  if ((not TArrayUtils.AreEqual(FimpData, tagged.GetEncoded()))) then
+  if ((not AreEqual(FimpData, tagged.GetEncoded()))) then
   begin
   begin
     Fail('implicit encoding failed');
     Fail('implicit encoding failed');
   end;
   end;
@@ -134,7 +126,7 @@ begin
 
 
   encoded := certObj.GetDerEncoded();
   encoded := certObj.GetDerEncoded();
 
 
-  if ((not TArrayUtils.AreEqual(FcertData, encoded))) then
+  if ((not AreEqual(FcertData, encoded))) then
   begin
   begin
     Fail('re-encoding of certificate data failed');
     Fail('re-encoding of certificate data failed');
   end;
   end;
@@ -152,8 +144,7 @@ begin
 
 
   // Type1 :::= VisibleString
   // Type1 :::= VisibleString
   type1 := TDerVisibleString.Create('Jones');
   type1 := TDerVisibleString.Create('Jones');
-  if (not TArrayUtils.AreEqual(THex.Decode('1A054A6F6E6573'),
-    type1.GetEncoded())) then
+  if (not AreEqual(DecodeHex('1A054A6F6E6573'), type1.GetEncoded())) then
   begin
   begin
     Fail('ERROR: expected value doesn''t match!');
     Fail('ERROR: expected value doesn''t match!');
   end;
   end;
@@ -162,8 +153,7 @@ begin
   isExplicit := false;
   isExplicit := false;
   type2 := TDerApplicationSpecific.Create(isExplicit, 3, type1);
   type2 := TDerApplicationSpecific.Create(isExplicit, 3, type1);
   // type2.isConstructed()
   // type2.isConstructed()
-  if (not TArrayUtils.AreEqual(THex.Decode('43054A6F6E6573'),
-    type2.GetEncoded())) then
+  if (not AreEqual(DecodeHex('43054A6F6E6573'), type2.GetEncoded())) then
   begin
   begin
     Fail('ERROR: expected value doesn''t match!');
     Fail('ERROR: expected value doesn''t match!');
   end;
   end;
@@ -171,8 +161,7 @@ begin
   // Type3 :::= [2] Type2
   // Type3 :::= [2] Type2
   isExplicit := true;
   isExplicit := true;
   type3 := TDerTaggedObject.Create(isExplicit, 2, type2);
   type3 := TDerTaggedObject.Create(isExplicit, 2, type2);
-  if (not TArrayUtils.AreEqual(THex.Decode('A20743054A6F6E6573'),
-    type3.GetEncoded())) then
+  if (not AreEqual(DecodeHex('A20743054A6F6E6573'), type3.GetEncoded())) then
   begin
   begin
     Fail('ERROR: expected value doesn''t match!');
     Fail('ERROR: expected value doesn''t match!');
   end;
   end;
@@ -180,8 +169,7 @@ begin
   // Type4 :::= [APPLICATION 7] IMPLICIT Type3
   // Type4 :::= [APPLICATION 7] IMPLICIT Type3
   isExplicit := false;
   isExplicit := false;
   type4 := TDerApplicationSpecific.Create(isExplicit, 7, type3);
   type4 := TDerApplicationSpecific.Create(isExplicit, 7, type3);
-  if (not TArrayUtils.AreEqual(THex.Decode('670743054A6F6E6573'),
-    type4.GetEncoded())) then
+  if (not AreEqual(DecodeHex('670743054A6F6E6573'), type4.GetEncoded())) then
   begin
   begin
     Fail('ERROR: expected value doesn''t match!');
     Fail('ERROR: expected value doesn''t match!');
   end;
   end;
@@ -190,8 +178,7 @@ begin
   isExplicit := false;
   isExplicit := false;
   type5 := TDerTaggedObject.Create(isExplicit, 2, type2);
   type5 := TDerTaggedObject.Create(isExplicit, 2, type2);
   // type5.isConstructed()
   // type5.isConstructed()
-  if (not TArrayUtils.AreEqual(THex.Decode('82054A6F6E6573'),
-    type5.GetEncoded())) then
+  if (not AreEqual(DecodeHex('82054A6F6E6573'), type5.GetEncoded())) then
   begin
   begin
     Fail('ERROR: expected value doesn''t match!');
     Fail('ERROR: expected value doesn''t match!');
   end;
   end;

+ 5 - 11
CryptoLib.Tests/src/Asn1/EnumeratedTests.pas

@@ -33,20 +33,14 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpAsn1Objects,
   ClpAsn1Objects,
   ClpIAsn1Objects,
   ClpIAsn1Objects,
-  ClpEncoders;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// Tests used to verify correct decoding of the ENUMERATED type.
   /// Tests used to verify correct decoding of the ENUMERATED type.
   /// </summary>
   /// </summary>
-  TTestEnumerated = class(TCryptoLibTestCase)
+  TTestEnumerated = class(TCryptoLibAlgorithmTestCase)
   var
   var
   private
   private
     FMultipleSingleByteItems, FMultipleDoubleByteItems,
     FMultipleSingleByteItems, FMultipleDoubleByteItems,
@@ -82,17 +76,17 @@ begin
   /// Test vector used to test decoding of multiple items.
   /// Test vector used to test decoding of multiple items.
   /// </summary>
   /// </summary>
   /// <remarks>This sample uses an ENUMERATED and a BOOLEAN.</remarks>
   /// <remarks>This sample uses an ENUMERATED and a BOOLEAN.</remarks>
-  FMultipleSingleByteItems := THex.Decode('30060a01010101ff');
+  FMultipleSingleByteItems := DecodeHex('30060a01010101ff');
   /// <summary>
   /// <summary>
   /// Test vector used to test decoding of multiple items.
   /// Test vector used to test decoding of multiple items.
   /// </summary>
   /// </summary>
   /// <remarks>This sample uses two ENUMERATEDs.</remarks>
   /// <remarks>This sample uses two ENUMERATEDs.</remarks>
-  FMultipleDoubleByteItems := THex.Decode('30080a0201010a020202');
+  FMultipleDoubleByteItems := DecodeHex('30080a0201010a020202');
   /// <summary>
   /// <summary>
   /// Test vector used to test decoding of multiple items.
   /// Test vector used to test decoding of multiple items.
   /// </summary>
   /// </summary>
   /// <remarks>This sample uses an ENUMERATED and an OBJECT IDENTIFIER.</remarks>
   /// <remarks>This sample uses an ENUMERATED and an OBJECT IDENTIFIER.</remarks>
-  FMultipleTripleByteItems := THex.Decode('300a0a0301010106032b0601');
+  FMultipleTripleByteItems := DecodeHex('300a0a0301010106032b0601');
 end;
 end;
 
 
 procedure TTestEnumerated.TearDown;
 procedure TTestEnumerated.TearDown;

+ 9 - 14
CryptoLib.Tests/src/Asn1/EqualsAndHashCodeTests.pas

@@ -32,25 +32,19 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpEncoders,
-  ClpCryptoLibTypes,
   ClpConverters,
   ClpConverters,
   ClpIAsn1Objects,
   ClpIAsn1Objects,
-  ClpAsn1Objects;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpAsn1Objects,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestEqualsAndHashCode = class(TCryptoLibTestCase)
+  TTestEqualsAndHashCode = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
-    Fdata: TCryptoLibByteArray;
+    Fdata: TBytes;
     Fvalues: TCryptoLibGenericArray<IAsn1Object>;
     Fvalues: TCryptoLibGenericArray<IAsn1Object>;
 
 
   protected
   protected
@@ -67,7 +61,8 @@ implementation
 
 
 procedure TTestEqualsAndHashCode.SetUp;
 procedure TTestEqualsAndHashCode.SetUp;
 begin
 begin
-  Fdata := TCryptoLibByteArray.Create(0, 1, 0, 1, 0, 0, 1);
+  inherited;
+  Fdata := TBytes.Create(0, 1, 0, 1, 0, 0, 1);
   Fvalues := TCryptoLibGenericArray<IAsn1Object>.Create(
   Fvalues := TCryptoLibGenericArray<IAsn1Object>.Create(
 
 
     TBerOctetString.Create(Fdata),
     TBerOctetString.Create(Fdata),
@@ -89,7 +84,7 @@ begin
 
 
     TDerUtf8String.Create('hello world'),
     TDerUtf8String.Create('hello world'),
     TDerVisibleString.Create('hello world'),
     TDerVisibleString.Create('hello world'),
-    TDerGraphicString.Create(THex.Decode('deadbeef')),
+    TDerGraphicString.Create(DecodeHex('deadbeef')),
     TDerVideotexString.Create(TConverters.ConvertStringToBytes('Hello World',
     TDerVideotexString.Create(TConverters.ConvertStringToBytes('Hello World',
     TEncoding.ANSI)),
     TEncoding.ANSI)),
 
 
@@ -124,7 +119,7 @@ var
   aOut: TAsn1OutputStream;
   aOut: TAsn1OutputStream;
   aIn: TAsn1InputStream;
   aIn: TAsn1InputStream;
   o: IAsn1Object;
   o: IAsn1Object;
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   bOut := TMemoryStream.Create();
   bOut := TMemoryStream.Create();

+ 53 - 60
CryptoLib.Tests/src/Asn1/OIDTests.pas

@@ -32,33 +32,26 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes,
   ClpAsn1Objects,
   ClpAsn1Objects,
-  ClpIAsn1Objects;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpIAsn1Objects,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestOID = class(TCryptoLibTestCase)
+  TTestOID = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
     Foid: string;
     Foid: string;
-    Freq1, Freq2: TCryptoLibByteArray;
+    Freq1, Freq2: TBytes;
 
 
-    procedure recodeCheck(const oid: String; const enc: TBytes);
-    procedure validOidCheck(const oid: String);
-    procedure invalidOidCheck;
-    procedure branchCheck(const stem, branch: String);
-    procedure onCheck(const stem, test: String; expected: Boolean);
-    procedure constructorMethod;
+    procedure DoRecodeCheck(const oid: String; const enc: TBytes);
+    procedure DoValidOidCheck(const oid: String);
+    procedure DoInvalidOidCheck;
+    procedure DoBranchCheck(const stem, branch: String);
+    procedure DoOnCheck(const stem, test: String; expected: Boolean);
+    procedure DoConstructorMethod;
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -72,7 +65,7 @@ implementation
 
 
 { TTestOID }
 { TTestOID }
 
 
-procedure TTestOID.branchCheck(const stem, branch: String);
+procedure TTestOID.DoBranchCheck(const stem, branch: String);
 var
 var
   expected, actual: String;
   expected, actual: String;
   instance: IDerObjectIdentifier;
   instance: IDerObjectIdentifier;
@@ -85,12 +78,12 @@ begin
     + branch);
     + branch);
 end;
 end;
 
 
-procedure TTestOID.constructorMethod;
+procedure TTestOID.DoConstructorMethod;
 begin
 begin
   TDerObjectIdentifier.Create(Foid);
   TDerObjectIdentifier.Create(Foid);
 end;
 end;
 
 
-procedure TTestOID.invalidOidCheck;
+procedure TTestOID.DoInvalidOidCheck;
 var
 var
 {$IFNDEF FPC}
 {$IFNDEF FPC}
   Method: TTestMethod;
   Method: TTestMethod;
@@ -99,12 +92,12 @@ var
 {$ENDIF FPC}
 {$ENDIF FPC}
 begin
 begin
 
 
-  Method := constructorMethod;
+  Method := DoConstructorMethod;
   CheckException(Method, EFormatCryptoLibException,
   CheckException(Method, EFormatCryptoLibException,
     'Expected "EFormatCryptoLibException" But None Gotten');
     'Expected "EFormatCryptoLibException" But None Gotten');
 end;
 end;
 
 
-procedure TTestOID.onCheck(const stem, test: String; expected: Boolean);
+procedure TTestOID.DoOnCheck(const stem, test: String; expected: Boolean);
 var
 var
   tempDer, tempDer2: IDerObjectIdentifier;
   tempDer, tempDer2: IDerObjectIdentifier;
   actual: Boolean;
   actual: Boolean;
@@ -115,7 +108,7 @@ begin
   CheckEquals(expected, actual, 'failed "on" check for ' + stem + '"/"' + test);
   CheckEquals(expected, actual, 'failed "on" check for ' + stem + '"/"' + test);
 end;
 end;
 
 
-procedure TTestOID.recodeCheck(const oid: String; const enc: TBytes);
+procedure TTestOID.DoRecodeCheck(const oid: String; const enc: TBytes);
 var
 var
   o, encO: IDerObjectIdentifier;
   o, encO: IDerObjectIdentifier;
   bytes: TBytes;
   bytes: TBytes;
@@ -130,14 +123,14 @@ begin
 
 
   CheckEquals(true, o.Equals(encO), 'object comparison failed');
   CheckEquals(true, o.Equals(encO), 'object comparison failed');
 
 
-  CheckEquals(true, TArrayUtils.AreEqual(bytes, enc),
-    'bytearray comparison failed');
+  CheckEquals(true, AreEqual(bytes, enc), 'bytearray comparison failed');
 end;
 end;
 
 
 procedure TTestOID.SetUp;
 procedure TTestOID.SetUp;
 begin
 begin
-  Freq1 := THex.Decode('0603813403');
-  Freq2 := THex.Decode('06082A36FFFFFFDD6311');
+  inherited;
+  Freq1 := DecodeHex('0603813403');
+  Freq2 := DecodeHex('06082A36FFFFFFDD6311');
 end;
 end;
 
 
 procedure TTestOID.TearDown;
 procedure TTestOID.TearDown;
@@ -148,58 +141,58 @@ end;
 
 
 procedure TTestOID.TestOID;
 procedure TTestOID.TestOID;
 begin
 begin
-  recodeCheck('2.100.3', Freq1);
-  recodeCheck('1.2.54.34359733987.17', Freq2);
+  DoRecodeCheck('2.100.3', Freq1);
+  DoRecodeCheck('1.2.54.34359733987.17', Freq2);
 
 
-  validOidCheck('0.1');
-  validOidCheck
+  DoValidOidCheck('0.1');
+  DoValidOidCheck
     ('1.1.127.32512.8323072.2130706432.545460846592.139637976727552.35747322042253312.9151314442816847872');
     ('1.1.127.32512.8323072.2130706432.545460846592.139637976727552.35747322042253312.9151314442816847872');
-  validOidCheck('1.2.123.12345678901.1.1.1');
+  DoValidOidCheck('1.2.123.12345678901.1.1.1');
 
 
-  validOidCheck('2.25.196556539987194312349856245628873852187.1');
+  DoValidOidCheck('2.25.196556539987194312349856245628873852187.1');
 
 
   Foid := '0';
   Foid := '0';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '1';
   Foid := '1';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '2';
   Foid := '2';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '3.1';
   Foid := '3.1';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '..1';
   Foid := '..1';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '192.168.1.1';
   Foid := '192.168.1.1';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '.123452';
   Foid := '.123452';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '1.';
   Foid := '1.';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '1.345.23.34..234';
   Foid := '1.345.23.34..234';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '1.345.23.34.234.';
   Foid := '1.345.23.34.234.';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '.12.345.77.234';
   Foid := '.12.345.77.234';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '.12.345.77.234.';
   Foid := '.12.345.77.234.';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '1.2.3.4.A.5';
   Foid := '1.2.3.4.A.5';
-  invalidOidCheck;
+  DoInvalidOidCheck;
   Foid := '1,2';
   Foid := '1,2';
-  invalidOidCheck;
-
-  branchCheck('1.1', '2.2');
-
-  onCheck('1.1', '1.1', false);
-  onCheck('1.1', '1.2', false);
-  onCheck('1.1', '1.2.1', false);
-  onCheck('1.1', '2.1', false);
-  onCheck('1.1', '1.11', false);
-  onCheck('1.12', '1.1.2', false);
-  onCheck('1.1', '1.1.1', true);
-  onCheck('1.1', '1.1.2', true);
+  DoInvalidOidCheck;
+
+  DoBranchCheck('1.1', '2.2');
+
+  DoOnCheck('1.1', '1.1', false);
+  DoOnCheck('1.1', '1.2', false);
+  DoOnCheck('1.1', '1.2.1', false);
+  DoOnCheck('1.1', '2.1', false);
+  DoOnCheck('1.1', '1.11', false);
+  DoOnCheck('1.12', '1.1.2', false);
+  DoOnCheck('1.1', '1.1.1', true);
+  DoOnCheck('1.1', '1.1.2', true);
 end;
 end;
 
 
-procedure TTestOID.validOidCheck(const oid: String);
+procedure TTestOID.DoValidOidCheck(const oid: String);
 var
 var
   o: IDerObjectIdentifier;
   o: IDerObjectIdentifier;
 begin
 begin

+ 4 - 10
CryptoLib.Tests/src/Asn1/ParseTests.pas

@@ -33,18 +33,12 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpAsn1Objects,
   ClpAsn1Objects,
   ClpIAsn1Objects,
   ClpIAsn1Objects,
-  ClpEncoders;
+  CryptoLibTestBase;
 
 
 type
 type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-  TTestParse = class(TCryptoLibTestCase)
-  var
+  TTestParse = class(TCryptoLibAlgorithmTestCase)
   private
   private
+  var
     FlongTagged: TBytes;
     FlongTagged: TBytes;
 
 
   protected
   protected
@@ -62,7 +56,7 @@ implementation
 procedure TTestParse.SetUp;
 procedure TTestParse.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FlongTagged := THex.Decode('9f1f023330');
+  FlongTagged := DecodeHex('9f1f023330');
 end;
 end;
 
 
 procedure TTestParse.TearDown;
 procedure TTestParse.TearDown;

+ 5 - 11
CryptoLib.Tests/src/Asn1/ParsingTests.pas

@@ -33,17 +33,11 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpAsn1Objects,
   ClpAsn1Objects,
   ClpIAsn1Objects,
   ClpIAsn1Objects,
-  ClpEncoders,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-  TTestParsing = class(TCryptoLibTestCase)
+  TTestParsing = class(TCryptoLibAlgorithmTestCase)
   var
   var
   private
   private
     FStreams: TCryptoLibStringArray;
     FStreams: TCryptoLibStringArray;
@@ -134,7 +128,7 @@ var
 begin
 begin
   for stream in FStreams do
   for stream in FStreams do
   begin
   begin
-    aIn := TAsn1InputStream.Create(TBase64.Decode(stream));
+    aIn := TAsn1InputStream.Create(DecodeBase64(stream));
 
 
     try
     try
 
 
@@ -180,7 +174,7 @@ var
 begin
 begin
   for stream in FStreams do
   for stream in FStreams do
   begin
   begin
-    aIn := TAsn1StreamParser.Create(TBase64.Decode(stream));
+    aIn := TAsn1StreamParser.Create(DecodeBase64(stream));
 
 
     try
     try
 
 

+ 3 - 8
CryptoLib.Tests/src/Asn1/StringTests.pas

@@ -33,20 +33,15 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpAsn1Objects,
   ClpAsn1Objects,
   ClpIAsn1Objects,
   ClpIAsn1Objects,
-  ClpConverters;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpConverters,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// X.690 test example
   /// X.690 test example
   /// </summary>
   /// </summary>
-  TTestString = class(TCryptoLibTestCase)
+  TTestString = class(TCryptoLibAlgorithmTestCase)
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;

+ 5 - 12
CryptoLib.Tests/src/Asn1/TagTests.pas

@@ -36,25 +36,18 @@ uses
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
   ClpBits,
   ClpBits,
-  ClpEncoders,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// X.690 test example
   /// X.690 test example
   /// </summary>
   /// </summary>
-  TTestTag = class(TCryptoLibTestCase)
+  TTestTag = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
-    FlongAppSpecificTag, FlongTagged: TCryptoLibByteArray;
+    FlongAppSpecificTag, FlongTagged: TBytes;
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -71,9 +64,9 @@ implementation
 procedure TTestTag.SetUp;
 procedure TTestTag.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FlongAppSpecificTag := THex.Decode('5F610101');
+  FlongAppSpecificTag := DecodeHex('5F610101');
 
 
-  FlongTagged := TBase64.Decode
+  FlongTagged := DecodeBase64
     ('ZSRzIp8gEEZFRENCQTk4NzY1NDMyMTCfIQwyMDA2MDQwMTEyMzSUCCAFERVz' +
     ('ZSRzIp8gEEZFRENCQTk4NzY1NDMyMTCfIQwyMDA2MDQwMTEyMzSUCCAFERVz' +
     'A4kCAHEXGBkalAggBRcYGRqUCCAFZS6QAkRFkQlURUNITklLRVKSBQECAwQF' +
     'A4kCAHEXGBkalAggBRcYGRqUCCAFZS6QAkRFkQlURUNITklLRVKSBQECAwQF' +
     'kxAREhMUFRYXGBkalAggBREVcwOJAgBxFxgZGpQIIAUXGBkalAggBWUukAJE' +
     'kxAREhMUFRYXGBkalAggBREVcwOJAgBxFxgZGpQIIAUXGBkalAggBWUukAJE' +

+ 36 - 44
CryptoLib.Tests/src/Crypto/AESSICTests.pas

@@ -37,15 +37,8 @@ uses
   ClpIBufferedCipher,
   ClpIBufferedCipher,
   ClpParameterUtilities,
   ClpParameterUtilities,
   ClpCipherUtilities,
   ClpCipherUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -53,7 +46,7 @@ type
   /// Test vectors based on NIST Special Publication 800-38A, <br />
   /// Test vectors based on NIST Special Publication 800-38A, <br />
   /// "Recommendation for Block Cipher Modes of Operation"
   /// "Recommendation for Block Cipher Modes of Operation"
   /// </summary>
   /// </summary>
-  TTestAESSIC = class(TCryptoLibTestCase)
+  TTestAESSIC = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -78,33 +71,33 @@ begin
   inherited;
   inherited;
 
 
   Fkeys := TCryptoLibMatrixByteArray.Create
   Fkeys := TCryptoLibMatrixByteArray.Create
-    (THex.Decode('2B7E151628AED2A6ABF7158809CF4F3C'),
-    THex.Decode('8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B'),
-    THex.Decode
-    ('603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4'));
+    (DecodeHex('2B7E151628AED2A6ABF7158809CF4F3C'),
+    DecodeHex('8E73B0F7DA0E6452C810F32B809079E562F8EAD2522C6B7B'),
+    DecodeHex(
+    '603DEB1015CA71BE2B73AEF0857D77811F352C073B6108D72D9810A30914DFF4'));
 
 
   Fplain := TCryptoLibMatrixByteArray.Create
   Fplain := TCryptoLibMatrixByteArray.Create
-    (THex.Decode('6BC1BEE22E409F96E93D7E117393172A'),
-    THex.Decode('AE2D8A571E03AC9C9EB76FAC45AF8E51'),
-    THex.Decode('30C81C46A35CE411E5FBC1191A0A52EF'),
-    THex.Decode('F69F2445DF4F9B17AD2B417BE66C3710'));
+    (DecodeHex('6BC1BEE22E409F96E93D7E117393172A'),
+    DecodeHex('AE2D8A571E03AC9C9EB76FAC45AF8E51'),
+    DecodeHex('30C81C46A35CE411E5FBC1191A0A52EF'),
+    DecodeHex('F69F2445DF4F9B17AD2B417BE66C3710'));
 
 
   Fcipher := TCryptoLibGenericArray<TCryptoLibMatrixByteArray>.Create
   Fcipher := TCryptoLibGenericArray<TCryptoLibMatrixByteArray>.Create
     (TCryptoLibMatrixByteArray.Create
     (TCryptoLibMatrixByteArray.Create
-    (THex.Decode('874D6191B620E3261BEF6864990DB6CE'),
-    THex.Decode('9806F66B7970FDFF8617187BB9FFFDFF'),
-    THex.Decode('5AE4DF3EDBD5D35E5B4F09020DB03EAB'),
-    THex.Decode('1E031DDA2FBE03D1792170A0F3009CEE')),
+    (DecodeHex('874D6191B620E3261BEF6864990DB6CE'),
+    DecodeHex('9806F66B7970FDFF8617187BB9FFFDFF'),
+    DecodeHex('5AE4DF3EDBD5D35E5B4F09020DB03EAB'),
+    DecodeHex('1E031DDA2FBE03D1792170A0F3009CEE')),
     TCryptoLibMatrixByteArray.Create
     TCryptoLibMatrixByteArray.Create
-    (THex.Decode('1ABC932417521CA24F2B0459FE7E6E0B'),
-    THex.Decode('090339EC0AA6FAEFD5CCC2C6F4CE8E94'),
-    THex.Decode('1E36B26BD1EBC670D1BD1D665620ABF7'),
-    THex.Decode('4F78A7F6D29809585A97DAEC58C6B050')),
+    (DecodeHex('1ABC932417521CA24F2B0459FE7E6E0B'),
+    DecodeHex('090339EC0AA6FAEFD5CCC2C6F4CE8E94'),
+    DecodeHex('1E36B26BD1EBC670D1BD1D665620ABF7'),
+    DecodeHex('4F78A7F6D29809585A97DAEC58C6B050')),
     TCryptoLibMatrixByteArray.Create
     TCryptoLibMatrixByteArray.Create
-    (THex.Decode('601EC313775789A5B7A7F504BBF3D228'),
-    THex.Decode('F443E3CA4D62B59ACA84E990CACAF5C5'),
-    THex.Decode('2B0930DAA23DE94CE87017BA2D84988D'),
-    THex.Decode('DFC9C58DB67AADA613C2DD08457941A6')));
+    (DecodeHex('601EC313775789A5B7A7F504BBF3D228'),
+    DecodeHex('F443E3CA4D62B59ACA84E990CACAF5C5'),
+    DecodeHex('2B0930DAA23DE94CE87017BA2D84988D'),
+    DecodeHex('DFC9C58DB67AADA613C2DD08457941A6')));
 end;
 end;
 
 
 procedure TTestAESSIC.TearDown;
 procedure TTestAESSIC.TearDown;
@@ -132,13 +125,13 @@ begin
   begin
   begin
     skey := TParameterUtilities.CreateKeyParameter('AES', Fkeys[i]);
     skey := TParameterUtilities.CreateKeyParameter('AES', Fkeys[i]);
     c.Init(true, TParametersWithIV.Create(skey,
     c.Init(true, TParametersWithIV.Create(skey,
-      THex.Decode('F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF')) as IParametersWithIV);
+      DecodeHex('F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF')) as IParametersWithIV);
 
 
     j := 0;
     j := 0;
     while j <> System.Length(Fplain) do
     while j <> System.Length(Fplain) do
     begin
     begin
       enc := c.ProcessBytes(Fplain[j]);
       enc := c.ProcessBytes(Fplain[j]);
-      if (not TArrayUtils.AreEqual(enc, Fcipher[i, j])) then
+      if (not AreEqual(enc, Fcipher[i, j])) then
       begin
       begin
         Fail('AESSIC encrypt failed: key ' + IntToStr(i) + ' block ' +
         Fail('AESSIC encrypt failed: key ' + IntToStr(i) + ' block ' +
           IntToStr(j));
           IntToStr(j));
@@ -147,13 +140,13 @@ begin
     end;
     end;
 
 
     c.Init(false, TParametersWithIV.Create(skey,
     c.Init(false, TParametersWithIV.Create(skey,
-      THex.Decode('F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF')) as IParametersWithIV);
+      DecodeHex('F0F1F2F3F4F5F6F7F8F9FAFBFCFDFEFF')) as IParametersWithIV);
 
 
     j := 0;
     j := 0;
     while j <> System.Length(Fplain) do
     while j <> System.Length(Fplain) do
     begin
     begin
       enc := c.ProcessBytes(Fcipher[i, j]);
       enc := c.ProcessBytes(Fcipher[i, j]);
-      if (not TArrayUtils.AreEqual(enc, Fplain[j])) then
+      if (not AreEqual(enc, Fplain[j])) then
       begin
       begin
         Fail('AESSIC decrypt failed: key ' + IntToStr(i) + ' block ' +
         Fail('AESSIC decrypt failed: key ' + IntToStr(i) + ' block ' +
           IntToStr(j));
           IntToStr(j));
@@ -170,15 +163,14 @@ begin
   c := TCipherUtilities.GetCipher('AES/CTR/NoPadding');
   c := TCipherUtilities.GetCipher('AES/CTR/NoPadding');
 
 
   sk := TParameterUtilities.CreateKeyParameter('AES',
   sk := TParameterUtilities.CreateKeyParameter('AES',
-    THex.Decode('2B7E151628AED2A6ABF7158809CF4F3C'));
+    DecodeHex('2B7E151628AED2A6ABF7158809CF4F3C'));
 
 
   c.Init(true, TParametersWithIV.Create(sk,
   c.Init(true, TParametersWithIV.Create(sk,
-    THex.Decode('F0F1F2F3F4F5F6F7F8F9FAFBFCFD0001')) as IParametersWithIV);
+    DecodeHex('F0F1F2F3F4F5F6F7F8F9FAFBFCFD0001')) as IParametersWithIV);
 
 
-  crypt := c.DoFinal(THex.Decode('00000000000000000000000000000000'));
+  crypt := c.DoFinal(DecodeHex('00000000000000000000000000000000'));
 
 
-  if (not TArrayUtils.AreEqual(crypt,
-    THex.Decode('D23513162B02D0F72A43A2FE4A5F97AB'))) then
+  if (not AreEqual(crypt, DecodeHex('D23513162B02D0F72A43A2FE4A5F97AB'))) then
   begin
   begin
     Fail('AESSIC failed test 2');
     Fail('AESSIC failed test 2');
   end;
   end;
@@ -189,19 +181,19 @@ begin
   c := TCipherUtilities.GetCipher('AES/CTR/NoPadding');
   c := TCipherUtilities.GetCipher('AES/CTR/NoPadding');
 
 
   sk := TParameterUtilities.CreateKeyParameter('AES',
   sk := TParameterUtilities.CreateKeyParameter('AES',
-    THex.Decode('2B7E151628AED2A6ABF7158809CF4F3C'));
+    DecodeHex('2B7E151628AED2A6ABF7158809CF4F3C'));
 
 
   c.Init(true, TParametersWithIV.Create(sk,
   c.Init(true, TParametersWithIV.Create(sk,
-    THex.Decode('F0F1F2F3F4F5F6F7F8F9FAFBFCFD0001')) as IParametersWithIV);
+    DecodeHex('F0F1F2F3F4F5F6F7F8F9FAFBFCFD0001')) as IParametersWithIV);
 
 
-  crypt := c.DoFinal(THex.Decode('12345678'));
+  crypt := c.DoFinal(DecodeHex('12345678'));
 
 
   c.Init(false, TParametersWithIV.Create(sk,
   c.Init(false, TParametersWithIV.Create(sk,
-    THex.Decode('F0F1F2F3F4F5F6F7F8F9FAFBFCFD0001')) as IParametersWithIV);
+    DecodeHex('F0F1F2F3F4F5F6F7F8F9FAFBFCFD0001')) as IParametersWithIV);
 
 
   crypt := c.DoFinal(crypt);
   crypt := c.DoFinal(crypt);
 
 
-  if (not TArrayUtils.AreEqual(crypt, THex.Decode('12345678'))) then
+  if (not AreEqual(crypt, DecodeHex('12345678'))) then
   begin
   begin
     Fail('AESSIC failed partial test');
     Fail('AESSIC failed partial test');
   end;
   end;

+ 32 - 39
CryptoLib.Tests/src/Crypto/AESTests.pas

@@ -53,25 +53,18 @@ uses
   // ClpIPaddedBufferedBlockCipher,
   // ClpIPaddedBufferedBlockCipher,
   // ClpPaddingModes,
   // ClpPaddingModes,
   // ClpIPaddingModes,
   // ClpIPaddingModes,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestAES = class(TCryptoLibTestCase)
+  TTestAES = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
-    procedure dooidTest(const oids, names: TCryptoLibStringArray;
+    procedure DoOidTest(const oids, names: TCryptoLibStringArray;
       groupSize: Int32);
       groupSize: Int32);
 
 
-    procedure doAESTest(const cipher: IBufferedCipher;
+    procedure DoAESTest(const cipher: IBufferedCipher;
       const param: ICipherParameters; const input, output: String;
       const param: ICipherParameters; const input, output: String;
       withpadding: Boolean = False);
       withpadding: Boolean = False);
 
 
@@ -94,15 +87,15 @@ implementation
 
 
 { TTestAES }
 { TTestAES }
 
 
-procedure TTestAES.doAESTest(const cipher: IBufferedCipher;
+procedure TTestAES.DoAESTest(const cipher: IBufferedCipher;
   const param: ICipherParameters; const input, output: String;
   const param: ICipherParameters; const input, output: String;
   withpadding: Boolean);
   withpadding: Boolean);
 var
 var
   LInput, LOutput, EncryptionResult, DecryptionResult: TBytes;
   LInput, LOutput, EncryptionResult, DecryptionResult: TBytes;
   // len1, len2: Int32;
   // len1, len2: Int32;
 begin
 begin
-  LInput := THex.Decode(input);
-  LOutput := THex.Decode(output);
+  LInput := DecodeHex(input);
+  LOutput := DecodeHex(output);
 
 
   cipher.Init(True, param);
   cipher.Init(True, param);
 
 
@@ -123,10 +116,10 @@ begin
 
 
   if not withpadding then
   if not withpadding then
   begin
   begin
-    if (not TArrayUtils.AreEqual(LOutput, EncryptionResult)) then
+    if (not AreEqual(LOutput, EncryptionResult)) then
     begin
     begin
       Fail(Format('Encryption Failed - Expected %s but got %s',
       Fail(Format('Encryption Failed - Expected %s but got %s',
-        [THex.Encode(LOutput), THex.Encode(EncryptionResult)]));
+        [EncodeHex(LOutput), EncodeHex(EncryptionResult)]));
     end;
     end;
   end;
   end;
 
 
@@ -149,14 +142,14 @@ begin
     System.SetLength(DecryptionResult, len2);
     System.SetLength(DecryptionResult, len2);
     * }
     * }
 
 
-  if (not TArrayUtils.AreEqual(LInput, DecryptionResult)) then
+  if (not AreEqual(LInput, DecryptionResult)) then
   begin
   begin
     Fail(Format('Decryption Failed - Expected %s but got %s',
     Fail(Format('Decryption Failed - Expected %s but got %s',
-      [THex.Encode(LInput), THex.Encode(DecryptionResult)]));
+      [EncodeHex(LInput), EncodeHex(DecryptionResult)]));
   end;
   end;
 end;
 end;
 
 
-procedure TTestAES.dooidTest(const oids, names: TCryptoLibStringArray;
+procedure TTestAES.DoOidTest(const oids, names: TCryptoLibStringArray;
   groupSize: Int32);
   groupSize: Int32);
 var
 var
   data, result, IV: TBytes;
   data, result, IV: TBytes;
@@ -189,7 +182,7 @@ begin
 
 
     result := c2.DoFinal(c1.DoFinal(data));
     result := c2.DoFinal(c1.DoFinal(data));
 
 
-    if (not TArrayUtils.AreEqual(data, result)) then
+    if (not AreEqual(data, result)) then
     begin
     begin
       Fail('failed OID test');
       Fail('failed OID test');
     end;
     end;
@@ -233,15 +226,15 @@ begin
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CBC)
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CBC)
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CBC) do
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CBC) do
   begin
   begin
-    keyBytes := THex.Decode(TAESTestVectors.FOfficialVectorKeys_AES_CBC[i]);
-    IVBytes := THex.Decode(TAESTestVectors.FOfficialVectorIVs_AES_CBC[i]);
+    keyBytes := DecodeHex(TAESTestVectors.FOfficialVectorKeys_AES_CBC[i]);
+    IVBytes := DecodeHex(TAESTestVectors.FOfficialVectorIVs_AES_CBC[i]);
     input := TAESTestVectors.FOfficialVectorInputs_AES_CBC[i];
     input := TAESTestVectors.FOfficialVectorInputs_AES_CBC[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CBC[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CBC[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
 
 
-    doAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
+    DoAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;
@@ -268,15 +261,15 @@ begin
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CBC)
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CBC)
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CBC) do
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CBC) do
   begin
   begin
-    keyBytes := THex.Decode(TAESTestVectors.FOfficialVectorKeys_AES_CBC[i]);
-    IVBytes := THex.Decode(TAESTestVectors.FOfficialVectorIVs_AES_CBC[i]);
+    keyBytes := DecodeHex(TAESTestVectors.FOfficialVectorKeys_AES_CBC[i]);
+    IVBytes := DecodeHex(TAESTestVectors.FOfficialVectorIVs_AES_CBC[i]);
     input := TAESTestVectors.FOfficialVectorInputs_AES_CBC[i];
     input := TAESTestVectors.FOfficialVectorInputs_AES_CBC[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CBC[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CBC[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
 
 
-    doAESTest(cipher, KeyParametersWithIV as ICipherParameters, input,
+    DoAESTest(cipher, KeyParametersWithIV as ICipherParameters, input,
       output, True);
       output, True);
   end;
   end;
 
 
@@ -302,15 +295,15 @@ begin
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CFB)
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CFB)
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CFB) do
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CFB) do
   begin
   begin
-    keyBytes := THex.Decode(TAESTestVectors.FOfficialVectorKeys_AES_CFB[i]);
-    IVBytes := THex.Decode(TAESTestVectors.FOfficialVectorIVs_AES_CFB[i]);
+    keyBytes := DecodeHex(TAESTestVectors.FOfficialVectorKeys_AES_CFB[i]);
+    IVBytes := DecodeHex(TAESTestVectors.FOfficialVectorIVs_AES_CFB[i]);
     input := TAESTestVectors.FOfficialVectorInputs_AES_CFB[i];
     input := TAESTestVectors.FOfficialVectorInputs_AES_CFB[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CFB[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CFB[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
 
 
-    doAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
+    DoAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;
@@ -334,15 +327,15 @@ begin
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CTR)
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_CTR)
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CTR) do
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_CTR) do
   begin
   begin
-    keyBytes := THex.Decode(TAESTestVectors.FOfficialVectorKeys_AES_CTR[i]);
-    IVBytes := THex.Decode(TAESTestVectors.FOfficialVectorIVs_AES_CTR[i]);
+    keyBytes := DecodeHex(TAESTestVectors.FOfficialVectorKeys_AES_CTR[i]);
+    IVBytes := DecodeHex(TAESTestVectors.FOfficialVectorIVs_AES_CTR[i]);
     input := TAESTestVectors.FOfficialVectorInputs_AES_CTR[i];
     input := TAESTestVectors.FOfficialVectorInputs_AES_CTR[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CTR[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_CTR[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
 
 
-    doAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
+    DoAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;
@@ -366,13 +359,13 @@ begin
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_ECB)
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_ECB)
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_ECB) do
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_ECB) do
   begin
   begin
-    keyBytes := THex.Decode(TAESTestVectors.FOfficialVectorKeys_AES_ECB[i]);
+    keyBytes := DecodeHex(TAESTestVectors.FOfficialVectorKeys_AES_ECB[i]);
     input := TAESTestVectors.FOfficialVectorInputs_AES_ECB[i];
     input := TAESTestVectors.FOfficialVectorInputs_AES_ECB[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_ECB[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_ECB[i];
 
 
     keyParameter := TParameterUtilities.CreateKeyParameter('AES', keyBytes);
     keyParameter := TParameterUtilities.CreateKeyParameter('AES', keyBytes);
 
 
-    doAESTest(cipher, keyParameter as ICipherParameters, input, output);
+    DoAESTest(cipher, keyParameter as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;
@@ -397,15 +390,15 @@ begin
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_OFB)
   for i := System.Low(TAESTestVectors.FOfficialVectorKeys_AES_OFB)
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_OFB) do
     to System.High(TAESTestVectors.FOfficialVectorKeys_AES_OFB) do
   begin
   begin
-    keyBytes := THex.Decode(TAESTestVectors.FOfficialVectorKeys_AES_OFB[i]);
-    IVBytes := THex.Decode(TAESTestVectors.FOfficialVectorIVs_AES_OFB[i]);
+    keyBytes := DecodeHex(TAESTestVectors.FOfficialVectorKeys_AES_OFB[i]);
+    IVBytes := DecodeHex(TAESTestVectors.FOfficialVectorIVs_AES_OFB[i]);
     input := TAESTestVectors.FOfficialVectorInputs_AES_OFB[i];
     input := TAESTestVectors.FOfficialVectorInputs_AES_OFB[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_OFB[i];
     output := TAESTestVectors.FOfficialVectorOutputs_AES_OFB[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
       (TParameterUtilities.CreateKeyParameter('AES', keyBytes), IVBytes);
 
 
-    doAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
+    DoAESTest(cipher, KeyParametersWithIV as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;
@@ -433,7 +426,7 @@ begin
     'AES/CFB/NoPadding', 'AES/ECB/PKCS7Padding', 'AES/CBC/PKCS7Padding',
     'AES/CFB/NoPadding', 'AES/ECB/PKCS7Padding', 'AES/CBC/PKCS7Padding',
     'AES/OFB/NoPadding', 'AES/CFB/NoPadding');
     'AES/OFB/NoPadding', 'AES/CFB/NoPadding');
 
 
-  dooidTest(oids, names, 4);
+  DoOidTest(oids, names, 4);
 end;
 end;
 
 
 initialization
 initialization

+ 3 - 8
CryptoLib.Tests/src/Crypto/Argon2Tests.pas

@@ -34,20 +34,15 @@ uses
   ClpIKeyParameter,
   ClpIKeyParameter,
   ClpArgon2ParametersGenerator,
   ClpArgon2ParametersGenerator,
   ClpIArgon2ParametersGenerator,
   ClpIArgon2ParametersGenerator,
-  ClpConverters;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpConverters,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// A test class for Argon2.
   /// A test class for Argon2.
   /// </summary>
   /// </summary>
-  TTestArgon2 = class(TCryptoLibTestCase)
+  TTestArgon2 = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
 
 

+ 13 - 23
CryptoLib.Tests/src/Crypto/BlockCipherMonteCarloTests.pas

@@ -45,15 +45,7 @@ uses
   ClpIKeyParameter,
   ClpIKeyParameter,
   ClpBufferedBlockCipher,
   ClpBufferedBlockCipher,
   ClpIBufferedBlockCipher,
   ClpIBufferedBlockCipher,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -62,7 +54,7 @@ type
   /// output string. This test wraps the engine in a buffered block cipher
   /// output string. This test wraps the engine in a buffered block cipher
   /// with padding disabled.
   /// with padding disabled.
   /// </summary>
   /// </summary>
-  TTestBlockCipherMonteCarlo = class(TCryptoLibTestCase)
+  TTestBlockCipherMonteCarlo = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     procedure DoBlockCipherMonteCarloTest(const iteration: string;
     procedure DoBlockCipherMonteCarloTest(const iteration: string;
@@ -92,8 +84,8 @@ var
   len1, len2, i, iterations: Int32;
   len1, len2, i, iterations: Int32;
   LInput, LOutput, outBytes: TBytes;
   LInput, LOutput, outBytes: TBytes;
 begin
 begin
-  LInput := THex.Decode(input);
-  LOutput := THex.Decode(output);
+  LInput := DecodeHex(input);
+  LOutput := DecodeHex(output);
   iterations := StrToInt(iteration);
   iterations := StrToInt(iteration);
 
 
   cipher := TBufferedBlockCipher.Create(engine);
   cipher := TBufferedBlockCipher.Create(engine);
@@ -115,10 +107,10 @@ begin
     System.Inc(i);
     System.Inc(i);
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(outBytes, LOutput)) then
+  if (not AreEqual(outBytes, LOutput)) then
   begin
   begin
     Fail(Format('Encryption Failed - Expected %s but got %s',
     Fail(Format('Encryption Failed - Expected %s but got %s',
-      [THex.Encode(LOutput), THex.Encode(outBytes)]));
+      [EncodeHex(LOutput), EncodeHex(outBytes)]));
   end;
   end;
 
 
   cipher.Init(false, param);
   cipher.Init(false, param);
@@ -133,10 +125,10 @@ begin
     System.Inc(i);
     System.Inc(i);
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(LInput, outBytes)) then
+  if (not AreEqual(LInput, outBytes)) then
   begin
   begin
     Fail(Format('Decryption Failed - Expected %s but got %s',
     Fail(Format('Decryption Failed - Expected %s but got %s',
-      [THex.Encode(LInput), THex.Encode(outBytes)]));
+      [EncodeHex(LInput), EncodeHex(outBytes)]));
   end;
   end;
 end;
 end;
 
 
@@ -160,9 +152,8 @@ begin
   begin
   begin
     DoBlockCipherMonteCarloTest(TAESTestVectors.FBlockCipherMonteCarloIterations
     DoBlockCipherMonteCarloTest(TAESTestVectors.FBlockCipherMonteCarloIterations
       [i], TAesEngine.Create() as IAesEngine,
       [i], TAesEngine.Create() as IAesEngine,
-      TKeyParameter.Create
-      (THex.Decode(TAESTestVectors.FBlockCipherMonteCarloKeys[i]))
-      as IKeyParameter, TAESTestVectors.FBlockCipherMonteCarloInputs[i],
+      TKeyParameter.Create(DecodeHex(TAESTestVectors.FBlockCipherMonteCarloKeys
+      [i])) as IKeyParameter, TAESTestVectors.FBlockCipherMonteCarloInputs[i],
       TAESTestVectors.FBlockCipherMonteCarloOutputs[i]);
       TAESTestVectors.FBlockCipherMonteCarloOutputs[i]);
   end;
   end;
 
 
@@ -177,9 +168,8 @@ begin
   begin
   begin
     DoBlockCipherMonteCarloTest(TAESTestVectors.FBlockCipherMonteCarloIterations
     DoBlockCipherMonteCarloTest(TAESTestVectors.FBlockCipherMonteCarloIterations
       [i], TAesLightEngine.Create() as IAesLightEngine,
       [i], TAesLightEngine.Create() as IAesLightEngine,
-      TKeyParameter.Create
-      (THex.Decode(TAESTestVectors.FBlockCipherMonteCarloKeys[i]))
-      as IKeyParameter, TAESTestVectors.FBlockCipherMonteCarloInputs[i],
+      TKeyParameter.Create(DecodeHex(TAESTestVectors.FBlockCipherMonteCarloKeys
+      [i])) as IKeyParameter, TAESTestVectors.FBlockCipherMonteCarloInputs[i],
       TAESTestVectors.FBlockCipherMonteCarloOutputs[i]);
       TAESTestVectors.FBlockCipherMonteCarloOutputs[i]);
   end;
   end;
 
 
@@ -198,7 +188,7 @@ begin
       (StrToInt(TRijndaelTestVectors.FBlockCipherMonteCarloBlockSizes[i]))
       (StrToInt(TRijndaelTestVectors.FBlockCipherMonteCarloBlockSizes[i]))
       as IRijndaelEngine,
       as IRijndaelEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TRijndaelTestVectors.FBlockCipherMonteCarloKeys[i]))
+      (DecodeHex(TRijndaelTestVectors.FBlockCipherMonteCarloKeys[i]))
       as IKeyParameter, TRijndaelTestVectors.FBlockCipherMonteCarloInputs[i],
       as IKeyParameter, TRijndaelTestVectors.FBlockCipherMonteCarloInputs[i],
       TRijndaelTestVectors.FBlockCipherMonteCarloOutputs[i]);
       TRijndaelTestVectors.FBlockCipherMonteCarloOutputs[i]);
   end;
   end;

+ 27 - 36
CryptoLib.Tests/src/Crypto/BlockCipherVectorTests.pas

@@ -55,15 +55,8 @@ uses
   ClpIParametersWithIV,
   ClpIParametersWithIV,
   ClpBufferedBlockCipher,
   ClpBufferedBlockCipher,
   ClpIBufferedBlockCipher,
   ClpIBufferedBlockCipher,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -72,7 +65,7 @@ type
   /// output string. This test wraps the engine in a buffered block cipher
   /// output string. This test wraps the engine in a buffered block cipher
   /// with padding disabled.
   /// with padding disabled.
   /// </summary>
   /// </summary>
-  TTestBlockCipherVector = class(TCryptoLibTestCase)
+  TTestBlockCipherVector = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     procedure DoBlockCipherVectorTest(const engine: IBlockCipher;
     procedure DoBlockCipherVectorTest(const engine: IBlockCipher;
@@ -113,8 +106,8 @@ var
   len1, len2: Int32;
   len1, len2: Int32;
   LInput, LOutput, outBytes: TBytes;
   LInput, LOutput, outBytes: TBytes;
 begin
 begin
-  LInput := THex.Decode(input);
-  LOutput := THex.Decode(output);
+  LInput := DecodeHex(input);
+  LOutput := DecodeHex(output);
 
 
   cipher := TBufferedBlockCipher.Create(engine);
   cipher := TBufferedBlockCipher.Create(engine);
 
 
@@ -126,10 +119,10 @@ begin
 
 
   cipher.DoFinal(outBytes, len1);
   cipher.DoFinal(outBytes, len1);
 
 
-  if (not TArrayUtils.AreEqual(outBytes, LOutput)) then
+  if (not AreEqual(outBytes, LOutput)) then
   begin
   begin
     Fail(Format('Encryption Failed - Expected %s but got %s',
     Fail(Format('Encryption Failed - Expected %s but got %s',
-      [THex.Encode(LOutput), THex.Encode(outBytes)]));
+      [EncodeHex(LOutput), EncodeHex(outBytes)]));
   end;
   end;
 
 
   cipher.Init(false, param);
   cipher.Init(false, param);
@@ -138,10 +131,10 @@ begin
 
 
   cipher.DoFinal(outBytes, len2);
   cipher.DoFinal(outBytes, len2);
 
 
-  if (not TArrayUtils.AreEqual(LInput, outBytes)) then
+  if (not AreEqual(LInput, outBytes)) then
   begin
   begin
     Fail(Format('Decryption Failed - Expected %s but got %s',
     Fail(Format('Decryption Failed - Expected %s but got %s',
-      [THex.Encode(LInput), THex.Encode(outBytes)]));
+      [EncodeHex(LInput), EncodeHex(outBytes)]));
   end;
   end;
 end;
 end;
 
 
@@ -230,8 +223,8 @@ begin
     to System.High(TAESTestVectors.FBlockCipherVectorKeys) do
     to System.High(TAESTestVectors.FBlockCipherVectorKeys) do
   begin
   begin
     DoBlockCipherVectorTest(TAesEngine.Create() as IAesEngine,
     DoBlockCipherVectorTest(TAesEngine.Create() as IAesEngine,
-      TKeyParameter.Create(THex.Decode(TAESTestVectors.FBlockCipherVectorKeys[I]
-      )) as IKeyParameter, TAESTestVectors.FBlockCipherVectorInputs[I],
+      TKeyParameter.Create(DecodeHex(TAESTestVectors.FBlockCipherVectorKeys[I]))
+      as IKeyParameter, TAESTestVectors.FBlockCipherVectorInputs[I],
       TAESTestVectors.FBlockCipherVectorOutputs[I]);
       TAESTestVectors.FBlockCipherVectorOutputs[I]);
   end;
   end;
 
 
@@ -245,8 +238,8 @@ begin
     to System.High(TAESTestVectors.FBlockCipherVectorKeys) do
     to System.High(TAESTestVectors.FBlockCipherVectorKeys) do
   begin
   begin
     DoBlockCipherVectorTest(TAesLightEngine.Create() as IAesLightEngine,
     DoBlockCipherVectorTest(TAesLightEngine.Create() as IAesLightEngine,
-      TKeyParameter.Create(THex.Decode(TAESTestVectors.FBlockCipherVectorKeys[I]
-      )) as IKeyParameter, TAESTestVectors.FBlockCipherVectorInputs[I],
+      TKeyParameter.Create(DecodeHex(TAESTestVectors.FBlockCipherVectorKeys[I]))
+      as IKeyParameter, TAESTestVectors.FBlockCipherVectorInputs[I],
       TAESTestVectors.FBlockCipherVectorOutputs[I]);
       TAESTestVectors.FBlockCipherVectorOutputs[I]);
   end;
   end;
 
 
@@ -260,9 +253,8 @@ begin
     to System.High(TBlowfishTestVectors.FBlockCipherVectorKeys) do
     to System.High(TBlowfishTestVectors.FBlockCipherVectorKeys) do
   begin
   begin
     DoBlockCipherVectorTest(TBlowfishEngine.Create() as IBlowfishEngine,
     DoBlockCipherVectorTest(TBlowfishEngine.Create() as IBlowfishEngine,
-      TKeyParameter.Create
-      (THex.Decode(TBlowfishTestVectors.FBlockCipherVectorKeys[I]))
-      as IKeyParameter, TBlowfishTestVectors.FBlockCipherVectorInputs[I],
+      TKeyParameter.Create(DecodeHex(TBlowfishTestVectors.FBlockCipherVectorKeys
+      [I])) as IKeyParameter, TBlowfishTestVectors.FBlockCipherVectorInputs[I],
       TBlowfishTestVectors.FBlockCipherVectorOutputs[I]);
       TBlowfishTestVectors.FBlockCipherVectorOutputs[I]);
   end;
   end;
 
 
@@ -279,9 +271,8 @@ begin
       (TRijndaelEngine.Create
       (TRijndaelEngine.Create
       (StrToInt(TRijndaelTestVectors.FBlockCipherVectorBlockSizes[I]))
       (StrToInt(TRijndaelTestVectors.FBlockCipherVectorBlockSizes[I]))
       as IRijndaelEngine,
       as IRijndaelEngine,
-      TKeyParameter.Create
-      (THex.Decode(TRijndaelTestVectors.FBlockCipherVectorKeys[I]))
-      as IKeyParameter, TRijndaelTestVectors.FBlockCipherVectorInputs[I],
+      TKeyParameter.Create(DecodeHex(TRijndaelTestVectors.FBlockCipherVectorKeys
+      [I])) as IKeyParameter, TRijndaelTestVectors.FBlockCipherVectorInputs[I],
       TRijndaelTestVectors.FBlockCipherVectorOutputs[I]);
       TRijndaelTestVectors.FBlockCipherVectorOutputs[I]);
   end;
   end;
 
 
@@ -296,7 +287,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck32Engine.Create() as ISpeckEngine,
     DoBlockCipherVectorTest(TSpeck32Engine.Create() as ISpeckEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck32BlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck32BlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck32BlockCipherVectorInputs[I],
       as IKeyParameter, TSpeckTestVectors.FSpeck32BlockCipherVectorInputs[I],
       TSpeckTestVectors.FSpeck32BlockCipherVectorOutputs[I]);
       TSpeckTestVectors.FSpeck32BlockCipherVectorOutputs[I]);
   end;
   end;
@@ -312,7 +303,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck48Engine.Create() as ISpeckEngine,
     DoBlockCipherVectorTest(TSpeck48Engine.Create() as ISpeckEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck48BlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck48BlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck48BlockCipherVectorInputs[I],
       as IKeyParameter, TSpeckTestVectors.FSpeck48BlockCipherVectorInputs[I],
       TSpeckTestVectors.FSpeck48BlockCipherVectorOutputs[I]);
       TSpeckTestVectors.FSpeck48BlockCipherVectorOutputs[I]);
   end;
   end;
@@ -328,7 +319,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck64Engine.Create() as ISpeckEngine,
     DoBlockCipherVectorTest(TSpeck64Engine.Create() as ISpeckEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck64BlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck64BlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck64BlockCipherVectorInputs[I],
       as IKeyParameter, TSpeckTestVectors.FSpeck64BlockCipherVectorInputs[I],
       TSpeckTestVectors.FSpeck64BlockCipherVectorOutputs[I]);
       TSpeckTestVectors.FSpeck64BlockCipherVectorOutputs[I]);
   end;
   end;
@@ -344,7 +335,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck96Engine.Create() as ISpeckEngine,
     DoBlockCipherVectorTest(TSpeck96Engine.Create() as ISpeckEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck96BlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck96BlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck96BlockCipherVectorInputs[I],
       as IKeyParameter, TSpeckTestVectors.FSpeck96BlockCipherVectorInputs[I],
       TSpeckTestVectors.FSpeck96BlockCipherVectorOutputs[I]);
       TSpeckTestVectors.FSpeck96BlockCipherVectorOutputs[I]);
   end;
   end;
@@ -360,7 +351,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck128Engine.Create() as ISpeckEngine,
     DoBlockCipherVectorTest(TSpeck128Engine.Create() as ISpeckEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck128BlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck128BlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck128BlockCipherVectorInputs[I],
       as IKeyParameter, TSpeckTestVectors.FSpeck128BlockCipherVectorInputs[I],
       TSpeckTestVectors.FSpeck128BlockCipherVectorOutputs[I]);
       TSpeckTestVectors.FSpeck128BlockCipherVectorOutputs[I]);
   end;
   end;
@@ -376,7 +367,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck32LegacyEngine.Create() as ISpeckLegacyEngine,
     DoBlockCipherVectorTest(TSpeck32LegacyEngine.Create() as ISpeckLegacyEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck32LegacyBlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck32LegacyBlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck32LegacyBlockCipherVectorInputs
       as IKeyParameter, TSpeckTestVectors.FSpeck32LegacyBlockCipherVectorInputs
       [I], TSpeckTestVectors.FSpeck32LegacyBlockCipherVectorOutputs[I]);
       [I], TSpeckTestVectors.FSpeck32LegacyBlockCipherVectorOutputs[I]);
   end;
   end;
@@ -392,7 +383,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck48LegacyEngine.Create() as ISpeckLegacyEngine,
     DoBlockCipherVectorTest(TSpeck48LegacyEngine.Create() as ISpeckLegacyEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck48LegacyBlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck48LegacyBlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck48LegacyBlockCipherVectorInputs
       as IKeyParameter, TSpeckTestVectors.FSpeck48LegacyBlockCipherVectorInputs
       [I], TSpeckTestVectors.FSpeck48LegacyBlockCipherVectorOutputs[I]);
       [I], TSpeckTestVectors.FSpeck48LegacyBlockCipherVectorOutputs[I]);
   end;
   end;
@@ -408,7 +399,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck64LegacyEngine.Create() as ISpeckLegacyEngine,
     DoBlockCipherVectorTest(TSpeck64LegacyEngine.Create() as ISpeckLegacyEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck64LegacyBlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck64LegacyBlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck64LegacyBlockCipherVectorInputs
       as IKeyParameter, TSpeckTestVectors.FSpeck64LegacyBlockCipherVectorInputs
       [I], TSpeckTestVectors.FSpeck64LegacyBlockCipherVectorOutputs[I]);
       [I], TSpeckTestVectors.FSpeck64LegacyBlockCipherVectorOutputs[I]);
   end;
   end;
@@ -424,7 +415,7 @@ begin
   begin
   begin
     DoBlockCipherVectorTest(TSpeck96LegacyEngine.Create() as ISpeckLegacyEngine,
     DoBlockCipherVectorTest(TSpeck96LegacyEngine.Create() as ISpeckLegacyEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck96LegacyBlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck96LegacyBlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck96LegacyBlockCipherVectorInputs
       as IKeyParameter, TSpeckTestVectors.FSpeck96LegacyBlockCipherVectorInputs
       [I], TSpeckTestVectors.FSpeck96LegacyBlockCipherVectorOutputs[I]);
       [I], TSpeckTestVectors.FSpeck96LegacyBlockCipherVectorOutputs[I]);
   end;
   end;
@@ -441,7 +432,7 @@ begin
     DoBlockCipherVectorTest(TSpeck128LegacyEngine.Create()
     DoBlockCipherVectorTest(TSpeck128LegacyEngine.Create()
       as ISpeckLegacyEngine,
       as ISpeckLegacyEngine,
       TKeyParameter.Create
       TKeyParameter.Create
-      (THex.Decode(TSpeckTestVectors.FSpeck128LegacyBlockCipherVectorKeys[I]))
+      (DecodeHex(TSpeckTestVectors.FSpeck128LegacyBlockCipherVectorKeys[I]))
       as IKeyParameter, TSpeckTestVectors.FSpeck128LegacyBlockCipherVectorInputs
       as IKeyParameter, TSpeckTestVectors.FSpeck128LegacyBlockCipherVectorInputs
       [I], TSpeckTestVectors.FSpeck128LegacyBlockCipherVectorOutputs[I]);
       [I], TSpeckTestVectors.FSpeck128LegacyBlockCipherVectorOutputs[I]);
   end;
   end;

+ 18 - 26
CryptoLib.Tests/src/Crypto/CTSTests.pas

@@ -54,27 +54,19 @@ uses
   // ClpIPaddedBufferedBlockCipher,
   // ClpIPaddedBufferedBlockCipher,
   // ClpPaddingModes,
   // ClpPaddingModes,
   // ClpIPaddingModes,
   // ClpIPaddingModes,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestCTS = class(TCryptoLibTestCase)
+  TTestCTS = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Faes128, FaesIn1, FaesIn2, FaesIn3, FaesOut1, FaesOut2, FaesOut3,
     Faes128, FaesIn1, FaesIn2, FaesIn3, FaesOut1, FaesOut2, FaesOut3,
-      FZeroIV: TCryptoLibByteArray;
+      FZeroIV: TBytes;
 
 
     procedure DoCTSTest(id: Int32; const cipher: IBlockCipher;
     procedure DoCTSTest(id: Int32; const cipher: IBlockCipher;
-      const params: ICipherParameters;
-      const input, output: TCryptoLibByteArray);
+      const params: ICipherParameters; const input, output: TBytes);
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -91,9 +83,9 @@ implementation
 { TTestCTS }
 { TTestCTS }
 
 
 procedure TTestCTS.DoCTSTest(id: Int32; const cipher: IBlockCipher;
 procedure TTestCTS.DoCTSTest(id: Int32; const cipher: IBlockCipher;
-  const params: ICipherParameters; const input, output: TCryptoLibByteArray);
+  const params: ICipherParameters; const input, output: TBytes);
 var
 var
-  &out: TCryptoLibByteArray;
+  &out: TBytes;
   engine: IBufferedBlockCipher;
   engine: IBufferedBlockCipher;
   len: Int32;
   len: Int32;
 begin
 begin
@@ -107,10 +99,10 @@ begin
 
 
   engine.doFinal(&out, len);
   engine.doFinal(&out, len);
 
 
-  if not(TArrayUtils.AreEqual(output, &out)) then
+  if not(AreEqual(output, &out)) then
   begin
   begin
     Fail(Format('Failed Encryption, ID %d Expected %s but got %s',
     Fail(Format('Failed Encryption, ID %d Expected %s but got %s',
-      [id, THex.Encode(output), THex.Encode(&out)]));
+      [id, EncodeHex(output), EncodeHex(&out)]));
   end;
   end;
 
 
   engine.Init(false, params);
   engine.Init(false, params);
@@ -119,10 +111,10 @@ begin
 
 
   engine.doFinal(&out, len);
   engine.doFinal(&out, len);
 
 
-  if not(TArrayUtils.AreEqual(input, &out)) then
+  if not(AreEqual(input, &out)) then
   begin
   begin
     Fail(Format('Failed Decryption, ID %d Expected %s but got %s',
     Fail(Format('Failed Decryption, ID %d Expected %s but got %s',
-      [id, THex.Encode(input), THex.Encode(&out)]));
+      [id, EncodeHex(input), EncodeHex(&out)]));
   end;
   end;
 end;
 end;
 
 
@@ -132,16 +124,16 @@ begin
   //
   //
   // test vectors from rfc3962
   // test vectors from rfc3962
   //
   //
-  Faes128 := THex.Decode('636869636B656E207465726979616B69');
-  FaesIn1 := THex.Decode('4920776F756C64206C696B652074686520');
-  FaesOut1 := THex.Decode('C6353568F2BF8CB4D8A580362DA7FF7F97');
-  FaesIn2 := THex.Decode
+  Faes128 := DecodeHex('636869636B656E207465726979616B69');
+  FaesIn1 := DecodeHex('4920776F756C64206C696B652074686520');
+  FaesOut1 := DecodeHex('C6353568F2BF8CB4D8A580362DA7FF7F97');
+  FaesIn2 := DecodeHex
     ('4920776F756C64206C696B65207468652047656E6572616C20476175277320');
     ('4920776F756C64206C696B65207468652047656E6572616C20476175277320');
-  FaesOut2 := THex.Decode
+  FaesOut2 := DecodeHex
     ('FC00783E0EFDB2C1D445D4C8EFF7ED2297687268D6ECCCC0C07B25E25ECFE5');
     ('FC00783E0EFDB2C1D445D4C8EFF7ED2297687268D6ECCCC0C07B25E25ECFE5');
-  FaesIn3 := THex.Decode
+  FaesIn3 := DecodeHex
     ('4920776F756C64206C696B65207468652047656E6572616C2047617527732043');
     ('4920776F756C64206C696B65207468652047656E6572616C2047617527732043');
-  FaesOut3 := THex.Decode
+  FaesOut3 := DecodeHex
     ('39312523A78662D5BE7FCBCC98EBF5A897687268D6ECCCC0C07B25E25ECFE584');
     ('39312523A78662D5BE7FCBCC98EBF5A897687268D6ECCCC0C07B25E25ECFE584');
   System.SetLength(FZeroIV, 16);
   System.SetLength(FZeroIV, 16);
 end;
 end;

+ 31 - 40
CryptoLib.Tests/src/Crypto/ChaChaTests.pas

@@ -38,15 +38,8 @@ uses
   ClpIKeyParameter,
   ClpIKeyParameter,
   ClpParametersWithIV,
   ClpParametersWithIV,
   ClpIParametersWithIV,
   ClpIParametersWithIV,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -59,10 +52,10 @@ type
   /// estreambench-20080905.
   /// estreambench-20080905.
   /// </para>
   /// </para>
   /// </summary>
   /// </summary>
-  TTestChaCha = class(TCryptoLibTestCase)
+  TTestChaCha = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
-    FZeroes: TCryptoLibByteArray;
+    FZeroes: TBytes;
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448, FSet1v9_0, FSet1v9_192,
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448, FSet1v9_0, FSet1v9_192,
       FSet1v9_256, FSet1v9_448, FSet6v0_0, FSet6v0_65472, FSet6v0_65536,
       FSet1v9_256, FSet1v9_448, FSet6v0_0, FSet6v0_65472, FSet6v0_65536,
       FSet6v1_0, FSet6v1_65472, FSet6v1_65536, FChaCha12_set1v0_0,
       FSet6v1_0, FSet6v1_65472, FSet6v1_65536, FChaCha12_set1v0_0,
@@ -70,8 +63,7 @@ type
       FChaCha8_set1v0_0, FChaCha8_set1v0_192, FChaCha8_set1v0_256,
       FChaCha8_set1v0_0, FChaCha8_set1v0_192, FChaCha8_set1v0_256,
       FChaCha8_set1v0_448: String;
       FChaCha8_set1v0_448: String;
 
 
-    procedure Mismatch(const name, expected: String;
-      found: TCryptoLibByteArray);
+    procedure Mismatch(const name, expected: String; found: TBytes);
     procedure DoChaChaTest1(rounds: Int32; const parameters: ICipherParameters;
     procedure DoChaChaTest1(rounds: Int32; const parameters: ICipherParameters;
       const v0, v192, v256, v448: String);
       const v0, v192, v256, v448: String);
 
 
@@ -96,7 +88,7 @@ implementation
 procedure TTestChaCha.SetUp;
 procedure TTestChaCha.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FZeroes := THex.Decode('00000000000000000000000000000000' +
+  FZeroes := DecodeHex('00000000000000000000000000000000' +
     '00000000000000000000000000000000' + '00000000000000000000000000000000' +
     '00000000000000000000000000000000' + '00000000000000000000000000000000' +
     '00000000000000000000000000000000');
     '00000000000000000000000000000000');
 
 
@@ -198,18 +190,17 @@ begin
 
 
 end;
 end;
 
 
-procedure TTestChaCha.Mismatch(const name, expected: String;
-  found: TCryptoLibByteArray);
+procedure TTestChaCha.Mismatch(const name, expected: String; found: TBytes);
 begin
 begin
   Fail(Format('Mismatch on %s, Expected %s, Found %s.',
   Fail(Format('Mismatch on %s, Expected %s, Found %s.',
-    [name, expected, THex.Encode(found)]));
+    [name, expected, EncodeHex(found)]));
 end;
 end;
 
 
 procedure TTestChaCha.DoChaChaTest1(rounds: Int32;
 procedure TTestChaCha.DoChaChaTest1(rounds: Int32;
   const parameters: ICipherParameters; const v0, v192, v256, v448: String);
   const parameters: ICipherParameters; const v0, v192, v256, v448: String);
 var
 var
   chacha: IChaChaEngine;
   chacha: IChaChaEngine;
-  buf: TCryptoLibByteArray;
+  buf: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   chacha := TChaChaEngine.Create(rounds);
   chacha := TChaChaEngine.Create(rounds);
@@ -222,21 +213,21 @@ begin
     case i of
     case i of
       0:
       0:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v0))) then
+          if not(AreEqual(buf, DecodeHex(v0))) then
           begin
           begin
             Mismatch(Format('v0/%d', [rounds]), v0, buf);
             Mismatch(Format('v0/%d', [rounds]), v0, buf);
           end;
           end;
         end;
         end;
       3:
       3:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v192))) then
+          if not(AreEqual(buf, DecodeHex(v192))) then
           begin
           begin
             Mismatch(Format('v192/%d', [rounds]), v192, buf);
             Mismatch(Format('v192/%d', [rounds]), v192, buf);
           end;
           end;
         end;
         end;
       4:
       4:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v256))) then
+          if not(AreEqual(buf, DecodeHex(v256))) then
           begin
           begin
             Mismatch(Format('v256/%d', [rounds]), v256, buf);
             Mismatch(Format('v256/%d', [rounds]), v256, buf);
           end;
           end;
@@ -256,7 +247,7 @@ begin
     System.Inc(i);
     System.Inc(i);
   end;
   end;
 
 
-  if not(TArrayUtils.AreEqual(buf, THex.Decode(v448))) then
+  if not(AreEqual(buf, DecodeHex(v448))) then
   begin
   begin
     Mismatch(Format('v448/%d', [rounds]), v448, buf);
     Mismatch(Format('v448/%d', [rounds]), v448, buf);
   end;
   end;
@@ -266,7 +257,7 @@ procedure TTestChaCha.DoChaChaTest2(const parameters: ICipherParameters;
   const v0, v65472, v65536: String);
   const v0, v65472, v65536: String);
 var
 var
   chacha: IChaChaEngine;
   chacha: IChaChaEngine;
-  buf: TCryptoLibByteArray;
+  buf: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   chacha := TChaChaEngine.Create();
   chacha := TChaChaEngine.Create();
@@ -279,21 +270,21 @@ begin
     case i of
     case i of
       0:
       0:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v0))) then
+          if not(AreEqual(buf, DecodeHex(v0))) then
           begin
           begin
             Mismatch('v0', v0, buf);
             Mismatch('v0', v0, buf);
           end;
           end;
         end;
         end;
       1023:
       1023:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v65472))) then
+          if not(AreEqual(buf, DecodeHex(v65472))) then
           begin
           begin
             Mismatch('v65472', v65472, buf);
             Mismatch('v65472', v65472, buf);
           end;
           end;
         end;
         end;
       1024:
       1024:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v65536))) then
+          if not(AreEqual(buf, DecodeHex(v65536))) then
           begin
           begin
             Mismatch('v65536', v65536, buf);
             Mismatch('v65536', v65536, buf);
           end;
           end;
@@ -311,21 +302,21 @@ end;
 procedure TTestChaCha.TestDoChaChaTest1;
 procedure TTestChaCha.TestDoChaChaTest1;
 begin
 begin
   DoChaChaTest1(20, TParametersWithIV.Create
   DoChaChaTest1(20, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')) as IParametersWithIV,
+    (TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')) as IParametersWithIV,
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448);
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448);
   DoChaChaTest1(20, TParametersWithIV.Create
   DoChaChaTest1(20, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('00400000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')) as IParametersWithIV,
+    (TKeyParameter.Create(DecodeHex('00400000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')) as IParametersWithIV,
     FSet1v9_0, FSet1v9_192, FSet1v9_256, FSet1v9_448);
     FSet1v9_0, FSet1v9_192, FSet1v9_256, FSet1v9_448);
 
 
   DoChaChaTest1(12, TParametersWithIV.Create
   DoChaChaTest1(12, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')), FChaCha12_set1v0_0,
+    (TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')), FChaCha12_set1v0_0,
     FChaCha12_set1v0_192, FChaCha12_set1v0_256, FChaCha12_set1v0_448);
     FChaCha12_set1v0_192, FChaCha12_set1v0_256, FChaCha12_set1v0_448);
   DoChaChaTest1(8, TParametersWithIV.Create
   DoChaChaTest1(8, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')) as IParametersWithIV,
+    (TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')) as IParametersWithIV,
     FChaCha8_set1v0_0, FChaCha8_set1v0_192, FChaCha8_set1v0_256,
     FChaCha8_set1v0_0, FChaCha8_set1v0_192, FChaCha8_set1v0_256,
     FChaCha8_set1v0_448);
     FChaCha8_set1v0_448);
 
 
@@ -334,14 +325,14 @@ end;
 procedure TTestChaCha.TestDoChaChaTest2;
 procedure TTestChaCha.TestDoChaChaTest2;
 begin
 begin
   DoChaChaTest2(TParametersWithIV.Create(TKeyParameter.Create
   DoChaChaTest2(TParametersWithIV.Create(TKeyParameter.Create
-    (THex.Decode
+    (DecodeHex
     ('0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D'))
     ('0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D'))
-    as IKeyParameter, THex.Decode('0D74DB42A91077DE')) as IParametersWithIV,
+    as IKeyParameter, DecodeHex('0D74DB42A91077DE')) as IParametersWithIV,
     FSet6v0_0, FSet6v0_65472, FSet6v0_65536);
     FSet6v0_0, FSet6v0_65472, FSet6v0_65536);
   DoChaChaTest2(TParametersWithIV.Create(TKeyParameter.Create
   DoChaChaTest2(TParametersWithIV.Create(TKeyParameter.Create
-    (THex.Decode
+    (DecodeHex
     ('0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12'))
     ('0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12'))
-    as IKeyParameter, THex.Decode('167DE44BB21980E7')) as IParametersWithIV,
+    as IKeyParameter, DecodeHex('167DE44BB21980E7')) as IParametersWithIV,
     FSet6v1_0, FSet6v1_65472, FSet6v1_65536);
     FSet6v1_0, FSet6v1_65472, FSet6v1_65536);
 end;
 end;
 
 
@@ -351,8 +342,8 @@ var
   parameters: IParametersWithIV;
   parameters: IParametersWithIV;
   chacha: IChaChaEngine;
   chacha: IChaChaEngine;
 begin
 begin
-  key := TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'));
-  parameters := TParametersWithIV.Create(key, THex.Decode('0000000000000000'));
+  key := TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'));
+  parameters := TParametersWithIV.Create(key, DecodeHex('0000000000000000'));
 
 
   chacha := TChaChaEngine.Create();
   chacha := TChaChaEngine.Create();
 
 

+ 3 - 8
CryptoLib.Tests/src/Crypto/DHTests.pas

@@ -53,16 +53,11 @@ uses
   ClpDHKeyGenerationParameters,
   ClpDHKeyGenerationParameters,
   ClpIAsymmetricCipherKeyPair,
   ClpIAsymmetricCipherKeyPair,
   ClpBigInteger,
   ClpBigInteger,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-  TTestDH = class(TCryptoLibTestCase)
+  TTestDH = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
   var
   var

+ 95 - 94
CryptoLib.Tests/src/Crypto/DSATests.pas

@@ -72,9 +72,7 @@ uses
   ClpX9ObjectIdentifiers,
   ClpX9ObjectIdentifiers,
   ClpECKeyGenerationParameters,
   ClpECKeyGenerationParameters,
   ClpIECKeyGenerationParameters,
   ClpIECKeyGenerationParameters,
-  ClpEncoders,
   ClpBigInteger,
   ClpBigInteger,
-  ClpArrayUtils,
   ClpAsn1Objects,
   ClpAsn1Objects,
   ClpDSADigestSigner,
   ClpDSADigestSigner,
   ClpIDSADigestSigner,
   ClpIDSADigestSigner,
@@ -83,7 +81,8 @@ uses
   ClpFixedSecureRandom,
   ClpFixedSecureRandom,
   ClpIFixedSecureRandom,
   ClpIFixedSecureRandom,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
   IDSATestSecureRandom = interface(IFixedSecureRandom)
   IDSATestSecureRandom = interface(IFixedSecureRandom)
@@ -97,15 +96,9 @@ type
     Ffirst: Boolean;
     Ffirst: Boolean;
 
 
   public
   public
-    constructor Create(const value: TCryptoLibByteArray);
+    constructor Create(const value: TBytes);
 
 
-    procedure NextBytes(const bytes: TCryptoLibByteArray); override;
-
-  end;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
+    procedure NextBytes(const bytes: TBytes); override;
 
 
   end;
   end;
 
 
@@ -114,7 +107,7 @@ type
   /// <summary>
   /// <summary>
   /// Test based on FIPS 186-2, Appendix 5, an example of DSA, and FIPS 168-3 test vectors.
   /// Test based on FIPS 186-2, Appendix 5, an example of DSA, and FIPS 168-3 test vectors.
   /// </summary>
   /// </summary>
-  TTestDSA = class(TCryptoLibTestCase)
+  TTestDSA = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
 
 
@@ -128,12 +121,12 @@ type
 
 
     procedure DoCheckMessage(const sgr: ISigner;
     procedure DoCheckMessage(const sgr: ISigner;
       const sKey: IECPrivateKeyParameters; const vKey: IECPublicKeyParameters;
       const sKey: IECPrivateKeyParameters; const vKey: IECPublicKeyParameters;
-      const &message, sig: TCryptoLibByteArray);
+      const &message, sig: TBytes);
 
 
     procedure DoTestKeyGeneration(keysize: Int32);
     procedure DoTestKeyGeneration(keysize: Int32);
     procedure DoTestBadStrength(strength: Int32);
     procedure DoTestBadStrength(strength: Int32);
 
 
-    function DoDerDecode(const encoding: TCryptoLibByteArray)
+    function DoDerDecode(const encoding: TBytes)
       : TCryptoLibGenericArray<TBigInteger>;
       : TCryptoLibGenericArray<TBigInteger>;
 
 
   protected
   protected
@@ -183,9 +176,9 @@ implementation
 
 
 procedure TTestDSA.DoCheckMessage(const sgr: ISigner;
 procedure TTestDSA.DoCheckMessage(const sgr: ISigner;
   const sKey: IECPrivateKeyParameters; const vKey: IECPublicKeyParameters;
   const sKey: IECPrivateKeyParameters; const vKey: IECPublicKeyParameters;
-  const &message, sig: TCryptoLibByteArray);
+  const &message, sig: TBytes);
 var
 var
-  kData, sigBytes: TCryptoLibByteArray;
+  kData, sigBytes: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
 begin
 begin
 
 
@@ -202,7 +195,7 @@ begin
 
 
   sigBytes := sgr.GenerateSignature();
   sigBytes := sgr.GenerateSignature();
 
 
-  if (not TArrayUtils.AreEqual(sigBytes, sig)) then
+  if (not AreEqual(sigBytes, sig)) then
   begin
   begin
     Fail(Format('%s %s', [TConverters.ConvertBytesToString(&message,
     Fail(Format('%s %s', [TConverters.ConvertBytesToString(&message,
       TEncoding.UTF8), 'signature incorrect']));
       TEncoding.UTF8), 'signature incorrect']));
@@ -219,7 +212,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TTestDSA.DoDerDecode(const encoding: TCryptoLibByteArray)
+function TTestDSA.DoDerDecode(const encoding: TBytes)
   : TCryptoLibGenericArray<TBigInteger>;
   : TCryptoLibGenericArray<TBigInteger>;
 var
 var
   s: IAsn1Sequence;
   s: IAsn1Sequence;
@@ -253,7 +246,7 @@ end;
 
 
 procedure TTestDSA.DoDSA2Test1;
 procedure TTestDSA.DoDSA2Test1;
 var
 var
-  seed, msg: TCryptoLibByteArray;
+  seed, msg: TBytes;
   pGen: IDsaParametersGenerator;
   pGen: IDsaParametersGenerator;
   params: IDSAParameters;
   params: IDSAParameters;
   pv: IDSAValidationParameters;
   pv: IDSAValidationParameters;
@@ -264,7 +257,7 @@ var
   signer: IDSASigner;
   signer: IDSASigner;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
-  seed := THex.Decode('ED8BEE8D1CB89229D2903CBF0E51EE7377F48698');
+  seed := DecodeHex('ED8BEE8D1CB89229D2903CBF0E51EE7377F48698');
 
 
   pGen := TDsaParametersGenerator.Create();
   pGen := TDsaParametersGenerator.Create();
 
 
@@ -280,7 +273,7 @@ begin
     Fail('counter incorrect');
     Fail('counter incorrect');
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(seed, pv.seed)) then
+  if (not AreEqual(seed, pv.seed)) then
   begin
   begin
     Fail('seed incorrect');
     Fail('seed incorrect');
   end;
   end;
@@ -346,10 +339,10 @@ begin
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     ('349C55648DCF992F3F33E8026CFAC87C1D2BA075'),
     ('349C55648DCF992F3F33E8026CFAC87C1D2BA075'),
-    TFixedSecureRandom.TData.Create(THex.Decode('01020304')))))
+    TFixedSecureRandom.TData.Create(DecodeHex('01020304')))))
     as IParametersWithRandom);
     as IParametersWithRandom);
 
 
-  msg := THex.Decode('A9993E364706816ABA3E25717850C26C9CD0D89D');
+  msg := DecodeHex('A9993E364706816ABA3E25717850C26C9CD0D89D');
 
 
   sig := signer.GenerateSignature(msg);
   sig := signer.GenerateSignature(msg);
 
 
@@ -375,7 +368,7 @@ end;
 
 
 procedure TTestDSA.DoDSA2Test2;
 procedure TTestDSA.DoDSA2Test2;
 var
 var
-  seed, msg: TCryptoLibByteArray;
+  seed, msg: TBytes;
   pGen: IDsaParametersGenerator;
   pGen: IDsaParametersGenerator;
   params: IDSAParameters;
   params: IDSAParameters;
   pv: IDSAValidationParameters;
   pv: IDSAValidationParameters;
@@ -386,8 +379,7 @@ var
   signer: IDSASigner;
   signer: IDSASigner;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
-  seed := THex.Decode
-    ('5AFCC1EFFC079A9CCA6ECA86D6E3CC3B18642D9BE1CC6207C84002A9');
+  seed := DecodeHex('5AFCC1EFFC079A9CCA6ECA86D6E3CC3B18642D9BE1CC6207C84002A9');
 
 
   pGen := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-224'));
   pGen := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-224'));
 
 
@@ -403,7 +395,7 @@ begin
     Fail('counter incorrect');
     Fail('counter incorrect');
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(seed, pv.seed)) then
+  if (not AreEqual(seed, pv.seed)) then
   begin
   begin
     Fail('seed incorrect');
     Fail('seed incorrect');
   end;
   end;
@@ -448,7 +440,7 @@ begin
 
 
   kpGen.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.Create
   kpGen.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
-    (THex.Decode('00D0F09ED3E2568F6CADF9224117DA2AEC5A4300E009DE1366023E17')))),
+    (DecodeHex('00D0F09ED3E2568F6CADF9224117DA2AEC5A4300E009DE1366023E17')))),
     params) as IDSAKeyGenerationParameters);
     params) as IDSAKeyGenerationParameters);
 
 
   kp := kpGen.GenerateKeyPair();
   kp := kpGen.GenerateKeyPair();
@@ -483,11 +475,10 @@ begin
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     ('735959CC4463B8B440E407EECA8A473BF6A6D1FE657546F67D401F05'),
     ('735959CC4463B8B440E407EECA8A473BF6A6D1FE657546F67D401F05'),
-    TFixedSecureRandom.TData.Create(THex.Decode('01020304')))))
+    TFixedSecureRandom.TData.Create(DecodeHex('01020304')))))
     as IParametersWithRandom);
     as IParametersWithRandom);
 
 
-  msg := THex.Decode
-    ('23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7');
+  msg := DecodeHex('23097D223405D8228642A477BDA255B32AADBCE4BDA0B3F7E36C9DA7');
 
 
   sig := signer.GenerateSignature(msg);
   sig := signer.GenerateSignature(msg);
 
 
@@ -513,7 +504,7 @@ end;
 
 
 procedure TTestDSA.DoDSA2Test3;
 procedure TTestDSA.DoDSA2Test3;
 var
 var
-  seed, msg: TCryptoLibByteArray;
+  seed, msg: TBytes;
   pGen: IDsaParametersGenerator;
   pGen: IDsaParametersGenerator;
   params: IDSAParameters;
   params: IDSAParameters;
   pv: IDSAValidationParameters;
   pv: IDSAValidationParameters;
@@ -524,7 +515,7 @@ var
   signer: IDSASigner;
   signer: IDSASigner;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
-  seed := THex.Decode
+  seed := DecodeHex
     ('4783081972865EA95D43318AB2EAF9C61A2FC7BBF1B772A09017BDF5A58F4FF0');
     ('4783081972865EA95D43318AB2EAF9C61A2FC7BBF1B772A09017BDF5A58F4FF0');
 
 
   pGen := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-256'));
   pGen := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-256'));
@@ -541,7 +532,7 @@ begin
     Fail('counter incorrect');
     Fail('counter incorrect');
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(seed, pv.seed)) then
+  if (not AreEqual(seed, pv.seed)) then
   begin
   begin
     Fail('seed incorrect');
     Fail('seed incorrect');
   end;
   end;
@@ -587,7 +578,7 @@ begin
 
 
   kpGen.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.Create
   kpGen.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
-    (THex.Decode
+    (DecodeHex
     ('0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C')))),
     ('0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C')))),
     params) as IDSAKeyGenerationParameters);
     params) as IDSAKeyGenerationParameters);
 
 
@@ -624,10 +615,10 @@ begin
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     ('0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C'),
     ('0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C'),
-    TFixedSecureRandom.TData.Create(THex.Decode('01020304')))))
+    TFixedSecureRandom.TData.Create(DecodeHex('01020304')))))
     as IParametersWithRandom);
     as IParametersWithRandom);
 
 
-  msg := THex.Decode
+  msg := DecodeHex
     ('BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD');
     ('BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD');
 
 
   sig := signer.GenerateSignature(msg);
   sig := signer.GenerateSignature(msg);
@@ -656,7 +647,7 @@ end;
 
 
 procedure TTestDSA.DoDSA2Test4;
 procedure TTestDSA.DoDSA2Test4;
 var
 var
-  seed, msg: TCryptoLibByteArray;
+  seed, msg: TBytes;
   pGen: IDsaParametersGenerator;
   pGen: IDsaParametersGenerator;
   params: IDSAParameters;
   params: IDSAParameters;
   pv: IDSAValidationParameters;
   pv: IDSAValidationParameters;
@@ -667,7 +658,7 @@ var
   signer: IDSASigner;
   signer: IDSASigner;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
-  seed := THex.Decode
+  seed := DecodeHex
     ('193AFCA7C1E77B3C1ECC618C81322E47B8B8B997C9C83515C59CC446C2D9BD47');
     ('193AFCA7C1E77B3C1ECC618C81322E47B8B8B997C9C83515C59CC446C2D9BD47');
 
 
   pGen := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-256'));
   pGen := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-256'));
@@ -684,7 +675,7 @@ begin
     Fail('counter incorrect');
     Fail('counter incorrect');
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(seed, pv.seed)) then
+  if (not AreEqual(seed, pv.seed)) then
   begin
   begin
     Fail('seed incorrect');
     Fail('seed incorrect');
   end;
   end;
@@ -742,7 +733,7 @@ begin
 
 
   kpGen.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.Create
   kpGen.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
-    (THex.Decode
+    (DecodeHex
     ('3ABC1587297CE7B9EA1AD6651CF2BC4D7F92ED25CABC8553F567D1B40EBB8764')))
     ('3ABC1587297CE7B9EA1AD6651CF2BC4D7F92ED25CABC8553F567D1B40EBB8764')))
     ), params));
     ), params));
 
 
@@ -785,10 +776,10 @@ begin
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     (TFixedSecureRandom.TBigIntegerSource.Create
     ('A6902C1E6E3943C5628061588A8B007BCCEA91DBF12915483F04B24AB0678BEE'),
     ('A6902C1E6E3943C5628061588A8B007BCCEA91DBF12915483F04B24AB0678BEE'),
-    TFixedSecureRandom.TData.Create(THex.Decode('01020304')))))
+    TFixedSecureRandom.TData.Create(DecodeHex('01020304')))))
     as IParametersWithRandom);
     as IParametersWithRandom);
 
 
-  msg := THex.Decode
+  msg := DecodeHex
     ('BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD');
     ('BA7816BF8F01CFEA414140DE5DAE2223B00361A396177A9CB410FF61F20015AD');
 
 
   sig := signer.GenerateSignature(msg);
   sig := signer.GenerateSignature(msg);
@@ -822,7 +813,7 @@ var
   priKey: IDSAPrivateKeyParameters;
   priKey: IDSAPrivateKeyParameters;
   pubKey: IDSAPublicKeyParameters;
   pubKey: IDSAPublicKeyParameters;
   k: ISecureRandom;
   k: ISecureRandom;
-  M, encSig: TCryptoLibByteArray;
+  M, encSig: TBytes;
   dsa: IDSADigestSigner;
   dsa: IDSADigestSigner;
   RS: TCryptoLibGenericArray<TBigInteger>;
   RS: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
@@ -873,9 +864,9 @@ begin
     (TFixedSecureRandom.TBigIntegerSource.Create(TBigInteger.Create
     (TFixedSecureRandom.TBigIntegerSource.Create(TBigInteger.Create
     ('72546832179840998877302529996971396893172522460793442785601695562409154906335')
     ('72546832179840998877302529996971396893172522460793442785601695562409154906335')
     .ToByteArrayUnsigned), TFixedSecureRandom.TData.Create
     .ToByteArrayUnsigned), TFixedSecureRandom.TData.Create
-    (THex.Decode('01020304'))));
+    (DecodeHex('01020304'))));
 
 
-  M := THex.Decode
+  M := DecodeHex
     ('1BD4ED430B0F384B4E8D458EFF1A8A553286D7AC21CB2F6806172EF5F94A06AD');
     ('1BD4ED430B0F384B4E8D458EFF1A8A553286D7AC21CB2F6806172EF5F94A06AD');
 
 
   dsa := TDSADigestSigner.Create(TDSASigner.Create() as IDSASigner,
   dsa := TDSADigestSigner.Create(TDSASigner.Create() as IDSASigner,
@@ -921,7 +912,7 @@ end;
 procedure TTestDSA.DoTestECDsa239BitBinary(const algorithm: String;
 procedure TTestDSA.DoTestECDsa239BitBinary(const algorithm: String;
   const oid: IDerObjectIdentifier);
   const oid: IDerObjectIdentifier);
 var
 var
-  kData, &message, sigBytes: TCryptoLibByteArray;
+  kData, &message, sigBytes: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IECCurve;
   curve: IECCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
@@ -946,9 +937,10 @@ begin
     TBigInteger.Four);
     TBigInteger.Four);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
-    ), // G
+    curve.DecodePoint
+    (DecodeHex
+    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')),
+    // G
     TBigInteger.Create
     TBigInteger.Create
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     // n
     // n
@@ -961,9 +953,10 @@ begin
     parameters);
     parameters);
 
 
   vKey := TECPublicKeyParameters.Create('ECDSA',
   vKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
-    ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
-    ), // Q
+    curve.DecodePoint
+    (DecodeHex
+    ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')),
+    // Q
     parameters);
     parameters);
 
 
   sgr := TSignerUtilities.GetSigner(algorithm);
   sgr := TSignerUtilities.GetSigner(algorithm);
@@ -1142,7 +1135,7 @@ end;
 
 
 procedure TTestDSA.TestDSA;
 procedure TTestDSA.TestDSA;
 var
 var
-  k1, k2, keyData, &message: TCryptoLibByteArray;
+  k1, k2, keyData, &message: TBytes;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
   random, keyRandom: ISecureRandom;
   random, keyRandom: ISecureRandom;
   pValue, qValue, r, s: TBigInteger;
   pValue, qValue, r, s: TBigInteger;
@@ -1155,19 +1148,19 @@ var
   param: IParametersWithRandom;
   param: IParametersWithRandom;
   dsa: IDSASigner;
   dsa: IDSASigner;
 begin
 begin
-  k1 := THex.Decode('d5014e4b60ef2ba8b6211b4062ba3224e0427dd3');
-  k2 := THex.Decode
+  k1 := DecodeHex('d5014e4b60ef2ba8b6211b4062ba3224e0427dd3');
+  k2 := DecodeHex
     ('345e8d05c075c3a508df729a1685690e68fcfb8c8117847e89063bca1f85d968fd281540b6e13bd1af989a1fbf17e06462bf511f9d0b140fb48ac1b1baa5bded');
     ('345e8d05c075c3a508df729a1685690e68fcfb8c8117847e89063bca1f85d968fd281540b6e13bd1af989a1fbf17e06462bf511f9d0b140fb48ac1b1baa5bded');
 
 
   random := TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
   random := TFixedSecureRandom.Create(TCryptoLibGenericArray<ISource>.Create
     (TFixedSecureRandom.TData.Create(k1), TFixedSecureRandom.TData.Create(k2)));
     (TFixedSecureRandom.TData.Create(k1), TFixedSecureRandom.TData.Create(k2)));
 
 
-  keyData := THex.Decode('b5014e4b60ef2ba8b6211b4062ba3224e0427dd3');
+  keyData := DecodeHex('b5014e4b60ef2ba8b6211b4062ba3224e0427dd3');
 
 
   keyRandom := TFixedSecureRandom.Create
   keyRandom := TFixedSecureRandom.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
     (TCryptoLibGenericArray<ISource>.Create(TFixedSecureRandom.TData.Create
     (keyData), TFixedSecureRandom.TData.Create(keyData),
     (keyData), TFixedSecureRandom.TData.Create(keyData),
-    TFixedSecureRandom.TData.Create(THex.Decode('01020304'))));
+    TFixedSecureRandom.TData.Create(DecodeHex('01020304'))));
 
 
   pValue := TBigInteger.Create
   pValue := TBigInteger.Create
     ('8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291',
     ('8df2a494492276aa3d25759bb06869cbeac0d83afb8d0cf7cbb8324f0d7882e5d0762fc5b7210eafc2e9adac32ab7aac49693dfbf83724c2ec0736ee31c80291',
@@ -1250,7 +1243,7 @@ end;
 
 
 procedure TTestDSA.TestDsa2Parameters;
 procedure TTestDSA.TestDsa2Parameters;
 var
 var
-  seed, encodeParams, encodeParams_2, data, sigBytes: TCryptoLibByteArray;
+  seed, encodeParams, encodeParams_2, data, sigBytes: TBytes;
   a: IDsaParametersGenerator;
   a: IDsaParametersGenerator;
   dsaP: IDSAParameters;
   dsaP: IDSAParameters;
   G: IAsymmetricCipherKeyPairGenerator;
   G: IAsymmetricCipherKeyPairGenerator;
@@ -1260,7 +1253,7 @@ var
   p2: IDSAParameters;
   p2: IDSAParameters;
   s: ISigner;
   s: ISigner;
 begin
 begin
-  seed := THex.Decode
+  seed := DecodeHex
     ('4783081972865EA95D43318AB2EAF9C61A2FC7BBF1B772A09017BDF5A58F4FF0');
     ('4783081972865EA95D43318AB2EAF9C61A2FC7BBF1B772A09017BDF5A58F4FF0');
 
 
   a := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-256'));
   a := TDsaParametersGenerator.Create(TDigestUtilities.GetDigest('SHA-256'));
@@ -1310,7 +1303,7 @@ begin
   G := TGeneratorUtilities.GetKeyPairGenerator('DSA');
   G := TGeneratorUtilities.GetKeyPairGenerator('DSA');
 
 
   G.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.From
   G.Init(TDSAKeyGenerationParameters.Create(TFixedSecureRandom.From
-    (TCryptoLibMatrixByteArray.Create(THex.Decode
+    (TCryptoLibMatrixByteArray.Create(DecodeHex
     ('0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C'))),
     ('0CAF2EF547EC49C4F3A6FE6DF4223A174D01F2C115D49A6F73437C29A2A8458C'))),
     dsaP) as IDSAKeyGenerationParameters);
     dsaP) as IDSAKeyGenerationParameters);
 
 
@@ -1347,13 +1340,13 @@ begin
 
 
   encodeParams_2 := TDsaParameter.Create(p2.p, p2.Q, p2.G).GetDerEncoded();
   encodeParams_2 := TDsaParameter.Create(p2.p, p2.Q, p2.G).GetDerEncoded();
 
 
-  if (not TArrayUtils.AreEqual(encodeParams, encodeParams_2)) then
+  if (not AreEqual(encodeParams, encodeParams_2)) then
   begin
   begin
     Fail('encode/decode parameters failed');
     Fail('encode/decode parameters failed');
   end;
   end;
 
 
   s := TSignerUtilities.GetSigner('DSA');
   s := TSignerUtilities.GetSigner('DSA');
-  data := TCryptoLibByteArray.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
+  data := TBytes.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
 
 
   s.Init(true, sKey);
   s.Init(true, sKey);
 
 
@@ -1376,7 +1369,7 @@ end;
 procedure TTestDSA.TestECDsa239BitPrime;
 procedure TTestDSA.TestECDsa239BitPrime;
 var
 var
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData, &message, sigBytes: TCryptoLibByteArray;
+  kData, &message, sigBytes: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IECCurve;
   curve: IECCurve;
   spec: IECDomainParameters;
   spec: IECDomainParameters;
@@ -1411,7 +1404,8 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   spec := TECDomainParameters.Create(curve,
   spec := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     TBigInteger.Create
     TBigInteger.Create
     ('883423532389192164791648750360308884807550341691627752275345424702807307')
     ('883423532389192164791648750360308884807550341691627752275345424702807307')
@@ -1424,7 +1418,8 @@ begin
     spec);
     spec);
 
 
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     spec);
     spec);
 
 
@@ -1470,7 +1465,7 @@ end;
 procedure TTestDSA.TestGeneration;
 procedure TTestDSA.TestGeneration;
 var
 var
   s: ISigner;
   s: ISigner;
-  data, sigBytes: TCryptoLibByteArray;
+  data, sigBytes: TBytes;
   rand: ISecureRandom;
   rand: ISecureRandom;
   G: IAsymmetricCipherKeyPairGenerator;
   G: IAsymmetricCipherKeyPairGenerator;
   pGen: IDsaParametersGenerator;
   pGen: IDsaParametersGenerator;
@@ -1488,7 +1483,7 @@ begin
   DoTestBadStrength(1025);
   DoTestBadStrength(1025);
 
 
   s := TSignerUtilities.GetSigner('DSA');
   s := TSignerUtilities.GetSigner('DSA');
-  data := TCryptoLibByteArray.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
+  data := TBytes.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
   rand := TSecureRandom.Create();
   rand := TSecureRandom.Create();
 
 
   G := TGeneratorUtilities.GetKeyPairGenerator('DSA');
   G := TGeneratorUtilities.GetKeyPairGenerator('DSA');
@@ -1539,7 +1534,8 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   ecSpec := TECDomainParameters.Create(curve,
   ecSpec := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     TBigInteger.Create
     TBigInteger.Create
     ('883423532389192164791648750360308884807550341691627752275345424702807307')
     ('883423532389192164791648750360308884807550341691627752275345424702807307')
@@ -1587,9 +1583,10 @@ begin
     TBigInteger.Four);
     TBigInteger.Four);
 
 
   ecSpec := TECDomainParameters.Create(curve,
   ecSpec := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
-    ), // G
+    curve.DecodePoint
+    (DecodeHex
+    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')),
+    // G
     TBigInteger.Create
     TBigInteger.Create
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     // n
     // n
@@ -1632,7 +1629,7 @@ end;
 procedure TTestDSA.TestECDsa239BitBinary;
 procedure TTestDSA.TestECDsa239BitBinary;
 var
 var
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData, &message, sigBytes: TCryptoLibByteArray;
+  kData, &message, sigBytes: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IECCurve;
   curve: IECCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
@@ -1664,9 +1661,10 @@ begin
     TBigInteger.Four);
     TBigInteger.Four);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
-    ), // G
+    curve.DecodePoint
+    (DecodeHex
+    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')),
+    // G
     TBigInteger.Create
     TBigInteger.Create
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     // n
     // n
@@ -1679,9 +1677,10 @@ begin
     parameters);
     parameters);
 
 
   vKey := TECPublicKeyParameters.Create('ECDSA',
   vKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
-    ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
-    ), // Q
+    curve.DecodePoint
+    (DecodeHex
+    ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')),
+    // Q
     parameters);
     parameters);
 
 
   sgr := TSignerUtilities.GetSigner('ECDSA');
   sgr := TSignerUtilities.GetSigner('ECDSA');
@@ -1758,7 +1757,7 @@ end;
 
 
 procedure TTestDSA.TestNONEwithDSA;
 procedure TTestDSA.TestNONEwithDSA;
 var
 var
-  dummySha1, sigBytes: TCryptoLibByteArray;
+  dummySha1, sigBytes: TBytes;
   rand: ISecureRandom;
   rand: ISecureRandom;
   pGen: IDsaParametersGenerator;
   pGen: IDsaParametersGenerator;
   G: IAsymmetricCipherKeyPairGenerator;
   G: IAsymmetricCipherKeyPairGenerator;
@@ -1767,7 +1766,7 @@ var
   signer: IDSASigner;
   signer: IDSASigner;
   RS: TCryptoLibGenericArray<TBigInteger>;
   RS: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
-  dummySha1 := THex.Decode('01020304050607080910111213141516');
+  dummySha1 := DecodeHex('01020304050607080910111213141516');
 
 
   rand := TSecureRandom.Create();
   rand := TSecureRandom.Create();
 
 
@@ -1811,7 +1810,7 @@ end;
 
 
 procedure TTestDSA.TestNONEwithECDSA239bitPrime;
 procedure TTestDSA.TestNONEwithECDSA239bitPrime;
 var
 var
-  &message, sig: TCryptoLibByteArray;
+  &message, sig: TBytes;
   curve: IECCurve;
   curve: IECCurve;
   spec: IECDomainParameters;
   spec: IECDomainParameters;
   priKey: IECPrivateKeyParameters;
   priKey: IECPrivateKeyParameters;
@@ -1832,7 +1831,8 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   spec := TECDomainParameters.Create(curve,
   spec := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     TBigInteger.Create
     TBigInteger.Create
     ('883423532389192164791648750360308884807550341691627752275345424702807307')
     ('883423532389192164791648750360308884807550341691627752275345424702807307')
@@ -1845,21 +1845,22 @@ begin
     spec);
     spec);
 
 
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     spec);
     spec);
 
 
   sgr := TSignerUtilities.GetSigner('NONEwithECDSA');
   sgr := TSignerUtilities.GetSigner('NONEwithECDSA');
 
 
   &message := TConverters.ConvertStringToBytes('abc', TEncoding.UTF8);
   &message := TConverters.ConvertStringToBytes('abc', TEncoding.UTF8);
-  sig := THex.Decode
+  sig := DecodeHex
     ('3040021e2cb7f36803ebb9c427c58d8265f11fc5084747133078fc279de874fbecb0021e64cb19604be06c57e761b3de5518f71de0f6e0cd2df677cec8a6ffcb690d');
     ('3040021e2cb7f36803ebb9c427c58d8265f11fc5084747133078fc279de874fbecb0021e64cb19604be06c57e761b3de5518f71de0f6e0cd2df677cec8a6ffcb690d');
 
 
   DoCheckMessage(sgr, priKey, pubKey, &message, sig);
   DoCheckMessage(sgr, priKey, pubKey, &message, sig);
 
 
   &message := TConverters.ConvertStringToBytes('abcdefghijklmnopqrstuvwxyz',
   &message := TConverters.ConvertStringToBytes('abcdefghijklmnopqrstuvwxyz',
     TEncoding.UTF8);
     TEncoding.UTF8);
-  sig := THex.Decode
+  sig := DecodeHex
     ('3040021e2cb7f36803ebb9c427c58d8265f11fc5084747133078fc279de874fbecb0021e43fd65b3363d76aabef8630572257dbb67c82818ad9fad31256539b1b02c');
     ('3040021e2cb7f36803ebb9c427c58d8265f11fc5084747133078fc279de874fbecb0021e43fd65b3363d76aabef8630572257dbb67c82818ad9fad31256539b1b02c');
 
 
   DoCheckMessage(sgr, priKey, pubKey, &message, sig);
   DoCheckMessage(sgr, priKey, pubKey, &message, sig);
@@ -1867,7 +1868,7 @@ begin
   &message := TConverters.ConvertStringToBytes
   &message := TConverters.ConvertStringToBytes
     ('a very very long message gauranteed to cause an overflow',
     ('a very very long message gauranteed to cause an overflow',
     TEncoding.UTF8);
     TEncoding.UTF8);
-  sig := THex.Decode
+  sig := DecodeHex
     ('3040021e2cb7f36803ebb9c427c58d8265f11fc5084747133078fc279de874fbecb0021e7d5be84b22937a1691859a3c6fe45ed30b108574431d01b34025825ec17a');
     ('3040021e2cb7f36803ebb9c427c58d8265f11fc5084747133078fc279de874fbecb0021e7d5be84b22937a1691859a3c6fe45ed30b108574431d01b34025825ec17a');
 
 
   DoCheckMessage(sgr, priKey, pubKey, &message, sig);
   DoCheckMessage(sgr, priKey, pubKey, &message, sig);
@@ -1879,7 +1880,7 @@ var
   random: ISecureRandom;
   random: ISecureRandom;
   a: IDsaParametersGenerator;
   a: IDsaParametersGenerator;
   p: IDSAParameters;
   p: IDSAParameters;
-  encodeParams, encodeParams_2, data, sigBytes: TCryptoLibByteArray;
+  encodeParams, encodeParams_2, data, sigBytes: TBytes;
   dsaP: IDsaParameter;
   dsaP: IDsaParameter;
   p2: IDSAParameters;
   p2: IDSAParameters;
   G: IAsymmetricCipherKeyPairGenerator;
   G: IAsymmetricCipherKeyPairGenerator;
@@ -1889,9 +1890,9 @@ var
 begin
 begin
   random := TFixedSecureRandom.From
   random := TFixedSecureRandom.From
     (TCryptoLibMatrixByteArray.Create
     (TCryptoLibMatrixByteArray.Create
-    (THex.Decode('d5014e4b60ef2ba8b6211b4062ba3224e0427dd3'),
-    THex.Decode
-    ('345e8d05c075c3a508df729a1685690e68fcfb8c8117847e89063bca1f85d968fd281540b6e13bd1af989a1fbf17e06462bf511f9d0b140fb48ac1b1baa5bded'))
+    (DecodeHex('d5014e4b60ef2ba8b6211b4062ba3224e0427dd3'),
+    DecodeHex(
+    '345e8d05c075c3a508df729a1685690e68fcfb8c8117847e89063bca1f85d968fd281540b6e13bd1af989a1fbf17e06462bf511f9d0b140fb48ac1b1baa5bded'))
     );
     );
 
 
   a := TDsaParametersGenerator.Create();
   a := TDsaParametersGenerator.Create();
@@ -1908,7 +1909,7 @@ begin
   // a and a2 should be equivalent!
   // a and a2 should be equivalent!
   encodeParams_2 := TDsaParameter.Create(p2.p, p2.Q, p2.G).GetDerEncoded();
   encodeParams_2 := TDsaParameter.Create(p2.p, p2.Q, p2.G).GetDerEncoded();
 
 
-  if (not TArrayUtils.AreEqual(encodeParams, encodeParams_2)) then
+  if (not AreEqual(encodeParams, encodeParams_2)) then
   begin
   begin
     Fail('encode/Decode parameters failed');
     Fail('encode/Decode parameters failed');
   end;
   end;
@@ -1946,13 +1947,13 @@ end;
 
 
 { TDSATestSecureRandom }
 { TDSATestSecureRandom }
 
 
-constructor TDSATestSecureRandom.Create(const value: TCryptoLibByteArray);
+constructor TDSATestSecureRandom.Create(const value: TBytes);
 begin
 begin
   Inherited Create(System.Copy(value));
   Inherited Create(System.Copy(value));
   Ffirst := true;
   Ffirst := true;
 end;
 end;
 
 
-procedure TDSATestSecureRandom.NextBytes(const bytes: TCryptoLibByteArray);
+procedure TDSATestSecureRandom.NextBytes(const bytes: TBytes);
 begin
 begin
   if (Ffirst) then
   if (Ffirst) then
   begin
   begin

+ 10 - 16
CryptoLib.Tests/src/Crypto/DeterministicDsaTests.pas

@@ -52,14 +52,8 @@ uses
   ClpBigInteger,
   ClpBigInteger,
   ClpDigestUtilities,
   ClpDigestUtilities,
   ClpSecNamedCurves,
   ClpSecNamedCurves,
-  ClpEncoders,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -68,11 +62,11 @@ type
   /// Signature Algorithm (DSA) and Elliptic Curve Digital Signature
   /// Signature Algorithm (DSA) and Elliptic Curve Digital Signature
   /// Algorithm (ECDSA)".
   /// Algorithm (ECDSA)".
   /// </summary>
   /// </summary>
-  TTestDeterministicDsa = class(TCryptoLibTestCase)
+  TTestDeterministicDsa = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
   var
   var
-    FSAMPLE, FTEST: TCryptoLibByteArray;
+    FSAMPLE, FTEST: TBytes;
 
 
     // test vectors from appendix in RFC 6979
     // test vectors from appendix in RFC 6979
     procedure DoTestHMacDeterministic;
     procedure DoTestHMacDeterministic;
@@ -91,7 +85,7 @@ type
       const privKey: IECPrivateKeyParameters; const r, s: TBigInteger);
       const privKey: IECPrivateKeyParameters; const r, s: TBigInteger);
 
 
     procedure DoTestHMacDetECDsa(const detSigner: IDsa; const digest: IDigest;
     procedure DoTestHMacDetECDsa(const detSigner: IDsa; const digest: IDigest;
-      const data: TCryptoLibByteArray; const privKey: ICipherParameters;
+      const data: TBytes; const privKey: ICipherParameters;
       const r, s: TBigInteger);
       const r, s: TBigInteger);
 
 
   protected
   protected
@@ -221,10 +215,10 @@ begin
 end;
 end;
 
 
 procedure TTestDeterministicDsa.DoTestHMacDetECDsa(const detSigner: IDsa;
 procedure TTestDeterministicDsa.DoTestHMacDetECDsa(const detSigner: IDsa;
-  const digest: IDigest; const data: TCryptoLibByteArray;
-  const privKey: ICipherParameters; const r, s: TBigInteger);
+  const digest: IDigest; const data: TBytes; const privKey: ICipherParameters;
+  const r, s: TBigInteger);
 var
 var
-  m: TCryptoLibByteArray;
+  m: TBytes;
   rs: TCryptoLibGenericArray<TBigInteger>;
   rs: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
   System.SetLength(m, digest.GetDigestSize());
   System.SetLength(m, digest.GetDigestSize());
@@ -399,8 +393,8 @@ end;
 procedure TTestDeterministicDsa.SetUp;
 procedure TTestDeterministicDsa.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FSAMPLE := THex.Decode('73616d706c65'); // "sample"
-  FTEST := THex.Decode('74657374'); // "test"
+  FSAMPLE := DecodeHex('73616d706c65'); // "sample"
+  FTEST := DecodeHex('74657374'); // "test"
 end;
 end;
 
 
 procedure TTestDeterministicDsa.TearDown;
 procedure TTestDeterministicDsa.TearDown;

+ 22 - 28
CryptoLib.Tests/src/Crypto/DigestRandomNumberTests.pas

@@ -36,19 +36,12 @@ uses
   ClpDigestRandomGenerator,
   ClpDigestRandomGenerator,
   ClpIDigestRandomGenerator,
   ClpIDigestRandomGenerator,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestDigestRandomNumber = class(TCryptoLibTestCase)
+  TTestDigestRandomNumber = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -163,13 +156,13 @@ begin
 
 
   if (noCycle <> Nil) then
   if (noCycle <> Nil) then
   begin
   begin
-    if (TArrayUtils.AreEqual(noCycle, output)) then
+    if (AreEqual(noCycle, output)) then
     begin
     begin
       Fail('seed not being cycled!');
       Fail('seed not being cycled!');
     end;
     end;
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(expected, output)) then
+  if (not AreEqual(expected, output)) then
   begin
   begin
     Fail('expected output doesn''t match');
     Fail('expected output doesn''t match');
   end;
   end;
@@ -195,7 +188,7 @@ begin
     System.Inc(i);
     System.Inc(i);
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(expected, output)) then
+  if (not AreEqual(expected, output)) then
   begin
   begin
     Fail('expected output doesn''t match');
     Fail('expected output doesn''t match');
   end;
   end;
@@ -205,26 +198,27 @@ procedure TTestDigestRandomNumber.SetUp;
 begin
 begin
   FZERO_SEED := TBytes.Create(0, 0, 0, 0, 0, 0, 0, 0);
   FZERO_SEED := TBytes.Create(0, 0, 0, 0, 0, 0, 0, 0);
 
 
-  FTEST_SEED := THex.Decode('81dcfafc885914057876');
+  FTEST_SEED := DecodeHex('81dcfafc885914057876');
 
 
-  Fexpected0SHA1 := THex.Decode('95bca677b3d4ff793213c00892d2356ec729ee02');
-  FnoCycle0SHA1 := THex.Decode('d57ccd0eb12c3938d59226412bc1268037b6b846');
+  Fexpected0SHA1 := DecodeHex('95bca677b3d4ff793213c00892d2356ec729ee02');
+  FnoCycle0SHA1 := DecodeHex('d57ccd0eb12c3938d59226412bc1268037b6b846');
   Fexpected0SHA256 :=
   Fexpected0SHA256 :=
-    THex.Decode
-    ('587e2dfd597d086e47ddcd343eac983a5c913bef8c6a1a560a5c1bc3a74b0991');
-  FnoCycle0SHA256 := THex.Decode
-    ('e5776c4483486ba7be081f4e1b9dafbab25c8fae290fd5474c1ceda2c16f9509');
-  Fexpected100SHA1 := THex.Decode('b9d924092546e0876cafd4937d7364ebf9efa4be');
+    DecodeHex(
+    '587e2dfd597d086e47ddcd343eac983a5c913bef8c6a1a560a5c1bc3a74b0991');
+  FnoCycle0SHA256 :=
+    DecodeHex(
+    'e5776c4483486ba7be081f4e1b9dafbab25c8fae290fd5474c1ceda2c16f9509');
+  Fexpected100SHA1 := DecodeHex('b9d924092546e0876cafd4937d7364ebf9efa4be');
   Fexpected100SHA256 :=
   Fexpected100SHA256 :=
-    THex.Decode
-    ('fbc4aa54b948b99de104c44563a552899d718bb75d1941cc62a2444b0506abaf');
-  FexpectedTestSHA1 := THex.Decode('e9ecef9f5306daf1ac51a89a211a64cb24415649');
+    DecodeHex(
+    'fbc4aa54b948b99de104c44563a552899d718bb75d1941cc62a2444b0506abaf');
+  FexpectedTestSHA1 := DecodeHex('e9ecef9f5306daf1ac51a89a211a64cb24415649');
   FexpectedTestSHA256 :=
   FexpectedTestSHA256 :=
-    THex.Decode
-    ('bdab3ca831b472a2fa09bd1bade541ef16c96640a91fcec553679a136061de98');
+    DecodeHex(
+    'bdab3ca831b472a2fa09bd1bade541ef16c96640a91fcec553679a136061de98');
 
 
-  Fsha1Xors := THex.Decode('7edcc1216934f3891b03ffa65821611a3e2b1f79');
-  Fsha256Xors := THex.Decode
+  Fsha1Xors := DecodeHex('7edcc1216934f3891b03ffa65821611a3e2b1f79');
+  Fsha256Xors := DecodeHex
     ('5ec48189cc0aa71e79c707bc3c33ffd47bbba368a83d6cfebf3cd3969d7f3eed');
     ('5ec48189cc0aa71e79c707bc3c33ffd47bbba368a83d6cfebf3cd3969d7f3eed');
 end;
 end;
 
 

+ 56 - 57
CryptoLib.Tests/src/Crypto/HMacTests.pas

@@ -41,23 +41,15 @@ uses
   ClpIanaObjectIdentifiers,
   ClpIanaObjectIdentifiers,
   ClpNistObjectIdentifiers,
   ClpNistObjectIdentifiers,
   ClpRosstandartObjectIdentifiers,
   ClpRosstandartObjectIdentifiers,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// HMAC tester
   /// HMAC tester
   /// </summary>
   /// </summary>
-  TTestHMac = class(TCryptoLibTestCase)
+  TTestHMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FkeyBytes, Fmessage, Foutput1, FoutputMD5, FoutputMD2, FoutputMD4,
     FkeyBytes, Fmessage, Foutput1, FoutputMD5, FoutputMD2, FoutputMD4,
@@ -117,10 +109,10 @@ begin
   mac.BlockUpdate(Fmessage, 0, System.Length(Fmessage));
   mac.BlockUpdate(Fmessage, 0, System.Length(Fmessage));
   outBytes := TMacUtilities.DoFinal(mac);
   outBytes := TMacUtilities.DoFinal(mac);
 
 
-  if (not TArrayUtils.AreEqual(outBytes, output)) then
+  if (not AreEqual(outBytes, output)) then
   begin
   begin
-    Fail('Failed - expected ' + THex.Encode(output) + ' got ' +
-      THex.Encode(outBytes));
+    Fail('Failed - expected ' + EncodeHex(output) + ' got ' +
+      EncodeHex(outBytes));
   end;
   end;
 
 
   kGen := TGeneratorUtilities.GetKeyGenerator(hmacName);
   kGen := TGeneratorUtilities.GetKeyGenerator(hmacName);
@@ -146,10 +138,10 @@ begin
   mac.BlockUpdate(Fmessage, 0, System.Length(Fmessage));
   mac.BlockUpdate(Fmessage, 0, System.Length(Fmessage));
   outBytes := TMacUtilities.DoFinal(mac);
   outBytes := TMacUtilities.DoFinal(mac);
 
 
-  if (not TArrayUtils.AreEqual(outBytes, output)) then
+  if (not AreEqual(outBytes, output)) then
   begin
   begin
-    Fail('Failed - expected ' + THex.Encode(output) + ' got ' +
-      THex.Encode(outBytes));
+    Fail('Failed - expected ' + EncodeHex(output) + ' got ' +
+      EncodeHex(outBytes));
   end;
   end;
 
 
   kGen := TGeneratorUtilities.GetKeyGenerator(hmacName);
   kGen := TGeneratorUtilities.GetKeyGenerator(hmacName);
@@ -165,55 +157,62 @@ end;
 procedure TTestHMac.SetUp;
 procedure TTestHMac.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FkeyBytes := THex.Decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
+  FkeyBytes := DecodeHex('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
   Fmessage := TConverters.ConvertStringToBytes('Hi There', TEncoding.ASCII);
   Fmessage := TConverters.ConvertStringToBytes('Hi There', TEncoding.ASCII);
-  Foutput1 := THex.Decode('b617318655057264e28bc0b6fb378c8ef146be00');
-  FoutputMD5 := THex.Decode('5ccec34ea9656392457fa1ac27f08fbc');
-  FoutputMD2 := THex.Decode('dc1923ef5f161d35bef839ca8c807808');
-  FoutputMD4 := THex.Decode('5570ce964ba8c11756cdc3970278ff5a');
-  Foutput224 := THex.Decode
+  Foutput1 := DecodeHex('b617318655057264e28bc0b6fb378c8ef146be00');
+  FoutputMD5 := DecodeHex('5ccec34ea9656392457fa1ac27f08fbc');
+  FoutputMD2 := DecodeHex('dc1923ef5f161d35bef839ca8c807808');
+  FoutputMD4 := DecodeHex('5570ce964ba8c11756cdc3970278ff5a');
+  Foutput224 := DecodeHex
     ('896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22');
     ('896fb1128abbdf196832107cd49df33f47b4b1169912ba4f53684b22');
-  Foutput256 := THex.Decode
+  Foutput256 := DecodeHex
     ('b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7');
     ('b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7');
-  Foutput384 := THex.Decode
+  Foutput384 := DecodeHex
     ('afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6');
     ('afd03944d84895626b0825f4ab46907f15f9dadbe4101ec682aa034c7cebc59cfaea9ea9076ede7f4af152e8b2fa9cb6');
-  Foutput512 := THex.Decode
+  Foutput512 := DecodeHex
     ('87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854');
     ('87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854');
-  Foutput512_224 := THex.Decode
-    ('b244ba01307c0e7a8ccaad13b1067a4cf6b961fe0c6a20bda3d92039');
-  Foutput512_256 := THex.Decode
-    ('9f9126c3d9c3c330d760425ca8a217e31feae31bfe70196ff81642b868402eab');
-  FoutputRipeMD128 := THex.Decode('fda5717fb7e20cf05d30bb286a44b05d');
-  FoutputRipeMD160 := THex.Decode('24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668');
-  FoutputTiger := THex.Decode
-    ('1d7a658c75f8f004916e7b07e2a2e10aec7de2ae124d3647');
-
-  FoutputKck224 := THex.Decode
-    ('b73d595a2ba9af815e9f2b4e53e78581ebd34a80b3bbaac4e702c4cc');
-  FoutputKck256 := THex.Decode
-    ('9663d10c73ee294054dc9faf95647cb99731d12210ff7075fb3d3395abfb9821');
-  FoutputKck288 := THex.Decode
-    ('36145df8742160a1811139494d708f9a12757c30dedc622a98aa6ecb69da32a34ea55441');
-  FoutputKck384 := THex.Decode
-    ('892dfdf5d51e4679bf320cd16d4c9dc6f749744608e003add7fba894acff87361efa4e5799be06b6461f43b60ae97048');
-  FoutputKck512 := THex.Decode
-    ('8852c63be8cfc21541a4ee5e5a9a852fc2f7a9adec2ff3a13718ab4ed81aaea0b87b7eb397323548e261a64e7fc75198f6663a11b22cd957f7c8ec858a1c7755');
-
-  FoutputSha3_224 := THex.Decode
-    ('3b16546bbc7be2706a031dcafd56373d9884367641d8c59af3c860f7');
-  FoutputSha3_256 := THex.Decode
-    ('ba85192310dffa96e2a3a40e69774351140bb7185e1202cdcc917589f95e16bb');
-  FoutputSha3_384 := THex.Decode
-    ('68d2dcf7fd4ddd0a2240c8a437305f61fb7334cfb5d0226e1bc27dc10a2e723a20d370b47743130e26ac7e3d532886bd');
-  FoutputSha3_512 := THex.Decode
-    ('eb3fbd4b2eaab8f5c504bd3a41465aacec15770a7cabac531e482f860b5ec7ba47ccb2c6f2afce8f88d22b6dc61380f23a668fd3888bb80537c0a0b86407689e');
+  Foutput512_224 :=
+    DecodeHex('b244ba01307c0e7a8ccaad13b1067a4cf6b961fe0c6a20bda3d92039');
+  Foutput512_256 :=
+    DecodeHex(
+    '9f9126c3d9c3c330d760425ca8a217e31feae31bfe70196ff81642b868402eab');
+  FoutputRipeMD128 := DecodeHex('fda5717fb7e20cf05d30bb286a44b05d');
+  FoutputRipeMD160 := DecodeHex('24cb4bd67d20fc1a5d2ed7732dcc39377f0a5668');
+  FoutputTiger := DecodeHex('1d7a658c75f8f004916e7b07e2a2e10aec7de2ae124d3647');
+
+  FoutputKck224 :=
+    DecodeHex('b73d595a2ba9af815e9f2b4e53e78581ebd34a80b3bbaac4e702c4cc');
+  FoutputKck256 :=
+    DecodeHex(
+    '9663d10c73ee294054dc9faf95647cb99731d12210ff7075fb3d3395abfb9821');
+  FoutputKck288 :=
+    DecodeHex(
+    '36145df8742160a1811139494d708f9a12757c30dedc622a98aa6ecb69da32a34ea55441');
+  FoutputKck384 :=
+    DecodeHex(
+    '892dfdf5d51e4679bf320cd16d4c9dc6f749744608e003add7fba894acff87361efa4e5799be06b6461f43b60ae97048');
+  FoutputKck512 :=
+    DecodeHex(
+    '8852c63be8cfc21541a4ee5e5a9a852fc2f7a9adec2ff3a13718ab4ed81aaea0b87b7eb397323548e261a64e7fc75198f6663a11b22cd957f7c8ec858a1c7755');
+
+  FoutputSha3_224 :=
+    DecodeHex('3b16546bbc7be2706a031dcafd56373d9884367641d8c59af3c860f7');
+  FoutputSha3_256 :=
+    DecodeHex(
+    'ba85192310dffa96e2a3a40e69774351140bb7185e1202cdcc917589f95e16bb');
+  FoutputSha3_384 :=
+    DecodeHex(
+    '68d2dcf7fd4ddd0a2240c8a437305f61fb7334cfb5d0226e1bc27dc10a2e723a20d370b47743130e26ac7e3d532886bd');
+  FoutputSha3_512 :=
+    DecodeHex(
+    'eb3fbd4b2eaab8f5c504bd3a41465aacec15770a7cabac531e482f860b5ec7ba47ccb2c6f2afce8f88d22b6dc61380f23a668fd3888bb80537c0a0b86407689e');
 
 
   FoutputGost2012_256 :=
   FoutputGost2012_256 :=
-    THex.Decode
-    ('f03422dfa37a507ca126ce01b8eba6b7fdda8f8a60dd8f2703e3a372120b8294');
+    DecodeHex(
+    'f03422dfa37a507ca126ce01b8eba6b7fdda8f8a60dd8f2703e3a372120b8294');
   FoutputGost2012_512 :=
   FoutputGost2012_512 :=
-    THex.Decode
-    ('86b6a06bfa9f1974aff6ccd7fa3f835f0bd850395d6084efc47b9dda861a2cdf0dcaf959160733d5269f6567966dd7a9f932a77cd6f080012cd476f1c2cc31bb');
+    DecodeHex(
+    '86b6a06bfa9f1974aff6ccd7fa3f835f0bd850395d6084efc47b9dda861a2cdf0dcaf959160733d5269f6567966dd7a9f932a77cd6f080012cd476f1c2cc31bb');
 
 
 end;
 end;
 
 

+ 30 - 39
CryptoLib.Tests/src/Crypto/HkdfGeneratorTests.pas

@@ -31,32 +31,23 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpEncoders,
   ClpIDigest,
   ClpIDigest,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpArrayUtils,
   ClpHkdfParameters,
   ClpHkdfParameters,
   ClpIHkdfParameters,
   ClpIHkdfParameters,
   ClpHkdfBytesGenerator,
   ClpHkdfBytesGenerator,
   ClpIHkdfBytesGenerator,
   ClpIHkdfBytesGenerator,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// HKDF tests - vectors from RFC 5869, + 2 more, 101 and 102
   /// HKDF tests - vectors from RFC 5869, + 2 more, 101 and 102
   /// </summary>
   /// </summary>
-  TTestHkdfGenerator = class(TCryptoLibTestCase)
+  TTestHkdfGenerator = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
-    procedure CompareOkm(test: Int32;
-      const calculatedOkm, testOkm: TCryptoLibByteArray);
+    procedure CompareOkm(test: Int32; const calculatedOkm, testOkm: TBytes);
     procedure DoTestHKDF();
     procedure DoTestHKDF();
 
 
   protected
   protected
@@ -73,9 +64,9 @@ implementation
 { TTestHkdfGenerator }
 { TTestHkdfGenerator }
 
 
 procedure TTestHkdfGenerator.CompareOkm(test: Int32;
 procedure TTestHkdfGenerator.CompareOkm(test: Int32;
-  const calculatedOkm, testOkm: TCryptoLibByteArray);
+  const calculatedOkm, testOkm: TBytes);
 begin
 begin
-  if (not TArrayUtils.AreEqual(calculatedOkm, testOkm)) then
+  if (not AreEqual(calculatedOkm, testOkm)) then
   begin
   begin
     Fail('HKDF failed generator test ' + IntToStr(test));
     Fail('HKDF failed generator test ' + IntToStr(test));
   end;
   end;
@@ -92,9 +83,9 @@ begin
   // === A.1. Test Case 1 - Basic test case with SHA-256 ===
   // === A.1. Test Case 1 - Basic test case with SHA-256 ===
 
 
   hash := TDigestUtilities.GetDigest('SHA-256');
   hash := TDigestUtilities.GetDigest('SHA-256');
-  ikm := THex.Decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
-  salt := THex.Decode('000102030405060708090a0b0c');
-  info := THex.Decode('f0f1f2f3f4f5f6f7f8f9');
+  ikm := DecodeHex('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
+  salt := DecodeHex('000102030405060708090a0b0c');
+  info := DecodeHex('f0f1f2f3f4f5f6f7f8f9');
   l := 42;
   l := 42;
   System.SetLength(okm, l);
   System.SetLength(okm, l);
 
 
@@ -104,7 +95,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(1, okm, THex.Decode('3cb25f25faacd57a90434f64d0362f2a' +
+  CompareOkm(1, okm, DecodeHex('3cb25f25faacd57a90434f64d0362f2a' +
     '2d2d0a90cf1a5a4c5db02d56ecc4c5bf' + '34007208d5b887185865'));
     '2d2d0a90cf1a5a4c5db02d56ecc4c5bf' + '34007208d5b887185865'));
 
 
 
 
@@ -112,13 +103,13 @@ begin
   // ===
   // ===
 
 
   hash := TDigestUtilities.GetDigest('SHA-256');
   hash := TDigestUtilities.GetDigest('SHA-256');
-  ikm := THex.Decode('000102030405060708090a0b0c0d0e0f' +
+  ikm := DecodeHex('000102030405060708090a0b0c0d0e0f' +
     '101112131415161718191a1b1c1d1e1f' + '202122232425262728292a2b2c2d2e2f' +
     '101112131415161718191a1b1c1d1e1f' + '202122232425262728292a2b2c2d2e2f' +
     '303132333435363738393a3b3c3d3e3f' + '404142434445464748494a4b4c4d4e4f');
     '303132333435363738393a3b3c3d3e3f' + '404142434445464748494a4b4c4d4e4f');
-  salt := THex.Decode('606162636465666768696a6b6c6d6e6f' +
+  salt := DecodeHex('606162636465666768696a6b6c6d6e6f' +
     '707172737475767778797a7b7c7d7e7f' + '808182838485868788898a8b8c8d8e8f' +
     '707172737475767778797a7b7c7d7e7f' + '808182838485868788898a8b8c8d8e8f' +
     '909192939495969798999a9b9c9d9e9f' + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf');
     '909192939495969798999a9b9c9d9e9f' + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf');
-  info := THex.Decode('b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' +
+  info := DecodeHex('b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' +
     'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' +
     'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' +
     'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff');
     'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff');
   l := 82;
   l := 82;
@@ -130,7 +121,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(2, okm, THex.Decode('b11e398dc80327a1c8e7f78c596a4934' +
+  CompareOkm(2, okm, DecodeHex('b11e398dc80327a1c8e7f78c596a4934' +
     '4f012eda2d4efad8a050cc4c19afa97c' + '59045a99cac7827271cb41c65e590e09' +
     '4f012eda2d4efad8a050cc4c19afa97c' + '59045a99cac7827271cb41c65e590e09' +
     'da3275600c2f09b8367793a9aca3db71' + 'cc30c58179ec3e87c14c01d5c1f3434f'
     'da3275600c2f09b8367793a9aca3db71' + 'cc30c58179ec3e87c14c01d5c1f3434f'
     + '1d87'));
     + '1d87'));
@@ -146,7 +137,7 @@ begin
   // structure
   // structure
 
 
   hash := TDigestUtilities.GetDigest('SHA-256');
   hash := TDigestUtilities.GetDigest('SHA-256');
-  ikm := THex.Decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
+  ikm := DecodeHex('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
   System.SetLength(salt, 0);
   System.SetLength(salt, 0);
   info := Nil;
   info := Nil;
   l := 42;
   l := 42;
@@ -158,7 +149,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(3, okm, THex.Decode('8da4e775a563c18f715f802a063c5a31' +
+  CompareOkm(3, okm, DecodeHex('8da4e775a563c18f715f802a063c5a31' +
     'b8a11f5c5ee1879ec3454e5f3c738d2d' + '9d201395faa4b61a96c8'));
     'b8a11f5c5ee1879ec3454e5f3c738d2d' + '9d201395faa4b61a96c8'));
 
 
 
 
@@ -166,9 +157,9 @@ begin
   // === A.4. Test Case 4 - Basic test case with SHA-1 ===
   // === A.4. Test Case 4 - Basic test case with SHA-1 ===
 
 
   hash := TDigestUtilities.GetDigest('SHA-1');
   hash := TDigestUtilities.GetDigest('SHA-1');
-  ikm := THex.Decode('0b0b0b0b0b0b0b0b0b0b0b');
-  salt := THex.Decode('000102030405060708090a0b0c');
-  info := THex.Decode('f0f1f2f3f4f5f6f7f8f9');
+  ikm := DecodeHex('0b0b0b0b0b0b0b0b0b0b0b');
+  salt := DecodeHex('000102030405060708090a0b0c');
+  info := DecodeHex('f0f1f2f3f4f5f6f7f8f9');
   l := 42;
   l := 42;
   System.SetLength(okm, l);
   System.SetLength(okm, l);
 
 
@@ -178,20 +169,20 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(4, okm, THex.Decode('085a01ea1b10f36933068b56efa5ad81' +
+  CompareOkm(4, okm, DecodeHex('085a01ea1b10f36933068b56efa5ad81' +
     'a4f14b822f5b091568a9cdd4f155fda2' + 'c22e422478d305f3f896'));
     'a4f14b822f5b091568a9cdd4f155fda2' + 'c22e422478d305f3f896'));
 
 
 
 
   // === A.5. Test Case 5 - Test with SHA-1 and longer inputs/outputs ===
   // === A.5. Test Case 5 - Test with SHA-1 and longer inputs/outputs ===
 
 
   hash := TDigestUtilities.GetDigest('SHA-1');
   hash := TDigestUtilities.GetDigest('SHA-1');
-  ikm := THex.Decode('000102030405060708090a0b0c0d0e0f' +
+  ikm := DecodeHex('000102030405060708090a0b0c0d0e0f' +
     '101112131415161718191a1b1c1d1e1f' + '202122232425262728292a2b2c2d2e2f' +
     '101112131415161718191a1b1c1d1e1f' + '202122232425262728292a2b2c2d2e2f' +
     '303132333435363738393a3b3c3d3e3f' + '404142434445464748494a4b4c4d4e4f');
     '303132333435363738393a3b3c3d3e3f' + '404142434445464748494a4b4c4d4e4f');
-  salt := THex.Decode('606162636465666768696a6b6c6d6e6f' +
+  salt := DecodeHex('606162636465666768696a6b6c6d6e6f' +
     '707172737475767778797a7b7c7d7e7f' + '808182838485868788898a8b8c8d8e8f' +
     '707172737475767778797a7b7c7d7e7f' + '808182838485868788898a8b8c8d8e8f' +
     '909192939495969798999a9b9c9d9e9f' + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf');
     '909192939495969798999a9b9c9d9e9f' + 'a0a1a2a3a4a5a6a7a8a9aaabacadaeaf');
-  info := THex.Decode('b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' +
+  info := DecodeHex('b0b1b2b3b4b5b6b7b8b9babbbcbdbebf' +
     'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' +
     'c0c1c2c3c4c5c6c7c8c9cacbcccdcecf' + 'd0d1d2d3d4d5d6d7d8d9dadbdcdddedf' +
     'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff');
     'e0e1e2e3e4e5e6e7e8e9eaebecedeeef' + 'f0f1f2f3f4f5f6f7f8f9fafbfcfdfeff');
   l := 82;
   l := 82;
@@ -203,7 +194,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(5, okm, THex.Decode('0bd770a74d1160f7c9f12cd5912a06eb' +
+  CompareOkm(5, okm, DecodeHex('0bd770a74d1160f7c9f12cd5912a06eb' +
     'ff6adcae899d92191fe4305673ba2ffe' + '8fa3f1a4e5ad79f3f334b3b202b2173c' +
     'ff6adcae899d92191fe4305673ba2ffe' + '8fa3f1a4e5ad79f3f334b3b202b2173c' +
     '486ea37ce3d397ed034c7f9dfeb15c5e' + '927336d0441f4c4300e2cff0d0900b52'
     '486ea37ce3d397ed034c7f9dfeb15c5e' + '927336d0441f4c4300e2cff0d0900b52'
     + 'd3b4'));
     + 'd3b4'));
@@ -217,7 +208,7 @@ begin
   // valued bytes
   // valued bytes
 
 
   hash := TDigestUtilities.GetDigest('SHA-1');
   hash := TDigestUtilities.GetDigest('SHA-1');
-  ikm := THex.Decode('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
+  ikm := DecodeHex('0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b');
   salt := Nil;
   salt := Nil;
   System.SetLength(info, 0);
   System.SetLength(info, 0);
   l := 42;
   l := 42;
@@ -229,7 +220,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(6, okm, THex.Decode('0ac1af7002b3d761d1e55298da9d0506' +
+  CompareOkm(6, okm, DecodeHex('0ac1af7002b3d761d1e55298da9d0506' +
     'b9ae52057220a306e07b6b87e8df21d0' + 'ea00033de03984d34918'));
     'b9ae52057220a306e07b6b87e8df21d0' + 'ea00033de03984d34918'));
 
 
 
 
@@ -241,7 +232,7 @@ begin
   // this test is identical to test 6 in all ways bar the IKM value
   // this test is identical to test 6 in all ways bar the IKM value
 
 
   hash := TDigestUtilities.GetDigest('SHA-1');
   hash := TDigestUtilities.GetDigest('SHA-1');
-  ikm := THex.Decode('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c');
+  ikm := DecodeHex('0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c');
   salt := Nil;
   salt := Nil;
   System.SetLength(info, 0);
   System.SetLength(info, 0);
   l := 42;
   l := 42;
@@ -253,7 +244,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(7, okm, THex.Decode('2c91117204d745f3500d636a62f64f0a' +
+  CompareOkm(7, okm, DecodeHex('2c91117204d745f3500d636a62f64f0a' +
     'b3bae548aa53d423b0d1f27ebba6f5e5' + '673a081d70cce7acfc48'));
     'b3bae548aa53d423b0d1f27ebba6f5e5' + '673a081d70cce7acfc48'));
 
 
 
 
@@ -266,7 +257,7 @@ begin
   // which is set to the PRK value
   // which is set to the PRK value
 
 
   hash := TDigestUtilities.GetDigest('SHA-1');
   hash := TDigestUtilities.GetDigest('SHA-1');
-  ikm := THex.Decode('2adccada18779e7c2077ad2eb19d3f3e731385dd');
+  ikm := DecodeHex('2adccada18779e7c2077ad2eb19d3f3e731385dd');
   System.SetLength(info, 0);
   System.SetLength(info, 0);
   l := 42;
   l := 42;
   System.SetLength(okm, l);
   System.SetLength(okm, l);
@@ -277,7 +268,7 @@ begin
   hkdf.Init(parameters);
   hkdf.Init(parameters);
   hkdf.GenerateBytes(okm, 0, l);
   hkdf.GenerateBytes(okm, 0, l);
 
 
-  CompareOkm(101, okm, THex.Decode('2c91117204d745f3500d636a62f64f0a' +
+  CompareOkm(101, okm, DecodeHex('2c91117204d745f3500d636a62f64f0a' +
     'b3bae548aa53d423b0d1f27ebba6f5e5' + '673a081d70cce7acfc48'));
     'b3bae548aa53d423b0d1f27ebba6f5e5' + '673a081d70cce7acfc48'));
 
 
   // === A.102. Additional Test Case - Test with SHA-1, maximum output ===
   // === A.102. Additional Test Case - Test with SHA-1, maximum output ===
@@ -286,7 +277,7 @@ begin
   // this test is identical to test 7 in all ways bar the IKM value
   // this test is identical to test 7 in all ways bar the IKM value
 
 
   hash := TDigestUtilities.GetDigest('SHA-1');
   hash := TDigestUtilities.GetDigest('SHA-1');
-  ikm := THex.Decode('2adccada18779e7c2077ad2eb19d3f3e731385dd');
+  ikm := DecodeHex('2adccada18779e7c2077ad2eb19d3f3e731385dd');
   System.SetLength(info, 0);
   System.SetLength(info, 0);
   l := 255 * hash.GetDigestSize();
   l := 255 * hash.GetDigestSize();
   System.SetLength(okm, l);
   System.SetLength(okm, l);

+ 15 - 22
CryptoLib.Tests/src/Crypto/Kdf1GeneratorTests.pas

@@ -39,28 +39,21 @@ uses
   ClpIso18033KdfParameters,
   ClpIso18033KdfParameters,
   ClpKdf1BytesGenerator,
   ClpKdf1BytesGenerator,
   ClpIKdf1BytesGenerator,
   ClpIKdf1BytesGenerator,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// KDF1 tests - vectors from ISO 18033.
   /// KDF1 tests - vectors from ISO 18033.
   /// </summary>
   /// </summary>
-  TTestKdf1Generator = class(TCryptoLibTestCase)
+  TTestKdf1Generator = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
-    Fseed1, Fmask1, Fseed2, Fmask2, Fseed3, Fmask3: TCryptoLibByteArray;
+    Fseed1, Fmask1, Fseed2, Fmask2, Fseed3, Fmask3: TBytes;
 
 
     procedure CheckMask(count: Int32; const kdf: IDerivationFunction;
     procedure CheckMask(count: Int32; const kdf: IDerivationFunction;
-      const seed, result: TCryptoLibByteArray);
+      const seed, result: TBytes);
     procedure DoTestKdf1Generator();
     procedure DoTestKdf1Generator();
 
 
   protected
   protected
@@ -77,9 +70,9 @@ implementation
 { TTestKdf1Generator }
 { TTestKdf1Generator }
 
 
 procedure TTestKdf1Generator.CheckMask(count: Int32;
 procedure TTestKdf1Generator.CheckMask(count: Int32;
-  const kdf: IDerivationFunction; const seed, result: TCryptoLibByteArray);
+  const kdf: IDerivationFunction; const seed, result: TBytes);
 var
 var
-  data: TCryptoLibByteArray;
+  data: TBytes;
 begin
 begin
   System.SetLength(data, System.Length(result));
   System.SetLength(data, System.Length(result));
 
 
@@ -87,7 +80,7 @@ begin
 
 
   kdf.GenerateBytes(data, 0, System.Length(data));
   kdf.GenerateBytes(data, 0, System.Length(data));
 
 
-  if (not TArrayUtils.AreEqual(result, data)) then
+  if (not AreEqual(result, data)) then
   begin
   begin
     Fail(Format('KDF1 failed generator test %d', [count]));
     Fail(Format('KDF1 failed generator test %d', [count]));
   end;
   end;
@@ -95,7 +88,7 @@ end;
 
 
 procedure TTestKdf1Generator.DoTestKdf1Generator;
 procedure TTestKdf1Generator.DoTestKdf1Generator;
 var
 var
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
 
 
   CheckMask(1, TKdf1BytesGenerator.Create(TShortenedDigest.Create
   CheckMask(1, TKdf1BytesGenerator.Create(TShortenedDigest.Create
@@ -126,16 +119,16 @@ end;
 procedure TTestKdf1Generator.SetUp;
 procedure TTestKdf1Generator.SetUp;
 begin
 begin
   inherited;
   inherited;
-  Fseed1 := THex.Decode('d6e168c5f256a2dcff7ef12facd390f393c7a88d');
-  Fmask1 := THex.Decode('0742ba966813af75536bb6149cc44fc256fd6406df79665bc31dc5'
-    + 'a62f70535e52c53015b9d37d412ff3c1193439599e1b628774c50d9c' +
+  Fseed1 := DecodeHex('d6e168c5f256a2dcff7ef12facd390f393c7a88d');
+  Fmask1 := DecodeHex('0742ba966813af75536bb6149cc44fc256fd6406df79665bc31dc5' +
+    'a62f70535e52c53015b9d37d412ff3c1193439599e1b628774c50d9c' +
     'cb78d82c425e4521ee47b8c36a4bcffe8b8112a89312fc04420a39de' +
     'cb78d82c425e4521ee47b8c36a4bcffe8b8112a89312fc04420a39de' +
     '99223890e74ce10378bc515a212b97b8a6447ba6a8870278');
     '99223890e74ce10378bc515a212b97b8a6447ba6a8870278');
 
 
-  Fseed2 := THex.Decode
+  Fseed2 := DecodeHex
     ('032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741' +
     ('032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741' +
     '52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4');
     '52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4');
-  Fmask2 := THex.Decode
+  Fmask2 := DecodeHex
     ('5f8de105b5e96b2e490ddecbd147dd1def7e3b8e0e6a26eb7b956ccb8b3bdc1ca9' +
     ('5f8de105b5e96b2e490ddecbd147dd1def7e3b8e0e6a26eb7b956ccb8b3bdc1ca9' +
     '75bc57c3989e8fbad31a224655d800c46954840ff32052cdf0d640562bdfadfa263c' +
     '75bc57c3989e8fbad31a224655d800c46954840ff32052cdf0d640562bdfadfa263c' +
     'fccf3c52b29f2af4a1869959bc77f854cf15bd7a25192985a842dbff8e13efee5b7e' +
     'fccf3c52b29f2af4a1869959bc77f854cf15bd7a25192985a842dbff8e13efee5b7e' +
@@ -143,7 +136,7 @@ begin
 
 
   Fseed3 := Fseed2;
   Fseed3 := Fseed2;
 
 
-  Fmask3 := THex.Decode
+  Fmask3 := DecodeHex
     ('09e2decf2a6e1666c2f6071ff4298305e2643fd510a2403db42a8743cb989de86e' +
     ('09e2decf2a6e1666c2f6071ff4298305e2643fd510a2403db42a8743cb989de86e' +
     '668d168cbe604611ac179f819a3d18412e9eb45668f2923c087c12fee0c5a0d2a8aa' +
     '668d168cbe604611ac179f819a3d18412e9eb45668f2923c087c12fee0c5a0d2a8aa' +
     '70185401fbbd99379ec76c663e875a60b4aacb1319fa11c3365a8b79a44669f26fb5' +
     '70185401fbbd99379ec76c663e875a60b4aacb1319fa11c3365a8b79a44669f26fb5' +

+ 22 - 28
CryptoLib.Tests/src/Crypto/Kdf2GeneratorTests.pas

@@ -39,29 +39,22 @@ uses
   ClpIKdfParameters,
   ClpIKdfParameters,
   ClpKdf2BytesGenerator,
   ClpKdf2BytesGenerator,
   ClpIKdf2BytesGenerator,
   ClpIKdf2BytesGenerator,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// KDF2 tests - vectors from ISO 18033.
   /// KDF2 tests - vectors from ISO 18033.
   /// </summary>
   /// </summary>
-  TTestKdf2Generator = class(TCryptoLibTestCase)
+  TTestKdf2Generator = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fseed1, Fmask1, Fseed2, Fmask2, Fseed3, Fmask3, Fseed4, Fmask4,
     Fseed1, Fmask1, Fseed2, Fmask2, Fseed3, Fmask3, Fseed4, Fmask4,
-      FadjustedMask2, Fsha1Mask: TCryptoLibByteArray;
+      FadjustedMask2, Fsha1Mask: TBytes;
 
 
     procedure CheckMask(count: Int32; const kdf: IDerivationFunction;
     procedure CheckMask(count: Int32; const kdf: IDerivationFunction;
-      const seed, result: TCryptoLibByteArray);
+      const seed, result: TBytes);
     procedure DoTestKdf2Generator();
     procedure DoTestKdf2Generator();
 
 
   protected
   protected
@@ -78,9 +71,9 @@ implementation
 { TTestKdf2Generator }
 { TTestKdf2Generator }
 
 
 procedure TTestKdf2Generator.CheckMask(count: Int32;
 procedure TTestKdf2Generator.CheckMask(count: Int32;
-  const kdf: IDerivationFunction; const seed, result: TCryptoLibByteArray);
+  const kdf: IDerivationFunction; const seed, result: TBytes);
 var
 var
-  data: TCryptoLibByteArray;
+  data: TBytes;
 begin
 begin
   System.SetLength(data, System.Length(result));
   System.SetLength(data, System.Length(result));
 
 
@@ -88,7 +81,7 @@ begin
 
 
   kdf.GenerateBytes(data, 0, System.Length(data));
   kdf.GenerateBytes(data, 0, System.Length(data));
 
 
-  if (not TArrayUtils.AreEqual(result, data)) then
+  if (not AreEqual(result, data)) then
   begin
   begin
     Fail(Format('KDF2 failed generator test %d', [count]));
     Fail(Format('KDF2 failed generator test %d', [count]));
   end;
   end;
@@ -96,7 +89,7 @@ end;
 
 
 procedure TTestKdf2Generator.DoTestKdf2Generator;
 procedure TTestKdf2Generator.DoTestKdf2Generator;
 var
 var
-  temp: TCryptoLibByteArray;
+  temp: TBytes;
 begin
 begin
 
 
   CheckMask(1, TKdf2BytesGenerator.Create(TShortenedDigest.Create
   CheckMask(1, TKdf2BytesGenerator.Create(TShortenedDigest.Create
@@ -136,37 +129,38 @@ end;
 procedure TTestKdf2Generator.SetUp;
 procedure TTestKdf2Generator.SetUp;
 begin
 begin
   inherited;
   inherited;
-  Fseed1 := THex.Decode('d6e168c5f256a2dcff7ef12facd390f393c7a88d');
-  Fmask1 := THex.Decode('df79665bc31dc5a62f70535e52c53015b9d37d412ff3c119343959'
-    + '9e1b628774c50d9ccb78d82c425e4521ee47b8c36a4bcffe8b8112a8' +
+  Fseed1 := DecodeHex('d6e168c5f256a2dcff7ef12facd390f393c7a88d');
+  Fmask1 := DecodeHex('df79665bc31dc5a62f70535e52c53015b9d37d412ff3c119343959' +
+    '9e1b628774c50d9ccb78d82c425e4521ee47b8c36a4bcffe8b8112a8' +
     '9312fc04420a39de99223890e74ce10378bc515a212b97b8a6447ba6' +
     '9312fc04420a39de99223890e74ce10378bc515a212b97b8a6447ba6' +
     'a8870278f0262727ca041fa1aa9f7b5d1cf7f308232fe861');
     'a8870278f0262727ca041fa1aa9f7b5d1cf7f308232fe861');
 
 
-  Fseed2 := THex.Decode
+  Fseed2 := DecodeHex
     ('032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741' +
     ('032e45326fa859a72ec235acff929b15d1372e30b207255f0611b8f785d7643741' +
     '52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4');
     '52e0ac009e509e7ba30cd2f1778e113b64e135cf4e2292c75efe5288edfda4');
-  Fmask2 := THex.Decode
+  Fmask2 := DecodeHex
     ('10a2403db42a8743cb989de86e668d168cbe604611ac179f819a3d18412e9eb456' +
     ('10a2403db42a8743cb989de86e668d168cbe604611ac179f819a3d18412e9eb456' +
     '68f2923c087c12fee0c5a0d2a8aa70185401fbbd99379ec76c663e875a60b4aacb13' +
     '68f2923c087c12fee0c5a0d2a8aa70185401fbbd99379ec76c663e875a60b4aacb13' +
     '19fa11c3365a8b79a44669f26fb555c80391847b05eca1cb5cf8c2d531448d33fbac' +
     '19fa11c3365a8b79a44669f26fb555c80391847b05eca1cb5cf8c2d531448d33fbac' +
     'a19f6410ee1fcb260892670e0814c348664f6a7248aaf998a3acc6');
     'a19f6410ee1fcb260892670e0814c348664f6a7248aaf998a3acc6');
-  FadjustedMask2 := THex.Decode
-    ('10a2403db42a8743cb989de86e668d168cbe6046e23ff26f741e87949a3bba1311ac1' +
+  FadjustedMask2 :=
+    DecodeHex(
+    '10a2403db42a8743cb989de86e668d168cbe6046e23ff26f741e87949a3bba1311ac1' +
     '79f819a3d18412e9eb45668f2923c087c1299005f8d5fd42ca257bc93e8fee0c5a0d2' +
     '79f819a3d18412e9eb45668f2923c087c1299005f8d5fd42ca257bc93e8fee0c5a0d2' +
     'a8aa70185401fbbd99379ec76c663e9a29d0b70f3fe261a59cdc24875a60b4aacb131' +
     'a8aa70185401fbbd99379ec76c663e9a29d0b70f3fe261a59cdc24875a60b4aacb131' +
     '9fa11c3365a8b79a44669f26fba933d012db213d7e3b16349');
     '9fa11c3365a8b79a44669f26fba933d012db213d7e3b16349');
 
 
-  Fsha1Mask := THex.Decode
+  Fsha1Mask := DecodeHex
     ('0e6a26eb7b956ccb8b3bdc1ca975bc57c3989e8fbad31a224655d800c46954840ff32' +
     ('0e6a26eb7b956ccb8b3bdc1ca975bc57c3989e8fbad31a224655d800c46954840ff32' +
     '052cdf0d640562bdfadfa263cfccf3c52b29f2af4a1869959bc77f854cf15bd7a2519' +
     '052cdf0d640562bdfadfa263cfccf3c52b29f2af4a1869959bc77f854cf15bd7a2519' +
     '2985a842dbff8e13efee5b7e7e55bbe4d389647c686a9a9ab3fb889b2d7767d3837ee' +
     '2985a842dbff8e13efee5b7e7e55bbe4d389647c686a9a9ab3fb889b2d7767d3837ee' +
     'a4e0a2f04b53ca8f50fb31225c1be2d0126c8c7a4753b0807');
     'a4e0a2f04b53ca8f50fb31225c1be2d0126c8c7a4753b0807');
 
 
-  Fseed3 := THex.Decode('CA7C0F8C3FFA87A96E1B74AC8E6AF594347BB40A');
-  Fmask3 := THex.Decode('744AB703F5BC082E59185F6D049D2D367DB245C2');
+  Fseed3 := DecodeHex('CA7C0F8C3FFA87A96E1B74AC8E6AF594347BB40A');
+  Fmask3 := DecodeHex('744AB703F5BC082E59185F6D049D2D367DB245C2');
 
 
-  Fseed4 := THex.Decode('0499B502FC8B5BAFB0F4047E731D1F9FD8CD0D8881');
-  Fmask4 := THex.Decode
+  Fseed4 := DecodeHex('0499B502FC8B5BAFB0F4047E731D1F9FD8CD0D8881');
+  Fmask4 := DecodeHex
     ('03C62280C894E103C680B13CD4B4AE740A5EF0C72547292F82DC6B1777F47D63BA9D1EA732DBF386');
     ('03C62280C894E103C680B13CD4B4AE740A5EF0C72547292F82DC6B1777F47D63BA9D1EA732DBF386');
 end;
 end;
 
 

+ 9 - 16
CryptoLib.Tests/src/Crypto/MD5HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// MD5 HMac Test, test vectors from RFC 2202
   /// MD5 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestMD5HMac = class(TCryptoLibTestCase)
+  TTestMD5HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -114,14 +107,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -133,18 +126,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 17 - 25
CryptoLib.Tests/src/Crypto/PaddingTests.pas

@@ -42,30 +42,22 @@ uses
   ClpIPaddingModes,
   ClpIPaddingModes,
   ClpPaddedBufferedBlockCipher,
   ClpPaddedBufferedBlockCipher,
   ClpIPaddedBufferedBlockCipher,
   ClpIPaddedBufferedBlockCipher,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// Padding tests.
   /// Padding tests.
   /// </summary>
   /// </summary>
-  TTestPadding = class(TCryptoLibTestCase)
+  TTestPadding = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     procedure DoBlockCheck(const cipher: IPaddedBufferedBlockCipher;
     procedure DoBlockCheck(const cipher: IPaddedBufferedBlockCipher;
       const padding: IBlockCipherPadding; const key: IKeyParameter;
       const padding: IBlockCipherPadding; const key: IKeyParameter;
-      const data: TCryptoLibByteArray);
+      const data: TBytes);
     procedure DoTestPadding(const padding: IBlockCipherPadding;
     procedure DoTestPadding(const padding: IBlockCipherPadding;
-      const rand: ISecureRandom;
-      const ffVector, ZeroVector: TCryptoLibByteArray);
+      const rand: ISecureRandom; const ffVector, ZeroVector: TBytes);
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -84,7 +76,7 @@ implementation
 
 
 procedure TTestPadding.DoBlockCheck(const cipher: IPaddedBufferedBlockCipher;
 procedure TTestPadding.DoBlockCheck(const cipher: IPaddedBufferedBlockCipher;
   const padding: IBlockCipherPadding; const key: IKeyParameter;
   const padding: IBlockCipherPadding; const key: IKeyParameter;
-  const data: TCryptoLibByteArray);
+  const data: TBytes);
 var
 var
   &out, dec: TBytes;
   &out, dec: TBytes;
   len, decLen: Int32;
   len, decLen: Int32;
@@ -107,7 +99,7 @@ begin
     // decLen := decLen + cipher.doFinal(dec, decLen);
     // decLen := decLen + cipher.doFinal(dec, decLen);
     cipher.doFinal(dec, decLen);
     cipher.doFinal(dec, decLen);
 
 
-    if (not TArrayUtils.AreEqual(data, dec)) then
+    if (not AreEqual(data, dec)) then
     begin
     begin
       Fail('failed to decrypt - i = ' + IntToStr(System.Length(data)) +
       Fail('failed to decrypt - i = ' + IntToStr(System.Length(data)) +
         ', padding = ' + padding.PaddingName);
         ', padding = ' + padding.PaddingName);
@@ -143,7 +135,7 @@ var
 begin
 begin
   bc := TPaddedBufferedBlockCipher.Create(TAESEngine.Create() as IAESEngine,
   bc := TPaddedBufferedBlockCipher.Create(TAESEngine.Create() as IAESEngine,
     TPKCS7Padding.Create() as IPKCS7Padding);
     TPKCS7Padding.Create() as IPKCS7Padding);
-  key := TKeyParameter.Create(THex.decode('001122334455667788990A0B0C0D0E0F'));
+  key := TKeyParameter.Create(DecodeHex('001122334455667788990A0B0C0D0E0F'));
 
 
   for i := 0 to (bc.GetBlockSize * 2) do
   for i := 0 to (bc.GetBlockSize * 2) do
   begin
   begin
@@ -183,7 +175,7 @@ begin
   rand := TSecureRandom.GetInstance('SHA256PRNG');
   rand := TSecureRandom.GetInstance('SHA256PRNG');
 
 
   DoTestPadding(TPKCS7Padding.Create() as IPKCS7Padding, rand,
   DoTestPadding(TPKCS7Padding.Create() as IPKCS7Padding, rand,
-    THex.decode('ffffff0505050505'), THex.decode('0000000004040404'));
+    DecodeHex('ffffff0505050505'), DecodeHex('0000000004040404'));
 
 
   padder := TPKCS7Padding.Create();
   padder := TPKCS7Padding.Create();
   try
   try
@@ -210,19 +202,19 @@ begin
   DoTestPadding(TX923Padding.Create() as IX923Padding, rand, Nil, Nil);
   DoTestPadding(TX923Padding.Create() as IX923Padding, rand, Nil, Nil);
 
 
   DoTestPadding(TTBCPadding.Create() as ITBCPadding, rand,
   DoTestPadding(TTBCPadding.Create() as ITBCPadding, rand,
-    THex.decode('ffffff0000000000'), THex.decode('00000000ffffffff'));
+    DecodeHex('ffffff0000000000'), DecodeHex('00000000ffffffff'));
 
 
   DoTestPadding(TZeroBytePadding.Create() as IZeroBytePadding, rand,
   DoTestPadding(TZeroBytePadding.Create() as IZeroBytePadding, rand,
-    THex.decode('ffffff0000000000'), Nil);
+    DecodeHex('ffffff0000000000'), Nil);
 
 
   DoTestPadding(TISO7816d4Padding.Create() as IISO7816d4Padding, rand,
   DoTestPadding(TISO7816d4Padding.Create() as IISO7816d4Padding, rand,
-    THex.decode('ffffff8000000000'), THex.decode('0000000080000000'));
+    DecodeHex('ffffff8000000000'), DecodeHex('0000000080000000'));
 
 
   TestOutputSizes();
   TestOutputSizes();
 end;
 end;
 
 
 procedure TTestPadding.DoTestPadding(const padding: IBlockCipherPadding;
 procedure TTestPadding.DoTestPadding(const padding: IBlockCipherPadding;
-  const rand: ISecureRandom; const ffVector, ZeroVector: TCryptoLibByteArray);
+  const rand: ISecureRandom; const ffVector, ZeroVector: TBytes);
 var
 var
   cipher: IPaddedBufferedBlockCipher;
   cipher: IPaddedBufferedBlockCipher;
   key: IKeyParameter;
   key: IKeyParameter;
@@ -231,7 +223,7 @@ var
 begin
 begin
   cipher := TPaddedBufferedBlockCipher.Create(TAESEngine.Create()
   cipher := TPaddedBufferedBlockCipher.Create(TAESEngine.Create()
     as IAESEngine, padding);
     as IAESEngine, padding);
-  key := TKeyParameter.Create(THex.decode('001122334455667788990A0B0C0D0E0F'));
+  key := TKeyParameter.Create(DecodeHex('001122334455667788990A0B0C0D0E0F'));
 
 
   //
   //
   // ff test
   // ff test
@@ -242,7 +234,7 @@ begin
   begin
   begin
     padding.AddPadding(data, 3);
     padding.AddPadding(data, 3);
 
 
-    if (not TArrayUtils.AreEqual(data, ffVector)) then
+    if (not AreEqual(data, ffVector)) then
     begin
     begin
       Fail('failed ff test for ' + padding.PaddingName);
       Fail('failed ff test for ' + padding.PaddingName);
     end;
     end;
@@ -253,10 +245,10 @@ begin
   //
   //
   if (ZeroVector <> Nil) then
   if (ZeroVector <> Nil) then
   begin
   begin
-    TArrayUtils.ZeroFill(data);
+    ZeroFill(data);
     padding.AddPadding(data, 4);
     padding.AddPadding(data, 4);
 
 
-    if (not TArrayUtils.AreEqual(data, ZeroVector)) then
+    if (not AreEqual(data, ZeroVector)) then
     begin
     begin
       Fail('failed zero test for ' + padding.PaddingName);
       Fail('failed zero test for ' + padding.PaddingName);
     end;
     end;

+ 37 - 45
CryptoLib.Tests/src/Crypto/Pkcs5Tests.pas

@@ -35,23 +35,15 @@ uses
   ClpPkcs5S2ParametersGenerator,
   ClpPkcs5S2ParametersGenerator,
   ClpIPkcs5S2ParametersGenerator,
   ClpIPkcs5S2ParametersGenerator,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// A test class for Pkcs5 PbeS2 with PBKDF2(Pkcs5 v2.0).
   /// A test class for Pkcs5 PbeS2 with PBKDF2(Pkcs5 v2.0).
   /// </summary>
   /// </summary>
-  TTestPkcs5 = class(TCryptoLibTestCase)
+  TTestPkcs5 = class(TCryptoLibAlgorithmTestCase)
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -98,7 +90,7 @@ begin
   //
   //
   // RFC 3211 tests
   // RFC 3211 tests
   //
   //
-  SaltBytes := THex.Decode('1234567878563412');
+  SaltBytes := DecodeHex('1234567878563412');
 
 
   PasswordString := 'password';
   PasswordString := 'password';
   PasswordBytes := TConverters.ConvertStringToBytes(PasswordString,
   PasswordBytes := TConverters.ConvertStringToBytes(PasswordString,
@@ -108,8 +100,8 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, 5);
   generator.Init(PasswordBytes, SaltBytes, 5);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(64)
-    as IKeyParameter).GetKey(), THex.Decode('D1DAA78615F287E6'))) then
+  if (not AreEqual((generator.GenerateDerivedMacParameters(64) as IKeyParameter)
+    .GetKey(), DecodeHex('D1DAA78615F287E6'))) then
   begin
   begin
     Fail('PBKDF2 HMAC-SHA1 with iteration count "5", 64 bits key generation test failed');
     Fail('PBKDF2 HMAC-SHA1 with iteration count "5", 64 bits key generation test failed');
   end;
   end;
@@ -123,9 +115,9 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, 500);
   generator.Init(PasswordBytes, SaltBytes, 500);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(192)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(192)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode('6A8970BF68C92CAEA84A8DF28510858607126380CC47AB2D'))) then
+    DecodeHex('6A8970BF68C92CAEA84A8DF28510858607126380CC47AB2D'))) then
   begin
   begin
     Fail('PBKDF2 HMAC-SHA1 with iteration count "500", 192 bits key generation test failed');
     Fail('PBKDF2 HMAC-SHA1 with iteration count "500", 192 bits key generation test failed');
   end;
   end;
@@ -134,9 +126,9 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, 60000);
   generator.Init(PasswordBytes, SaltBytes, 60000);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(192)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(192)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode('29AAEF810C12ECD2236BBCFB55407F9852B5573DC1C095BB'))) then
+    DecodeHex('29AAEF810C12ECD2236BBCFB55407F9852B5573DC1C095BB'))) then
   begin
   begin
     Fail('PBKDF2 HMAC-SHA1 with iteration count "60000", 192 bits key generation test failed');
     Fail('PBKDF2 HMAC-SHA1 with iteration count "60000", 192 bits key generation test failed');
   end;
   end;
@@ -163,9 +155,9 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode('0C60C80F961F0E71F3A9B524AF6012062FE037A6'))) then
+    DecodeHex('0C60C80F961F0E71F3A9B524AF6012062FE037A6'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
@@ -182,9 +174,9 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode('EA6C014DC72D6F8CCD1ED92ACE1D41F0D8DE8957'))) then
+    DecodeHex('EA6C014DC72D6F8CCD1ED92ACE1D41F0D8DE8957'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
@@ -202,9 +194,9 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode('4B007901B765489ABEAD49D926F721D065A429C1'))) then
+    DecodeHex('4B007901B765489ABEAD49D926F721D065A429C1'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
@@ -221,9 +213,9 @@ begin
   //
   //
   // generator.Init(PasswordBytes, SaltBytes, iteration_count);
   // generator.Init(PasswordBytes, SaltBytes, iteration_count);
   //
   //
-  // if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  // if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
   // as IKeyParameter).GetKey(),
   // as IKeyParameter).GetKey(),
-  // THex.Decode('EEFE3D61CD4DA4E4E9945B3D6BA2158C2634E984'))) then
+  // DecodeHex('EEFE3D61CD4DA4E4E9945B3D6BA2158C2634E984'))) then
   // begin
   // begin
   // Fail(Format
   // Fail(Format
   // ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
   // ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
@@ -248,9 +240,9 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode('3D2EEC4FE41C849B80C8D83662C0E44A8B291A964CF2F07038'))) then
+    DecodeHex('3D2EEC4FE41C849B80C8D83662C0E44A8B291A964CF2F07038'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA1 with iteration count "%u", %u bits key generation test failed',
@@ -276,8 +268,8 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
-    as IKeyParameter).GetKey(), THex.Decode('56FA6AA75548099DCC37D7F03425E0C3')))
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+    as IKeyParameter).GetKey(), DecodeHex('56FA6AA75548099DCC37D7F03425E0C3')))
   then
   then
   begin
   begin
     Fail(Format
     Fail(Format
@@ -317,10 +309,10 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode
-    ('120FB6CFFCF8B32C43E7225256C4F837A86548C92CCC35480805987CB70BE17B'))) then
+    DecodeHex(
+    '120FB6CFFCF8B32C43E7225256C4F837A86548C92CCC35480805987CB70BE17B'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA256 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA256 with iteration count "%u", %u bits key generation test failed',
@@ -337,10 +329,10 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode
-    ('AE4D0C95AF6B46D32D0ADFF928F06DD02A303F8EF3C251DFD6E2D85A95474C43'))) then
+    DecodeHex(
+    'AE4D0C95AF6B46D32D0ADFF928F06DD02A303F8EF3C251DFD6E2D85A95474C43'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA256 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA256 with iteration count "%u", %u bits key generation test failed',
@@ -357,10 +349,10 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode
-    ('C5E478D59288C841AA530DB6845C4C8D962893A001CE4E11A4963873AA98134A'))) then
+    DecodeHex(
+    'C5E478D59288C841AA530DB6845C4C8D962893A001CE4E11A4963873AA98134A'))) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('PBKDF2 HMAC-SHA256 with iteration count "%u", %u bits key generation test failed',
       ('PBKDF2 HMAC-SHA256 with iteration count "%u", %u bits key generation test failed',
@@ -377,9 +369,9 @@ begin
   //
   //
   // generator.Init(PasswordBytes, SaltBytes, iteration_count);
   // generator.Init(PasswordBytes, SaltBytes, iteration_count);
   //
   //
-  // if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  // if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
   // as IKeyParameter).GetKey(),
   // as IKeyParameter).GetKey(),
-  // THex.Decode
+  // DecodeHex
   // ('CF81C66FE8CFC04D1F31ECB65DAB4089F7F179E89B3B0BCB17AD10E3AC6EBA46'))) then
   // ('CF81C66FE8CFC04D1F31ECB65DAB4089F7F179E89B3B0BCB17AD10E3AC6EBA46'))) then
   // begin
   // begin
   // Fail(Format
   // Fail(Format
@@ -404,10 +396,10 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
     as IKeyParameter).GetKey(),
     as IKeyParameter).GetKey(),
-    THex.Decode
-    ('348C89DBCBD32B2F32D814B8116E84CF2B17347EBC1800181C4E2A1FB8DD53E1C635518C7DAC47E9'))
+    DecodeHex(
+    '348C89DBCBD32B2F32D814B8116E84CF2B17347EBC1800181C4E2A1FB8DD53E1C635518C7DAC47E9'))
     ) then
     ) then
   begin
   begin
     Fail(Format
     Fail(Format
@@ -433,8 +425,8 @@ begin
 
 
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
   generator.Init(PasswordBytes, SaltBytes, iteration_count);
 
 
-  if (not TArrayUtils.AreEqual((generator.GenerateDerivedMacParameters(dkLen)
-    as IKeyParameter).GetKey(), THex.Decode('89B69D0516F829893C696226650A8687')))
+  if (not AreEqual((generator.GenerateDerivedMacParameters(dkLen)
+    as IKeyParameter).GetKey(), DecodeHex('89B69D0516F829893C696226650A8687')))
   then
   then
   begin
   begin
     Fail(Format
     Fail(Format

+ 9 - 16
CryptoLib.Tests/src/Crypto/RIPEMD128HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// RIPEMD128 HMac Test, test vectors from RFC 2202
   /// RIPEMD128 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestRIPEMD128HMac = class(TCryptoLibTestCase)
+  TTestRIPEMD128HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -113,14 +106,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -132,18 +125,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 9 - 16
CryptoLib.Tests/src/Crypto/RIPEMD160HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// RIPEMD160 HMac Test, test vectors from RFC 2202
   /// RIPEMD160 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestRIPEMD160HMac = class(TCryptoLibTestCase)
+  TTestRIPEMD160HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -118,14 +111,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -137,18 +130,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 9 - 16
CryptoLib.Tests/src/Crypto/SHA1HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// SHA1 HMac Test, test vectors from RFC 2202
   /// SHA1 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestSHA1HMac = class(TCryptoLibTestCase)
+  TTestSHA1HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -119,14 +112,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -138,18 +131,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 9 - 16
CryptoLib.Tests/src/Crypto/SHA224HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// SHA224 HMac Test, test vectors from RFC 2202
   /// SHA224 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestSHA224HMac = class(TCryptoLibTestCase)
+  TTestSHA224HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -120,14 +113,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -139,18 +132,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 9 - 16
CryptoLib.Tests/src/Crypto/SHA256HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// SHA256 HMac Test, test vectors from RFC 2202
   /// SHA256 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestSHA256HMac = class(TCryptoLibTestCase)
+  TTestSHA256HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -120,14 +113,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -139,18 +132,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 9 - 16
CryptoLib.Tests/src/Crypto/SHA384HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// SHA384 HMac Test, test vectors from RFC 2202
   /// SHA384 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestSHA384HMac = class(TCryptoLibTestCase)
+  TTestSHA384HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -120,14 +113,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -139,18 +132,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 9 - 16
CryptoLib.Tests/src/Crypto/SHA512HMacTests.pas

@@ -35,24 +35,17 @@ uses
   ClpHMac,
   ClpHMac,
   ClpIMac,
   ClpIMac,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpStringUtils,
   ClpStringUtils,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// SHA512 HMac Test, test vectors from RFC 2202
   /// SHA512 HMac Test, test vectors from RFC 2202
   /// </summary>
   /// </summary>
-  TTestSHA512HMac = class(TCryptoLibTestCase)
+  TTestSHA512HMac = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
     Fkeys, Fdigests, Fmessages: TCryptoLibStringArray;
@@ -120,14 +113,14 @@ begin
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     m := TConverters.ConvertStringToBytes(Fmessages[i], TEncoding.ASCII);
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     if (TStringUtils.BeginsWith(Fmessages[i], '0x', True)) then
     begin
     begin
-      m := THex.Decode(System.Copy(Fmessages[i], 3,
+      m := DecodeHex(System.Copy(Fmessages[i], 3,
         System.Length(Fmessages[i]) - 2));
         System.Length(Fmessages[i]) - 2));
     end;
     end;
-    hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[i])));
+    hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[i])));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.BlockUpdate(m, 0, System.Length(m));
     hmac.DoFinal(resBuf, 0);
     hmac.DoFinal(resBuf, 0);
 
 
-    if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[i]))) then
+    if (not AreEqual(resBuf, DecodeHex(Fdigests[i]))) then
     begin
     begin
       Fail('Vector ' + IntToStr(i) + ' failed');
       Fail('Vector ' + IntToStr(i) + ' failed');
     end;
     end;
@@ -139,18 +132,18 @@ begin
 
 
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   if (TStringUtils.BeginsWith(Fmessages[vector], '0x', True)) then
   begin
   begin
-    m2 := THex.Decode(System.Copy(Fmessages[vector], 3,
+    m2 := DecodeHex(System.Copy(Fmessages[vector], 3,
       System.Length(Fmessages[vector]) - 2));
       System.Length(Fmessages[vector]) - 2));
   end;
   end;
 
 
-  hmac.Init(TKeyParameter.Create(THex.Decode(Fkeys[vector])));
+  hmac.Init(TKeyParameter.Create(DecodeHex(Fkeys[vector])));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
   hmac.Reset();
   hmac.Reset();
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.BlockUpdate(m2, 0, System.Length(m2));
   hmac.DoFinal(resBuf, 0);
   hmac.DoFinal(resBuf, 0);
 
 
-  if (not TArrayUtils.AreEqual(resBuf, THex.Decode(Fdigests[vector]))) then
+  if (not AreEqual(resBuf, DecodeHex(Fdigests[vector]))) then
   begin
   begin
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
     Fail('Reset with vector ' + IntToStr(vector) + ' failed');
   end;
   end;

+ 26 - 39
CryptoLib.Tests/src/Crypto/SPECKTests.pas

@@ -45,22 +45,14 @@ uses
   ClpIBlockCipher,
   ClpIBlockCipher,
   ClpBufferedBlockCipher,
   ClpBufferedBlockCipher,
   ClpIBufferedBlockCipher,
   ClpIBufferedBlockCipher,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestSPECK = class(TCryptoLibTestCase)
+  TTestSPECK = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
-    procedure doSPECKTest(const cipher: IBufferedCipher;
+    procedure DoSPECKTest(const cipher: IBufferedCipher;
       const param: ICipherParameters; const input, output: String;
       const param: ICipherParameters; const input, output: String;
       withpadding: Boolean = False);
       withpadding: Boolean = False);
 
 
@@ -82,15 +74,15 @@ implementation
 
 
 { TTestSPECK }
 { TTestSPECK }
 
 
-procedure TTestSPECK.doSPECKTest(const cipher: IBufferedCipher;
+procedure TTestSPECK.DoSPECKTest(const cipher: IBufferedCipher;
   const param: ICipherParameters; const input, output: String;
   const param: ICipherParameters; const input, output: String;
   withpadding: Boolean);
   withpadding: Boolean);
 var
 var
   LInput, LOutput, EncryptionResult, DecryptionResult: TBytes;
   LInput, LOutput, EncryptionResult, DecryptionResult: TBytes;
   // len1, len2: Int32;
   // len1, len2: Int32;
 begin
 begin
-  LInput := THex.Decode(input);
-  LOutput := THex.Decode(output);
+  LInput := DecodeHex(input);
+  LOutput := DecodeHex(output);
 
 
   cipher.Init(True, param);
   cipher.Init(True, param);
 
 
@@ -111,10 +103,10 @@ begin
 
 
   if not withpadding then
   if not withpadding then
   begin
   begin
-    if (not TArrayUtils.AreEqual(LOutput, EncryptionResult)) then
+    if (not AreEqual(LOutput, EncryptionResult)) then
     begin
     begin
       Fail(Format('Encryption Failed - Expected %s but got %s',
       Fail(Format('Encryption Failed - Expected %s but got %s',
-        [THex.Encode(LOutput), THex.Encode(EncryptionResult)]));
+        [EncodeHex(LOutput), EncodeHex(EncryptionResult)]));
     end;
     end;
   end;
   end;
 
 
@@ -137,10 +129,10 @@ begin
     System.SetLength(DecryptionResult, len2);
     System.SetLength(DecryptionResult, len2);
     * }
     * }
 
 
-  if (not TArrayUtils.AreEqual(LInput, DecryptionResult)) then
+  if (not AreEqual(LInput, DecryptionResult)) then
   begin
   begin
     Fail(Format('Decryption Failed - Expected %s but got %s',
     Fail(Format('Decryption Failed - Expected %s but got %s',
-      [THex.Encode(LInput), THex.Encode(DecryptionResult)]));
+      [EncodeHex(LInput), EncodeHex(DecryptionResult)]));
   end;
   end;
 end;
 end;
 
 
@@ -174,16 +166,15 @@ begin
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CBC)
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CBC)
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CBC) do
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CBC) do
   begin
   begin
-    keyBytes := THex.Decode
-      (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CBC[i]);
-    IVBytes := THex.Decode(TSPECKTestVectors.FCryptoPPVectorIVs_SPECK64_CBC[i]);
+    keyBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CBC[i]);
+    IVBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorIVs_SPECK64_CBC[i]);
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK64_CBC[i];
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK64_CBC[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK64_CBC[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK64_CBC[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
 
 
-    doSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
+    DoSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
       input, output);
       input, output);
   end;
   end;
 
 
@@ -208,17 +199,16 @@ begin
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CBC)
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CBC)
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CBC) do
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CBC) do
   begin
   begin
-    keyBytes := THex.Decode
+    keyBytes := DecodeHex
       (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CBC[i]);
       (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CBC[i]);
-    IVBytes := THex.Decode
-      (TSPECKTestVectors.FCryptoPPVectorIVs_SPECK128_CBC[i]);
+    IVBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorIVs_SPECK128_CBC[i]);
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK128_CBC[i];
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK128_CBC[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK128_CBC[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK128_CBC[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
 
 
-    doSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
+    DoSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
       input, output);
       input, output);
   end;
   end;
 
 
@@ -243,16 +233,15 @@ begin
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CTR)
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CTR)
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CTR) do
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CTR) do
   begin
   begin
-    keyBytes := THex.Decode
-      (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CTR[i]);
-    IVBytes := THex.Decode(TSPECKTestVectors.FCryptoPPVectorIVs_SPECK64_CTR[i]);
+    keyBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_CTR[i]);
+    IVBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorIVs_SPECK64_CTR[i]);
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK64_CTR[i];
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK64_CTR[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK64_CTR[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK64_CTR[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
 
 
-    doSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
+    DoSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
       input, output);
       input, output);
   end;
   end;
 
 
@@ -277,17 +266,16 @@ begin
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CTR)
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CTR)
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CTR) do
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CTR) do
   begin
   begin
-    keyBytes := THex.Decode
+    keyBytes := DecodeHex
       (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CTR[i]);
       (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_CTR[i]);
-    IVBytes := THex.Decode
-      (TSPECKTestVectors.FCryptoPPVectorIVs_SPECK128_CTR[i]);
+    IVBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorIVs_SPECK128_CTR[i]);
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK128_CTR[i];
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK128_CTR[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK128_CTR[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK128_CTR[i];
 
 
     KeyParametersWithIV := TParametersWithIV.Create
     KeyParametersWithIV := TParametersWithIV.Create
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
       (TKeyParameter.Create(keyBytes) as IKeyParameter, IVBytes);
 
 
-    doSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
+    DoSPECKTest(cipher, KeyParametersWithIV as ICipherParameters,
       input, output);
       input, output);
   end;
   end;
 
 
@@ -312,14 +300,13 @@ begin
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_ECB)
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_ECB)
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_ECB) do
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_ECB) do
   begin
   begin
-    keyBytes := THex.Decode
-      (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_ECB[i]);
+    keyBytes := DecodeHex(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK64_ECB[i]);
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK64_ECB[i];
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK64_ECB[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK64_ECB[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK64_ECB[i];
 
 
     keyParameter := TKeyParameter.Create(keyBytes);
     keyParameter := TKeyParameter.Create(keyBytes);
 
 
-    doSPECKTest(cipher, keyParameter as ICipherParameters, input, output);
+    DoSPECKTest(cipher, keyParameter as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;
@@ -343,14 +330,14 @@ begin
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_ECB)
   for i := System.Low(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_ECB)
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_ECB) do
     to System.High(TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_ECB) do
   begin
   begin
-    keyBytes := THex.Decode
+    keyBytes := DecodeHex
       (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_ECB[i]);
       (TSPECKTestVectors.FCryptoPPVectorKeys_SPECK128_ECB[i]);
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK128_ECB[i];
     input := TSPECKTestVectors.FCryptoPPVectorInputs_SPECK128_ECB[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK128_ECB[i];
     output := TSPECKTestVectors.FCryptoPPVectorOutputs_SPECK128_ECB[i];
 
 
     keyParameter := TKeyParameter.Create(keyBytes);
     keyParameter := TKeyParameter.Create(keyBytes);
 
 
-    doSPECKTest(cipher, keyParameter as ICipherParameters, input, output);
+    DoSPECKTest(cipher, keyParameter as ICipherParameters, input, output);
   end;
   end;
 
 
 end;
 end;

+ 31 - 40
CryptoLib.Tests/src/Crypto/Salsa20Tests.pas

@@ -38,22 +38,15 @@ uses
   ClpIKeyParameter,
   ClpIKeyParameter,
   ClpParametersWithIV,
   ClpParametersWithIV,
   ClpIParametersWithIV,
   ClpIParametersWithIV,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestSalsa20 = class(TCryptoLibTestCase)
+  TTestSalsa20 = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
-    FZeroes: TCryptoLibByteArray;
+    FZeroes: TBytes;
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448, FSet1v9_0, FSet1v9_192,
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448, FSet1v9_0, FSet1v9_192,
       FSet1v9_256, FSet1v9_448, FSet6v0_0, FSet6v0_65472, FSet6v0_65536,
       FSet1v9_256, FSet1v9_448, FSet6v0_0, FSet6v0_65472, FSet6v0_65536,
       FSet6v1_0, FSet6v1_65472, FSet6v1_65536, FSalsa12_set1v0_0,
       FSet6v1_0, FSet6v1_65472, FSet6v1_65536, FSalsa12_set1v0_0,
@@ -61,8 +54,7 @@ type
       FSalsa8_set1v0_0, FSalsa8_set1v0_192, FSalsa8_set1v0_256,
       FSalsa8_set1v0_0, FSalsa8_set1v0_192, FSalsa8_set1v0_256,
       FSalsa8_set1v0_448: String;
       FSalsa8_set1v0_448: String;
 
 
-    procedure Mismatch(const name, expected: String;
-      found: TCryptoLibByteArray);
+    procedure Mismatch(const name, expected: String; found: TBytes);
     procedure DoSalsa20Test1(rounds: Int32; const parameters: ICipherParameters;
     procedure DoSalsa20Test1(rounds: Int32; const parameters: ICipherParameters;
       const v0, v192, v256, v448: String);
       const v0, v192, v256, v448: String);
 
 
@@ -87,7 +79,7 @@ implementation
 procedure TTestSalsa20.SetUp;
 procedure TTestSalsa20.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FZeroes := THex.Decode('00000000000000000000000000000000' +
+  FZeroes := DecodeHex('00000000000000000000000000000000' +
     '00000000000000000000000000000000' + '00000000000000000000000000000000' +
     '00000000000000000000000000000000' + '00000000000000000000000000000000' +
     '00000000000000000000000000000000');
     '00000000000000000000000000000000');
 
 
@@ -191,18 +183,17 @@ begin
 
 
 end;
 end;
 
 
-procedure TTestSalsa20.Mismatch(const name, expected: String;
-  found: TCryptoLibByteArray);
+procedure TTestSalsa20.Mismatch(const name, expected: String; found: TBytes);
 begin
 begin
   Fail(Format('Mismatch on %s, Expected %s, Found %s.',
   Fail(Format('Mismatch on %s, Expected %s, Found %s.',
-    [name, expected, THex.Encode(found)]));
+    [name, expected, EncodeHex(found)]));
 end;
 end;
 
 
 procedure TTestSalsa20.DoSalsa20Test1(rounds: Int32;
 procedure TTestSalsa20.DoSalsa20Test1(rounds: Int32;
   const parameters: ICipherParameters; const v0, v192, v256, v448: String);
   const parameters: ICipherParameters; const v0, v192, v256, v448: String);
 var
 var
   salsa: ISalsa20Engine;
   salsa: ISalsa20Engine;
-  buf: TCryptoLibByteArray;
+  buf: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   salsa := TSalsa20Engine.Create(rounds);
   salsa := TSalsa20Engine.Create(rounds);
@@ -215,21 +206,21 @@ begin
     case i of
     case i of
       0:
       0:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v0))) then
+          if not(AreEqual(buf, DecodeHex(v0))) then
           begin
           begin
             Mismatch(Format('v0/%d', [rounds]), v0, buf);
             Mismatch(Format('v0/%d', [rounds]), v0, buf);
           end;
           end;
         end;
         end;
       3:
       3:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v192))) then
+          if not(AreEqual(buf, DecodeHex(v192))) then
           begin
           begin
             Mismatch(Format('v192/%d', [rounds]), v192, buf);
             Mismatch(Format('v192/%d', [rounds]), v192, buf);
           end;
           end;
         end;
         end;
       4:
       4:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v256))) then
+          if not(AreEqual(buf, DecodeHex(v256))) then
           begin
           begin
             Mismatch(Format('v256/%d', [rounds]), v256, buf);
             Mismatch(Format('v256/%d', [rounds]), v256, buf);
           end;
           end;
@@ -249,7 +240,7 @@ begin
     System.Inc(i);
     System.Inc(i);
   end;
   end;
 
 
-  if not(TArrayUtils.AreEqual(buf, THex.Decode(v448))) then
+  if not(AreEqual(buf, DecodeHex(v448))) then
   begin
   begin
     Mismatch(Format('v448/%d', [rounds]), v448, buf);
     Mismatch(Format('v448/%d', [rounds]), v448, buf);
   end;
   end;
@@ -259,7 +250,7 @@ procedure TTestSalsa20.DoSalsa20Test2(const parameters: ICipherParameters;
   const v0, v65472, v65536: String);
   const v0, v65472, v65536: String);
 var
 var
   salsa: ISalsa20Engine;
   salsa: ISalsa20Engine;
-  buf: TCryptoLibByteArray;
+  buf: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   salsa := TSalsa20Engine.Create();
   salsa := TSalsa20Engine.Create();
@@ -272,21 +263,21 @@ begin
     case i of
     case i of
       0:
       0:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v0))) then
+          if not(AreEqual(buf, DecodeHex(v0))) then
           begin
           begin
             Mismatch('v0', v0, buf);
             Mismatch('v0', v0, buf);
           end;
           end;
         end;
         end;
       1023:
       1023:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v65472))) then
+          if not(AreEqual(buf, DecodeHex(v65472))) then
           begin
           begin
             Mismatch('v65472', v65472, buf);
             Mismatch('v65472', v65472, buf);
           end;
           end;
         end;
         end;
       1024:
       1024:
         begin
         begin
-          if not(TArrayUtils.AreEqual(buf, THex.Decode(v65536))) then
+          if not(AreEqual(buf, DecodeHex(v65536))) then
           begin
           begin
             Mismatch('v65536', v65536, buf);
             Mismatch('v65536', v65536, buf);
           end;
           end;
@@ -304,21 +295,21 @@ end;
 procedure TTestSalsa20.TestSalsa20Test1;
 procedure TTestSalsa20.TestSalsa20Test1;
 begin
 begin
   DoSalsa20Test1(20, TParametersWithIV.Create
   DoSalsa20Test1(20, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')) as IParametersWithIV,
+    (TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')) as IParametersWithIV,
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448);
     FSet1v0_0, FSet1v0_192, FSet1v0_256, FSet1v0_448);
   DoSalsa20Test1(20, TParametersWithIV.Create
   DoSalsa20Test1(20, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('00400000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')) as IParametersWithIV,
+    (TKeyParameter.Create(DecodeHex('00400000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')) as IParametersWithIV,
     FSet1v9_0, FSet1v9_192, FSet1v9_256, FSet1v9_448);
     FSet1v9_0, FSet1v9_192, FSet1v9_256, FSet1v9_448);
 
 
   DoSalsa20Test1(12, TParametersWithIV.Create
   DoSalsa20Test1(12, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')), FSalsa12_set1v0_0,
+    (TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')), FSalsa12_set1v0_0,
     FSalsa12_set1v0_192, FSalsa12_set1v0_256, FSalsa12_set1v0_448);
     FSalsa12_set1v0_192, FSalsa12_set1v0_256, FSalsa12_set1v0_448);
   DoSalsa20Test1(8, TParametersWithIV.Create
   DoSalsa20Test1(8, TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'))
-    as IKeyParameter, THex.Decode('0000000000000000')) as IParametersWithIV,
+    (TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'))
+    as IKeyParameter, DecodeHex('0000000000000000')) as IParametersWithIV,
     FSalsa8_set1v0_0, FSalsa8_set1v0_192, FSalsa8_set1v0_256,
     FSalsa8_set1v0_0, FSalsa8_set1v0_192, FSalsa8_set1v0_256,
     FSalsa8_set1v0_448);
     FSalsa8_set1v0_448);
 
 
@@ -327,14 +318,14 @@ end;
 procedure TTestSalsa20.TestSalsa20Test2;
 procedure TTestSalsa20.TestSalsa20Test2;
 begin
 begin
   DoSalsa20Test2(TParametersWithIV.Create
   DoSalsa20Test2(TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode
+    (TKeyParameter.Create(DecodeHex
     ('0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D'))
     ('0053A6F94C9FF24598EB3E91E4378ADD3083D6297CCF2275C81B6EC11467BA0D'))
-    as IKeyParameter, THex.Decode('0D74DB42A91077DE')) as IParametersWithIV,
+    as IKeyParameter, DecodeHex('0D74DB42A91077DE')) as IParametersWithIV,
     FSet6v0_0, FSet6v0_65472, FSet6v0_65536);
     FSet6v0_0, FSet6v0_65472, FSet6v0_65536);
   DoSalsa20Test2(TParametersWithIV.Create
   DoSalsa20Test2(TParametersWithIV.Create
-    (TKeyParameter.Create(THex.Decode
+    (TKeyParameter.Create(DecodeHex
     ('0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12'))
     ('0558ABFE51A4F74A9DF04396E93C8FE23588DB2E81D4277ACD2073C6196CBF12'))
-    as IKeyParameter, THex.Decode('167DE44BB21980E7')) as IParametersWithIV,
+    as IKeyParameter, DecodeHex('167DE44BB21980E7')) as IParametersWithIV,
     FSet6v1_0, FSet6v1_65472, FSet6v1_65536);
     FSet6v1_0, FSet6v1_65472, FSet6v1_65536);
 end;
 end;
 
 
@@ -344,8 +335,8 @@ var
   parameters: IParametersWithIV;
   parameters: IParametersWithIV;
   salsa: ISalsa20Engine;
   salsa: ISalsa20Engine;
 begin
 begin
-  key := TKeyParameter.Create(THex.Decode('80000000000000000000000000000000'));
-  parameters := TParametersWithIV.Create(key, THex.Decode('0000000000000000'));
+  key := TKeyParameter.Create(DecodeHex('80000000000000000000000000000000'));
+  parameters := TParametersWithIV.Create(key, DecodeHex('0000000000000000'));
 
 
   salsa := TSalsa20Engine.Create();
   salsa := TSalsa20Engine.Create();
 
 

+ 2 - 8
CryptoLib.Tests/src/Crypto/ScryptTests.pas

@@ -36,20 +36,14 @@ uses
   ClpIScryptParametersGenerator,
   ClpIScryptParametersGenerator,
   ClpConverters,
   ClpConverters,
   HlpHashLibTypes,
   HlpHashLibTypes,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// A Test class for Scrypt.
   /// A Test class for Scrypt.
   /// </summary>
   /// </summary>
-  TTestScrypt = class(TCryptoLibTestCase)
+  TTestScrypt = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
 
 

+ 11 - 13
CryptoLib.Tests/src/Crypto/StreamCipherResetTests.pas

@@ -45,9 +45,7 @@ uses
   ClpIParametersWithIV,
   ClpIParametersWithIV,
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -66,18 +64,18 @@ type
   /// Test whether block ciphers implement reset contract on init,
   /// Test whether block ciphers implement reset contract on init,
   /// encrypt/decrypt and reset.
   /// encrypt/decrypt and reset.
   /// </summary>
   /// </summary>
-  TTestStreamCipherReset = class(TCryptoLibTestCase)
+  TTestStreamCipherReset = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FSecureRandom: ISecureRandom;
     FSecureRandom: ISecureRandom;
 
 
     procedure DoCheckReset(const cipher: IStreamCipher;
     procedure DoCheckReset(const cipher: IStreamCipher;
       const cipherParams: ICipherParameters; encrypt: Boolean;
       const cipherParams: ICipherParameters; encrypt: Boolean;
-      const pretext, posttext: TCryptoLibByteArray);
+      const pretext, posttext: TBytes);
 
 
     function DoMake(CipherEngine: TCipherEngine): IStreamCipher;
     function DoMake(CipherEngine: TCipherEngine): IStreamCipher;
 
 
-    function DoRandom(size: Int32): TCryptoLibByteArray;
+    function DoRandom(size: Int32): TBytes;
     procedure DoTestReset(CipherEngine: TCipherEngine;
     procedure DoTestReset(CipherEngine: TCipherEngine;
       KeyLen, IVLen: Int32); overload;
       KeyLen, IVLen: Int32); overload;
     procedure DoTestReset(const cipher1, cipher2: IStreamCipher;
     procedure DoTestReset(const cipher1, cipher2: IStreamCipher;
@@ -98,9 +96,9 @@ implementation
 
 
 procedure TTestStreamCipherReset.DoCheckReset(const cipher: IStreamCipher;
 procedure TTestStreamCipherReset.DoCheckReset(const cipher: IStreamCipher;
   const cipherParams: ICipherParameters; encrypt: Boolean;
   const cipherParams: ICipherParameters; encrypt: Boolean;
-  const pretext, posttext: TCryptoLibByteArray);
+  const pretext, posttext: TBytes);
 var
 var
-  output: TCryptoLibByteArray;
+  output: TBytes;
 begin
 begin
   // Do initial run
   // Do initial run
   System.SetLength(output, System.Length(posttext));
   System.SetLength(output, System.Length(posttext));
@@ -119,10 +117,10 @@ begin
 
 
   end;
   end;
 
 
-  if not(TArrayUtils.AreEqual(output, posttext)) then
+  if not(AreEqual(output, posttext)) then
   begin
   begin
     Fail(Format('%s init did not reset. Expected %s But Got %s',
     Fail(Format('%s init did not reset. Expected %s But Got %s',
-      [cipher.AlgorithmName, THex.Encode(posttext), THex.Encode(output)]));
+      [cipher.AlgorithmName, EncodeHex(posttext), EncodeHex(output)]));
   end;
   end;
 
 
   // Check reset resets data
   // Check reset resets data
@@ -139,7 +137,7 @@ begin
 
 
   end;
   end;
 
 
-  if not(TArrayUtils.AreEqual(output, posttext)) then
+  if not(AreEqual(output, posttext)) then
   begin
   begin
     Fail(Format('%s init did not reset.', [cipher.AlgorithmName]));
     Fail(Format('%s init did not reset.', [cipher.AlgorithmName]));
   end;
   end;
@@ -176,7 +174,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TTestStreamCipherReset.DoRandom(size: Int32): TCryptoLibByteArray;
+function TTestStreamCipherReset.DoRandom(size: Int32): TBytes;
 begin
 begin
   Result := TSecureRandom.GetNextBytes(FSecureRandom, size);
   Result := TSecureRandom.GetNextBytes(FSecureRandom, size);
 end;
 end;
@@ -192,7 +190,7 @@ end;
 procedure TTestStreamCipherReset.DoTestReset(const cipher1,
 procedure TTestStreamCipherReset.DoTestReset(const cipher1,
   cipher2: IStreamCipher; const cipherParams: ICipherParameters);
   cipher2: IStreamCipher; const cipherParams: ICipherParameters);
 var
 var
-  plaintext, ciphertext: TCryptoLibByteArray;
+  plaintext, ciphertext: TBytes;
 begin
 begin
   cipher1.Init(true, cipherParams);
   cipher1.Init(true, cipherParams);
   System.SetLength(plaintext, 1023);
   System.SetLength(plaintext, 1023);

+ 10 - 17
CryptoLib.Tests/src/Crypto/XSalsa20Tests.pas

@@ -37,19 +37,12 @@ uses
   ClpIKeyParameter,
   ClpIKeyParameter,
   ClpParametersWithIV,
   ClpParametersWithIV,
   ClpIParametersWithIV,
   ClpIParametersWithIV,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestXSalsa20 = class(TCryptoLibTestCase)
+  TTestXSalsa20 = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
   var
   var
@@ -76,13 +69,13 @@ procedure TTestXSalsa20.DoXSalsa20Test(number: Int32;
 var
 var
   engine: IXSalsa20Engine;
   engine: IXSalsa20Engine;
 var
 var
-  LPlainText, LCipherText, LOutput, LKey, LIV: TCryptoLibByteArray;
+  LPlainText, LCipherText, LOutput, LKey, LIV: TBytes;
 begin
 begin
-  LPlainText := THex.Decode(ATestVectorParams[2]);
+  LPlainText := DecodeHex(ATestVectorParams[2]);
   System.SetLength(LOutput, System.Length(LPlainText));
   System.SetLength(LOutput, System.Length(LPlainText));
-  LKey := THex.Decode(ATestVectorParams[0]);
-  LIV := THex.Decode(ATestVectorParams[1]);
-  LCipherText := THex.Decode(ATestVectorParams[3]);
+  LKey := DecodeHex(ATestVectorParams[0]);
+  LIV := DecodeHex(ATestVectorParams[1]);
+  LCipherText := DecodeHex(ATestVectorParams[3]);
 
 
   engine := TXSalsa20Engine.Create();
   engine := TXSalsa20Engine.Create();
   engine.Init(false, TParametersWithIV.Create(TKeyParameter.Create(LKey)
   engine.Init(false, TParametersWithIV.Create(TKeyParameter.Create(LKey)
@@ -90,10 +83,10 @@ begin
 
 
   engine.ProcessBytes(LPlainText, 0, System.Length(LPlainText), LOutput, 0);
   engine.ProcessBytes(LPlainText, 0, System.Length(LPlainText), LOutput, 0);
 
 
-  if not(TArrayUtils.AreEqual(LCipherText, LOutput)) then
+  if not(AreEqual(LCipherText, LOutput)) then
   begin
   begin
     Fail(Format('Mismatch on %d, Expected %s but found %s',
     Fail(Format('Mismatch on %d, Expected %s but found %s',
-      [number, THex.Encode(LCipherText), THex.Encode(LOutput)]));
+      [number, EncodeHex(LCipherText), EncodeHex(LOutput)]));
   end;
   end;
 
 
 end;
 end;

+ 76 - 0
CryptoLib.Tests/src/CryptoLibTestBase.pas

@@ -0,0 +1,76 @@
+unit CryptoLibTestBase;
+
+interface
+
+{$IFDEF FPC}
+{$WARNINGS OFF}
+{$NOTES OFF}
+{$ENDIF FPC}
+
+uses
+  SysUtils,
+{$IFDEF FPC}
+  fpcunit,
+  testregistry,
+{$ELSE}
+  TestFramework,
+{$ENDIF FPC}
+  ClpEncoders,
+  ClpArrayUtils;
+
+type
+
+  TCryptoLibTestCase = class abstract(TTestCase)
+
+  end;
+
+type
+
+  TCryptoLibAlgorithmTestCase = class abstract(TCryptoLibTestCase)
+  protected
+
+    function DecodeHex(const data: String): TBytes;
+    function EncodeHex(const data: TBytes): String;
+    function DecodeBase64(const data: String): TBytes;
+    procedure ZeroFill(const data: TBytes);
+    function Prepend(const data: TBytes; b: Byte): TBytes;
+    function AreEqual(const A, b: TBytes): Boolean;
+
+  end;
+
+implementation
+
+{ TCryptoLibAlgorithmTestCase }
+
+function TCryptoLibAlgorithmTestCase.DecodeBase64(const data: String): TBytes;
+begin
+  result := TBase64.Decode(data);
+end;
+
+function TCryptoLibAlgorithmTestCase.DecodeHex(const data: String): TBytes;
+begin
+  result := THex.Decode(data);
+end;
+
+function TCryptoLibAlgorithmTestCase.EncodeHex(const data: TBytes): String;
+begin
+  result := THex.Encode(data);
+end;
+
+function TCryptoLibAlgorithmTestCase.Prepend(const data: TBytes;
+  b: Byte): TBytes;
+begin
+  result := TArrayUtils.Prepend(data, b);
+end;
+
+procedure TCryptoLibAlgorithmTestCase.ZeroFill(const data: TBytes);
+begin
+  TArrayUtils.ZeroFill(data);
+end;
+
+function TCryptoLibAlgorithmTestCase.AreEqual(const A, b: TBytes): Boolean;
+begin
+  result := TArrayUtils.AreEqual(A, b);
+end;
+
+end.

+ 11 - 19
CryptoLib.Tests/src/Math/BigIntegerTests.pas

@@ -33,22 +33,15 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpCryptoLibTypes,
-  ClpArrayUtils,
-  ClpEncoders,
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpBigInteger;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpBigInteger,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestBigInteger = class(TCryptoLibTestCase)
+  TTestBigInteger = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -380,10 +373,9 @@ procedure TTestBigInteger.TestConstructors;
 var
 var
   i: Int32;
   i: Int32;
 begin
 begin
+  CheckEqualsBigInteger(TBigInteger.Zero, TBigInteger.Create(TBytes.Create(0)));
   CheckEqualsBigInteger(TBigInteger.Zero,
   CheckEqualsBigInteger(TBigInteger.Zero,
-    TBigInteger.Create(TCryptoLibByteArray.Create(0)));
-  CheckEqualsBigInteger(TBigInteger.Zero,
-    TBigInteger.Create(TCryptoLibByteArray.Create(0, 0)));
+    TBigInteger.Create(TBytes.Create(0, 0)));
 
 
   for i := 0 to System.Pred(10) do
   for i := 0 to System.Pred(10) do
 
 
@@ -482,7 +474,7 @@ begin
 
 
   shift := 63;
   shift := 63;
   a := Fone.ShiftLeft(shift);
   a := Fone.ShiftLeft(shift);
-  b := TBigInteger.Create(1, THex.Decode('2504b470dc188499'));
+  b := TBigInteger.Create(1, DecodeHex('2504b470dc188499'));
   bShift := b.ShiftRight(shift);
   bShift := b.ShiftRight(shift);
 
 
   data := Format('shift:=%d, b:=%s', [shift, b.ToString(16)]);
   data := Format('shift:=%d, b:=%s', [shift, b.ToString(16)]);
@@ -1263,13 +1255,13 @@ end;
 
 
 procedure TTestBigInteger.TestToByteArray;
 procedure TTestBigInteger.TestToByteArray;
 var
 var
-  z, temp, b: TCryptoLibByteArray;
+  z, temp, b: TBytes;
   i: Int32;
   i: Int32;
   x, y: TBigInteger;
   x, y: TBigInteger;
 begin
 begin
   z := TBigInteger.Zero.ToByteArray();
   z := TBigInteger.Zero.ToByteArray();
   System.SetLength(temp, 1);
   System.SetLength(temp, 1);
-  CheckTrue(TArrayUtils.AreEqual(temp, z));
+  CheckTrue(AreEqual(temp, z));
   for i := 16 to 48 do
   for i := 16 to 48 do
   begin
   begin
     x := TBigInteger.ProbablePrime(i, FRandom);
     x := TBigInteger.ProbablePrime(i, FRandom);
@@ -1288,13 +1280,13 @@ end;
 
 
 procedure TTestBigInteger.TestToByteArrayUnsigned;
 procedure TTestBigInteger.TestToByteArrayUnsigned;
 var
 var
-  z, temp, b: TCryptoLibByteArray;
+  z, temp, b: TBytes;
   i: Int32;
   i: Int32;
   x, y: TBigInteger;
   x, y: TBigInteger;
 begin
 begin
   z := TBigInteger.Zero.ToByteArrayUnsigned();
   z := TBigInteger.Zero.ToByteArrayUnsigned();
   System.SetLength(temp, 0);
   System.SetLength(temp, 0);
-  CheckTrue(TArrayUtils.AreEqual(temp, z));
+  CheckTrue(AreEqual(temp, z));
   for i := 16 to 48 do
   for i := 16 to 48 do
   begin
   begin
     x := TBigInteger.ProbablePrime(i, FRandom);
     x := TBigInteger.ProbablePrime(i, FRandom);

+ 6 - 10
CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP256R1FieldTests.pas

@@ -24,6 +24,7 @@ interface
 {$ENDIF FPC}
 {$ENDIF FPC}
 
 
 uses
 uses
+  SysUtils,
 {$IFDEF FPC}
 {$IFDEF FPC}
   fpcunit,
   fpcunit,
   testregistry,
   testregistry,
@@ -32,23 +33,18 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpCryptoLibTypes,
   ClpIX9ECParameters,
   ClpIX9ECParameters,
   ClpSecObjectIdentifiers,
   ClpSecObjectIdentifiers,
   ClpConverters,
   ClpConverters,
   ClpCustomNamedCurves,
   ClpCustomNamedCurves,
   ClpIECC,
   ClpIECC,
-  ClpBigInteger;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpBigInteger,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestSecP256R1Field = class(TCryptoLibTestCase)
+  TTestSecP256R1Field = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FRandom: ISecureRandom;
     FRandom: ISecureRandom;
@@ -166,7 +162,7 @@ end;
 function TTestSecP256R1Field.Nat256_ToBigInteger(const x: TCryptoLibUInt32Array)
 function TTestSecP256R1Field.Nat256_ToBigInteger(const x: TCryptoLibUInt32Array)
   : TBigInteger;
   : TBigInteger;
 var
 var
-  bs, temp: TCryptoLibByteArray;
+  bs, temp: TBytes;
   i: Int32;
   i: Int32;
   x_i: UInt32;
   x_i: UInt32;
 begin
 begin

+ 6 - 10
CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP384R1FieldTests.pas

@@ -24,6 +24,7 @@ interface
 {$ENDIF FPC}
 {$ENDIF FPC}
 
 
 uses
 uses
+  SysUtils,
 {$IFDEF FPC}
 {$IFDEF FPC}
   fpcunit,
   fpcunit,
   testregistry,
   testregistry,
@@ -32,23 +33,18 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpCryptoLibTypes,
   ClpIX9ECParameters,
   ClpIX9ECParameters,
   ClpSecObjectIdentifiers,
   ClpSecObjectIdentifiers,
   ClpConverters,
   ClpConverters,
   ClpCustomNamedCurves,
   ClpCustomNamedCurves,
   ClpIECC,
   ClpIECC,
-  ClpBigInteger;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpBigInteger,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestSecP384R1Field = class(TCryptoLibTestCase)
+  TTestSecP384R1Field = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FRandom: ISecureRandom;
     FRandom: ISecureRandom;
@@ -122,7 +118,7 @@ end;
 function TTestSecP384R1Field.Nat_ToBigInteger(len: Int32;
 function TTestSecP384R1Field.Nat_ToBigInteger(len: Int32;
   const x: TCryptoLibUInt32Array): TBigInteger;
   const x: TCryptoLibUInt32Array): TBigInteger;
 var
 var
-  bs, temp: TCryptoLibByteArray;
+  bs, temp: TBytes;
   i: Int32;
   i: Int32;
   x_i: UInt32;
   x_i: UInt32;
 begin
 begin

+ 3 - 8
CryptoLib.Tests/src/Math/EC/FixedPointTests.pas

@@ -41,17 +41,12 @@ uses
   ClpIFixedPointCombMultiplier,
   ClpIFixedPointCombMultiplier,
   ClpECAlgorithms,
   ClpECAlgorithms,
   ClpIX9ECParameters,
   ClpIX9ECParameters,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestFixedPoint = class(TCryptoLibTestCase)
+  TTestFixedPoint = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     class var
     class var

+ 19 - 28
CryptoLib.Tests/src/Math/EC/Rfc7748/X25519Tests.pas

@@ -34,26 +34,18 @@ uses
   ClpX25519,
   ClpX25519,
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpArrayUtils,
-  ClpEncoders,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestX25519 = class(TCryptoLibTestCase)
+  TTestX25519 = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FRandom: ISecureRandom;
     FRandom: ISecureRandom;
 
 
     procedure CheckECDHVector(const sA, sAPub, sB, sBPub, sK, text: String);
     procedure CheckECDHVector(const sA, sAPub, sB, sBPub, sK, text: String);
     procedure CheckIterated(count: Int32);
     procedure CheckIterated(count: Int32);
-    procedure CheckValue(const n: TCryptoLibByteArray; const text, se: String);
+    procedure CheckValue(const n: TBytes; const text, se: String);
     procedure CheckX25519Vector(const sK, su, se, text: String);
     procedure CheckX25519Vector(const sK, su, se, text: String);
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -77,12 +69,12 @@ implementation
 procedure TTestX25519.CheckECDHVector(const sA, sAPub, sB, sBPub, sK,
 procedure TTestX25519.CheckECDHVector(const sA, sAPub, sB, sBPub, sK,
   text: String);
   text: String);
 var
 var
-  a, b, aPub, bPub, aK, bK: TCryptoLibByteArray;
+  a, b, aPub, bPub, aK, bK: TBytes;
 begin
 begin
-  a := THex.Decode(sA);
+  a := DecodeHex(sA);
   CheckEquals(TX25519.ScalarSize, System.Length(a));
   CheckEquals(TX25519.ScalarSize, System.Length(a));
 
 
-  b := THex.Decode(sB);
+  b := DecodeHex(sB);
   CheckEquals(TX25519.ScalarSize, System.Length(b));
   CheckEquals(TX25519.ScalarSize, System.Length(b));
 
 
   System.SetLength(aPub, TX25519.PointSize);
   System.SetLength(aPub, TX25519.PointSize);
@@ -107,7 +99,7 @@ end;
 
 
 procedure TTestX25519.CheckIterated(count: Int32);
 procedure TTestX25519.CheckIterated(count: Int32);
 var
 var
-  k, u, r: TCryptoLibByteArray;
+  k, u, r: TBytes;
   iterations: Int32;
   iterations: Int32;
 begin
 begin
   CheckEquals(TX25519.PointSize, TX25519.ScalarSize);
   CheckEquals(TX25519.PointSize, TX25519.ScalarSize);
@@ -144,23 +136,22 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TTestX25519.CheckValue(const n: TCryptoLibByteArray;
-  const text, se: String);
+procedure TTestX25519.CheckValue(const n: TBytes; const text, se: String);
 var
 var
-  e: TCryptoLibByteArray;
+  e: TBytes;
 begin
 begin
-  e := THex.Decode(se);
-  CheckTrue(TArrayUtils.AreEqual(e, n), text);
+  e := DecodeHex(se);
+  CheckTrue(AreEqual(e, n), text);
 end;
 end;
 
 
 procedure TTestX25519.CheckX25519Vector(const sK, su, se, text: String);
 procedure TTestX25519.CheckX25519Vector(const sK, su, se, text: String);
 var
 var
-  k, u, r: TCryptoLibByteArray;
+  k, u, r: TBytes;
 begin
 begin
-  k := THex.Decode(sK);
+  k := DecodeHex(sK);
   CheckEquals(TX25519.ScalarSize, System.Length(k));
   CheckEquals(TX25519.ScalarSize, System.Length(k));
 
 
-  u := THex.Decode(su);
+  u := DecodeHex(su);
   CheckEquals(TX25519.PointSize, System.Length(u));
   CheckEquals(TX25519.PointSize, System.Length(u));
 
 
   System.SetLength(r, TX25519.PointSize);
   System.SetLength(r, TX25519.PointSize);
@@ -182,7 +173,7 @@ end;
 
 
 procedure TTestX25519.TestConsistency;
 procedure TTestX25519.TestConsistency;
 var
 var
-  u, k, rF, rV: TCryptoLibByteArray;
+  u, k, rF, rV: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   System.SetLength(u, TX25519.PointSize);
   System.SetLength(u, TX25519.PointSize);
@@ -196,13 +187,13 @@ begin
     FRandom.NextBytes(k);
     FRandom.NextBytes(k);
     TX25519.ScalarMultBase(k, 0, rF, 0);
     TX25519.ScalarMultBase(k, 0, rF, 0);
     TX25519.ScalarMult(k, 0, u, 0, rV, 0);
     TX25519.ScalarMult(k, 0, u, 0, rV, 0);
-    CheckTrue(TArrayUtils.AreEqual(rF, rV), Format('Consistency #%d', [i]));
+    CheckTrue(AreEqual(rF, rV), Format('Consistency #%d', [i]));
   end;
   end;
 end;
 end;
 
 
 procedure TTestX25519.TestECDH;
 procedure TTestX25519.TestECDH;
 var
 var
-  kA, Kb, qA, qB, sA, sB: TCryptoLibByteArray;
+  kA, Kb, qA, qB, sA, sB: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   System.SetLength(kA, TX25519.ScalarSize);
   System.SetLength(kA, TX25519.ScalarSize);
@@ -227,7 +218,7 @@ begin
     TX25519.ScalarMult(Kb, 0, qA, 0, sB, 0);
     TX25519.ScalarMult(Kb, 0, qA, 0, sB, 0);
 
 
     // ... which is the same for both parties.
     // ... which is the same for both parties.
-    if (not TArrayUtils.AreEqual(sA, sB)) then
+    if (not AreEqual(sA, sB)) then
     begin
     begin
       Fail(Format(' %d', [i]));
       Fail(Format(' %d', [i]));
     end;
     end;
@@ -278,7 +269,7 @@ initialization
 // Register any test cases with the test runner
 // Register any test cases with the test runner
 
 
 {$IFDEF FPC}
 {$IFDEF FPC}
- RegisterTest(TTestX25519);
+  RegisterTest(TTestX25519);
 {$ELSE}
 {$ELSE}
   RegisterTest(TTestX25519.Suite);
   RegisterTest(TTestX25519.Suite);
 {$ENDIF FPC}
 {$ENDIF FPC}

+ 36 - 44
CryptoLib.Tests/src/Math/EC/Rfc8032/Ed25519Tests.pas

@@ -36,19 +36,11 @@ uses
   ClpIDigest,
   ClpIDigest,
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpArrayUtils,
-  ClpEncoders,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestEd25519 = class(TCryptoLibTestCase)
+  TTestEd25519 = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
 
 
@@ -86,21 +78,21 @@ implementation
 procedure TTestEd25519.CheckEd25519Vector(const sSK, sPK, sM, sSig,
 procedure TTestEd25519.CheckEd25519Vector(const sSK, sPK, sM, sSig,
   text: String);
   text: String);
 var
 var
-  sk, pk, pkGen, m, sig, badsig, sigGen: TCryptoLibByteArray;
+  sk, pk, pkGen, m, sig, badsig, sigGen: TBytes;
   Ed25519Instance: IEd25519;
   Ed25519Instance: IEd25519;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
 begin
 begin
-  sk := THex.Decode(sSK);
-  pk := THex.Decode(sPK);
+  sk := DecodeHex(sSK);
+  pk := DecodeHex(sPK);
 
 
   System.SetLength(pkGen, TEd25519.PublicKeySize);
   System.SetLength(pkGen, TEd25519.PublicKeySize);
 
 
   Ed25519Instance := TEd25519.Create();
   Ed25519Instance := TEd25519.Create();
   Ed25519Instance.GeneratePublicKey(sk, 0, pkGen, 0);
   Ed25519Instance.GeneratePublicKey(sk, 0, pkGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(pk, pkGen), text);
+  CheckTrue(AreEqual(pk, pkGen), text);
 
 
-  m := THex.Decode(sM);
-  sig := THex.Decode(sSig);
+  m := DecodeHex(sM);
+  sig := DecodeHex(sSig);
 
 
   badsig := System.Copy(sig);
   badsig := System.Copy(sig);
 
 
@@ -110,10 +102,10 @@ begin
   System.SetLength(sigGen, TEd25519.SignatureSize);
   System.SetLength(sigGen, TEd25519.SignatureSize);
 
 
   Ed25519Instance.Sign(sk, 0, m, 0, System.Length(m), sigGen, 0);
   Ed25519Instance.Sign(sk, 0, m, 0, System.Length(m), sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   Ed25519Instance.Sign(sk, 0, pk, 0, m, 0, System.Length(m), sigGen, 0);
   Ed25519Instance.Sign(sk, 0, pk, 0, m, 0, System.Length(m), sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   shouldVerify := Ed25519Instance.Verify(sig, 0, pk, 0, m, 0, System.Length(m));
   shouldVerify := Ed25519Instance.Verify(sig, 0, pk, 0, m, 0, System.Length(m));
   CheckTrue(shouldVerify, text);
   CheckTrue(shouldVerify, text);
@@ -126,22 +118,22 @@ end;
 procedure TTestEd25519.CheckEd25519ctxVector(const sSK, sPK, sM, sCTX, sSig,
 procedure TTestEd25519.CheckEd25519ctxVector(const sSK, sPK, sM, sCTX, sSig,
   text: String);
   text: String);
 var
 var
-  sk, pk, pkGen, m, ctx, sig, badsig, sigGen: TCryptoLibByteArray;
+  sk, pk, pkGen, m, ctx, sig, badsig, sigGen: TBytes;
   Ed25519Instance: IEd25519;
   Ed25519Instance: IEd25519;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
 begin
 begin
-  sk := THex.Decode(sSK);
-  pk := THex.Decode(sPK);
+  sk := DecodeHex(sSK);
+  pk := DecodeHex(sPK);
 
 
   System.SetLength(pkGen, TEd25519.PublicKeySize);
   System.SetLength(pkGen, TEd25519.PublicKeySize);
 
 
   Ed25519Instance := TEd25519.Create();
   Ed25519Instance := TEd25519.Create();
   Ed25519Instance.GeneratePublicKey(sk, 0, pkGen, 0);
   Ed25519Instance.GeneratePublicKey(sk, 0, pkGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(pk, pkGen), text);
+  CheckTrue(AreEqual(pk, pkGen), text);
 
 
-  m := THex.Decode(sM);
-  ctx := THex.Decode(sCTX);
-  sig := THex.Decode(sSig);
+  m := DecodeHex(sM);
+  ctx := DecodeHex(sCTX);
+  sig := DecodeHex(sSig);
 
 
   badsig := System.Copy(sig);
   badsig := System.Copy(sig);
 
 
@@ -151,10 +143,10 @@ begin
   System.SetLength(sigGen, TEd25519.SignatureSize);
   System.SetLength(sigGen, TEd25519.SignatureSize);
 
 
   Ed25519Instance.Sign(sk, 0, ctx, m, 0, System.Length(m), sigGen, 0);
   Ed25519Instance.Sign(sk, 0, ctx, m, 0, System.Length(m), sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   Ed25519Instance.Sign(sk, 0, pk, 0, ctx, m, 0, System.Length(m), sigGen, 0);
   Ed25519Instance.Sign(sk, 0, pk, 0, ctx, m, 0, System.Length(m), sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   shouldVerify := Ed25519Instance.Verify(sig, 0, pk, 0, ctx, m, 0,
   shouldVerify := Ed25519Instance.Verify(sig, 0, pk, 0, ctx, m, 0,
     System.Length(m));
     System.Length(m));
@@ -168,23 +160,23 @@ end;
 procedure TTestEd25519.CheckEd25519phVector(const sSK, sPK, sM, sCTX, sSig,
 procedure TTestEd25519.CheckEd25519phVector(const sSK, sPK, sM, sCTX, sSig,
   text: String);
   text: String);
 var
 var
-  sk, pk, pkGen, m, ph, ctx, sig, badsig, sigGen: TCryptoLibByteArray;
+  sk, pk, pkGen, m, ph, ctx, sig, badsig, sigGen: TBytes;
   Ed25519Instance: IEd25519;
   Ed25519Instance: IEd25519;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
   prehash: IDigest;
   prehash: IDigest;
 begin
 begin
-  sk := THex.Decode(sSK);
-  pk := THex.Decode(sPK);
+  sk := DecodeHex(sSK);
+  pk := DecodeHex(sPK);
 
 
   System.SetLength(pkGen, TEd25519.PublicKeySize);
   System.SetLength(pkGen, TEd25519.PublicKeySize);
 
 
   Ed25519Instance := TEd25519.Create();
   Ed25519Instance := TEd25519.Create();
   Ed25519Instance.GeneratePublicKey(sk, 0, pkGen, 0);
   Ed25519Instance.GeneratePublicKey(sk, 0, pkGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(pk, pkGen), text);
+  CheckTrue(AreEqual(pk, pkGen), text);
 
 
-  m := THex.Decode(sM);
-  ctx := THex.Decode(sCTX);
-  sig := THex.Decode(sSig);
+  m := DecodeHex(sM);
+  ctx := DecodeHex(sCTX);
+  sig := DecodeHex(sSig);
 
 
   badsig := System.Copy(sig);
   badsig := System.Copy(sig);
 
 
@@ -201,10 +193,10 @@ begin
   prehash.DoFinal(ph, 0);
   prehash.DoFinal(ph, 0);
 
 
   Ed25519Instance.SignPreHash(sk, 0, ctx, ph, 0, sigGen, 0);
   Ed25519Instance.SignPreHash(sk, 0, ctx, ph, 0, sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   Ed25519Instance.SignPreHash(sk, 0, pk, 0, ctx, ph, 0, sigGen, 0);
   Ed25519Instance.SignPreHash(sk, 0, pk, 0, ctx, ph, 0, sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   shouldVerify := Ed25519Instance.VerifyPreHash(sig, 0, pk, 0, ctx, ph, 0);
   shouldVerify := Ed25519Instance.VerifyPreHash(sig, 0, pk, 0, ctx, ph, 0);
   CheckTrue(shouldVerify, text);
   CheckTrue(shouldVerify, text);
@@ -217,13 +209,13 @@ begin
   prehash.BlockUpdate(m, 0, System.Length(m));
   prehash.BlockUpdate(m, 0, System.Length(m));
 
 
   Ed25519Instance.SignPreHash(sk, 0, ctx, prehash, sigGen, 0);
   Ed25519Instance.SignPreHash(sk, 0, ctx, prehash, sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   prehash := Ed25519Instance.CreatePreHash();
   prehash := Ed25519Instance.CreatePreHash();
   prehash.BlockUpdate(m, 0, System.Length(m));
   prehash.BlockUpdate(m, 0, System.Length(m));
 
 
   Ed25519Instance.SignPreHash(sk, 0, pk, 0, ctx, prehash, sigGen, 0);
   Ed25519Instance.SignPreHash(sk, 0, pk, 0, ctx, prehash, sigGen, 0);
-  CheckTrue(TArrayUtils.AreEqual(sig, sigGen), text);
+  CheckTrue(AreEqual(sig, sigGen), text);
 
 
   prehash := Ed25519Instance.CreatePreHash();
   prehash := Ed25519Instance.CreatePreHash();
   prehash.BlockUpdate(m, 0, System.Length(m));
   prehash.BlockUpdate(m, 0, System.Length(m));
@@ -255,7 +247,7 @@ end;
 
 
 procedure TTestEd25519.TestEd25519Consistency;
 procedure TTestEd25519.TestEd25519Consistency;
 var
 var
-  sk, pk, m, sig1, sig2: TCryptoLibByteArray;
+  sk, pk, m, sig1, sig2: TBytes;
   i, mLen: Int32;
   i, mLen: Int32;
   Ed25519Instance: IEd25519;
   Ed25519Instance: IEd25519;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
@@ -279,7 +271,7 @@ begin
     Ed25519Instance.Sign(sk, 0, m, 0, mLen, sig1, 0);
     Ed25519Instance.Sign(sk, 0, m, 0, mLen, sig1, 0);
     Ed25519Instance.Sign(sk, 0, pk, 0, m, 0, mLen, sig2, 0);
     Ed25519Instance.Sign(sk, 0, pk, 0, m, 0, mLen, sig2, 0);
 
 
-    CheckTrue(TArrayUtils.AreEqual(sig1, sig2),
+    CheckTrue(AreEqual(sig1, sig2),
       Format('Ed25519 consistent signatures #%d', [i]));
       Format('Ed25519 consistent signatures #%d', [i]));
 
 
     shouldVerify := Ed25519Instance.Verify(sig1, 0, pk, 0, m, 0, mLen);
     shouldVerify := Ed25519Instance.Verify(sig1, 0, pk, 0, m, 0, mLen);
@@ -297,7 +289,7 @@ end;
 
 
 procedure TTestEd25519.TestEd25519ctxConsistency;
 procedure TTestEd25519.TestEd25519ctxConsistency;
 var
 var
-  sk, pk, ctx, m, sig1, sig2: TCryptoLibByteArray;
+  sk, pk, ctx, m, sig1, sig2: TBytes;
   i, mLen: Int32;
   i, mLen: Int32;
   Ed25519Instance: IEd25519;
   Ed25519Instance: IEd25519;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
@@ -323,7 +315,7 @@ begin
     Ed25519Instance.Sign(sk, 0, ctx, m, 0, mLen, sig1, 0);
     Ed25519Instance.Sign(sk, 0, ctx, m, 0, mLen, sig1, 0);
     Ed25519Instance.Sign(sk, 0, pk, 0, ctx, m, 0, mLen, sig2, 0);
     Ed25519Instance.Sign(sk, 0, pk, 0, ctx, m, 0, mLen, sig2, 0);
 
 
-    CheckTrue(TArrayUtils.AreEqual(sig1, sig2),
+    CheckTrue(AreEqual(sig1, sig2),
       Format('Ed25519ctx consistent signatures #%d', [i]));
       Format('Ed25519ctx consistent signatures #%d', [i]));
 
 
     shouldVerify := Ed25519Instance.Verify(sig1, 0, pk, 0, ctx, m, 0, mLen);
     shouldVerify := Ed25519Instance.Verify(sig1, 0, pk, 0, ctx, m, 0, mLen);
@@ -483,7 +475,7 @@ end;
 
 
 procedure TTestEd25519.TestEd25519phConsistency;
 procedure TTestEd25519.TestEd25519phConsistency;
 var
 var
-  sk, pk, ctx, m, ph, sig1, sig2: TCryptoLibByteArray;
+  sk, pk, ctx, m, ph, sig1, sig2: TBytes;
   i, mLen: Int32;
   i, mLen: Int32;
   Ed25519Instance: IEd25519;
   Ed25519Instance: IEd25519;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
@@ -515,7 +507,7 @@ begin
     Ed25519Instance.SignPreHash(sk, 0, ctx, ph, 0, sig1, 0);
     Ed25519Instance.SignPreHash(sk, 0, ctx, ph, 0, sig1, 0);
     Ed25519Instance.SignPreHash(sk, 0, pk, 0, ctx, ph, 0, sig2, 0);
     Ed25519Instance.SignPreHash(sk, 0, pk, 0, ctx, ph, 0, sig2, 0);
 
 
-    CheckTrue(TArrayUtils.AreEqual(sig1, sig2),
+    CheckTrue(AreEqual(sig1, sig2),
       Format('Ed25519ph consistent signatures #%d', [i]));
       Format('Ed25519ph consistent signatures #%d', [i]));
 
 
     shouldVerify := Ed25519Instance.VerifyPreHash(sig1, 0, pk, 0, ctx, ph, 0);
     shouldVerify := Ed25519Instance.VerifyPreHash(sig1, 0, pk, 0, ctx, ph, 0);

+ 3 - 8
CryptoLib.Tests/src/Math/ECAlgorithmsTests.pas

@@ -46,17 +46,12 @@ uses
   ClpECAlgorithms,
   ClpECAlgorithms,
   ClpX9ECParameters,
   ClpX9ECParameters,
   ClpIX9ECParameters,
   ClpIX9ECParameters,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestECAlgorithms = class(TCryptoLibTestCase)
+  TTestECAlgorithms = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     class var
     class var

+ 41 - 47
CryptoLib.Tests/src/Math/ECIESTests.pas

@@ -72,24 +72,17 @@ uses
   ClpIKeyEncoder,
   ClpIKeyEncoder,
   ClpAesEngine,
   ClpAesEngine,
   ClpIAesEngine,
   ClpIAesEngine,
-  ClpEncoders,
-  ClpArrayUtils,
   ClpBigInteger,
   ClpBigInteger,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// test for ECIES - Elliptic Curve Integrated Encryption Scheme
   /// test for ECIES - Elliptic Curve Integrated Encryption Scheme
   /// </summary>
   /// </summary>
-  TTestECIES = class(TCryptoLibTestCase)
+  TTestECIES = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FAES_IV: TBytes;
     FAES_IV: TBytes;
@@ -141,8 +134,8 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   params := TECDomainParameters.Create(curve,
   params := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
+    curve.DecodePoint
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
     n);
     n);
 
 
   priKey := TECPrivateKeyParameters.Create
   priKey := TECPrivateKeyParameters.Create
@@ -151,8 +144,8 @@ begin
     params);
     params);
 
 
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
-    ('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')), // Q
+    (curve.DecodePoint
+    (DecodeHex('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')), // Q
     params);
     params);
 
 
   p1 := TAsymmetricCipherKeyPair.Create(pubKey, priKey);
   p1 := TAsymmetricCipherKeyPair.Create(pubKey, priKey);
@@ -188,12 +181,12 @@ begin
   i2.Init(p1.Private, p, TECIESPublicKeyParser.Create(params)
   i2.Init(p1.Private, p, TECIESPublicKeyParser.Create(params)
     as IECIESPublicKeyParser);
     as IECIESPublicKeyParser);
 
 
-  &message := THex.Decode('1234567890abcdef');
+  &message := DecodeHex('1234567890abcdef');
 
 
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('stream cipher test failed');
     Fail('stream cipher test failed');
   end;
   end;
@@ -233,13 +226,13 @@ begin
   i2.Init(p1.Private, p, TECIESPublicKeyParser.Create(params)
   i2.Init(p1.Private, p, TECIESPublicKeyParser.Create(params)
     as IECIESPublicKeyParser);
     as IECIESPublicKeyParser);
 
 
-  &message := THex.Decode('1234567890abcdef');
+  &message := DecodeHex('1234567890abcdef');
 
 
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
 
 
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('AES cipher test failed');
     Fail('AES cipher test failed');
   end;
   end;
@@ -272,8 +265,8 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   params := TECDomainParameters.Create(curve,
   params := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
+    curve.DecodePoint
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
     n);
     n);
 
 
   priKey := TECPrivateKeyParameters.Create
   priKey := TECPrivateKeyParameters.Create
@@ -282,8 +275,8 @@ begin
     params);
     params);
 
 
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
-    ('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')), // Q
+    (curve.DecodePoint
+    (DecodeHex('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')), // Q
     params);
     params);
 
 
   p1 := TAsymmetricCipherKeyPair.Create(pubKey, priKey);
   p1 := TAsymmetricCipherKeyPair.Create(pubKey, priKey);
@@ -314,7 +307,7 @@ begin
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('stream cipher test failed');
     Fail('stream cipher test failed');
   end;
   end;
@@ -358,7 +351,7 @@ begin
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('V cipher test failed');
     Fail('V cipher test failed');
   end;
   end;
@@ -409,8 +402,8 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   params := TECDomainParameters.Create(curve,
   params := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
+    curve.DecodePoint
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   priKey := TECPrivateKeyParameters.Create
   priKey := TECPrivateKeyParameters.Create
@@ -419,8 +412,8 @@ begin
     params);
     params);
 
 
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
-    ('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')), // Q
+    (curve.DecodePoint
+    (DecodeHex('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')), // Q
     params);
     params);
 
 
   p1 := TAsymmetricCipherKeyPair.Create(pubKey, priKey);
   p1 := TAsymmetricCipherKeyPair.Create(pubKey, priKey);
@@ -446,20 +439,19 @@ begin
   i1.Init(true, p1.Private, p2.Public, p);
   i1.Init(true, p1.Private, p2.Public, p);
   i2.Init(false, p2.getPrivate, p1.getPublic, p);
   i2.Init(false, p2.getPrivate, p1.getPublic, p);
 
 
-  &message := THex.Decode('1234567890abcdef');
+  &message := DecodeHex('1234567890abcdef');
 
 
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
 
 
-  if (not TArrayUtils.AreEqual(out1,
-    THex.Decode('468d89877e8238802403ec4cb6b329faeccfa6f3a730f2cdb3c0a8e8')))
-  then
+  if (not AreEqual(out1,
+    DecodeHex('468d89877e8238802403ec4cb6b329faeccfa6f3a730f2cdb3c0a8e8'))) then
   begin
   begin
     Fail('stream cipher test failed on enc');
     Fail('stream cipher test failed on enc');
   end;
   end;
 
 
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('stream cipher test failed');
     Fail('stream cipher test failed');
   end;
   end;
@@ -498,29 +490,31 @@ begin
   i1.Init(true, p1.Private, p2.Public, p);
   i1.Init(true, p1.Private, p2.Public, p);
   i2.Init(false, p2.Private, p1.Public, p);
   i2.Init(false, p2.Private, p1.Public, p);
 
 
-  &message := THex.Decode('1234567890abcdef');
+  &message := DecodeHex('1234567890abcdef');
 
 
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
 
 
   if iv = Nil then
   if iv = Nil then
   begin
   begin
-    compareValue := THex.Decode
-      ('33578c27c3c044a535d42b9fe77003c3c4c9a74b987adac5c21c920b4b878debdefdff1e');
+    compareValue :=
+      DecodeHex(
+      '33578c27c3c044a535d42b9fe77003c3c4c9a74b987adac5c21c920b4b878debdefdff1e');
   end
   end
   else
   else
   begin
   begin
-    compareValue := THex.Decode
-      ('cae615459828884e5444a33a0271d763a8ca8affc60b8551a5fb2cc362409c0226e225e0');
+    compareValue :=
+      DecodeHex(
+      'cae615459828884e5444a33a0271d763a8ca8affc60b8551a5fb2cc362409c0226e225e0');
   end;
   end;
 
 
-  if (not TArrayUtils.AreEqual(out1, compareValue)) then
+  if (not AreEqual(out1, compareValue)) then
   begin
   begin
     Fail('AES cipher test failed on enc');
     Fail('AES cipher test failed on enc');
   end;
   end;
 
 
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('AES cipher test failed');
     Fail('AES cipher test failed');
   end;
   end;
@@ -554,13 +548,13 @@ begin
   i1.Init(true, p1.Private, p2.Public, p);
   i1.Init(true, p1.Private, p2.Public, p);
   i2.Init(false, p2.getPrivate, p1.getPublic, p);
   i2.Init(false, p2.getPrivate, p1.getPublic, p);
 
 
-  &message := THex.Decode('1234567890abcdef');
+  &message := DecodeHex('1234567890abcdef');
 
 
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
 
 
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('stream cipher test failed');
     Fail('stream cipher test failed');
   end;
   end;
@@ -594,13 +588,13 @@ begin
   i1.Init(true, p1.Private, p2.Public, p);
   i1.Init(true, p1.Private, p2.Public, p);
   i2.Init(false, p2.Private, p1.Public, p);
   i2.Init(false, p2.Private, p1.Public, p);
 
 
-  &message := THex.Decode('1234567890abcdef');
+  &message := DecodeHex('1234567890abcdef');
 
 
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
   out1 := i1.ProcessBlock(&message, 0, System.Length(&message));
 
 
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
   out2 := i2.ProcessBlock(out1, 0, System.Length(out1));
 
 
-  if (not TArrayUtils.AreEqual(out2, &message)) then
+  if (not AreEqual(out2, &message)) then
   begin
   begin
     Fail('AES cipher test failed');
     Fail('AES cipher test failed');
   end;
   end;
@@ -609,7 +603,7 @@ end;
 procedure TTestECIES.SetUp;
 procedure TTestECIES.SetUp;
 begin
 begin
   inherited;
   inherited;
-  FAES_IV := THex.Decode('000102030405060708090a0b0c0d0e0f');
+  FAES_IV := DecodeHex('000102030405060708090a0b0c0d0e0f');
 end;
 end;
 
 
 procedure TTestECIES.TearDown;
 procedure TTestECIES.TearDown;
@@ -644,8 +638,8 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   params := TECDomainParameters.Create(curve,
   params := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
+    curve.DecodePoint
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')), // G
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   eGen := TECKeyPairGenerator.Create();
   eGen := TECKeyPairGenerator.Create();

+ 30 - 31
CryptoLib.Tests/src/Math/ECNRTests.pas

@@ -49,32 +49,25 @@ uses
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
   ClpFixedSecureRandom,
   ClpFixedSecureRandom,
-  ClpEncoders,
   ClpSignerUtilities,
   ClpSignerUtilities,
   ClpBigInteger,
   ClpBigInteger,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// ECNR tests.
   /// ECNR tests.
   /// </summary>
   /// </summary>
-  TTestECNR = class(TCryptoLibTestCase)
+  TTestECNR = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     procedure DoCheckSignature(size: Int32; const sKey: IECPrivateKeyParameters;
     procedure DoCheckSignature(size: Int32; const sKey: IECPrivateKeyParameters;
       const vKey: IECPublicKeyParameters; const sgr: ISigner;
       const vKey: IECPublicKeyParameters; const sgr: ISigner;
-      const k: ISecureRandom; const &message: TCryptoLibByteArray;
-      const r, s: TBigInteger);
+      const k: ISecureRandom; const &message: TBytes; const r, s: TBigInteger);
 
 
-    function DoDerDecode(const encoding: TCryptoLibByteArray)
+    function DoDerDecode(const encoding: TBytes)
       : TCryptoLibGenericArray<TBigInteger>;
       : TCryptoLibGenericArray<TBigInteger>;
 
 
   protected
   protected
@@ -136,8 +129,8 @@ implementation
 
 
 procedure TTestECNR.DoCheckSignature(size: Int32;
 procedure TTestECNR.DoCheckSignature(size: Int32;
   const sKey: IECPrivateKeyParameters; const vKey: IECPublicKeyParameters;
   const sKey: IECPrivateKeyParameters; const vKey: IECPublicKeyParameters;
-  const sgr: ISigner; const k: ISecureRandom;
-  const &message: TCryptoLibByteArray; const r, s: TBigInteger);
+  const sgr: ISigner; const k: ISecureRandom; const &message: TBytes;
+  const r, s: TBigInteger);
 var
 var
   sigBytes: TBytes;
   sigBytes: TBytes;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
@@ -175,7 +168,7 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TTestECNR.DoDerDecode(const encoding: TCryptoLibByteArray)
+function TTestECNR.DoDerDecode(const encoding: TBytes)
   : TCryptoLibGenericArray<TBigInteger>;
   : TCryptoLibGenericArray<TBigInteger>;
 var
 var
   s: IAsn1Sequence;
   s: IAsn1Sequence;
@@ -232,8 +225,8 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('03188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012')), // G
+    curve.DecodePoint
+    (DecodeHex('03188DA80EB03090F67CBF20EB43A18800F4FF0AFD82FF1012')), // G
     TBigInteger.Create
     TBigInteger.Create
     ('6277101735386680763835789423176059013767194773182842284081')
     ('6277101735386680763835789423176059013767194773182842284081')
     // n
     // n
@@ -246,8 +239,8 @@ begin
     parameters);
     parameters);
 
 
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
-    ('0262B12D60690CDCF330BABAB6E69763B471F994DD702D16A5')), // Q
+    (curve.DecodePoint
+    (DecodeHex('0262B12D60690CDCF330BABAB6E69763B471F994DD702D16A5')), // Q
     parameters);
     parameters);
 
 
   sgr := TSignerUtilities.GetSigner('SHA1withECNR');
   sgr := TSignerUtilities.GetSigner('SHA1withECNR');
@@ -295,7 +288,8 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
@@ -328,7 +322,8 @@ begin
 
 
   // Verify the signature
   // Verify the signature
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
+    (curve.DecodePoint
+    (DecodeHex
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     parameters);
     parameters);
 
 
@@ -373,7 +368,8 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     TBigInteger.Create
     TBigInteger.Create
     ('883423532389192164791648750360308884807550341691627752275345424702807307'),
     ('883423532389192164791648750360308884807550341691627752275345424702807307'),
@@ -387,7 +383,8 @@ begin
     parameters);
     parameters);
 
 
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
+    (curve.DecodePoint
+    (DecodeHex
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')), // Q
     parameters);
     parameters);
 
 
@@ -430,15 +427,16 @@ begin
     ('0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00',
     ('0051953EB9618E1C9A1F929A21A0B68540EEA2DA725B99B315F3B8B489918EF109E156193951EC7E937B1652C0BD3BB1BF073573DF883D2C34F1EF451FD46B503F00',
     16), // b
     16), // b
     TBigInteger.Create(1,
     TBigInteger.Create(1,
-    THex.Decode
-    ('01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409')
+    DecodeHex(
+    '01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409')
     ), TBigInteger.One);
     ), TBigInteger.One);
   // b
   // b
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66')
-    ), // G
+    curve.DecodePoint
+    (DecodeHex
+    ('0200C6858E06B70404E9CD9E3ECB662395B4429C648139053FB521F828AF606B4D3DBAA14B5E77EFE75928FE1DC127A2FFA8DE3348B3C1856A429BF97E7E31C2E5BD66')),
+    // G
     TBigInteger.Create
     TBigInteger.Create
     ('01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409',
     ('01FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA51868783BF2F966B7FCC0148F709A5D03BB5C9B8899C47AEBB6FB71E91386409',
     16)
     16)
@@ -452,9 +450,10 @@ begin
     parameters);
     parameters);
 
 
   pubKey := TECPublicKeyParameters.Create
   pubKey := TECPublicKeyParameters.Create
-    (curve.DecodePoint(THex.Decode
-    ('02006BFDD2C9278B63C92D6624F151C9D7A822CC75BD983B17D25D74C26740380022D3D8FAF304781E416175EADF4ED6E2B47142D2454A7AC7801DD803CF44A4D1F0AC')
-    ), // Q
+    (curve.DecodePoint
+    (DecodeHex
+    ('02006BFDD2C9278B63C92D6624F151C9D7A822CC75BD983B17D25D74C26740380022D3D8FAF304781E416175EADF4ED6E2B47142D2454A7AC7801DD803CF44A4D1F0AC')),
+    // Q
     parameters);
     parameters);
 
 
   sgr := TSignerUtilities.GetSigner('SHA512withECNR');
   sgr := TSignerUtilities.GetSigner('SHA512withECNR');

+ 6 - 14
CryptoLib.Tests/src/Math/ECPointTests.pas

@@ -45,13 +45,7 @@ uses
   ClpIX9ECParameters,
   ClpIX9ECParameters,
   ClpECC,
   ClpECC,
   ClpIECC,
   ClpIECC,
-  ClpArrayUtils;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
   // /**
   // /**
@@ -100,7 +94,7 @@ type
 
 
 type
 type
 
 
-  TTestECPoint = class(TCryptoLibTestCase)
+  TTestECPoint = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -115,8 +109,7 @@ type
     procedure AssertBigIntegersEqual(const a, b: TBigInteger);
     procedure AssertBigIntegersEqual(const a, b: TBigInteger);
     procedure AssertIFiniteFieldsEqual(const a, b: IFiniteField);
     procedure AssertIFiniteFieldsEqual(const a, b: IFiniteField);
     procedure AssertOptionalValuesAgree(const a, b: TBigInteger); overload;
     procedure AssertOptionalValuesAgree(const a, b: TBigInteger); overload;
-    procedure AssertOptionalValuesAgree(const a,
-      b: TCryptoLibByteArray); overload;
+    procedure AssertOptionalValuesAgree(const a, b: TBytes); overload;
 
 
     procedure AssertECFieldElementsEqual(const a, b: IECFieldElement);
     procedure AssertECFieldElementsEqual(const a, b: IECFieldElement);
 
 
@@ -281,12 +274,11 @@ begin
   end;
   end;
 end;
 end;
 
 
-procedure TTestECPoint.AssertOptionalValuesAgree(const a,
-  b: TCryptoLibByteArray);
+procedure TTestECPoint.AssertOptionalValuesAgree(const a, b: TBytes);
 begin
 begin
   if ((a <> Nil) and (b <> Nil)) then
   if ((a <> Nil) and (b <> Nil)) then
   begin
   begin
-    CheckTrue(TArrayUtils.AreEqual(a, b));
+    CheckTrue(AreEqual(a, b));
   end;
   end;
 end;
 end;
 
 
@@ -455,7 +447,7 @@ end;
 
 
 procedure TTestECPoint.ImplTestEncoding(const p: IECPoint);
 procedure TTestECPoint.ImplTestEncoding(const p: IECPoint);
 var
 var
-  unCompBarr, compBarr: TCryptoLibByteArray;
+  unCompBarr, compBarr: TBytes;
   decUnComp, decComp: IECPoint;
   decUnComp, decComp: IECPoint;
 begin
 begin
   // Not Point Compression
   // Not Point Compression

+ 5 - 12
CryptoLib.Tests/src/Math/IESCipherTests.pas

@@ -68,21 +68,14 @@ uses
   ClpIECPrivateKeyParameters,
   ClpIECPrivateKeyParameters,
   ClpIIESCipher,
   ClpIIESCipher,
   ClpIESCipher,
   ClpIESCipher,
-  ClpEncoders,
   ClpDigestUtilities,
   ClpDigestUtilities,
   ClpMacUtilities,
   ClpMacUtilities,
   ClpConverters,
   ClpConverters,
-  ClpArrayUtils;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestIESCipher = class(TCryptoLibTestCase)
+  TTestIESCipher = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     function GetECIESAES256CBCEngine: IIESEngine;
     function GetECIESAES256CBCEngine: IIESEngine;
@@ -128,10 +121,10 @@ begin
     param, Random);
     param, Random);
   DecryptionResultBytes := CipherDecrypt.DoFinal(CipherTextBytes);
   DecryptionResultBytes := CipherDecrypt.DoFinal(CipherTextBytes);
 
 
-  if (not TArrayUtils.AreEqual(PlainTextBytes, DecryptionResultBytes)) then
+  if (not AreEqual(PlainTextBytes, DecryptionResultBytes)) then
   begin
   begin
     Fail(Format('Decryption Failed - Expected %s but got %s',
     Fail(Format('Decryption Failed - Expected %s but got %s',
-      [THex.Encode(PlainTextBytes), THex.Encode(DecryptionResultBytes)]));
+      [EncodeHex(PlainTextBytes), EncodeHex(DecryptionResultBytes)]));
   end;
   end;
 end;
 end;
 
 
@@ -249,7 +242,7 @@ begin
   begin
   begin
     System.SetLength(RandomBytes, Byte(RandomInstance.NextInt32));
     System.SetLength(RandomBytes, Byte(RandomInstance.NextInt32));
     RandomInstance.NextBytes(RandomBytes);
     RandomInstance.NextBytes(RandomBytes);
-    PlainText := THex.Encode(RandomBytes);
+    PlainText := EncodeHex(RandomBytes);
 
 
     // Call IESCipher Encryption and Decryption Method
     // Call IESCipher Encryption and Decryption Method
 
 

+ 6 - 13
CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas

@@ -36,7 +36,6 @@ uses
   ClpIBlockCipherModes,
   ClpIBlockCipherModes,
   ClpAesEngine,
   ClpAesEngine,
   ClpIAesEngine,
   ClpIAesEngine,
-  ClpEncoders,
   ClpBigInteger,
   ClpBigInteger,
   ClpCustomNamedCurves,
   ClpCustomNamedCurves,
   ClpDigestUtilities,
   ClpDigestUtilities,
@@ -52,13 +51,7 @@ uses
   ClpMacUtilities,
   ClpMacUtilities,
   ClpIX9ECParameters,
   ClpIX9ECParameters,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -66,7 +59,7 @@ type
   /// Test for PascalCoin ECIES - PascalCoin Elliptic Curve Integrated Encryption Scheme
   /// Test for PascalCoin ECIES - PascalCoin Elliptic Curve Integrated Encryption Scheme
   /// Test vectors were gotten from the PascalCoin TESTNET Wallet.
   /// Test vectors were gotten from the PascalCoin TESTNET Wallet.
   /// </summary>
   /// </summary>
-  TTestPascalCoinECIES = class(TCryptoLibTestCase)
+  TTestPascalCoinECIES = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     type
     type
@@ -249,9 +242,9 @@ begin
   // Encryption
   // Encryption
   CipherEncrypt := TIESCipher.Create(GetECIESPascalCoinCompatibilityEngine());
   CipherEncrypt := TIESCipher.Create(GetECIESPascalCoinCompatibilityEngine());
   CipherEncrypt.Init(True, RecreatePublicKeyFromAffineXandAffineYCoord(keyType,
   CipherEncrypt.Init(True, RecreatePublicKeyFromAffineXandAffineYCoord(keyType,
-    THex.Decode(RawAffineXCoord), THex.Decode(RawAffineYCoord)),
+    DecodeHex(RawAffineXCoord), DecodeHex(RawAffineYCoord)),
     GetPascalCoinIESParameterSpec(), FRandom);
     GetPascalCoinIESParameterSpec(), FRandom);
-  Result := THex.Encode(CipherEncrypt.DoFinal(TConverters.ConvertStringToBytes
+  Result := EncodeHex(CipherEncrypt.DoFinal(TConverters.ConvertStringToBytes
     (PayloadToEncrypt, TEncoding.ASCII)));
     (PayloadToEncrypt, TEncoding.ASCII)));
 end;
 end;
 
 
@@ -264,10 +257,10 @@ begin
     // Decryption
     // Decryption
     CipherDecrypt := TIESCipher.Create(GetECIESPascalCoinCompatibilityEngine());
     CipherDecrypt := TIESCipher.Create(GetECIESPascalCoinCompatibilityEngine());
     CipherDecrypt.Init(False, RecreatePrivateKeyFromByteArray(keyType,
     CipherDecrypt.Init(False, RecreatePrivateKeyFromByteArray(keyType,
-      THex.Decode(RawPrivateKey)), GetPascalCoinIESParameterSpec(), FRandom);
+      DecodeHex(RawPrivateKey)), GetPascalCoinIESParameterSpec(), FRandom);
 
 
     Result := TConverters.ConvertBytesToString
     Result := TConverters.ConvertBytesToString
-      (CipherDecrypt.DoFinal(THex.Decode(PayloadToDecrypt)), TEncoding.ASCII);
+      (CipherDecrypt.DoFinal(DecodeHex(PayloadToDecrypt)), TEncoding.ASCII);
   except
   except
     // should only happen if decryption fails
     // should only happen if decryption fails
     raise;
     raise;

+ 13 - 20
CryptoLib.Tests/src/Others/DigestTests.pas

@@ -35,20 +35,13 @@ uses
   ClpRosstandartObjectIdentifiers,
   ClpRosstandartObjectIdentifiers,
   ClpIDigest,
   ClpIDigest,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpCryptoLibTypes,
-  ClpConverters;
+  ClpConverters,
+  CryptoLibTestBase,
+  ClpCryptoLibTypes;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestDigest = class(TCryptoLibTestCase)
+  TTestDigest = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FabcVectors: TCryptoLibMatrixGenericArray<String>;
     FabcVectors: TCryptoLibMatrixGenericArray<String>;
@@ -177,7 +170,7 @@ end;
 
 
 procedure TTestDigest.DoAbcTest(const algorithm, hash: String);
 procedure TTestDigest.DoAbcTest(const algorithm, hash: String);
 var
 var
-  abc, result: TCryptoLibByteArray;
+  abc, result: TBytes;
   digest: IDigest;
   digest: IDigest;
 begin
 begin
   abc := TBytes.Create($61, $62, $63);
   abc := TBytes.Create($61, $62, $63);
@@ -187,7 +180,7 @@ begin
   digest.BlockUpdate(abc, 0, System.Length(abc));
   digest.BlockUpdate(abc, 0, System.Length(abc));
   result := TDigestUtilities.DoFinal(digest);
   result := TDigestUtilities.DoFinal(digest);
 
 
-  if (not TArrayUtils.AreEqual(result, THex.Decode(hash))) then
+  if (not AreEqual(result, DecodeHex(hash))) then
   begin
   begin
     Fail(Format('abc result not equal for %s', [algorithm]));
     Fail(Format('abc result not equal for %s', [algorithm]));
   end;
   end;
@@ -195,7 +188,7 @@ end;
 
 
 procedure TTestDigest.DoTest(const algorithm: String);
 procedure TTestDigest.DoTest(const algorithm: String);
 var
 var
-  &message, result, result2: TCryptoLibByteArray;
+  &message, result, result2: TBytes;
   digest, d: IDigest;
   digest, d: IDigest;
   i: Int32;
   i: Int32;
 begin
 begin
@@ -210,7 +203,7 @@ begin
   result2 := TDigestUtilities.DoFinal(digest);
   result2 := TDigestUtilities.DoFinal(digest);
 
 
   // test one digest the same message with the same instance
   // test one digest the same message with the same instance
-  if (not TArrayUtils.AreEqual(result, result2)) then
+  if (not AreEqual(result, result2)) then
   begin
   begin
     Fail('Result object 1 not equal');
     Fail('Result object 1 not equal');
   end;
   end;
@@ -223,7 +216,7 @@ begin
 
 
   result2 := TDigestUtilities.DoFinal(digest);
   result2 := TDigestUtilities.DoFinal(digest);
 
 
-  if (not TArrayUtils.AreEqual(result, result2)) then
+  if (not AreEqual(result, result2)) then
   begin
   begin
     Fail('Result object 2 not equal');
     Fail('Result object 2 not equal');
   end;
   end;
@@ -235,7 +228,7 @@ begin
 
 
   result2 := TDigestUtilities.DoFinal(digest);
   result2 := TDigestUtilities.DoFinal(digest);
 
 
-  if (not TArrayUtils.AreEqual(result, result2)) then
+  if (not AreEqual(result, result2)) then
   begin
   begin
     Fail('Result object 3 not equal');
     Fail('Result object 3 not equal');
   end;
   end;
@@ -248,7 +241,7 @@ begin
 
 
   result2 := TDigestUtilities.DoFinal(digest);
   result2 := TDigestUtilities.DoFinal(digest);
 
 
-  if (not TArrayUtils.AreEqual(result, result2)) then
+  if (not AreEqual(result, result2)) then
   begin
   begin
     Fail('Result object 4(a) not equal');
     Fail('Result object 4(a) not equal');
   end;
   end;
@@ -258,7 +251,7 @@ begin
 
 
   result2 := TDigestUtilities.DoFinal(d);
   result2 := TDigestUtilities.DoFinal(d);
 
 
-  if (not TArrayUtils.AreEqual(result, result2)) then
+  if (not AreEqual(result, result2)) then
   begin
   begin
     Fail('Result object 4(b) not equal');
     Fail('Result object 4(b) not equal');
   end;
   end;
@@ -272,7 +265,7 @@ begin
 
 
   result2 := TDigestUtilities.DoFinal(digest);
   result2 := TDigestUtilities.DoFinal(digest);
 
 
-  if (not TArrayUtils.AreEqual(result, result2)) then
+  if (not AreEqual(result, result2)) then
   begin
   begin
     Fail('Result object 5 not equal');
     Fail('Result object 5 not equal');
   end;
   end;

+ 28 - 32
CryptoLib.Tests/src/Others/ECDsa5Tests.pas

@@ -32,11 +32,9 @@ uses
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpBigInteger,
   ClpBigInteger,
-  ClpEncoders,
   ClpFixedSecureRandom,
   ClpFixedSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
   ClpSecureRandom,
   ClpSecureRandom,
-  ClpCryptoLibTypes,
   ClpECC,
   ClpECC,
   ClpIECDomainParameters,
   ClpIECDomainParameters,
   ClpIECPrivateKeyParameters,
   ClpIECPrivateKeyParameters,
@@ -56,20 +54,16 @@ uses
   ClpIAsn1Objects,
   ClpIAsn1Objects,
   ClpISigner,
   ClpISigner,
   ClpAsn1Objects,
   ClpAsn1Objects,
-  ClpConverters;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpConverters,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestECDsa5 = class(TCryptoLibTestCase)
+  TTestECDsa5 = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
-    function derDecode(const encoding: TCryptoLibByteArray)
+    function derDecode(const encoding: TBytes)
       : TCryptoLibGenericArray<TBigInteger>;
       : TCryptoLibGenericArray<TBigInteger>;
 
 
   protected
   protected
@@ -98,7 +92,7 @@ implementation
 
 
 { TTestECDsa5 }
 { TTestECDsa5 }
 
 
-function TTestECDsa5.derDecode(const encoding: TCryptoLibByteArray)
+function TTestECDsa5.derDecode(const encoding: TBytes)
   : TCryptoLibGenericArray<TBigInteger>;
   : TCryptoLibGenericArray<TBigInteger>;
 var
 var
   s: IAsn1Sequence;
   s: IAsn1Sequence;
@@ -140,7 +134,7 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   p := curve.DecodePoint
   p := curve.DecodePoint
-    (THex.Decode('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'));
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'));
 
 
   x := p.XCoord.ToBigInteger(); // p.getAffineX();
   x := p.XCoord.ToBigInteger(); // p.getAffineX();
 
 
@@ -161,7 +155,7 @@ end;
 procedure TTestECDsa5.TestECDsa239BitBinary;
 procedure TTestECDsa5.TestECDsa239BitBinary;
 var
 var
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData, &message, sigBytes: TCryptoLibByteArray;
+  kData, &message, sigBytes: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IECCurve;
   curve: IECCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
@@ -192,9 +186,10 @@ begin
     TBigInteger.Four);
     TBigInteger.Four);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
-    ), // G
+    curve.DecodePoint
+    (DecodeHex
+    ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')),
+    // G
     TBigInteger.Create
     TBigInteger.Create
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     ('220855883097298041197912187592864814557886993776713230936715041207411783'),
     // n
     // n
@@ -207,9 +202,10 @@ begin
     parameters);
     parameters);
 
 
   vKey := TECPublicKeyParameters.Create('ECDSA',
   vKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
-    ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
-    ), // Q
+    curve.DecodePoint
+    (DecodeHex
+    ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')),
+    // Q
     parameters);
     parameters);
 
 
   sgr := TSignerUtilities.GetSigner('ECDSA');
   sgr := TSignerUtilities.GetSigner('ECDSA');
@@ -250,7 +246,7 @@ end;
 procedure TTestECDsa5.TestECDsa239BitPrime;
 procedure TTestECDsa5.TestECDsa239BitPrime;
 var
 var
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData, &message, sigBytes: TCryptoLibByteArray;
+  kData, &message, sigBytes: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IECCurve;
   curve: IECCurve;
   spec: IECDomainParameters;
   spec: IECDomainParameters;
@@ -284,9 +280,9 @@ begin
 
 
   spec := TECDomainParameters.Create(curve,
   spec := TECDomainParameters.Create(curve,
 
 
-    curve.DecodePoint(THex.Decode
-    ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf'))
-    as IECPoint, // G
+    curve.DecodePoint
+    (DecodeHex('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')
+    ) as IECPoint, // G
     TBigInteger.Create
     TBigInteger.Create
     ('883423532389192164791648750360308884807550341691627752275345424702807307'),
     ('883423532389192164791648750360308884807550341691627752275345424702807307'),
     // n
     // n
@@ -300,9 +296,9 @@ begin
 
 
   vKey := TECPublicKeyParameters.Create('ECDSA',
   vKey := TECPublicKeyParameters.Create('ECDSA',
 
 
-    curve.DecodePoint(THex.Decode
-    ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70'))
-    as IECPoint, // Q
+    curve.DecodePoint
+    (DecodeHex('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')
+    ) as IECPoint, // Q
     spec);
     spec);
 
 
   sgr := TSignerUtilities.GetSigner('ECDSA');
   sgr := TSignerUtilities.GetSigner('ECDSA');
@@ -342,7 +338,7 @@ end;
 
 
 procedure TTestECDsa5.TestGeneration;
 procedure TTestECDsa5.TestGeneration;
 var
 var
-  data, sigBytes: TCryptoLibByteArray;
+  data, sigBytes: TBytes;
   s: ISigner;
   s: ISigner;
   g: IAsymmetricCipherKeyPairGenerator;
   g: IAsymmetricCipherKeyPairGenerator;
   curve: IECCurve;
   curve: IECCurve;
@@ -354,7 +350,7 @@ begin
   //
   //
   // ECDSA generation test
   // ECDSA generation test
   //
   //
-  data := TCryptoLibByteArray.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
+  data := TBytes.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 0);
   s := TSignerUtilities.GetSigner('ECDSA');
   s := TSignerUtilities.GetSigner('ECDSA');
   g := TECKeyPairGenerator.Create('ECDSA');
   g := TECKeyPairGenerator.Create('ECDSA');
 
 
@@ -371,9 +367,9 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   ecSpec := TECDomainParameters.Create(curve,
   ecSpec := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf'))
-    as IECPoint, // G
+    curve.DecodePoint
+    (DecodeHex('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')
+    ) as IECPoint, // G
     TBigInteger.Create
     TBigInteger.Create
     ('883423532389192164791648750360308884807550341691627752275345424702807307'),
     ('883423532389192164791648750360308884807550341691627752275345424702807307'),
     // n
     // n

+ 11 - 18
CryptoLib.Tests/src/Others/ECSchnorrTests.pas

@@ -50,25 +50,18 @@ uses
   ClpIX9ECParameters,
   ClpIX9ECParameters,
   ClpIECC,
   ClpIECC,
   ClpSecNamedCurves,
   ClpSecNamedCurves,
-  ClpCryptoLibTypes,
   ClpBigInteger,
   ClpBigInteger,
   ClpSignerUtilities,
   ClpSignerUtilities,
-  ClpEncoders,
-  ClpArrayUtils,
-  ClpConverters;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpConverters,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// ECSchnorr tests.
   /// ECSchnorr tests.
   /// </summary>
   /// </summary>
-  TTestECSchnorr = class(TCryptoLibTestCase)
+  TTestECSchnorr = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -270,8 +263,8 @@ begin
 
 
     PrivateKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
     PrivateKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
     PublicKeyByteArray := TBigInteger.Create(vector[2], 16).ToByteArray;
     PublicKeyByteArray := TBigInteger.Create(vector[2], 16).ToByteArray;
-    &message := THex.Decode(vector[3]);
-    expectedSignature := THex.Decode(vector[4]);
+    &message := DecodeHex(vector[3]);
+    expectedSignature := DecodeHex(vector[4]);
 
 
     point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
     point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
 
 
@@ -293,7 +286,7 @@ begin
 
 
     sigBytes := signer.GenerateSignature();
     sigBytes := signer.GenerateSignature();
 
 
-    CheckTrue(TArrayUtils.AreEqual(expectedSignature, sigBytes),
+    CheckTrue(AreEqual(expectedSignature, sigBytes),
       vector[0] + ' Signature did not match Output');
       vector[0] + ' Signature did not match Output');
 
 
     // verify
     // verify
@@ -328,8 +321,8 @@ begin
   begin
   begin
 
 
     PublicKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
     PublicKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
-    &message := THex.Decode(vector[2]);
-    expectedSignature := THex.Decode(vector[3]);
+    &message := DecodeHex(vector[2]);
+    expectedSignature := DecodeHex(vector[3]);
 
 
     if vector[0] = 'Test vector 5' then
     if vector[0] = 'Test vector 5' then
     begin
     begin
@@ -392,8 +385,8 @@ begin
   begin
   begin
 
 
     PublicKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
     PublicKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
-    &message := THex.Decode(vector[2]);
-    expectedSignature := THex.Decode(vector[3]);
+    &message := DecodeHex(vector[2]);
+    expectedSignature := DecodeHex(vector[3]);
 
 
     point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
     point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
 
 

+ 42 - 39
CryptoLib.Tests/src/Others/ECTests.pas

@@ -57,24 +57,17 @@ uses
   ClpCustomNamedCurves,
   ClpCustomNamedCurves,
   ClpECC,
   ClpECC,
   ClpIECC,
   ClpIECC,
-  ClpEncoders,
-  ClpCryptoLibTypes,
   ClpBigInteger,
   ClpBigInteger,
   ClpBigIntegers,
   ClpBigIntegers,
-  ClpArrayUtils;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
   /// <summary>
   /// <summary>
   /// ECDSA tests are taken from X9.62.
   /// ECDSA tests are taken from X9.62.
   /// </summary>
   /// </summary>
-  TTestEC = class(TCryptoLibTestCase)
+  TTestEC = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -148,7 +141,7 @@ procedure TTestEC.TestDecode;
 var
 var
   curve: IFpCurve;
   curve: IFpCurve;
   p: IECPoint;
   p: IECPoint;
-  encoding: TCryptoLibByteArray;
+  encoding: TBytes;
 begin
 begin
   curve := TFpCurve.Create
   curve := TFpCurve.Create
     (TBigInteger.Create
     (TBigInteger.Create
@@ -162,7 +155,7 @@ begin
     TBigInteger.One);
     TBigInteger.One);
 
 
   p := curve.DecodePoint
   p := curve.DecodePoint
-    (THex.Decode('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'))
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'))
     .Normalize();
     .Normalize();
 
 
   if (not p.AffineXCoord.ToBigInteger()
   if (not p.AffineXCoord.ToBigInteger()
@@ -181,8 +174,8 @@ begin
 
 
   encoding := p.GetEncoded(true);
   encoding := p.GetEncoded(true);
 
 
-  if (not TArrayUtils.AreEqual(encoding,
-    THex.Decode('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'))) then
+  if (not AreEqual(encoding,
+    DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'))) then
   begin
   begin
     Fail('point compressed incorrectly');
     Fail('point compressed incorrectly');
   end;
   end;
@@ -191,7 +184,7 @@ end;
 procedure TTestEC.TestECDsa191bitBinary;
 procedure TTestEC.TestECDsa191bitBinary;
 var
 var
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData, &message: TCryptoLibByteArray;
+  kData, &message: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IF2mCurve;
   curve: IF2mCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
@@ -222,7 +215,8 @@ begin
     TBigInteger.Two);
     TBigInteger.Two);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('0436B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB')
     ('0436B3DAF8A23206F9C4F299D7B21A9C369137F2C84AE1AA0D765BE73433B3F95E332932E70EA245CA2418EA0EF98018FB')
     ) as IECPoint, // G
     ) as IECPoint, // G
     TBigInteger.Create
     TBigInteger.Create
@@ -257,7 +251,8 @@ begin
 
 
   // Verify the signature
   // Verify the signature
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('045DE37E756BD55D72E3768CB396FFEB962614DEA4CE28A2E755C0E0E02F5FB132CAF416EF85B229BBB8E1352003125BA1')
     ('045DE37E756BD55D72E3768CB396FFEB962614DEA4CE28A2E755C0E0E02F5FB132CAF416EF85B229BBB8E1352003125BA1')
     ) as IECPoint, // Q
     ) as IECPoint, // Q
     parameters);
     parameters);
@@ -272,7 +267,7 @@ end;
 procedure TTestEC.TestECDsa192bitPrime;
 procedure TTestEC.TestECDsa192bitPrime;
 var
 var
   r, s, n: TBigInteger;
   r, s, n: TBigInteger;
-  kData, &message: TCryptoLibByteArray;
+  kData, &message: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IFpCurve;
   curve: IFpCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
@@ -307,8 +302,9 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012')) as IECPoint, // G
+    curve.DecodePoint
+    (DecodeHex('03188da80eb03090f67cbf20eb43a18800f4ff0afd82ff1012'))
+    as IECPoint, // G
     n);
     n);
 
 
   priKey := TECPrivateKeyParameters.Create('ECDSA',
   priKey := TECPrivateKeyParameters.Create('ECDSA',
@@ -340,8 +336,9 @@ begin
 
 
   // Verify the signature
   // Verify the signature
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
-    ('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5')) as IECPoint, // Q
+    curve.DecodePoint
+    (DecodeHex('0262b12d60690cdcf330babab6e69763b471f994dd702d16a5'))
+    as IECPoint, // Q
     parameters);
     parameters);
 
 
   ecdsa.Init(false, pubKey);
   ecdsa.Init(false, pubKey);
@@ -356,14 +353,14 @@ var
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
   k: ISecureRandom;
   k: ISecureRandom;
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData: TCryptoLibByteArray;
+  kData: TBytes;
   curve: IF2mCurve;
   curve: IF2mCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
   priKey: IECPrivateKeyParameters;
   priKey: IECPrivateKeyParameters;
   pubKey: IECPublicKeyParameters;
   pubKey: IECPublicKeyParameters;
   ecdsa: IECDsaSigner;
   ecdsa: IECDsaSigner;
   param: IParametersWithRandom;
   param: IParametersWithRandom;
-  &message: TCryptoLibByteArray;
+  &message: TBytes;
 begin
 begin
   r := TBigInteger.Create
   r := TBigInteger.Create
     ('21596333210419611985018340039034612628818151486841789642455876922391552');
     ('21596333210419611985018340039034612628818151486841789642455876922391552');
@@ -388,7 +385,8 @@ begin
     TBigInteger.Four);
     TBigInteger.Four);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
     ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
     ) as IECPoint, // G
     ) as IECPoint, // G
     TBigInteger.Create
     TBigInteger.Create
@@ -425,7 +423,8 @@ begin
 
 
   // Verify the signature
   // Verify the signature
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
     ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
     ) as IECPoint, // Q
     ) as IECPoint, // Q
     parameters);
     parameters);
@@ -440,7 +439,7 @@ end;
 procedure TTestEC.TestECDsa239bitBinaryAndLargeDigest;
 procedure TTestEC.TestECDsa239bitBinaryAndLargeDigest;
 var
 var
   r, s: TBigInteger;
   r, s: TBigInteger;
-  kData, &message: TCryptoLibByteArray;
+  kData, &message: TBytes;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IF2mCurve;
   curve: IF2mCurve;
   parameters: IECDomainParameters;
   parameters: IECDomainParameters;
@@ -473,7 +472,8 @@ begin
     TBigInteger.Four);
     TBigInteger.Four);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
     ('0457927098FA932E7C0A96D3FD5B706EF7E5F5C156E16B7E7C86038552E91D61D8EE5077C33FECF6F1A16B268DE469C3C7744EA9A971649FC7A9616305')
     ) as IECPoint, // G
     ) as IECPoint, // G
     TBigInteger.Create
     TBigInteger.Create
@@ -511,7 +511,8 @@ begin
 
 
   // Verify the signature
   // Verify the signature
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
     ('045894609CCECF9A92533F630DE713A958E96C97CCB8F5ABB5A688A238DEED6DC2D9D0C94EBFB7D526BA6A61764175B99CB6011E2047F9F067293F57F5')
     ) as IECPoint, // Q
     ) as IECPoint, // Q
     parameters);
     parameters);
@@ -525,7 +526,7 @@ end;
 
 
 procedure TTestEC.TestECDsa239bitPrime;
 procedure TTestEC.TestECDsa239bitPrime;
 var
 var
-  &message, kData: TCryptoLibByteArray;
+  &message, kData: TBytes;
   r, s, n: TBigInteger;
   r, s, n: TBigInteger;
   k: ISecureRandom;
   k: ISecureRandom;
   curve: IFpCurve;
   curve: IFpCurve;
@@ -562,9 +563,9 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
-    ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf'))
-    as IECPoint, // G
+    curve.DecodePoint
+    (DecodeHex('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')
+    ) as IECPoint, // G
     n);
     n);
 
 
   priKey := TECPrivateKeyParameters.Create('ECDSA',
   priKey := TECPrivateKeyParameters.Create('ECDSA',
@@ -596,9 +597,9 @@ begin
 
 
   // Verify the signature
   // Verify the signature
   pubKey := TECPublicKeyParameters.Create('ECDSA',
   pubKey := TECPublicKeyParameters.Create('ECDSA',
-    curve.DecodePoint(THex.Decode
-    ('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70'))
-    as IECPoint, // Q
+    curve.DecodePoint
+    (DecodeHex('025b6dc53bc61a2548ffb0f671472de6c9521a9d2d2534e65abfcbd5fe0c70')
+    ) as IECPoint, // Q
     parameters);
     parameters);
 
 
   ecdsa.Init(false, pubKey);
   ecdsa.Init(false, pubKey);
@@ -619,7 +620,7 @@ var
   pair: IAsymmetricCipherKeyPair;
   pair: IAsymmetricCipherKeyPair;
   param: IParametersWithRandom;
   param: IParametersWithRandom;
   ecdsa: IECDsaSigner;
   ecdsa: IECDsaSigner;
-  &message: TCryptoLibByteArray;
+  &message: TBytes;
   sig: TCryptoLibGenericArray<TBigInteger>;
   sig: TCryptoLibGenericArray<TBigInteger>;
 begin
 begin
   random := TSecureRandom.Create();
   random := TSecureRandom.Create();
@@ -638,7 +639,8 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     n);
     n);
 
 
@@ -694,7 +696,8 @@ begin
     n, TBigInteger.One);
     n, TBigInteger.One);
 
 
   parameters := TECDomainParameters.Create(curve,
   parameters := TECDomainParameters.Create(curve,
-    curve.DecodePoint(THex.Decode
+    curve.DecodePoint
+    (DecodeHex
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     ('020ffa963cdca8816ccc33b8642bedf905c3d358573d3f27fbbd3b3cb9aaaf')), // G
     n);
     n);
 
 

+ 30 - 39
CryptoLib.Tests/src/Others/Ed25519HigherLevelTests.pas

@@ -57,15 +57,8 @@ uses
   ClpEd25519KeyGenerationParameters,
   ClpEd25519KeyGenerationParameters,
   ClpIEd25519KeyGenerationParameters,
   ClpIEd25519KeyGenerationParameters,
   ClpSignerUtilities,
   ClpSignerUtilities,
-  ClpArrayUtils,
-  ClpEncoders,
-  ClpCryptoLibTypes;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
@@ -73,7 +66,7 @@ type
   /// test vectors gotten from <see href="https://github.com/warner/python-ed25519" />
   /// test vectors gotten from <see href="https://github.com/warner/python-ed25519" />
   /// and <see href="https://github.com/Matoking/python-ed25519-blake2b" />
   /// and <see href="https://github.com/Matoking/python-ed25519-blake2b" />
   /// </summary>
   /// </summary>
-  TTestEd25519HigherLevel = class(TCryptoLibTestCase)
+  TTestEd25519HigherLevel = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FRandom: ISecureRandom;
     FRandom: ISecureRandom;
@@ -83,18 +76,18 @@ type
     TEd25519SignerAlgorithm = (Ed25519, Ed25519Blake2B);
     TEd25519SignerAlgorithm = (Ed25519, Ed25519Blake2B);
 {$SCOPEDENUMS OFF}
 {$SCOPEDENUMS OFF}
   function CreateSigner(algorithm: TEd25519.TEd25519Algorithm;
   function CreateSigner(algorithm: TEd25519.TEd25519Algorithm;
-    const context: TCryptoLibByteArray): ISigner;
+    const context: TBytes): ISigner;
 
 
   function CreateCustomSigner(const algorithm: TEd25519SignerAlgorithm)
   function CreateCustomSigner(const algorithm: TEd25519SignerAlgorithm)
     : ISigner;
     : ISigner;
 
 
   function ReconstructEd25519KeyPair(algorithm: TEd25519SignerAlgorithm;
   function ReconstructEd25519KeyPair(algorithm: TEd25519SignerAlgorithm;
-    const sk, pk: TCryptoLibByteArray): IAsymmetricCipherKeyPair;
+    const sk, pk: TBytes): IAsymmetricCipherKeyPair;
 
 
-  function RandomContext(length: Int32): TCryptoLibByteArray;
+  function RandomContext(length: Int32): TBytes;
 
 
   procedure DoTestConsistency(algorithm: TEd25519.TEd25519Algorithm;
   procedure DoTestConsistency(algorithm: TEd25519.TEd25519Algorithm;
-    const context: TCryptoLibByteArray);
+    const context: TBytes);
 
 
   procedure DoEd25519Test(id: Int32; algorithm: TEd25519SignerAlgorithm;
   procedure DoEd25519Test(id: Int32; algorithm: TEd25519SignerAlgorithm;
     const sk, pk, msg, sig: String);
     const sk, pk, msg, sig: String);
@@ -122,8 +115,7 @@ begin
 end;
 end;
 
 
 function TTestEd25519HigherLevel.CreateSigner
 function TTestEd25519HigherLevel.CreateSigner
-  (algorithm: TEd25519.TEd25519Algorithm;
-  const context: TCryptoLibByteArray): ISigner;
+  (algorithm: TEd25519.TEd25519Algorithm; const context: TBytes): ISigner;
 begin
 begin
   case algorithm of
   case algorithm of
     TEd25519.TEd25519Algorithm.Ed25519:
     TEd25519.TEd25519Algorithm.Ed25519:
@@ -142,15 +134,15 @@ end;
 procedure TTestEd25519HigherLevel.DoEd25519Test(id: Int32;
 procedure TTestEd25519HigherLevel.DoEd25519Test(id: Int32;
   algorithm: TEd25519SignerAlgorithm; const sk, pk, msg, sig: String);
   algorithm: TEd25519SignerAlgorithm; const sk, pk, msg, sig: String);
 var
 var
-  LSk, LPk, LMsg, LSig, LResultSig, LKey: TCryptoLibByteArray;
+  LSk, LPk, LMsg, LSig, LResultSig, LKey: TBytes;
   LKeyPair: IAsymmetricCipherKeyPair;
   LKeyPair: IAsymmetricCipherKeyPair;
   LIsVerified: Boolean;
   LIsVerified: Boolean;
   LSigner: ISigner;
   LSigner: ISigner;
 begin
 begin
-  LSk := THex.Decode(sk);
-  LPk := THex.Decode(pk);
-  LMsg := THex.Decode(msg);
-  LSig := THex.Decode(sig);
+  LSk := DecodeHex(sk);
+  LPk := DecodeHex(pk);
+  LMsg := DecodeHex(msg);
+  LSig := DecodeHex(sig);
   LKeyPair := ReconstructEd25519KeyPair(algorithm, LSk, LPk);
   LKeyPair := ReconstructEd25519KeyPair(algorithm, LSk, LPk);
   LSigner := CreateCustomSigner(algorithm);
   LSigner := CreateCustomSigner(algorithm);
 
 
@@ -158,39 +150,39 @@ begin
     TTestEd25519HigherLevel.TEd25519SignerAlgorithm.Ed25519:
     TTestEd25519HigherLevel.TEd25519SignerAlgorithm.Ed25519:
       begin
       begin
         LKey := (LKeyPair.Private as IEd25519PrivateKeyParameters).GetEncoded();
         LKey := (LKeyPair.Private as IEd25519PrivateKeyParameters).GetEncoded();
-        if not TArrayUtils.AreEqual(LKey, System.Copy(LSk, 0, 32)) then
+        if not AreEqual(LKey, System.Copy(LSk, 0, 32)) then
         begin
         begin
           Fail(Format
           Fail(Format
             ('Test with Id %d Failed on PrivateKey Reconstruction Comparison, Expected "%s" but got "%s"',
             ('Test with Id %d Failed on PrivateKey Reconstruction Comparison, Expected "%s" but got "%s"',
-            [id, THex.Encode(LSk), THex.Encode(LKey)]));
+            [id, EncodeHex(LSk), EncodeHex(LKey)]));
         end;
         end;
 
 
         LKey := (LKeyPair.Public as IEd25519PublicKeyParameters).GetEncoded();
         LKey := (LKeyPair.Public as IEd25519PublicKeyParameters).GetEncoded();
-        if not TArrayUtils.AreEqual(LKey, System.Copy(LPk, 0, 64)) then
+        if not AreEqual(LKey, System.Copy(LPk, 0, 64)) then
         begin
         begin
           Fail(Format
           Fail(Format
             ('Test with Id %d Failed on PublicKey Reconstruction Comparison, Expected "%s" but got "%s"',
             ('Test with Id %d Failed on PublicKey Reconstruction Comparison, Expected "%s" but got "%s"',
-            [id, THex.Encode(LPk), THex.Encode(LKey)]));
+            [id, EncodeHex(LPk), EncodeHex(LKey)]));
         end;
         end;
       end;
       end;
     TTestEd25519HigherLevel.TEd25519SignerAlgorithm.Ed25519Blake2B:
     TTestEd25519HigherLevel.TEd25519SignerAlgorithm.Ed25519Blake2B:
       begin
       begin
         LKey := (LKeyPair.Private as IEd25519Blake2BPrivateKeyParameters)
         LKey := (LKeyPair.Private as IEd25519Blake2BPrivateKeyParameters)
           .GetEncoded();
           .GetEncoded();
-        if not TArrayUtils.AreEqual(LKey, System.Copy(LSk, 0, 32)) then
+        if not AreEqual(LKey, System.Copy(LSk, 0, 32)) then
         begin
         begin
           Fail(Format
           Fail(Format
             ('Test with Id %d Failed on PrivateKey Reconstruction Comparison, Expected "%s" but got "%s"',
             ('Test with Id %d Failed on PrivateKey Reconstruction Comparison, Expected "%s" but got "%s"',
-            [id, THex.Encode(LSk), THex.Encode(LKey)]));
+            [id, EncodeHex(LSk), EncodeHex(LKey)]));
         end;
         end;
 
 
         LKey := (LKeyPair.Public as IEd25519Blake2BPublicKeyParameters)
         LKey := (LKeyPair.Public as IEd25519Blake2BPublicKeyParameters)
           .GetEncoded();
           .GetEncoded();
-        if not TArrayUtils.AreEqual(LKey, System.Copy(LPk, 0, 64)) then
+        if not AreEqual(LKey, System.Copy(LPk, 0, 64)) then
         begin
         begin
           Fail(Format
           Fail(Format
             ('Test with Id %d Failed on PublicKey Reconstruction Comparison, Expected "%s" but got "%s"',
             ('Test with Id %d Failed on PublicKey Reconstruction Comparison, Expected "%s" but got "%s"',
-            [id, THex.Encode(LPk), THex.Encode(LKey)]));
+            [id, EncodeHex(LPk), EncodeHex(LKey)]));
         end;
         end;
       end
       end
   else
   else
@@ -204,11 +196,11 @@ begin
   LSigner.BlockUpdate(LMsg, 0, System.length(LMsg));
   LSigner.BlockUpdate(LMsg, 0, System.length(LMsg));
   LResultSig := LSigner.GenerateSignature();
   LResultSig := LSigner.GenerateSignature();
 
 
-  if not TArrayUtils.AreEqual(LResultSig, System.Copy(LSig, 0, 64)) then
+  if not AreEqual(LResultSig, System.Copy(LSig, 0, 64)) then
   begin
   begin
     Fail(Format
     Fail(Format
       ('Test with Id %d Failed on Signature Comparison, Expected "%s" but got "%s"',
       ('Test with Id %d Failed on Signature Comparison, Expected "%s" but got "%s"',
-      [id, THex.Encode(LSig), THex.Encode(LResultSig)]));
+      [id, EncodeHex(LSig), EncodeHex(LResultSig)]));
   end;
   end;
 
 
   LSigner.Init(False, LKeyPair.Public);
   LSigner.Init(False, LKeyPair.Public);
@@ -218,18 +210,18 @@ begin
   if not LIsVerified then
   if not LIsVerified then
   begin
   begin
     Fail(Format('Test with Id %d Failed on Verifying "%s" Signature',
     Fail(Format('Test with Id %d Failed on Verifying "%s" Signature',
-      [id, THex.Encode(LResultSig)]));
+      [id, EncodeHex(LResultSig)]));
   end;
   end;
 end;
 end;
 
 
 procedure TTestEd25519HigherLevel.DoTestConsistency
 procedure TTestEd25519HigherLevel.DoTestConsistency
-  (algorithm: TEd25519.TEd25519Algorithm; const context: TCryptoLibByteArray);
+  (algorithm: TEd25519.TEd25519Algorithm; const context: TBytes);
 var
 var
   kpg: IEd25519KeyPairGenerator;
   kpg: IEd25519KeyPairGenerator;
   kp: IAsymmetricCipherKeyPair;
   kp: IAsymmetricCipherKeyPair;
   privateKey: IEd25519PrivateKeyParameters;
   privateKey: IEd25519PrivateKeyParameters;
   publicKey: IEd25519PublicKeyParameters;
   publicKey: IEd25519PublicKeyParameters;
-  msg, signature, wrongLengthSignature: TCryptoLibByteArray;
+  msg, signature, wrongLengthSignature: TBytes;
   Signer, verifier: ISigner;
   Signer, verifier: ISigner;
   shouldVerify, shouldNotVerify: Boolean;
   shouldVerify, shouldNotVerify: Boolean;
   algorithmName: String;
   algorithmName: String;
@@ -264,7 +256,7 @@ begin
     Fail(Format('Ed25519 (%s) signature failed to verify', [algorithmName]));
     Fail(Format('Ed25519 (%s) signature failed to verify', [algorithmName]));
   end;
   end;
 
 
-  wrongLengthSignature := TArrayUtils.Prepend(signature, Byte($00));
+  wrongLengthSignature := Prepend(signature, Byte($00));
 
 
   verifier.Init(False, publicKey);
   verifier.Init(False, publicKey);
   verifier.BlockUpdate(msg, 0, System.length(msg));
   verifier.BlockUpdate(msg, 0, System.length(msg));
@@ -292,15 +284,14 @@ begin
   end;
   end;
 end;
 end;
 
 
-function TTestEd25519HigherLevel.RandomContext(length: Int32)
-  : TCryptoLibByteArray;
+function TTestEd25519HigherLevel.RandomContext(length: Int32): TBytes;
 begin
 begin
   System.SetLength(Result, length);
   System.SetLength(Result, length);
   FRandom.NextBytes(Result);
   FRandom.NextBytes(Result);
 end;
 end;
 
 
 function TTestEd25519HigherLevel.ReconstructEd25519KeyPair
 function TTestEd25519HigherLevel.ReconstructEd25519KeyPair
-  (algorithm: TEd25519SignerAlgorithm; const sk, pk: TCryptoLibByteArray)
+  (algorithm: TEd25519SignerAlgorithm; const sk, pk: TBytes)
   : IAsymmetricCipherKeyPair;
   : IAsymmetricCipherKeyPair;
 begin
 begin
   case algorithm of
   case algorithm of
@@ -342,7 +333,7 @@ end;
 procedure TTestEd25519HigherLevel.TestConsistency;
 procedure TTestEd25519HigherLevel.TestConsistency;
 var
 var
   i: Int32;
   i: Int32;
-  context: TCryptoLibByteArray;
+  context: TBytes;
 begin
 begin
   i := 0;
   i := 0;
   while i < 10 do
   while i < 10 do

+ 3 - 9
CryptoLib.Tests/src/Others/NamedCurveTests.pas

@@ -54,20 +54,14 @@ uses
   ClpGeneratorUtilities,
   ClpGeneratorUtilities,
   ClpAgreementUtilities,
   ClpAgreementUtilities,
   ClpConverters,
   ClpConverters,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 resourcestring
 resourcestring
   SUnknownCurveName = 'Unknown Curve Name: %s';
   SUnknownCurveName = 'Unknown Curve Name: %s';
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestNamedCurve = class(TCryptoLibTestCase)
+  TTestNamedCurve = class(TCryptoLibAlgorithmTestCase)
   private
   private
     function GetCurveParameters(const name: String): IECDomainParameters;
     function GetCurveParameters(const name: String): IECDomainParameters;
     procedure DoTestECDsa(const name: String);
     procedure DoTestECDsa(const name: String);
@@ -91,7 +85,7 @@ var
   sgr: ISigner;
   sgr: ISigner;
   pair: IAsymmetricCipherKeyPair;
   pair: IAsymmetricCipherKeyPair;
   sKey, vKey: IAsymmetricKeyParameter;
   sKey, vKey: IAsymmetricKeyParameter;
-  &message, sigBytes: TCryptoLibByteArray;
+  &message, sigBytes: TBytes;
 begin
 begin
   ecSpec := GetCurveParameters(name);
   ecSpec := GetCurveParameters(name);
 
 

+ 6 - 12
CryptoLib.Tests/src/Others/ShortenedDigestTests.pas

@@ -35,18 +35,12 @@ uses
   ClpIShortenedDigest,
   ClpIShortenedDigest,
   ClpShortenedDigest,
   ClpShortenedDigest,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestShortenedDigest = class(TCryptoLibTestCase)
+  TTestShortenedDigest = class(TCryptoLibAlgorithmTestCase)
 
 
   private
   private
     procedure DoTestShortenedDigest();
     procedure DoTestShortenedDigest();
@@ -67,7 +61,7 @@ procedure TTestShortenedDigest.DoTestShortenedDigest;
 var
 var
   d: IDigest;
   d: IDigest;
   sd: IShortenedDigest;
   sd: IShortenedDigest;
-  temp, temp2: TCryptoLibByteArray;
+  temp, temp2: TBytes;
 begin
 begin
   d := TDigestUtilities.GetDigest('SHA-1');
   d := TDigestUtilities.GetDigest('SHA-1');
   sd := TShortenedDigest.Create(TDigestUtilities.GetDigest('SHA-1'), 10);
   sd := TShortenedDigest.Create(TDigestUtilities.GetDigest('SHA-1'), 10);
@@ -90,7 +84,7 @@ begin
   sd.DoFinal(temp, 0);
   sd.DoFinal(temp, 0);
   sd.DoFinal(temp2, 0);
   sd.DoFinal(temp2, 0);
 
 
-  CheckTrue(TArrayUtils.AreEqual(temp, temp2),
+  CheckTrue(AreEqual(temp, temp2),
     Format('DoFinal(temp, 0) <> temp := DoFinal() %s', [sd.AlgorithmName]));
     Format('DoFinal(temp, 0) <> temp := DoFinal() %s', [sd.AlgorithmName]));
 
 
   d := TDigestUtilities.GetDigest('SHA-512');
   d := TDigestUtilities.GetDigest('SHA-512');
@@ -114,7 +108,7 @@ begin
   sd.DoFinal(temp, 0);
   sd.DoFinal(temp, 0);
   sd.DoFinal(temp2, 0);
   sd.DoFinal(temp2, 0);
 
 
-  CheckTrue(TArrayUtils.AreEqual(temp, temp2),
+  CheckTrue(AreEqual(temp, temp2),
     Format('DoFinal(temp, 0) <> temp := DoFinal() %s', [sd.AlgorithmName]));
     Format('DoFinal(temp, 0) <> temp := DoFinal() %s', [sd.AlgorithmName]));
 
 
   try
   try

+ 17 - 25
CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas

@@ -32,9 +32,7 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpEncoders,
   ClpBigInteger,
   ClpBigInteger,
-  ClpCryptoLibTypes,
   ClpISigner,
   ClpISigner,
   ClpECC,
   ClpECC,
   ClpIRandom,
   ClpIRandom,
@@ -59,17 +57,12 @@ uses
   ClpEd25519KeyGenerationParameters,
   ClpEd25519KeyGenerationParameters,
   ClpIEd25519KeyGenerationParameters,
   ClpIEd25519KeyGenerationParameters,
   ClpIAsymmetricCipherKeyPair,
   ClpIAsymmetricCipherKeyPair,
-  ClpGeneratorUtilities;
+  ClpGeneratorUtilities,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestSignerUtilities = class(TCryptoLibTestCase)
+  TTestSignerUtilities = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
   var
   var
@@ -106,18 +99,18 @@ begin
   //
   //
 
 
   FECParraGX := TBigInteger.Create
   FECParraGX := TBigInteger.Create
-    (TBase64.Decode('D/qWPNyogWzMM7hkK+35BcPTWFc9Pyf7vTs8uaqv'));
+    (DecodeBase64('D/qWPNyogWzMM7hkK+35BcPTWFc9Pyf7vTs8uaqv'));
   FECParraGY := TBigInteger.Create
   FECParraGY := TBigInteger.Create
-    (TBase64.Decode('AhQXGxb1olGRv6s1LPRfuatMF+cx3ZTGgzSE/Q5R'));
-  FECParraH := TBigInteger.Create(TBase64.Decode('AQ=='));
+    (DecodeBase64('AhQXGxb1olGRv6s1LPRfuatMF+cx3ZTGgzSE/Q5R'));
+  FECParraH := TBigInteger.Create(DecodeBase64('AQ=='));
   FECParraN := TBigInteger.Create
   FECParraN := TBigInteger.Create
-    (TBase64.Decode('f///////////////f///nl6an12QcfvRUiaIkJ0L'));
+    (DecodeBase64('f///////////////f///nl6an12QcfvRUiaIkJ0L'));
   FECPubQX := TBigInteger.Create
   FECPubQX := TBigInteger.Create
-    (TBase64.Decode('HWWi17Yb+Bm3PYr/DMjLOYNFhyOwX1QY7ZvqqM+l'));
+    (DecodeBase64('HWWi17Yb+Bm3PYr/DMjLOYNFhyOwX1QY7ZvqqM+l'));
   FECPubQY := TBigInteger.Create
   FECPubQY := TBigInteger.Create
-    (TBase64.Decode('JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx'));
+    (DecodeBase64('JrlJfxu3WGhqwtL/55BOs/wsUeiDFsvXcGhB8DGx'));
   FECPrivD := TBigInteger.Create
   FECPrivD := TBigInteger.Create
-    (TBase64.Decode('GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo'));
+    (DecodeBase64('GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo'));
 
 
   Fcurve := TFpCurve.Create
   Fcurve := TFpCurve.Create
     (TBigInteger.Create
     (TBigInteger.Create
@@ -142,21 +135,20 @@ begin
   //
   //
 
 
   FDSAParaG := TBigInteger.Create
   FDSAParaG := TBigInteger.Create
-    (TBase64.Decode
+    (DecodeBase64
     ('AL0fxOTq10OHFbCf8YldyGembqEu08EDVzxyLL29Zn/t4It661YNol1rnhPIs+cirw+yf9zeCe+KL1IbZ/qIMZM=')
     ('AL0fxOTq10OHFbCf8YldyGembqEu08EDVzxyLL29Zn/t4It661YNol1rnhPIs+cirw+yf9zeCe+KL1IbZ/qIMZM=')
     );
     );
   FDSAParaP := TBigInteger.Create
   FDSAParaP := TBigInteger.Create
-    (TBase64.Decode
+    (DecodeBase64
     ('AM2b/UeQA+ovv3dL05wlDHEKJ+qhnJBsRT5OB9WuyRC830G79y0R8wuq8jyIYWCYcTn1TeqVPWqiTv6oAoiEeOs=')
     ('AM2b/UeQA+ovv3dL05wlDHEKJ+qhnJBsRT5OB9WuyRC830G79y0R8wuq8jyIYWCYcTn1TeqVPWqiTv6oAoiEeOs=')
     );
     );
-  FDSAParaQ := TBigInteger.Create
-    (TBase64.Decode('AIlJT7mcKL6SUBMmvm24zX1EvjNx'));
+  FDSAParaQ := TBigInteger.Create(DecodeBase64('AIlJT7mcKL6SUBMmvm24zX1EvjNx'));
   FDSAPublicY := TBigInteger.Create
   FDSAPublicY := TBigInteger.Create
-    (TBase64.Decode
+    (DecodeBase64
     ('TtWy2GuT9yGBWOHi1/EpCDa/bWJCk2+yAdr56rAcqP0eHGkMnA9s9GJD2nGU8sFjNHm55swpn6JQb8q0agrCfw==')
     ('TtWy2GuT9yGBWOHi1/EpCDa/bWJCk2+yAdr56rAcqP0eHGkMnA9s9GJD2nGU8sFjNHm55swpn6JQb8q0agrCfw==')
     );
     );
   FDsaPrivateX := TBigInteger.Create
   FDsaPrivateX := TBigInteger.Create
-    (TBase64.Decode('MMpBAxNlv7eYfxLTZ2BItJeD31A='));
+    (DecodeBase64('MMpBAxNlv7eYfxLTZ2BItJeD31A='));
 
 
   Fpara := TDsaParameters.Create(FDSAParaP, FDSAParaQ, FDSAParaG);
   Fpara := TDsaParameters.Create(FDSAParaP, FDSAParaQ, FDSAParaG);
   FdsaPriv := TDsaPrivateKeyParameters.Create(FDsaPrivateX, Fpara);
   FdsaPriv := TDsaPrivateKeyParameters.Create(FDsaPrivateX, Fpara);
@@ -181,7 +173,7 @@ end;
 
 
 procedure TTestSignerUtilities.TestAlgorithms;
 procedure TTestSignerUtilities.TestAlgorithms;
 var
 var
-  shortMsg, longMsg, sig: TCryptoLibByteArray;
+  shortMsg, longMsg, sig: TBytes;
   LRandom: IRandom;
   LRandom: IRandom;
   algorithm, upper, cipherName: string;
   algorithm, upper, cipherName: string;
   signer: ISigner;
   signer: ISigner;
@@ -192,7 +184,7 @@ begin
   //
   //
   // signer loop
   // signer loop
   //
   //
-  shortMsg := TCryptoLibByteArray.Create(1, 4, 5, 6, 8, 8, 4, 2, 1, 3);
+  shortMsg := TBytes.Create(1, 4, 5, 6, 8, 8, 4, 2, 1, 3);
   System.SetLength(longMsg, 100);
   System.SetLength(longMsg, 100);
 
 
   LRandom := TSecureRandom.Create();
   LRandom := TSecureRandom.Create();

+ 6 - 12
CryptoLib.Tests/src/Others/X25519HigherLevelTests.pas

@@ -24,6 +24,7 @@ interface
 {$ENDIF FPC}
 {$ENDIF FPC}
 
 
 uses
 uses
+  SysUtils,
 {$IFDEF FPC}
 {$IFDEF FPC}
   fpcunit,
   fpcunit,
   testregistry,
   testregistry,
@@ -32,7 +33,6 @@ uses
 {$ENDIF FPC}
 {$ENDIF FPC}
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
-  ClpArrayUtils,
   ClpX25519Agreement,
   ClpX25519Agreement,
   ClpIX25519Agreement,
   ClpIX25519Agreement,
   ClpIAsymmetricCipherKeyPair,
   ClpIAsymmetricCipherKeyPair,
@@ -41,17 +41,11 @@ uses
   ClpX25519KeyGenerationParameters,
   ClpX25519KeyGenerationParameters,
   ClpIX25519KeyGenerationParameters,
   ClpIX25519KeyGenerationParameters,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPairGenerator,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestX25519HigherLevel = class(TCryptoLibTestCase)
+  TTestX25519HigherLevel = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
     FRandom: ISecureRandom;
     FRandom: ISecureRandom;
@@ -74,7 +68,7 @@ var
   kpGen: IAsymmetricCipherKeyPairGenerator;
   kpGen: IAsymmetricCipherKeyPairGenerator;
   kpA, kpB: IAsymmetricCipherKeyPair;
   kpA, kpB: IAsymmetricCipherKeyPair;
   agreeA, agreeB: IX25519Agreement;
   agreeA, agreeB: IX25519Agreement;
-  secretA, secretB: TCryptoLibByteArray;
+  secretA, secretB: TBytes;
 begin
 begin
   kpGen := TX25519KeyPairGenerator.Create() as IX25519KeyPairGenerator;
   kpGen := TX25519KeyPairGenerator.Create() as IX25519KeyPairGenerator;
   kpGen.Init(TX25519KeyGenerationParameters.Create(FRandom)
   kpGen.Init(TX25519KeyGenerationParameters.Create(FRandom)
@@ -93,7 +87,7 @@ begin
   System.SetLength(secretB, agreeB.AgreementSize);
   System.SetLength(secretB, agreeB.AgreementSize);
   agreeB.CalculateAgreement(kpA.Public, secretB, 0);
   agreeB.CalculateAgreement(kpA.Public, secretB, 0);
 
 
-  if (not TArrayUtils.AreEqual(secretA, secretB)) then
+  if (not AreEqual(secretA, secretB)) then
   begin
   begin
     Fail('X25519 agreement failed');
     Fail('X25519 agreement failed');
   end;
   end;
@@ -128,7 +122,7 @@ initialization
 // Register any test cases with the test runner
 // Register any test cases with the test runner
 
 
 {$IFDEF FPC}
 {$IFDEF FPC}
- RegisterTest(TTestX25519HigherLevel);
+  RegisterTest(TTestX25519HigherLevel);
 {$ELSE}
 {$ELSE}
   RegisterTest(TTestX25519HigherLevel.Suite);
   RegisterTest(TTestX25519HigherLevel.Suite);
 {$ENDIF FPC}
 {$ENDIF FPC}

+ 12 - 20
CryptoLib.Tests/src/Security/DigestUtilitiesTests.pas

@@ -36,28 +36,20 @@ uses
   ClpIDigest,
   ClpIDigest,
   ClpDigest,
   ClpDigest,
   ClpDigestUtilities,
   ClpDigestUtilities,
-  ClpArrayUtils,
-  ClpCryptoLibTypes;
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
-
-type
-
-  TTestDigestUtilities = class(TCryptoLibTestCase)
+  TTestDigestUtilities = class(TCryptoLibAlgorithmTestCase)
   private
   private
   var
   var
-    FTestBytes: TCryptoLibByteArray;
+    FTestBytes: TBytes;
 
 
-    function MakeTestPlainDigest(const digest: IDigest): TCryptoLibByteArray;
+    function MakeTestPlainDigest(const digest: IDigest): TBytes;
     procedure CheckPlainDigestAlgorithm(const name: String;
     procedure CheckPlainDigestAlgorithm(const name: String;
       const digest: IDigest);
       const digest: IDigest);
 
 
-    function MakeTestXofDigest(const digest: IDigest; count: Int32)
-      : TCryptoLibByteArray;
+    function MakeTestXofDigest(const digest: IDigest; count: Int32): TBytes;
     procedure CheckXofDigestAlgorithm(const name: String;
     procedure CheckXofDigestAlgorithm(const name: String;
       const digest: IDigest);
       const digest: IDigest);
 
 
@@ -86,15 +78,15 @@ begin
 end;
 end;
 
 
 function TTestDigestUtilities.MakeTestXofDigest(const digest: IDigest;
 function TTestDigestUtilities.MakeTestXofDigest(const digest: IDigest;
-  count: Int32): TCryptoLibByteArray;
+  count: Int32): TBytes;
 begin
 begin
   System.SetLength(Result, count);
   System.SetLength(Result, count);
   digest.BlockUpdate(FTestBytes, 0, System.Length(FTestBytes));
   digest.BlockUpdate(FTestBytes, 0, System.Length(FTestBytes));
   digest.DoFinal(Result, 0);
   digest.DoFinal(Result, 0);
 end;
 end;
 
 
-function TTestDigestUtilities.MakeTestPlainDigest(const digest: IDigest)
-  : TCryptoLibByteArray;
+function TTestDigestUtilities.MakeTestPlainDigest(const digest
+  : IDigest): TBytes;
 var
 var
   i: Int32;
   i: Int32;
 begin
 begin
@@ -111,7 +103,7 @@ end;
 procedure TTestDigestUtilities.CheckXofDigestAlgorithm(const name: String;
 procedure TTestDigestUtilities.CheckXofDigestAlgorithm(const name: String;
   const digest: IDigest);
   const digest: IDigest);
 var
 var
-  hash1, hash2: TCryptoLibByteArray;
+  hash1, hash2: TBytes;
   i: Int32;
   i: Int32;
 begin
 begin
   for i := 1 to 100 do
   for i := 1 to 100 do
@@ -119,7 +111,7 @@ begin
     hash1 := MakeTestXofDigest(digest, i);
     hash1 := MakeTestXofDigest(digest, i);
     hash2 := MakeTestXofDigest(TDigestUtilities.GetDigest(name), i);
     hash2 := MakeTestXofDigest(TDigestUtilities.GetDigest(name), i);
 
 
-    if not TArrayUtils.AreEqual(hash1, hash2) then
+    if not AreEqual(hash1, hash2) then
     begin
     begin
       Fail(Format
       Fail(Format
         ('%s (%d) at Index %d CheckXofDigestAlgorithm Operation Failed',
         ('%s (%d) at Index %d CheckXofDigestAlgorithm Operation Failed',
@@ -131,12 +123,12 @@ end;
 procedure TTestDigestUtilities.CheckPlainDigestAlgorithm(const name: String;
 procedure TTestDigestUtilities.CheckPlainDigestAlgorithm(const name: String;
   const digest: IDigest);
   const digest: IDigest);
 var
 var
-  hash1, hash2: TCryptoLibByteArray;
+  hash1, hash2: TBytes;
 begin
 begin
   hash1 := MakeTestPlainDigest(digest);
   hash1 := MakeTestPlainDigest(digest);
   hash2 := MakeTestPlainDigest(TDigestUtilities.GetDigest(name));
   hash2 := MakeTestPlainDigest(TDigestUtilities.GetDigest(name));
 
 
-  if not TArrayUtils.AreEqual(hash1, hash2) then
+  if not AreEqual(hash1, hash2) then
   begin
   begin
     Fail(Format('%s CheckPlainDigestAlgorithm Operation Failed', [name]));
     Fail(Format('%s CheckPlainDigestAlgorithm Operation Failed', [name]));
   end;
   end;

+ 5 - 10
CryptoLib.Tests/src/Security/SecureRandomTests.pas

@@ -32,21 +32,16 @@ uses
 {$ELSE}
 {$ELSE}
   TestFramework,
   TestFramework,
 {$ENDIF FPC}
 {$ENDIF FPC}
-  ClpCryptoLibTypes,
   ClpSecureRandom,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpISecureRandom,
   ClpCryptoApiRandomGenerator,
   ClpCryptoApiRandomGenerator,
-  ClpICryptoApiRandomGenerator;
-
-type
-
-  TCryptoLibTestCase = class abstract(TTestCase)
-
-  end;
+  ClpICryptoApiRandomGenerator,
+  ClpCryptoLibTypes,
+  CryptoLibTestBase;
 
 
 type
 type
 
 
-  TTestSecureRandom = class(TCryptoLibTestCase)
+  TTestSecureRandom = class(TCryptoLibAlgorithmTestCase)
   private
   private
 
 
     procedure CheckSecureRandom(const random: ISecureRandom);
     procedure CheckSecureRandom(const random: ISecureRandom);
@@ -80,7 +75,7 @@ end;
 function TTestSecureRandom.MeasureChiSquared(const random: ISecureRandom;
 function TTestSecureRandom.MeasureChiSquared(const random: ISecureRandom;
   rounds: Int32): Double;
   rounds: Int32): Double;
 var
 var
-  opts, bs: TCryptoLibByteArray;
+  opts, bs: TBytes;
   counts: TCryptoLibInt32Array;
   counts: TCryptoLibInt32Array;
   I, b, total, k, mask, shift: Int32;
   I, b, total, k, mask, shift: Int32;
   chi2, diff, diff2, temp: Double;
   chi2, diff, diff2, temp: Double;