Browse Source

Add Support For ECNR and DSA Signing.

Ugochukwu Mmaduekwe 7 years ago
parent
commit
7916ee69cd
27 changed files with 2174 additions and 53 deletions
  1. 22 3
      CryptoLib.Samples/Delphi.Samples/UsageSamples.dpr
  2. 20 1
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr
  3. 48 28
      CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas
  4. 151 0
      CryptoLib/src/Crypto/Generators/ClpDsaKeyPairGenerator.pas
  5. 66 0
      CryptoLib/src/Crypto/Parameters/ClpDsaKeyGenerationParameters.pas
  6. 95 0
      CryptoLib/src/Crypto/Parameters/ClpDsaKeyParameters.pas
  7. 141 0
      CryptoLib/src/Crypto/Parameters/ClpDsaParameters.pas
  8. 98 0
      CryptoLib/src/Crypto/Parameters/ClpDsaPrivateKeyParameters.pas
  9. 118 0
      CryptoLib/src/Crypto/Parameters/ClpDsaPublicKeyParameters.pas
  10. 120 0
      CryptoLib/src/Crypto/Parameters/ClpDsaValidationParameters.pas
  11. 267 0
      CryptoLib/src/Crypto/Signers/ClpDsaSigner.pas
  12. 288 0
      CryptoLib/src/Crypto/Signers/ClpECNRSigner.pas
  13. 40 0
      CryptoLib/src/Interfaces/ClpIDsaKeyGenerationParameters.pas
  14. 38 0
      CryptoLib/src/Interfaces/ClpIDsaKeyPairGenerator.pas
  15. 43 0
      CryptoLib/src/Interfaces/ClpIDsaKeyParameters.pas
  16. 48 0
      CryptoLib/src/Interfaces/ClpIDsaParameters.pas
  17. 40 0
      CryptoLib/src/Interfaces/ClpIDsaPrivateKeyParameters.pas
  18. 40 0
      CryptoLib/src/Interfaces/ClpIDsaPublicKeyParameters.pas
  19. 70 0
      CryptoLib/src/Interfaces/ClpIDsaSigner.pas
  20. 42 0
      CryptoLib/src/Interfaces/ClpIDsaValidationParameters.pas
  21. 50 0
      CryptoLib/src/Interfaces/ClpIECNRSigner.pas
  22. 78 2
      CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk
  23. 8 1
      CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas
  24. 9 0
      CryptoLib/src/Security/ClpGeneratorUtilities.pas
  25. 170 14
      CryptoLib/src/Security/ClpSignerUtilities.pas
  26. 53 0
      CryptoLib/src/Utils/Encoders/ClpBase58.pas
  27. 11 4
      CryptoLib/src/Utils/Encoders/ClpHex.pas

+ 22 - 3
CryptoLib.Samples/Delphi.Samples/UsageSamples.dpr

@@ -372,7 +372,26 @@ uses
   ClpIECSchnorrISOXSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrISOXSigner.pas',
   ClpIECSchnorrISOXSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrISOXSigner.pas',
   ClpECSchnorrISOXSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrISOXSigner.pas',
   ClpECSchnorrISOXSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrISOXSigner.pas',
   ClpIECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrLIBSECPSigner.pas',
   ClpIECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrLIBSECPSigner.pas',
-  ClpECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrLIBSECPSigner.pas';
+  ClpECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrLIBSECPSigner.pas',
+  ClpECNRSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECNRSigner.pas',
+  ClpIECNRSigner in '..\..\CryptoLib\src\Interfaces\ClpIECNRSigner.pas',
+  ClpDsaValidationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaValidationParameters.pas',
+  ClpIDsaValidationParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaValidationParameters.pas',
+  ClpDsaParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaParameters.pas',
+  ClpIDsaParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaParameters.pas',
+  ClpDsaPublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaPublicKeyParameters.pas',
+  ClpIDsaPublicKeyParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaPublicKeyParameters.pas',
+  ClpDsaKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaKeyParameters.pas',
+  ClpIDsaKeyParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaKeyParameters.pas',
+  ClpDsaKeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaKeyGenerationParameters.pas',
+  ClpIDsaKeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaKeyGenerationParameters.pas',
+  ClpDsaPrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaPrivateKeyParameters.pas',
+  ClpIDsaPrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaPrivateKeyParameters.pas',
+  ClpDsaKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDsaKeyPairGenerator.pas',
+  ClpIDsaKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\ClpIDsaKeyPairGenerator.pas',
+  ClpDsaSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpDsaSigner.pas',
+  ClpBase58 in '..\..\CryptoLib\src\Utils\Encoders\ClpBase58.pas',
+  ClpIDsaSigner in '..\..\CryptoLib\src\Interfaces\ClpIDsaSigner.pas';
 
 
 begin
 begin
   try
   try
@@ -384,8 +403,8 @@ begin
     TUsageExamples.RecreatePublicKeyFromXAndYCoordByteArray;
     TUsageExamples.RecreatePublicKeyFromXAndYCoordByteArray;
     TUsageExamples.BinaryCompatiblePascalCoinAES256EncryptDecryptDemo('Pascal Rules', 'Pascal');
     TUsageExamples.BinaryCompatiblePascalCoinAES256EncryptDecryptDemo('Pascal Rules', 'Pascal');
     TUsageExamples.BinaryCompatiblePascalCoinECIESEncryptDecryptDemo('Kowalski');
     TUsageExamples.BinaryCompatiblePascalCoinECIESEncryptDecryptDemo('Kowalski');
-//  TUsageExamples.BinaryCompatiblePascalCoinECIESEncryptExistingPayloadDemo('', '', '');
-//  TUsageExamples.BinaryCompatiblePascalCoinECIESDecryptExistingPayloadDemo('', '', '');
+//    TUsageExamples.BinaryCompatiblePascalCoinECIESEncryptExistingPayloadDemo('', '', '');
+//    TUsageExamples.BinaryCompatiblePascalCoinECIESDecryptExistingPayloadDemo('', '', '');
       Readln;
       Readln;
   except
   except
     on E: Exception do
     on E: Exception do

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

@@ -410,7 +410,26 @@ uses
   ClpIECSchnorrISOXSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrISOXSigner.pas',
   ClpIECSchnorrISOXSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrISOXSigner.pas',
   ClpECSchnorrISOXSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrISOXSigner.pas',
   ClpECSchnorrISOXSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrISOXSigner.pas',
   ClpIECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrLIBSECPSigner.pas',
   ClpIECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Interfaces\ClpIECSchnorrLIBSECPSigner.pas',
-  ClpECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrLIBSECPSigner.pas';
+  ClpECSchnorrLIBSECPSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrLIBSECPSigner.pas',
+  ClpECNRSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECNRSigner.pas',
+  ClpIECNRSigner in '..\..\CryptoLib\src\Interfaces\ClpIECNRSigner.pas',
+  ClpDsaValidationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaValidationParameters.pas',
+  ClpIDsaValidationParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaValidationParameters.pas',
+  ClpDsaParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaParameters.pas',
+  ClpIDsaParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaParameters.pas',
+  ClpDsaPublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaPublicKeyParameters.pas',
+  ClpIDsaPublicKeyParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaPublicKeyParameters.pas',
+  ClpDsaKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaKeyParameters.pas',
+  ClpIDsaKeyParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaKeyParameters.pas',
+  ClpDsaKeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaKeyGenerationParameters.pas',
+  ClpIDsaKeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaKeyGenerationParameters.pas',
+  ClpDsaPrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaPrivateKeyParameters.pas',
+  ClpIDsaPrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\ClpIDsaPrivateKeyParameters.pas',
+  ClpDsaKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDsaKeyPairGenerator.pas',
+  ClpIDsaKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\ClpIDsaKeyPairGenerator.pas',
+  ClpDsaSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpDsaSigner.pas',
+  ClpBase58 in '..\..\CryptoLib\src\Utils\Encoders\ClpBase58.pas',
+  ClpIDsaSigner in '..\..\CryptoLib\src\Interfaces\ClpIDsaSigner.pas';
 
 
 begin
 begin
 
 

+ 48 - 28
CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas

@@ -22,6 +22,7 @@ interface
 uses
 uses
   Classes,
   Classes,
   SysUtils,
   SysUtils,
+  ClpHex,
 {$IFDEF FPC}
 {$IFDEF FPC}
   fpcunit,
   fpcunit,
   testregistry,
   testregistry,
@@ -44,7 +45,13 @@ uses
   ClpECPrivateKeyParameters,
   ClpECPrivateKeyParameters,
   ClpIECPublicKeyParameters,
   ClpIECPublicKeyParameters,
   ClpIECPrivateKeyParameters,
   ClpIECPrivateKeyParameters,
-  ClpIECInterface;
+  ClpIECInterface,
+  ClpIDsaParameters,
+  ClpIDsaPrivateKeyParameters,
+  ClpIDsaPublicKeyParameters,
+  ClpDsaParameters,
+  ClpDsaPrivateKeyParameters,
+  ClpDsaPublicKeyParameters;
 
 
 type
 type
 
 
@@ -58,16 +65,15 @@ type
   private
   private
 
 
   var
   var
-    //
-    // ECDSA parameters
-    //
-
-    FECParraGX, FECParraGY, FECParraH, FECParraN, FECPubQX, FECPubQY,
-      FECPrivD: TBigInteger;
+    FECParraGX, FECParraGY, FECParraH, FECParraN, FECPubQX, FECPubQY, FECPrivD,
+      FDSAParaG, FDSAParaP, FDSAParaQ, FDSAPublicY, FDsaPrivateX: TBigInteger;
     Fcurve: IECCurve;
     Fcurve: IECCurve;
     FecDomain: IECDomainParameters;
     FecDomain: IECDomainParameters;
     FecPub: IECPublicKeyParameters;
     FecPub: IECPublicKeyParameters;
     FecPriv: IECPrivateKeyParameters;
     FecPriv: IECPrivateKeyParameters;
+    Fpara: IDsaParameters;
+    FdsaPriv: IDsaPrivateKeyParameters;
+    FdsaPub: IDsaPublicKeyParameters;
 
 
   protected
   protected
     procedure SetUp; override;
     procedure SetUp; override;
@@ -84,6 +90,11 @@ implementation
 procedure TTestSignerUtilities.SetUp;
 procedure TTestSignerUtilities.SetUp;
 begin
 begin
   inherited;
   inherited;
+
+  //
+  // ECDSA parameters
+  //
+
   FECParraGX := TBigInteger.Create
   FECParraGX := TBigInteger.Create
     (TBase64.Decode('D/qWPNyogWzMM7hkK+35BcPTWFc9Pyf7vTs8uaqv'));
     (TBase64.Decode('D/qWPNyogWzMM7hkK+35BcPTWFc9Pyf7vTs8uaqv'));
   FECParraGY := TBigInteger.Create
   FECParraGY := TBigInteger.Create
@@ -98,27 +109,6 @@ begin
   FECPrivD := TBigInteger.Create
   FECPrivD := TBigInteger.Create
     (TBase64.Decode('GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo'));
     (TBase64.Decode('GYQmd/NF1B+He1iMkWt3by2Az6Eu07t0ynJ4YCAo'));
 
 
-  // FECParraGX := TBigInteger.Create(TCryptoLibByteArray.Create(15, 250, 150, 60,
-  // 220, 168, 129, 108, 204, 51, 184, 100, 43, 237, 249, 5, 195, 211, 88, 87,
-  // 61, 63, 39, 251, 189, 59, 60, 185, 170, 175));
-  // FECParraGY := TBigInteger.Create(TCryptoLibByteArray.Create(2, 20, 23, 27, 22,
-  // 245, 162, 81, 145, 191, 171, 53, 44, 244, 95, 185, 171, 76, 23, 231, 49,
-  // 221, 148, 198, 131, 52, 132, 253, 14, 81));
-  //
-  // FECParraH := TBigInteger.Create(TCryptoLibByteArray.Create(1));
-  // FECParraN := TBigInteger.Create(TCryptoLibByteArray.Create(127, 255, 255, 255,
-  // 255, 255, 255, 255, 255, 255, 255, 255, 127, 255, 255, 158, 94, 154, 159,
-  // 93, 144, 113, 251, 209, 82, 38, 136, 144, 157, 11));
-  // FECPubQX := TBigInteger.Create(TCryptoLibByteArray.Create(29, 101, 162, 215,
-  // 182, 27, 248, 25, 183, 61, 138, 255, 12, 200, 203, 57, 131, 69, 135, 35,
-  // 176, 95, 84, 24, 237, 155, 234, 168, 207, 165));
-  // FECPubQY := TBigInteger.Create(TCryptoLibByteArray.Create(38, 185, 73, 127,
-  // 27, 183, 88, 104, 106, 194, 210, 255, 231, 144, 78, 179, 252, 44, 81, 232,
-  // 131, 22, 203, 215, 112, 104, 65, 240, 49, 177));
-  // FECPrivD := TBigInteger.Create(TCryptoLibByteArray.Create(25, 132, 38, 119,
-  // 243, 69, 212, 31, 135, 123, 88, 140, 145, 107, 119, 111, 45, 128, 207, 161,
-  // 46, 211, 187, 116, 202, 114, 120, 96, 32, 40));
-
   Fcurve := TFpCurve.Create
   Fcurve := TFpCurve.Create
     (TBigInteger.Create
     (TBigInteger.Create
     ('883423532389192164791648750360308885314476597252960362792450860609699839'),
     ('883423532389192164791648750360308885314476597252960362792450860609699839'),
@@ -138,6 +128,31 @@ begin
 
 
   FecPriv := TECPrivateKeyParameters.Create(FECPrivD, FecDomain);
   FecPriv := TECPrivateKeyParameters.Create(FECPrivD, FecDomain);
 
 
+  //
+  // DSA parameters
+  //
+
+  FDSAParaG := TBigInteger.Create
+    (TBase64.Decode
+    ('AL0fxOTq10OHFbCf8YldyGembqEu08EDVzxyLL29Zn/t4It661YNol1rnhPIs+cirw+yf9zeCe+KL1IbZ/qIMZM=')
+    );
+  FDSAParaP := TBigInteger.Create
+    (TBase64.Decode
+    ('AM2b/UeQA+ovv3dL05wlDHEKJ+qhnJBsRT5OB9WuyRC830G79y0R8wuq8jyIYWCYcTn1TeqVPWqiTv6oAoiEeOs=')
+    );
+  FDSAParaQ := TBigInteger.Create
+    (TBase64.Decode('AIlJT7mcKL6SUBMmvm24zX1EvjNx'));
+  FDSAPublicY := TBigInteger.Create
+    (TBase64.Decode
+    ('TtWy2GuT9yGBWOHi1/EpCDa/bWJCk2+yAdr56rAcqP0eHGkMnA9s9GJD2nGU8sFjNHm55swpn6JQb8q0agrCfw==')
+    );
+  FDsaPrivateX := TBigInteger.Create
+    (TBase64.Decode('MMpBAxNlv7eYfxLTZ2BItJeD31A='));
+
+  Fpara := TDsaParameters.Create(FDSAParaP, FDSAParaQ, FDSAParaG);
+  FdsaPriv := TDsaPrivateKeyParameters.Create(FDsaPrivateX, Fpara);
+  FdsaPub := TDsaPublicKeyParameters.Create(FDSAPublicY, Fpara);
+
 end;
 end;
 
 
 procedure TTestSignerUtilities.TearDown;
 procedure TTestSignerUtilities.TearDown;
@@ -189,6 +204,11 @@ begin
       signParams := FecPriv;
       signParams := FecPriv;
       verifyParams := FecPub;
       verifyParams := FecPub;
     end
     end
+    else if (cipherName = 'DSA') then
+    begin
+      signParams := FdsaPriv;
+      verifyParams := FdsaPub;
+    end
     else
     else
     begin
     begin
       Fail('Unknown algorithm encountered: ' + cipherName);
       Fail('Unknown algorithm encountered: ' + cipherName);

+ 151 - 0
CryptoLib/src/Crypto/Generators/ClpDsaKeyPairGenerator.pas

@@ -0,0 +1,151 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaKeyPairGenerator;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpISecureRandom,
+  ClpIDsaParameters,
+  ClpIDsaKeyPairGenerator,
+  ClpDsaPublicKeyParameters,
+  ClpIDsaPublicKeyParameters,
+  ClpDsaPrivateKeyParameters,
+  ClpIDsaPrivateKeyParameters,
+  ClpAsymmetricCipherKeyPair,
+  ClpIAsymmetricCipherKeyPair,
+  ClpIKeyGenerationParameters,
+  ClpIDsaKeyGenerationParameters,
+  ClpIAsymmetricCipherKeyPairGenerator,
+  ClpBits,
+  ClpBigInteger,
+  ClpBigIntegers,
+  ClpWNafUtilities,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SParametersCannotBeNil = '"parameters" Cannot Be Nil';
+
+type
+
+  /// <summary>
+  /// <para>
+  /// a DSA key pair generator.
+  /// </para>
+  /// <para>
+  /// This Generates DSA keys in line with the method described in <i>
+  /// FIPS 186-3 B.1 FFC Key Pair Generation</i>
+  /// </para>
+  /// </summary>
+  TDsaKeyPairGenerator = class sealed(TInterfacedObject,
+    IAsymmetricCipherKeyPairGenerator, IDsaKeyPairGenerator)
+
+  strict private
+    class var
+
+      FOne: TBigInteger;
+
+  var
+    Fparam: IDsaKeyGenerationParameters;
+
+    class function GeneratePrivateKey(const q: TBigInteger;
+      const random: ISecureRandom): TBigInteger; static;
+
+    class function CalculatePublicKey(const p, g, x: TBigInteger): TBigInteger;
+      static; inline;
+
+    class constructor DsaKeyPairGenerator();
+
+  public
+
+    procedure Init(const parameters: IKeyGenerationParameters);
+
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+
+  end;
+
+implementation
+
+{ TDsaKeyPairGenerator }
+
+class function TDsaKeyPairGenerator.CalculatePublicKey(const p, g,
+  x: TBigInteger): TBigInteger;
+begin
+  result := g.ModPow(x, p);
+end;
+
+class constructor TDsaKeyPairGenerator.DsaKeyPairGenerator;
+begin
+  FOne := TBigInteger.One;
+end;
+
+function TDsaKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
+var
+  dsaParams: IDsaParameters;
+  x, y: TBigInteger;
+begin
+  dsaParams := Fparam.parameters;
+
+  x := GeneratePrivateKey(dsaParams.q, Fparam.random);
+  y := CalculatePublicKey(dsaParams.p, dsaParams.g, x);
+
+  result := TAsymmetricCipherKeyPair.Create(TDsaPublicKeyParameters.Create(y,
+    dsaParams) as IDsaPublicKeyParameters, TDsaPrivateKeyParameters.Create(x,
+    dsaParams) as IDsaPrivateKeyParameters);
+end;
+
+class function TDsaKeyPairGenerator.GeneratePrivateKey(const q: TBigInteger;
+  const random: ISecureRandom): TBigInteger;
+var
+  minWeight: Int32;
+  x: TBigInteger;
+begin
+  result := Default (TBigInteger);
+  // B.1.2 Key Pair Generation by Testing Candidates
+  minWeight := TBits.Asr32(q.BitLength, 2);
+  while (True) do
+  begin
+    // TODO Prefer this method? (change test cases that used fixed random)
+    // B.1.1 Key Pair Generation Using Extra Random Bits
+    // x := TBigInteger.Create(q.BitLength + 64, random).&Mod(q.Subtract(One)).Add(One);
+
+    x := TBigIntegers.CreateRandomInRange(FOne, q.Subtract(FOne), random);
+    if (TWNafUtilities.GetNafWeight(x) >= minWeight) then
+    begin
+      result := x;
+      Exit;
+    end;
+  end;
+end;
+
+procedure TDsaKeyPairGenerator.Init(const parameters: IKeyGenerationParameters);
+begin
+  if (parameters = Nil) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+  end;
+
+  // Note: If we start accepting instances of KeyGenerationParameters,
+  // must apply constraint checking on strength (see DsaParametersGenerator.Init)
+
+  Fparam := parameters as IDsaKeyGenerationParameters;
+end;
+
+end.

+ 66 - 0
CryptoLib/src/Crypto/Parameters/ClpDsaKeyGenerationParameters.pas

@@ -0,0 +1,66 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaKeyGenerationParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpBigInteger,
+  ClpISecureRandom,
+  ClpIDsaParameters,
+  ClpIDsaKeyGenerationParameters,
+  ClpKeyGenerationParameters;
+
+type
+  TDsaKeyGenerationParameters = class sealed(TKeyGenerationParameters,
+    IDsaKeyGenerationParameters)
+  strict private
+  var
+    Fparameters: IDsaParameters;
+
+    function GetParameters: IDsaParameters; inline;
+
+  public
+    constructor Create(const random: ISecureRandom;
+      const parameters: IDsaParameters);
+
+    property parameters: IDsaParameters read GetParameters;
+  end;
+
+implementation
+
+{ TDsaKeyGenerationParameters }
+
+constructor TDsaKeyGenerationParameters.Create(const random: ISecureRandom;
+  const parameters: IDsaParameters);
+var
+  P: TBigInteger;
+begin
+  P := parameters.P;
+  Inherited Create(random, P.BitLength - 1);
+  Fparameters := parameters;
+end;
+
+function TDsaKeyGenerationParameters.GetParameters: IDsaParameters;
+begin
+  result := Fparameters;
+end;
+
+end.

+ 95 - 0
CryptoLib/src/Crypto/Parameters/ClpDsaKeyParameters.pas

@@ -0,0 +1,95 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaKeyParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaParameters,
+  ClpIDsaKeyParameters,
+  ClpIAsymmetricKeyParameter,
+  ClpAsymmetricKeyParameter;
+
+type
+  TDsaKeyParameters = class abstract(TAsymmetricKeyParameter, IDsaKeyParameters)
+
+  strict private
+  var
+    Fparameters: IDsaParameters;
+  strict private
+    function GetParameters: IDsaParameters;
+  protected
+    constructor Create(isPrivate: Boolean; parameters: IDsaParameters);
+
+  public
+    function Equals(const other: IDsaKeyParameters): Boolean; reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property parameters: IDsaParameters read GetParameters;
+
+  end;
+
+implementation
+
+{ TDsaKeyParameters }
+
+constructor TDsaKeyParameters.Create(isPrivate: Boolean;
+  parameters: IDsaParameters);
+begin
+  Inherited Create(isPrivate);
+  // Note: parameters may be Nil
+  Fparameters := parameters;
+end;
+
+function TDsaKeyParameters.Equals(const other: IDsaKeyParameters): Boolean;
+begin
+  if other = Nil then
+  begin
+    result := False;
+    Exit;
+  end;
+  if ((Self as IDsaKeyParameters) = other) then
+  begin
+    result := True;
+    Exit;
+  end;
+  result := (parameters as TObject).Equals(other.parameters as TObject) and
+    (Inherited Equals(other));
+end;
+
+function TDsaKeyParameters.GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  result := Inherited GetHashCode();
+
+  if (parameters <> Nil) then
+  begin
+    result := result xor parameters.GetHashCode();
+  end;
+
+end;
+
+function TDsaKeyParameters.GetParameters: IDsaParameters;
+begin
+  result := Fparameters;
+end;
+
+end.

+ 141 - 0
CryptoLib/src/Crypto/Parameters/ClpDsaParameters.pas

@@ -0,0 +1,141 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpICipherParameters,
+  ClpIDsaParameters,
+  ClpIDsaValidationParameters,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SPUnInitialized = '"P" Cannot Be Uninitialized';
+  SQUnInitialized = '"Q" Cannot Be Uninitialized';
+  SGUnInitialized = '"G" Cannot Be Uninitialized';
+
+type
+  TDsaParameters = class(TInterfacedObject, ICipherParameters, IDsaParameters)
+
+  strict private
+  var
+    Fp, Fq, Fg: TBigInteger;
+    Fvalidation: IDsaValidationParameters;
+
+    function GetG: TBigInteger; inline;
+    function GetP: TBigInteger; inline;
+    function GetQ: TBigInteger; inline;
+    function GetValidationParameters: IDsaValidationParameters; inline;
+
+  public
+    constructor Create(const p, q, g: TBigInteger); overload;
+    constructor Create(const p, q, g: TBigInteger;
+      const parameters: IDsaValidationParameters); overload;
+
+    function Equals(const other: IDsaParameters): Boolean; reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property p: TBigInteger read GetP;
+    property q: TBigInteger read GetQ;
+    property g: TBigInteger read GetG;
+    property ValidationParameters: IDsaValidationParameters
+      read GetValidationParameters;
+
+  end;
+
+implementation
+
+{ TDsaParameters }
+
+constructor TDsaParameters.Create(const p, q, g: TBigInteger);
+begin
+  Create(p, q, g, Nil);
+end;
+
+constructor TDsaParameters.Create(const p, q, g: TBigInteger;
+  const parameters: IDsaValidationParameters);
+begin
+  Inherited Create();
+  if (not(p.IsInitialized)) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SPUnInitialized);
+  end;
+
+  if (not(q.IsInitialized)) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SQUnInitialized);
+  end;
+
+  if (not(g.IsInitialized)) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SGUnInitialized);
+  end;
+
+  Fp := p;
+  Fq := q;
+  Fg := g;
+  Fvalidation := parameters;
+end;
+
+function TDsaParameters.Equals(const other: IDsaParameters): Boolean;
+begin
+  if other = Nil then
+  begin
+    result := False;
+    Exit;
+  end;
+  if ((Self as IDsaParameters) = other) then
+  begin
+    result := True;
+    Exit;
+  end;
+  result := p.Equals(other.p) and q.Equals(other.q) and g.Equals(other.g);
+end;
+
+function TDsaParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  result := p.GetHashCode() xor q.GetHashCode() xor g.GetHashCode();
+end;
+
+function TDsaParameters.GetG: TBigInteger;
+begin
+  result := Fg;
+end;
+
+function TDsaParameters.GetP: TBigInteger;
+begin
+  result := Fp;
+end;
+
+function TDsaParameters.GetQ: TBigInteger;
+begin
+  result := Fq;
+end;
+
+function TDsaParameters.GetValidationParameters: IDsaValidationParameters;
+begin
+  result := Fvalidation;
+end;
+
+end.

+ 98 - 0
CryptoLib/src/Crypto/Parameters/ClpDsaPrivateKeyParameters.pas

@@ -0,0 +1,98 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaPrivateKeyParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaParameters,
+  ClpIDsaPrivateKeyParameters,
+  ClpDsaKeyParameters,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SXUnInitialized = '"X" Cannot Be Uninitialized';
+
+type
+  TDsaPrivateKeyParameters = class sealed(TDsaKeyParameters,
+    IDsaPrivateKeyParameters)
+
+  strict private
+  var
+    Fx: TBigInteger;
+
+    function GetX: TBigInteger; inline;
+
+  public
+    constructor Create(const x: TBigInteger; const parameters: IDsaParameters);
+
+    function Equals(const other: IDsaPrivateKeyParameters): Boolean;
+      reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property x: TBigInteger read GetX;
+  end;
+
+implementation
+
+{ TDsaPrivateKeyParameters }
+
+constructor TDsaPrivateKeyParameters.Create(const x: TBigInteger;
+  const parameters: IDsaParameters);
+begin
+  Inherited Create(true, parameters);
+  if (not(x.IsInitialized)) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SXUnInitialized);
+  end;
+
+  Fx := x;
+end;
+
+function TDsaPrivateKeyParameters.Equals(const other
+  : IDsaPrivateKeyParameters): Boolean;
+begin
+  if other = Nil then
+  begin
+    result := False;
+    Exit;
+  end;
+  if ((Self as IDsaPrivateKeyParameters) = other) then
+  begin
+    result := true;
+    Exit;
+  end;
+  result := (x.Equals(other.x)) and (Inherited Equals(other));
+end;
+
+function TDsaPrivateKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  result := x.GetHashCode() xor (Inherited GetHashCode());
+end;
+
+function TDsaPrivateKeyParameters.GetX: TBigInteger;
+begin
+  result := Fx;
+end;
+
+end.

+ 118 - 0
CryptoLib/src/Crypto/Parameters/ClpDsaPublicKeyParameters.pas

@@ -0,0 +1,118 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaPublicKeyParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaParameters,
+  ClpIDsaPublicKeyParameters,
+  ClpDsaKeyParameters,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SYUnInitialized = '"Y" Cannot Be Uninitialized';
+  SInvalidYInCorrectGroup = '"Y" Value Does Not Appear To Be In Correct Group';
+
+type
+  TDsaPublicKeyParameters = class sealed(TDsaKeyParameters,
+    IDsaPublicKeyParameters)
+
+  strict private
+  var
+    Fy: TBigInteger;
+
+    class function Validate(const y: TBigInteger;
+      const parameters: IDsaParameters): TBigInteger; static; inline;
+
+    function GetY: TBigInteger; inline;
+
+  public
+    constructor Create(const y: TBigInteger; const parameters: IDsaParameters);
+
+    function Equals(const other: IDsaPublicKeyParameters): Boolean; reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property y: TBigInteger read GetY;
+  end;
+
+implementation
+
+{ TDsaPublicKeyParameters }
+
+class function TDsaPublicKeyParameters.Validate(const y: TBigInteger;
+  const parameters: IDsaParameters): TBigInteger;
+begin
+  // we can't validate without params, fortunately we can't use the key either...
+  if (parameters <> Nil) then
+  begin
+    if ((y.CompareTo(TBigInteger.Two) < 0) or
+      (y.CompareTo(parameters.P.Subtract(TBigInteger.Two)) > 0) or
+      (not(y.ModPow(parameters.Q, parameters.P).Equals(TBigInteger.One)))) then
+    begin
+      raise EArgumentCryptoLibException.CreateRes(@SInvalidYInCorrectGroup);
+    end;
+  end;
+
+  result := y;
+end;
+
+constructor TDsaPublicKeyParameters.Create(const y: TBigInteger;
+  const parameters: IDsaParameters);
+begin
+  Inherited Create(false, parameters);
+  if (not(y.IsInitialized)) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SYUnInitialized);
+  end;
+
+  Fy := Validate(y, parameters);
+end;
+
+function TDsaPublicKeyParameters.Equals(const other
+  : IDsaPublicKeyParameters): Boolean;
+begin
+  if other = Nil then
+  begin
+    result := False;
+    Exit;
+  end;
+  if ((Self as IDsaPublicKeyParameters) = other) then
+  begin
+    result := True;
+    Exit;
+  end;
+  result := (y.Equals(other.y)) and (Inherited Equals(other));
+end;
+
+function TDsaPublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  result := y.GetHashCode() xor (Inherited GetHashCode());
+end;
+
+function TDsaPublicKeyParameters.GetY: TBigInteger;
+begin
+  result := Fy;
+end;
+
+end.

+ 120 - 0
CryptoLib/src/Crypto/Parameters/ClpDsaValidationParameters.pas

@@ -0,0 +1,120 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaValidationParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaValidationParameters,
+  ClpArrayUtils,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SSeedNil = '"Seed" Cannot Be Nil';
+
+type
+  TDsaValidationParameters = class(TInterfacedObject, IDsaValidationParameters)
+  strict private
+  var
+    Fseed: TCryptoLibByteArray;
+    Fcounter, FusageIndex: Int32;
+
+    function GetCounter: Int32; virtual;
+    function GetUsageIndex: Int32; virtual;
+    function GetSeed: TCryptoLibByteArray; virtual;
+
+  public
+    constructor Create(seed: TCryptoLibByteArray; counter: Int32); overload;
+    constructor Create(seed: TCryptoLibByteArray;
+      counter, usageIndex: Int32); overload;
+
+    function Equals(const other: IDsaValidationParameters): Boolean;
+      reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property counter: Int32 read GetCounter;
+    property usageIndex: Int32 read GetUsageIndex;
+    property seed: TCryptoLibByteArray read GetSeed;
+  end;
+
+implementation
+
+{ TDsaValidationParameters }
+
+constructor TDsaValidationParameters.Create(seed: TCryptoLibByteArray;
+  counter: Int32);
+begin
+  Create(seed, counter, -1);
+end;
+
+constructor TDsaValidationParameters.Create(seed: TCryptoLibByteArray;
+  counter, usageIndex: Int32);
+begin
+  Inherited Create();
+  if (seed = Nil) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SSeedNil);
+  end;
+
+  Fseed := System.Copy(seed);
+  Fcounter := counter;
+  FusageIndex := usageIndex;
+end;
+
+function TDsaValidationParameters.Equals(const other
+  : IDsaValidationParameters): Boolean;
+begin
+  if other = Nil then
+  begin
+    result := False;
+    Exit;
+  end;
+  if ((Self as IDsaValidationParameters) = other) then
+  begin
+    result := True;
+    Exit;
+  end;
+  result := (counter = other.counter) and TArrayUtils.AreEqual(seed,
+    other.seed);
+end;
+
+function TDsaValidationParameters.GetCounter: Int32;
+begin
+  result := Fcounter;
+end;
+
+function TDsaValidationParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  result := counter xor TArrayUtils.GetArrayHashCode(seed);
+end;
+
+function TDsaValidationParameters.GetSeed: TCryptoLibByteArray;
+begin
+  result := System.Copy(Fseed);
+end;
+
+function TDsaValidationParameters.GetUsageIndex: Int32;
+begin
+  result := FusageIndex;
+end;
+
+end.

+ 267 - 0
CryptoLib/src/Crypto/Signers/ClpDsaSigner.pas

@@ -0,0 +1,267 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpDsaSigner;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  Math,
+  SysUtils,
+  ClpIDsa,
+  ClpIDsaSigner,
+  ClpISecureRandom,
+  ClpIDsaParameters,
+  ClpIDsaKCalculator,
+  ClpICipherParameters,
+  ClpIDsaKeyParameters,
+  ClpIParametersWithRandom,
+  ClpIDsaPublicKeyParameters,
+  ClpIDsaPrivateKeyParameters,
+  ClpSecureRandom,
+  ClpRandomDsaKCalculator,
+  ClpBits,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SDSAPrivateKeyNotFound = 'DSA Private Key Required For Signing';
+  SDSAPublicKeyNotFound = 'DSA Public Key Required For Verification';
+
+type
+
+  /// <summary>
+  /// The Digital Signature Algorithm - as described in "Handbook of Applied <br />
+  /// Cryptography", pages 452 - 453.
+  /// </summary>
+  TDsaSigner = class(TInterfacedObject, IDsa, IDsaSigner)
+
+  strict private
+    function GetAlgorithmName: String; virtual;
+  strict protected
+  var
+    FkCalculator: IDsaKCalculator;
+    Fkey: IDsaKeyParameters;
+    Frandom: ISecureRandom;
+
+    function CalculateE(const n: TBigInteger; &message: TCryptoLibByteArray)
+      : TBigInteger; virtual;
+
+    function InitSecureRandom(needed: Boolean; const provided: ISecureRandom)
+      : ISecureRandom; virtual;
+
+  public
+
+    /// <summary>
+    /// Default configuration, random K values.
+    /// </summary>
+    constructor Create(); overload;
+
+    /// <summary>
+    /// Configuration with an alternate, possibly deterministic calculator of
+    /// K.
+    /// </summary>
+    /// <param name="kCalculator">
+    /// a K value calculator.
+    /// </param>
+    constructor Create(const kCalculator: IDsaKCalculator); overload;
+
+    procedure Init(forSigning: Boolean; const parameters: ICipherParameters);
+
+    /// <summary>
+    /// Generate a signature for the given message using the key we were <br />
+    /// initialised with. For conventional DSA the message should be a SHA-1 <br />
+    /// hash of the message of interest.
+    /// </summary>
+    /// <param name="&amp;message">
+    /// the message that will be verified later.
+    /// </param>
+    function GenerateSignature(&message: TCryptoLibByteArray)
+      : TCryptoLibGenericArray<TBigInteger>; virtual;
+
+    /// <summary>
+    /// return true if the value r and s represent a DSA signature for <br />
+    /// the passed in message for standard DSA the message should be a <br />
+    /// SHA-1 hash of the real message to be verified.
+    /// </summary>
+    function VerifySignature(&message: TCryptoLibByteArray;
+      const r, s: TBigInteger): Boolean; virtual;
+
+    property AlgorithmName: String read GetAlgorithmName;
+
+  end;
+
+implementation
+
+{ TDsaSigner }
+
+constructor TDsaSigner.Create;
+begin
+  Inherited Create();
+  FkCalculator := TRandomDsaKCalculator.Create();
+end;
+
+function TDsaSigner.CalculateE(const n: TBigInteger;
+  &message: TCryptoLibByteArray): TBigInteger;
+var
+  length: Int32;
+begin
+  length := Math.Min(System.length(&message), TBits.Asr32(n.BitLength, 3));
+  result := TBigInteger.Create(1, &message, 0, length);
+end;
+
+constructor TDsaSigner.Create(const kCalculator: IDsaKCalculator);
+begin
+  Inherited Create();
+  FkCalculator := kCalculator;
+end;
+
+function TDsaSigner.GenerateSignature(&message: TCryptoLibByteArray)
+  : TCryptoLibGenericArray<TBigInteger>;
+var
+  parameters: IDsaParameters;
+  q, m, x, k, r, s: TBigInteger;
+begin
+  parameters := Fkey.parameters;
+  q := parameters.q;
+  m := CalculateE(q, &message);
+  x := (Fkey as IDsaPrivateKeyParameters).x;
+
+  if (FkCalculator.IsDeterministic) then
+  begin
+    FkCalculator.Init(q, x, &message);
+  end
+  else
+  begin
+    FkCalculator.Init(q, Frandom);
+  end;
+
+  k := FkCalculator.NextK();
+
+  r := parameters.G.ModPow(k, parameters.P).&Mod(q);
+
+  k := k.ModInverse(q).Multiply(m.Add(x.Multiply(r)));
+
+  s := k.&Mod(q);
+
+  result := TCryptoLibGenericArray<TBigInteger>.Create(r, s);
+end;
+
+function TDsaSigner.GetAlgorithmName: String;
+begin
+  result := 'DSA';
+end;
+
+procedure TDsaSigner.Init(forSigning: Boolean;
+  const parameters: ICipherParameters);
+var
+  providedRandom: ISecureRandom;
+  rParam: IParametersWithRandom;
+  Lparameters: ICipherParameters;
+begin
+  providedRandom := Nil;
+  Lparameters := parameters;
+
+  if (forSigning) then
+  begin
+    if (Supports(Lparameters, IParametersWithRandom, rParam)) then
+    begin
+      providedRandom := rParam.Random;
+      Lparameters := rParam.parameters;
+    end;
+
+    if (not Supports(Lparameters, IDsaPrivateKeyParameters)) then
+    begin
+      raise EInvalidKeyCryptoLibException.CreateRes(@SDSAPrivateKeyNotFound);
+    end;
+
+    Fkey := Lparameters as IDsaPrivateKeyParameters;
+  end
+  else
+  begin
+    if (not Supports(Lparameters, IDsaPublicKeyParameters)) then
+    begin
+      raise EInvalidKeyCryptoLibException.CreateRes(@SDSAPublicKeyNotFound);
+    end;
+
+    Fkey := Lparameters as IDsaPublicKeyParameters;
+  end;
+
+  Frandom := InitSecureRandom(forSigning and (not FkCalculator.IsDeterministic),
+    providedRandom);
+end;
+
+function TDsaSigner.InitSecureRandom(needed: Boolean;
+  const provided: ISecureRandom): ISecureRandom;
+begin
+  if (not needed) then
+  begin
+    result := Nil;
+  end
+  else
+  begin
+    if provided <> Nil then
+    begin
+      result := provided;
+    end
+    else
+    begin
+      result := TSecureRandom.Create();
+    end;
+  end;
+
+end;
+
+function TDsaSigner.VerifySignature(&message: TCryptoLibByteArray;
+  const r, s: TBigInteger): Boolean;
+var
+  parameters: IDsaParameters;
+  q, m, w, u1, u2, P, v: TBigInteger;
+begin
+  parameters := Fkey.parameters;
+  q := parameters.q;
+  m := CalculateE(q, &message);
+
+  if ((r.SignValue <= 0) or (q.CompareTo(r) <= 0)) then
+  begin
+    result := false;
+    Exit;
+  end;
+
+  if ((s.SignValue <= 0) or (q.CompareTo(s) <= 0)) then
+  begin
+    result := false;
+    Exit;
+  end;
+
+  w := s.ModInverse(q);
+
+  u1 := m.Multiply(w).&Mod(q);
+  u2 := r.Multiply(w).&Mod(q);
+
+  P := parameters.P;
+  u1 := parameters.G.ModPow(u1, P);
+  u2 := (Fkey as IDsaPublicKeyParameters).Y.ModPow(u2, P);
+
+  v := u1.Multiply(u2).&Mod(P).&Mod(q);
+
+  result := v.Equals(r);
+end;
+
+end.

+ 288 - 0
CryptoLib/src/Crypto/Signers/ClpECNRSigner.pas

@@ -0,0 +1,288 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpECNRSigner;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpIDsa,
+  ClpIECInterface,
+  ClpIECNRSigner,
+  ClpBigInteger,
+  ClpISecureRandom,
+  ClpIECKeyParameters,
+  ClpIParametersWithRandom,
+  ClpICipherParameters,
+  ClpIECKeyPairGenerator,
+  ClpECKeyPairGenerator,
+  ClpECKeyGenerationParameters,
+  ClpIECKeyGenerationParameters,
+  ClpIECPrivateKeyParameters,
+  ClpIECPublicKeyParameters,
+  ClpIAsymmetricCipherKeyPair,
+  ClpSecureRandom,
+  ClpECAlgorithms,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SECPublicKeyNotFound = 'EC Public Key Required for Verification';
+  SECPrivateKeyNotFound = 'EC Private Key Required for Signing';
+  SNotInitializedForSigning = 'Not Initialised For Signing';
+  SNotInitializedForVerifying = 'Not Initialised For Verifying';
+  SInputTooLargeForECNRKey = 'Input Too Large For ECNR Key.';
+
+type
+
+  /// <summary>
+  /// EC-NR as described in IEEE 1363-2000
+  /// </summary>
+  TECNRSigner = class sealed(TInterfacedObject, IDsa, IECNRSigner)
+
+  strict private
+  var
+    FforSigning: Boolean;
+    Fkey: IECKeyParameters;
+    Frandom: ISecureRandom;
+
+    function GetAlgorithmName: String; virtual;
+
+  public
+
+    property AlgorithmName: String read GetAlgorithmName;
+
+    procedure Init(forSigning: Boolean;
+      const parameters: ICipherParameters); virtual;
+
+    /// <summary>
+    /// <para>
+    /// Section 7.2.5 ECSP-NR, pg 34
+    /// </para>
+    /// <para>
+    /// generate a signature for the given message using the key we were <br />
+    /// initialised with. Generally, the order of the curve should be at <br />
+    /// least as long as the hash of the message of interest, and with <br />
+    /// ECNR it *must* be at least as long.
+    /// </para>
+    /// </summary>
+    /// <param name="&amp;message">
+    /// the digest to be signed.
+    /// </param>
+    /// <exception cref="EDataLengthCryptoLibException">
+    /// if the digest is longer than the key allows
+    /// </exception>
+    function GenerateSignature(&message: TCryptoLibByteArray)
+      : TCryptoLibGenericArray<TBigInteger>; virtual;
+
+    /// <summary>
+    /// <para>
+    /// Section 7.2.6 ECVP-NR, pg 35
+    /// </para>
+    /// <para>
+    /// return true if the value r and s represent a signature for the <br />
+    /// message passed in. Generally, the order of the curve should be at
+    /// <br />least as long as the hash of the message of interest, and
+    /// with <br />ECNR, it *must* be at least as long. But just in case
+    /// the signer <br />applied mod(n) to the longer digest, this
+    /// implementation will <br />apply mod(n) during verification.
+    /// </para>
+    /// </summary>
+    /// <param name="&amp;message">
+    /// the digest to be verified.
+    /// </param>
+    /// <param name="r">
+    /// the r value of the signature.
+    /// </param>
+    /// <param name="s">
+    /// the s value of the signature.
+    /// </param>
+    /// <exception cref="EDataLengthCryptoLibException">
+    /// if the digest is longer than the key allows
+    /// </exception>
+    function VerifySignature(&message: TCryptoLibByteArray;
+      const r, s: TBigInteger): Boolean;
+
+  end;
+
+implementation
+
+{ TECNRSigner }
+
+function TECNRSigner.GenerateSignature(&message: TCryptoLibByteArray)
+  : TCryptoLibGenericArray<TBigInteger>;
+var
+  n, e, r, s, Vx, x, u: TBigInteger;
+  nBitLength, eBitLength: Int32;
+  privKey: IECPrivateKeyParameters;
+  tempPair: IAsymmetricCipherKeyPair;
+  keyGen: IECKeyPairGenerator;
+  V: IECPublicKeyParameters;
+begin
+  if (not FforSigning) then
+  begin
+    // not properly initialized... deal with it
+    raise EInvalidOperationCryptoLibException.CreateRes
+      (@SNotInitializedForSigning);
+  end;
+
+  n := (Fkey as IECPrivateKeyParameters).parameters.n;
+  nBitLength := n.BitLength;
+
+  e := TBigInteger.Create(1, &message);
+  eBitLength := e.BitLength;
+
+  privKey := Fkey as IECPrivateKeyParameters;
+
+  if (eBitLength > nBitLength) then
+  begin
+    raise EDataLengthCryptoLibException.CreateRes(@SInputTooLargeForECNRKey);
+  end;
+
+  repeat // generate r
+    // generate another, but very temporary, key pair using
+    // the same EC parameters
+    keyGen := TECKeyPairGenerator.Create();
+
+    keyGen.Init(TECKeyGenerationParameters.Create(privKey.parameters, Frandom)
+      as IECKeyGenerationParameters);
+
+    tempPair := keyGen.GenerateKeyPair();
+
+    // BigInteger Vx := tempPair.getPublic().getW().getAffineX();
+    V := tempPair.Public as IECPublicKeyParameters; // get temp's public key
+    Vx := V.Q.AffineXCoord.ToBigInteger(); // get the point's x coordinate
+
+    r := Vx.Add(e).&Mod(n);
+  until (not(r.SignValue = 0));
+
+  // generate s
+  x := privKey.D; // private key value
+  u := (tempPair.Private as IECPrivateKeyParameters).D;
+  // temp's private key value
+  s := u.Subtract(r.Multiply(x)).&Mod(n);
+
+  result := TCryptoLibGenericArray<TBigInteger>.Create(r, s);
+end;
+
+function TECNRSigner.GetAlgorithmName: String;
+begin
+  result := 'ECNR';
+end;
+
+procedure TECNRSigner.Init(forSigning: Boolean;
+  const parameters: ICipherParameters);
+var
+  rParam: IParametersWithRandom;
+  Lparameters: ICipherParameters;
+begin
+  FforSigning := forSigning;
+  Lparameters := parameters;
+  if (forSigning) then
+  begin
+
+    if (Supports(Lparameters, IParametersWithRandom, rParam)) then
+    begin
+      Frandom := rParam.random;
+      Lparameters := rParam.parameters;
+    end
+    else
+    begin
+      Frandom := TSecureRandom.Create();
+    end;
+
+    if (not(Supports(Lparameters, IECPrivateKeyParameters))) then
+    begin
+      raise EInvalidKeyCryptoLibException.CreateRes(@SECPrivateKeyNotFound);
+    end;
+
+    Fkey := Lparameters as IECPrivateKeyParameters;
+  end
+  else
+  begin
+    if (not(Supports(Lparameters, IECPublicKeyParameters))) then
+    begin
+      raise EInvalidKeyCryptoLibException.CreateRes(@SECPublicKeyNotFound);
+    end;
+
+    Fkey := Lparameters as IECPublicKeyParameters;
+  end;
+end;
+
+function TECNRSigner.VerifySignature(&message: TCryptoLibByteArray;
+  const r, s: TBigInteger): Boolean;
+var
+  pubKey: IECPublicKeyParameters;
+  n, e, x, t: TBigInteger;
+  nBitLength, eBitLength: Int32;
+  G, W, P: IECPoint;
+begin
+  if (FforSigning) then
+  begin
+    // not properly initialized... deal with it
+    raise EInvalidOperationCryptoLibException.CreateRes
+      (@SNotInitializedForVerifying);
+  end;
+
+  pubKey := Fkey as IECPublicKeyParameters;
+  n := pubKey.parameters.n;
+  nBitLength := n.BitLength;
+
+  e := TBigInteger.Create(1, &message);
+  eBitLength := e.BitLength;
+
+  if (eBitLength > nBitLength) then
+  begin
+    raise EDataLengthCryptoLibException.CreateRes(@SInputTooLargeForECNRKey);
+  end;
+
+  // r in the range [1,n-1]
+  if ((r.CompareTo(TBigInteger.One) < 0) or (r.CompareTo(n) >= 0)) then
+  begin
+    result := false;
+    Exit;
+  end;
+
+  // s in the range [0,n-1]           NB: ECNR spec says 0
+  if ((s.CompareTo(TBigInteger.Zero) < 0) or (s.CompareTo(n) >= 0)) then
+  begin
+    result := false;
+    Exit;
+  end;
+
+  // compute P = sG + rW
+
+  G := pubKey.parameters.G;
+  W := pubKey.Q;
+  // calculate P using ECAlgorithms Math
+  P := TECAlgorithms.SumOfTwoMultiplies(G, s, W, r).Normalize();
+
+  if (P.IsInfinity) then
+  begin
+    result := false;
+    Exit;
+  end;
+
+  x := P.AffineXCoord.ToBigInteger();
+  t := r.Subtract(x).&Mod(n);
+
+  result := t.Equals(e);
+end;
+
+end.

+ 40 - 0
CryptoLib/src/Interfaces/ClpIDsaKeyGenerationParameters.pas

@@ -0,0 +1,40 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaKeyGenerationParameters;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaParameters,
+  ClpIKeyGenerationParameters;
+
+type
+  IDsaKeyGenerationParameters = interface(IKeyGenerationParameters)
+    ['{0EBFC33A-31D3-4F20-8836-35250F53EA73}']
+
+    function GetParameters: IDsaParameters;
+
+    property parameters: IDsaParameters read GetParameters;
+
+  end;
+
+implementation
+
+end.

+ 38 - 0
CryptoLib/src/Interfaces/ClpIDsaKeyPairGenerator.pas

@@ -0,0 +1,38 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaKeyPairGenerator;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIAsymmetricCipherKeyPair,
+  ClpIKeyGenerationParameters,
+  ClpIAsymmetricCipherKeyPairGenerator;
+
+type
+  IDsaKeyPairGenerator = interface(IAsymmetricCipherKeyPairGenerator)
+    ['{37A4647D-2D9A-4EB1-A2AF-B3FBE72B66F3}']
+    procedure Init(const parameters: IKeyGenerationParameters);
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+  end;
+
+implementation
+
+end.

+ 43 - 0
CryptoLib/src/Interfaces/ClpIDsaKeyParameters.pas

@@ -0,0 +1,43 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaKeyParameters;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaParameters,
+  ClpIAsymmetricKeyParameter;
+
+type
+  IDsaKeyParameters = interface(IAsymmetricKeyParameter)
+    ['{1E3454DF-DC9F-4EA0-91DA-0768A77387C5}']
+
+    function GetParameters: IDsaParameters;
+
+    function Equals(const other: IDsaKeyParameters): Boolean;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+    property parameters: IDsaParameters read GetParameters;
+
+  end;
+
+implementation
+
+end.

+ 48 - 0
CryptoLib/src/Interfaces/ClpIDsaParameters.pas

@@ -0,0 +1,48 @@
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaParameters;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpICipherParameters,
+  ClpIDsaValidationParameters,
+  ClpBigInteger;
+
+type
+  IDsaParameters = interface(ICipherParameters)
+    ['{6A088962-AF58-4699-83B9-ADDABFC65A7E}']
+
+    function GetG: TBigInteger;
+    function GetP: TBigInteger;
+    function GetQ: TBigInteger;
+    function GetValidationParameters: IDsaValidationParameters;
+
+    function Equals(const other: IDsaParameters): Boolean;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+    property p: TBigInteger read GetP;
+    property q: TBigInteger read GetQ;
+    property g: TBigInteger read GetG;
+    property ValidationParameters: IDsaValidationParameters
+      read GetValidationParameters;
+
+  end;
+
+implementation
+
+end.

+ 40 - 0
CryptoLib/src/Interfaces/ClpIDsaPrivateKeyParameters.pas

@@ -0,0 +1,40 @@
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaPrivateKeyParameters;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaKeyParameters,
+  ClpBigInteger;
+
+type
+  IDsaPrivateKeyParameters = interface(IDsaKeyParameters)
+    ['{A956E21D-0A60-4073-8F17-5EA8B4615B68}']
+
+    function GetX: TBigInteger;
+
+    function Equals(const other: IDsaPrivateKeyParameters): Boolean;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+    property X: TBigInteger read GetX;
+
+  end;
+
+implementation
+
+end.

+ 40 - 0
CryptoLib/src/Interfaces/ClpIDsaPublicKeyParameters.pas

@@ -0,0 +1,40 @@
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaPublicKeyParameters;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsaKeyParameters,
+  ClpBigInteger;
+
+type
+  IDsaPublicKeyParameters = interface(IDsaKeyParameters)
+    ['{B3F14490-AF3D-437C-9E42-B6940B2ECADE}']
+
+    function GetY: TBigInteger;
+
+    function Equals(const other: IDsaPublicKeyParameters): Boolean;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+    property y: TBigInteger read GetY;
+
+  end;
+
+implementation
+
+end.

+ 70 - 0
CryptoLib/src/Interfaces/ClpIDsaSigner.pas

@@ -0,0 +1,70 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaSigner;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsa,
+  ClpISecureRandom,
+  ClpICipherParameters,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+type
+  IDsaSigner = interface(IDsa)
+    ['{687C14CD-F126-4886-87FC-535DEB083C2F}']
+
+    function GetAlgorithmName: String;
+
+    function CalculateE(const n: TBigInteger; &message: TCryptoLibByteArray)
+      : TBigInteger;
+
+    function InitSecureRandom(needed: Boolean; const provided: ISecureRandom)
+      : ISecureRandom;
+
+    procedure Init(forSigning: Boolean; const parameters: ICipherParameters);
+
+    /// <summary>
+    /// Generate a signature for the given message using the key we were <br />
+    /// initialised with. For conventional DSA the message should be a SHA-1 <br />
+    /// hash of the message of interest.
+    /// </summary>
+    /// <param name="&amp;message">
+    /// the message that will be verified later.
+    /// </param>
+    function GenerateSignature(&message: TCryptoLibByteArray)
+      : TCryptoLibGenericArray<TBigInteger>;
+
+    /// <summary>
+    /// return true if the value r and s represent a DSA signature for <br />
+    /// the passed in message for standard DSA the message should be a <br />
+    /// SHA-1 hash of the real message to be verified.
+    /// </summary>
+    function VerifySignature(&message: TCryptoLibByteArray;
+      const r, s: TBigInteger): Boolean;
+
+    property AlgorithmName: String read GetAlgorithmName;
+
+  end;
+
+implementation
+
+end.

+ 42 - 0
CryptoLib/src/Interfaces/ClpIDsaValidationParameters.pas

@@ -0,0 +1,42 @@
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaValidationParameters;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpCryptoLibTypes;
+
+type
+  IDsaValidationParameters = interface(IInterface)
+    ['{F7C394CB-BDC3-47B5-835F-6216FBBF90F9}']
+
+    function GetCounter: Int32;
+    function GetUsageIndex: Int32;
+    function GetSeed: TCryptoLibByteArray;
+
+    function Equals(const other: IDsaValidationParameters): Boolean;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+    property counter: Int32 read GetCounter;
+    property usageIndex: Int32 read GetUsageIndex;
+    property seed: TCryptoLibByteArray read GetSeed;
+  end;
+
+implementation
+
+end.

+ 50 - 0
CryptoLib/src/Interfaces/ClpIECNRSigner.pas

@@ -0,0 +1,50 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIECNRSigner;
+
+{$I ..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIDsa,
+  ClpICipherParameters,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+type
+  IECNRSigner = interface(IDsa)
+    ['{C136F005-404E-4022-886E-DE5EFCECFF9C}']
+
+    function GetAlgorithmName: String;
+
+    property AlgorithmName: String read GetAlgorithmName;
+
+    procedure Init(forSigning: Boolean; const parameters: ICipherParameters);
+
+    function GenerateSignature(&message: TCryptoLibByteArray)
+      : TCryptoLibGenericArray<TBigInteger>;
+
+    function VerifySignature(&message: TCryptoLibByteArray;
+      const r, s: TBigInteger): Boolean;
+
+  end;
+
+implementation
+
+end.

+ 78 - 2
CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.lpk

@@ -24,8 +24,8 @@
 
 
  Acknowledgements: 
  Acknowledgements: 
 Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the development of this library "/>
 Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the development of this library "/>
-    <Version Major="2" Minor="1"/>
-    <Files Count="369">
+    <Version Major="2" Minor="2"/>
+    <Files Count="388">
       <Item1>
       <Item1>
         <Filename Value="..\..\Asn1\ClpAsn1Encodable.pas"/>
         <Filename Value="..\..\Asn1\ClpAsn1Encodable.pas"/>
         <UnitName Value="ClpAsn1Encodable"/>
         <UnitName Value="ClpAsn1Encodable"/>
@@ -1503,6 +1503,82 @@ Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring the devel
         <Filename Value="..\..\Crypto\Signers\ClpECSchnorrBSISigner.pas"/>
         <Filename Value="..\..\Crypto\Signers\ClpECSchnorrBSISigner.pas"/>
         <UnitName Value="ClpECSchnorrBSISigner"/>
         <UnitName Value="ClpECSchnorrBSISigner"/>
       </Item369>
       </Item369>
+      <Item370>
+        <Filename Value="..\..\Crypto\Signers\ClpDsaSigner.pas"/>
+        <UnitName Value="ClpDsaSigner"/>
+      </Item370>
+      <Item371>
+        <Filename Value="..\..\Crypto\Generators\ClpDsaKeyPairGenerator.pas"/>
+        <UnitName Value="ClpDsaKeyPairGenerator"/>
+      </Item371>
+      <Item372>
+        <Filename Value="..\..\Crypto\Signers\ClpECNRSigner.pas"/>
+        <UnitName Value="ClpECNRSigner"/>
+      </Item372>
+      <Item373>
+        <Filename Value="..\..\Crypto\Parameters\ClpDsaKeyGenerationParameters.pas"/>
+        <UnitName Value="ClpDsaKeyGenerationParameters"/>
+      </Item373>
+      <Item374>
+        <Filename Value="..\..\Crypto\Parameters\ClpDsaPrivateKeyParameters.pas"/>
+        <UnitName Value="ClpDsaPrivateKeyParameters"/>
+      </Item374>
+      <Item375>
+        <Filename Value="..\..\Crypto\Parameters\ClpDsaPublicKeyParameters.pas"/>
+        <UnitName Value="ClpDsaPublicKeyParameters"/>
+      </Item375>
+      <Item376>
+        <Filename Value="..\..\Crypto\Parameters\ClpDsaValidationParameters.pas"/>
+        <UnitName Value="ClpDsaValidationParameters"/>
+      </Item376>
+      <Item377>
+        <Filename Value="..\..\Crypto\Parameters\ClpDsaParameters.pas"/>
+        <UnitName Value="ClpDsaParameters"/>
+      </Item377>
+      <Item378>
+        <Filename Value="..\..\Crypto\Parameters\ClpDsaKeyParameters.pas"/>
+        <UnitName Value="ClpDsaKeyParameters"/>
+      </Item378>
+      <Item379>
+        <Filename Value="..\..\Interfaces\ClpIECNRSigner.pas"/>
+        <UnitName Value="ClpIECNRSigner"/>
+      </Item379>
+      <Item380>
+        <Filename Value="..\..\Interfaces\ClpIDsaSigner.pas"/>
+        <UnitName Value="ClpIDsaSigner"/>
+      </Item380>
+      <Item381>
+        <Filename Value="..\..\Interfaces\ClpIDsaKeyPairGenerator.pas"/>
+        <UnitName Value="ClpIDsaKeyPairGenerator"/>
+      </Item381>
+      <Item382>
+        <Filename Value="..\..\Interfaces\ClpIDsaPrivateKeyParameters.pas"/>
+        <UnitName Value="ClpIDsaPrivateKeyParameters"/>
+      </Item382>
+      <Item383>
+        <Filename Value="..\..\Interfaces\ClpIDsaKeyGenerationParameters.pas"/>
+        <UnitName Value="ClpIDsaKeyGenerationParameters"/>
+      </Item383>
+      <Item384>
+        <Filename Value="..\..\Interfaces\ClpIDsaKeyParameters.pas"/>
+        <UnitName Value="ClpIDsaKeyParameters"/>
+      </Item384>
+      <Item385>
+        <Filename Value="..\..\Interfaces\ClpIDsaPublicKeyParameters.pas"/>
+        <UnitName Value="ClpIDsaPublicKeyParameters"/>
+      </Item385>
+      <Item386>
+        <Filename Value="..\..\Interfaces\ClpIDsaParameters.pas"/>
+        <UnitName Value="ClpIDsaParameters"/>
+      </Item386>
+      <Item387>
+        <Filename Value="..\..\Interfaces\ClpIDsaValidationParameters.pas"/>
+        <UnitName Value="ClpIDsaValidationParameters"/>
+      </Item387>
+      <Item388>
+        <Filename Value="..\..\Utils\Encoders\ClpBase58.pas"/>
+        <UnitName Value="ClpBase58"/>
+      </Item388>
     </Files>
     </Files>
     <RequiredPkgs Count="3">
     <RequiredPkgs Count="3">
       <Item1>
       <Item1>

+ 8 - 1
CryptoLib/src/Packages/FPC/CryptoLib4PascalPackage.pas

@@ -121,7 +121,14 @@ uses
   ClpIanaObjectIdentifiers, ClpMacUtilities, ClpIMac, ClpIHMac, 
   ClpIanaObjectIdentifiers, ClpMacUtilities, ClpIMac, ClpIHMac, 
   ClpIECSchnorrLIBSECPSigner, ClpIECSchnorrISOXSigner, ClpIECSchnorrISOSigner, 
   ClpIECSchnorrLIBSECPSigner, ClpIECSchnorrISOXSigner, ClpIECSchnorrISOSigner, 
   ClpIECSchnorrBSISigner, ClpISchnorr, ClpECSchnorrLIBSECPSigner, 
   ClpIECSchnorrBSISigner, ClpISchnorr, ClpECSchnorrLIBSECPSigner, 
-  ClpECSchnorrISOXSigner, ClpECSchnorrISOSigner, ClpECSchnorrBSISigner;
+  ClpECSchnorrISOXSigner, ClpECSchnorrISOSigner, ClpECSchnorrBSISigner, 
+  ClpDsaSigner, ClpDsaKeyPairGenerator, ClpECNRSigner, 
+  ClpDsaKeyGenerationParameters, ClpDsaPrivateKeyParameters, 
+  ClpDsaPublicKeyParameters, ClpDsaValidationParameters, ClpDsaParameters, 
+  ClpDsaKeyParameters, ClpIECNRSigner, ClpIDsaSigner, ClpIDsaKeyPairGenerator, 
+  ClpIDsaPrivateKeyParameters, ClpIDsaKeyGenerationParameters, 
+  ClpIDsaKeyParameters, ClpIDsaPublicKeyParameters, ClpIDsaParameters, 
+  ClpIDsaValidationParameters, ClpBase58;
 
 
 implementation
 implementation
 
 

+ 9 - 0
CryptoLib/src/Security/ClpGeneratorUtilities.pas

@@ -29,6 +29,8 @@ uses
   ClpCipherKeyGenerator,
   ClpCipherKeyGenerator,
   ClpICipherKeyGenerator,
   ClpICipherKeyGenerator,
   ClpIDerObjectIdentifier,
   ClpIDerObjectIdentifier,
+  ClpDsaKeyPairGenerator,
+  ClpIDsaKeyPairGenerator,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpNistObjectIdentifiers,
   ClpNistObjectIdentifiers,
   ClpIanaObjectIdentifiers,
   ClpIanaObjectIdentifiers,
@@ -235,6 +237,7 @@ begin
   // key pair generators.
   // key pair generators.
   //
   //
 
 
+  AddKpgAlgorithm('DSA', []);
   AddKpgAlgorithm('ECDH', ['ECIES']);
   AddKpgAlgorithm('ECDH', ['ECIES']);
   AddKpgAlgorithm('ECDSA', []);
   AddKpgAlgorithm('ECDSA', []);
 
 
@@ -355,6 +358,12 @@ begin
       (@SKeyPairGeneratorAlgorithmNotRecognised, [algorithm]);
       (@SKeyPairGeneratorAlgorithmNotRecognised, [algorithm]);
   end;
   end;
 
 
+  if (canonicalName = 'DSA') then
+  begin
+    result := TDsaKeyPairGenerator.Create() as IDsaKeyPairGenerator;
+    Exit;
+  end;
+
   // "EC", "ECDH", "ECDHC", "ECDSA", "ECGOST3410", "ECMQV"
   // "EC", "ECDH", "ECDHC", "ECDSA", "ECGOST3410", "ECMQV"
   if TStringUtils.BeginsWith(canonicalName, 'EC', True) then
   if TStringUtils.BeginsWith(canonicalName, 'EC', True) then
   begin
   begin

+ 170 - 14
CryptoLib/src/Security/ClpSignerUtilities.pas

@@ -24,7 +24,8 @@ interface
 uses
 uses
   SysUtils,
   SysUtils,
   Generics.Collections,
   Generics.Collections,
-  ClpCryptoLibTypes,
+  ClpECNRSigner,
+  ClpIECNRSigner,
   ClpIDigest,
   ClpIDigest,
   ClpDigestUtilities,
   ClpDigestUtilities,
   ClpDsaDigestSigner,
   ClpDsaDigestSigner,
@@ -39,11 +40,16 @@ uses
   ClpIECSchnorrLIBSECPSigner,
   ClpIECSchnorrLIBSECPSigner,
   ClpX9ObjectIdentifiers,
   ClpX9ObjectIdentifiers,
   ClpTeleTrusTObjectIdentifiers,
   ClpTeleTrusTObjectIdentifiers,
+  ClpOiwObjectIdentifiers,
+  ClpNistObjectIdentifiers,
   ClpCryptoProObjectIdentifiers,
   ClpCryptoProObjectIdentifiers,
+  ClpDsaSigner,
+  ClpIDsaSigner,
   ClpECDsaSigner,
   ClpECDsaSigner,
   ClpIECDsaSigner,
   ClpIECDsaSigner,
   ClpISigner,
   ClpISigner,
-  ClpIDerObjectIdentifier;
+  ClpIDerObjectIdentifier,
+  ClpCryptoLibTypes;
 
 
 resourcestring
 resourcestring
   SMechanismNil = 'Mechanism Cannot be Nil';
   SMechanismNil = 'Mechanism Cannot be Nil';
@@ -103,9 +109,58 @@ begin
   Foids := TDictionary<String, IDerObjectIdentifier>.Create();
   Foids := TDictionary<String, IDerObjectIdentifier>.Create();
 
 
   TX9ObjectIdentifiers.Boot;
   TX9ObjectIdentifiers.Boot;
+  TOiwObjectIdentifiers.Boot;
+  TNistObjectIdentifiers.Boot;
   TTeleTrusTObjectIdentifiers.Boot;
   TTeleTrusTObjectIdentifiers.Boot;
   TCryptoProObjectIdentifiers.Boot;
   TCryptoProObjectIdentifiers.Boot;
 
 
+  Falgorithms.Add('NONEWITHDSA', 'NONEwithDSA');
+  Falgorithms.Add('DSAWITHNONE', 'NONEwithDSA');
+  Falgorithms.Add('RAWDSA', 'NONEwithDSA');
+
+  Falgorithms.Add('DSA', 'SHA-1withDSA');
+  Falgorithms.Add('DSAWITHSHA1', 'SHA-1withDSA');
+  Falgorithms.Add('DSAWITHSHA-1', 'SHA-1withDSA');
+  Falgorithms.Add('SHA/DSA', 'SHA-1withDSA');
+  Falgorithms.Add('SHA1/DSA', 'SHA-1withDSA');
+  Falgorithms.Add('SHA-1/DSA', 'SHA-1withDSA');
+  Falgorithms.Add('SHA1WITHDSA', 'SHA-1withDSA');
+  Falgorithms.Add('SHA-1WITHDSA', 'SHA-1withDSA');
+  Falgorithms.Add(TX9ObjectIdentifiers.IdDsaWithSha1.id, 'SHA-1withDSA');
+  Falgorithms.Add(TOiwObjectIdentifiers.DsaWithSha1.id, 'SHA-1withDSA');
+
+  Falgorithms.Add('DSAWITHSHA224', 'SHA-224withDSA');
+  Falgorithms.Add('DSAWITHSHA-224', 'SHA-224withDSA');
+  Falgorithms.Add('SHA224/DSA', 'SHA-224withDSA');
+  Falgorithms.Add('SHA-224/DSA', 'SHA-224withDSA');
+  Falgorithms.Add('SHA224WITHDSA', 'SHA-224withDSA');
+  Falgorithms.Add('SHA-224WITHDSA', 'SHA-224withDSA');
+  Falgorithms.Add(TNistObjectIdentifiers.DsaWithSha224.id, 'SHA-224withDSA');
+
+  Falgorithms.Add('DSAWITHSHA256', 'SHA-256withDSA');
+  Falgorithms.Add('DSAWITHSHA-256', 'SHA-256withDSA');
+  Falgorithms.Add('SHA256/DSA', 'SHA-256withDSA');
+  Falgorithms.Add('SHA-256/DSA', 'SHA-256withDSA');
+  Falgorithms.Add('SHA256WITHDSA', 'SHA-256withDSA');
+  Falgorithms.Add('SHA-256WITHDSA', 'SHA-256withDSA');
+  Falgorithms.Add(TNistObjectIdentifiers.DsaWithSha256.id, 'SHA-256withDSA');
+
+  Falgorithms.Add('DSAWITHSHA384', 'SHA-384withDSA');
+  Falgorithms.Add('DSAWITHSHA-384', 'SHA-384withDSA');
+  Falgorithms.Add('SHA384/DSA', 'SHA-384withDSA');
+  Falgorithms.Add('SHA-384/DSA', 'SHA-384withDSA');
+  Falgorithms.Add('SHA384WITHDSA', 'SHA-384withDSA');
+  Falgorithms.Add('SHA-384WITHDSA', 'SHA-384withDSA');
+  Falgorithms.Add(TNistObjectIdentifiers.DsaWithSha384.id, 'SHA-384withDSA');
+
+  Falgorithms.Add('DSAWITHSHA512', 'SHA-512withDSA');
+  Falgorithms.Add('DSAWITHSHA-512', 'SHA-512withDSA');
+  Falgorithms.Add('SHA512/DSA', 'SHA-512withDSA');
+  Falgorithms.Add('SHA-512/DSA', 'SHA-512withDSA');
+  Falgorithms.Add('SHA512WITHDSA', 'SHA-512withDSA');
+  Falgorithms.Add('SHA-512WITHDSA', 'SHA-512withDSA');
+  Falgorithms.Add(TNistObjectIdentifiers.DsaWithSha512.id, 'SHA-512withDSA');
+
   Falgorithms.Add('NONEWITHECDSA', 'NONEwithECDSA');
   Falgorithms.Add('NONEWITHECDSA', 'NONEwithECDSA');
   Falgorithms.Add('ECDSAWITHNONE', 'NONEwithECDSA');
   Falgorithms.Add('ECDSAWITHNONE', 'NONEwithECDSA');
 
 
@@ -170,18 +225,6 @@ begin
   // Falgorithms.Add(TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001.id,
   // Falgorithms.Add(TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001.id,
   // 'ECGOST3410');
   // 'ECGOST3410');
 
 
-  Foids.Add('SHA-1withECDSA', TX9ObjectIdentifiers.ECDsaWithSha1);
-  Foids.Add('SHA-224withECDSA', TX9ObjectIdentifiers.ECDsaWithSha224);
-  Foids.Add('SHA-256withECDSA', TX9ObjectIdentifiers.ECDsaWithSha256);
-  Foids.Add('SHA-384withECDSA', TX9ObjectIdentifiers.ECDsaWithSha384);
-  Foids.Add('SHA-512withECDSA', TX9ObjectIdentifiers.ECDsaWithSha512);
-
-  // Foids.Add('GOST3410',
-  // TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
-  //
-  // Foids.Add('ECGOST3410',
-  // TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
-
   // ECSCHNORR BSI
   // ECSCHNORR BSI
 
 
   Falgorithms.Add('SHA1/ECSCHNORR/BSI', 'SHA-1withECSCHNORRBSI');
   Falgorithms.Add('SHA1/ECSCHNORR/BSI', 'SHA-1withECSCHNORRBSI');
@@ -350,6 +393,20 @@ begin
   Falgorithms.Add('RIPEMD160WITHECSCHNORRLIBSECP',
   Falgorithms.Add('RIPEMD160WITHECSCHNORRLIBSECP',
     'RIPEMD160withECSCHNORRLIBSECP');
     'RIPEMD160withECSCHNORRLIBSECP');
 
 
+  Foids.Add('SHA-1withDSA', TX9ObjectIdentifiers.IdDsaWithSha1);
+
+  Foids.Add('SHA-1withECDSA', TX9ObjectIdentifiers.ECDsaWithSha1);
+  Foids.Add('SHA-224withECDSA', TX9ObjectIdentifiers.ECDsaWithSha224);
+  Foids.Add('SHA-256withECDSA', TX9ObjectIdentifiers.ECDsaWithSha256);
+  Foids.Add('SHA-384withECDSA', TX9ObjectIdentifiers.ECDsaWithSha384);
+  Foids.Add('SHA-512withECDSA', TX9ObjectIdentifiers.ECDsaWithSha512);
+
+  // Foids.Add('GOST3410',
+  // TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x94);
+  //
+  // Foids.Add('ECGOST3410',
+  // TCryptoProObjectIdentifiers.GostR3411x94WithGostR3410x2001);
+
 end;
 end;
 
 
 class destructor TSignerUtilities.DestroySignerUtilities;
 class destructor TSignerUtilities.DestroySignerUtilities;
@@ -411,6 +468,60 @@ begin
     mechanism := algorithm;
     mechanism := algorithm;
   end;
   end;
 
 
+  if (mechanism = 'NONEwithDSA') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('NULL');
+
+    Result := (TDsaDigestSigner.Create(TDsaSigner.Create() as IDsaSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA-1withDSA') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-1');
+
+    Result := (TDsaDigestSigner.Create(TDsaSigner.Create() as IDsaSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA-224withDSA') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-224');
+
+    Result := (TDsaDigestSigner.Create(TDsaSigner.Create() as IDsaSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA-256withDSA') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-256');
+
+    Result := (TDsaDigestSigner.Create(TDsaSigner.Create() as IDsaSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA-384withDSA') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-384');
+
+    Result := (TDsaDigestSigner.Create(TDsaSigner.Create() as IDsaSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA-512withDSA') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-512');
+
+    Result := (TDsaDigestSigner.Create(TDsaSigner.Create() as IDsaSigner,
+      DigestInstance));
+    Exit;
+  end;
+
   if (mechanism = 'NONEwithECDSA') then
   if (mechanism = 'NONEwithECDSA') then
   begin
   begin
     DigestInstance := TDigestUtilities.GetDigest('NULL');
     DigestInstance := TDigestUtilities.GetDigest('NULL');
@@ -469,6 +580,51 @@ begin
     Exit;
     Exit;
   end;
   end;
 
 
+  if (mechanism = 'SHA1WITHECNR') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-1');
+
+    Result := (TDsaDigestSigner.Create(TECNRSigner.Create() as IECNRSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA224WITHECNR') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-224');
+
+    Result := (TDsaDigestSigner.Create(TECNRSigner.Create() as IECNRSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA256WITHECNR') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-256');
+
+    Result := (TDsaDigestSigner.Create(TECNRSigner.Create() as IECNRSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA384WITHECNR') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-384');
+
+    Result := (TDsaDigestSigner.Create(TECNRSigner.Create() as IECNRSigner,
+      DigestInstance));
+    Exit;
+  end;
+
+  if (mechanism = 'SHA512WITHECNR') then
+  begin
+    DigestInstance := TDigestUtilities.GetDigest('SHA-512');
+
+    Result := (TDsaDigestSigner.Create(TECNRSigner.Create() as IECNRSigner,
+      DigestInstance));
+    Exit;
+  end;
+
   if (mechanism = 'SHA-1withECSCHNORRBSI') then
   if (mechanism = 'SHA-1withECSCHNORRBSI') then
   begin
   begin
     DigestInstance := TDigestUtilities.GetDigest('SHA-1');
     DigestInstance := TDigestUtilities.GetDigest('SHA-1');

+ 53 - 0
CryptoLib/src/Utils/Encoders/ClpBase58.pas

@@ -0,0 +1,53 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpBase58;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SbpBase58,
+{$IFDEF DELPHI}
+  SbpIBase58,
+{$ENDIF DELPHI}
+  ClpCryptoLibTypes;
+
+type
+  TBase58 = class sealed(TObject)
+
+  public
+    class function Encode(Input: TCryptoLibByteArray): String; static;
+    class function Decode(const Input: String): TCryptoLibByteArray; static;
+  end;
+
+implementation
+
+{ TBase58 }
+
+class function TBase58.Decode(const Input: String): TCryptoLibByteArray;
+begin
+  result := SbpBase58.TBase58.BitCoin.Decode(Input);
+end;
+
+class function TBase58.Encode(Input: TCryptoLibByteArray): String;
+begin
+  result := SbpBase58.TBase58.BitCoin.Encode(Input);
+end;
+
+end.

+ 11 - 4
CryptoLib/src/Utils/Encoders/ClpHex.pas

@@ -30,7 +30,8 @@ type
 
 
   public
   public
     class function Decode(const Hex: String): TCryptoLibByteArray; static;
     class function Decode(const Hex: String): TCryptoLibByteArray; static;
-    class function Encode(Input: TCryptoLibByteArray): String; static;
+    class function Encode(Input: TCryptoLibByteArray; UpperCase: Boolean = True)
+      : String; static;
   end;
   end;
 
 
 implementation
 implementation
@@ -39,12 +40,18 @@ implementation
 
 
 class function THex.Decode(const Hex: String): TCryptoLibByteArray;
 class function THex.Decode(const Hex: String): TCryptoLibByteArray;
 begin
 begin
-  result := TBase16.Decode(Hex);
+  result := SbpBase16.TBase16.Decode(Hex);
 end;
 end;
 
 
-class function THex.Encode(Input: TCryptoLibByteArray): String;
+class function THex.Encode(Input: TCryptoLibByteArray;
+  UpperCase: Boolean): String;
 begin
 begin
-  result := TBase16.EncodeUpper(Input);
+  case UpperCase of
+    True:
+      result := SbpBase16.TBase16.EncodeUpper(Input);
+    False:
+      result := SbpBase16.TBase16.EncodeLower(Input);
+  end;
 end;
 end;
 
 
 end.
 end.