2
0
Ugochukwu Mmaduekwe 1 долоо хоног өмнө
parent
commit
5c093585c0
100 өөрчлөгдсөн 3775 нэмэгдсэн , 5585 устгасан
  1. 20 79
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr
  2. 4 5
      CryptoLib.Tests/src/Asn1/X509/DeltaCertificateTests.pas
  3. 2 10
      CryptoLib.Tests/src/Crypto/DHTests.pas
  4. 4 21
      CryptoLib.Tests/src/Crypto/DSATests.pas
  5. 2 6
      CryptoLib.Tests/src/Crypto/DeterministicDsaTests.pas
  6. 2 2
      CryptoLib.Tests/src/Crypto/ISO9796Tests.pas
  7. 4 8
      CryptoLib.Tests/src/Crypto/PssTests.pas
  8. 4 8
      CryptoLib.Tests/src/Crypto/RSABlindedTests.pas
  9. 2 4
      CryptoLib.Tests/src/Crypto/RSADigestSignerTests.pas
  10. 4 8
      CryptoLib.Tests/src/Crypto/RSATests.pas
  11. 2 4
      CryptoLib.Tests/src/Crypto/X931SignerTests.pas
  12. 5 12
      CryptoLib.Tests/src/Math/ECIESTests.pas
  13. 4 10
      CryptoLib.Tests/src/Math/ECNRTests.pas
  14. 4 9
      CryptoLib.Tests/src/Math/IESCipherTests.pas
  15. 6 11
      CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas
  16. 8 16
      CryptoLib.Tests/src/Others/CertTests.pas
  17. 3 8
      CryptoLib.Tests/src/Others/ECDsa5Tests.pas
  18. 4 10
      CryptoLib.Tests/src/Others/ECTests.pas
  19. 4 8
      CryptoLib.Tests/src/Others/Ed25519HigherLevelTests.pas
  20. 3 5
      CryptoLib.Tests/src/Others/NamedCurveTests.pas
  21. 6 16
      CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas
  22. 4 4
      CryptoLib.Tests/src/Others/X25519HigherLevelTests.pas
  23. 3 11
      CryptoLib.Tests/src/X509/X509CertGenTests.pas
  24. 2 2
      CryptoLib/src/Asn1/CryptoPro/ClpECGost3410NamedCurves.pas
  25. 8 11
      CryptoLib/src/Crypto/Agreements/ClpDHAgreement.pas
  26. 4 6
      CryptoLib/src/Crypto/Agreements/ClpDHBasicAgreement.pas
  27. 1 3
      CryptoLib/src/Crypto/Agreements/ClpECDHBasicAgreement.pas
  28. 1 3
      CryptoLib/src/Crypto/Agreements/ClpECDHCBasicAgreement.pas
  29. 2 3
      CryptoLib/src/Crypto/Agreements/ClpX25519Agreement.pas
  30. 1 2
      CryptoLib/src/Crypto/Ciphers/ClpBufferedIesCipher.pas
  31. 1 1
      CryptoLib/src/Crypto/ClpKeyEncoder.pas
  32. 1 1
      CryptoLib/src/Crypto/Encodings/ClpISO9796d1Encoding.pas
  33. 1 2
      CryptoLib/src/Crypto/Engines/ClpIesEngine.pas
  34. 1 2
      CryptoLib/src/Crypto/Engines/ClpRsaBlindedEngine.pas
  35. 1 2
      CryptoLib/src/Crypto/Engines/ClpRsaBlindingEngine.pas
  36. 1 2
      CryptoLib/src/Crypto/Engines/ClpRsaCoreEngine.pas
  37. 53 76
      CryptoLib/src/Crypto/Generators/ClpArgon2ParametersGenerator.pas
  38. 61 61
      CryptoLib/src/Crypto/Generators/ClpBaseKdfBytesGenerator.pas
  39. 32 37
      CryptoLib/src/Crypto/Generators/ClpCipherKeyGenerator.pas
  40. 0 104
      CryptoLib/src/Crypto/Generators/ClpDHBasicKeyPairGenerator.pas
  41. 134 0
      CryptoLib/src/Crypto/Generators/ClpDHGenerators.pas
  42. 31 69
      CryptoLib/src/Crypto/Generators/ClpDHKeyGeneratorHelper.pas
  43. 0 104
      CryptoLib/src/Crypto/Generators/ClpDHKeyPairGenerator.pas
  44. 0 88
      CryptoLib/src/Crypto/Generators/ClpDHParametersGenerator.pas
  45. 71 108
      CryptoLib/src/Crypto/Generators/ClpDHParametersHelper.pas
  46. 678 0
      CryptoLib/src/Crypto/Generators/ClpDsaGenerators.pas
  47. 0 142
      CryptoLib/src/Crypto/Generators/ClpDsaKeyPairGenerator.pas
  48. 0 619
      CryptoLib/src/Crypto/Generators/ClpDsaParametersGenerator.pas
  49. 161 0
      CryptoLib/src/Crypto/Generators/ClpECGenerators.pas
  50. 0 221
      CryptoLib/src/Crypto/Generators/ClpECKeyPairGenerator.pas
  51. 6 15
      CryptoLib/src/Crypto/Generators/ClpEd25519Generators.pas
  52. 12 13
      CryptoLib/src/Crypto/Generators/ClpEphemeralKeyPairGenerator.pas
  53. 12 12
      CryptoLib/src/Crypto/Generators/ClpGeneratorUtilities.pas
  54. 61 72
      CryptoLib/src/Crypto/Generators/ClpHkdfBytesGenerator.pas
  55. 3 3
      CryptoLib/src/Crypto/Generators/ClpKdf1BytesGenerator.pas
  56. 3 3
      CryptoLib/src/Crypto/Generators/ClpKdf2BytesGenerator.pas
  57. 26 37
      CryptoLib/src/Crypto/Generators/ClpPascalCoinECIESKdfBytesGenerator.pas
  58. 10 10
      CryptoLib/src/Crypto/Generators/ClpPbeParametersGenerator.pas
  59. 46 51
      CryptoLib/src/Crypto/Generators/ClpPkcs5S2ParametersGenerator.pas
  60. 0 111
      CryptoLib/src/Crypto/Generators/ClpRsaBlindingFactorGenerator.pas
  61. 237 0
      CryptoLib/src/Crypto/Generators/ClpRsaGenerators.pas
  62. 0 243
      CryptoLib/src/Crypto/Generators/ClpRsaKeyPairGenerator.pas
  63. 41 46
      CryptoLib/src/Crypto/Generators/ClpScryptParametersGenerator.pas
  64. 12 21
      CryptoLib/src/Crypto/Generators/ClpX25519Generators.pas
  65. 13 13
      CryptoLib/src/Crypto/Parameters/ClpAsymmetricKeyParameter.pas
  66. 0 78
      CryptoLib/src/Crypto/Parameters/ClpDHKeyGenerationParameters.pas
  67. 0 115
      CryptoLib/src/Crypto/Parameters/ClpDHKeyParameters.pas
  68. 442 76
      CryptoLib/src/Crypto/Parameters/ClpDHParameters.pas
  69. 0 117
      CryptoLib/src/Crypto/Parameters/ClpDHPrivateKeyParameters.pas
  70. 0 135
      CryptoLib/src/Crypto/Parameters/ClpDHPublicKeyParameters.pas
  71. 0 103
      CryptoLib/src/Crypto/Parameters/ClpDHValidationParameters.pas
  72. 0 66
      CryptoLib/src/Crypto/Parameters/ClpDsaKeyGenerationParameters.pas
  73. 0 94
      CryptoLib/src/Crypto/Parameters/ClpDsaKeyParameters.pas
  74. 0 146
      CryptoLib/src/Crypto/Parameters/ClpDsaParameterGenerationParameters.pas
  75. 442 62
      CryptoLib/src/Crypto/Parameters/ClpDsaParameters.pas
  76. 0 105
      CryptoLib/src/Crypto/Parameters/ClpDsaPrivateKeyParameters.pas
  77. 0 118
      CryptoLib/src/Crypto/Parameters/ClpDsaPublicKeyParameters.pas
  78. 0 121
      CryptoLib/src/Crypto/Parameters/ClpDsaValidationParameters.pas
  79. 0 306
      CryptoLib/src/Crypto/Parameters/ClpECDomainParameters.pas
  80. 0 63
      CryptoLib/src/Crypto/Parameters/ClpECKeyGenerationParameters.pas
  81. 0 155
      CryptoLib/src/Crypto/Parameters/ClpECKeyParameters.pas
  82. 0 123
      CryptoLib/src/Crypto/Parameters/ClpECNamedDomainParameters.pas
  83. 678 0
      CryptoLib/src/Crypto/Parameters/ClpECParameters.pas
  84. 0 108
      CryptoLib/src/Crypto/Parameters/ClpECPrivateKeyParameters.pas
  85. 0 111
      CryptoLib/src/Crypto/Parameters/ClpECPublicKeyParameters.pas
  86. 0 47
      CryptoLib/src/Crypto/Parameters/ClpEd25519KeyGenerationParameters.pas
  87. 179 17
      CryptoLib/src/Crypto/Parameters/ClpEd25519Parameters.pas
  88. 0 204
      CryptoLib/src/Crypto/Parameters/ClpEd25519PublicKeyParameters.pas
  89. 29 29
      CryptoLib/src/Crypto/Parameters/ClpHkdfParameters.pas
  90. 0 80
      CryptoLib/src/Crypto/Parameters/ClpIesCipherParameters.pas
  91. 94 22
      CryptoLib/src/Crypto/Parameters/ClpIesParameters.pas
  92. 0 86
      CryptoLib/src/Crypto/Parameters/ClpIesWithCipherParameters.pas
  93. 6 6
      CryptoLib/src/Crypto/Parameters/ClpIso18033KdfParameters.pas
  94. 8 8
      CryptoLib/src/Crypto/Parameters/ClpKdfParameters.pas
  95. 10 10
      CryptoLib/src/Crypto/Parameters/ClpKeyGenerationParameters.pas
  96. 18 18
      CryptoLib/src/Crypto/Parameters/ClpKeyParameter.pas
  97. 20 20
      CryptoLib/src/Crypto/Parameters/ClpParametersWithIV.pas
  98. 17 17
      CryptoLib/src/Crypto/Parameters/ClpParametersWithRandom.pas
  99. 0 86
      CryptoLib/src/Crypto/Parameters/ClpRsaBlindingParameters.pas
  100. 0 139
      CryptoLib/src/Crypto/Parameters/ClpRsaKeyGenerationParameters.pas

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

@@ -83,32 +83,18 @@ uses
   ClpDefaultVerifierResult in '..\..\CryptoLib\src\Crypto\Operators\ClpDefaultVerifierResult.pas',
   ClpDHAgreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpDHAgreement.pas',
   ClpDHBasicAgreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpDHBasicAgreement.pas',
-  ClpDHBasicKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDHBasicKeyPairGenerator.pas',
-  ClpDHKeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDHKeyGenerationParameters.pas',
+  ClpDHGenerators in '..\..\CryptoLib\src\Crypto\Generators\ClpDHGenerators.pas',
   ClpDHKeyGeneratorHelper in '..\..\CryptoLib\src\Crypto\Generators\ClpDHKeyGeneratorHelper.pas',
-  ClpDHKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDHKeyPairGenerator.pas',
-  ClpDHKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDHKeyParameters.pas',
   ClpDHParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDHParameters.pas',
-  ClpDHParametersGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDHParametersGenerator.pas',
   ClpDHParametersHelper in '..\..\CryptoLib\src\Crypto\Generators\ClpDHParametersHelper.pas',
-  ClpDHPrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDHPrivateKeyParameters.pas',
-  ClpDHPublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDHPublicKeyParameters.pas',
-  ClpDHValidationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDHValidationParameters.pas',
   ClpDigest in '..\..\CryptoLib\src\Crypto\Digests\ClpDigest.pas',
   ClpDigestRandomGenerator in '..\..\CryptoLib\src\Rngs\ClpDigestRandomGenerator.pas',
   ClpDigestSink in '..\..\CryptoLib\src\Crypto\IO\ClpDigestSink.pas',
   ClpDigestUtilities in '..\..\CryptoLib\src\Crypto\Digests\ClpDigestUtilities.pas',
   ClpDsaDigestSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpDsaDigestSigner.pas',
-  ClpDsaKeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaKeyGenerationParameters.pas',
-  ClpDsaKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDsaKeyPairGenerator.pas',
-  ClpDsaKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaKeyParameters.pas',
-  ClpDsaParameterGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaParameterGenerationParameters.pas',
+  ClpDsaGenerators in '..\..\CryptoLib\src\Crypto\Generators\ClpDsaGenerators.pas',
   ClpDsaParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaParameters.pas',
-  ClpDsaParametersGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpDsaParametersGenerator.pas',
-  ClpDsaPrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaPrivateKeyParameters.pas',
-  ClpDsaPublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaPublicKeyParameters.pas',
   ClpDsaSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpDsaSigner.pas',
-  ClpDsaValidationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpDsaValidationParameters.pas',
   ClpEacObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Eac\ClpEacObjectIdentifiers.pas',
   ClpECAlgorithms in '..\..\CryptoLib\src\Math\EC\ClpECAlgorithms.pas',
   ClpECC in '..\..\CryptoLib\src\Math\EC\ClpECC.pas',
@@ -116,25 +102,18 @@ uses
   ClpECCurveConstants in '..\..\CryptoLib\src\Math\EC\ClpECCurveConstants.pas',
   ClpECDHBasicAgreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpECDHBasicAgreement.pas',
   ClpECDHCBasicAgreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpECDHCBasicAgreement.pas',
-  ClpECDomainParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECDomainParameters.pas',
-  ClpECNamedDomainParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECNamedDomainParameters.pas',
+  ClpECParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECParameters.pas',
   ClpECDsaSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECDsaSigner.pas',
   ClpECGost3410NamedCurves in '..\..\CryptoLib\src\Asn1\CryptoPro\ClpECGost3410NamedCurves.pas',
   ClpECIESPublicKeyParser in '..\..\CryptoLib\src\Crypto\Parsers\ClpECIESPublicKeyParser.pas',
-  ClpECKeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECKeyGenerationParameters.pas',
-  ClpECKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpECKeyPairGenerator.pas',
-  ClpECKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECKeyParameters.pas',
+  ClpECGenerators in '..\..\CryptoLib\src\Crypto\Generators\ClpECGenerators.pas',
   ClpECNamedCurveTable in '..\..\CryptoLib\src\Asn1\X9\ClpECNamedCurveTable.pas',
   ClpECNRSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECNRSigner.pas',
-  ClpECPrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECPrivateKeyParameters.pas',
-  ClpECPublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECPublicKeyParameters.pas',
   ClpEd25519 in '..\..\CryptoLib\src\Math\EC\Rfc8032\ClpEd25519.pas',
   ClpEd25519CtxSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpEd25519CtxSigner.pas',
-  ClpEd25519KeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpEd25519KeyGenerationParameters.pas',
-  ClpEd25519KeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpEd25519KeyPairGenerator.pas',
+  ClpEd25519Parameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpEd25519Parameters.pas',
+  ClpEd25519Generators in '..\..\CryptoLib\src\Crypto\Generators\ClpEd25519Generators.pas',
   ClpEd25519PhSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpEd25519PhSigner.pas',
-  ClpEd25519PrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpEd25519PrivateKeyParameters.pas',
-  ClpEd25519PublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpEd25519PublicKeyParameters.pas',
   ClpEd25519Signer in '..\..\CryptoLib\src\Crypto\Signers\ClpEd25519Signer.pas',
   ClpEdECObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Edec\ClpEdECObjectIdentifiers.pas',
   ClpEncoders in '..\..\CryptoLib\src\Encoders\ClpEncoders.pas',
@@ -189,59 +168,35 @@ uses
   ClpIDerivationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDerivationParameters.pas',
   ClpIDHAgreement in '..\..\CryptoLib\src\Interfaces\Crypto\Agreements\ClpIDHAgreement.pas',
   ClpIDHBasicAgreement in '..\..\CryptoLib\src\Interfaces\Crypto\Agreements\ClpIDHBasicAgreement.pas',
-  ClpIDHBasicKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDHBasicKeyPairGenerator.pas',
-  ClpIDHKeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDHKeyGenerationParameters.pas',
-  ClpIDHKeyGeneratorHelper in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDHKeyGeneratorHelper.pas',
-  ClpIDHKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDHKeyPairGenerator.pas',
-  ClpIDHKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDHKeyParameters.pas',
+  ClpIDHGenerators in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDHGenerators.pas',
   ClpIDHParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDHParameters.pas',
-  ClpIDHParametersGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDHParametersGenerator.pas',
-  ClpIDHPrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDHPrivateKeyParameters.pas',
-  ClpIDHPublicKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDHPublicKeyParameters.pas',
-  ClpIDHValidationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDHValidationParameters.pas',
   ClpIDigest in '..\..\CryptoLib\src\Interfaces\Crypto\Digests\ClpIDigest.pas',
   ClpIDigestFactory in '..\..\CryptoLib\src\Interfaces\Crypto\Operators\ClpIDigestFactory.pas',
   ClpIDigestRandomGenerator in '..\..\CryptoLib\src\Interfaces\Rngs\ClpIDigestRandomGenerator.pas',
   ClpIDsa in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIDsa.pas',
   ClpIDsaDigestSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIDsaDigestSigner.pas',
   ClpIDsaKCalculator in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIDsaKCalculator.pas',
-  ClpIDsaKeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaKeyGenerationParameters.pas',
-  ClpIDsaKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDsaKeyPairGenerator.pas',
-  ClpIDsaKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaKeyParameters.pas',
-  ClpIDsaParameterGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaParameterGenerationParameters.pas',
+  ClpIDsaGenerators in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDsaGenerators.pas',
   ClpIDsaParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaParameters.pas',
-  ClpIDsaParametersGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIDsaParametersGenerator.pas',
-  ClpIDsaPrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaPrivateKeyParameters.pas',
-  ClpIDsaPublicKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaPublicKeyParameters.pas',
   ClpIDsaSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIDsaSigner.pas',
-  ClpIDsaValidationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIDsaValidationParameters.pas',
   ClpIECC in '..\..\CryptoLib\src\Interfaces\Math\EC\ClpIECC.pas',
   ClpIECDHBasicAgreement in '..\..\CryptoLib\src\Interfaces\Crypto\Agreements\ClpIECDHBasicAgreement.pas',
   ClpIECDHCBasicAgreement in '..\..\CryptoLib\src\Interfaces\Crypto\Agreements\ClpIECDHCBasicAgreement.pas',
-  ClpIECDomainParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECDomainParameters.pas',
-  ClpIECNamedDomainParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECNamedDomainParameters.pas',
+  ClpIECParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECParameters.pas',
   ClpIECDsaSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIECDsaSigner.pas',
   ClpIECIESPublicKeyParser in '..\..\CryptoLib\src\Interfaces\Crypto\Parsers\ClpIECIESPublicKeyParser.pas',
-  ClpIECKeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECKeyGenerationParameters.pas',
-  ClpIECKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIECKeyPairGenerator.pas',
-  ClpIECKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECKeyParameters.pas',
+  ClpIECGenerators in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIECGenerators.pas',
   ClpIECNRSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIECNRSigner.pas',
-  ClpIECPrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECPrivateKeyParameters.pas',
-  ClpIECPublicKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECPublicKeyParameters.pas',
   ClpIEd25519CtxSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIEd25519CtxSigner.pas',
-  ClpIEd25519KeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIEd25519KeyGenerationParameters.pas',
-  ClpIEd25519KeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIEd25519KeyPairGenerator.pas',
+  ClpIEd25519Parameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIEd25519Parameters.pas',
+  ClpIEd25519Generators in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIEd25519Generators.pas',
   ClpIEd25519PhSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIEd25519PhSigner.pas',
-  ClpIEd25519PrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIEd25519PrivateKeyParameters.pas',
-  ClpIEd25519PublicKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIEd25519PublicKeyParameters.pas',
   ClpIEd25519Signer in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIEd25519Signer.pas',
   ClpIEndoPreCompInfo in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIEndoPreCompInfo.pas',
   ClpIEphemeralKeyPair in '..\..\CryptoLib\src\Interfaces\Crypto\ClpIEphemeralKeyPair.pas',
   ClpIEphemeralKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIEphemeralKeyPairGenerator.pas',
   ClpIesEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpIesEngine.pas',
   ClpIesParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpIesParameters.pas',
-  ClpIesCipherParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpIesCipherParameters.pas',
-  ClpIesWithCipherParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpIesWithCipherParameters.pas',
   ClpIetfUtilities in '..\..\CryptoLib\src\Asn1\X500\Style\ClpIetfUtilities.pas',
   ClpIExtensionField in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIExtensionField.pas',
   ClpIFiniteField in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIFiniteField.pas',
@@ -260,8 +215,6 @@ uses
   ClpIHMacDsaKCalculator in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerCalculators\ClpIHMacDsaKCalculator.pas',
   ClpIIesEngine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpIIesEngine.pas',
   ClpIIesParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIIesParameters.pas',
-  ClpIIesCipherParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIIesCipherParameters.pas',
-  ClpIIesWithCipherParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIIesWithCipherParameters.pas',
   ClpIIso18033KdfParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIIso18033KdfParameters.pas',
   ClpIISO9796d1Encoding in '..\..\CryptoLib\src\Interfaces\Crypto\Encodings\ClpIISO9796d1Encoding.pas',
   ClpIKdf1BytesGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIKdf1BytesGenerator.pas',
@@ -309,15 +262,11 @@ uses
   ClpIRsa in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIRsa.pas',
   ClpIRsaBlindedEngine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpIRsaBlindedEngine.pas',
   ClpIRsaBlindingEngine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpIRsaBlindingEngine.pas',
-  ClpIRsaBlindingFactorGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIRsaBlindingFactorGenerator.pas',
-  ClpIRsaBlindingParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIRsaBlindingParameters.pas',
+  ClpIRsaGenerators in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIRsaGenerators.pas',
   ClpIRsaCoreEngine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpIRsaCoreEngine.pas',
   ClpIRsaDigestSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIRsaDigestSigner.pas',
   ClpIRsaEngine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpIRsaEngine.pas',
-  ClpIRsaKeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIRsaKeyGenerationParameters.pas',
-  ClpIRsaKeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIRsaKeyPairGenerator.pas',
-  ClpIRsaKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIRsaKeyParameters.pas',
-  ClpIRsaPrivateCrtKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIRsaPrivateCrtKeyParameters.pas',
+  ClpIRsaParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIRsaParameters.pas',
   ClpISalsa20Engine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpISalsa20Engine.pas',
   ClpIScalarSplitParameters in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIScalarSplitParameters.pas',
   ClpIScaleXNegateYPointMap in '..\..\CryptoLib\src\Interfaces\Math\EC\ClpIScaleXNegateYPointMap.pas',
@@ -350,10 +299,8 @@ uses
   ClpIWNafPreCompInfo in '..\..\CryptoLib\src\Interfaces\Math\EC\Multiplier\ClpIWNafPreCompInfo.pas',
   ClpIWTauNafPreCompInfo in '..\..\CryptoLib\src\Interfaces\Math\EC\Multiplier\ClpIWTauNafPreCompInfo.pas',
   ClpIX25519Agreement in '..\..\CryptoLib\src\Interfaces\Crypto\Agreements\ClpIX25519Agreement.pas',
-  ClpIX25519KeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIX25519KeyGenerationParameters.pas',
-  ClpIX25519KeyPairGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIX25519KeyPairGenerator.pas',
-  ClpIX25519PrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIX25519PrivateKeyParameters.pas',
-  ClpIX25519PublicKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIX25519PublicKeyParameters.pas',
+  ClpIX25519Parameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIX25519Parameters.pas',
+  ClpIX25519Generators in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIX25519Generators.pas',
   ClpIX509Asn1Objects in '..\..\CryptoLib\src\Interfaces\Asn1\X509\ClpIX509Asn1Objects.pas',
   ClpIX509Asn1Generators in '..\..\CryptoLib\src\Interfaces\Asn1\X509\ClpIX509Asn1Generators.pas',
   ClpIX509NameEntryConverter in '..\..\CryptoLib\src\Interfaces\Asn1\X509\ClpIX509NameEntryConverter.pas',
@@ -411,15 +358,11 @@ uses
   ClpRosstandartObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Rosstandart\ClpRosstandartObjectIdentifiers.pas',
   ClpRsaBlindedEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpRsaBlindedEngine.pas',
   ClpRsaBlindingEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpRsaBlindingEngine.pas',
-  ClpRsaBlindingFactorGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpRsaBlindingFactorGenerator.pas',
-  ClpRsaBlindingParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpRsaBlindingParameters.pas',
+  ClpRsaGenerators in '..\..\CryptoLib\src\Crypto\Generators\ClpRsaGenerators.pas',
   ClpRsaCoreEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpRsaCoreEngine.pas',
   ClpRsaDigestSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpRsaDigestSigner.pas',
   ClpRsaEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpRsaEngine.pas',
-  ClpRsaKeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpRsaKeyGenerationParameters.pas',
-  ClpRsaKeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpRsaKeyPairGenerator.pas',
-  ClpRsaKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpRsaKeyParameters.pas',
-  ClpRsaPrivateCrtKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpRsaPrivateCrtKeyParameters.pas',
+  ClpRsaParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpRsaParameters.pas',
   ClpSalsa20Engine in '..\..\CryptoLib\src\Crypto\Engines\ClpSalsa20Engine.pas',
   ClpScalarSplitParameters in '..\..\CryptoLib\src\Math\EC\Endo\ClpScalarSplitParameters.pas',
   ClpScaleXNegateYPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleXNegateYPointMap.pas',
@@ -460,10 +403,8 @@ uses
   ClpX25519 in '..\..\CryptoLib\src\Math\EC\Rfc7748\ClpX25519.pas',
   ClpX25519Agreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpX25519Agreement.pas',
   ClpX25519Field in '..\..\CryptoLib\src\Math\EC\Rfc7748\ClpX25519Field.pas',
-  ClpX25519KeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpX25519KeyGenerationParameters.pas',
-  ClpX25519KeyPairGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpX25519KeyPairGenerator.pas',
-  ClpX25519PrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpX25519PrivateKeyParameters.pas',
-  ClpX25519PublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpX25519PublicKeyParameters.pas',
+  ClpX25519Parameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpX25519Parameters.pas',
+  ClpX25519Generators in '..\..\CryptoLib\src\Crypto\Generators\ClpX25519Generators.pas',
   ClpX509Asn1Objects in '..\..\CryptoLib\src\Asn1\X509\ClpX509Asn1Objects.pas',
   ClpX509DefaultEntryConverter in '..\..\CryptoLib\src\Asn1\X509\ClpX509DefaultEntryConverter.pas',
   ClpX509Extension in '..\..\CryptoLib\src\Asn1\X509\ClpX509Extension.pas',

+ 4 - 5
CryptoLib.Tests/src/Asn1/X509/DeltaCertificateTests.pas

@@ -45,21 +45,20 @@ uses
   ClpCryptoLibTypes,
   ClpBigInteger,
   ClpGeneratorUtilities,
-  ClpRsaKeyGenerationParameters,
-  ClpIRsaKeyGenerationParameters,
+  ClpRsaParameters,
+  ClpIRsaParameters,
   ClpSecureRandom,
   ClpISecureRandom,
-  ClpECKeyGenerationParameters,
+  ClpECParameters,
   ClpSecObjectIdentifiers,
   ClpCustomNamedCurves,
-  ClpECDomainParameters,
   ClpIX509Generators,
   ClpX509Generators,
   ClpAsn1SignatureFactory,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPair,
   ClpIX9ECAsn1Objects,
-  ClpIECDomainParameters,
+  ClpIECParameters,
   ClpISignatureFactory,
   CryptoLibTestBase;
 

+ 2 - 10
CryptoLib.Tests/src/Crypto/DHTests.pas

@@ -41,16 +41,8 @@ uses
   ClpDHBasicAgreement,
   ClpIDHParameters,
   ClpDHParameters,
-  ClpIDHParametersGenerator,
-  ClpDHParametersGenerator,
-  ClpIDHKeyPairGenerator,
-  ClpDHKeyPairGenerator,
-  ClpIDHBasicKeyPairGenerator,
-  ClpDHBasicKeyPairGenerator,
-  ClpIDHPrivateKeyParameters,
-  ClpIDHPublicKeyParameters,
-  ClpIDHKeyGenerationParameters,
-  ClpDHKeyGenerationParameters,
+  ClpIDHGenerators,
+  ClpDHGenerators,
   ClpIAsymmetricCipherKeyPair,
   ClpBigInteger,
   ClpCryptoLibTypes,

+ 4 - 21
CryptoLib.Tests/src/Crypto/DSATests.pas

@@ -38,29 +38,14 @@ uses
   ClpDsaParameters,
   ClpIECC,
   ClpECC,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
+  ClpECParameters,
+  ClpIECParameters,
   ClpIAsn1Objects,
-  ClpDsaParametersGenerator,
-  ClpIDsaParametersGenerator,
-  ClpIDsaValidationParameters,
-  ClpIDsaKeyPairGenerator,
-  ClpDsaKeyPairGenerator,
-  ClpIDsaPublicKeyParameters,
-  ClpDsaPublicKeyParameters,
-  ClpDsaPrivateKeyParameters,
-  ClpIDsaPrivateKeyParameters,
-  ClpIDsaKeyGenerationParameters,
-  ClpDsaKeyGenerationParameters,
-  ClpDsaParameterGenerationParameters,
-  ClpIDsaParameterGenerationParameters,
+  ClpDsaGenerators,
+  ClpIDsaGenerators,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPair,
   ClpIAsymmetricKeyParameter,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
   ClpParametersWithRandom,
   ClpIParametersWithRandom,
   ClpSignerUtilities,
@@ -68,8 +53,6 @@ uses
   ClpGeneratorUtilities,
   ClpTeleTrusTObjectIdentifiers,
   ClpX9ObjectIdentifiers,
-  ClpECKeyGenerationParameters,
-  ClpIECKeyGenerationParameters,
   ClpBigInteger,
   ClpAsn1Objects,
   ClpDSADigestSigner,

+ 2 - 6
CryptoLib.Tests/src/Crypto/DeterministicDsaTests.pas

@@ -43,12 +43,8 @@ uses
   ClpIHMacDsaKCalculator,
   ClpICipherParameters,
   ClpIX9ECAsn1Objects,
-  ClpIECPrivateKeyParameters,
-  ClpECPrivateKeyParameters,
-  ClpIDsaPrivateKeyParameters,
-  ClpDsaPrivateKeyParameters,
-  ClpIECDomainParameters,
-  ClpECDomainParameters,
+  ClpECParameters,
+  ClpIECParameters,
   ClpBigInteger,
   ClpDigestUtilities,
   ClpSecNamedCurves,

+ 2 - 2
CryptoLib.Tests/src/Crypto/ISO9796Tests.pas

@@ -37,8 +37,8 @@ uses
   ClpIRsaEngine,
   ClpISO9796d1Encoding,
   ClpIISO9796d1Encoding,
-  ClpRsaKeyParameters,
-  ClpIRsaKeyParameters,
+  ClpRsaParameters,
+  ClpIRsaParameters,
   ClpIAsymmetricBlockCipher,
   ClpCryptoLibTypes,
   CryptoLibTestBase;

+ 4 - 8
CryptoLib.Tests/src/Crypto/PssTests.pas

@@ -32,16 +32,12 @@ uses
   TestFramework,
 {$ENDIF FPC}
   ClpBigInteger,
-  ClpIRsaKeyParameters,
-  ClpRsaKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaKeyGenerationParameters,
-  ClpRsaKeyGenerationParameters,
+  ClpIRsaParameters,
+  ClpRsaParameters,
   ClpParametersWithRandom,
   ClpIParametersWithRandom,
-  ClpIRsaKeyPairGenerator,
-  ClpRsaKeyPairGenerator,
+  ClpIRsaGenerators,
+  ClpRsaGenerators,
   ClpRsaEngine,
   ClpRsaBlindedEngine,
   ClpPssSigner,

+ 4 - 8
CryptoLib.Tests/src/Crypto/RSABlindedTests.pas

@@ -20,14 +20,10 @@ uses
   ClpICipherParameters,
   ClpIAsymmetricBlockCipher,
   ClpIAsymmetricCipherKeyPair,
-  ClpRsaKeyParameters,
-  ClpIRsaKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
-  ClpRsaKeyGenerationParameters,
-  ClpIRsaKeyGenerationParameters,
-  ClpRsaKeyPairGenerator,
-  ClpIRsaKeyPairGenerator,
+  ClpRsaParameters,
+  ClpIRsaParameters,
+  ClpRsaGenerators,
+  ClpIRsaGenerators,
   ClpRsaBlindedEngine,
   ClpPkcs1Encoding,
   ClpIPkcs1Encoding,

+ 2 - 4
CryptoLib.Tests/src/Crypto/RSADigestSignerTests.pas

@@ -36,10 +36,8 @@ uses
   ClpISigner,
   ClpRsaDigestSigner,
   ClpIRsaDigestSigner,
-  ClpRsaKeyParameters,
-  ClpIRsaKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
+  ClpRsaParameters,
+  ClpIRsaParameters,
   ClpIAsn1Objects,
   ClpAsn1Objects,
   ClpX509Asn1Objects,

+ 4 - 8
CryptoLib.Tests/src/Crypto/RSATests.pas

@@ -32,14 +32,10 @@ uses
   TestFramework,
 {$ENDIF FPC}
   ClpBigInteger,
-  ClpIRsaKeyParameters,
-  ClpRsaKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaKeyGenerationParameters,
-  ClpRsaKeyGenerationParameters,
-  ClpIRsaKeyPairGenerator,
-  ClpRsaKeyPairGenerator,
+  ClpIRsaParameters,
+  ClpRsaParameters,
+  ClpIRsaGenerators,
+  ClpRsaGenerators,
   ClpRsaBlindedEngine,
   ClpPkcs1Encoding,
   ClpOaepEncoding,

+ 2 - 4
CryptoLib.Tests/src/Crypto/X931SignerTests.pas

@@ -32,10 +32,8 @@ uses
   TestFramework,
 {$ENDIF FPC}
   ClpBigInteger,
-  ClpIRsaKeyParameters,
-  ClpRsaKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
+  ClpIRsaParameters,
+  ClpRsaParameters,
   ClpRsaEngine,
   ClpIRsaEngine,
   ClpX931Signer,

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

@@ -45,23 +45,16 @@ uses
   ClpIKDF2BytesGenerator,
   ClpIAsymmetricCipherKeyPair,
   ClpAsymmetricCipherKeyPair,
-  ClpECKeyPairGenerator,
-  ClpIECKeyPairGenerator,
-  ClpECKeyGenerationParameters,
-  ClpIECKeyGenerationParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
+  ClpECGenerators,
+  ClpIECGenerators,
+  ClpECParameters,
+  ClpIECParameters,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpIKeyGenerationParameters,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
-  ClpIESParameters,
+  ClpIesParameters,
   ClpIBufferedBlockCipher,
   ClpPaddedBufferedBlockCipher,
-  ClpIESWithCipherParameters,
   ClpEphemeralKeyPairGenerator,
   ClpIEphemeralKeyPairGenerator,
   ClpECIESPublicKeyParser,

+ 4 - 10
CryptoLib.Tests/src/Math/ECNRTests.pas

@@ -38,16 +38,10 @@ uses
   ClpIDigest,
   ClpECNRSigner,
   ClpIECNRSigner,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
-  ClpIECKeyGenerationParameters,
-  ClpECKeyGenerationParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpECKeyPairGenerator,
-  ClpIECKeyPairGenerator,
+  ClpECParameters,
+  ClpIECParameters,
+  ClpECGenerators,
+  ClpIECGenerators,
   ClpISigner,
   ClpIX9ECAsn1Objects,
   ClpIAsymmetricCipherKeyPair,

+ 4 - 9
CryptoLib.Tests/src/Math/IESCipherTests.pas

@@ -37,10 +37,6 @@ uses
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpGeneratorUtilities,
   ClpICipherParameters,
-  ClpIIESParameters,
-  ClpIIESWithCipherParameters,
-
-  ClpIESWithCipherParameters,
   ClpParametersWithIV,
   ClpIParametersWithIV,
   ClpIBufferedBlockCipher,
@@ -57,14 +53,13 @@ uses
   ClpIKdf2BytesGenerator,
   ClpIX9ECAsn1Objects,
   ClpSecNamedCurves,
-  ClpIECDomainParameters,
-  ClpECDomainParameters,
-  ClpECKeyGenerationParameters,
+  ClpIECParameters,
+  ClpECParameters,
   ClpSecureRandom,
   ClpISecureRandom,
   ClpIAsymmetricCipherKeyPair,
-  ClpIIesCipherParameters,
-  ClpIesCipherParameters,
+  ClpIIesParameters,
+  ClpIesParameters,
   ClpIBufferedCipher,
   ClpBufferedIesCipher,
   ClpDigestUtilities,

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

@@ -22,21 +22,16 @@ uses
   ClpECIESPublicKeyParser,
   ClpIEphemeralKeyPairGenerator,
   ClpEphemeralKeyPairGenerator,
-  ClpIECKeyPairGenerator,
-  ClpECKeyPairGenerator,
-  ClpECKeyGenerationParameters,
+  ClpIECGenerators,
+  ClpECGenerators,
   ClpIKeyEncoder,
   ClpKeyEncoder,
   ClpIECDHBasicAgreement,
   ClpECDHBasicAgreement,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
+  ClpECParameters,
+  ClpIECParameters,
   ClpSecureRandom,
   ClpISecureRandom,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
   ClpIBufferedBlockCipher,
   ClpPaddedBufferedBlockCipher,
   ClpCbcBlockCipher,
@@ -47,8 +42,8 @@ uses
   ClpCustomNamedCurves,
   ClpDigestUtilities,
   ClpICipherParameters,
-  ClpIIESWithCipherParameters,
-  ClpIESWithCipherParameters,
+  ClpIIesParameters,
+  ClpIesParameters,
   ClpParametersWithIV,
   ClpIPascalCoinIESEngine,
   ClpPascalCoinIESEngine,

+ 8 - 16
CryptoLib.Tests/src/Others/CertTests.pas

@@ -50,16 +50,12 @@ uses
   ClpIX509Generators,
   ClpAsn1SignatureFactory,
   ClpISignatureFactory,
-  ClpRsaKeyParameters,
-  ClpIRsaKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
-  ClpDsaParametersGenerator,
-  ClpIDsaParametersGenerator,
-  ClpDsaKeyGenerationParameters,
-  ClpIDsaKeyGenerationParameters,
-  ClpRsaKeyGenerationParameters,
-  ClpIRsaKeyGenerationParameters,
+  ClpRsaParameters,
+  ClpIRsaParameters,
+  ClpDsaParameters,
+  ClpIDsaParameters,
+  ClpDsaGenerators,
+  ClpIDsaGenerators,
   ClpIAsymmetricKeyParameter,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPair,
@@ -84,12 +80,8 @@ uses
   ClpX9ObjectIdentifiers,
   ClpECNamedCurveTable,
   ClpIX9ECAsn1Objects,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
+  ClpECParameters,
+  ClpIECParameters,
   CryptoLibTestBase;
 
 type

+ 3 - 8
CryptoLib.Tests/src/Others/ECDsa5Tests.pas

@@ -36,13 +36,9 @@ uses
   ClpISecureRandom,
   ClpSecureRandom,
   ClpECC,
-  ClpIECDomainParameters,
-  ClpIECPrivateKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpECPrivateKeyParameters,
-  ClpECPublicKeyParameters,
-  ClpECKeyPairGenerator,
-  ClpECKeyGenerationParameters,
+  ClpIECParameters,
+  ClpECParameters,
+  ClpECGenerators,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPair,
   ClpIAsymmetricKeyParameter,
@@ -50,7 +46,6 @@ uses
   ClpIParametersWithRandom,
   ClpIECC,
   ClpSignerUtilities,
-  ClpECDomainParameters,
   ClpIAsn1Objects,
   ClpISigner,
   ClpAsn1Objects,

+ 4 - 10
CryptoLib.Tests/src/Others/ECTests.pas

@@ -43,16 +43,10 @@ uses
   ClpECDHCBasicAgreement,
   ClpParametersWithRandom,
   ClpIParametersWithRandom,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
-  ClpIECKeyPairGenerator,
-  ClpECKeyPairGenerator,
-  ClpIECKeyGenerationParameters,
-  ClpECKeyGenerationParameters,
+  ClpECParameters,
+  ClpIECParameters,
+  ClpIECGenerators,
+  ClpECGenerators,
   ClpIAsymmetricCipherKeyPair,
   ClpECC,
   ClpIECC,

+ 4 - 8
CryptoLib.Tests/src/Others/Ed25519HigherLevelTests.pas

@@ -35,14 +35,10 @@ uses
   ClpEd25519Signer,
   ClpEd25519CtxSigner,
   ClpEd25519PhSigner,
-  ClpEd25519PrivateKeyParameters,
-  ClpIEd25519PrivateKeyParameters,
-  ClpEd25519PublicKeyParameters,
-  ClpIEd25519PublicKeyParameters,
-  ClpEd25519KeyPairGenerator,
-  ClpIEd25519KeyPairGenerator,
-  ClpEd25519KeyGenerationParameters,
-  ClpIEd25519KeyGenerationParameters,
+  ClpEd25519Parameters,
+  ClpIEd25519Parameters,
+  ClpEd25519Generators,
+  ClpIEd25519Generators,
   ClpIAsymmetricCipherKeyPair,
   ClpISigner,
   ClpSecureRandom,

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

@@ -39,17 +39,15 @@ uses
   ClpSecNamedCurves,
   ClpTeleTrusTNamedCurves,
   ClpIX9ECAsn1Objects,
-  ClpECDomainParameters,
+  ClpECParameters,
   ClpECNamedCurveTable,
   ClpECGost3410NamedCurves,
-  ClpIECDomainParameters,
+  ClpIECParameters,
   ClpSignerUtilities,
-  ClpECKeyPairGenerator,
-  ClpECKeyGenerationParameters,
+  ClpECGenerators,
   ClpIAsymmetricKeyParameter,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIAsymmetricCipherKeyPair,
-  ClpIECKeyGenerationParameters,
   ClpGeneratorUtilities,
   ClpAgreementUtilities,
   ClpConverters,

+ 6 - 16
CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas

@@ -38,27 +38,17 @@ uses
   ClpSignerUtilities,
   ClpSecureRandom,
   ClpISecureRandom,
-  ClpECDomainParameters,
+  ClpECParameters,
   ClpICipherParameters,
-  ClpIECDomainParameters,
-  ClpECPublicKeyParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpIECPrivateKeyParameters,
+  ClpIECParameters,
   ClpIECC,
   ClpIDsaParameters,
-  ClpIDsaPrivateKeyParameters,
-  ClpIDsaPublicKeyParameters,
   ClpDsaParameters,
-  ClpDsaPrivateKeyParameters,
-  ClpDsaPublicKeyParameters,
-  ClpRsaKeyParameters,
-  ClpIRsaKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
+  ClpRsaParameters,
+  ClpIRsaParameters,
   ClpIAsymmetricCipherKeyPairGenerator,
-  ClpEd25519KeyGenerationParameters,
-  ClpIEd25519KeyGenerationParameters,
+  ClpEd25519Parameters,
+  ClpIEd25519Parameters,
   ClpIAsymmetricCipherKeyPair,
   ClpGeneratorUtilities,
   CryptoLibTestBase;

+ 4 - 4
CryptoLib.Tests/src/Others/X25519HigherLevelTests.pas

@@ -31,10 +31,10 @@ uses
 {$ELSE}
   TestFramework,
 {$ENDIF FPC}
-  ClpX25519KeyPairGenerator,
-  ClpIX25519KeyPairGenerator,
-  ClpX25519KeyGenerationParameters,
-  ClpIX25519KeyGenerationParameters,
+  ClpX25519Generators,
+  ClpIX25519Generators,
+  ClpX25519Parameters,
+  ClpIX25519Parameters,
   ClpX25519Agreement,
   ClpIX25519Agreement,
   ClpIAsymmetricCipherKeyPair,

+ 3 - 11
CryptoLib.Tests/src/X509/X509CertGenTests.pas

@@ -43,19 +43,11 @@ uses
   ClpIX509Generators,
   ClpAsn1SignatureFactory,
   ClpISignatureFactory,
-  ClpRsaKeyParameters,
-  ClpIRsaKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
+  ClpRsaParameters,
+  ClpIRsaParameters,
   ClpDsaParameters,
   ClpIDsaParameters,
-  ClpDsaPrivateKeyParameters,
-  ClpIDsaPrivateKeyParameters,
-  ClpDsaPublicKeyParameters,
-  ClpIDsaPublicKeyParameters,
-  ClpIECDomainParameters,
-  ClpIECPublicKeyParameters,
-  ClpIECPrivateKeyParameters,
+  ClpIECParameters,
   ClpIX9ECAsn1Objects,
   ClpRsaDigestSigner,
   ClpIRsaDigestSigner,

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

@@ -29,8 +29,8 @@ uses
   ClpRosstandartObjectIdentifiers,
   ClpECC,
   ClpIECC,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
+  ClpECParameters,
+  ClpIECParameters,
   ClpIAsn1Objects;
 
 type

+ 8 - 11
CryptoLib/src/Crypto/Agreements/ClpDHAgreement.pas

@@ -29,12 +29,9 @@ uses
   ClpICipherParameters,
   ClpIDHAgreement,
   ClpIDHParameters,
-  ClpDHKeyPairGenerator,
-  ClpIDHKeyPairGenerator,
-  ClpIDHPrivateKeyParameters,
-  ClpIDHPublicKeyParameters,
-  ClpDHKeyGenerationParameters,
-  ClpIDHKeyGenerationParameters,
+  ClpDHParameters,
+  ClpDHGenerators,
+  ClpIDHGenerators,
   ClpIAsymmetricKeyParameter,
   ClpIAsymmetricCipherKeyPair,
   ClpIParametersWithRandom,
@@ -122,7 +119,7 @@ begin
     raise EArgumentCryptoLibException.CreateRes(@SDHPublicKeyWrongParameter);
   end;
 
-  p := FdhParams.p;
+  p := FdhParams.P;
 
   peerY := pub.Y;
 
@@ -132,14 +129,14 @@ begin
     raise EArgumentCryptoLibException.CreateRes(@SDHPublicKeyWeak);
   end;
 
-  result := peerY.ModPow(FprivateValue, p);
+  Result := peerY.ModPow(FprivateValue, p);
 
-  if (result.Equals(TBigInteger.One)) then
+  if (Result.Equals(TBigInteger.One)) then
   begin
     raise EInvalidOperationCryptoLibException.CreateRes(@SSharedKeyInvalid);
   end;
 
-  result := &message.ModPow(Fkey.X, p).Multiply(result).&Mod(p);
+  Result := &message.ModPow(Fkey.X, p).Multiply(Result).&Mod(p);
 end;
 
 function TDHAgreement.CalculateMessage: TBigInteger;
@@ -156,7 +153,7 @@ begin
 
   FprivateValue := (dhPair.Private as IDHPrivateKeyParameters).X;
 
-  result := (dhPair.Public as IDHPublicKeyParameters).Y;
+  Result := (dhPair.Public as IDHPublicKeyParameters).Y;
 end;
 
 procedure TDHAgreement.Init(const parameters: ICipherParameters);

+ 4 - 6
CryptoLib/src/Crypto/Agreements/ClpDHBasicAgreement.pas

@@ -28,8 +28,6 @@ uses
   ClpIBasicAgreement,
   ClpIDHBasicAgreement,
   ClpIDHParameters,
-  ClpIDHPrivateKeyParameters,
-  ClpIDHPublicKeyParameters,
   ClpIParametersWithRandom,
   ClpCryptoLibTypes;
 
@@ -103,7 +101,7 @@ begin
     raise EArgumentCryptoLibException.CreateRes(@SDHPublicKeyWrongParameter);
   end;
 
-  p := FdhParams.p;
+  p := FdhParams.P;
 
   peerY := pub.Y;
 
@@ -113,9 +111,9 @@ begin
     raise EArgumentCryptoLibException.CreateRes(@SDHPublicKeyWeak);
   end;
 
-  result := peerY.ModPow(Fkey.X, p);
+  Result := peerY.ModPow(Fkey.X, p);
 
-  if (result.Equals(TBigInteger.One)) then
+  if (Result.Equals(TBigInteger.One)) then
   begin
     raise EInvalidOperationCryptoLibException.CreateRes(@SSharedKeyInvalid);
   end;
@@ -123,7 +121,7 @@ end;
 
 function TDHBasicAgreement.GetFieldSize: Int32;
 begin
-  result := (Fkey.Parameters.p.BitLength + 7) div 8;
+  Result := (Fkey.Parameters.P.BitLength + 7) div 8;
 end;
 
 procedure TDHBasicAgreement.Init(const parameters: ICipherParameters);

+ 1 - 3
CryptoLib/src/Crypto/Agreements/ClpECDHBasicAgreement.pas

@@ -26,13 +26,11 @@ uses
   ClpBigInteger,
   ClpECAlgorithms,
   ClpICipherParameters,
-  ClpIECDomainParameters,
+  ClpIECParameters,
   ClpIECC,
   ClpIBasicAgreement,
   ClpIECDHBasicAgreement,
-  ClpIECPrivateKeyParameters,
   ClpIParametersWithRandom,
-  ClpIECPublicKeyParameters,
   ClpCryptoLibTypes;
 
 resourcestring

+ 1 - 3
CryptoLib/src/Crypto/Agreements/ClpECDHCBasicAgreement.pas

@@ -28,11 +28,9 @@ uses
   ClpICipherParameters,
   ClpIECC,
   ClpIBasicAgreement,
-  ClpIECDomainParameters,
+  ClpIECParameters,
   ClpIECDHCBasicAgreement,
-  ClpIECPrivateKeyParameters,
   ClpIParametersWithRandom,
-  ClpIECPublicKeyParameters,
   ClpCryptoLibTypes;
 
 resourcestring

+ 2 - 3
CryptoLib/src/Crypto/Agreements/ClpX25519Agreement.pas

@@ -26,9 +26,8 @@ uses
   ClpIRawAgreement,
   ClpIX25519Agreement,
   ClpICipherParameters,
-  ClpX25519PrivateKeyParameters,
-  ClpIX25519PrivateKeyParameters,
-  ClpIX25519PublicKeyParameters,
+  ClpIX25519Parameters,
+  ClpX25519Parameters,
   ClpCryptoLibTypes;
 
 resourcestring

+ 1 - 2
CryptoLib/src/Crypto/Ciphers/ClpBufferedIesCipher.pas

@@ -26,8 +26,7 @@ uses
   SysUtils,
   ClpICipherParameters,
   ClpIIESEngine,
-  ClpIIESParameters,
-  ClpIIesCipherParameters,
+  ClpIIesParameters,
   ClpBufferedCipherBase,
   ClpCryptoLibTypes;
 

+ 1 - 1
CryptoLib/src/Crypto/ClpKeyEncoder.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   ClpIAsymmetricKeyParameter,
-  ClpIECPublicKeyParameters,
+  ClpIECParameters,
   ClpIKeyEncoder,
   ClpCryptoLibTypes;
 

+ 1 - 1
CryptoLib/src/Crypto/Encodings/ClpISO9796d1Encoding.pas

@@ -26,7 +26,7 @@ uses
   ClpBigInteger,
   ClpICipherParameters,
   ClpParameterUtilities,
-  ClpIRsaKeyParameters,
+  ClpIRsaParameters,
   ClpIAsymmetricBlockCipher,
   ClpIISO9796d1Encoding,
   ClpCryptoLibTypes;

+ 1 - 2
CryptoLib/src/Crypto/Engines/ClpIesEngine.pas

@@ -30,7 +30,7 @@ uses
   ClpIDerivationFunction,
   ClpIBufferedBlockCipher,
   ClpICipherParameters,
-  ClpIIESParameters,
+  ClpIIesParameters,
   ClpIEphemeralKeyPairGenerator,
   ClpIAsymmetricKeyParameter,
   ClpKeyParameter,
@@ -41,7 +41,6 @@ uses
   ClpIEphemeralKeyPair,
   ClpKdfParameters,
   ClpIKdfParameters,
-  ClpIIesWithCipherParameters,
   ClpPack,
   ClpArrayUtilities,
   ClpBigInteger,

+ 1 - 2
CryptoLib/src/Crypto/Engines/ClpRsaBlindedEngine.pas

@@ -26,8 +26,7 @@ uses
   ClpBigInteger,
   ClpBigIntegers,
   ClpICipherParameters,
-  ClpIRsaKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
+  ClpIRsaParameters,
   ClpIRsa,
   ClpIAsymmetricBlockCipher,
   ClpIRsaBlindedEngine,

+ 1 - 2
CryptoLib/src/Crypto/Engines/ClpRsaBlindingEngine.pas

@@ -27,8 +27,7 @@ uses
   ClpBigIntegers,
   ClpICipherParameters,
   ClpIParametersWithRandom,
-  ClpIRsaBlindingParameters,
-  ClpIRsaKeyParameters,
+  ClpIRsaParameters,
   ClpIRsa,
   ClpRsaCoreEngine,
   ClpIAsymmetricBlockCipher,

+ 1 - 2
CryptoLib/src/Crypto/Engines/ClpRsaCoreEngine.pas

@@ -27,8 +27,7 @@ uses
   ClpBigIntegers,
   ClpICipherParameters,
   ClpParameterUtilities,
-  ClpIRsaKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
+  ClpIRsaParameters,
   ClpIRsa,
   ClpIRsaCoreEngine,
   ClpCryptoLibTypes;

+ 53 - 76
CryptoLib/src/Crypto/Generators/ClpArgon2ParametersGenerator.pas

@@ -58,7 +58,7 @@ type
     FPBKDF_Argon2: IPBKDF_Argon2;
     FArgon2Parameters: IArgon2Parameters;
 
-    function GenerateDerivedKey(dkLen: Int32): TCryptoLibByteArray; inline;
+    function GenerateDerivedKey(ADkLen: Int32): TCryptoLibByteArray; inline;
 
   public
 
@@ -74,10 +74,10 @@ type
 
     destructor Destroy; override;
 
-    procedure Init(argon2Type: TCryptoLibArgon2Type;
-      argon2Version: TCryptoLibArgon2Version; const password, salt, secret,
-      additional: TCryptoLibByteArray; iterations, memory, parallelism: Int32;
-      memoryCostType: TCryptoLibArgon2MemoryCostType);
+    procedure Init(AArgon2Type: TCryptoLibArgon2Type;
+      AArgon2Version: TCryptoLibArgon2Version; const APassword, ASalt, ASecret,
+      AAdditional: TCryptoLibByteArray; AIterations, AMemory, AParallelism: Int32;
+      AMemoryCostType: TCryptoLibArgon2MemoryCostType);
 
     /// <summary>
     /// Generate a key parameter derived from the password, salt, and
@@ -92,7 +92,7 @@ type
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String; keySize: Int32)
+    function GenerateDerivedParameters(const AAlgorithm: String; AKeySize: Int32)
       : ICipherParameters; overload; override;
 
     /// <summary>
@@ -100,33 +100,15 @@ type
     /// the password, salt, and iteration count we are currently initialised
     /// with.
     /// </summary>
-    /// <param name="algorithm">
-    /// a parameters object representing a key.
-    /// </param>
-    /// <param name="keySize">
-    /// the length, in bits, of the key required.
-    /// </param>
-    /// <param name="ivSize">
-    /// the length, in bits, of the iv required.
-    /// </param>
-    /// <returns>
-    /// a parameters object representing a key and an iv.
-    /// </returns>
-    function GenerateDerivedParameters(const algorithm: String;
-      keySize, ivSize: Int32): ICipherParameters; overload; override;
+    function GenerateDerivedParameters(const AAlgorithm: String;
+      AKeySize, AIvSize: Int32): ICipherParameters; overload; override;
 
     /// <summary>
     /// Generate a key parameter for use with a MAC derived from the
     /// password, salt, and iteration count we are currently initialised
     /// with.
     /// </summary>
-    /// <param name="keySize">
-    /// the length, in bits, of the key required.
-    /// </param>
-    /// <returns>
-    /// a parameters object representing a key.
-    /// </returns>
-    function GenerateDerivedMacParameters(keySize: Int32)
+    function GenerateDerivedMacParameters(AKeySize: Int32)
       : ICipherParameters; override;
 
   end;
@@ -139,12 +121,12 @@ procedure TArgon2ParametersGenerator.Clear();
 begin
   TArrayUtilities.Fill<Byte>(FPassword, 0, System.Length(FPassword), Byte(0));
 
-  if FArgon2Parameters <> Nil then
+  if FArgon2Parameters <> nil then
   begin
     FArgon2Parameters.Clear();
   end;
 
-  if FPBKDF_Argon2 <> Nil then
+  if FPBKDF_Argon2 <> nil then
   begin
     FPBKDF_Argon2.Clear();
   end;
@@ -152,7 +134,7 @@ end;
 
 constructor TArgon2ParametersGenerator.Create();
 begin
-  Inherited Create();
+  inherited Create();
 end;
 
 destructor TArgon2ParametersGenerator.Destroy();
@@ -161,62 +143,57 @@ begin
   inherited Destroy;
 end;
 
-function TArgon2ParametersGenerator.GenerateDerivedKey(dkLen: Int32)
-  : TCryptoLibByteArray;
+function TArgon2ParametersGenerator.GenerateDerivedKey(ADkLen: Int32): TCryptoLibByteArray;
 begin
-  result := FPBKDF_Argon2.GetBytes(dkLen);
+  Result := FPBKDF_Argon2.GetBytes(ADkLen);
 end;
 
-function TArgon2ParametersGenerator.GenerateDerivedMacParameters(keySize: Int32)
-  : ICipherParameters;
+function TArgon2ParametersGenerator.GenerateDerivedMacParameters(AKeySize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
+  LDKey: TCryptoLibByteArray;
+  LKeySize: Int32;
 begin
-  keySize := keySize div 8;
-
-  dKey := GenerateDerivedKey(keySize);
-
-  result := TKeyParameter.Create(dKey, 0, keySize);
+  LKeySize := AKeySize div 8;
+  LDKey := GenerateDerivedKey(LKeySize);
+  Result := TKeyParameter.Create(LDKey, 0, LKeySize);
 end;
 
-function TArgon2ParametersGenerator.GenerateDerivedParameters(const algorithm
-  : String; keySize: Int32): ICipherParameters;
+function TArgon2ParametersGenerator.GenerateDerivedParameters(const AAlgorithm: String;
+  AKeySize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
+  LDKey: TCryptoLibByteArray;
+  LKeySize: Int32;
 begin
-  keySize := keySize div 8;
-
-  dKey := GenerateDerivedKey(keySize);
-
-  result := TParameterUtilities.CreateKeyParameter(algorithm, dKey, 0, keySize);
+  LKeySize := AKeySize div 8;
+  LDKey := GenerateDerivedKey(LKeySize);
+  Result := TParameterUtilities.CreateKeyParameter(AAlgorithm, LDKey, 0, LKeySize);
 end;
 
-function TArgon2ParametersGenerator.GenerateDerivedParameters(const algorithm
-  : String; keySize, ivSize: Int32): ICipherParameters;
+function TArgon2ParametersGenerator.GenerateDerivedParameters(const AAlgorithm: String;
+  AKeySize, AIvSize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
-  key: IKeyParameter;
+  LDKey: TCryptoLibByteArray;
+  LKey: IKeyParameter;
+  LKeySize, LIvSize: Int32;
 begin
-  keySize := keySize div 8;
-  ivSize := ivSize div 8;
-
-  dKey := GenerateDerivedKey(keySize + ivSize);
-  key := TParameterUtilities.CreateKeyParameter(algorithm, dKey, 0, keySize);
-
-  result := TParametersWithIV.Create(key, dKey, keySize, ivSize);
+  LKeySize := AKeySize div 8;
+  LIvSize := AIvSize div 8;
+  LDKey := GenerateDerivedKey(LKeySize + LIvSize);
+  LKey := TParameterUtilities.CreateKeyParameter(AAlgorithm, LDKey, 0, LKeySize);
+  Result := TParametersWithIV.Create(LKey, LDKey, LKeySize, LIvSize);
 end;
 
-procedure TArgon2ParametersGenerator.Init(argon2Type: TCryptoLibArgon2Type;
-  argon2Version: TCryptoLibArgon2Version; const password, salt, secret,
-  additional: TCryptoLibByteArray; iterations, memory, parallelism: Int32;
-  memoryCostType: TCryptoLibArgon2MemoryCostType);
+procedure TArgon2ParametersGenerator.Init(AArgon2Type: TCryptoLibArgon2Type;
+  AArgon2Version: TCryptoLibArgon2Version; const APassword, ASalt, ASecret,
+  AAdditional: TCryptoLibByteArray; AIterations, AMemory, AParallelism: Int32;
+  AMemoryCostType: TCryptoLibArgon2MemoryCostType);
 var
   LArgon2ParametersBuilder: IArgon2ParametersBuilder;
   LArgon2Version: TArgon2Version;
 begin
-  FPassword := System.Copy(password);
+  FPassword := System.Copy(APassword);
 
-  case argon2Type of
+  case AArgon2Type of
     TCryptoLibArgon2Type.Argon2D:
       begin
         LArgon2ParametersBuilder := TArgon2dParametersBuilder.Builder();
@@ -236,7 +213,7 @@ begin
     end;
   end;
 
-  case argon2Version of
+  case AArgon2Version of
     TCryptoLibArgon2Version.Argon2Version10:
       begin
         LArgon2Version := TArgon2Version.a2vARGON2_VERSION_10;
@@ -252,21 +229,21 @@ begin
     end;
   end;
 
-  case memoryCostType of
+  case AMemoryCostType of
     TCryptoLibArgon2MemoryCostType.MemoryAsKB:
       begin
-        LArgon2ParametersBuilder.WithVersion(LArgon2Version).WithSalt(salt)
-          .WithSecret(secret).WithAdditional(additional)
-          .WithIterations(iterations).WithMemoryAsKB(memory)
-          .WithParallelism(parallelism);
+        LArgon2ParametersBuilder.WithVersion(LArgon2Version).WithSalt(ASalt)
+          .WithSecret(ASecret).WithAdditional(AAdditional)
+          .WithIterations(AIterations).WithMemoryAsKB(AMemory)
+          .WithParallelism(AParallelism);
       end;
 
     TCryptoLibArgon2MemoryCostType.MemoryPowOfTwo:
       begin
-        LArgon2ParametersBuilder.WithVersion(LArgon2Version).WithSalt(salt)
-          .WithSecret(secret).WithAdditional(additional)
-          .WithIterations(iterations).WithMemoryPowOfTwo(memory)
-          .WithParallelism(parallelism);
+        LArgon2ParametersBuilder.WithVersion(LArgon2Version).WithSalt(ASalt)
+          .WithSecret(ASecret).WithAdditional(AAdditional)
+          .WithIterations(AIterations).WithMemoryPowOfTwo(AMemory)
+          .WithParallelism(AParallelism);
       end
   else
     begin

+ 61 - 61
CryptoLib/src/Crypto/Generators/ClpBaseKdfBytesGenerator.pas

@@ -53,9 +53,9 @@ type
 
   strict protected
   var
-    Fdigest: IDigest;
-    FcounterStart: Int32;
-    Fshared, Fiv: TCryptoLibByteArray;
+    FDigest: IDigest;
+    FCounterStart: Int32;
+    FShared, FIv: TCryptoLibByteArray;
 
     function GetDigest(): IDigest; virtual;
 
@@ -70,14 +70,14 @@ type
     /// <param name="digest">
     /// the digest to be used as the source of derived keys.
     /// </param>
-    constructor Create(counterStart: Int32; const digest: IDigest);
+    constructor Create(ACounterStart: Int32; const ADigest: IDigest);
 
-    procedure Init(const parameters: IDerivationParameters); virtual;
+    procedure Init(const AParameters: IDerivationParameters); virtual;
 
     /// <summary>
     /// return the underlying digest.
     /// </summary>
-    property digest: IDigest read GetDigest;
+    property Digest: IDigest read GetDigest;
 
     /// <summary>
     /// fill len bytes of the output buffer with bytes generated from the
@@ -89,8 +89,8 @@ type
     /// <exception cref="EDataLengthCryptoLibException">
     /// if the out buffer is too small.
     /// </exception>
-    function GenerateBytes(const output: TCryptoLibByteArray;
-      outOff, length: Int32): Int32; virtual;
+    function GenerateBytes(const AOutput: TCryptoLibByteArray;
+      AOutOff, ALength: Int32): Int32; virtual;
 
   end;
 
@@ -98,29 +98,31 @@ implementation
 
 { TBaseKdfBytesGenerator }
 
-constructor TBaseKdfBytesGenerator.Create(counterStart: Int32;
-  const digest: IDigest);
+constructor TBaseKdfBytesGenerator.Create(ACounterStart: Int32;
+  const ADigest: IDigest);
 begin
-  Inherited Create();
-  FcounterStart := counterStart;
-  Fdigest := digest;
+  inherited Create();
+  FCounterStart := ACounterStart;
+  FDigest := ADigest;
 end;
 
-function TBaseKdfBytesGenerator.GenerateBytes(const output: TCryptoLibByteArray;
-  outOff, length: Int32): Int32;
+function TBaseKdfBytesGenerator.GenerateBytes(const AOutput: TCryptoLibByteArray;
+  AOutOff, ALength: Int32): Int32;
 var
-  outLen, cThreshold, i: Int32;
-  oBytes: Int64;
-  counterBase: UInt32;
-  dig, C: TCryptoLibByteArray;
+  LOutLen, LCThreshold, LI, LOutOff, LLength: Int32;
+  LOBytes: Int64;
+  LCounterBase: UInt32;
+  LDig, LC: TCryptoLibByteArray;
 begin
-  if ((System.length(output) - length) < outOff) then
+  if (System.Length(AOutput) - ALength) < AOutOff then
   begin
     raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooSmall);
   end;
 
-  oBytes := length;
-  outLen := Fdigest.GetDigestSize;
+  LOBytes := ALength;
+  LOutLen := FDigest.GetDigestSize;
+  LOutOff := AOutOff;
+  LLength := ALength;
 
   //
   // this is at odds with the standard implementation, the
@@ -129,84 +131,82 @@ begin
   // array with a long index at the moment...
   //
 
-  if (oBytes > ((Int64(2) shl 32) - 1)) then
+  if LOBytes > ((Int64(2) shl 32) - 1) then
   begin
-
     raise EArgumentCryptoLibException.CreateRes(@SOutputLengthTooLarge);
   end;
 
-  cThreshold := Int32((oBytes + outLen - 1) div outLen);
+  LCThreshold := Int32((LOBytes + LOutLen - 1) div LOutLen);
 
-  System.SetLength(dig, Fdigest.GetDigestSize);
+  System.SetLength(LDig, FDigest.GetDigestSize);
 
-  System.SetLength(C, 4);
+  System.SetLength(LC, 4);
 
-  TPack.UInt32_To_BE(UInt32(FcounterStart), C, 0);
+  TPack.UInt32_To_BE(UInt32(FCounterStart), LC, 0);
 
-  counterBase := UInt32(FcounterStart and (not $FF));
+  LCounterBase := UInt32(FCounterStart and (not $FF));
 
-  i := 0;
-  while i < cThreshold do
+  LI := 0;
+  while LI < LCThreshold do
   begin
-    Fdigest.BlockUpdate(Fshared, 0, System.length(Fshared));
-    Fdigest.BlockUpdate(C, 0, 4);
+    FDigest.BlockUpdate(FShared, 0, System.Length(FShared));
+    FDigest.BlockUpdate(LC, 0, 4);
 
-    if (Fiv <> Nil) then
+    if FIv <> nil then
     begin
-      Fdigest.BlockUpdate(Fiv, 0, System.length(Fiv));
+      FDigest.BlockUpdate(FIv, 0, System.Length(FIv));
     end;
 
-    Fdigest.DoFinal(dig, 0);
+    FDigest.DoFinal(LDig, 0);
 
-    if (length > outLen) then
+    if LLength > LOutLen then
     begin
-      System.Move(dig[0], output[outOff], outLen * System.SizeOf(Byte));
-      outOff := outOff + outLen;
-      length := length - outLen;
+      System.Move(LDig[0], AOutput[LOutOff], LOutLen * System.SizeOf(Byte));
+      LOutOff := LOutOff + LOutLen;
+      LLength := LLength - LOutLen;
     end
     else
     begin
-      System.Move(dig[0], output[outOff], length * System.SizeOf(Byte));
+      System.Move(LDig[0], AOutput[LOutOff], LLength * System.SizeOf(Byte));
     end;
 
-    System.Inc(C[3]);
-    if (C[3] = 0) then
-
+    System.Inc(LC[3]);
+    if LC[3] = 0 then
     begin
-      counterBase := counterBase + $100;
-      TPack.UInt32_To_BE(counterBase, C, 0);
+      LCounterBase := LCounterBase + $100;
+      TPack.UInt32_To_BE(LCounterBase, LC, 0);
     end;
 
-    System.Inc(i);
+    System.Inc(LI);
   end;
 
-  Fdigest.Reset();
+  FDigest.Reset();
 
-  result := Int32(oBytes);
+  Result := Int32(LOBytes);
 end;
 
 function TBaseKdfBytesGenerator.GetDigest: IDigest;
 begin
-  result := Fdigest;
+  Result := FDigest;
 end;
 
-procedure TBaseKdfBytesGenerator.Init(const parameters: IDerivationParameters);
+procedure TBaseKdfBytesGenerator.Init(const AParameters: IDerivationParameters);
 var
-  Lparameters: IDerivationParameters;
-  p1: IKdfParameters;
-  p2: IIso18033KdfParameters;
+  LParameters: IDerivationParameters;
+  LP1: IKdfParameters;
+  LP2: IIso18033KdfParameters;
 begin
-  Lparameters := parameters;
+  LParameters := AParameters;
 
-  if Supports(Lparameters, IKdfParameters, p1) then
+  if Supports(LParameters, IKdfParameters, LP1) then
   begin
-    Fshared := p1.GetSharedSecret();
-    Fiv := p1.GetIV();
+    FShared := LP1.GetSharedSecret();
+    FIv := LP1.GetIV();
   end
-  else if Supports(Lparameters, IIso18033KdfParameters, p2) then
+  else if Supports(LParameters, IIso18033KdfParameters, LP2) then
   begin
-    Fshared := p2.GetSeed();
-    Fiv := Nil;
+    FShared := LP2.GetSeed();
+    FIv := nil;
   end
   else
   begin

+ 32 - 37
CryptoLib/src/Crypto/Generators/ClpCipherKeyGenerator.pas

@@ -44,23 +44,23 @@ type
 
   strict private
   var
-    Funinitialised: Boolean;
-    FdefaultStrength: Int32;
+    FUninitialised: Boolean;
+    FDefaultStrength: Int32;
 
-    function GetdefaultStrength: Int32; inline;
+    function GetDefaultStrength: Int32; inline;
 
   strict protected
   var
-    Frandom: ISecureRandom;
-    Fstrength: Int32;
+    FRandom: ISecureRandom;
+    FStrength: Int32;
 
-    procedure EngineInit(const parameters: IKeyGenerationParameters); virtual;
+    procedure EngineInit(const AParameters: IKeyGenerationParameters); virtual;
     function EngineGenerateKey: TCryptoLibByteArray; virtual;
 
   public
 
     constructor Create(); overload;
-    constructor Create(defaultStrength: Int32); overload;
+    constructor Create(ADefaultStrength: Int32); overload;
 
     /// <summary>
     /// initialise the key generator.
@@ -68,7 +68,7 @@ type
     /// <param name="parameters">
     /// the parameters to be used for key generation
     /// </param>
-    procedure Init(const parameters: IKeyGenerationParameters);
+    procedure Init(const AParameters: IKeyGenerationParameters);
 
     /// <summary>
     /// Generate a secret key.
@@ -78,7 +78,7 @@ type
     /// </returns>
     function GenerateKey: TCryptoLibByteArray;
 
-    property defaultStrength: Int32 read GetdefaultStrength;
+    property DefaultStrength: Int32 read GetDefaultStrength;
   end;
 
 implementation
@@ -87,68 +87,63 @@ implementation
 
 constructor TCipherKeyGenerator.Create;
 begin
-  Inherited Create();
-  Funinitialised := true;
+  inherited Create();
+  FUninitialised := True;
 end;
 
-constructor TCipherKeyGenerator.Create(defaultStrength: Int32);
+constructor TCipherKeyGenerator.Create(ADefaultStrength: Int32);
 begin
-  Inherited Create();
-  Funinitialised := true;
-  if (defaultStrength < 1) then
+  inherited Create();
+  FUninitialised := True;
+  if ADefaultStrength < 1 then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SInvalidStrengthValue);
   end;
 
-  FdefaultStrength := defaultStrength;
+  FDefaultStrength := ADefaultStrength;
 end;
 
 function TCipherKeyGenerator.EngineGenerateKey: TCryptoLibByteArray;
 begin
-  result := TSecureRandom.GetNextBytes(Frandom, Fstrength);
+  Result := TSecureRandom.GetNextBytes(FRandom, FStrength);
 end;
 
-procedure TCipherKeyGenerator.EngineInit(const parameters
-  : IKeyGenerationParameters);
+procedure TCipherKeyGenerator.EngineInit(const AParameters: IKeyGenerationParameters);
 begin
-  Frandom := parameters.Random;
-  Fstrength := (parameters.Strength + 7) div 8;
+  FRandom := AParameters.Random;
+  FStrength := (AParameters.Strength + 7) div 8;
 end;
 
 function TCipherKeyGenerator.GenerateKey: TCryptoLibByteArray;
 begin
-  if (Funinitialised) then
+  if FUninitialised then
   begin
-    if (FdefaultStrength < 1) then
-    begin
-      raise EInvalidOperationCryptoLibException.CreateRes
-        (@SGeneratorNotInitialized);
-    end;
-
-    Funinitialised := false;
+    if FDefaultStrength < 1 then
+      raise EInvalidOperationCryptoLibException.CreateRes(@SGeneratorNotInitialized);
 
+    FUninitialised := False;
     EngineInit(TKeyGenerationParameters.Create(TSecureRandom.Create()
-      as ISecureRandom, FdefaultStrength) as IKeyGenerationParameters);
+      as ISecureRandom, FDefaultStrength) as IKeyGenerationParameters);
   end;
 
-  result := EngineGenerateKey();
+  Result := EngineGenerateKey();
 end;
 
-function TCipherKeyGenerator.GetdefaultStrength: Int32;
+function TCipherKeyGenerator.GetDefaultStrength: Int32;
 begin
-  result := FdefaultStrength;
+  Result := FDefaultStrength;
 end;
 
-procedure TCipherKeyGenerator.Init(const parameters: IKeyGenerationParameters);
+procedure TCipherKeyGenerator.Init(const AParameters: IKeyGenerationParameters);
 begin
-  if (parameters = Nil) then
+  if AParameters = nil then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SParametersNil);
   end;
 
-  Funinitialised := false;
+  FUninitialised := False;
 
-  EngineInit(parameters);
+  EngineInit(AParameters);
 end;
 
 end.

+ 0 - 104
CryptoLib/src/Crypto/Generators/ClpDHBasicKeyPairGenerator.pas

@@ -1,104 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHBasicKeyPairGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDHParameters,
-  ClpIDHBasicKeyPairGenerator,
-  ClpDHPublicKeyParameters,
-  ClpIDHPublicKeyParameters,
-  ClpDHPrivateKeyParameters,
-  ClpIDHPrivateKeyParameters,
-  ClpAsymmetricCipherKeyPair,
-  ClpIAsymmetricCipherKeyPair,
-  ClpIKeyGenerationParameters,
-  ClpIDHKeyGenerationParameters,
-  ClpDHKeyGeneratorHelper,
-  ClpIDHKeyGeneratorHelper,
-  ClpIAsymmetricCipherKeyPairGenerator,
-  ClpBigInteger,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SParametersCannotBeNil = '"parameters" Cannot Be Nil';
-
-type
-
-  /// <summary>
-  /// <para>
-  /// a basic Diffie-Hellman key pair generator.
-  /// </para>
-  /// <para>
-  /// This generates keys consistent for use with the basic algorithm for
-  /// Diffie-Hellman.
-  /// </para>
-  /// </summary>
-  TDHBasicKeyPairGenerator = class sealed(TInterfacedObject,
-    IAsymmetricCipherKeyPairGenerator, IDHBasicKeyPairGenerator)
-
-  strict private
-
-  var
-    Fparam: IDHKeyGenerationParameters;
-
-  public
-
-    procedure Init(const parameters: IKeyGenerationParameters);
-
-    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
-
-  end;
-
-implementation
-
-{ TDHBasicKeyPairGenerator }
-
-function TDHBasicKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
-var
-  dhp: IDHParameters;
-  helper: IDHKeyGeneratorHelper;
-  x, y: TBigInteger;
-begin
-
-  helper := TDHKeyGeneratorHelper.Instance;
-  dhp := Fparam.Parameters;
-
-  x := helper.CalculatePrivate(dhp, Fparam.Random);
-  y := helper.CalculatePublic(dhp, x);
-
-  result := TAsymmetricCipherKeyPair.Create(TDHPublicKeyParameters.Create(y,
-    dhp) as IDHPublicKeyParameters, TDHPrivateKeyParameters.Create(x, dhp)
-    as IDHPrivateKeyParameters);
-end;
-
-procedure TDHBasicKeyPairGenerator.Init(const parameters
-  : IKeyGenerationParameters);
-begin
-  if (parameters = Nil) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
-  end;
-
-  Fparam := parameters as IDHKeyGenerationParameters;
-end;
-
-end.

+ 134 - 0
CryptoLib/src/Crypto/Generators/ClpDHGenerators.pas

@@ -0,0 +1,134 @@
+{ *********************************************************************************** }
+{ *                              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 ClpDHGenerators;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpIDHParameters,
+  ClpIDHGenerators,
+  ClpDHParameters,
+  ClpAsymmetricCipherKeyPair,
+  ClpIAsymmetricCipherKeyPair,
+  ClpIKeyGenerationParameters,
+  ClpDHKeyGeneratorHelper,
+  ClpIAsymmetricCipherKeyPairGenerator,
+  ClpISecureRandom,
+  ClpDHParametersHelper,
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SParametersCannotBeNil = '"parameters" Cannot Be Nil';
+
+type
+  TDHKeyPairGenerator = class sealed(TInterfacedObject,
+    IAsymmetricCipherKeyPairGenerator, IDHKeyPairGenerator)
+  strict private
+    FParam: IDHKeyGenerationParameters;
+  public
+    procedure Init(const AParameters: IKeyGenerationParameters);
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+  end;
+
+  TDHBasicKeyPairGenerator = class sealed(TInterfacedObject,
+    IAsymmetricCipherKeyPairGenerator, IDHBasicKeyPairGenerator)
+  strict private
+    FParam: IDHKeyGenerationParameters;
+  public
+    procedure Init(const AParameters: IKeyGenerationParameters);
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+  end;
+
+  TDHParametersGenerator = class(TInterfacedObject, IDHParametersGenerator)
+  strict private
+    FCertainty, FSize: Int32;
+    FRandom: ISecureRandom;
+  public
+    procedure Init(ASize, ACertainty: Int32; const ARandom: ISecureRandom);
+    function GenerateParameters(): IDHParameters; virtual;
+  end;
+
+implementation
+
+function TDHKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
+var
+  LDhp: IDHParameters;
+  LX, LY: TBigInteger;
+begin
+  LDhp := FParam.Parameters;
+  LX := TDHKeyGeneratorHelper.CalculatePrivate(LDhp, FParam.Random);
+  LY := TDHKeyGeneratorHelper.CalculatePublic(LDhp, LX);
+  Result := TAsymmetricCipherKeyPair.Create(TDHPublicKeyParameters.Create(LY,
+    LDhp) as IDHPublicKeyParameters, TDHPrivateKeyParameters.Create(LX, LDhp)
+    as IDHPrivateKeyParameters);
+end;
+
+procedure TDHKeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
+begin
+  if AParameters = nil then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+  if not Supports(AParameters, IDHKeyGenerationParameters, FParam) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+end;
+
+function TDHBasicKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
+var
+  LDhp: IDHParameters;
+  LX, LY: TBigInteger;
+begin
+  LDhp := FParam.Parameters;
+  LX := TDHKeyGeneratorHelper.CalculatePrivate(LDhp, FParam.Random);
+  LY := TDHKeyGeneratorHelper.CalculatePublic(LDhp, LX);
+  Result := TAsymmetricCipherKeyPair.Create(TDHPublicKeyParameters.Create(LY,
+    LDhp) as IDHPublicKeyParameters, TDHPrivateKeyParameters.Create(LX, LDhp)
+    as IDHPrivateKeyParameters);
+end;
+
+procedure TDHBasicKeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
+begin
+  if AParameters = nil then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+  if not Supports(AParameters, IDHKeyGenerationParameters, FParam) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+end;
+
+function TDHParametersGenerator.GenerateParameters: IDHParameters;
+var
+  LSafePrimes: TCryptoLibGenericArray<TBigInteger>;
+  LP, LQ, LG: TBigInteger;
+begin
+  LSafePrimes := TDHParametersHelper.GenerateSafePrimes(FSize, FCertainty, FRandom);
+  LP := LSafePrimes[0];
+  LQ := LSafePrimes[1];
+  LG := TDHParametersHelper.SelectGenerator(LP, LQ, FRandom);
+  Result := TDHParameters.Create(LP, LG, LQ, TBigInteger.Two, nil);
+end;
+
+procedure TDHParametersGenerator.Init(ASize, ACertainty: Int32;
+  const ARandom: ISecureRandom);
+begin
+  FSize := ASize;
+  FCertainty := ACertainty;
+  FRandom := ARandom;
+end;
+
+end.

+ 31 - 69
CryptoLib/src/Crypto/Generators/ClpDHKeyGeneratorHelper.pas

@@ -22,119 +22,81 @@ unit ClpDHKeyGeneratorHelper;
 interface
 
 uses
-
   ClpISecureRandom,
   ClpBitOperations,
   ClpBigInteger,
   ClpBigIntegers,
   ClpECCompUtilities,
-  ClpIDHParameters,
-  ClpIDHKeyGeneratorHelper;
+  ClpIDHParameters;
 
 type
-  TDHKeyGeneratorHelper = class sealed(TInterfacedObject, IDHKeyGeneratorHelper)
-
-  strict private
-  class var
-
-    FIsBooted: Boolean;
-    FInstance: IDHKeyGeneratorHelper;
-
-    class function GetInstance: IDHKeyGeneratorHelper; static; inline;
-
-    class procedure Boot(); static;
-    class constructor DHKeyGeneratorHelper();
+  TDHKeyGeneratorHelper = class sealed(TObject)
   public
-
-    function CalculatePrivate(const dhParams: IDHParameters;
-      const random: ISecureRandom): TBigInteger;
-
-    function CalculatePublic(const dhParams: IDHParameters;
-      const x: TBigInteger): TBigInteger;
-
-    class property Instance: IDHKeyGeneratorHelper read GetInstance;
-
+    class function CalculatePrivate(const ADHParams: IDHParameters;
+      const ARandom: ISecureRandom): TBigInteger; static;
+    class function CalculatePublic(const ADHParams: IDHParameters;
+      const AX: TBigInteger): TBigInteger; static;
   end;
 
 implementation
 
 { TDHKeyGeneratorHelper }
 
-class procedure TDHKeyGeneratorHelper.Boot;
-begin
-  if not FIsBooted then
-  begin
-    FInstance := TDHKeyGeneratorHelper.Create();
-
-    FIsBooted := True;
-  end;
-end;
-
-function TDHKeyGeneratorHelper.CalculatePrivate(const dhParams: IDHParameters;
-  const random: ISecureRandom): TBigInteger;
+class function TDHKeyGeneratorHelper.CalculatePrivate(const ADHParams: IDHParameters;
+  const ARandom: ISecureRandom): TBigInteger;
 var
-  limit, minWeight, m: Int32;
-  x, min, q, max: TBigInteger;
+  LLimit, LMinWeight, LM: Int32;
+  LX, LMin, LQ, LMax: TBigInteger;
 begin
   Result := TBigInteger.GetDefault;
-  limit := dhParams.L;
+  LLimit := ADHParams.L;
 
-  if (limit <> 0) then
+  if LLimit <> 0 then
   begin
-    minWeight := TBitOperations.Asr32(limit, 2);
+    LMinWeight := TBitOperations.Asr32(LLimit, 2);
 
     while True do
     begin
-      x := TBigInteger.Create(limit, random).SetBit(limit - 1);
-      if (TWNafUtilities.GetNafWeight(x) >= minWeight) then
+      LX := TBigInteger.Create(LLimit, ARandom).SetBit(LLimit - 1);
+      if TWNafUtilities.GetNafWeight(LX) >= LMinWeight then
       begin
-        Result := x;
+        Result := LX;
         Exit;
       end;
     end;
   end;
 
-  min := TBigInteger.Two;
-  m := dhParams.m;
-  if (m <> 0) then
+  LMin := TBigInteger.Two;
+  LM := ADHParams.M;
+  if LM <> 0 then
   begin
-    min := TBigInteger.One.ShiftLeft(m - 1);
+    LMin := TBigInteger.One.ShiftLeft(LM - 1);
   end;
 
-  q := dhParams.q;
-  if (not(q.IsInitialized)) then
+  LQ := ADHParams.Q;
+  if not LQ.IsInitialized then
   begin
-    q := dhParams.P;
+    LQ := ADHParams.P;
   end;
-  max := q.Subtract(TBigInteger.Two);
+  LMax := LQ.Subtract(TBigInteger.Two);
 
-  minWeight := TBitOperations.Asr32(max.BitLength, 2);
+  LMinWeight := TBitOperations.Asr32(LMax.BitLength, 2);
 
   while True do
   begin
-    x := TBigIntegers.CreateRandomInRange(min, max, random);
-    if (TWNafUtilities.GetNafWeight(x) >= minWeight) then
+    LX := TBigIntegers.CreateRandomInRange(LMin, LMax, ARandom);
+    if TWNafUtilities.GetNafWeight(LX) >= LMinWeight then
     begin
-      Result := x;
+      Result := LX;
       Exit;
     end;
   end;
 end;
 
-function TDHKeyGeneratorHelper.CalculatePublic(const dhParams: IDHParameters;
-  const x: TBigInteger): TBigInteger;
-begin
-  Result := dhParams.G.ModPow(x, dhParams.P);
-end;
-
-class constructor TDHKeyGeneratorHelper.DHKeyGeneratorHelper;
-begin
-  TDHKeyGeneratorHelper.Boot();
-end;
-
-class function TDHKeyGeneratorHelper.GetInstance: IDHKeyGeneratorHelper;
+class function TDHKeyGeneratorHelper.CalculatePublic(const ADHParams: IDHParameters;
+  const AX: TBigInteger): TBigInteger;
 begin
-  Result := FInstance;
+  Result := ADHParams.G.ModPow(AX, ADHParams.P);
 end;
 
 end.

+ 0 - 104
CryptoLib/src/Crypto/Generators/ClpDHKeyPairGenerator.pas

@@ -1,104 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHKeyPairGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDHParameters,
-  ClpIDHKeyPairGenerator,
-  ClpDHPublicKeyParameters,
-  ClpIDHPublicKeyParameters,
-  ClpDHPrivateKeyParameters,
-  ClpIDHPrivateKeyParameters,
-  ClpAsymmetricCipherKeyPair,
-  ClpIAsymmetricCipherKeyPair,
-  ClpIKeyGenerationParameters,
-  ClpIDHKeyGenerationParameters,
-  ClpDHKeyGeneratorHelper,
-  ClpIDHKeyGeneratorHelper,
-  ClpIAsymmetricCipherKeyPairGenerator,
-  ClpBigInteger,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SParametersCannotBeNil = '"parameters" Cannot Be Nil';
-
-type
-
-  /// <summary>
-  /// <para>
-  /// a Diffie-Hellman key pair generator.
-  /// </para>
-  /// <para>
-  /// This generates keys consistent for use in the MTI/A0 key agreement
-  /// protocol as described in "Handbook of Applied Cryptography", Pages
-  /// 516-519.
-  /// </para>
-  /// </summary>
-  TDHKeyPairGenerator = class sealed(TInterfacedObject,
-    IAsymmetricCipherKeyPairGenerator, IDHKeyPairGenerator)
-
-  strict private
-
-  var
-    Fparam: IDHKeyGenerationParameters;
-
-  public
-
-    procedure Init(const parameters: IKeyGenerationParameters);
-
-    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
-
-  end;
-
-implementation
-
-{ TDHKeyPairGenerator }
-
-function TDHKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
-var
-  dhp: IDHParameters;
-  helper: IDHKeyGeneratorHelper;
-  x, y: TBigInteger;
-begin
-
-  helper := TDHKeyGeneratorHelper.Instance;
-  dhp := Fparam.Parameters;
-
-  x := helper.CalculatePrivate(dhp, Fparam.Random);
-  y := helper.CalculatePublic(dhp, x);
-
-  result := TAsymmetricCipherKeyPair.Create(TDHPublicKeyParameters.Create(y,
-    dhp) as IDHPublicKeyParameters, TDHPrivateKeyParameters.Create(x, dhp)
-    as IDHPrivateKeyParameters);
-end;
-
-procedure TDHKeyPairGenerator.Init(const parameters: IKeyGenerationParameters);
-begin
-  if (parameters = Nil) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
-  end;
-
-  Fparam := parameters as IDHKeyGenerationParameters;
-end;
-
-end.

+ 0 - 88
CryptoLib/src/Crypto/Generators/ClpDHParametersGenerator.pas

@@ -1,88 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHParametersGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpISecureRandom,
-  ClpDHParameters,
-  ClpIDHParameters,
-  ClpIDHParametersGenerator,
-  ClpDHParametersHelper,
-  ClpBigInteger,
-  ClpCryptoLibTypes;
-
-type
-  TDHParametersGenerator = class(TInterfacedObject, IDHParametersGenerator)
-
-  strict private
-  var
-    Fcertainty, Fsize: Int32;
-    Frandom: ISecureRandom;
-
-  public
-
-    procedure Init(size, certainty: Int32; const random: ISecureRandom);
-
-    /// <summary>
-    /// <para>
-    /// which Generates the p and g values from the given parameters,
-    /// returning the DHParameters object.
-    /// </para>
-    /// <para>
-    /// Note: can take a while...
-    /// </para>
-    /// </summary>
-    function GenerateParameters(): IDHParameters; virtual;
-
-  end;
-
-implementation
-
-{ TDHParametersGenerator }
-
-function TDHParametersGenerator.GenerateParameters: IDHParameters;
-var
-  safePrimes: TCryptoLibGenericArray<TBigInteger>;
-  p, q, g: TBigInteger;
-begin
-  //
-  // find a safe prime p where p = 2*q + 1, where p and q are prime.
-  //
-  safePrimes := TDHParametersHelper.GenerateSafePrimes(Fsize,
-    Fcertainty, Frandom);
-
-  p := safePrimes[0];
-  q := safePrimes[1];
-  g := TDHParametersHelper.SelectGenerator(p, q, Frandom);
-
-  result := TDHParameters.Create(p, g, q, TBigInteger.Two, Nil);
-end;
-
-procedure TDHParametersGenerator.Init(size, certainty: Int32;
-  const random: ISecureRandom);
-begin
-  Fsize := size;
-  Fcertainty := certainty;
-  Frandom := random;
-end;
-
-end.

+ 71 - 108
CryptoLib/src/Crypto/Generators/ClpDHParametersHelper.pas

@@ -41,7 +41,7 @@ type
     FBigPrimeProducts: TCryptoLibGenericArray<TBigInteger>;
     FIsBooted: Boolean;
 
-    class function ConstructBigPrimeProducts(const primeProducts
+    class function ConstructBigPrimeProducts(const APrimeProducts
       : TCryptoLibInt32Array): TCryptoLibGenericArray<TBigInteger>; static;
 
     class procedure Boot(); static;
@@ -58,8 +58,8 @@ type
     /// (see: Handbook of Applied Cryptography 4.86)
     /// </para>
     /// </summary>
-    class function GenerateSafePrimes(size, certainty: Int32;
-      const random: ISecureRandom): TCryptoLibGenericArray<TBigInteger>; static;
+    class function GenerateSafePrimes(ASize, ACertainty: Int32;
+      const ARandom: ISecureRandom): TCryptoLibGenericArray<TBigInteger>; static;
 
 {$IFNDEF _FIXINSIGHT_}
     /// <summary>
@@ -71,8 +71,8 @@ type
     /// generateSafePrimes)
     /// </para>
     /// </summary>
-    class function SelectGenerator(const p, q: TBigInteger;
-      const random: ISecureRandom): TBigInteger; static;
+    class function SelectGenerator(const AP, AQ: TBigInteger;
+      const ARandom: ISecureRandom): TBigInteger; static;
 {$ENDIF}
   end;
 
@@ -99,171 +99,134 @@ begin
   TDHParametersHelper.Boot;
 end;
 
-class function TDHParametersHelper.ConstructBigPrimeProducts(const primeProducts
+class function TDHParametersHelper.ConstructBigPrimeProducts(const APrimeProducts
   : TCryptoLibInt32Array): TCryptoLibGenericArray<TBigInteger>;
 var
-  bpp: TCryptoLibGenericArray<TBigInteger>;
-  i: Int32;
+  LBpp: TCryptoLibGenericArray<TBigInteger>;
+  LI: Int32;
 begin
-  System.SetLength(bpp, System.Length(FPrimeProducts));
+  System.SetLength(LBpp, System.Length(FPrimeProducts));
 
-  for i := 0 to System.Pred(System.Length(bpp)) do
+  for LI := 0 to System.Pred(System.Length(LBpp)) do
   begin
-    bpp[i] := TBigInteger.ValueOf(primeProducts[i]);
+    LBpp[LI] := TBigInteger.ValueOf(APrimeProducts[LI]);
   end;
 
-  result := bpp;
+  Result := LBpp;
 end;
 
-class function TDHParametersHelper.GenerateSafePrimes(size, certainty: Int32;
-  const random: ISecureRandom): TCryptoLibGenericArray<TBigInteger>;
+class function TDHParametersHelper.GenerateSafePrimes(ASize, ACertainty: Int32;
+  const ARandom: ISecureRandom): TCryptoLibGenericArray<TBigInteger>;
 var
-  p, q: TBigInteger;
-  qLength, minWeight, i, test, rem3, diff, j, prime, qRem: Int32;
-  retryFlag: Boolean;
+  LP, LQ: TBigInteger;
+  LQLength, LMinWeight, LI, LTest, LRem3, LDiff, LJ, LPrime, LQRem: Int32;
+  LRetryFlag: Boolean;
   LPrimeList: TCryptoLibInt32Array;
 begin
-  retryFlag := False;
-  qLength := size - 1;
-  minWeight := TBitOperations.Asr32(size, 2);
+  LRetryFlag := False;
+  LQLength := ASize - 1;
+  LMinWeight := TBitOperations.Asr32(ASize, 2);
 
-  if (size <= 32) then
+  if ASize <= 32 then
   begin
     while True do
-
     begin
-      q := TBigInteger.Create(qLength, 2, random);
+      LQ := TBigInteger.Create(LQLength, 2, ARandom);
 
-      p := q.ShiftLeft(1).Add(TBigInteger.One);
+      LP := LQ.ShiftLeft(1).Add(TBigInteger.One);
 
-      if (not p.IsProbablePrime(certainty, True)) then
-      begin
-        continue;
-      end;
+      if not LP.IsProbablePrime(ACertainty, True) then
+        Continue;
 
-      if ((certainty > 2) and (not(q.IsProbablePrime(certainty, True)))) then
-      begin
-        continue;
-      end;
+      if (ACertainty > 2) and (not LQ.IsProbablePrime(ACertainty, True)) then
+        Continue;
 
-      break;
+      Break;
     end;
   end
   else
   begin
     while True do
     begin
-      q := TBigInteger.Create(qLength, 0, random);
+      LQ := TBigInteger.Create(LQLength, 0, ARandom);
 
-      i := 0;
-      while i < System.Length(FPrimeLists) do
+      LI := 0;
+      while LI < System.Length(FPrimeLists) do
       begin
-        test := q.Remainder(FBigPrimeProducts[i]).Int32Value;
+        LTest := LQ.Remainder(FBigPrimeProducts[LI]).Int32Value;
 
-        if (i = 0) then
+        if LI = 0 then
         begin
-          rem3 := test mod 3;
-          if (rem3 <> 2) then
+          LRem3 := LTest mod 3;
+          if LRem3 <> 2 then
           begin
-            diff := (2 * rem3) + 2;
-            q := q.Add(TBigInteger.ValueOf(diff));
-            test := (test + diff) mod FPrimeProducts[i];
+            LDiff := (2 * LRem3) + 2;
+            LQ := LQ.Add(TBigInteger.ValueOf(LDiff));
+            LTest := (LTest + LDiff) mod FPrimeProducts[LI];
           end;
         end;
 
-        LPrimeList := FPrimeLists[i];
-        for j := 0 to System.Pred(System.Length(LPrimeList)) do
+        LPrimeList := FPrimeLists[LI];
+        for LJ := 0 to System.Pred(System.Length(LPrimeList)) do
         begin
-          prime := LPrimeList[j];
-          qRem := test mod prime;
-          if ((qRem = 0) or (qRem = TBitOperations.Asr32(prime, 1))) then
+          LPrime := LPrimeList[LJ];
+          LQRem := LTest mod LPrime;
+          if (LQRem = 0) or (LQRem = TBitOperations.Asr32(LPrime, 1)) then
           begin
-            q := q.Add(FSix);
-            retryFlag := True;
-            break;
+            LQ := LQ.Add(FSix);
+            LRetryFlag := True;
+            Break;
           end;
         end;
 
-        if retryFlag then
+        if LRetryFlag then
         begin
-          i := 0;
-          retryFlag := False;
+          LI := 0;
+          LRetryFlag := False;
         end
         else
-        begin
-          System.Inc(i);
-        end;
-
+          System.Inc(LI);
       end;
 
-      if (q.BitLength <> qLength) then
-      begin
-        continue;
-      end;
+      if LQ.BitLength <> LQLength then
+        Continue;
 
-      if (not(q.RabinMillerTest(2, random, True))) then
-      begin
-        continue;
-      end;
+      if not LQ.RabinMillerTest(2, ARandom, True) then
+        Continue;
 
-      p := q.ShiftLeft(1).Add(TBigInteger.One);
+      LP := LQ.ShiftLeft(1).Add(TBigInteger.One);
 
-      if (not(p.RabinMillerTest(certainty, random, True))) then
-      begin
-        continue;
-      end;
+      if not LP.RabinMillerTest(ACertainty, ARandom, True) then
+        Continue;
 
-      if ((certainty > 2) and (not q.RabinMillerTest(certainty - 2, random,
-        True))) then
-      begin
-        continue;
-      end;
+      if (ACertainty > 2) and (not LQ.RabinMillerTest(ACertainty - 2, ARandom, True)) then
+        Continue;
 
-      (*
-        * Require a minimum weight of the NAF representation, since low-weight primes may be
-        * weak against a version of the number-field-sieve for the discrete-logarithm-problem.
-        *
-        * See "The number field sieve for integers of low weight", Oliver Schirokauer.
-      *)
-      if (TWNafUtilities.GetNafWeight(p) < minWeight) then
-      begin
-        continue;
-      end;
+      if TWNafUtilities.GetNafWeight(LP) < LMinWeight then
+        Continue;
 
-      break;
+      Break;
     end;
   end;
 
-  result := TCryptoLibGenericArray<TBigInteger>.Create(p, q);
+  Result := TCryptoLibGenericArray<TBigInteger>.Create(LP, LQ);
 end;
 
 {$IFNDEF _FIXINSIGHT_}
 
-class function TDHParametersHelper.SelectGenerator(const p, q: TBigInteger;
-  const random: ISecureRandom): TBigInteger;
+class function TDHParametersHelper.SelectGenerator(const AP, AQ: TBigInteger;
+  const ARandom: ISecureRandom): TBigInteger;
 var
-  g, h, pMinusTwo: TBigInteger;
-  // CompareResOne, CompareResTwo: Boolean;
+  LG, LH, LPMinusTwo: TBigInteger;
 begin
-  pMinusTwo := p.Subtract(TBigInteger.Two);
-
-
-  // (see: Handbook of Applied Cryptography 4.80)
-  //
-  // repeat
-  // g := TBigIntegers.CreateRandomInRange(TBigInteger.Two, pMinusTwo, random);
-  // CompareResOne := g.ModPow(TBigInteger.Two, p).Equals(TBigInteger.One);
-  // CompareResTwo := g.ModPow(q, p).Equals(TBigInteger.One);
-  // until ((not CompareResOne) and (not CompareResTwo));
-
-  // RFC 2631 2.2.1.2 (and see: Handbook of Applied Cryptography 4.81)
+  LPMinusTwo := AP.Subtract(TBigInteger.Two);
 
   repeat
-    h := TBigIntegers.CreateRandomInRange(TBigInteger.Two, pMinusTwo, random);
-    g := h.ModPow(TBigInteger.Two, p);
-  until ((not g.Equals(TBigInteger.One)));
+    LH := TBigIntegers.CreateRandomInRange(TBigInteger.Two, LPMinusTwo, ARandom);
+    LG := LH.ModPow(TBigInteger.Two, AP);
+  until not LG.Equals(TBigInteger.One);
 
-  result := g;
+  Result := LG;
 end;
 {$ENDIF}
 

+ 678 - 0
CryptoLib/src/Crypto/Generators/ClpDsaGenerators.pas

@@ -0,0 +1,678 @@
+{ *********************************************************************************** }
+{ *                              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 ClpDsaGenerators;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  Math,
+  SysUtils,
+  HlpSHA1,
+  ClpIDigest,
+  ClpISecureRandom,
+  ClpDsaParameters,
+  ClpIDsaParameters,
+  ClpIDsaGenerators,
+  ClpEncoders,
+  ClpDigestUtilities,
+  ClpBigInteger,
+  ClpBigIntegers,
+  ClpBitOperations,
+  ClpECCompUtilities,
+  ClpAsymmetricCipherKeyPair,
+  ClpIAsymmetricCipherKeyPair,
+  ClpIKeyGenerationParameters,
+  ClpIAsymmetricCipherKeyPairGenerator,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SParametersCannotBeNil = '"parameters" Cannot Be Nil';
+  SInvalidLValue =
+    'L Values Must be Between 1024 and 3072 and a Multiple of 1024';
+  SInvalidNValueForSpecifiedL = 'N Must be " %d " for L = " %d "';
+  SInvalidNValueForSpecifiedL_Two = 'N Must be " %d " or " %d " for L = " %d "';
+  SDigestOutputSizeTooSmallForN =
+    'Digest Output Size Too Small for Value of N Which is " %d "';
+  SUnsupportedDigest =
+    'Can Only Use SHA-1 For Generating FIPS 186-2 Parameters';
+  SInvalidDsaKeyStrength =
+    'Size Must Be From %d - %d and a multiple of %d, "%d"';
+
+type
+  TDsaKeyPairGenerator = class sealed(TInterfacedObject,
+    IAsymmetricCipherKeyPairGenerator, IDsaKeyPairGenerator)
+  strict private
+    FParam: IDsaKeyGenerationParameters;
+    class function GeneratePrivateKey(const AQ: TBigInteger;
+      const ARandom: ISecureRandom): TBigInteger; static;
+    class function CalculatePublicKey(const AP, AG, AX: TBigInteger): TBigInteger; static; inline;
+  public
+    procedure Init(const AParameters: IKeyGenerationParameters);
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+  end;
+
+  TDsaParametersGenerator = class(TInterfacedObject, IDsaParametersGenerator)
+
+  strict private
+    FDigest: IDigest;
+    FL, FN, FCertainty, FIterations, FUsageIndex: Int32;
+    FRandom: ISecureRandom;
+    FUse186_3: Boolean;
+
+    function IsProbablePrime(const AX: TBigInteger): Boolean; inline;
+
+    function GenerateParameters_FIPS186_2(): IDsaParameters;
+
+    /// <summary>
+    /// generate suitable parameters for DSA, in line with <i>FIPS 186-3 A.1
+    /// Generation of the FFC Primes p and q</i>
+    /// </summary>
+    function GenerateParameters_FIPS186_3(): IDsaParameters;
+
+    class function IsValidDsaStrength(AStrength: Int32): Boolean; static; inline;
+
+    class function GetDefaultN(AL: Int32): Int32; static; inline;
+    class function GetMinimumIterations(AL: Int32): Int32; static; inline;
+    class procedure Hash(const ADigest: IDigest;
+      const AInput, AOutput: TCryptoLibByteArray; AOutputPos: Int32);
+      static; inline;
+
+    class procedure Inc(const ABuf: TCryptoLibByteArray); static; inline;
+
+    class function CalculateGenerator_FIPS186_2(const AP, AQ: TBigInteger;
+      const ARandom: ISecureRandom): TBigInteger; static; inline;
+
+    class function CalculateGenerator_FIPS186_3_Unverifiable(const AP,
+      AQ: TBigInteger; const ARandom: ISecureRandom): TBigInteger; static; inline;
+
+    class function CalculateGenerator_FIPS186_3_Verifiable(const ADigest: IDigest;
+      const AP, AQ: TBigInteger; const ASeed: TCryptoLibByteArray; AIndex: Int32)
+      : TBigInteger; static; inline;
+
+  public
+    constructor Create(); overload;
+    constructor Create(const ADigest: IDigest); overload;
+
+    /// <summary>
+    /// initialise the key generator.
+    /// </summary>
+    /// <param name="size">
+    /// size of the key (range 2^512 -&amp;gt; 2^1024 - 64 bit increments)
+    /// </param>
+    /// <param name="certainty">
+    /// measure of robustness of prime (for FIPS 186-2 compliance this should
+    /// be at least 80).
+    /// </param>
+    /// <param name="random">
+    /// random byte source.
+    /// </param>
+    procedure Init(ASize, ACertainty: Int32;
+      const ARandom: ISecureRandom); overload;
+
+    /// <summary>
+    /// initialise the key generator.
+    /// </summary>
+    /// <param name="size">
+    /// size of the key (range 2^512 -&amp;gt; 2^1024 - 64 bit increments)
+    /// </param>
+    /// <param name="certainty">
+    /// measure of robustness of prime (for FIPS 186-2 compliance this should
+    /// be at least 80).
+    /// </param>
+    /// <param name="iterations">
+    /// iterations
+    /// </param>
+    /// <param name="random">
+    /// random byte source.
+    /// </param>
+    procedure Init(ASize, ACertainty, AIterations: Int32;
+      const ARandom: ISecureRandom); overload;
+
+    /// <summary>
+    /// <para>
+    /// Initialise the key generator for DSA 2.
+    /// </para>
+    /// <para>
+    /// Use this init method if you need to generate parameters for DSA 2
+    /// keys.
+    /// </para>
+    /// </summary>
+    /// <param name="params">
+    /// DSA 2 key generation parameters.
+    /// </param>
+    procedure Init(const AParams: IDsaParameterGenerationParameters); overload;
+
+    /// <summary>
+    /// <para>
+    /// which generates the p and g values from the given parameters,
+    /// returning the DSAParameters object.
+    /// </para>
+    /// <para>
+    /// Note: can take a while...
+    /// </para>
+    /// </summary>
+    /// <returns>
+    /// a generated DSA parameters object.
+    /// </returns>
+    function GenerateParameters(): IDsaParameters; virtual;
+
+  end;
+
+implementation
+
+{ TDsaKeyPairGenerator }
+
+class function TDsaKeyPairGenerator.CalculatePublicKey(const AP, AG, AX: TBigInteger): TBigInteger;
+begin
+  Result := AG.ModPow(AX, AP);
+end;
+
+function TDsaKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
+var
+  LDsaParams: IDsaParameters;
+  LX, LY: TBigInteger;
+begin
+  LDsaParams := FParam.Parameters;
+  LX := GeneratePrivateKey(LDsaParams.Q, FParam.Random);
+  LY := CalculatePublicKey(LDsaParams.P, LDsaParams.G, LX);
+  Result := TAsymmetricCipherKeyPair.Create(TDsaPublicKeyParameters.Create(LY,
+    LDsaParams) as IDsaPublicKeyParameters, TDsaPrivateKeyParameters.Create(LX,
+    LDsaParams) as IDsaPrivateKeyParameters);
+end;
+
+class function TDsaKeyPairGenerator.GeneratePrivateKey(const AQ: TBigInteger;
+  const ARandom: ISecureRandom): TBigInteger;
+var
+  LMinWeight: Int32;
+  LX, LOne: TBigInteger;
+begin
+  LOne := TBigInteger.One;
+  Result := TBigInteger.GetDefault;
+  LMinWeight := TBitOperations.Asr32(AQ.BitLength, 2);
+  while True do
+  begin
+    LX := TBigIntegers.CreateRandomInRange(LOne, AQ.Subtract(LOne), ARandom);
+    if TWNafUtilities.GetNafWeight(LX) >= LMinWeight then
+    begin
+      Result := LX;
+      Exit;
+    end;
+  end;
+end;
+
+procedure TDsaKeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
+begin
+  if AParameters = nil then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+  if not Supports(AParameters, IDsaKeyGenerationParameters, FParam) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParametersCannotBeNil);
+end;
+
+{ TDsaParametersGenerator }
+
+function TDsaParametersGenerator.IsProbablePrime(const AX: TBigInteger): Boolean;
+begin
+  Result := AX.IsProbablePrime(FCertainty);
+end;
+
+class function TDsaParametersGenerator.IsValidDsaStrength
+  (AStrength: Int32): Boolean;
+begin
+  // result := (AStrength >= 512) and (AStrength <= 1024) and ((AStrength mod 64) = 0);
+  Result := (AStrength >= 512) and (AStrength <= 1024) and
+    ((AStrength and 63) = 0);
+end;
+
+class function TDsaParametersGenerator.GetDefaultN(AL: Int32): Int32;
+begin
+  if AL > 1024 then
+  begin
+    Result := 256
+  end
+  else
+  begin
+    Result := 160;
+  end;
+end;
+
+class function TDsaParametersGenerator.GetMinimumIterations(AL: Int32): Int32;
+begin
+  // Values based on FIPS 186-4 C.3 Table C.1
+  if AL <= 1024 then
+  begin
+    Result := 40;
+  end
+  else
+  begin
+    Result := (48 + 8 * ((AL - 1) div 1024))
+  end;
+end;
+
+class procedure TDsaParametersGenerator.Hash(const ADigest: IDigest;
+  const AInput, AOutput: TCryptoLibByteArray; AOutputPos: Int32);
+begin
+  ADigest.BlockUpdate(AInput, 0, System.Length(AInput));
+  ADigest.DoFinal(AOutput, AOutputPos);
+end;
+
+class procedure TDsaParametersGenerator.Inc(const ABuf: TCryptoLibByteArray);
+var
+  LI: Int32;
+  LB: Byte;
+begin
+  LI := System.Length(ABuf) - 1;
+  while LI >= 0 do
+  begin
+    LB := Byte((ABuf[LI] + 1) and $FF);
+    ABuf[LI] := LB;
+
+    if (LB <> 0) then
+    begin
+      Break;
+    end;
+    System.Dec(LI);
+  end;
+end;
+
+constructor TDsaParametersGenerator.Create;
+begin
+  Create(TDigestUtilities.GetDigest('SHA-1'));
+end;
+
+class function TDsaParametersGenerator.CalculateGenerator_FIPS186_2(const AP,
+  AQ: TBigInteger; const ARandom: ISecureRandom): TBigInteger;
+var
+  LE, LPSub2, LH, LG: TBigInteger;
+begin
+  Result := TBigInteger.GetDefault;
+  LE := AP.Subtract(TBigInteger.One).Divide(AQ);
+  LPSub2 := AP.Subtract(TBigInteger.Two);
+
+  while True do
+  begin
+    LH := TBigIntegers.CreateRandomInRange(TBigInteger.Two, LPSub2, ARandom);
+    LG := LH.ModPow(LE, AP);
+    if (LG.BitLength > 1) then
+    begin
+      Result := LG;
+      Exit;
+    end;
+  end;
+end;
+
+class function TDsaParametersGenerator.CalculateGenerator_FIPS186_3_Unverifiable
+  (const AP, AQ: TBigInteger; const ARandom: ISecureRandom): TBigInteger;
+begin
+  Result := CalculateGenerator_FIPS186_2(AP, AQ, ARandom);
+end;
+
+class function TDsaParametersGenerator.CalculateGenerator_FIPS186_3_Verifiable
+  (const ADigest: IDigest; const AP, AQ: TBigInteger; const ASeed: TCryptoLibByteArray;
+  AIndex: Int32): TBigInteger;
+var
+  LE, LW, LG: TBigInteger;
+  LGgen, LU, LSmallW: TCryptoLibByteArray;
+  LCount: Int32;
+begin
+  // A.2.3 Verifiable Canonical Generation of the Generator g
+  LE := AP.Subtract(TBigInteger.One).Divide(AQ);
+  LGgen := THex.Decode('6767656E');
+
+  // 7. U = domain_parameter_seed || "ggen" || index || count.
+  System.SetLength(LU, System.Length(ASeed) + System.Length(LGgen) + 1 + 2);
+  System.Move(ASeed[0], LU[0], System.Length(ASeed) * System.SizeOf(Byte));
+  System.Move(LGgen[0], LU[System.Length(ASeed)], System.Length(LGgen) *
+    System.SizeOf(Byte));
+  LU[System.Length(LU) - 3] := Byte(AIndex);
+
+  System.SetLength(LSmallW, ADigest.GetDigestSize());
+
+  LCount := 1;
+  while LCount < (1 shl 16) do
+  begin
+    Inc(LU);
+    Hash(ADigest, LU, LSmallW, 0);
+    LW := TBigInteger.Create(1, LSmallW);
+    LG := LW.ModPow(LE, AP);
+    if (LG.CompareTo(TBigInteger.Two) >= 0) then
+    begin
+      Result := LG;
+      Exit;
+    end;
+    System.Inc(LCount);
+  end;
+
+  Result := TBigInteger.GetDefault;
+end;
+
+function TDsaParametersGenerator.GenerateParameters_FIPS186_2: IDsaParameters;
+var
+  LSeed, LPart1, LPart2, LU, LW, LOffset: TCryptoLibByteArray;
+  LN, LI, LCounter, LK, LRemaining: Int32;
+  LQ, LX, LC, LP, LG: TBigInteger;
+begin
+  Result := nil;
+  System.SetLength(LSeed, 20);
+  System.SetLength(LPart1, 20);
+  System.SetLength(LPart2, 20);
+  System.SetLength(LU, 20);
+  LN := (FL - 1) div 160;
+  System.SetLength(LW, FL div 8);
+
+  if (not {$IFDEF FPC} (Supports(FDigest.GetUnderlyingIHash, TSHA1))
+{$ELSE} (FDigest.GetUnderlyingIHash is TSHA1) {$ENDIF FPC}) then
+  begin
+    raise EInvalidParameterCryptoLibException.CreateRes(@SUnsupportedDigest);
+  end;
+
+  while True do
+  begin
+    FRandom.NextBytes(LSeed);
+
+    Hash(FDigest, LSeed, LPart1, 0);
+    System.Move(LSeed[0], LPart2[0], System.Length(LSeed) * System.SizeOf(Byte));
+    Inc(LPart2);
+    Hash(FDigest, LPart2, LPart2, 0);
+
+    LI := 0;
+    while LI <> System.Length(LU) do
+    begin
+      LU[LI] := Byte(LPart1[LI] xor LPart2[LI]);
+      System.Inc(LI);
+    end;
+
+    LU[0] := LU[0] or Byte($80);
+    LU[19] := LU[19] or Byte($01);
+
+    LQ := TBigInteger.Create(1, LU);
+
+    if (not IsProbablePrime(LQ)) then
+    begin
+      continue;
+    end;
+
+    LOffset := System.Copy(LSeed);
+    Inc(LOffset);
+    LCounter := 0;
+    while LCounter < 4096 do
+    begin
+
+      LK := 1;
+      while LK <= LN do
+      begin
+        Inc(LOffset);
+        Hash(FDigest, LOffset, LW, System.Length(LW) - (LK * System.Length(LPart1)));
+        System.Inc(LK);
+      end;
+
+      LRemaining := System.Length(LW) - (LN * System.Length(LPart1));
+      Inc(LOffset);
+      Hash(FDigest, LOffset, LPart1, 0);
+      System.Move(LPart1[System.Length(LPart1) - LRemaining], LW[0], LRemaining);
+
+      LW[0] := LW[0] or Byte($80);
+
+      LX := TBigInteger.Create(1, LW);
+
+      LC := LX.&Mod(LQ.ShiftLeft(1));
+
+      LP := LX.Subtract(LC.Subtract(TBigInteger.One));
+
+      if (LP.BitLength <> FL) then
+      begin
+        System.Inc(LCounter);
+        continue;
+      end;
+
+      if (IsProbablePrime(LP)) then
+      begin
+        LG := CalculateGenerator_FIPS186_2(LP, LQ, FRandom);
+
+        Result := TDsaParameters.Create(LP, LQ, LG,
+          TDsaValidationParameters.Create(LSeed, LCounter)
+          as IDsaValidationParameters);
+        Exit;
+      end;
+
+      System.Inc(LCounter);
+    end;
+  end;
+end;
+
+function TDsaParametersGenerator.GenerateParameters_FIPS186_3: IDsaParameters;
+var
+  LDigest: IDigest;
+  LOutLen, LSeedLen, LN, LCounterLimit, LCounter, LJ, LRemaining: Int32;
+  LSeed, LW, LOutput, LOffset: TCryptoLibByteArray;
+  LU, LQ, LX, LC, LP, LG: TBigInteger;
+begin
+  Result := nil;
+  // A.1.1.2 Generation of the Probable Primes p and q Using an Approved Hash Function
+  // TODO FIXME This should be configurable (digest size in bits must be >= N)
+  LDigest := FDigest;
+  LOutLen := LDigest.GetDigestSize() * 8;
+
+  // 1. Check that the (L, N) pair is in the list of acceptable (L, N pairs) (see Section 4.2). If
+  // the pair is not in the list, then return INVALID.
+  // Note: checked at initialisation
+
+  // 2. If (seedlen < N), then return INVALID.
+  // TODO FIXME This should be configurable (must be >= N)
+  LSeedLen := FN;
+  System.SetLength(LSeed, LSeedLen div 8);
+
+  // 3. n = ceiling(L / outlen) - 1.
+  LN := (FL - 1) div LOutLen;
+
+  // 4. b = L - 1 - (n * outlen).
+  // b := (FL - 1) mod outlen;
+
+  System.SetLength(LW, FL div 8);
+
+  System.SetLength(LOutput, LDigest.GetDigestSize());
+
+  while True do
+  begin
+    // 5. Get an arbitrary sequence of seedlen bits as the domain_parameter_seed.
+    FRandom.NextBytes(LSeed);
+
+    // 6. U = Hash (domain_parameter_seed) mod 2^(N–1).
+    Hash(LDigest, LSeed, LOutput, 0);
+
+    LU := TBigInteger.Create(1, LOutput).&Mod(TBigInteger.One.ShiftLeft(FN - 1));
+
+    // 7. q = 2^(N–1) + U + 1 – ( U mod 2).
+    LQ := LU.SetBit(0).SetBit(FN - 1);
+
+    // 8. Test whether or not q is prime as specified in Appendix C.3.
+    if (not IsProbablePrime(LQ)) then
+    begin
+      // 9. If q is not a prime, then go to step 5.
+      continue;
+    end;
+
+    // 10. offset = 1.
+    // Note: 'offset' value managed incrementally
+    LOffset := System.Copy(LSeed);
+
+    // 11. For counter = 0 to (4L – 1) do
+    LCounterLimit := 4 * FL;
+    LCounter := 0;
+    while LCounter < LCounterLimit do
+    begin
+      // 11.1 For j = 0 to n do
+      // Vj = Hash ((domain_parameter_seed + offset + j) mod 2^seedlen).
+      // 11.2 W = V0 + (V1 * 2^outlen) + ... + (V^(n–1) * 2^((n–1) * outlen)) + ((Vn mod 2^b) * 2^(n * outlen)).
+
+      LJ := 1;
+      while LJ <= LN do
+      begin
+        Inc(LOffset);
+        Hash(LDigest, LOffset, LW, System.Length(LW) - (LJ * System.Length(LOutput)));
+        System.Inc(LJ);
+      end;
+
+      LRemaining := System.Length(LW) - (LN * System.Length(LOutput));
+      Inc(LOffset);
+      Hash(LDigest, LOffset, LOutput, 0);
+      System.Move(LOutput[System.Length(LOutput) - LRemaining], LW[0], LRemaining);
+
+      // 11.3 X = W + 2^(L–1). Comment: 0 ≤ W < 2^(L–1); hence, 2^(L–1) ≤ X < 2^L.
+      LW[0] := LW[0] or Byte($80);
+
+      LX := TBigInteger.Create(1, LW);
+
+      // 11.4 c = X mod 2q.
+      LC := LX.&Mod(LQ.ShiftLeft(1));
+
+      // 11.5 p = X - (c - 1). Comment: p ≡ 1 (mod 2q).
+      LP := LX.Subtract(LC.Subtract(TBigInteger.One));
+
+      // 11.6 If (p < 2^(L-1)), then go to step 11.9
+      if (LP.BitLength <> FL) then
+      begin
+        System.Inc(LCounter);
+        continue;
+      end;
+
+      // 11.7 Test whether or not p is prime as specified in Appendix C.3.
+      if (IsProbablePrime(LP)) then
+      begin
+        // 11.8 If p is determined to be prime, then return VALID and the values of p, q and
+        // (optionally) the values of domain_parameter_seed and counter.
+        if (FUsageIndex >= 0) then
+        begin
+          LG := CalculateGenerator_FIPS186_3_Verifiable(LDigest, LP, LQ, LSeed,
+            FUsageIndex);
+          if (LG.IsInitialized) then
+          begin
+            Result := TDsaParameters.Create(LP, LQ, LG,
+              TDsaValidationParameters.Create(LSeed, LCounter, FUsageIndex)
+              as IDsaValidationParameters);
+            Exit;
+          end;
+        end;
+
+        LG := CalculateGenerator_FIPS186_3_Unverifiable(LP, LQ, FRandom);
+
+        Result := TDsaParameters.Create(LP, LQ, LG,
+          TDsaValidationParameters.Create(LSeed, LCounter)
+          as IDsaValidationParameters);
+        Exit;
+      end;
+
+      // 11.9 offset = offset + n + 1.      Comment: Increment offset; then, as part of
+      // the loop in step 11, increment counter; if
+      // counter < 4L, repeat steps 11.1 through 11.8.
+      // Note: 'offset' value already incremented in inner loop
+      System.Inc(LCounter);
+    end;
+    // 12. Go to step 5.
+  end;
+
+end;
+
+function TDsaParametersGenerator.GenerateParameters: IDsaParameters;
+begin
+  if FUse186_3 then
+  begin
+    Result := GenerateParameters_FIPS186_3()
+  end
+  else
+  begin
+    Result := GenerateParameters_FIPS186_2();
+  end;
+end;
+
+constructor TDsaParametersGenerator.Create(const ADigest: IDigest);
+begin
+  inherited Create();
+  FDigest := ADigest;
+end;
+
+procedure TDsaParametersGenerator.Init(ASize, ACertainty: Int32;
+  const ARandom: ISecureRandom);
+begin
+  Init(ASize, ACertainty, Max(GetMinimumIterations(ASize),
+    (ACertainty + 1) div 2), ARandom);
+end;
+
+procedure TDsaParametersGenerator.Init(ASize, ACertainty, AIterations: Int32;
+  const ARandom: ISecureRandom);
+begin
+  if (not IsValidDsaStrength(ASize)) then
+  begin
+    raise EArgumentCryptoLibException.CreateResFmt(@SInvalidDsaKeyStrength,
+      [512, 1024, 64, ASize]);
+  end;
+  FL := ASize;
+  FN := GetDefaultN(ASize);
+  FCertainty := ACertainty;
+  FIterations := AIterations;
+  FRandom := ARandom;
+  FUse186_3 := False;
+  FUsageIndex := -1;
+end;
+
+procedure TDsaParametersGenerator.Init(const AParams
+  : IDsaParameterGenerationParameters);
+var
+  LL, LN: Int32;
+begin
+  LL := AParams.L;
+  LN := AParams.N;
+
+  // if (((LL < 1024) or (LL > 3072)) or ((LL mod 1024) <> 0))
+  if (((LL < 1024) or (LL > 3072)) or ((LL and 1023) <> 0)) then
+  begin
+    raise EInvalidParameterCryptoLibException.CreateRes(@SInvalidLValue);
+  end
+  else if ((LL = 1024) and (LN <> 160)) then
+  begin
+    raise EInvalidParameterCryptoLibException.CreateResFmt
+      (@SInvalidNValueForSpecifiedL, [160, 1024]);
+  end
+  else if ((LL = 2048) and ((LN <> 224) and (LN <> 256))) then
+  begin
+    raise EInvalidParameterCryptoLibException.CreateResFmt
+      (@SInvalidNValueForSpecifiedL_Two, [224, 256, 2048]);
+  end
+  else if ((LL = 3072) and (LN <> 256)) then
+  begin
+    raise EInvalidParameterCryptoLibException.CreateResFmt
+      (@SInvalidNValueForSpecifiedL, [256, 3072]);
+  end;
+
+  if ((FDigest.GetDigestSize * 8) < LN) then
+  begin
+    raise EInvalidParameterCryptoLibException.CreateResFmt
+      (@SDigestOutputSizeTooSmallForN, [LN]);
+  end;
+
+  FL := LL;
+  FN := LN;
+  FCertainty := AParams.Certainty;
+  FIterations := Max(GetMinimumIterations(LL), (FCertainty + 1) div 2);
+  FRandom := AParams.Random;
+  FUse186_3 := True;
+  FUsageIndex := AParams.UsageIndex;
+end;
+
+end.

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

@@ -1,142 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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,
-  ClpBitOperations,
-  ClpBigInteger,
-  ClpBigIntegers,
-  ClpECCompUtilities,
-  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
-
-  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;
-
-  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;
-
-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, One: TBigInteger;
-begin
-  One := TBigInteger.One;
-  result := TBigInteger.GetDefault;
-  // B.1.2 Key Pair Generation by Testing Candidates
-  minWeight := TBitOperations.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(One, q.Subtract(One), 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.

+ 0 - 619
CryptoLib/src/Crypto/Generators/ClpDsaParametersGenerator.pas

@@ -1,619 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDsaParametersGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  Math,
-  SysUtils,
-  HlpSHA1,
-  ClpIDigest,
-  ClpISecureRandom,
-  ClpDsaParameters,
-  ClpIDsaParameters,
-  ClpDsaValidationParameters,
-  ClpIDsaValidationParameters,
-  ClpIDsaParametersGenerator,
-  ClpIDsaParameterGenerationParameters,
-  ClpEncoders,
-  ClpDigestUtilities,
-  ClpBigInteger,
-  ClpBigIntegers,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SInvalidLValue =
-    'L Values Must be Between 1024 and 3072 and a Multiple of 1024';
-  SInvalidNValueForSpecifiedL = 'N Must be " %d " for L = " %d "';
-  SInvalidNValueForSpecifiedL_Two = 'N Must be " %d " or " %d " for L = " %d "';
-  SDigestOutputSizeTooSmallForN =
-    'Digest Output Size Too Small for Value of N Which is " %d "';
-  SUnsupportedDigest =
-    'Can Only Use SHA-1 For Generating FIPS 186-2 Parameters';
-  SInvalidDsaKeyStrength =
-    'Size Must Be From %d - %d and a multiple of %d, "%d"';
-
-type
-
-  /// <summary>
-  /// Generate suitable parameters for DSA, in line with FIPS 186-2, or FIPS
-  /// 186-3.
-  /// </summary>
-  TDsaParametersGenerator = class(TInterfacedObject, IDsaParametersGenerator)
-
-  strict private
-    Fdigest: IDigest;
-    FL, FN, Fcertainty, Fiterations, FusageIndex: Int32;
-    Frandom: ISecureRandom;
-    Fuse186_3: Boolean;
-
-    function IsProbablePrime(const x: TBigInteger): Boolean; inline;
-
-    function GenerateParameters_FIPS186_2(): IDsaParameters;
-
-    /// <summary>
-    /// generate suitable parameters for DSA, in line with <i>FIPS 186-3 A.1
-    /// Generation of the FFC Primes p and q</i>
-    /// </summary>
-    function GenerateParameters_FIPS186_3(): IDsaParameters;
-
-    class function IsValidDsaStrength(strength: Int32): Boolean; static; inline;
-
-    class function GetDefaultN(L: Int32): Int32; static; inline;
-    class function GetMinimumIterations(L: Int32): Int32; static; inline;
-    class procedure Hash(const d: IDigest;
-      const input, output: TCryptoLibByteArray; outputPos: Int32);
-      static; inline;
-
-    class procedure Inc(const buf: TCryptoLibByteArray); static; inline;
-
-    class function CalculateGenerator_FIPS186_2(const p, q: TBigInteger;
-      const r: ISecureRandom): TBigInteger; static; inline;
-
-    class function CalculateGenerator_FIPS186_3_Unverifiable(const p,
-      q: TBigInteger; const r: ISecureRandom): TBigInteger; static; inline;
-
-    class function CalculateGenerator_FIPS186_3_Verifiable(const d: IDigest;
-      const p, q: TBigInteger; const seed: TCryptoLibByteArray; index: Int32)
-      : TBigInteger; static; inline;
-
-  public
-    constructor Create(); overload;
-    constructor Create(const digest: IDigest); overload;
-
-    /// <summary>
-    /// initialise the key generator.
-    /// </summary>
-    /// <param name="size">
-    /// size of the key (range 2^512 -&amp;gt; 2^1024 - 64 bit increments)
-    /// </param>
-    /// <param name="certainty">
-    /// measure of robustness of prime (for FIPS 186-2 compliance this should
-    /// be at least 80).
-    /// </param>
-    /// <param name="random">
-    /// random byte source.
-    /// </param>
-    procedure Init(size, certainty: Int32;
-      const random: ISecureRandom); overload;
-
-    /// <summary>
-    /// initialise the key generator.
-    /// </summary>
-    /// <param name="size">
-    /// size of the key (range 2^512 -&amp;gt; 2^1024 - 64 bit increments)
-    /// </param>
-    /// <param name="certainty">
-    /// measure of robustness of prime (for FIPS 186-2 compliance this should
-    /// be at least 80).
-    /// </param>
-    /// <param name="iterations">
-    /// iterations
-    /// </param>
-    /// <param name="random">
-    /// random byte source.
-    /// </param>
-    procedure Init(size, certainty, iterations: Int32;
-      const random: ISecureRandom); overload;
-
-    /// <summary>
-    /// <para>
-    /// Initialise the key generator for DSA 2.
-    /// </para>
-    /// <para>
-    /// Use this init method if you need to generate parameters for DSA 2
-    /// keys.
-    /// </para>
-    /// </summary>
-    /// <param name="params">
-    /// DSA 2 key generation parameters.
-    /// </param>
-    procedure Init(const params: IDsaParameterGenerationParameters); overload;
-
-    /// <summary>
-    /// <para>
-    /// which generates the p and g values from the given parameters,
-    /// returning the DSAParameters object.
-    /// </para>
-    /// <para>
-    /// Note: can take a while...
-    /// </para>
-    /// </summary>
-    /// <returns>
-    /// a generated DSA parameters object.
-    /// </returns>
-    function GenerateParameters(): IDsaParameters; virtual;
-
-  end;
-
-implementation
-
-{ TDsaParametersGenerator }
-
-function TDsaParametersGenerator.IsProbablePrime(const x: TBigInteger): Boolean;
-begin
-  result := x.IsProbablePrime(Fcertainty);
-end;
-
-class function TDsaParametersGenerator.IsValidDsaStrength
-  (strength: Int32): Boolean;
-begin
-  // result := (strength >= 512) and (strength <= 1024) and ((strength mod 64) = 0);
-  result := (strength >= 512) and (strength <= 1024) and
-    ((strength and 63) = 0);
-end;
-
-class function TDsaParametersGenerator.GetDefaultN(L: Int32): Int32;
-begin
-  if L > 1024 then
-  begin
-    result := 256
-  end
-  else
-  begin
-    result := 160;
-  end;
-end;
-
-class function TDsaParametersGenerator.GetMinimumIterations(L: Int32): Int32;
-begin
-  // Values based on FIPS 186-4 C.3 Table C.1
-  if L <= 1024 then
-  begin
-    result := 40;
-  end
-  else
-  begin
-    result := (48 + 8 * ((L - 1) div 1024))
-  end;
-end;
-
-class procedure TDsaParametersGenerator.Hash(const d: IDigest;
-  const input, output: TCryptoLibByteArray; outputPos: Int32);
-begin
-  d.BlockUpdate(input, 0, System.Length(input));
-  d.DoFinal(output, outputPos);
-end;
-
-class procedure TDsaParametersGenerator.Inc(const buf: TCryptoLibByteArray);
-var
-  i: Int32;
-  b: Byte;
-begin
-  i := System.Length(buf) - 1;
-  while i >= 0 do
-  begin
-    b := Byte((buf[i] + 1) and $FF);
-    buf[i] := b;
-
-    if (b <> 0) then
-    begin
-      break;
-    end;
-    System.Dec(i);
-  end;
-end;
-
-constructor TDsaParametersGenerator.Create;
-begin
-  Create(TDigestUtilities.GetDigest('SHA-1'));
-end;
-
-class function TDsaParametersGenerator.CalculateGenerator_FIPS186_2(const p,
-  q: TBigInteger; const r: ISecureRandom): TBigInteger;
-var
-  e, pSub2, h, g: TBigInteger;
-begin
-  result := TBigInteger.GetDefault;
-  e := p.subtract(TBigInteger.One).Divide(q);
-  pSub2 := p.subtract(TBigInteger.Two);
-
-  while True do
-  begin
-    h := TBigIntegers.CreateRandomInRange(TBigInteger.Two, pSub2, r);
-    g := h.ModPow(e, p);
-    if (g.BitLength > 1) then
-    begin
-      result := g;
-      Exit;
-    end;
-  end;
-end;
-
-class function TDsaParametersGenerator.CalculateGenerator_FIPS186_3_Unverifiable
-  (const p, q: TBigInteger; const r: ISecureRandom): TBigInteger;
-begin
-  result := CalculateGenerator_FIPS186_2(p, q, r);
-end;
-
-class function TDsaParametersGenerator.CalculateGenerator_FIPS186_3_Verifiable
-  (const d: IDigest; const p, q: TBigInteger; const seed: TCryptoLibByteArray;
-  index: Int32): TBigInteger;
-var
-  e, W, g: TBigInteger;
-  ggen, U, smallw: TCryptoLibByteArray;
-  count: Int32;
-begin
-  // A.2.3 Verifiable Canonical Generation of the Generator g
-  e := p.subtract(TBigInteger.One).Divide(q);
-  ggen := THex.Decode('6767656E');
-
-  // 7. U = domain_parameter_seed || "ggen" || index || count.
-  System.SetLength(U, System.Length(seed) + System.Length(ggen) + 1 + 2);
-  System.Move(seed[0], U[0], System.Length(seed) * System.SizeOf(Byte));
-  System.Move(ggen[0], U[System.Length(seed)], System.Length(ggen) *
-    System.SizeOf(Byte));
-  U[System.Length(U) - 3] := Byte(index);
-
-  System.SetLength(smallw, d.GetDigestSize());
-
-  count := 1;
-  while count < (1 shl 16) do
-  begin
-    Inc(U);
-    Hash(d, U, smallw, 0);
-    W := TBigInteger.Create(1, smallw);
-    g := W.ModPow(e, p);
-    if (g.CompareTo(TBigInteger.Two) >= 0) then
-    begin
-      result := g;
-      Exit;
-    end;
-    System.Inc(count);
-  end;
-
-  result := TBigInteger.GetDefault;
-end;
-
-function TDsaParametersGenerator.GenerateParameters_FIPS186_2: IDsaParameters;
-var
-  seed, part1, part2, U, W, offset: TCryptoLibByteArray;
-  n, i, counter, k, remaining: Int32;
-  q, x, c, p, g: TBigInteger;
-begin
-  result := Nil;
-  System.SetLength(seed, 20);
-  System.SetLength(part1, 20);
-  System.SetLength(part2, 20);
-  System.SetLength(U, 20);
-  n := (FL - 1) div 160;
-  System.SetLength(W, FL div 8);
-
-  if (not {$IFDEF FPC} (Supports(Fdigest.GetUnderlyingIHash, TSHA1))
-{$ELSE} (Fdigest.GetUnderlyingIHash is TSHA1) {$ENDIF FPC}) then
-  begin
-    raise EInvalidParameterCryptoLibException.CreateRes(@SUnsupportedDigest);
-  end;
-
-  while True do
-  begin
-    Frandom.NextBytes(seed);
-
-    Hash(Fdigest, seed, part1, 0);
-    System.Move(seed[0], part2[0], System.Length(seed) * System.SizeOf(Byte));
-    Inc(part2);
-    Hash(Fdigest, part2, part2, 0);
-
-    i := 0;
-    while i <> System.Length(U) do
-    begin
-      U[i] := Byte(part1[i] xor part2[i]);
-      System.Inc(i);
-    end;
-
-    U[0] := U[0] or Byte($80);
-    U[19] := U[19] or Byte($01);
-
-    q := TBigInteger.Create(1, U);
-
-    if (not IsProbablePrime(q)) then
-    begin
-      continue;
-    end;
-
-    offset := System.Copy(seed);
-    Inc(offset);
-    counter := 0;
-    while counter < 4096 do
-    begin
-
-      k := 1;
-      while k <= n do
-      begin
-        Inc(offset);
-        Hash(Fdigest, offset, W, System.Length(W) - (k * System.Length(part1)));
-        System.Inc(k);
-      end;
-
-      remaining := System.Length(W) - (n * System.Length(part1));
-      Inc(offset);
-      Hash(Fdigest, offset, part1, 0);
-      System.Move(part1[System.Length(part1) - remaining], W[0], remaining);
-
-      W[0] := W[0] or Byte($80);
-
-      x := TBigInteger.Create(1, W);
-
-      c := x.&Mod(q.ShiftLeft(1));
-
-      p := x.subtract(c.subtract(TBigInteger.One));
-
-      if (p.BitLength <> FL) then
-      begin
-        System.Inc(counter);
-        continue;
-      end;
-
-      if (IsProbablePrime(p)) then
-      begin
-        g := CalculateGenerator_FIPS186_2(p, q, Frandom);
-
-        result := TDsaParameters.Create(p, q, g,
-          TDsaValidationParameters.Create(seed, counter)
-          as IDsaValidationParameters);
-        Exit;
-      end;
-
-      System.Inc(counter);
-    end;
-  end;
-end;
-
-function TDsaParametersGenerator.GenerateParameters_FIPS186_3: IDsaParameters;
-var
-  d: IDigest;
-  outlen, seedlen, n, { b, } counterLimit, counter, j, remaining: Int32;
-  seed, W, output, offset: TCryptoLibByteArray;
-  U, q, x, c, p, g: TBigInteger;
-begin
-  result := Nil;
-  // A.1.1.2 Generation of the Probable Primes p and q Using an Approved Hash Function
-  // TODO FIXME This should be configurable (digest size in bits must be >= N)
-  d := Fdigest;
-  outlen := d.GetDigestSize() * 8;
-
-  // 1. Check that the (L, N) pair is in the list of acceptable (L, N pairs) (see Section 4.2). If
-  // the pair is not in the list, then return INVALID.
-  // Note: checked at initialisation
-
-  // 2. If (seedlen < N), then return INVALID.
-  // TODO FIXME This should be configurable (must be >= N)
-  seedlen := FN;
-  System.SetLength(seed, seedlen div 8);
-
-  // 3. n = ceiling(L / outlen) - 1.
-  n := (FL - 1) div outlen;
-
-  // 4. b = L - 1 - (n * outlen).
-  // b := (FL - 1) mod outlen;
-
-  System.SetLength(W, FL div 8);
-
-  System.SetLength(output, d.GetDigestSize());
-
-  while True do
-  begin
-    // 5. Get an arbitrary sequence of seedlen bits as the domain_parameter_seed.
-    Frandom.NextBytes(seed);
-
-    // 6. U = Hash (domain_parameter_seed) mod 2^(N–1).
-    Hash(d, seed, output, 0);
-
-    U := TBigInteger.Create(1, output).&Mod(TBigInteger.One.ShiftLeft(FN - 1));
-
-    // 7. q = 2^(N–1) + U + 1 – ( U mod 2).
-    q := U.SetBit(0).SetBit(FN - 1);
-
-    // 8. Test whether or not q is prime as specified in Appendix C.3.
-    if (not IsProbablePrime(q)) then
-    begin
-      // 9. If q is not a prime, then go to step 5.
-      continue;
-    end;
-
-    // 10. offset = 1.
-    // Note: 'offset' value managed incrementally
-    offset := System.Copy(seed);
-
-    // 11. For counter = 0 to (4L – 1) do
-    counterLimit := 4 * FL;
-    counter := 0;
-    while counter < counterLimit do
-    begin
-      // 11.1 For j = 0 to n do
-      // Vj = Hash ((domain_parameter_seed + offset + j) mod 2^seedlen).
-      // 11.2 W = V0 + (V1 * 2^outlen) + ... + (V^(n–1) * 2^((n–1) * outlen)) + ((Vn mod 2^b) * 2^(n * outlen)).
-
-      j := 1;
-      while j <= n do
-      begin
-        Inc(offset);
-        Hash(d, offset, W, System.Length(W) - (j * System.Length(output)));
-        System.Inc(j);
-      end;
-
-      remaining := System.Length(W) - (n * System.Length(output));
-      Inc(offset);
-      Hash(d, offset, output, 0);
-      System.Move(output[System.Length(output) - remaining], W[0], remaining);
-
-      // 11.3 X = W + 2^(L–1). Comment: 0 ≤ W < 2^(L–1); hence, 2^(L–1) ≤ X < 2^L.
-      W[0] := W[0] or Byte($80);
-
-      x := TBigInteger.Create(1, W);
-
-      // 11.4 c = X mod 2q.
-      c := x.&Mod(q.ShiftLeft(1));
-
-      // 11.5 p = X - (c - 1). Comment: p ≡ 1 (mod 2q).
-      p := x.subtract(c.subtract(TBigInteger.One));
-
-      // 11.6 If (p < 2^(L-1)), then go to step 11.9
-      if (p.BitLength <> FL) then
-      begin
-        System.Inc(counter);
-        continue;
-      end;
-
-      // 11.7 Test whether or not p is prime as specified in Appendix C.3.
-      if (IsProbablePrime(p)) then
-      begin
-        // 11.8 If p is determined to be prime, then return VALID and the values of p, q and
-        // (optionally) the values of domain_parameter_seed and counter.
-        if (FusageIndex >= 0) then
-        begin
-          g := CalculateGenerator_FIPS186_3_Verifiable(d, p, q, seed,
-            FusageIndex);
-          if (g.IsInitialized) then
-          begin
-            result := TDsaParameters.Create(p, q, g,
-              TDsaValidationParameters.Create(seed, counter, FusageIndex)
-              as IDsaValidationParameters);
-            Exit;
-          end;
-        end;
-
-        g := CalculateGenerator_FIPS186_3_Unverifiable(p, q, Frandom);
-
-        result := TDsaParameters.Create(p, q, g,
-          TDsaValidationParameters.Create(seed, counter)
-          as IDsaValidationParameters);
-        Exit;
-      end;
-
-      // 11.9 offset = offset + n + 1.      Comment: Increment offset; then, as part of
-      // the loop in step 11, increment counter; if
-      // counter < 4L, repeat steps 11.1 through 11.8.
-      // Note: 'offset' value already incremented in inner loop
-      System.Inc(counter);
-    end;
-    // 12. Go to step 5.
-  end;
-
-end;
-
-function TDsaParametersGenerator.GenerateParameters: IDsaParameters;
-begin
-  if Fuse186_3 then
-  begin
-    result := GenerateParameters_FIPS186_3()
-  end
-  else
-  begin
-    result := GenerateParameters_FIPS186_2();
-  end;
-end;
-
-constructor TDsaParametersGenerator.Create(const digest: IDigest);
-begin
-  Inherited Create();
-  Fdigest := digest;
-end;
-
-procedure TDsaParametersGenerator.Init(size, certainty: Int32;
-  const random: ISecureRandom);
-begin
-  Init(size, certainty, Max(GetMinimumIterations(size),
-    (certainty + 1) div 2), random);
-end;
-
-procedure TDsaParametersGenerator.Init(size, certainty, iterations: Int32;
-  const random: ISecureRandom);
-begin
-  if (not IsValidDsaStrength(size)) then
-  begin
-    raise EArgumentCryptoLibException.CreateResFmt(@SInvalidDsaKeyStrength,
-      [512, 1024, 64, size]);
-  end;
-  FL := size;
-  FN := GetDefaultN(size);
-  Fcertainty := certainty;
-  Fiterations := iterations;
-  Frandom := random;
-  Fuse186_3 := false;
-  FusageIndex := -1;
-end;
-
-procedure TDsaParametersGenerator.Init(const params
-  : IDsaParameterGenerationParameters);
-var
-  L, n: Int32;
-begin
-  L := params.L;
-  n := params.n;
-
-  // if (((L < 1024) or (L > 3072)) or ((L mod 1024) <> 0))
-  if (((L < 1024) or (L > 3072)) or ((L and 1023) <> 0)) then
-  begin
-    raise EInvalidParameterCryptoLibException.CreateRes(@SInvalidLValue);
-  end
-  else if ((L = 1024) and (n <> 160)) then
-  begin
-    raise EInvalidParameterCryptoLibException.CreateResFmt
-      (@SInvalidNValueForSpecifiedL, [160, 1024]);
-  end
-  else if ((L = 2048) and ((n <> 224) and (n <> 256))) then
-  begin
-    raise EInvalidParameterCryptoLibException.CreateResFmt
-      (@SInvalidNValueForSpecifiedL_Two, [224, 256, 2048]);
-  end
-  else if ((L = 3072) and (n <> 256)) then
-  begin
-    raise EInvalidParameterCryptoLibException.CreateResFmt
-      (@SInvalidNValueForSpecifiedL, [256, 3072]);
-  end;
-
-  if ((Fdigest.GetDigestSize * 8) < n) then
-  begin
-    raise EInvalidParameterCryptoLibException.CreateResFmt
-      (@SDigestOutputSizeTooSmallForN, [n]);
-  end;
-
-  FL := L;
-  FN := n;
-  Fcertainty := params.certainty;
-  Fiterations := Max(GetMinimumIterations(L), (Fcertainty + 1) div 2);
-  Frandom := params.Random;
-  Fuse186_3 := True;
-  FusageIndex := params.UsageIndex;
-end;
-
-end.

+ 161 - 0
CryptoLib/src/Crypto/Generators/ClpECGenerators.pas

@@ -0,0 +1,161 @@
+{ *********************************************************************************** }
+{ *                              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 ClpECGenerators;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpBigInteger,
+  ClpBitOperations,
+  ClpCryptoLibTypes,
+  ClpECParameters,
+  ClpECCompUtilities,
+  ClpIECGenerators,
+  ClpIAsn1Objects,
+  ClpIKeyGenerationParameters,
+  ClpIECParameters,
+  ClpIECC,
+  ClpMultipliers,
+  ClpIMultipliers,
+  ClpSecObjectIdentifiers,
+  ClpCustomNamedCurves,
+  ClpECNamedCurveTable,
+  ClpX9ObjectIdentifiers,
+  ClpIX9ECAsn1Objects,
+  ClpAsymmetricCipherKeyPair,
+  ClpIAsymmetricCipherKeyPair,
+  ClpSecureRandom,
+  ClpISecureRandom,
+  ClpIAsymmetricCipherKeyPairGenerator;
+
+resourcestring
+  SAlgorithmNil = 'Algorithm Cannot be Empty';
+  SInvalidKeySize = 'Unknown Key Size "%d"';
+
+type
+  TECKeyPairGenerator = class sealed(TInterfacedObject, IECKeyPairGenerator,
+    IAsymmetricCipherKeyPairGenerator)
+  strict private
+    FAlgorithm: String;
+    FParameters: IECDomainParameters;
+    FRandom: ISecureRandom;
+  strict protected
+    function CreateBasePointMultiplier(): IECMultiplier; virtual;
+  public
+    constructor Create(); overload;
+    constructor Create(const AAlgorithm: String); overload;
+    procedure Init(const AParameters: IKeyGenerationParameters);
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+    class function FindECCurveByOid(const AOid: IDerObjectIdentifier): IX9ECParameters; static;
+    class function GetCorrespondingPublicKey(const APrivKey: IECPrivateKeyParameters): IECPublicKeyParameters; static;
+  end;
+
+implementation
+
+constructor TECKeyPairGenerator.Create;
+begin
+  Create('EC');
+end;
+
+constructor TECKeyPairGenerator.Create(const AAlgorithm: String);
+begin
+  if AAlgorithm = '' then
+    raise EArgumentNilCryptoLibException.CreateRes(@SAlgorithmNil);
+  FAlgorithm := TECKeyParameters.VerifyAlgorithmName(AAlgorithm);
+end;
+
+function TECKeyPairGenerator.CreateBasePointMultiplier: IECMultiplier;
+begin
+  Result := TFixedPointCombMultiplier.Create();
+end;
+
+class function TECKeyPairGenerator.FindECCurveByOid(const AOid: IDerObjectIdentifier): IX9ECParameters;
+var
+  LEcP: IX9ECParameters;
+begin
+  LEcP := TCustomNamedCurves.GetByOid(AOid);
+  if LEcP = nil then
+    LEcP := TECNamedCurveTable.GetByOid(AOid);
+  Result := LEcP;
+end;
+
+function TECKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
+var
+  LN, LD: TBigInteger;
+  LMinWeight: Int32;
+  LQ: IECPoint;
+begin
+  LN := FParameters.N;
+  LMinWeight := TBitOperations.Asr32(LN.BitLength, 2);
+  while True do
+  begin
+    LD := TBigInteger.Create(LN.BitLength, FRandom);
+    if (LD.CompareTo(TBigInteger.One) < 0) or (LD.CompareTo(LN) >= 0) then
+      Continue;
+    if TWNafUtilities.GetNafWeight(LD) < LMinWeight then
+      Continue;
+    Break;
+  end;
+  LQ := CreateBasePointMultiplier().Multiply(FParameters.G, LD);
+  Result := TAsymmetricCipherKeyPair.Create(
+    TECPublicKeyParameters.Create(FAlgorithm, LQ, FParameters) as IECPublicKeyParameters,
+    TECPrivateKeyParameters.Create(FAlgorithm, LD, FParameters) as IECPrivateKeyParameters);
+end;
+
+class function TECKeyPairGenerator.GetCorrespondingPublicKey(const APrivKey: IECPrivateKeyParameters): IECPublicKeyParameters;
+var
+  LEc: IECDomainParameters;
+  LQ: IECPoint;
+begin
+  LEc := APrivKey.Parameters;
+  LQ := (TFixedPointCombMultiplier.Create() as IFixedPointCombMultiplier).Multiply(LEc.G, APrivKey.D);
+  Result := TECPublicKeyParameters.Create(APrivKey.AlgorithmName, LQ, LEc);
+end;
+
+procedure TECKeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
+var
+  LEcP: IECKeyGenerationParameters;
+  LEcps: IX9ECParameters;
+  LOid: IDerObjectIdentifier;
+begin
+  if Supports(AParameters, IECKeyGenerationParameters, LEcP) then
+    FParameters := LEcP.DomainParameters
+  else
+  begin
+    case AParameters.Strength of
+      192: LOid := TX9ObjectIdentifiers.Prime192v1;
+      224: LOid := TSecObjectIdentifiers.SecP224r1;
+      239: LOid := TX9ObjectIdentifiers.Prime239v1;
+      256: LOid := TX9ObjectIdentifiers.Prime256v1;
+      384: LOid := TSecObjectIdentifiers.SecP384r1;
+      521: LOid := TSecObjectIdentifiers.SecP521r1;
+    else
+      raise EInvalidParameterCryptoLibException.CreateResFmt(@SInvalidKeySize, [AParameters.Strength]);
+    end;
+    LEcps := FindECCurveByOid(LOid);
+    FParameters := TECDomainParameters.Create(LEcps.Curve, LEcps.G, LEcps.N, LEcps.H, LEcps.GetSeed());
+  end;
+  FRandom := AParameters.Random;
+  if FRandom = nil then
+    FRandom := TSecureRandom.Create();
+end;
+
+end.

+ 0 - 221
CryptoLib/src/Crypto/Generators/ClpECKeyPairGenerator.pas

@@ -1,221 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECKeyPairGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpBigInteger,
-  ClpBitOperations,
-  ClpCryptoLibTypes,
-  ClpECKeyParameters,
-  ClpECCompUtilities,
-  ClpIECKeyPairGenerator,
-  ClpIAsn1Objects,
-  ClpIKeyGenerationParameters,
-  ClpIECKeyGenerationParameters,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
-  ClpIECC,
-  ClpMultipliers,
-  ClpIMultipliers,
-  ClpSecObjectIdentifiers,
-  ClpCustomNamedCurves,
-  ClpECNamedCurveTable,
-  ClpX9ObjectIdentifiers,
-  ClpIX9ECAsn1Objects,
-  ClpAsymmetricCipherKeyPair,
-  ClpIAsymmetricCipherKeyPair,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpSecureRandom,
-  ClpISecureRandom,
-  ClpIAsymmetricCipherKeyPairGenerator;
-
-resourcestring
-  SAlgorithmNil = 'Algorithm Cannot be Empty';
-  SInvalidKeySize = 'Unknown Key Size "%d"';
-
-type
-  TECKeyPairGenerator = class sealed(TInterfacedObject, IECKeyPairGenerator,
-    IAsymmetricCipherKeyPairGenerator)
-
-  strict private
-  var
-    Falgorithm: String;
-    Fparameters: IECDomainParameters;
-    Frandom: ISecureRandom;
-
-  strict protected
-
-    function CreateBasePointMultiplier(): IECMultiplier; virtual;
-
-  public
-    constructor Create(); overload;
-    constructor Create(const algorithm: String); overload;
-
-    procedure Init(const parameters: IKeyGenerationParameters);
-    // /**
-    // * Given the domain parameters this routine generates an EC key
-    // * pair in accordance with X9.62 section 5.2.1 pages 26, 27.
-    // */
-    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
-
-    class function FindECCurveByOid(const oid: IDerObjectIdentifier)
-      : IX9ECParameters; static;
-
-    class function GetCorrespondingPublicKey(const privKey
-      : IECPrivateKeyParameters): IECPublicKeyParameters; static;
-
-  end;
-
-implementation
-
-{ TECKeyPairGenerator }
-
-constructor TECKeyPairGenerator.Create;
-begin
-  Create('EC');
-end;
-
-constructor TECKeyPairGenerator.Create(const algorithm: String);
-begin
-  if (algorithm = '') then
-    raise EArgumentNilCryptoLibException.CreateRes(@SAlgorithmNil);
-
-  Falgorithm := TECKeyParameters.VerifyAlgorithmName(algorithm);
-end;
-
-function TECKeyPairGenerator.CreateBasePointMultiplier: IECMultiplier;
-begin
-  result := TFixedPointCombMultiplier.Create();
-end;
-
-class function TECKeyPairGenerator.FindECCurveByOid
-  (const oid: IDerObjectIdentifier): IX9ECParameters;
-var
-  ecP: IX9ECParameters;
-begin
-  // TODO ECGost3410NamedCurves support (returns ECDomainParameters though)
-
-  ecP := TCustomNamedCurves.GetByOid(oid);
-  if (ecP = Nil) then
-  begin
-    ecP := TECNamedCurveTable.GetByOid(oid);
-  end;
-
-  result := ecP;
-end;
-
-function TECKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
-var
-  n, d: TBigInteger;
-  minWeight: Int32;
-  q: IECPoint;
-begin
-  n := Fparameters.n;
-  minWeight := TBitOperations.Asr32(n.BitLength, 2);
-
-  while (true) do
-  begin
-    d := TBigInteger.Create(n.BitLength, Frandom);
-
-    if ((d.CompareTo(TBigInteger.One) < 0) or (d.CompareTo(n) >= 0)) then
-      continue;
-
-    if (TWNafUtilities.GetNafWeight(d) < minWeight) then
-    begin
-      continue;
-    end;
-
-    break;
-  end;
-
-  q := CreateBasePointMultiplier().Multiply(Fparameters.G, d);
-
-  result := TAsymmetricCipherKeyPair.Create
-    (TECPublicKeyParameters.Create(Falgorithm, q, Fparameters)
-    as IECPublicKeyParameters, TECPrivateKeyParameters.Create(Falgorithm, d,
-    Fparameters) as IECPrivateKeyParameters);
-end;
-
-class function TECKeyPairGenerator.GetCorrespondingPublicKey
-  (const privKey: IECPrivateKeyParameters): IECPublicKeyParameters;
-var
-  ec: IECDomainParameters;
-  q: IECPoint;
-begin
-  ec := privKey.Parameters;
-  q := (TFixedPointCombMultiplier.Create() as IFixedPointCombMultiplier)
-    .Multiply(ec.G, privKey.d);
-
-  result := TECPublicKeyParameters.Create(privKey.AlgorithmName, q, ec);
-end;
-
-procedure TECKeyPairGenerator.Init(const parameters: IKeyGenerationParameters);
-var
-  ecP: IECKeyGenerationParameters;
-  ecps: IX9ECParameters;
-  oid: IDerObjectIdentifier;
-begin
-  if (Supports(parameters, IECKeyGenerationParameters, ecP)) then
-  begin
-    Fparameters := ecP.DomainParameters;
-  end
-  else
-  begin
-    case parameters.Strength of
-      192:
-        oid := TX9ObjectIdentifiers.Prime192v1;
-      224:
-        oid := TSecObjectIdentifiers.SecP224r1;
-      239:
-        oid := TX9ObjectIdentifiers.Prime239v1;
-      256:
-        oid := TX9ObjectIdentifiers.Prime256v1;
-      384:
-        oid := TSecObjectIdentifiers.SecP384r1;
-      521:
-        oid := TSecObjectIdentifiers.SecP521r1;
-    else
-      raise EInvalidParameterCryptoLibException.CreateResFmt(@SInvalidKeySize,
-        [parameters.Strength]);
-
-    end;
-
-    ecps := FindECCurveByOid(oid);
-
-    Fparameters := TECDomainParameters.Create(ecps.Curve, ecps.G, ecps.n,
-      ecps.H, ecps.GetSeed());
-  end;
-
-  Frandom := parameters.Random;
-
-  if (Frandom = Nil) then
-  begin
-    Frandom := TSecureRandom.Create();
-  end;
-
-end;
-
-end.

+ 6 - 15
CryptoLib/src/Crypto/Generators/ClpEd25519KeyPairGenerator.pas → CryptoLib/src/Crypto/Generators/ClpEd25519Generators.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpEd25519KeyPairGenerator;
+unit ClpEd25519Generators;
 
 {$I ..\..\Include\CryptoLib.inc}
 
@@ -23,10 +23,9 @@ interface
 
 uses
   ClpAsymmetricCipherKeyPair,
-  ClpIEd25519KeyPairGenerator,
-  ClpIEd25519PrivateKeyParameters,
-  ClpEd25519PrivateKeyParameters,
-  ClpIEd25519PublicKeyParameters,
+  ClpIEd25519Generators,
+  ClpIEd25519Parameters,
+  ClpEd25519Parameters,
   ClpISecureRandom,
   ClpIKeyGenerationParameters,
   ClpIAsymmetricCipherKeyPair,
@@ -35,24 +34,17 @@ uses
 type
   TEd25519KeyPairGenerator = class(TInterfacedObject, IEd25519KeyPairGenerator,
     IAsymmetricCipherKeyPairGenerator)
-
   strict private
-  var
     FRandom: ISecureRandom;
-
   public
     constructor Create();
     procedure Init(const AParameters: IKeyGenerationParameters);
-
     function GenerateKeyPair(): IAsymmetricCipherKeyPair;
-
   end;
 
 implementation
 
-{ TEd25519KeyPairGenerator }
-
-constructor TEd25519KeyPairGenerator.Create();
+constructor TEd25519KeyPairGenerator.Create;
 begin
   inherited Create();
 end;
@@ -67,8 +59,7 @@ begin
   Result := TAsymmetricCipherKeyPair.Create(LPublicKey, LPrivateKey);
 end;
 
-procedure TEd25519KeyPairGenerator.Init(const AParameters
-  : IKeyGenerationParameters);
+procedure TEd25519KeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
 begin
   FRandom := AParameters.Random;
 end;

+ 12 - 13
CryptoLib/src/Crypto/Generators/ClpEphemeralKeyPairGenerator.pas

@@ -35,34 +35,33 @@ type
 
   strict private
   var
-    Fgen: IAsymmetricCipherKeyPairGenerator;
-    FkeyEncoder: IKeyEncoder;
+    FGen: IAsymmetricCipherKeyPairGenerator;
+    FKeyEncoder: IKeyEncoder;
 
   public
     function Generate(): IEphemeralKeyPair; inline;
-    constructor Create(const gen: IAsymmetricCipherKeyPairGenerator;
-      const keyEncoder: IKeyEncoder);
+    constructor Create(const AGen: IAsymmetricCipherKeyPairGenerator;
+      const AKeyEncoder: IKeyEncoder);
   end;
 
 implementation
 
 { TEphemeralKeyPairGenerator }
 
-constructor TEphemeralKeyPairGenerator.Create
-  (const gen: IAsymmetricCipherKeyPairGenerator; const keyEncoder: IKeyEncoder);
+constructor TEphemeralKeyPairGenerator.Create(
+  const AGen: IAsymmetricCipherKeyPairGenerator; const AKeyEncoder: IKeyEncoder);
 begin
-  Inherited Create();
-  Fgen := gen;
-  FkeyEncoder := keyEncoder;
+  inherited Create();
+  FGen := AGen;
+  FKeyEncoder := AKeyEncoder;
 end;
 
 function TEphemeralKeyPairGenerator.Generate: IEphemeralKeyPair;
 var
-  eph: IAsymmetricCipherKeyPair;
+  LEph: IAsymmetricCipherKeyPair;
 begin
-  eph := Fgen.generateKeyPair();
-  // Encode the ephemeral public key
-  result := TEphemeralKeyPair.Create(eph, FkeyEncoder);
+  LEph := FGen.GenerateKeyPair();
+  Result := TEphemeralKeyPair.Create(LEph, FKeyEncoder);
 end;
 
 end.

+ 12 - 12
CryptoLib/src/Crypto/Generators/ClpGeneratorUtilities.pas

@@ -28,28 +28,28 @@ uses
   ClpCipherKeyGenerator,
   ClpCryptoLibComparers,
   ClpCryptoLibTypes,
-  ClpDsaKeyPairGenerator,
-  ClpECKeyPairGenerator,
-  ClpEd25519KeyPairGenerator,
+  ClpDsaGenerators,
+  ClpECGenerators,
+  ClpEd25519Generators,
   ClpEdECObjectIdentifiers,
-  ClpDHKeyPairGenerator,
+  ClpDHGenerators,
   ClpIAsn1Objects,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpICipherKeyGenerator,
-  ClpIDsaKeyPairGenerator,
-  ClpIDHKeyPairGenerator,
-  ClpIECKeyPairGenerator,
-  ClpIEd25519KeyPairGenerator,
-  ClpIRsaKeyPairGenerator,
-  ClpIX25519KeyPairGenerator,
+  ClpIDsaGenerators,
+  ClpIDHGenerators,
+  ClpIECGenerators,
+  ClpIEd25519Generators,
+  ClpIRsaGenerators,
+  ClpIX25519Generators,
   ClpIanaObjectIdentifiers,
   ClpNistObjectIdentifiers,
   ClpPkcsObjectIdentifiers,
   ClpRosstandartObjectIdentifiers,
-  ClpRsaKeyPairGenerator,
+  ClpRsaGenerators,
   ClpSecObjectIdentifiers,
   ClpStringUtilities,
-  ClpX25519KeyPairGenerator,
+  ClpX25519Generators,
   ClpX9ObjectIdentifiers;
 
 resourcestring

+ 61 - 72
CryptoLib/src/Crypto/Generators/ClpHkdfBytesGenerator.pas

@@ -56,9 +56,9 @@ type
 
   strict private
   var
-    FhMacHash: IHMac;
-    FhashLen, FgeneratedBytes: Int32;
-    Finfo, FcurrentT: TCryptoLibByteArray;
+    FHMacHash: IHMac;
+    FHashLen, FGeneratedBytes: Int32;
+    FInfo, FCurrentT: TCryptoLibByteArray;
 
     /// <summary>
     /// Performs the extract part of the key derivation function.
@@ -72,7 +72,7 @@ type
     /// <returns>
     /// the PRK as KeyParameter
     /// </returns>
-    function Extract(const salt, ikm: TCryptoLibByteArray): IKeyParameter;
+    function Extract(const ASalt, AIkm: TCryptoLibByteArray): IKeyParameter;
 
     /// <summary>
     /// Performs the expand part of the key derivation function, using
@@ -95,12 +95,12 @@ type
     /// <param name="hash">
     /// the digest to be used as the source of generatedBytes bytes
     /// </param>
-    constructor Create(const hash: IDigest);
+    constructor Create(const AHash: IDigest);
 
-    procedure Init(const parameters: IDerivationParameters); virtual;
+    procedure Init(const AParameters: IDerivationParameters); virtual;
 
-    function GenerateBytes(const output: TCryptoLibByteArray;
-      outOff, len: Int32): Int32; virtual;
+    function GenerateBytes(const AOutput: TCryptoLibByteArray;
+      AOutOff, ALen: Int32): Int32; virtual;
 
     property Digest: IDigest read GetDigest;
 
@@ -110,122 +110,111 @@ implementation
 
 { THkdfBytesGenerator }
 
-constructor THkdfBytesGenerator.Create(const hash: IDigest);
+constructor THkdfBytesGenerator.Create(const AHash: IDigest);
 begin
-  Inherited Create();
-  FhMacHash := THMac.Create(hash);
-  FhashLen := hash.GetDigestSize();
+  inherited Create();
+  FHMacHash := THMac.Create(AHash);
+  FHashLen := AHash.GetDigestSize();
 end;
 
 procedure THkdfBytesGenerator.ExpandNext;
 var
-  n: Int32;
+  LN: Int32;
 begin
-  n := (FgeneratedBytes div FhashLen) + 1;
-  if (n >= 256) then
+  LN := (FGeneratedBytes div FHashLen) + 1;
+  if LN >= 256 then
   begin
     raise EDataLengthCryptoLibException.CreateRes(@SSizeTooBigHKDF);
   end;
   // special case for T(0): T(0) is empty, so no update
-  if (FgeneratedBytes <> 0) then
+  if (FGeneratedBytes <> 0) then
   begin
-    FhMacHash.BlockUpdate(FcurrentT, 0, FhashLen);
+    FHMacHash.BlockUpdate(FCurrentT, 0, FHashLen);
   end;
-  FhMacHash.BlockUpdate(Finfo, 0, System.Length(Finfo));
-  FhMacHash.Update(Byte(n));
-  FhMacHash.DoFinal(FcurrentT, 0);
+  FHMacHash.BlockUpdate(FInfo, 0, System.Length(FInfo));
+  FHMacHash.Update(Byte(LN));
+  FHMacHash.DoFinal(FCurrentT, 0);
 end;
 
-function THkdfBytesGenerator.Extract(const salt, ikm: TCryptoLibByteArray)
-  : IKeyParameter;
+function THkdfBytesGenerator.Extract(const ASalt, AIkm: TCryptoLibByteArray): IKeyParameter;
 var
-  temp, prk: TCryptoLibByteArray;
+  LTemp, LPrk: TCryptoLibByteArray;
 begin
-  if (salt = Nil) then
+  if ASalt = nil then
   begin
-    System.SetLength(temp, FhashLen);
-    // TODO check if hashLen is indeed same as HMAC size
-    FhMacHash.Init(TKeyParameter.Create(temp) as IKeyParameter);
+    System.SetLength(LTemp, FHashLen);
+    FHMacHash.Init(TKeyParameter.Create(LTemp) as IKeyParameter);
   end
   else
   begin
-    FhMacHash.Init(TKeyParameter.Create(salt) as IKeyParameter);
+    FHMacHash.Init(TKeyParameter.Create(ASalt) as IKeyParameter);
   end;
 
-  FhMacHash.BlockUpdate(ikm, 0, System.Length(ikm));
+  FHMacHash.BlockUpdate(AIkm, 0, System.Length(AIkm));
 
-  System.SetLength(prk, FhashLen);
-  FhMacHash.DoFinal(prk, 0);
-  result := TKeyParameter.Create(prk);
+  System.SetLength(LPrk, FHashLen);
+  FHMacHash.DoFinal(LPrk, 0);
+  Result := TKeyParameter.Create(LPrk);
 end;
 
-function THkdfBytesGenerator.GenerateBytes(const output: TCryptoLibByteArray;
-  outOff, len: Int32): Int32;
+function THkdfBytesGenerator.GenerateBytes(const AOutput: TCryptoLibByteArray;
+  AOutOff, ALen: Int32): Int32;
 var
-  toGenerate, posInT, leftInT, toCopy: Int32;
+  LToGenerate, LPosInT, LLeftInT, LToCopy, LOutOff: Int32;
 begin
-  if ((FgeneratedBytes + len) > (255 * FhashLen)) then
-  begin
+  if (FGeneratedBytes + ALen) > (255 * FHashLen) then
     raise EDataLengthCryptoLibException.CreateRes(@SSizeTooBigHKDF2);
-  end;
 
-  if (FgeneratedBytes mod FhashLen = 0) then
-  begin
+  if FGeneratedBytes mod FHashLen = 0 then
     ExpandNext();
-  end;
 
-  // copy what is left in the currentT (1..hash
-  toGenerate := len;
-  posInT := FgeneratedBytes mod FhashLen;
-  leftInT := FhashLen - (FgeneratedBytes mod FhashLen);
-  toCopy := Min(leftInT, toGenerate);
-  System.Move(FcurrentT[posInT], output[outOff], toCopy);
-  FgeneratedBytes := FgeneratedBytes + toCopy;
-  toGenerate := toGenerate - toCopy;
-  outOff := outOff + toCopy;
-
-  while (toGenerate > 0) do
+  LToGenerate := ALen;
+  LPosInT := FGeneratedBytes mod FHashLen;
+  LLeftInT := FHashLen - (FGeneratedBytes mod FHashLen);
+  LToCopy := Min(LLeftInT, LToGenerate);
+  System.Move(FCurrentT[LPosInT], AOutput[AOutOff], LToCopy);
+  FGeneratedBytes := FGeneratedBytes + LToCopy;
+  LToGenerate := LToGenerate - LToCopy;
+  LOutOff := AOutOff + LToCopy;
+
+  while LToGenerate > 0 do
   begin
     ExpandNext();
-    toCopy := Min(FhashLen, toGenerate);
-    System.Move(FcurrentT[0], output[outOff], toCopy);
-    FgeneratedBytes := FgeneratedBytes + toCopy;
-    toGenerate := toGenerate - toCopy;
-    outOff := outOff + toCopy;
+    LToCopy := Min(FHashLen, LToGenerate);
+    System.Move(FCurrentT[0], AOutput[LOutOff], LToCopy);
+    FGeneratedBytes := FGeneratedBytes + LToCopy;
+    LToGenerate := LToGenerate - LToCopy;
+    LOutOff := LOutOff + LToCopy;
   end;
 
-  result := len;
+  Result := ALen;
 end;
 
 function THkdfBytesGenerator.GetDigest: IDigest;
 begin
-  result := FhMacHash.GetUnderlyingDigest();
+  Result := FHMacHash.GetUnderlyingDigest();
 end;
 
-procedure THkdfBytesGenerator.Init(const parameters: IDerivationParameters);
+procedure THkdfBytesGenerator.Init(const AParameters: IDerivationParameters);
 var
-  hkdfParameters: IHkdfParameters;
+  LHkdfParameters: IHkdfParameters;
 begin
-  if (not Supports(parameters, IHkdfParameters, hkdfParameters)) then
-  begin
+  if not Supports(AParameters, IHkdfParameters, LHkdfParameters) then
     raise EArgumentCryptoLibException.CreateRes(@SInvalidParameterHKDF);
-  end;
 
-  if (hkdfParameters.SkipExtract) then
+  if LHkdfParameters.SkipExtract then
   begin
-    // use IKM directly as PRK
-    FhMacHash.Init(TKeyParameter.Create(hkdfParameters.GetIkm())
-      as IKeyParameter);
+    FHMacHash.Init(TKeyParameter.Create(LHkdfParameters.GetIkm()) as IKeyParameter);
   end
   else
   begin
-    FhMacHash.Init(Extract(hkdfParameters.GetSalt(), hkdfParameters.GetIkm()));
+    FHMacHash.Init(Extract(LHkdfParameters.GetSalt(), LHkdfParameters.GetIkm()));
   end;
 
-  Finfo := hkdfParameters.GetInfo();
+  FInfo := LHkdfParameters.GetInfo();
 
-  FgeneratedBytes := 0;
-  System.SetLength(FcurrentT, FhashLen);
+  FGeneratedBytes := 0;
+  System.SetLength(FCurrentT, FHashLen);
 end;
 
 end.

+ 3 - 3
CryptoLib/src/Crypto/Generators/ClpKdf1BytesGenerator.pas

@@ -47,7 +47,7 @@ type
     /// <param name="digest">
     /// the digest to be used as the source of derived keys.
     /// </param>
-    constructor Create(const digest: IDigest);
+    constructor Create(const ADigest: IDigest);
 
   end;
 
@@ -55,9 +55,9 @@ implementation
 
 { TKdf1BytesGenerator }
 
-constructor TKdf1BytesGenerator.Create(const digest: IDigest);
+constructor TKdf1BytesGenerator.Create(const ADigest: IDigest);
 begin
-  Inherited Create(0, digest);
+  inherited Create(0, ADigest);
 end;
 
 end.

+ 3 - 3
CryptoLib/src/Crypto/Generators/ClpKdf2BytesGenerator.pas

@@ -48,7 +48,7 @@ type
     /// <param name="digest">
     /// the digest to be used as the source of derived keys.
     /// </param>
-    constructor Create(const digest: IDigest);
+    constructor Create(const ADigest: IDigest);
 
   end;
 
@@ -56,9 +56,9 @@ implementation
 
 { TKdf2BytesGenerator }
 
-constructor TKdf2BytesGenerator.Create(const digest: IDigest);
+constructor TKdf2BytesGenerator.Create(const ADigest: IDigest);
 begin
-  Inherited Create(1, digest);
+  inherited Create(1, ADigest);
 end;
 
 end.

+ 26 - 37
CryptoLib/src/Crypto/Generators/ClpPascalCoinECIESKdfBytesGenerator.pas

@@ -54,9 +54,9 @@ type
     /// <param name="digest">
     /// the digest to be used as the source of derived keys.
     /// </param>
-    constructor Create(const digest: IDigest);
+    constructor Create(const ADigest: IDigest);
 
-    procedure Init(const parameters: IDerivationParameters); override;
+    procedure Init(const AParameters: IDerivationParameters); override;
 
     /// <summary>
     /// fill len bytes of the output buffer with bytes generated from the
@@ -68,8 +68,8 @@ type
     /// <exception cref="EDataLengthCryptoLibException">
     /// if the out buffer is too small.
     /// </exception>
-    function GenerateBytes(const output: TCryptoLibByteArray;
-      outOff, length: Int32): Int32; override;
+    function GenerateBytes(const AOutput: TCryptoLibByteArray;
+      AOutOff, ALength: Int32): Int32; override;
 
   end;
 
@@ -77,58 +77,47 @@ implementation
 
 { TPascalCoinECIESKdfBytesGenerator }
 
-constructor TPascalCoinECIESKdfBytesGenerator.Create(const digest: IDigest);
+constructor TPascalCoinECIESKdfBytesGenerator.Create(const ADigest: IDigest);
 begin
-  Inherited Create(0, digest);
+  inherited Create(0, ADigest);
 end;
 
-function TPascalCoinECIESKdfBytesGenerator.GenerateBytes
-  (const output: TCryptoLibByteArray; outOff, length: Int32): Int32;
+function TPascalCoinECIESKdfBytesGenerator.GenerateBytes(
+  const AOutput: TCryptoLibByteArray; AOutOff, ALength: Int32): Int32;
 var
-  outLen: Int32;
-  temp: TCryptoLibByteArray;
+  LOutLen: Int32;
+  LTemp: TCryptoLibByteArray;
 begin
-  if ((System.length(output) - length) < outOff) then
-  begin
+  if (System.Length(AOutput) - ALength) < AOutOff then
     raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooSmall);
-  end;
-
-  outLen := digest.GetDigestSize;
 
-  if (length > outLen) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes
-      (@SHashCannotNotProduceSufficientData);
-  end;
+  LOutLen := GetDigest().GetDigestSize();
 
-  System.SetLength(temp, digest.GetDigestSize);
-  digest.BlockUpdate(Fshared, 0, System.length(Fshared));
-  digest.DoFinal(temp, 0);
+  if ALength > LOutLen then
+    raise EDataLengthCryptoLibException.CreateRes(@SHashCannotNotProduceSufficientData);
 
-  System.Move(temp[0], output[outOff], length * System.SizeOf(Byte));
+  System.SetLength(LTemp, GetDigest().GetDigestSize());
+  GetDigest().BlockUpdate(FShared, 0, System.Length(FShared));
+  GetDigest().DoFinal(LTemp, 0);
 
-  digest.Reset();
+  System.Move(LTemp[0], AOutput[AOutOff], ALength * System.SizeOf(Byte));
 
-  result := length;
+  GetDigest().Reset();
 
+  Result := ALength;
 end;
 
-procedure TPascalCoinECIESKdfBytesGenerator.Init(const parameters
-  : IDerivationParameters);
+procedure TPascalCoinECIESKdfBytesGenerator.Init(const AParameters: IDerivationParameters);
 var
-  Lparameters: IDerivationParameters;
-  p1: IKdfParameters;
+  LParameters: IDerivationParameters;
+  LP1: IKdfParameters;
 begin
-  Lparameters := parameters;
+  LParameters := AParameters;
 
-  if Supports(Lparameters, IKdfParameters, p1) then
-  begin
-    Fshared := p1.GetSharedSecret();
-  end
+  if Supports(LParameters, IKdfParameters, LP1) then
+    FShared := LP1.GetSharedSecret()
   else
-  begin
     raise EArgumentCryptoLibException.CreateRes(@SKDFParameterNotFound);
-  end;
 end;
 
 end.

+ 10 - 10
CryptoLib/src/Crypto/Generators/ClpPbeParametersGenerator.pas

@@ -41,48 +41,48 @@ type
     /// <summary>
     /// Generate derived parameters for a key of length keySize.
     /// </summary>
-    /// <param name="algorithm">
+    /// <param name="AAlgorithm">
     /// a parameters object representing a key.
     /// </param>
-    /// <param name="keySize">
+    /// <param name="AKeySize">
     /// the length, in bits, of the key required.
     /// </param>
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String; keySize: Int32)
+    function GenerateDerivedParameters(const AAlgorithm: String; AKeySize: Int32)
       : ICipherParameters; overload; virtual; abstract;
 
     /// <summary>
     /// Generate derived parameters for a key of length keySize and iv
     /// of length ivSize.
     /// </summary>
-    /// <param name="algorithm">
+    /// <param name="AAlgorithm">
     /// a parameters object representing a key.
     /// </param>
-    /// <param name="keySize">
+    /// <param name="AKeySize">
     /// the length, in bits, of the key required.
     /// </param>
-    /// <param name="ivSize">
+    /// <param name="AIvSize">
     /// the length, in bits, of the iv required.
     /// </param>
     /// <returns>
     /// a parameters object representing a key and an iv.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String;
-      keySize, ivSize: Int32): ICipherParameters; overload; virtual; abstract;
+    function GenerateDerivedParameters(const AAlgorithm: String;
+      AKeySize, AIvSize: Int32): ICipherParameters; overload; virtual; abstract;
 
     /// <summary>
     /// Generate derived parameters for a key of length keySize,
     /// specifically <br />for use with a MAC.
     /// </summary>
-    /// <param name="keySize">
+    /// <param name="AKeySize">
     /// the length, in bits, of the key required.
     /// </param>
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedMacParameters(keySize: Int32): ICipherParameters;
+    function GenerateDerivedMacParameters(AKeySize: Int32): ICipherParameters;
       virtual; abstract;
 
   end;

+ 46 - 51
CryptoLib/src/Crypto/Generators/ClpPkcs5S2ParametersGenerator.pas

@@ -48,7 +48,7 @@ type
   strict private
   var
     FPassword, FSalt: TCryptoLibByteArray;
-    Fdigest: IDigest;
+    FDigest: IDigest;
     FPBKDF2_HMAC: HlpIHashInfo.IPBKDF2_HMAC;
 
     /// <returns>
@@ -56,7 +56,7 @@ type
     /// </returns>
     function GetDigest: IDigest; inline;
 
-    function GenerateDerivedKey(dkLen: Int32): TCryptoLibByteArray; inline;
+    function GenerateDerivedKey(ADkLen: Int32): TCryptoLibByteArray; inline;
 
   public
 
@@ -67,12 +67,12 @@ type
     /// <param name="digest">
     /// digest to use for constructing hmac
     /// </param>
-    constructor Create(const digest: IDigest);
+    constructor Create(const ADigest: IDigest);
 
     destructor Destroy; override;
 
-    procedure Init(const password, salt: TCryptoLibByteArray;
-      iterationCount: Int32);
+    procedure Init(const APassword, ASalt: TCryptoLibByteArray;
+      AIterationCount: Int32);
 
     /// <summary>
     /// Generate a key parameter derived from the password, salt, and
@@ -87,7 +87,7 @@ type
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String; keySize: Int32)
+    function GenerateDerivedParameters(const AAlgorithm: String; AKeySize: Int32)
       : ICipherParameters; overload; override;
 
     /// <summary>
@@ -107,8 +107,8 @@ type
     /// <returns>
     /// a parameters object representing a key and an iv.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String;
-      keySize, ivSize: Int32): ICipherParameters; overload; override;
+    function GenerateDerivedParameters(const AAlgorithm: String;
+      AKeySize, AIvSize: Int32): ICipherParameters; overload; override;
 
     /// <summary>
     /// Generate a key parameter for use with a MAC derived from the
@@ -121,13 +121,13 @@ type
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedMacParameters(keySize: Int32)
+    function GenerateDerivedMacParameters(AKeySize: Int32)
       : ICipherParameters; override;
 
     /// <value>
     /// the underlying digest.
     /// </value>
-    property digest: IDigest read GetDigest;
+    property Digest: IDigest read GetDigest;
   end;
 
 implementation
@@ -139,16 +139,16 @@ begin
   TArrayUtilities.Fill<Byte>(FPassword, 0, System.Length(FPassword), Byte(0));
   TArrayUtilities.Fill<Byte>(FSalt, 0, System.Length(FSalt), Byte(0));
 
-  if FPBKDF2_HMAC <> Nil then
+  if FPBKDF2_HMAC <> nil then
   begin
     FPBKDF2_HMAC.Clear();
   end;
 end;
 
-constructor TPkcs5S2ParametersGenerator.Create(const digest: IDigest);
+constructor TPkcs5S2ParametersGenerator.Create(const ADigest: IDigest);
 begin
-  Inherited Create();
-  Fdigest := digest;
+  inherited Create();
+  FDigest := ADigest;
 end;
 
 destructor TPkcs5S2ParametersGenerator.Destroy;
@@ -157,63 +157,58 @@ begin
   inherited Destroy;
 end;
 
-function TPkcs5S2ParametersGenerator.GenerateDerivedKey(dkLen: Int32)
-  : TCryptoLibByteArray;
+function TPkcs5S2ParametersGenerator.GenerateDerivedKey(ADkLen: Int32): TCryptoLibByteArray;
 begin
-  result := FPBKDF2_HMAC.GetBytes(dkLen);
+  Result := FPBKDF2_HMAC.GetBytes(ADkLen);
 end;
 
-function TPkcs5S2ParametersGenerator.GenerateDerivedMacParameters
-  (keySize: Int32): ICipherParameters;
+function TPkcs5S2ParametersGenerator.GenerateDerivedMacParameters(AKeySize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
+  LDKey: TCryptoLibByteArray;
+  LKeySize: Int32;
 begin
-  keySize := keySize div 8;
-
-  dKey := GenerateDerivedKey(keySize);
-
-  result := TKeyParameter.Create(dKey, 0, keySize);
+  LKeySize := AKeySize div 8;
+  LDKey := GenerateDerivedKey(LKeySize);
+  Result := TKeyParameter.Create(LDKey, 0, LKeySize);
 end;
 
-function TPkcs5S2ParametersGenerator.GenerateDerivedParameters(const algorithm
-  : String; keySize: Int32): ICipherParameters;
+function TPkcs5S2ParametersGenerator.GenerateDerivedParameters(const AAlgorithm: String;
+  AKeySize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
+  LDKey: TCryptoLibByteArray;
+  LKeySize: Int32;
 begin
-  keySize := keySize div 8;
-
-  dKey := GenerateDerivedKey(keySize);
-
-  result := TParameterUtilities.CreateKeyParameter(algorithm, dKey, 0, keySize);
+  LKeySize := AKeySize div 8;
+  LDKey := GenerateDerivedKey(LKeySize);
+  Result := TParameterUtilities.CreateKeyParameter(AAlgorithm, LDKey, 0, LKeySize);
 end;
 
-function TPkcs5S2ParametersGenerator.GenerateDerivedParameters(const algorithm
-  : String; keySize, ivSize: Int32): ICipherParameters;
+function TPkcs5S2ParametersGenerator.GenerateDerivedParameters(const AAlgorithm: String;
+  AKeySize, AIvSize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
-  key: IKeyParameter;
+  LDKey: TCryptoLibByteArray;
+  LKey: IKeyParameter;
+  LKeySize, LIvSize: Int32;
 begin
-  keySize := keySize div 8;
-  ivSize := ivSize div 8;
-
-  dKey := GenerateDerivedKey(keySize + ivSize);
-  key := TParameterUtilities.CreateKeyParameter(algorithm, dKey, 0, keySize);
-
-  result := TParametersWithIV.Create(key, dKey, keySize, ivSize);
+  LKeySize := AKeySize div 8;
+  LIvSize := AIvSize div 8;
+  LDKey := GenerateDerivedKey(LKeySize + LIvSize);
+  LKey := TParameterUtilities.CreateKeyParameter(AAlgorithm, LDKey, 0, LKeySize);
+  Result := TParametersWithIV.Create(LKey, LDKey, LKeySize, LIvSize);
 end;
 
 function TPkcs5S2ParametersGenerator.GetDigest: IDigest;
 begin
-  result := Fdigest;
+  Result := FDigest;
 end;
 
-procedure TPkcs5S2ParametersGenerator.Init(const password,
-  salt: TCryptoLibByteArray; iterationCount: Int32);
+procedure TPkcs5S2ParametersGenerator.Init(const APassword, ASalt: TCryptoLibByteArray;
+  AIterationCount: Int32);
 begin
-  FPassword := System.Copy(password);
-  FSalt := System.Copy(salt);
-  FPBKDF2_HMAC := TKDF.TPBKDF2_HMAC.CreatePBKDF2_HMAC
-    (Fdigest.GetUnderlyingIHash, FPassword, FSalt, iterationCount);
+  FPassword := System.Copy(APassword);
+  FSalt := System.Copy(ASalt);
+  FPBKDF2_HMAC := TKDF.TPBKDF2_HMAC.CreatePBKDF2_HMAC(
+    FDigest.GetUnderlyingIHash, FPassword, FSalt, AIterationCount);
 end;
 
 end.

+ 0 - 111
CryptoLib/src/Crypto/Generators/ClpRsaBlindingFactorGenerator.pas

@@ -1,111 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpRsaBlindingFactorGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpBigInteger,
-  ClpBigIntegers,
-  ClpICipherParameters,
-  ClpParameterUtilities,
-  ClpIRsaKeyParameters,
-  ClpIRsaBlindingFactorGenerator,
-  ClpISecureRandom,
-  ClpSecureRandom,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SGeneratorNotInit = 'Generator not initialised';
-  SPublicKeyRequired = 'Generator requires RSA public key';
-
-type
-  /// <summary>
-  /// Generate a random factor suitable for use with RSA blind signatures.
-  /// </summary>
-  TRsaBlindingFactorGenerator = class(TInterfacedObject, IRsaBlindingFactorGenerator)
-
-  strict private
-  var
-    FKey: IRsaKeyParameters;
-    FRandom: ISecureRandom;
-
-  public
-    constructor Create();
-
-    procedure Init(const param: ICipherParameters);
-    function GenerateBlindingFactor: TBigInteger;
-
-  end;
-
-implementation
-
-{ TRsaBlindingFactorGenerator }
-
-constructor TRsaBlindingFactorGenerator.Create;
-begin
-  inherited Create();
-  FKey := nil;
-  FRandom := nil;
-end;
-
-procedure TRsaBlindingFactorGenerator.Init(const param: ICipherParameters);
-var
-  LParameters: ICipherParameters;
-  providedRandom: ISecureRandom;
-begin
-  LParameters := TParameterUtilities.GetRandom(param, providedRandom);
-  FKey := LParameters as IRsaKeyParameters;
-
-  if providedRandom <> nil then
-    FRandom := providedRandom
-  else
-    FRandom := TSecureRandom.Create();
-
-  if FKey.IsPrivate then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SPublicKeyRequired);
-  end;
-end;
-
-function TRsaBlindingFactorGenerator.GenerateBlindingFactor: TBigInteger;
-var
-  m: TBigInteger;
-  len: Int32;
-  factor: TBigInteger;
-begin
-  if FKey = nil then
-  begin
-    raise EInvalidOperationCryptoLibException.CreateRes(@SGeneratorNotInit);
-  end;
-
-  m := FKey.Modulus;
-  len := m.BitLength - 1; // must be less than m.BitLength
-
-  repeat
-    factor := TBigInteger.Create(len, FRandom);
-  until (factor.CompareTo(TBigInteger.Two) >= 0) and
-    TBigIntegers.ModOddIsCoprimeVar(m, factor);
-
-  Result := factor;
-end;
-
-end.

+ 237 - 0
CryptoLib/src/Crypto/Generators/ClpRsaGenerators.pas

@@ -0,0 +1,237 @@
+{ *********************************************************************************** }
+{ *                              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 ClpRsaGenerators;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpArrayUtilities,
+  ClpBigInteger,
+  ClpBigIntegers,
+  ClpBitOperations,
+  ClpIKeyGenerationParameters,
+  ClpIRsaParameters,
+  ClpRsaParameters,
+  ClpIAsymmetricCipherKeyPair,
+  ClpAsymmetricCipherKeyPair,
+  ClpIAsymmetricCipherKeyPairGenerator,
+  ClpIRsaGenerators,
+  ClpECCompUtilities,
+  ClpICipherParameters,
+  ClpParameterUtilities,
+  ClpISecureRandom,
+  ClpSecureRandom,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SRsaKeyGenNotInit = 'RSA key pair generator not initialised';
+  SGeneratorNotInit = 'Generator not initialised';
+  SPublicKeyRequired = 'Generator requires RSA public key';
+  SRsaKeyParametersRequired = 'Parameters must support IRsaKeyParameters';
+
+type
+  TRsaKeyPairGenerator = class(TInterfacedObject,
+    IAsymmetricCipherKeyPairGenerator, IRsaKeyPairGenerator)
+  strict private
+  class var
+    FDefaultPublicExponent: TBigInteger;
+    FSpecialEValues: TCryptoLibInt32Array;
+    FSpecialEHighest: Int32;
+    FSpecialEBits: Int32;
+  var
+    FParam: IRsaKeyGenerationParameters;
+    class constructor CreateRsaKeyPairGenerator;
+    function ChooseRandomPrime(ABitLength: Int32;
+      const AE: TBigInteger): TBigInteger;
+  public
+    const DefaultTests = 100;
+    constructor Create();
+    procedure Init(const AParameters: IKeyGenerationParameters);
+    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
+  end;
+
+  TRsaBlindingFactorGenerator = class(TInterfacedObject, IRsaBlindingFactorGenerator)
+  strict private
+    FKey: IRsaKeyParameters;
+    FRandom: ISecureRandom;
+  public
+    constructor Create();
+    procedure Init(const AParam: ICipherParameters);
+    function GenerateBlindingFactor: TBigInteger;
+  end;
+
+implementation
+
+{ TRsaKeyPairGenerator }
+
+class constructor TRsaKeyPairGenerator.CreateRsaKeyPairGenerator;
+begin
+  FSpecialEValues := TCryptoLibInt32Array.Create(3, 5, 17, 257, 65537);
+  FSpecialEHighest := 65537;
+  FSpecialEBits := TBigInteger.ValueOf(FSpecialEHighest).BitLength;
+  FDefaultPublicExponent := TBigInteger.ValueOf($10001);
+end;
+
+constructor TRsaKeyPairGenerator.Create;
+begin
+  inherited Create();
+  FParam := nil;
+end;
+
+procedure TRsaKeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
+begin
+  if not Supports(AParameters, IRsaKeyGenerationParameters, FParam) then
+    FParam := TRsaKeyGenerationParameters.Create(
+      FDefaultPublicExponent, AParameters.Random, AParameters.Strength, DefaultTests);
+end;
+
+function TRsaKeyPairGenerator.ChooseRandomPrime(ABitLength: Int32;
+  const AE: TBigInteger): TBigInteger;
+var
+  LP, LPSub1: TBigInteger;
+  LEIsKnownOddPrime: Boolean;
+begin
+  LEIsKnownOddPrime := (AE.BitLength <= FSpecialEBits) and
+    TArrayUtilities.Contains<Int32>(FSpecialEValues, AE.Int32Value);
+  while True do
+  begin
+    LP := TBigInteger.Create(ABitLength, 1, FParam.Random);
+    if LP.&Mod(AE).Equals(TBigInteger.One) then
+      Continue;
+    if not LP.IsProbablePrime(FParam.Certainty, True) then
+      Continue;
+    if not LEIsKnownOddPrime then
+    begin
+      LPSub1 := LP.Subtract(TBigInteger.One);
+      if not AE.Gcd(LPSub1).Equals(TBigInteger.One) then
+        Continue;
+    end;
+    Result := LP;
+    Exit;
+  end;
+end;
+
+function TRsaKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
+var
+  LStrength, LPBitLength, LQBitLength, LMinDiffBits, LMinWeight: Int32;
+  LE, LP, LQ, LPSub1, LQSub1: TBigInteger;
+  LN, LD, LDP, LDQ, LQInv: TBigInteger;
+  LDiff, LGcd, LLcm, LTmp: TBigInteger;
+  LPubKey: IRsaKeyParameters;
+  LPrivKey: IRsaPrivateCrtKeyParameters;
+begin
+  if FParam = nil then
+    raise EInvalidOperationCryptoLibException.CreateRes(@SRsaKeyGenNotInit);
+  while True do
+  begin
+    LStrength := FParam.Strength;
+    LE := FParam.PublicExponent;
+    LPBitLength := (LStrength + 1) div 2;
+    LQBitLength := LStrength - LPBitLength;
+    LMinDiffBits := LStrength div 3;
+    LMinWeight := TBitOperations.Asr32(LStrength, 2);
+    LP := ChooseRandomPrime(LPBitLength, LE);
+    while True do
+    begin
+      LQ := ChooseRandomPrime(LQBitLength, LE);
+      LDiff := LQ.Subtract(LP).Abs();
+      if LDiff.BitLength < LMinDiffBits then
+        Continue;
+      LN := LP.Multiply(LQ);
+      if LN.BitLength <> LStrength then
+      begin
+        LP := LP.Max(LQ);
+        Continue;
+      end;
+      if TWNafUtilities.GetNafWeight(LN) < LMinWeight then
+      begin
+        LP := ChooseRandomPrime(LPBitLength, LE);
+        Continue;
+      end;
+      Break;
+    end;
+    if LP.CompareTo(LQ) < 0 then
+    begin
+      LTmp := LP;
+      LP := LQ;
+      LQ := LTmp;
+    end;
+    LPSub1 := LP.Subtract(TBigInteger.One);
+    LQSub1 := LQ.Subtract(TBigInteger.One);
+    LGcd := LPSub1.Gcd(LQSub1);
+    LLcm := LPSub1.Divide(LGcd).Multiply(LQSub1);
+    LD := LE.ModInverse(LLcm);
+    if LD.BitLength <= LQBitLength then
+      Continue;
+    LDP := LD.Remainder(LPSub1);
+    LDQ := LD.Remainder(LQSub1);
+    LQInv := TBigIntegers.ModOddInverse(LP, LQ);
+    LPubKey := TRsaKeyParameters.Create(False, LN, LE) as IRsaKeyParameters;
+    LPrivKey := TRsaPrivateCrtKeyParameters.Create(LN, LE, LD, LP, LQ, LDP, LDQ, LQInv)
+      as IRsaPrivateCrtKeyParameters;
+    Result := TAsymmetricCipherKeyPair.Create(LPubKey, LPrivKey);
+    Exit;
+  end;
+end;
+
+{ TRsaBlindingFactorGenerator }
+
+constructor TRsaBlindingFactorGenerator.Create;
+begin
+  inherited Create();
+  FKey := nil;
+  FRandom := nil;
+end;
+
+procedure TRsaBlindingFactorGenerator.Init(const AParam: ICipherParameters);
+var
+  LParameters: ICipherParameters;
+  LProvidedRandom: ISecureRandom;
+begin
+  LParameters := TParameterUtilities.GetRandom(AParam, LProvidedRandom);
+  if not Supports(LParameters, IRsaKeyParameters, FKey) then
+    raise EArgumentCryptoLibException.CreateRes(@SRsaKeyParametersRequired);
+  if LProvidedRandom <> nil then
+    FRandom := LProvidedRandom
+  else
+    FRandom := TSecureRandom.Create();
+  if FKey.IsPrivate then
+    raise EArgumentCryptoLibException.CreateRes(@SPublicKeyRequired);
+end;
+
+function TRsaBlindingFactorGenerator.GenerateBlindingFactor: TBigInteger;
+var
+  LM: TBigInteger;
+  LLen: Int32;
+  LFactor: TBigInteger;
+begin
+  if FKey = nil then
+    raise EInvalidOperationCryptoLibException.CreateRes(@SGeneratorNotInit);
+  LM := FKey.Modulus;
+  LLen := LM.BitLength - 1;
+  repeat
+    LFactor := TBigInteger.Create(LLen, FRandom);
+  until (LFactor.CompareTo(TBigInteger.Two) >= 0) and
+    TBigIntegers.ModOddIsCoprimeVar(LM, LFactor);
+  Result := LFactor;
+end;
+
+end.

+ 0 - 243
CryptoLib/src/Crypto/Generators/ClpRsaKeyPairGenerator.pas

@@ -1,243 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpRsaKeyPairGenerator;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpArrayUtilities,
-  ClpBigInteger,
-  ClpBigIntegers,
-  ClpIKeyGenerationParameters,
-  ClpIRsaKeyGenerationParameters,
-  ClpRsaKeyGenerationParameters,
-  ClpIRsaKeyParameters,
-  ClpRsaKeyParameters,
-  ClpIRsaPrivateCrtKeyParameters,
-  ClpRsaPrivateCrtKeyParameters,
-  ClpIAsymmetricCipherKeyPair,
-  ClpAsymmetricCipherKeyPair,
-  ClpIAsymmetricCipherKeyPairGenerator,
-  ClpIRsaKeyPairGenerator,
-  ClpECCompUtilities,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SRsaKeyGenNotInit = 'RSA key pair generator not initialised';
-
-type
-  /// <summary>
-  /// RSA key pair generator.
-  /// </summary>
-  TRsaKeyPairGenerator = class(TInterfacedObject,
-    IAsymmetricCipherKeyPairGenerator, IRsaKeyPairGenerator)
-
-  strict private
-  class var
-    FDefaultPublicExponent: TBigInteger;
-
-  const
-    DefaultTests = 100;
-
-  class var
-    FSpecialEValues: TCryptoLibInt32Array;
-    FSpecialEHighest: Int32;
-    FSpecialEBits: Int32;
-
-  var
-    FParam: IRsaKeyGenerationParameters;
-
-    class constructor CreateRsaKeyPairGenerator;
-
-    function ChooseRandomPrime(bitLength: Int32;
-      const e: TBigInteger): TBigInteger;
-
-  public
-    constructor Create();
-
-    procedure Init(const parameters: IKeyGenerationParameters);
-    function GenerateKeyPair(): IAsymmetricCipherKeyPair;
-
-  end;
-
-implementation
-
-{ TRsaKeyPairGenerator }
-
-class constructor TRsaKeyPairGenerator.CreateRsaKeyPairGenerator;
-begin
-  FSpecialEValues := TCryptoLibInt32Array.Create(3, 5, 17, 257, 65537);
-  FSpecialEHighest := 65537;
-  FSpecialEBits := TBigInteger.ValueOf(FSpecialEHighest).BitLength;
-  FDefaultPublicExponent := TBigInteger.ValueOf($10001);  // 65537
-end;
-
-constructor TRsaKeyPairGenerator.Create;
-begin
-  inherited Create();
-  FParam := nil;
-end;
-
-procedure TRsaKeyPairGenerator.Init(const parameters: IKeyGenerationParameters);
-begin
-  if Supports(parameters, IRsaKeyGenerationParameters) then
-    FParam := parameters as IRsaKeyGenerationParameters
-  else
-    // Create default RSA parameters if not provided
-    FParam := TRsaKeyGenerationParameters.Create(
-      FDefaultPublicExponent, parameters.Random, parameters.Strength, DefaultTests);
-end;
-
-function TRsaKeyPairGenerator.ChooseRandomPrime(bitLength: Int32;
-  const e: TBigInteger): TBigInteger;
-var
-  p, pSub1: TBigInteger;
-  eIsKnownOddPrime: Boolean;
-begin
-  eIsKnownOddPrime := (e.BitLength <= FSpecialEBits) and TArrayUtilities.Contains<Int32>(FSpecialEValues, e.Int32Value);
-
-  while True do
-  begin
-    // Generate random odd number
-    p := TBigInteger.Create(bitLength, 1, FParam.Random);
-
-    // Check p mod e != 1
-    if p.&Mod(e).Equals(TBigInteger.One) then
-      Continue;
-
-    // Check primality
-    if not p.IsProbablePrime(FParam.Certainty, True) then
-      Continue;
-
-    // If e is not a known small prime, check gcd(e, p-1) = 1
-    if not eIsKnownOddPrime then
-    begin
-      pSub1 := p.Subtract(TBigInteger.One);
-      if not e.Gcd(pSub1).Equals(TBigInteger.One) then
-        Continue;
-    end;
-
-    Result := p;
-    Exit;
-  end;
-end;
-
-function TRsaKeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
-var
-  strength, pBitLength, qBitLength, minDiffBits, minWeight: Int32;
-  e, p, q, pSub1, qSub1: TBigInteger;
-  n, d, dP, dQ, qInv: TBigInteger;
-  diff, gcd, lcm, tmp: TBigInteger;
-  pubKey: IRsaKeyParameters;
-  privKey: IRsaPrivateCrtKeyParameters;
-begin
-  if FParam = nil then
-  begin
-    raise EInvalidOperationCryptoLibException.CreateRes(@SRsaKeyGenNotInit);
-  end;
-
-  while True do
-  begin
-    strength := FParam.Strength;
-    e := FParam.PublicExponent;
-
-    // p and q bit lengths
-    pBitLength := (strength + 1) div 2;
-    qBitLength := strength - pBitLength;
-    minDiffBits := strength div 3;
-    minWeight := strength shr 2;
-
-    // Generate p
-    p := ChooseRandomPrime(pBitLength, e);
-
-    // Generate q and modulus
-    while True do
-    begin
-      q := ChooseRandomPrime(qBitLength, e);
-
-      // p and q should not be too close together (or equal!)
-      diff := q.Subtract(p).Abs();
-      if diff.BitLength < minDiffBits then
-        Continue;
-
-      // Calculate the modulus
-      n := p.Multiply(q);
-
-      if n.BitLength <> strength then
-      begin
-        // If we get here our primes aren't big enough, make the largest
-        // of the two p and try again
-        p := p.Max(q);
-        Continue;
-      end;
-
-      // Require a minimum weight of the NAF representation, since low-weight
-      // composites may be weak against a version of the number-field-sieve
-      // for factoring.
-      // See "The number field sieve for integers of low weight", Oliver Schirokauer.
-      if TWNafUtilities.GetNafWeight(n) < minWeight then
-      begin
-        p := ChooseRandomPrime(pBitLength, e);
-        Continue;
-      end;
-
-      Break;
-    end;
-
-    // Ensure p > q (for CRT)
-    if p.CompareTo(q) < 0 then
-    begin
-      tmp := p;
-      p := q;
-      q := tmp;
-    end;
-
-    // Calculate phi components
-    pSub1 := p.Subtract(TBigInteger.One);
-    qSub1 := q.Subtract(TBigInteger.One);
-
-    // Calculate LCM(p-1, q-1) = (p-1) * (q-1) / gcd(p-1, q-1)
-    gcd := pSub1.Gcd(qSub1);
-    lcm := pSub1.Divide(gcd).Multiply(qSub1);
-
-    // Calculate the private exponent d = e^(-1) mod lcm
-    d := e.ModInverse(lcm);
-
-    // Check d has sufficient bit length
-    if d.BitLength <= qBitLength then
-      Continue;
-
-    // Calculate CRT parameters
-    dP := d.Remainder(pSub1);
-    dQ := d.Remainder(qSub1);
-    qInv := TBigIntegers.ModOddInverse(p, q);
-
-    // Create key pair
-    pubKey := TRsaKeyParameters.Create(False, n, e) as IRsaKeyParameters;
-    privKey := TRsaPrivateCrtKeyParameters.Create(n, e, d, p, q, dP, dQ, qInv)
-      as IRsaPrivateCrtKeyParameters;
-
-    Result := TAsymmetricCipherKeyPair.Create(pubKey, privKey);
-    Exit;
-  end;
-end;
-
-end.

+ 41 - 46
CryptoLib/src/Crypto/Generators/ClpScryptParametersGenerator.pas

@@ -49,7 +49,7 @@ type
     FPassword, FSalt: TCryptoLibByteArray;
     FPBKDF_Scrypt: HlpIHashInfo.IPBKDF_Scrypt;
 
-    function GenerateDerivedKey(dkLen: Int32): TCryptoLibByteArray; inline;
+    function GenerateDerivedKey(ADkLen: Int32): TCryptoLibByteArray; inline;
 
   public
 
@@ -61,8 +61,8 @@ type
 
     destructor Destroy; override;
 
-    procedure Init(const password, salt: TCryptoLibByteArray;
-      cost, blockSize, parallelism: Int32);
+    procedure Init(const APassword, ASalt: TCryptoLibByteArray;
+      ACost, ABlockSize, AParallelism: Int32);
 
     /// <summary>
     /// Generate a key parameter derived from the password, salt,
@@ -77,7 +77,7 @@ type
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String; keySize: Int32)
+    function GenerateDerivedParameters(const AAlgorithm: String; AKeySize: Int32)
       : ICipherParameters; overload; override;
 
     /// <summary>
@@ -97,8 +97,8 @@ type
     /// <returns>
     /// a parameters object representing a key and an iv.
     /// </returns>
-    function GenerateDerivedParameters(const algorithm: String;
-      keySize, ivSize: Int32): ICipherParameters; overload; override;
+    function GenerateDerivedParameters(const AAlgorithm: String;
+      AKeySize, AIvSize: Int32): ICipherParameters; overload; override;
 
     /// <summary>
     /// Generate a key parameter for use with a MAC derived from the
@@ -111,21 +111,21 @@ type
     /// <returns>
     /// a parameters object representing a key.
     /// </returns>
-    function GenerateDerivedMacParameters(keySize: Int32)
+    function GenerateDerivedMacParameters(AKeySize: Int32)
       : ICipherParameters; override;
 
   end;
 
 implementation
 
-{ TPkcs5S2ParametersGenerator }
+{ TScryptParametersGenerator }
 
 procedure TScryptParametersGenerator.Clear();
 begin
   TArrayUtilities.Fill<Byte>(FPassword, 0, System.Length(FPassword), Byte(0));
   TArrayUtilities.Fill<Byte>(FSalt, 0, System.Length(FSalt), Byte(0));
 
-  if FPBKDF_Scrypt <> Nil then
+  if FPBKDF_Scrypt <> nil then
   begin
     FPBKDF_Scrypt.Clear();
   end;
@@ -133,7 +133,7 @@ end;
 
 constructor TScryptParametersGenerator.Create();
 begin
-  Inherited Create();
+  inherited Create();
 end;
 
 destructor TScryptParametersGenerator.Destroy;
@@ -142,58 +142,53 @@ begin
   inherited Destroy;
 end;
 
-function TScryptParametersGenerator.GenerateDerivedKey(dkLen: Int32)
-  : TCryptoLibByteArray;
+function TScryptParametersGenerator.GenerateDerivedKey(ADkLen: Int32): TCryptoLibByteArray;
 begin
-  result := FPBKDF_Scrypt.GetBytes(dkLen);
+  Result := FPBKDF_Scrypt.GetBytes(ADkLen);
 end;
 
-function TScryptParametersGenerator.GenerateDerivedMacParameters(keySize: Int32)
-  : ICipherParameters;
+function TScryptParametersGenerator.GenerateDerivedMacParameters(AKeySize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
+  LDKey: TCryptoLibByteArray;
+  LKeySize: Int32;
 begin
-  keySize := keySize div 8;
-
-  dKey := GenerateDerivedKey(keySize);
-
-  result := TKeyParameter.Create(dKey, 0, keySize);
+  LKeySize := AKeySize div 8;
+  LDKey := GenerateDerivedKey(LKeySize);
+  Result := TKeyParameter.Create(LDKey, 0, LKeySize);
 end;
 
-function TScryptParametersGenerator.GenerateDerivedParameters(const algorithm
-  : String; keySize: Int32): ICipherParameters;
+function TScryptParametersGenerator.GenerateDerivedParameters(const AAlgorithm: String;
+  AKeySize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
+  LDKey: TCryptoLibByteArray;
+  LKeySize: Int32;
 begin
-  keySize := keySize div 8;
-
-  dKey := GenerateDerivedKey(keySize);
-
-  result := TParameterUtilities.CreateKeyParameter(algorithm, dKey, 0, keySize);
+  LKeySize := AKeySize div 8;
+  LDKey := GenerateDerivedKey(LKeySize);
+  Result := TParameterUtilities.CreateKeyParameter(AAlgorithm, LDKey, 0, LKeySize);
 end;
 
-function TScryptParametersGenerator.GenerateDerivedParameters(const algorithm
-  : String; keySize, ivSize: Int32): ICipherParameters;
+function TScryptParametersGenerator.GenerateDerivedParameters(const AAlgorithm: String;
+  AKeySize, AIvSize: Int32): ICipherParameters;
 var
-  dKey: TCryptoLibByteArray;
-  key: IKeyParameter;
+  LDKey: TCryptoLibByteArray;
+  LKey: IKeyParameter;
+  LKeySize, LIvSize: Int32;
 begin
-  keySize := keySize div 8;
-  ivSize := ivSize div 8;
-
-  dKey := GenerateDerivedKey(keySize + ivSize);
-  key := TParameterUtilities.CreateKeyParameter(algorithm, dKey, 0, keySize);
-
-  result := TParametersWithIV.Create(key, dKey, keySize, ivSize);
+  LKeySize := AKeySize div 8;
+  LIvSize := AIvSize div 8;
+  LDKey := GenerateDerivedKey(LKeySize + LIvSize);
+  LKey := TParameterUtilities.CreateKeyParameter(AAlgorithm, LDKey, 0, LKeySize);
+  Result := TParametersWithIV.Create(LKey, LDKey, LKeySize, LIvSize);
 end;
 
-procedure TScryptParametersGenerator.Init(const password,
-  salt: TCryptoLibByteArray; cost, blockSize, parallelism: Int32);
+procedure TScryptParametersGenerator.Init(const APassword, ASalt: TCryptoLibByteArray;
+  ACost, ABlockSize, AParallelism: Int32);
 begin
-  FPassword := System.Copy(password);
-  FSalt := System.Copy(salt);
-  FPBKDF_Scrypt := TKDF.TPBKDF_Scrypt.CreatePBKDF_Scrypt(FPassword, FSalt, cost,
-    blockSize, parallelism);
+  FPassword := System.Copy(APassword);
+  FSalt := System.Copy(ASalt);
+  FPBKDF_Scrypt := TKDF.TPBKDF_Scrypt.CreatePBKDF_Scrypt(FPassword, FSalt, ACost,
+    ABlockSize, AParallelism);
 end;
 
 end.

+ 12 - 21
CryptoLib/src/Crypto/Generators/ClpX25519KeyPairGenerator.pas → CryptoLib/src/Crypto/Generators/ClpX25519Generators.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpX25519KeyPairGenerator;
+unit ClpX25519Generators;
 
 {$I ..\..\Include\CryptoLib.inc}
 
@@ -23,10 +23,9 @@ interface
 
 uses
   ClpAsymmetricCipherKeyPair,
-  ClpIX25519KeyPairGenerator,
-  ClpIX25519PrivateKeyParameters,
-  ClpX25519PrivateKeyParameters,
-  ClpIX25519PublicKeyParameters,
+  ClpIX25519Generators,
+  ClpIX25519Parameters,
+  ClpX25519Parameters,
   ClpISecureRandom,
   ClpIKeyGenerationParameters,
   ClpIAsymmetricCipherKeyPair,
@@ -35,36 +34,28 @@ uses
 type
   TX25519KeyPairGenerator = class sealed(TInterfacedObject,
     IX25519KeyPairGenerator, IAsymmetricCipherKeyPairGenerator)
-
   strict private
-  var
     FRandom: ISecureRandom;
-
   public
-    procedure Init(const parameters: IKeyGenerationParameters);
-
+    procedure Init(const AParameters: IKeyGenerationParameters);
     function GenerateKeyPair(): IAsymmetricCipherKeyPair;
-
   end;
 
 implementation
 
-{ TX25519KeyPairGenerator }
-
 function TX25519KeyPairGenerator.GenerateKeyPair: IAsymmetricCipherKeyPair;
 var
-  privateKey: IX25519PrivateKeyParameters;
-  publicKey: IX25519PublicKeyParameters;
+  LPrivateKey: IX25519PrivateKeyParameters;
+  LPublicKey: IX25519PublicKeyParameters;
 begin
-  privateKey := TX25519PrivateKeyParameters.Create(FRandom);
-  publicKey := privateKey.GeneratePublicKey();
-  result := TAsymmetricCipherKeyPair.Create(publicKey, privateKey);
+  LPrivateKey := TX25519PrivateKeyParameters.Create(FRandom);
+  LPublicKey := LPrivateKey.GeneratePublicKey();
+  Result := TAsymmetricCipherKeyPair.Create(LPublicKey, LPrivateKey);
 end;
 
-procedure TX25519KeyPairGenerator.Init(const parameters
-  : IKeyGenerationParameters);
+procedure TX25519KeyPairGenerator.Init(const AParameters: IKeyGenerationParameters);
 begin
-  FRandom := parameters.Random;
+  FRandom := AParameters.Random;
 end;
 
 end.

+ 13 - 13
CryptoLib/src/Crypto/Parameters/ClpAsymmetricKeyParameter.pas

@@ -31,18 +31,18 @@ type
 
   strict private
   var
-    FprivateKey: Boolean;
+    FPrivateKey: Boolean;
 
   strict protected
     function GetPrivateKey: Boolean; inline;
     function GetIsPrivate: Boolean; inline;
 
-    constructor Create(privateKey: Boolean);
+    constructor Create(APrivateKey: Boolean);
 
   public
     property IsPrivate: Boolean read GetIsPrivate;
-    property privateKey: Boolean read GetPrivateKey;
-    function Equals(const other: IAsymmetricKeyParameter): Boolean; reintroduce;
+    property PrivateKey: Boolean read GetPrivateKey;
+    function Equals(const AOther: IAsymmetricKeyParameter): Boolean; reintroduce;
     function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}override;
 
@@ -52,37 +52,37 @@ implementation
 
 { TAsymmetricKeyParameter }
 
-constructor TAsymmetricKeyParameter.Create(privateKey: Boolean);
+constructor TAsymmetricKeyParameter.Create(APrivateKey: Boolean);
 begin
   inherited Create();
-  FprivateKey := privateKey;
+  FPrivateKey := APrivateKey;
 end;
 
-function TAsymmetricKeyParameter.Equals(const other
+function TAsymmetricKeyParameter.Equals(const AOther
   : IAsymmetricKeyParameter): Boolean;
 begin
-  if (other = Nil) then
+  if (AOther = nil) then
   begin
-    Result := false;
+    Result := False;
     Exit;
   end;
-  Result := FprivateKey = other.privateKey;
+  Result := FPrivateKey = AOther.PrivateKey;
 end;
 
 function TAsymmetricKeyParameter.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}
 begin
-  Result := Ord(FprivateKey);
+  Result := Ord(FPrivateKey);
 end;
 
 function TAsymmetricKeyParameter.GetIsPrivate: Boolean;
 begin
-  Result := FprivateKey;
+  Result := FPrivateKey;
 end;
 
 function TAsymmetricKeyParameter.GetPrivateKey: Boolean;
 begin
-  Result := FprivateKey;
+  Result := FPrivateKey;
 end;
 
 end.

+ 0 - 78
CryptoLib/src/Crypto/Parameters/ClpDHKeyGenerationParameters.pas

@@ -1,78 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHKeyGenerationParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpISecureRandom,
-  ClpIDHParameters,
-  ClpIDHKeyGenerationParameters,
-  ClpKeyGenerationParameters;
-
-type
-  TDHKeyGenerationParameters = class sealed(TKeyGenerationParameters,
-    IDHKeyGenerationParameters)
-  strict private
-  var
-    Fparameters: IDHParameters;
-
-    function GetParameters: IDHParameters; inline;
-
-    class function GetStrengthLocal(const parameters: IDHParameters): Int32;
-      static; inline;
-
-  public
-    constructor Create(const random: ISecureRandom;
-      const parameters: IDHParameters);
-
-    property parameters: IDHParameters read GetParameters;
-  end;
-
-implementation
-
-{ TDHKeyGenerationParameters }
-
-function TDHKeyGenerationParameters.GetParameters: IDHParameters;
-begin
-  result := Fparameters;
-end;
-
-class function TDHKeyGenerationParameters.GetStrengthLocal(const parameters
-  : IDHParameters): Int32;
-begin
-  if parameters.L <> 0 then
-  begin
-    result := parameters.L;
-  end
-  else
-  begin
-    result := parameters.P.BitLength;
-  end;
-end;
-
-constructor TDHKeyGenerationParameters.Create(const random: ISecureRandom;
-  const parameters: IDHParameters);
-begin
-  Inherited Create(random, GetStrengthLocal(parameters));
-  Fparameters := parameters;
-end;
-
-end.

+ 0 - 115
CryptoLib/src/Crypto/Parameters/ClpDHKeyParameters.pas

@@ -1,115 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDHParameters,
-  ClpIDHKeyParameters,
-  ClpPkcsObjectIdentifiers,
-  ClpIAsn1Objects,
-  ClpAsymmetricKeyParameter;
-
-type
-  TDHKeyParameters = class abstract(TAsymmetricKeyParameter, IDHKeyParameters)
-
-  strict private
-  var
-    Fparameters: IDHParameters;
-    FalgorithmOid: IDerObjectIdentifier;
-  strict protected
-    function GetParameters: IDHParameters;
-    function GetAlgorithmOid: IDerObjectIdentifier;
-
-    constructor Create(isPrivate: Boolean;
-      const parameters: IDHParameters); overload;
-
-    constructor Create(isPrivate: Boolean; const parameters: IDHParameters;
-      const algorithmOid: IDerObjectIdentifier); overload;
-
-  public
-    function Equals(const other: IDHKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property parameters: IDHParameters read GetParameters;
-    property algorithmOid: IDerObjectIdentifier read GetAlgorithmOid;
-
-  end;
-
-implementation
-
-{ TDHKeyParameters }
-
-function TDHKeyParameters.GetParameters: IDHParameters;
-begin
-  result := Fparameters;
-end;
-
-function TDHKeyParameters.GetAlgorithmOid: IDerObjectIdentifier;
-begin
-  result := FalgorithmOid;
-end;
-
-constructor TDHKeyParameters.Create(isPrivate: Boolean;
-  const parameters: IDHParameters);
-begin
-  Create(isPrivate, parameters, TPkcsObjectIdentifiers.DhKeyAgreement);
-end;
-
-constructor TDHKeyParameters.Create(isPrivate: Boolean;
-  const parameters: IDHParameters; const algorithmOid: IDerObjectIdentifier);
-begin
-  Inherited Create(isPrivate);
-  // TODO Should we allow parameters to be null?
-  Fparameters := parameters;
-  FalgorithmOid := algorithmOid;
-end;
-
-function TDHKeyParameters.Equals(const other: IDHKeyParameters): Boolean;
-begin
-  if other = Nil then
-  begin
-    result := False;
-    Exit;
-  end;
-  if ((Self as IDHKeyParameters) = other) then
-  begin
-    result := True;
-    Exit;
-  end;
-
-  result := Parameters.Equals(other.Parameters) and (Inherited Equals(other));
-end;
-
-function TDHKeyParameters.GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := Inherited GetHashCode();
-
-  if (parameters <> Nil) then
-  begin
-    result := result xor parameters.GetHashCode();
-  end;
-end;
-
-end.

+ 442 - 76
CryptoLib/src/Crypto/Parameters/ClpDHParameters.pas

@@ -25,8 +25,13 @@ uses
   Math,
   ClpICipherParameters,
   ClpIDHParameters,
-  ClpIDHValidationParameters,
+  ClpAsymmetricKeyParameter,
+  ClpPkcsObjectIdentifiers,
+  ClpIAsn1Objects,
+  ClpKeyGenerationParameters,
+  ClpISecureRandom,
   ClpBigInteger,
+  ClpArrayUtilities,
   ClpCryptoLibTypes;
 
 resourcestring
@@ -39,8 +44,33 @@ resourcestring
   SLErrorOne = 'when L value specified, it must be less than bitlength(P), "L"';
   SLErrorTwo = 'when L value specified, it may not be less than m value, "L"';
   SInvalidSubGroupFactor = 'Subgroup factor must be >= 2, "j"';
+  SSeedNil = '"Seed" Cannot Be Nil';
+  SYUnInitialized = '"Y" Cannot Be Uninitialized';
+  SInvalidDHPublicKey = 'Invalid DH public key "Y"';
+  SInvalidYInCorrectGroup = '"Y" Value Does Not Appear To Be In Correct Group';
+  SXUnInitialized = '"X" Cannot Be Uninitialized';
 
 type
+  TDHValidationParameters = class(TInterfacedObject, IDHValidationParameters)
+  strict private
+  var
+    FSeed: TCryptoLibByteArray;
+    FCounter: Int32;
+
+    function GetCounter: Int32; virtual;
+    function GetSeed: TCryptoLibByteArray; virtual;
+
+  public
+    constructor Create(const ASeed: TCryptoLibByteArray; ACounter: Int32);
+
+    function Equals(const AOther: IDHValidationParameters): Boolean; reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property Counter: Int32 read GetCounter;
+    property Seed: TCryptoLibByteArray read GetSeed;
+  end;
+
   TDHParameters = class(TInterfacedObject, ICipherParameters, IDHParameters)
 
   strict private
@@ -49,9 +79,9 @@ type
     DefaultMinimumLength = Int32(160);
 
   var
-    Fp, Fq, Fg, Fj: TBigInteger;
-    Fm, Fl: Int32;
-    Fvalidation: IDHValidationParameters;
+    FP, FQ, FG, FJ: TBigInteger;
+    FM, FL: Int32;
+    FValidation: IDHValidationParameters;
 
     function GetG: TBigInteger; inline;
     function GetP: TBigInteger; inline;
@@ -61,206 +91,542 @@ type
     function GetL: Int32; inline;
     function GetValidationParameters: IDHValidationParameters; inline;
 
-    class function GetDefaultMParam(lParam: Int32): Int32; static; inline;
+    class function GetDefaultMParam(ALParam: Int32): Int32; static; inline;
 
   public
 
-    constructor Create(const p, g: TBigInteger); overload;
+    constructor Create(const AP, AG: TBigInteger); overload;
 
-    constructor Create(const p, g, q: TBigInteger); overload;
+    constructor Create(const AP, AG, AQ: TBigInteger); overload;
 
-    constructor Create(const p, g, q: TBigInteger; l: Int32); overload;
+    constructor Create(const AP, AG, AQ: TBigInteger; AL: Int32); overload;
 
-    constructor Create(const p, g, q: TBigInteger; m, l: Int32); overload;
+    constructor Create(const AP, AG, AQ: TBigInteger; AM, AL: Int32); overload;
 
-    constructor Create(const p, g, q, j: TBigInteger;
-      const validation: IDHValidationParameters); overload;
+    constructor Create(const AP, AG, AQ, AJ: TBigInteger;
+      const AValidation: IDHValidationParameters); overload;
 
-    constructor Create(const p, g, q: TBigInteger; m, l: Int32;
-      const j: TBigInteger; const validation: IDHValidationParameters);
+    constructor Create(const AP, AG, AQ: TBigInteger; AM, AL: Int32;
+      const AJ: TBigInteger; const AValidation: IDHValidationParameters);
       overload;
 
-    function Equals(const other: IDHParameters): Boolean; reintroduce;
+    function Equals(const AOther: IDHParameters): 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 j: TBigInteger read GetJ;
-    /// <summary>The minimum bitlength of the private value.</summary>
-    property m: Int32 read GetM;
-    /// <summary>The bitlength of the private value.</summary>
-    property l: Int32 read GetL;
+    property P: TBigInteger read GetP;
+    property Q: TBigInteger read GetQ;
+    property G: TBigInteger read GetG;
+    property J: TBigInteger read GetJ;
+    property M: Int32 read GetM;
+    property L: Int32 read GetL;
     property ValidationParameters: IDHValidationParameters
       read GetValidationParameters;
 
   end;
 
+  TDHKeyParameters = class abstract(TAsymmetricKeyParameter, IDHKeyParameters)
+
+  strict private
+  var
+    FParameters: IDHParameters;
+    FAlgorithmOid: IDerObjectIdentifier;
+  strict protected
+    function GetParameters: IDHParameters;
+    function GetAlgorithmOid: IDerObjectIdentifier;
+
+    constructor Create(AIsPrivate: Boolean;
+      const AParameters: IDHParameters); overload;
+
+    constructor Create(AIsPrivate: Boolean; const AParameters: IDHParameters;
+      const AAlgorithmOid: IDerObjectIdentifier); overload;
+
+  public
+    function Equals(const AOther: IDHKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property Parameters: IDHParameters read GetParameters;
+    property AlgorithmOid: IDerObjectIdentifier read GetAlgorithmOid;
+
+  end;
+
+  TDHPublicKeyParameters = class sealed(TDHKeyParameters,
+    IDHPublicKeyParameters)
+
+  strict private
+  var
+    FY: TBigInteger;
+
+    class function Validate(const AY: TBigInteger; const ADHParams: IDHParameters)
+      : TBigInteger; static; inline;
+
+    function GetY: TBigInteger; inline;
+
+  public
+    constructor Create(const AY: TBigInteger;
+      const AParameters: IDHParameters); overload;
+
+    constructor Create(const AY: TBigInteger; const AParameters: IDHParameters;
+      const AAlgorithmOid: IDerObjectIdentifier); overload;
+
+    function Equals(const AOther: IDHPublicKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property Y: TBigInteger read GetY;
+  end;
+
+  TDHPrivateKeyParameters = class sealed(TDHKeyParameters,
+    IDHPrivateKeyParameters)
+
+  strict private
+  var
+    FX: TBigInteger;
+
+    function GetX: TBigInteger; inline;
+
+    class function Validate(const AX: TBigInteger): TBigInteger; static; inline;
+
+  public
+    constructor Create(const AX: TBigInteger;
+      const AParameters: IDHParameters); overload;
+
+    constructor Create(const AX: TBigInteger; const AParameters: IDHParameters;
+      const AAlgorithmOid: IDerObjectIdentifier); overload;
+
+    function Equals(const AOther: IDHPrivateKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property X: TBigInteger read GetX;
+  end;
+
+  TDHKeyGenerationParameters = class sealed(TKeyGenerationParameters,
+    IDHKeyGenerationParameters)
+  strict private
+  var
+    FParameters: IDHParameters;
+
+    function GetParameters: IDHParameters; inline;
+
+    class function GetStrengthLocal(const AParameters: IDHParameters): Int32;
+      static; inline;
+
+  public
+    constructor Create(const ARandom: ISecureRandom;
+      const AParameters: IDHParameters);
+
+    property Parameters: IDHParameters read GetParameters;
+  end;
+
 implementation
 
+{ TDHValidationParameters }
+
+constructor TDHValidationParameters.Create(const ASeed: TCryptoLibByteArray;
+  ACounter: Int32);
+begin
+  inherited Create();
+  if (ASeed = nil) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SSeedNil);
+  end;
+
+  FSeed := System.Copy(ASeed);
+  FCounter := ACounter;
+end;
+
+function TDHValidationParameters.Equals(const AOther: IDHValidationParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDHValidationParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+  Result := (Counter = AOther.Counter) and TArrayUtilities.AreEqual<Byte>(Seed,
+    AOther.Seed);
+end;
+
+function TDHValidationParameters.GetCounter: Int32;
+begin
+  Result := FCounter;
+end;
+
+function TDHValidationParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := Counter xor TArrayUtilities.GetArrayHashCode(Seed);
+end;
+
+function TDHValidationParameters.GetSeed: TCryptoLibByteArray;
+begin
+  Result := System.Copy(FSeed);
+end;
+
 { TDHParameters }
 
 function TDHParameters.GetL: Int32;
 begin
-  result := Fl;
+  Result := FL;
 end;
 
 function TDHParameters.GetM: Int32;
 begin
-  result := Fm;
+  Result := FM;
 end;
 
 function TDHParameters.GetJ: TBigInteger;
 begin
-  result := Fj;
+  Result := FJ;
 end;
 
 function TDHParameters.GetP: TBigInteger;
 begin
-  result := Fp;
+  Result := FP;
 end;
 
 function TDHParameters.GetQ: TBigInteger;
 begin
-  result := Fq;
+  Result := FQ;
 end;
 
 function TDHParameters.GetG: TBigInteger;
 begin
-  result := Fg;
+  Result := FG;
 end;
 
-class function TDHParameters.GetDefaultMParam(lParam: Int32): Int32;
+class function TDHParameters.GetDefaultMParam(ALParam: Int32): Int32;
 begin
-  if (lParam = 0) then
+  if (ALParam = 0) then
   begin
-    result := DefaultMinimumLength;
+    Result := DefaultMinimumLength;
     Exit;
   end;
 
-  result := Min(lParam, DefaultMinimumLength);
+  Result := Min(ALParam, DefaultMinimumLength);
 end;
 
-constructor TDHParameters.Create(const p, g: TBigInteger);
+constructor TDHParameters.Create(const AP, AG: TBigInteger);
 begin
-  Create(p, g, TBigInteger.GetDefault, 0);
+  Create(AP, AG, TBigInteger.GetDefault, 0);
 end;
 
-constructor TDHParameters.Create(const p, g, q: TBigInteger);
+constructor TDHParameters.Create(const AP, AG, AQ: TBigInteger);
 begin
-  Create(p, g, q, 0);
+  Create(AP, AG, AQ, 0);
 end;
 
-constructor TDHParameters.Create(const p, g, q: TBigInteger; l: Int32);
+constructor TDHParameters.Create(const AP, AG, AQ: TBigInteger; AL: Int32);
 begin
-  Create(p, g, q, GetDefaultMParam(l), l, TBigInteger.GetDefault, Nil);
+  Create(AP, AG, AQ, GetDefaultMParam(AL), AL, TBigInteger.GetDefault, nil);
 end;
 
-constructor TDHParameters.Create(const p, g, q: TBigInteger; m, l: Int32);
+constructor TDHParameters.Create(const AP, AG, AQ: TBigInteger; AM, AL: Int32);
 begin
-  Create(p, g, q, m, l, TBigInteger.GetDefault, Nil);
+  Create(AP, AG, AQ, AM, AL, TBigInteger.GetDefault, nil);
 end;
 
-constructor TDHParameters.Create(const p, g, q, j: TBigInteger;
-  const validation: IDHValidationParameters);
+constructor TDHParameters.Create(const AP, AG, AQ, AJ: TBigInteger;
+  const AValidation: IDHValidationParameters);
 begin
-  Create(p, g, q, DefaultMinimumLength, 0, j, validation)
+  Create(AP, AG, AQ, DefaultMinimumLength, 0, AJ, AValidation)
 end;
 
-constructor TDHParameters.Create(const p, g, q: TBigInteger; m, l: Int32;
-  const j: TBigInteger; const validation: IDHValidationParameters);
+constructor TDHParameters.Create(const AP, AG, AQ: TBigInteger; AM, AL: Int32;
+  const AJ: TBigInteger; const AValidation: IDHValidationParameters);
 begin
-  Inherited Create();
-  if (not(p.IsInitialized)) then
+  inherited Create();
+  if (not AP.IsInitialized) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SPUnInitialized);
   end;
 
-  if (not(g.IsInitialized)) then
+  if (not AG.IsInitialized) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SGUnInitialized);
   end;
 
-  if (not p.TestBit(0)) then
+  if (not AP.TestBit(0)) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SMustBeOddPrime);
   end;
 
-  if ((g.CompareTo(TBigInteger.Two) < 0) or
-    (g.CompareTo(p.Subtract(TBigInteger.Two)) > 0)) then
+  if ((AG.CompareTo(TBigInteger.Two) < 0) or
+    (AG.CompareTo(AP.Subtract(TBigInteger.Two)) > 0)) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SInvalidGeneratorRange);
   end;
 
-  if ((q.IsInitialized) and (q.BitLength >= p.BitLength)) then
+  if ((AQ.IsInitialized) and (AQ.BitLength >= AP.BitLength)) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SQTooBigToBeAFactor);
   end;
 
-  if (m >= p.BitLength) then
+  if (AM >= AP.BitLength) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SMTooBig);
   end;
 
-  if (l <> 0) then
+  if (AL <> 0) then
   begin
 
-    if (l >= p.BitLength) then
+    if (AL >= AP.BitLength) then
     begin
       raise EArgumentCryptoLibException.CreateRes(@SLErrorOne);
     end;
-    if (l < m) then
+    if (AL < AM) then
     begin
       raise EArgumentCryptoLibException.CreateRes(@SLErrorTwo);
     end;
   end;
 
-  if ((j.IsInitialized) and (j.CompareTo(TBigInteger.Two) < 0)) then
+  if ((AJ.IsInitialized) and (AJ.CompareTo(TBigInteger.Two) < 0)) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SInvalidSubGroupFactor);
   end;
 
-  // TODO If q, j both provided, validate p = jq + 1 ?
-
-  Fp := p;
-  Fg := g;
-  Fq := q;
-  Fm := m;
-  Fl := l;
-  Fj := j;
-  Fvalidation := validation;
+  FP := AP;
+  FG := AG;
+  FQ := AQ;
+  FM := AM;
+  FL := AL;
+  FJ := AJ;
+  FValidation := AValidation;
 end;
 
-function TDHParameters.Equals(const other: IDHParameters): Boolean;
+function TDHParameters.Equals(const AOther: IDHParameters): Boolean;
 begin
-  if other = Nil then
+  if AOther = nil then
   begin
-    result := False;
+    Result := False;
     Exit;
   end;
-  if ((Self as IDHParameters) = other) then
+  if ((Self as IDHParameters) = AOther) then
   begin
-    result := True;
+    Result := True;
     Exit;
   end;
-  result := p.Equals(other.p) and q.Equals(other.q) and g.Equals(other.g);
+  Result := P.Equals(AOther.P) and Q.Equals(AOther.Q) and G.Equals(AOther.G);
 end;
 
 function TDHParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}
 begin
-  result := p.GetHashCode() xor g.GetHashCode();
+  Result := P.GetHashCode() xor G.GetHashCode();
 
-  if Fq.IsInitialized then
+  if FQ.IsInitialized then
   begin
-    result := result xor q.GetHashCode();
+    Result := Result xor Q.GetHashCode();
   end;
 end;
 
 function TDHParameters.GetValidationParameters: IDHValidationParameters;
 begin
-  result := Fvalidation;
+  Result := FValidation;
+end;
+
+{ TDHKeyParameters }
+
+function TDHKeyParameters.GetParameters: IDHParameters;
+begin
+  Result := FParameters;
+end;
+
+function TDHKeyParameters.GetAlgorithmOid: IDerObjectIdentifier;
+begin
+  Result := FAlgorithmOid;
+end;
+
+constructor TDHKeyParameters.Create(AIsPrivate: Boolean;
+  const AParameters: IDHParameters);
+begin
+  Create(AIsPrivate, AParameters, TPkcsObjectIdentifiers.DhKeyAgreement);
+end;
+
+constructor TDHKeyParameters.Create(AIsPrivate: Boolean;
+  const AParameters: IDHParameters; const AAlgorithmOid: IDerObjectIdentifier);
+begin
+  inherited Create(AIsPrivate);
+  FParameters := AParameters;
+  FAlgorithmOid := AAlgorithmOid;
+end;
+
+function TDHKeyParameters.Equals(const AOther: IDHKeyParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDHKeyParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  Result := Parameters.Equals(AOther.Parameters) and (inherited Equals(AOther));
+end;
+
+function TDHKeyParameters.GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := inherited GetHashCode();
+
+  if (Parameters <> nil) then
+  begin
+    Result := Result xor Parameters.GetHashCode();
+  end;
+end;
+
+{ TDHPublicKeyParameters }
+
+function TDHPublicKeyParameters.GetY: TBigInteger;
+begin
+  Result := FY;
+end;
+
+class function TDHPublicKeyParameters.Validate(const AY: TBigInteger;
+  const ADHParams: IDHParameters): TBigInteger;
+begin
+  if (not AY.IsInitialized) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SYUnInitialized);
+  end;
+
+  if ((AY.CompareTo(TBigInteger.Two) < 0) or
+    (AY.CompareTo(ADHParams.P.Subtract(TBigInteger.Two)) > 0)) then
+  begin
+    raise EArgumentCryptoLibException.CreateRes(@SInvalidDHPublicKey);
+  end;
+
+  if ((ADHParams.Q.IsInitialized) and
+    (not AY.ModPow(ADHParams.Q, ADHParams.P).Equals(TBigInteger.One))) then
+  begin
+    raise EArgumentCryptoLibException.CreateRes(@SInvalidYInCorrectGroup);
+  end;
+
+  Result := AY;
+end;
+
+constructor TDHPublicKeyParameters.Create(const AY: TBigInteger;
+  const AParameters: IDHParameters);
+begin
+  inherited Create(False, AParameters);
+  FY := Validate(AY, AParameters);
+end;
+
+constructor TDHPublicKeyParameters.Create(const AY: TBigInteger;
+  const AParameters: IDHParameters; const AAlgorithmOid: IDerObjectIdentifier);
+begin
+  inherited Create(False, AParameters, AAlgorithmOid);
+  FY := Validate(AY, AParameters);
+end;
+
+function TDHPublicKeyParameters.Equals(const AOther: IDHPublicKeyParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDHPublicKeyParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+  Result := (Y.Equals(AOther.Y)) and (inherited Equals(AOther));
+end;
+
+function TDHPublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := Y.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TDHPrivateKeyParameters }
+
+function TDHPrivateKeyParameters.GetX: TBigInteger;
+begin
+  Result := FX;
+end;
+
+class function TDHPrivateKeyParameters.Validate(const AX: TBigInteger): TBigInteger;
+begin
+  if (not AX.IsInitialized) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SXUnInitialized);
+  end;
+  Result := AX;
+end;
+
+constructor TDHPrivateKeyParameters.Create(const AX: TBigInteger;
+  const AParameters: IDHParameters);
+begin
+  inherited Create(True, AParameters);
+  FX := Validate(AX);
+end;
+
+constructor TDHPrivateKeyParameters.Create(const AX: TBigInteger;
+  const AParameters: IDHParameters; const AAlgorithmOid: IDerObjectIdentifier);
+begin
+  inherited Create(True, AParameters, AAlgorithmOid);
+  FX := Validate(AX);
+end;
+
+function TDHPrivateKeyParameters.Equals(const AOther: IDHPrivateKeyParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDHPrivateKeyParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+  Result := (X.Equals(AOther.X)) and (inherited Equals(AOther));
+end;
+
+function TDHPrivateKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := X.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TDHKeyGenerationParameters }
+
+function TDHKeyGenerationParameters.GetParameters: IDHParameters;
+begin
+  Result := FParameters;
+end;
+
+class function TDHKeyGenerationParameters.GetStrengthLocal(const AParameters: IDHParameters): Int32;
+begin
+  if AParameters.L <> 0 then
+  begin
+    Result := AParameters.L;
+  end
+  else
+  begin
+    Result := AParameters.P.BitLength;
+  end;
+end;
+
+constructor TDHKeyGenerationParameters.Create(const ARandom: ISecureRandom;
+  const AParameters: IDHParameters);
+begin
+  inherited Create(ARandom, GetStrengthLocal(AParameters));
+  FParameters := AParameters;
 end;
 
 end.

+ 0 - 117
CryptoLib/src/Crypto/Parameters/ClpDHPrivateKeyParameters.pas

@@ -1,117 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHPrivateKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDHParameters,
-  ClpIDHPrivateKeyParameters,
-  ClpDHKeyParameters,
-  ClpIAsn1Objects,
-  ClpBigInteger,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SXUnInitialized = '"X" Cannot Be Uninitialized';
-
-type
-  TDHPrivateKeyParameters = class sealed(TDHKeyParameters,
-    IDHPrivateKeyParameters)
-
-  strict private
-  var
-    Fx: TBigInteger;
-
-    function GetX: TBigInteger; inline;
-
-    class function Validate(const x: TBigInteger): TBigInteger; static; inline;
-
-  public
-    constructor Create(const x: TBigInteger;
-      const parameters: IDHParameters); overload;
-
-    constructor Create(const x: TBigInteger; const parameters: IDHParameters;
-      const algorithmOid: IDerObjectIdentifier); overload;
-
-    function Equals(const other: IDHPrivateKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property x: TBigInteger read GetX;
-  end;
-
-implementation
-
-{ TDHPrivateKeyParameters }
-
-function TDHPrivateKeyParameters.GetX: TBigInteger;
-begin
-  result := Fx;
-end;
-
-class function TDHPrivateKeyParameters.Validate(const x: TBigInteger)
-  : TBigInteger;
-begin
-  if (not(x.IsInitialized)) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SXUnInitialized);
-  end;
-  result := x;
-end;
-
-constructor TDHPrivateKeyParameters.Create(const x: TBigInteger;
-  const parameters: IDHParameters);
-begin
-  Inherited Create(true, parameters);
-  Fx := Validate(x);
-end;
-
-constructor TDHPrivateKeyParameters.Create(const x: TBigInteger;
-  const parameters: IDHParameters; const algorithmOid: IDerObjectIdentifier);
-begin
-  Inherited Create(true, parameters, algorithmOid);
-  Fx := Validate(x);
-end;
-
-function TDHPrivateKeyParameters.Equals(const other
-  : IDHPrivateKeyParameters): Boolean;
-begin
-  if other = Nil then
-  begin
-    result := False;
-    Exit;
-  end;
-  if ((Self as IDHPrivateKeyParameters) = other) then
-  begin
-    result := true;
-    Exit;
-  end;
-  result := (x.Equals(other.x)) and (Inherited Equals(other));
-end;
-
-function TDHPrivateKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := x.GetHashCode() xor (Inherited GetHashCode());
-end;
-
-end.

+ 0 - 135
CryptoLib/src/Crypto/Parameters/ClpDHPublicKeyParameters.pas

@@ -1,135 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHPublicKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDHParameters,
-  ClpIDHPublicKeyParameters,
-  ClpIAsn1Objects,
-  ClpDHKeyParameters,
-  ClpBigInteger,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SYUnInitialized = '"Y" Cannot Be Uninitialized';
-  SInvalidDHPublicKey = 'Invalid DH public key "Y"';
-  SInvalidYInCorrectGroup = '"Y" Value Does Not Appear To Be In Correct Group';
-
-type
-  TDHPublicKeyParameters = class sealed(TDHKeyParameters,
-    IDHPublicKeyParameters)
-
-  strict private
-  var
-    Fy: TBigInteger;
-
-    class function Validate(const y: TBigInteger; const dhParams: IDHParameters)
-      : TBigInteger; static; inline;
-
-    function GetY: TBigInteger; inline;
-
-  public
-    constructor Create(const y: TBigInteger;
-      const parameters: IDHParameters); overload;
-
-    constructor Create(const y: TBigInteger; const parameters: IDHParameters;
-      const algorithmOid: IDerObjectIdentifier); overload;
-
-    function Equals(const other: IDHPublicKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property y: TBigInteger read GetY;
-  end;
-
-implementation
-
-{ TDHPublicKeyParameters }
-
-function TDHPublicKeyParameters.GetY: TBigInteger;
-begin
-  result := Fy;
-end;
-
-class function TDHPublicKeyParameters.Validate(const y: TBigInteger;
-  const dhParams: IDHParameters): TBigInteger;
-begin
-  if (not(y.IsInitialized)) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SYUnInitialized);
-  end;
-
-  // TLS check
-  if ((y.CompareTo(TBigInteger.Two) < 0) or
-    (y.CompareTo(dhParams.P.Subtract(TBigInteger.Two)) > 0)) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidDHPublicKey);
-  end;
-
-  // we can't validate without Q.
-  if ((dhParams.Q.IsInitialized) and
-    (not(y.ModPow(dhParams.Q, dhParams.P).Equals(TBigInteger.One)))) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidYInCorrectGroup);
-  end;
-
-  result := y;
-end;
-
-constructor TDHPublicKeyParameters.Create(const y: TBigInteger;
-  const parameters: IDHParameters);
-begin
-  Inherited Create(false, parameters);
-  Fy := Validate(y, parameters);
-end;
-
-constructor TDHPublicKeyParameters.Create(const y: TBigInteger;
-  const parameters: IDHParameters; const algorithmOid: IDerObjectIdentifier);
-begin
-  Inherited Create(false, parameters, algorithmOid);
-  Fy := Validate(y, parameters);
-end;
-
-function TDHPublicKeyParameters.Equals(const other
-  : IDHPublicKeyParameters): Boolean;
-begin
-  if other = Nil then
-  begin
-    result := false;
-    Exit;
-  end;
-  if ((Self as IDHPublicKeyParameters) = other) then
-  begin
-    result := True;
-    Exit;
-  end;
-  result := (y.Equals(other.y)) and (Inherited Equals(other));
-end;
-
-function TDHPublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := y.GetHashCode() xor (Inherited GetHashCode());
-end;
-
-end.

+ 0 - 103
CryptoLib/src/Crypto/Parameters/ClpDHValidationParameters.pas

@@ -1,103 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDHValidationParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDHValidationParameters,
-  ClpArrayUtilities,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SSeedNil = '"Seed" Cannot Be Nil';
-
-type
-  TDHValidationParameters = class(TInterfacedObject, IDHValidationParameters)
-  strict private
-  var
-    Fseed: TCryptoLibByteArray;
-    Fcounter: Int32;
-
-    function GetCounter: Int32; virtual;
-    function GetSeed: TCryptoLibByteArray; virtual;
-
-  public
-    constructor Create(const seed: TCryptoLibByteArray; counter: Int32);
-
-    function Equals(const other: IDHValidationParameters): Boolean; reintroduce;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property counter: Int32 read GetCounter;
-    property seed: TCryptoLibByteArray read GetSeed;
-  end;
-
-implementation
-
-{ TDHValidationParameters }
-
-constructor TDHValidationParameters.Create(const seed: TCryptoLibByteArray;
-  counter: Int32);
-begin
-  Inherited Create();
-  if (seed = Nil) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SSeedNil);
-  end;
-
-  Fseed := System.Copy(seed);
-  Fcounter := counter;
-end;
-
-function TDHValidationParameters.Equals(const other
-  : IDHValidationParameters): Boolean;
-begin
-  if other = Nil then
-  begin
-    result := False;
-    Exit;
-  end;
-  if ((Self as IDHValidationParameters) = other) then
-  begin
-    result := True;
-    Exit;
-  end;
-  result := (counter = other.counter) and TArrayUtilities.AreEqual<Byte>(seed,
-    other.seed);
-end;
-
-function TDHValidationParameters.GetCounter: Int32;
-begin
-  result := Fcounter;
-end;
-
-function TDHValidationParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := counter xor TArrayUtilities.GetArrayHashCode(seed);
-end;
-
-function TDHValidationParameters.GetSeed: TCryptoLibByteArray;
-begin
-  result := System.Copy(Fseed);
-end;
-
-end.

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

@@ -1,66 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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.

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

@@ -1,94 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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,
-  ClpAsymmetricKeyParameter;
-
-type
-  TDsaKeyParameters = class abstract(TAsymmetricKeyParameter, IDsaKeyParameters)
-
-  strict private
-  var
-    Fparameters: IDsaParameters;
-  strict protected
-    function GetParameters: IDsaParameters;
-    constructor Create(isPrivate: Boolean; const parameters: IDsaParameters);
-
-  public
-    function Equals(const other: IDsaKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property Parameters: IDsaParameters read GetParameters;
-
-  end;
-
-implementation
-
-{ TDsaKeyParameters }
-
-constructor TDsaKeyParameters.Create(isPrivate: Boolean;
-  const 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.Equals(other.Parameters) 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.

+ 0 - 146
CryptoLib/src/Crypto/Parameters/ClpDsaParameterGenerationParameters.pas

@@ -1,146 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpDsaParameterGenerationParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpISecureRandom,
-  ClpIDsaParameterGenerationParameters;
-
-type
-  TDsaParameterGenerationParameters = class(TInterfacedObject,
-    IDsaParameterGenerationParameters)
-
-  strict private
-  var
-    Fl, Fn, Fcertainty, FusageIndex: Int32;
-    Frandom: ISecureRandom;
-
-  strict protected
-
-    function GetL: Int32; virtual;
-    function GetN: Int32; virtual;
-    function GetCertainty: Int32; virtual;
-    function GetUsageIndex: Int32; virtual;
-    function GetRandom: ISecureRandom; virtual;
-
-  public
-
-    const
-    DigitalSignatureUsage = Int32(1);
-    KeyEstablishmentUsage = Int32(2);
-
-    /// <summary>
-    /// Construct without a usage index, this will do a random construction
-    /// of G.
-    /// </summary>
-    /// <param name="L">
-    /// desired length of prime P in bits (the effective key size).
-    /// </param>
-    /// <param name="N">
-    /// desired length of prime Q in bits.
-    /// </param>
-    /// <param name="certainty">
-    /// certainty level for prime number generation.
-    /// </param>
-    /// <param name="random">
-    /// the source of randomness to use.
-    /// </param>
-    constructor Create(L, N, certainty: Int32;
-      const random: ISecureRandom); overload;
-
-    /// <summary>
-    /// Construct without a usage index, this will do a random construction
-    /// of G.
-    /// </summary>
-    /// <param name="L">
-    /// desired length of prime P in bits (the effective key size).
-    /// </param>
-    /// <param name="N">
-    /// desired length of prime Q in bits.
-    /// </param>
-    /// <param name="certainty">
-    /// certainty level for prime number generation.
-    /// </param>
-    /// <param name="random">
-    /// the source of randomness to use.
-    /// </param>
-    /// <param name="usageIndex">
-    /// a valid usage index.
-    /// </param>
-    constructor Create(L, N, certainty: Int32; const random: ISecureRandom;
-      usageIndex: Int32); overload;
-
-    property L: Int32 read GetL;
-    property N: Int32 read GetN;
-    property usageIndex: Int32 read GetUsageIndex;
-    property certainty: Int32 read GetCertainty;
-    property random: ISecureRandom read GetRandom;
-
-  end;
-
-implementation
-
-{ TDsaParameterGenerationParameters }
-
-constructor TDsaParameterGenerationParameters.Create(L, N, certainty: Int32;
-  const random: ISecureRandom);
-begin
-  Create(L, N, certainty, random, -1);
-end;
-
-constructor TDsaParameterGenerationParameters.Create(L, N, certainty: Int32;
-  const random: ISecureRandom; usageIndex: Int32);
-begin
-  Inherited Create();
-  Fl := L;
-  Fn := N;
-  Fcertainty := certainty;
-  Frandom := random;
-  FusageIndex := usageIndex;
-end;
-
-function TDsaParameterGenerationParameters.GetL: Int32;
-begin
-  result := Fl;
-end;
-
-function TDsaParameterGenerationParameters.GetN: Int32;
-begin
-  result := Fn;
-end;
-
-function TDsaParameterGenerationParameters.GetCertainty: Int32;
-begin
-  result := Fcertainty;
-end;
-
-function TDsaParameterGenerationParameters.GetUsageIndex: Int32;
-begin
-  result := FusageIndex;
-end;
-
-function TDsaParameterGenerationParameters.GetRandom: ISecureRandom;
-begin
-  result := Frandom;
-end;
-
-end.

+ 442 - 62
CryptoLib/src/Crypto/Parameters/ClpDsaParameters.pas

@@ -24,22 +24,55 @@ interface
 uses
   ClpICipherParameters,
   ClpIDsaParameters,
-  ClpIDsaValidationParameters,
+  ClpAsymmetricKeyParameter,
   ClpBigInteger,
+  ClpKeyGenerationParameters,
+  ClpISecureRandom,
+  ClpArrayUtilities,
   ClpCryptoLibTypes;
 
 resourcestring
   SPUnInitialized = '"P" Cannot Be Uninitialized';
   SQUnInitialized = '"Q" Cannot Be Uninitialized';
   SGUnInitialized = '"G" Cannot Be Uninitialized';
+  SSeedNil = '"Seed" Cannot Be Nil';
+  SYUnInitialized = '"Y" Cannot Be Uninitialized';
+  SInvalidYInCorrectGroup = '"Y" Value Does Not Appear To Be In Correct Group';
+  SXUnInitialized = '"X" Cannot Be Uninitialized';
 
 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(const ASeed: TCryptoLibByteArray;
+      ACounter: Int32); overload;
+    constructor Create(const ASeed: TCryptoLibByteArray;
+      ACounter, AUsageIndex: Int32); overload;
+
+    function Equals(const AOther: 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;
+
   TDsaParameters = class(TInterfacedObject, ICipherParameters, IDsaParameters)
 
   strict private
   var
-    Fp, Fq, Fg: TBigInteger;
-    Fvalidation: IDsaValidationParameters;
+    FP, FQ, FG: TBigInteger;
+    FValidation: IDsaValidationParameters;
 
     function GetG: TBigInteger; inline;
     function GetP: TBigInteger; inline;
@@ -48,123 +81,470 @@ type
 
   public
 
-    /// <summary>
-    /// Creates a new DSAParameter with the specified parameter values.
-    /// </summary>
-    /// <param name="p">
-    /// the prime.
-    /// </param>
-    /// <param name="q">
-    /// the sub-prime.
-    /// </param>
-    /// <param name="g">
-    /// the base.
-    /// </param>
-    constructor Create(const p, q, g: TBigInteger); overload;
-    /// <summary>
-    /// Creates a new DSAParameter with the specified parameter values.
-    /// </summary>
-    /// <param name="p">
-    /// the prime.
-    /// </param>
-    /// <param name="q">
-    /// the sub-prime.
-    /// </param>
-    /// <param name="g">
-    /// the base.
-    /// </param>
-    /// <param name="parameters">
-    /// dsa validation parameters (this includes the seed, counter and usage
-    /// index)
-    /// </param>
-    constructor Create(const p, q, g: TBigInteger;
-      const parameters: IDsaValidationParameters); overload;
-
-    function Equals(const other: IDsaParameters): Boolean; reintroduce;
+    constructor Create(const AP, AQ, AG: TBigInteger); overload;
+    constructor Create(const AP, AQ, AG: TBigInteger;
+      const AValidationParameters: IDsaValidationParameters); overload;
+
+    function Equals(const AOther: 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 P: TBigInteger read GetP;
+    property Q: TBigInteger read GetQ;
+    property G: TBigInteger read GetG;
     property ValidationParameters: IDsaValidationParameters
       read GetValidationParameters;
 
   end;
 
+  TDsaKeyParameters = class abstract(TAsymmetricKeyParameter, IDsaKeyParameters)
+
+  strict private
+  var
+    FParameters: IDsaParameters;
+  strict protected
+    function GetParameters: IDsaParameters;
+    constructor Create(AIsPrivate: Boolean; const AParameters: IDsaParameters);
+
+  public
+    function Equals(const AOther: IDsaKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property Parameters: IDsaParameters read GetParameters;
+
+  end;
+
+  TDsaPublicKeyParameters = class sealed(TDsaKeyParameters,
+    IDsaPublicKeyParameters)
+
+  strict private
+  var
+    FY: TBigInteger;
+
+    class function Validate(const AY: TBigInteger;
+      const AParameters: IDsaParameters): TBigInteger; static; inline;
+
+    function GetY: TBigInteger; inline;
+
+  public
+    constructor Create(const AY: TBigInteger; const AParameters: IDsaParameters);
+
+    function Equals(const AOther: IDsaPublicKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property Y: TBigInteger read GetY;
+  end;
+
+  TDsaPrivateKeyParameters = class sealed(TDsaKeyParameters,
+    IDsaPrivateKeyParameters)
+
+  strict private
+  var
+    FX: TBigInteger;
+
+    function GetX: TBigInteger; inline;
+
+    class function Validate(const AX: TBigInteger): TBigInteger; static; inline;
+
+  public
+    constructor Create(const AX: TBigInteger; const AParameters: IDsaParameters);
+
+    function Equals(const AOther: IDsaPrivateKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+    property X: TBigInteger read GetX;
+  end;
+
+  TDsaKeyGenerationParameters = class sealed(TKeyGenerationParameters,
+    IDsaKeyGenerationParameters)
+  strict private
+  var
+    FParameters: IDsaParameters;
+
+    function GetParameters: IDsaParameters; inline;
+
+  public
+    constructor Create(const ARandom: ISecureRandom;
+      const AParameters: IDsaParameters);
+
+    property Parameters: IDsaParameters read GetParameters;
+  end;
+
+  TDsaParameterGenerationParameters = class(TInterfacedObject,
+    IDsaParameterGenerationParameters)
+
+  strict private
+  var
+    FL, FN, FCertainty, FUsageIndex: Int32;
+    FRandom: ISecureRandom;
+
+  strict protected
+
+    function GetL: Int32; virtual;
+    function GetN: Int32; virtual;
+    function GetCertainty: Int32; virtual;
+    function GetUsageIndex: Int32; virtual;
+    function GetRandom: ISecureRandom; virtual;
+
+  public
+
+    const
+    DigitalSignatureUsage = Int32(1);
+    KeyEstablishmentUsage = Int32(2);
+
+    constructor Create(AL, AN, ACertainty: Int32;
+      const ARandom: ISecureRandom); overload;
+
+    constructor Create(AL, AN, ACertainty: Int32; const ARandom: ISecureRandom;
+      AUsageIndex: Int32); overload;
+
+    property L: Int32 read GetL;
+    property N: Int32 read GetN;
+    property UsageIndex: Int32 read GetUsageIndex;
+    property Certainty: Int32 read GetCertainty;
+    property Random: ISecureRandom read GetRandom;
+
+  end;
+
 implementation
 
+{ TDsaValidationParameters }
+
+constructor TDsaValidationParameters.Create(const ASeed: TCryptoLibByteArray;
+  ACounter: Int32);
+begin
+  Create(ASeed, ACounter, -1);
+end;
+
+constructor TDsaValidationParameters.Create(const ASeed: TCryptoLibByteArray;
+  ACounter, AUsageIndex: Int32);
+begin
+  inherited Create();
+  if (ASeed = nil) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SSeedNil);
+  end;
+
+  FSeed := System.Copy(ASeed);
+  FCounter := ACounter;
+  FUsageIndex := AUsageIndex;
+end;
+
+function TDsaValidationParameters.Equals(const AOther: IDsaValidationParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDsaValidationParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+  Result := (Counter = AOther.Counter) and TArrayUtilities.AreEqual<Byte>(Seed,
+    AOther.Seed);
+end;
+
+function TDsaValidationParameters.GetCounter: Int32;
+begin
+  Result := FCounter;
+end;
+
+function TDsaValidationParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := Counter xor TArrayUtilities.GetArrayHashCode(Seed);
+end;
+
+function TDsaValidationParameters.GetSeed: TCryptoLibByteArray;
+begin
+  Result := System.Copy(FSeed);
+end;
+
+function TDsaValidationParameters.GetUsageIndex: Int32;
+begin
+  Result := FUsageIndex;
+end;
+
 { TDsaParameters }
 
 function TDsaParameters.GetG: TBigInteger;
 begin
-  result := Fg;
+  Result := FG;
 end;
 
 function TDsaParameters.GetP: TBigInteger;
 begin
-  result := Fp;
+  Result := FP;
 end;
 
 function TDsaParameters.GetQ: TBigInteger;
 begin
-  result := Fq;
+  Result := FQ;
 end;
 
 function TDsaParameters.GetValidationParameters: IDsaValidationParameters;
 begin
-  result := Fvalidation;
+  Result := FValidation;
 end;
 
-constructor TDsaParameters.Create(const p, q, g: TBigInteger);
+constructor TDsaParameters.Create(const AP, AQ, AG: TBigInteger);
 begin
-  Create(p, q, g, Nil);
+  Create(AP, AQ, AG, nil);
 end;
 
-constructor TDsaParameters.Create(const p, q, g: TBigInteger;
-  const parameters: IDsaValidationParameters);
+constructor TDsaParameters.Create(const AP, AQ, AG: TBigInteger;
+  const AValidationParameters: IDsaValidationParameters);
 begin
-  Inherited Create();
-  if (not(p.IsInitialized)) then
+  inherited Create();
+  if (not AP.IsInitialized) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SPUnInitialized);
   end;
 
-  if (not(q.IsInitialized)) then
+  if (not AQ.IsInitialized) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SQUnInitialized);
   end;
 
-  if (not(g.IsInitialized)) then
+  if (not AG.IsInitialized) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SGUnInitialized);
   end;
 
-  Fp := p;
-  Fq := q;
-  Fg := g;
-  Fvalidation := parameters;
+  FP := AP;
+  FQ := AQ;
+  FG := AG;
+  FValidation := AValidationParameters;
 end;
 
-function TDsaParameters.Equals(const other: IDsaParameters): Boolean;
+function TDsaParameters.Equals(const AOther: IDsaParameters): Boolean;
 begin
-  if other = Nil then
+  if AOther = nil then
   begin
-    result := False;
+    Result := False;
     Exit;
   end;
-  if ((Self as IDsaParameters) = other) then
+  if ((Self as IDsaParameters) = AOther) then
   begin
-    result := True;
+    Result := True;
     Exit;
   end;
-  result := p.Equals(other.p) and q.Equals(other.q) and g.Equals(other.g);
+  Result := P.Equals(AOther.P) and Q.Equals(AOther.Q) and G.Equals(AOther.G);
 end;
 
 function TDsaParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}
 begin
-  result := p.GetHashCode() xor q.GetHashCode() xor g.GetHashCode();
+  Result := P.GetHashCode() xor Q.GetHashCode() xor G.GetHashCode();
+end;
+
+{ TDsaKeyParameters }
+
+constructor TDsaKeyParameters.Create(AIsPrivate: Boolean;
+  const AParameters: IDsaParameters);
+begin
+  inherited Create(AIsPrivate);
+  FParameters := AParameters;
+end;
+
+function TDsaKeyParameters.Equals(const AOther: IDsaKeyParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDsaKeyParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  Result := Parameters.Equals(AOther.Parameters) and (inherited Equals(AOther));
+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;
+
+{ TDsaPublicKeyParameters }
+
+function TDsaPublicKeyParameters.GetY: TBigInteger;
+begin
+  Result := FY;
+end;
+
+class function TDsaPublicKeyParameters.Validate(const AY: TBigInteger;
+  const AParameters: IDsaParameters): TBigInteger;
+begin
+  if (not AY.IsInitialized) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SYUnInitialized);
+  end;
+  if (AParameters <> nil) then
+  begin
+    if ((AY.CompareTo(TBigInteger.Two) < 0) or
+      (AY.CompareTo(AParameters.P.Subtract(TBigInteger.Two)) > 0) or
+      (not AY.ModPow(AParameters.Q, AParameters.P).Equals(TBigInteger.One))) then
+    begin
+      raise EArgumentCryptoLibException.CreateRes(@SInvalidYInCorrectGroup);
+    end;
+  end;
+
+  Result := AY;
+end;
+
+constructor TDsaPublicKeyParameters.Create(const AY: TBigInteger;
+  const AParameters: IDsaParameters);
+begin
+  inherited Create(False, AParameters);
+  FY := Validate(AY, AParameters);
+end;
+
+function TDsaPublicKeyParameters.Equals(const AOther: IDsaPublicKeyParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDsaPublicKeyParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+  Result := (Y.Equals(AOther.Y)) and (inherited Equals(AOther));
+end;
+
+function TDsaPublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := Y.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TDsaPrivateKeyParameters }
+
+function TDsaPrivateKeyParameters.GetX: TBigInteger;
+begin
+  Result := FX;
+end;
+
+class function TDsaPrivateKeyParameters.Validate(const AX: TBigInteger): TBigInteger;
+begin
+  if (not AX.IsInitialized) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SXUnInitialized);
+  end;
+  Result := AX;
+end;
+
+constructor TDsaPrivateKeyParameters.Create(const AX: TBigInteger;
+  const AParameters: IDsaParameters);
+begin
+  inherited Create(True, AParameters);
+  FX := Validate(AX);
+end;
+
+function TDsaPrivateKeyParameters.Equals(const AOther: IDsaPrivateKeyParameters): Boolean;
+begin
+  if AOther = nil then
+  begin
+    Result := False;
+    Exit;
+  end;
+  if ((Self as IDsaPrivateKeyParameters) = AOther) then
+  begin
+    Result := True;
+    Exit;
+  end;
+  Result := (X.Equals(AOther.X)) and (inherited Equals(AOther));
+end;
+
+function TDsaPrivateKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := X.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TDsaKeyGenerationParameters }
+
+constructor TDsaKeyGenerationParameters.Create(const ARandom: ISecureRandom;
+  const AParameters: IDsaParameters);
+var
+  LP: TBigInteger;
+begin
+  LP := AParameters.P;
+  inherited Create(ARandom, LP.BitLength - 1);
+  FParameters := AParameters;
+end;
+
+function TDsaKeyGenerationParameters.GetParameters: IDsaParameters;
+begin
+  Result := FParameters;
+end;
+
+{ TDsaParameterGenerationParameters }
+
+constructor TDsaParameterGenerationParameters.Create(AL, AN, ACertainty: Int32;
+  const ARandom: ISecureRandom);
+begin
+  Create(AL, AN, ACertainty, ARandom, -1);
+end;
+
+constructor TDsaParameterGenerationParameters.Create(AL, AN, ACertainty: Int32;
+  const ARandom: ISecureRandom; AUsageIndex: Int32);
+begin
+  inherited Create();
+  FL := AL;
+  FN := AN;
+  FCertainty := ACertainty;
+  FRandom := ARandom;
+  FUsageIndex := AUsageIndex;
+end;
+
+function TDsaParameterGenerationParameters.GetL: Int32;
+begin
+  Result := FL;
+end;
+
+function TDsaParameterGenerationParameters.GetN: Int32;
+begin
+  Result := FN;
+end;
+
+function TDsaParameterGenerationParameters.GetCertainty: Int32;
+begin
+  Result := FCertainty;
+end;
+
+function TDsaParameterGenerationParameters.GetUsageIndex: Int32;
+begin
+  Result := FUsageIndex;
+end;
+
+function TDsaParameterGenerationParameters.GetRandom: ISecureRandom;
+begin
+  Result := FRandom;
 end;
 
 end.

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

@@ -1,105 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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;
-
-    class function Validate(const x: TBigInteger): TBigInteger; static; inline;
-
-  public
-    constructor Create(const x: TBigInteger; const parameters: IDsaParameters);
-
-    function Equals(const other: IDsaPrivateKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property x: TBigInteger read GetX;
-  end;
-
-implementation
-
-{ TDsaPrivateKeyParameters }
-
-function TDsaPrivateKeyParameters.GetX: TBigInteger;
-begin
-  result := Fx;
-end;
-
-class function TDsaPrivateKeyParameters.Validate(const x: TBigInteger)
-  : TBigInteger;
-begin
-  if (not(x.IsInitialized)) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SXUnInitialized);
-  end;
-  result := x;
-end;
-
-constructor TDsaPrivateKeyParameters.Create(const x: TBigInteger;
-  const parameters: IDsaParameters);
-begin
-  Inherited Create(true, parameters);
-  Fx := Validate(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;
-
-end.

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

@@ -1,118 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-    property y: TBigInteger read GetY;
-  end;
-
-implementation
-
-{ TDsaPublicKeyParameters }
-
-function TDsaPublicKeyParameters.GetY: TBigInteger;
-begin
-  result := Fy;
-end;
-
-class function TDsaPublicKeyParameters.Validate(const y: TBigInteger;
-  const parameters: IDsaParameters): TBigInteger;
-begin
-  if (not(y.IsInitialized)) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SYUnInitialized);
-  end;
-  // 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);
-  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;
-
-end.

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

@@ -1,121 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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,
-  ClpArrayUtilities,
-  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(const seed: TCryptoLibByteArray;
-      counter: Int32); overload;
-    constructor Create(const 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(const seed: TCryptoLibByteArray;
-  counter: Int32);
-begin
-  Create(seed, counter, -1);
-end;
-
-constructor TDsaValidationParameters.Create(const 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 TArrayUtilities.AreEqual<Byte>(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 TArrayUtilities.GetArrayHashCode(seed);
-end;
-
-function TDsaValidationParameters.GetSeed: TCryptoLibByteArray;
-begin
-  result := System.Copy(Fseed);
-end;
-
-function TDsaValidationParameters.GetUsageIndex: Int32;
-begin
-  result := FusageIndex;
-end;
-
-end.

+ 0 - 306
CryptoLib/src/Crypto/Parameters/ClpECDomainParameters.pas

@@ -1,306 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECDomainParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SyncObjs,
-  ClpBigInteger,
-  ClpECAlgorithms,
-  ClpIECC,
-  ClpCryptoLibTypes,
-  ClpIECDomainParameters,
-  ClpIX9ECAsn1Objects,
-  ClpIAsn1Objects,
-  ClpX9ECAsn1Objects;
-
-resourcestring
-  SCurveNil = 'Curve Cannot be Nil';
-  SScalarNil = 'Scalar Cannot be Nil';
-  SGNil = 'G Cannot be Nil';
-  SBigIntegerNotInitialized = 'BigInteger Not Initialized "%s"';
-  SQNil = 'Q Cannot be Nil';
-  SQInfinity = 'Point at Infinity "Q"';
-  SQPointNotOnCurve = 'Point Not on Curve "Q"';
-  SScalarInvalidRange = 'Scalar is not in the Interval [1, n - 1]';
-  SImplicitlyCANotImplemented = 'implicitlyCA';
-
-type
-
-  TECDomainParameters = class(TInterfacedObject, IECDomainParameters)
-
-  strict private
-
-  var
-    FLock: TCriticalSection;
-    Fcurve: IECCurve;
-    Fseed: TCryptoLibByteArray;
-    Fg: IECPoint;
-    Fn, Fh, FhInv: TBigInteger;
-
-    function GetCurve: IECCurve; inline;
-    function GetG: IECPoint; inline;
-    function GetH: TBigInteger; inline;
-    function GetN: TBigInteger; inline;
-    function GetHInv: TBigInteger; inline;
-    function GetSeed: TCryptoLibByteArray; inline;
-
-  public
-
-    class function ValidatePublicPoint(const c: IECCurve; const q: IECPoint)
-      : IECPoint; overload; static;
-
-    class function FromX9ECParameters(const AX9ECParameters: IX9ECParameters): IECDomainParameters; static;
-    class function FromX962Parameters(const AX962Parameters: IX962Parameters): IECDomainParameters; static;
-
-    constructor Create(const curve: IECCurve; const g: IECPoint;
-      const n: TBigInteger); overload;
-    constructor Create(const curve: IECCurve; const g: IECPoint;
-      const n, h: TBigInteger); overload;
-    constructor Create(const curve: IECCurve; const g: IECPoint;
-      const n, h: TBigInteger; const seed: TCryptoLibByteArray); overload;
-
-    function ValidatePrivateScalar(const d: TBigInteger): TBigInteger;
-    function ValidatePublicPoint(const q: IECPoint): IECPoint; overload;
-
-    destructor Destroy; override;
-
-    property curve: IECCurve read GetCurve;
-    property g: IECPoint read GetG;
-    property n: TBigInteger read GetN;
-    property h: TBigInteger read GetH;
-    property HInv: TBigInteger read GetHInv;
-    property seed: TCryptoLibByteArray read GetSeed;
-    function Equals(const other: IECDomainParameters): Boolean; reintroduce;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-    function ToX962Parameters: IX962Parameters;
-    function ToX9ECParameters: IX9ECParameters;
-
-  end;
-
-implementation
-
-uses
-  ClpECNamedDomainParameters;
-
-{ TECDomainParameters }
-
-class function TECDomainParameters.ValidatePublicPoint(const c: IECCurve;
-  const q: IECPoint): IECPoint;
-begin
-  if (q = Nil) then
-    raise EArgumentNilCryptoLibException.CreateRes(@SQNil);
-
-  result := TECAlgorithms.ImportPoint(c, q).Normalize();
-
-  if (result.IsInfinity) then
-    raise EArgumentCryptoLibException.CreateRes(@SQInfinity);
-
-  if (not(result.IsValid())) then
-    raise EArgumentCryptoLibException.CreateRes(@SQPointNotOnCurve);
-
-end;
-
-class function TECDomainParameters.FromX9ECParameters(const AX9ECParameters: IX9ECParameters): IECDomainParameters;
-begin
-  Result := TECDomainParameters.Create(AX9ECParameters.Curve, AX9ECParameters.G, AX9ECParameters.N, AX9ECParameters.H, AX9ECParameters.GetSeed());
-end;
-
-class function TECDomainParameters.FromX962Parameters(const AX962Parameters: IX962Parameters): IECDomainParameters;
-var
-  LNamedCurve: IDerObjectIdentifier;
-  LX9: IX9ECParameters;
-begin
-  if AX962Parameters.IsImplicitlyCA then
-    raise ENotSupportedCryptoLibException.Create(SImplicitlyCANotImplemented);
-
-  LNamedCurve := AX962Parameters.GetNamedCurve;
-  if LNamedCurve <> nil then
-  begin
-    Result := TECNamedDomainParameters.LookupOid(LNamedCurve);
-    Exit;
-  end;
-
-  LX9 := TX9ECParameters.GetInstance(AX962Parameters.GetParameters);
-  Result := FromX9ECParameters(LX9);
-end;
-
-function TECDomainParameters.GetCurve: IECCurve;
-begin
-  result := Fcurve;
-end;
-
-function TECDomainParameters.GetG: IECPoint;
-begin
-  result := Fg;
-end;
-
-function TECDomainParameters.GetH: TBigInteger;
-begin
-  result := Fh;
-end;
-
-function TECDomainParameters.GetN: TBigInteger;
-begin
-  result := Fn;
-end;
-
-function TECDomainParameters.GetHInv: TBigInteger;
-begin
-  FLock.Acquire;
-  try
-    if (not(FhInv.IsInitialized)) then
-    begin
-      FhInv := h.ModInverse(n);
-    end;
-    result := FhInv;
-  finally
-    FLock.Release;
-  end;
-end;
-
-function TECDomainParameters.GetSeed: TCryptoLibByteArray;
-begin
-  result := System.Copy(Fseed);
-end;
-
-constructor TECDomainParameters.Create(const curve: IECCurve; const g: IECPoint;
-  const n: TBigInteger);
-begin
-  Create(curve, g, n, TBigInteger.One, Nil);
-end;
-
-constructor TECDomainParameters.Create(const curve: IECCurve; const g: IECPoint;
-  const n, h: TBigInteger);
-begin
-  Create(curve, g, n, h, Nil);
-end;
-
-constructor TECDomainParameters.Create(const curve: IECCurve; const g: IECPoint;
-  const n, h: TBigInteger; const seed: TCryptoLibByteArray);
-begin
-  if (curve = Nil) then
-    raise EArgumentNilCryptoLibException.CreateRes(@SCurveNil);
-  if (g = Nil) then
-    raise EArgumentNilCryptoLibException.CreateRes(@SGNil);
-
-  if (not n.IsInitialized) then
-    raise EArgumentNilCryptoLibException.CreateResFmt
-      (@SBigIntegerNotInitialized, ['n']);
-
-  FLock := TCriticalSection.Create;
-
-  // we can't check for (not (h.IsInitialized)) here as h is optional in X9.62 as it is not required for ECDSA
-
-  Fcurve := curve;
-  Fg := ValidatePublicPoint(curve, g);
-  Fn := n;
-  Fh := h;
-  FhInv := TBigInteger.GetDefault;
-
-  Fseed := System.Copy(seed);
-
-end;
-
-destructor TECDomainParameters.Destroy;
-begin
-  FLock.Free;
-  inherited Destroy;
-end;
-
-function TECDomainParameters.ValidatePublicPoint(const q: IECPoint): IECPoint;
-begin
-  result := ValidatePublicPoint(curve, q);
-end;
-
-function TECDomainParameters.ValidatePrivateScalar(const d: TBigInteger)
-  : TBigInteger;
-begin
-  if (not(d.IsInitialized)) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SScalarNil);
-  end;
-
-  if ((d.CompareTo(TBigInteger.One) < 0) or (d.CompareTo(n) >= 0)) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SScalarInvalidRange);
-  end;
-  result := d;
-end;
-
-function TECDomainParameters.Equals(const other: IECDomainParameters): Boolean;
-begin
-
-  if (other = Self as IECDomainParameters) then
-  begin
-    result := True;
-    Exit;
-  end;
-
-  if (other = Nil) then
-  begin
-    result := false;
-    Exit;
-  end;
-
-  result := curve.Equals(other.curve) and g.Equals(other.g) and
-    n.Equals(other.n);
-
-  if h.IsInitialized then
-  begin
-    result := result and h.Equals(other.h);
-  end;
-end;
-
-function TECDomainParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := 4;
-  result := result * 257;
-  result := result xor Fcurve.GetHashCode();
-  result := result * 257;
-  result := result xor Fg.GetHashCode();
-  result := result * 257;
-  result := result xor Fn.GetHashCode();
-
-  if h.IsInitialized then
-  begin
-    result := result * 257;
-    result := result xor Fh.GetHashCode();
-  end;
-end;
-
-function TECDomainParameters.ToX962Parameters: IX962Parameters;
-begin
-  Result := TX962Parameters.Create(ToX9ECParameters());
-end;
-
-function TECDomainParameters.ToX9ECParameters: IX9ECParameters;
-var
-  LG: IX9ECPoint;
-begin
-  // TODO Support for choosing compressed==true?
-  LG := TX9ECPoint.Create(g, False);
-  Result := TX9ECParameters.Create(curve, LG, n, h, seed);
-end;
-
-end.

+ 0 - 63
CryptoLib/src/Crypto/Parameters/ClpECKeyGenerationParameters.pas

@@ -1,63 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECKeyGenerationParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpBigInteger,
-  ClpISecureRandom,
-  ClpIECKeyGenerationParameters,
-  ClpIECDomainParameters,
-  ClpKeyGenerationParameters;
-
-type
-  TECKeyGenerationParameters = class sealed(TKeyGenerationParameters,
-    IECKeyGenerationParameters)
-
-  strict private
-  var
-    FdomainParams: IECDomainParameters;
-
-    function GetDomainParameters: IECDomainParameters;
-
-  public
-    constructor Create(const domainParameters: IECDomainParameters;
-      const random: ISecureRandom);
-    property domainParameters: IECDomainParameters read GetDomainParameters;
-  end;
-
-implementation
-
-{ TECKeyGenerationParameters }
-
-constructor TECKeyGenerationParameters.Create(const domainParameters
-  : IECDomainParameters; const random: ISecureRandom);
-begin
-  Inherited Create(random, domainParameters.N.BitLength);
-  FdomainParams := domainParameters;
-end;
-
-function TECKeyGenerationParameters.GetDomainParameters: IECDomainParameters;
-begin
-  Result := FdomainParams;
-end;
-
-end.

+ 0 - 155
CryptoLib/src/Crypto/Parameters/ClpECKeyParameters.pas

@@ -1,155 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpIECKeyParameters,
-  ClpIECDomainParameters,
-  ClpIECKeyGenerationParameters,
-  ClpAsymmetricKeyParameter,
-  ClpECKeyGenerationParameters,
-  ClpISecureRandom,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SAlgorithmNil = 'Algorithm Cannot be Empty';
-  SParameterNil = 'Parameter Cannot be Nil';
-  SUnRecognizedAlgorithm = 'Unrecognised Algorithm: " %s, "Algorithm';
-
-type
-  TECKeyParameters = class abstract(TAsymmetricKeyParameter, IECKeyParameters)
-
-  strict private
-
-  const
-
-    Falgorithms: array [0 .. 5] of String = ('EC', 'ECDSA', 'ECDH', 'ECDHC', 'ECGOST3410', 'ECMQV');
-
-  var
-    Falgorithm: String;
-    Fparameters: IECDomainParameters;
-
-  strict protected
-
-    constructor Create(const algorithm: String; isPrivate: Boolean;
-      const parameters: IECDomainParameters);
-
-    function CreateKeyGenerationParameters(const random: ISecureRandom)
-      : IECKeyGenerationParameters; inline;
-
-    function GetAlgorithmName: String; inline;
-    function GetParameters: IECDomainParameters; inline;
-
-    function Equals(const other: IECKeyParameters): Boolean;
-      reintroduce; overload;
-
-  public
-    class function VerifyAlgorithmName(const algorithm: String): String; static;
-    property AlgorithmName: String read GetAlgorithmName;
-    property parameters: IECDomainParameters read GetParameters;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-  end;
-
-implementation
-
-function TECKeyParameters.GetParameters: IECDomainParameters;
-begin
-  result := Fparameters;
-end;
-
-class function TECKeyParameters.VerifyAlgorithmName(const algorithm
-  : String): String;
-var
-  upper: String;
-  i: Int32;
-  found: Boolean;
-begin
-  upper := UpperCase(algorithm);
-  found := false;
-  for i := System.Low(Falgorithms) to System.High(Falgorithms) do
-  begin
-    if (Falgorithms[i] = algorithm) then
-    begin
-      found := true;
-      break;
-    end;
-  end;
-
-  if (not found) then
-  begin
-    raise EArgumentCryptoLibException.CreateResFmt(@SUnRecognizedAlgorithm,
-      [algorithm]);
-  end;
-  result := upper;
-end;
-
-constructor TECKeyParameters.Create(const algorithm: String; isPrivate: Boolean;
-  const parameters: IECDomainParameters);
-begin
-  Inherited Create(isPrivate);
-  if (algorithm = '') then
-    raise EArgumentNilCryptoLibException.CreateRes(@SAlgorithmNil);
-
-  if (parameters = Nil) then
-    raise EArgumentNilCryptoLibException.CreateRes(@SParameterNil);
-
-  Falgorithm := VerifyAlgorithmName(algorithm);
-  Fparameters := parameters;
-end;
-
-function TECKeyParameters.CreateKeyGenerationParameters
-  (const random: ISecureRandom): IECKeyGenerationParameters;
-begin
-  result := TECKeyGenerationParameters.Create(parameters, random);
-end;
-
-function TECKeyParameters.Equals(const other: IECKeyParameters): Boolean;
-begin
-  if (other = Self as IECKeyParameters) then
-  begin
-    result := true;
-    Exit;
-  end;
-
-  if (other = Nil) then
-  begin
-    result := false;
-    Exit;
-  end;
-  result := Fparameters.Equals(other.Parameters) and (inherited Equals(other));
-end;
-
-function TECKeyParameters.GetAlgorithmName: String;
-begin
-  result := Falgorithm;
-end;
-
-function TECKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := Fparameters.GetHashCode() xor (inherited GetHashCode());
-end;
-
-end.

+ 0 - 123
CryptoLib/src/Crypto/Parameters/ClpECNamedDomainParameters.pas

@@ -1,123 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECNamedDomainParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpBigInteger,
-  ClpIAsn1Objects,
-  ClpIECC,
-  ClpIECDomainParameters,
-  ClpIECNamedDomainParameters,
-  ClpIX9ECAsn1Objects,
-  ClpX9ECAsn1Objects,
-  ClpECDomainParameters,
-  ClpECUtilities,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SOidNil = 'OID Cannot be Nil';
-  SOidNotValid = 'OID is not a valid public key parameter set';
-
-type
-  TECNamedDomainParameters = class sealed(TECDomainParameters, IECNamedDomainParameters)
-
-  strict private
-  var
-    FName: IDerObjectIdentifier;
-
-    function GetName: IDerObjectIdentifier; inline;
-
-  public
-    class function LookupOid(const AOid: IDerObjectIdentifier): IECNamedDomainParameters; static;
-
-    constructor Create(const AName: IDerObjectIdentifier; const ADp: IECDomainParameters); overload;
-    constructor Create(const AName: IDerObjectIdentifier; const AX9: IX9ECParameters); overload;
-    constructor Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN: TBigInteger); overload;
-    constructor Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger); overload;
-    constructor Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger; const ASeed: TCryptoLibByteArray); overload;
-
-    function ToX962Parameters: IX962Parameters; reintroduce;
-
-    property Name: IDerObjectIdentifier read GetName;
-
-  end;
-
-implementation
-
-{ TECNamedDomainParameters }
-
-class function TECNamedDomainParameters.LookupOid(const AOid: IDerObjectIdentifier): IECNamedDomainParameters;
-var
-  LX9: IX9ECParameters;
-begin
-  if AOid = nil then
-    raise EArgumentNilCryptoLibException.Create(SOidNil);
-
-  LX9 := TECUtilities.FindECCurveByOid(AOid);
-
-  if LX9 = nil then
-    raise EArgumentCryptoLibException.Create(SOidNotValid);
-
-  Result := TECNamedDomainParameters.Create(AOid, LX9);
-end;
-
-function TECNamedDomainParameters.GetName: IDerObjectIdentifier;
-begin
-  Result := FName;
-end;
-
-constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ADp: IECDomainParameters);
-begin
-  inherited Create(ADp.Curve, ADp.G, ADp.N, ADp.H, ADp.Seed);
-  FName := AName;
-end;
-
-constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const AX9: IX9ECParameters);
-begin
-  inherited Create(AX9.Curve, AX9.G, AX9.N, AX9.H, AX9.GetSeed());
-  FName := AName;
-end;
-
-constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN: TBigInteger);
-begin
-  inherited Create(ACurve, AG, AN);
-  FName := AName;
-end;
-
-constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger);
-begin
-  inherited Create(ACurve, AG, AN, AH);
-  FName := AName;
-end;
-
-constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger; const ASeed: TCryptoLibByteArray);
-begin
-  inherited Create(ACurve, AG, AN, AH, ASeed);
-  FName := AName;
-end;
-
-function TECNamedDomainParameters.ToX962Parameters: IX962Parameters;
-begin
-  Result := TX962Parameters.Create(FName);
-end;
-
-end.

+ 678 - 0
CryptoLib/src/Crypto/Parameters/ClpECParameters.pas

@@ -0,0 +1,678 @@
+{ *********************************************************************************** }
+{ *                              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 ClpECParameters;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SyncObjs,
+  SysUtils,
+  ClpBigInteger,
+  ClpECAlgorithms,
+  ClpIECC,
+  ClpIECParameters,
+  ClpIAsn1Objects,
+  ClpIX9ECAsn1Objects,
+  ClpX9ECAsn1Objects,
+  ClpAsymmetricKeyParameter,
+  ClpKeyGenerationParameters,
+  ClpISecureRandom,
+  ClpECUtilities,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SCurveNil = 'Curve Cannot be Nil';
+  SScalarNil = 'Scalar Cannot be Nil';
+  SGNil = 'G Cannot be Nil';
+  SBigIntegerNotInitialized = 'BigInteger Not Initialized "%s"';
+  SQNil = 'Q Cannot be Nil';
+  SQInfinity = 'Point at Infinity "Q"';
+  SQPointNotOnCurve = 'Point Not on Curve "Q"';
+  SScalarInvalidRange = 'Scalar is not in the Interval [1, n - 1]';
+  SImplicitlyCANotImplemented = 'implicitlyCA';
+  SOidNil = 'OID Cannot be Nil';
+  SOidNotValid = 'OID is not a valid public key parameter set';
+  SAlgorithmNil = 'Algorithm Cannot be Empty';
+  SParameterNil = 'Parameter Cannot be Nil';
+  SUnRecognizedAlgorithm = 'Unrecognised Algorithm: " %s, "Algorithm';
+
+type
+  TECDomainParameters = class(TInterfacedObject, IECDomainParameters)
+
+  strict private
+
+  var
+    FLock: TCriticalSection;
+    FCurve: IECCurve;
+    FSeed: TCryptoLibByteArray;
+    FG: IECPoint;
+    Fn, FH, FHInv: TBigInteger;
+
+    function GetCurve: IECCurve; inline;
+    function GetG: IECPoint; inline;
+    function GetH: TBigInteger; inline;
+    function GetN: TBigInteger; inline;
+    function GetHInv: TBigInteger; inline;
+    function GetSeed: TCryptoLibByteArray; inline;
+
+  public
+
+    class function ValidatePublicPoint(const ACurve: IECCurve; const AQ: IECPoint)
+      : IECPoint; overload; static;
+
+    class function FromX9ECParameters(const AX9ECParameters: IX9ECParameters): IECDomainParameters; static;
+    class function FromX962Parameters(const AX962Parameters: IX962Parameters): IECDomainParameters; static;
+
+    constructor Create(const ACurve: IECCurve; const AG: IECPoint;
+      const AN: TBigInteger); overload;
+    constructor Create(const ACurve: IECCurve; const AG: IECPoint;
+      const AN, AH: TBigInteger); overload;
+    constructor Create(const ACurve: IECCurve; const AG: IECPoint;
+      const AN, AH: TBigInteger; const ASeed: TCryptoLibByteArray); overload;
+
+    function ValidatePrivateScalar(const AD: TBigInteger): TBigInteger;
+    function ValidatePublicPoint(const AQ: IECPoint): IECPoint; overload;
+
+    destructor Destroy; override;
+
+    property Curve: IECCurve read GetCurve;
+    property G: IECPoint read GetG;
+    property N: TBigInteger read GetN;
+    property H: TBigInteger read GetH;
+    property HInv: TBigInteger read GetHInv;
+    property Seed: TCryptoLibByteArray read GetSeed;
+    function Equals(const AOther: IECDomainParameters): Boolean; reintroduce;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+    function ToX962Parameters: IX962Parameters;
+    function ToX9ECParameters: IX9ECParameters;
+
+  end;
+
+  TECNamedDomainParameters = class sealed(TECDomainParameters, IECNamedDomainParameters)
+
+  strict private
+  var
+    FName: IDerObjectIdentifier;
+
+    function GetName: IDerObjectIdentifier; inline;
+
+  public
+    class function LookupOid(const AOid: IDerObjectIdentifier): IECNamedDomainParameters; static;
+
+    constructor Create(const AName: IDerObjectIdentifier; const ADp: IECDomainParameters); overload;
+    constructor Create(const AName: IDerObjectIdentifier; const AX9: IX9ECParameters); overload;
+    constructor Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN: TBigInteger); overload;
+    constructor Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger); overload;
+    constructor Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger; const ASeed: TCryptoLibByteArray); overload;
+
+    function ToX962Parameters: IX962Parameters; reintroduce;
+
+    property Name: IDerObjectIdentifier read GetName;
+
+  end;
+
+  TECKeyParameters = class abstract(TAsymmetricKeyParameter, IECKeyParameters)
+
+  strict private
+
+  const
+
+    FAlgorithms: array [0 .. 5] of String = ('EC', 'ECDSA', 'ECDH', 'ECDHC', 'ECGOST3410', 'ECMQV');
+
+  var
+    FAlgorithm: String;
+    FParameters: IECDomainParameters;
+
+  strict protected
+
+    constructor Create(const AAlgorithm: String; AIsPrivate: Boolean;
+      const AParameters: IECDomainParameters);
+
+    function CreateKeyGenerationParameters(const ARandom: ISecureRandom)
+      : IECKeyGenerationParameters; inline;
+
+    function GetAlgorithmName: String; inline;
+    function GetParameters: IECDomainParameters; inline;
+
+    function Equals(const AOther: IECKeyParameters): Boolean;
+      reintroduce; overload;
+
+  public
+    class function VerifyAlgorithmName(const AAlgorithm: String): String; static;
+    property AlgorithmName: String read GetAlgorithmName;
+    property Parameters: IECDomainParameters read GetParameters;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+  end;
+
+  TECPublicKeyParameters = class sealed(TECKeyParameters,
+    IECPublicKeyParameters)
+
+  strict private
+  var
+    FQ: IECPoint;
+
+    function GetQ: IECPoint; inline;
+
+  public
+    constructor Create(const AQ: IECPoint;
+      const AParameters: IECDomainParameters); overload;
+
+    constructor Create(const AAlgorithm: String; const AQ: IECPoint;
+      const AParameters: IECDomainParameters); overload;
+
+    property Q: IECPoint read GetQ;
+
+    function Equals(const AOther: IECPublicKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+  end;
+
+  TECPrivateKeyParameters = class sealed(TECKeyParameters,
+    IECPrivateKeyParameters)
+
+  strict private
+  var
+    FD: TBigInteger;
+
+    function GetD: TBigInteger; inline;
+
+  public
+    constructor Create(const AD: TBigInteger;
+      const AParameters: IECDomainParameters); overload;
+
+    constructor Create(const AAlgorithm: String; const AD: TBigInteger;
+      const AParameters: IECDomainParameters); overload;
+
+    property D: TBigInteger read GetD;
+
+    function Equals(const AOther: IECPrivateKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+
+  end;
+
+  TECKeyGenerationParameters = class sealed(TKeyGenerationParameters,
+    IECKeyGenerationParameters)
+
+  strict private
+  var
+    FDomainParams: IECDomainParameters;
+
+    function GetDomainParameters: IECDomainParameters;
+
+  public
+    constructor Create(const ADomainParameters: IECDomainParameters;
+      const ARandom: ISecureRandom);
+    property DomainParameters: IECDomainParameters read GetDomainParameters;
+  end;
+
+implementation
+
+{ TECDomainParameters }
+
+class function TECDomainParameters.ValidatePublicPoint(const ACurve: IECCurve;
+  const AQ: IECPoint): IECPoint;
+begin
+  if (AQ = nil) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SQNil);
+
+  Result := TECAlgorithms.ImportPoint(ACurve, AQ).Normalize();
+
+  if (Result.IsInfinity) then
+    raise EArgumentCryptoLibException.CreateRes(@SQInfinity);
+
+  if (not(Result.IsValid())) then
+    raise EArgumentCryptoLibException.CreateRes(@SQPointNotOnCurve);
+
+end;
+
+class function TECDomainParameters.FromX9ECParameters(const AX9ECParameters: IX9ECParameters): IECDomainParameters;
+begin
+  Result := TECDomainParameters.Create(AX9ECParameters.Curve, AX9ECParameters.G, AX9ECParameters.N, AX9ECParameters.H, AX9ECParameters.GetSeed());
+end;
+
+class function TECDomainParameters.FromX962Parameters(const AX962Parameters: IX962Parameters): IECDomainParameters;
+var
+  LNamedCurve: IDerObjectIdentifier;
+  LX9: IX9ECParameters;
+begin
+  if AX962Parameters.IsImplicitlyCA then
+    raise ENotSupportedCryptoLibException.Create(SImplicitlyCANotImplemented);
+
+  LNamedCurve := AX962Parameters.GetNamedCurve;
+  if LNamedCurve <> nil then
+  begin
+    Result := TECNamedDomainParameters.LookupOid(LNamedCurve);
+    Exit;
+  end;
+
+  LX9 := TX9ECParameters.GetInstance(AX962Parameters.GetParameters);
+  Result := FromX9ECParameters(LX9);
+end;
+
+function TECDomainParameters.GetCurve: IECCurve;
+begin
+  Result := FCurve;
+end;
+
+function TECDomainParameters.GetG: IECPoint;
+begin
+  Result := FG;
+end;
+
+function TECDomainParameters.GetH: TBigInteger;
+begin
+  Result := FH;
+end;
+
+function TECDomainParameters.GetN: TBigInteger;
+begin
+  Result := Fn;
+end;
+
+function TECDomainParameters.GetHInv: TBigInteger;
+begin
+  FLock.Acquire;
+  try
+    if (not(FHInv.IsInitialized)) then
+    begin
+      FHInv := H.ModInverse(N);
+    end;
+    Result := FHInv;
+  finally
+    FLock.Release;
+  end;
+end;
+
+function TECDomainParameters.GetSeed: TCryptoLibByteArray;
+begin
+  Result := System.Copy(FSeed);
+end;
+
+constructor TECDomainParameters.Create(const ACurve: IECCurve; const AG: IECPoint;
+  const AN: TBigInteger);
+begin
+  Create(ACurve, AG, AN, TBigInteger.One, nil);
+end;
+
+constructor TECDomainParameters.Create(const ACurve: IECCurve; const AG: IECPoint;
+  const AN, AH: TBigInteger);
+begin
+  Create(ACurve, AG, AN, AH, nil);
+end;
+
+constructor TECDomainParameters.Create(const ACurve: IECCurve; const AG: IECPoint;
+  const AN, AH: TBigInteger; const ASeed: TCryptoLibByteArray);
+begin
+  if (ACurve = nil) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SCurveNil);
+  if (AG = nil) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SGNil);
+
+  if (not AN.IsInitialized) then
+    raise EArgumentNilCryptoLibException.CreateResFmt
+      (@SBigIntegerNotInitialized, ['n']);
+
+  FLock := TCriticalSection.Create;
+
+  FCurve := ACurve;
+  FG := ValidatePublicPoint(ACurve, AG);
+  Fn := AN;
+  FH := AH;
+  FHInv := TBigInteger.GetDefault;
+
+  FSeed := System.Copy(ASeed);
+
+end;
+
+destructor TECDomainParameters.Destroy;
+begin
+  FLock.Free;
+  inherited Destroy;
+end;
+
+function TECDomainParameters.ValidatePublicPoint(const AQ: IECPoint): IECPoint;
+begin
+  Result := ValidatePublicPoint(Curve, AQ);
+end;
+
+function TECDomainParameters.ValidatePrivateScalar(const AD: TBigInteger)
+  : TBigInteger;
+begin
+  if (not(AD.IsInitialized)) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SScalarNil);
+  end;
+
+  if ((AD.CompareTo(TBigInteger.One) < 0) or (AD.CompareTo(N) >= 0)) then
+  begin
+    raise EArgumentCryptoLibException.CreateRes(@SScalarInvalidRange);
+  end;
+  Result := AD;
+end;
+
+function TECDomainParameters.Equals(const AOther: IECDomainParameters): Boolean;
+begin
+
+  if (AOther = Self as IECDomainParameters) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  if (AOther = nil) then
+  begin
+    Result := False;
+    Exit;
+  end;
+
+  Result := Curve.Equals(AOther.Curve) and G.Equals(AOther.G) and
+    N.Equals(AOther.N);
+
+  if H.IsInitialized then
+  begin
+    Result := Result and H.Equals(AOther.H);
+  end;
+end;
+
+function TECDomainParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := 4;
+  Result := Result * 257;
+  Result := Result xor FCurve.GetHashCode();
+  Result := Result * 257;
+  Result := Result xor FG.GetHashCode();
+  Result := Result * 257;
+  Result := Result xor Fn.GetHashCode();
+
+  if H.IsInitialized then
+  begin
+    Result := Result * 257;
+    Result := Result xor FH.GetHashCode();
+  end;
+end;
+
+function TECDomainParameters.ToX962Parameters: IX962Parameters;
+begin
+  Result := TX962Parameters.Create(ToX9ECParameters());
+end;
+
+function TECDomainParameters.ToX9ECParameters: IX9ECParameters;
+var
+  LG: IX9ECPoint;
+begin
+  LG := TX9ECPoint.Create(G, False);
+  Result := TX9ECParameters.Create(Curve, LG, N, H, Seed);
+end;
+
+{ TECNamedDomainParameters }
+
+class function TECNamedDomainParameters.LookupOid(const AOid: IDerObjectIdentifier): IECNamedDomainParameters;
+var
+  LX9: IX9ECParameters;
+begin
+  if AOid = nil then
+    raise EArgumentNilCryptoLibException.Create(SOidNil);
+
+  LX9 := TECUtilities.FindECCurveByOid(AOid);
+
+  if LX9 = nil then
+    raise EArgumentCryptoLibException.Create(SOidNotValid);
+
+  Result := TECNamedDomainParameters.Create(AOid, LX9);
+end;
+
+function TECNamedDomainParameters.GetName: IDerObjectIdentifier;
+begin
+  Result := FName;
+end;
+
+constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ADp: IECDomainParameters);
+begin
+  inherited Create(ADp.Curve, ADp.G, ADp.N, ADp.H, ADp.Seed);
+  FName := AName;
+end;
+
+constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const AX9: IX9ECParameters);
+begin
+  inherited Create(AX9.Curve, AX9.G, AX9.N, AX9.H, AX9.GetSeed());
+  FName := AName;
+end;
+
+constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN: TBigInteger);
+begin
+  inherited Create(ACurve, AG, AN);
+  FName := AName;
+end;
+
+constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger);
+begin
+  inherited Create(ACurve, AG, AN, AH);
+  FName := AName;
+end;
+
+constructor TECNamedDomainParameters.Create(const AName: IDerObjectIdentifier; const ACurve: IECCurve; const AG: IECPoint; const AN, AH: TBigInteger; const ASeed: TCryptoLibByteArray);
+begin
+  inherited Create(ACurve, AG, AN, AH, ASeed);
+  FName := AName;
+end;
+
+function TECNamedDomainParameters.ToX962Parameters: IX962Parameters;
+begin
+  Result := TX962Parameters.Create(FName);
+end;
+
+{ TECKeyParameters }
+
+function TECKeyParameters.GetParameters: IECDomainParameters;
+begin
+  Result := FParameters;
+end;
+
+class function TECKeyParameters.VerifyAlgorithmName(const AAlgorithm
+  : String): String;
+var
+  LUpper: String;
+  LI: Int32;
+  LFound: Boolean;
+begin
+  LUpper := UpperCase(AAlgorithm);
+  LFound := False;
+  for LI := System.Low(FAlgorithms) to System.High(FAlgorithms) do
+  begin
+    if (FAlgorithms[LI] = AAlgorithm) then
+    begin
+      LFound := True;
+      break;
+    end;
+  end;
+
+  if (not LFound) then
+  begin
+    raise EArgumentCryptoLibException.CreateResFmt(@SUnRecognizedAlgorithm,
+      [AAlgorithm]);
+  end;
+  Result := LUpper;
+end;
+
+constructor TECKeyParameters.Create(const AAlgorithm: String; AIsPrivate: Boolean;
+  const AParameters: IECDomainParameters);
+begin
+  inherited Create(AIsPrivate);
+  if (AAlgorithm = '') then
+    raise EArgumentNilCryptoLibException.CreateRes(@SAlgorithmNil);
+
+  if (AParameters = nil) then
+    raise EArgumentNilCryptoLibException.CreateRes(@SParameterNil);
+
+  FAlgorithm := VerifyAlgorithmName(AAlgorithm);
+  FParameters := AParameters;
+end;
+
+function TECKeyParameters.CreateKeyGenerationParameters
+  (const ARandom: ISecureRandom): IECKeyGenerationParameters;
+begin
+  Result := TECKeyGenerationParameters.Create(Parameters, ARandom);
+end;
+
+function TECKeyParameters.Equals(const AOther: IECKeyParameters): Boolean;
+begin
+  if (AOther = Self as IECKeyParameters) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  if (AOther = nil) then
+  begin
+    Result := False;
+    Exit;
+  end;
+  Result := FParameters.Equals(AOther.Parameters) and (inherited Equals(AOther));
+end;
+
+function TECKeyParameters.GetAlgorithmName: String;
+begin
+  Result := FAlgorithm;
+end;
+
+function TECKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := FParameters.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TECPublicKeyParameters }
+
+function TECPublicKeyParameters.GetQ: IECPoint;
+begin
+  Result := FQ;
+end;
+
+constructor TECPublicKeyParameters.Create(const AAlgorithm: String;
+  const AQ: IECPoint; const AParameters: IECDomainParameters);
+begin
+  inherited Create(AAlgorithm, False, AParameters);
+
+  if (AQ = nil) then
+  begin
+    raise EArgumentNilCryptoLibException.CreateRes(@SQNil);
+  end;
+
+  FQ := AParameters.ValidatePublicPoint(AQ);
+end;
+
+constructor TECPublicKeyParameters.Create(const AQ: IECPoint;
+  const AParameters: IECDomainParameters);
+begin
+  Create('EC', AQ, AParameters);
+end;
+
+function TECPublicKeyParameters.Equals(const AOther
+  : IECPublicKeyParameters): Boolean;
+begin
+  if (AOther = Self as IECPublicKeyParameters) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  if (AOther = nil) then
+  begin
+    Result := False;
+    Exit;
+  end;
+  Result := Q.Equals(AOther.Q) and (inherited Equals(AOther));
+end;
+
+function TECPublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := Q.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TECPrivateKeyParameters }
+
+function TECPrivateKeyParameters.GetD: TBigInteger;
+begin
+  Result := FD;
+end;
+
+constructor TECPrivateKeyParameters.Create(const AD: TBigInteger;
+  const AParameters: IECDomainParameters);
+begin
+  Create('EC', AD, AParameters);
+end;
+
+constructor TECPrivateKeyParameters.Create(const AAlgorithm: String;
+  const AD: TBigInteger; const AParameters: IECDomainParameters);
+begin
+  inherited Create(AAlgorithm, True, AParameters);
+  if (not(AD.IsInitialized)) then
+    raise EArgumentNilCryptoLibException.CreateResFmt
+      (@SBigIntegerNotInitialized, ['d']);
+  FD := AParameters.ValidatePrivateScalar(AD);
+end;
+
+function TECPrivateKeyParameters.Equals(const AOther
+  : IECPrivateKeyParameters): Boolean;
+begin
+  if (AOther = Self as IECPrivateKeyParameters) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  if (AOther = nil) then
+  begin
+    Result := False;
+    Exit;
+  end;
+  Result := D.Equals(AOther.D) and (inherited Equals(AOther));
+end;
+
+function TECPrivateKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := D.GetHashCode() xor (inherited GetHashCode());
+end;
+
+{ TECKeyGenerationParameters }
+
+constructor TECKeyGenerationParameters.Create(const ADomainParameters
+  : IECDomainParameters; const ARandom: ISecureRandom);
+begin
+  inherited Create(ARandom, ADomainParameters.N.BitLength);
+  FDomainParams := ADomainParameters;
+end;
+
+function TECKeyGenerationParameters.GetDomainParameters: IECDomainParameters;
+begin
+  Result := FDomainParams;
+end;
+
+end.

+ 0 - 108
CryptoLib/src/Crypto/Parameters/ClpECPrivateKeyParameters.pas

@@ -1,108 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECPrivateKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpBigInteger,
-  ClpCryptoLibTypes,
-  ClpECKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpIECDomainParameters;
-
-resourcestring
-  SBigIntegerNotInitialized = 'BigInteger Not Initialized "%s"';
-
-type
-  TECPrivateKeyParameters = class sealed(TECKeyParameters,
-    IECPrivateKeyParameters)
-
-  strict private
-  var
-    Fd: TBigInteger;
-
-    function GetD: TBigInteger; inline;
-
-  public
-    constructor Create(const d: TBigInteger;
-      const parameters: IECDomainParameters); overload;
-
-    constructor Create(const algorithm: String; const d: TBigInteger;
-      const parameters: IECDomainParameters); overload;
-
-    property d: TBigInteger read GetD;
-
-    function Equals(const other: IECPrivateKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-  end;
-
-implementation
-
-{ TECPrivateKeyParameters }
-
-function TECPrivateKeyParameters.GetD: TBigInteger;
-begin
-  result := Fd;
-end;
-
-constructor TECPrivateKeyParameters.Create(const d: TBigInteger;
-  const parameters: IECDomainParameters);
-begin
-  Create('EC', d, parameters);
-end;
-
-constructor TECPrivateKeyParameters.Create(const algorithm: String;
-  const d: TBigInteger; const parameters: IECDomainParameters);
-begin
-  Inherited Create(algorithm, true, parameters);
-  if (not(d.IsInitialized)) then
-    raise EArgumentNilCryptoLibException.CreateResFmt
-      (@SBigIntegerNotInitialized, ['d']);
-  Fd := parameters.ValidatePrivateScalar(d);
-end;
-
-function TECPrivateKeyParameters.Equals(const other
-  : IECPrivateKeyParameters): Boolean;
-begin
-  if (other = Self as IECPrivateKeyParameters) then
-  begin
-    result := true;
-    Exit;
-  end;
-
-  if (other = Nil) then
-  begin
-    result := false;
-    Exit;
-  end;
-  result := d.Equals(other.d) and (inherited Equals(other));
-end;
-
-function TECPrivateKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := d.GetHashCode() xor (inherited GetHashCode());
-end;
-
-end.

+ 0 - 111
CryptoLib/src/Crypto/Parameters/ClpECPublicKeyParameters.pas

@@ -1,111 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpECPublicKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpCryptoLibTypes,
-  ClpIECC,
-  ClpIECPublicKeyParameters,
-  ClpIECDomainParameters,
-  ClpECKeyParameters;
-
-resourcestring
-  SQNil = 'Q Cannot be Nil';
-
-type
-  TECPublicKeyParameters = class sealed(TECKeyParameters,
-    IECPublicKeyParameters)
-
-  strict private
-  var
-    Fq: IECPoint;
-
-    function GetQ: IECPoint; inline;
-
-  public
-    constructor Create(const q: IECPoint;
-      const parameters: IECDomainParameters); overload;
-
-    constructor Create(const algorithm: String; const q: IECPoint;
-      const parameters: IECDomainParameters); overload;
-
-    property q: IECPoint read GetQ;
-
-    function Equals(const other: IECPublicKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-  end;
-
-implementation
-
-{ TECPublicKeyParameters }
-
-function TECPublicKeyParameters.GetQ: IECPoint;
-begin
-  result := Fq;
-end;
-
-constructor TECPublicKeyParameters.Create(const algorithm: String;
-  const q: IECPoint; const parameters: IECDomainParameters);
-begin
-  Inherited Create(algorithm, false, parameters);
-
-  if (q = Nil) then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SQNil);
-  end;
-
-  Fq := parameters.validatePublicPoint(q);
-end;
-
-constructor TECPublicKeyParameters.Create(const q: IECPoint;
-  const parameters: IECDomainParameters);
-begin
-  Create('EC', q, parameters);
-end;
-
-function TECPublicKeyParameters.Equals(const other
-  : IECPublicKeyParameters): Boolean;
-begin
-  if (other = Self as IECPublicKeyParameters) then
-  begin
-    result := true;
-    Exit;
-  end;
-
-  if (other = Nil) then
-  begin
-    result := false;
-    Exit;
-  end;
-  result := q.Equals(other.q) and (inherited Equals(other));
-end;
-
-function TECPublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  result := q.GetHashCode() xor (inherited GetHashCode());
-end;
-
-end.

+ 0 - 47
CryptoLib/src/Crypto/Parameters/ClpEd25519KeyGenerationParameters.pas

@@ -1,47 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpEd25519KeyGenerationParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpISecureRandom,
-  ClpIEd25519KeyGenerationParameters,
-  ClpKeyGenerationParameters;
-
-type
-  TEd25519KeyGenerationParameters = class sealed(TKeyGenerationParameters,
-    IEd25519KeyGenerationParameters)
-
-  public
-    constructor Create(const random: ISecureRandom);
-
-  end;
-
-implementation
-
-{ TEd25519KeyGenerationParameters }
-
-constructor TEd25519KeyGenerationParameters.Create(const random: ISecureRandom);
-begin
-  Inherited Create(random, 256);
-end;
-
-end.

+ 179 - 17
CryptoLib/src/Crypto/Parameters/ClpEd25519PrivateKeyParameters.pas → CryptoLib/src/Crypto/Parameters/ClpEd25519Parameters.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpEd25519PrivateKeyParameters;
+unit ClpEd25519Parameters;
 
 {$I ..\..\Include\CryptoLib.inc}
 
@@ -26,23 +26,53 @@ uses
   ClpEd25519,
   ClpISecureRandom,
   ClpAsymmetricKeyParameter,
-  ClpIEd25519PrivateKeyParameters,
-  ClpIEd25519PublicKeyParameters,
-  ClpEd25519PublicKeyParameters,
+  ClpIEd25519Parameters,
+  ClpKeyGenerationParameters,
   ClpArrayUtilities,
   ClpStreamUtilities,
   ClpCryptoLibTypes;
 
 resourcestring
+  SEOFInPublicKey = 'EOF encountered in middle of Ed25519 public key';
+  SInvalidPublicKey = 'invalid public key';
+  SMustHaveLengthKeySize = 'must have length %d';
   SEOFInPrivateKey = 'EOF encountered in middle of Ed25519 private key';
   SUnsupportedAlgorithm = 'Unsupported Algorithm';
   SCtxNotNil = 'Ctx must be Nil for Ed25519 Algorithm';
   SCtxNil = 'Ctx must not be Nil for Ed25519ctx/Ed25519ph';
   SCtxLength = 'Ctx length must be at most 255';
   SMsgLen = 'MsgLen must be Equal to PreHashSize for Ed25519ph Algorithm';
-  SMustHaveLengthKeySize = 'must have length %d';
 
 type
+  TEd25519PublicKeyParameters = class sealed(TAsymmetricKeyParameter,
+    IEd25519PublicKeyParameters)
+
+  strict private
+  var
+    FPublicPoint: TEd25519.IPublicPoint;
+
+  public
+    const
+    KeySize = Int32(TEd25519.PublicKeySize);
+
+    constructor Create(const ABuf: TCryptoLibByteArray); overload;
+    constructor Create(const ABuf: TCryptoLibByteArray; AOff: Int32); overload;
+    constructor Create(AInput: TStream); overload;
+    constructor Create(const APublicPoint: TEd25519.IPublicPoint); overload;
+
+    procedure Encode(const ABuf: TCryptoLibByteArray; AOff: Int32); inline;
+    function GetEncoded(): TCryptoLibByteArray; inline;
+
+    function Verify(AAlgorithm: TEd25519.TAlgorithm;
+      const ACtx, AMsg: TCryptoLibByteArray; AMsgOff, AMsgLen: Int32;
+      const ASig: TCryptoLibByteArray; ASigOff: Int32): Boolean;
+
+    function Equals(const AOther: IEd25519PublicKeyParameters): Boolean;
+      reintroduce; overload;
+    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}override;
+  end;
+
   TEd25519PrivateKeyParameters = class sealed(TAsymmetricKeyParameter,
     IEd25519PrivateKeyParameters)
 
@@ -52,7 +82,6 @@ type
     FCachedPublicKey: IEd25519PublicKeyParameters;
 
   public
-
     const
     KeySize = Int32(TEd25519.SecretKeySize);
     SignatureSize = Int32(TEd25519.SignatureSize);
@@ -74,15 +103,146 @@ type
       reintroduce; overload;
     function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}override;
+  end;
+
+  TEd25519KeyGenerationParameters = class sealed(TKeyGenerationParameters,
+    IEd25519KeyGenerationParameters)
 
+  public
+    constructor Create(const ARandom: ISecureRandom);
   end;
 
 implementation
 
+{ TEd25519PublicKeyParameters }
+
+constructor TEd25519PublicKeyParameters.Create(const ABuf: TCryptoLibByteArray);
+begin
+  if System.Length(ABuf) <> KeySize then
+    raise EArgumentCryptoLibException.CreateResFmt(@SMustHaveLengthKeySize,
+      [KeySize]);
+  Create(ABuf, 0);
+end;
+
+constructor TEd25519PublicKeyParameters.Create(const ABuf: TCryptoLibByteArray;
+  AOff: Int32);
+var
+  LPoint: TEd25519.IPublicPoint;
+begin
+  inherited Create(False);
+  LPoint := TEd25519.ValidatePublicKeyPartialExport(ABuf, AOff);
+  if LPoint = nil then
+    raise EArgumentCryptoLibException.CreateRes(@SInvalidPublicKey);
+  FPublicPoint := LPoint;
+end;
+
+constructor TEd25519PublicKeyParameters.Create(AInput: TStream);
+var
+  LData: TCryptoLibByteArray;
+  LPoint: TEd25519.IPublicPoint;
+begin
+  inherited Create(False);
+  System.SetLength(LData, KeySize);
+  if KeySize <> TStreamUtilities.ReadFully(AInput, LData) then
+    raise EEndOfStreamCryptoLibException.CreateRes(@SEOFInPublicKey);
+  LPoint := TEd25519.ValidatePublicKeyPartialExport(LData, 0);
+  if LPoint = nil then
+    raise EArgumentCryptoLibException.CreateRes(@SInvalidPublicKey);
+  FPublicPoint := LPoint;
+end;
+
+constructor TEd25519PublicKeyParameters.Create(const APublicPoint: TEd25519.IPublicPoint);
+begin
+  inherited Create(False);
+  if APublicPoint = nil then
+    raise EArgumentNilCryptoLibException.CreateRes(@SInvalidPublicKey);
+  FPublicPoint := APublicPoint;
+end;
+
+procedure TEd25519PublicKeyParameters.Encode(const ABuf: TCryptoLibByteArray;
+  AOff: Int32);
+begin
+  TEd25519.EncodePublicPoint(FPublicPoint, ABuf, AOff);
+end;
+
+function TEd25519PublicKeyParameters.GetEncoded: TCryptoLibByteArray;
+begin
+  System.SetLength(Result, KeySize);
+  Encode(Result, 0);
+end;
+
+function TEd25519PublicKeyParameters.Verify(AAlgorithm: TEd25519.TAlgorithm;
+  const ACtx, AMsg: TCryptoLibByteArray; AMsgOff, AMsgLen: Int32;
+  const ASig: TCryptoLibByteArray; ASigOff: Int32): Boolean;
+var
+  LEd25519: TEd25519;
+begin
+  LEd25519 := TEd25519.Create();
+  try
+    case AAlgorithm of
+      TEd25519.TAlgorithm.Ed25519:
+        begin
+          if ACtx <> nil then
+            raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SInvalidPublicKey);
+          Result := LEd25519.Verify(ASig, ASigOff, FPublicPoint, AMsg, AMsgOff,
+            AMsgLen);
+        end;
+      TEd25519.TAlgorithm.Ed25519ctx:
+        begin
+          if System.Length(ACtx) > 255 then
+            raise EArgumentOutOfRangeCryptoLibException.CreateRes
+              (@SInvalidPublicKey);
+          Result := LEd25519.Verify(ASig, ASigOff, FPublicPoint, ACtx, AMsg,
+            AMsgOff, AMsgLen);
+        end;
+      TEd25519.TAlgorithm.Ed25519ph:
+        begin
+          if System.Length(ACtx) > 255 then
+            raise EArgumentOutOfRangeCryptoLibException.CreateRes
+              (@SInvalidPublicKey);
+          if TEd25519.PrehashSize <> AMsgLen then
+            raise EArgumentOutOfRangeCryptoLibException.CreateRes
+              (@SInvalidPublicKey);
+          Result := LEd25519.VerifyPreHash(ASig, ASigOff, FPublicPoint, ACtx,
+            AMsg, AMsgOff);
+        end
+    else
+      raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SInvalidPublicKey);
+    end;
+  finally
+    LEd25519.Free;
+  end;
+end;
+
+function TEd25519PublicKeyParameters.Equals(const AOther: IEd25519PublicKeyParameters): Boolean;
+var
+  LEncoded, LOtherEncoded: TCryptoLibByteArray;
+begin
+  if (AOther = Self as IEd25519PublicKeyParameters) then
+  begin
+    Result := True;
+    Exit;
+  end;
+
+  if (AOther = nil) then
+  begin
+    Result := False;
+    Exit;
+  end;
+  LEncoded := GetEncoded();
+  LOtherEncoded := AOther.GetEncoded();
+  Result := TArrayUtilities.FixedTimeEquals(LEncoded, LOtherEncoded);
+end;
+
+function TEd25519PublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
+{$ENDIF DELPHI}
+begin
+  Result := TArrayUtilities.GetArrayHashCode(GetEncoded());
+end;
+
 { TEd25519PrivateKeyParameters }
 
-function TEd25519PrivateKeyParameters.GeneratePublicKey
-  : IEd25519PublicKeyParameters;
+function TEd25519PrivateKeyParameters.GeneratePublicKey: IEd25519PublicKeyParameters;
 var
   LPoint: TEd25519.IPublicPoint;
 begin
@@ -103,7 +263,7 @@ constructor TEd25519PrivateKeyParameters.Create(const ARandom: ISecureRandom);
 var
   LEd25519: TEd25519;
 begin
-  Inherited Create(True);
+  inherited Create(True);
   System.SetLength(FData, KeySize);
   LEd25519 := TEd25519.Create();
   try
@@ -124,14 +284,14 @@ end;
 constructor TEd25519PrivateKeyParameters.Create(const ABuf: TCryptoLibByteArray;
   AOff: Int32);
 begin
-  Inherited Create(True);
+  inherited Create(True);
   System.SetLength(FData, KeySize);
   System.Move(ABuf[AOff], FData[0], KeySize * System.SizeOf(Byte));
 end;
 
 constructor TEd25519PrivateKeyParameters.Create(AInput: TStream);
 begin
-  Inherited Create(True);
+  inherited Create(True);
   System.SetLength(FData, KeySize);
   if KeySize <> TStreamUtilities.ReadFully(AInput, FData) then
     raise EEndOfStreamCryptoLibException.CreateRes(@SEOFInPrivateKey);
@@ -143,8 +303,7 @@ begin
   System.Move(FData[0], ABuf[AOff], KeySize * System.SizeOf(Byte));
 end;
 
-function TEd25519PrivateKeyParameters.Equals(const AOther
-  : IEd25519PrivateKeyParameters): Boolean;
+function TEd25519PrivateKeyParameters.Equals(const AOther: IEd25519PrivateKeyParameters): Boolean;
 begin
   if (AOther = Self as IEd25519PrivateKeyParameters) then
   begin
@@ -190,8 +349,6 @@ begin
 
       TEd25519.TAlgorithm.Ed25519ctx:
         begin
-          // Note: In Pascal, nil and empty arrays are equivalent.
-          // We allow nil here, treating it as an empty context.
           if System.Length(ACtx) > 255 then
             raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SCtxLength);
           LEd25519.Sign(FData, 0, LPk, 0, ACtx, AMsg, AMsgOff, AMsgLen, ASig,
@@ -200,8 +357,6 @@ begin
 
       TEd25519.TAlgorithm.Ed25519ph:
         begin
-          // Note: In Pascal, nil and empty arrays are equivalent.
-          // We allow nil here, treating it as an empty context.
           if System.Length(ACtx) > 255 then
             raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SCtxLength);
           if TEd25519.PrehashSize <> AMsgLen then
@@ -217,4 +372,11 @@ begin
   end;
 end;
 
+{ TEd25519KeyGenerationParameters }
+
+constructor TEd25519KeyGenerationParameters.Create(const ARandom: ISecureRandom);
+begin
+  inherited Create(ARandom, 256);
+end;
+
 end.

+ 0 - 204
CryptoLib/src/Crypto/Parameters/ClpEd25519PublicKeyParameters.pas

@@ -1,204 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpEd25519PublicKeyParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  Classes,
-  ClpEd25519,
-  ClpAsymmetricKeyParameter,
-  ClpIEd25519PublicKeyParameters,
-  ClpArrayUtilities,
-  ClpStreamUtilities,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SEOFInPublicKey = 'EOF encountered in middle of Ed25519 public key';
-  SInvalidPublicKey = 'invalid public key';
-  SMustHaveLengthKeySize = 'must have length %d';
-
-type
-  TEd25519PublicKeyParameters = class sealed(TAsymmetricKeyParameter,
-    IEd25519PublicKeyParameters)
-
-  strict private
-  var
-    FPublicPoint: TEd25519.IPublicPoint;
-
-  public
-
-    const
-    KeySize = Int32(TEd25519.PublicKeySize);
-
-    constructor Create(const ABuf: TCryptoLibByteArray); overload;
-    constructor Create(const ABuf: TCryptoLibByteArray; AOff: Int32); overload;
-    constructor Create(AInput: TStream); overload;
-    constructor Create(const APublicPoint: TEd25519.IPublicPoint); overload;
-
-    procedure Encode(const ABuf: TCryptoLibByteArray; AOff: Int32); inline;
-    function GetEncoded(): TCryptoLibByteArray; inline;
-
-    function Verify(AAlgorithm: TEd25519.TAlgorithm;
-      const ACtx, AMsg: TCryptoLibByteArray; AMsgOff, AMsgLen: Int32;
-      const ASig: TCryptoLibByteArray; ASigOff: Int32): Boolean;
-
-    function Equals(const AOther: IEd25519PublicKeyParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}override;
-
-  end;
-
-implementation
-
-{ TEd25519PublicKeyParameters }
-
-constructor TEd25519PublicKeyParameters.Create(const ABuf: TCryptoLibByteArray);
-begin
-  if System.Length(ABuf) <> KeySize then
-    raise EArgumentCryptoLibException.CreateResFmt(@SMustHaveLengthKeySize,
-      [KeySize]);
-  Create(ABuf, 0);
-end;
-
-constructor TEd25519PublicKeyParameters.Create(const ABuf: TCryptoLibByteArray;
-  AOff: Int32);
-var
-  LPoint: TEd25519.IPublicPoint;
-begin
-  Inherited Create(False);
-  LPoint := TEd25519.ValidatePublicKeyPartialExport(ABuf, AOff);
-  if LPoint = nil then
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidPublicKey);
-  FPublicPoint := LPoint;
-end;
-
-constructor TEd25519PublicKeyParameters.Create(AInput: TStream);
-var
-  LData: TCryptoLibByteArray;
-  LPoint: TEd25519.IPublicPoint;
-begin
-  Inherited Create(False);
-  System.SetLength(LData, KeySize);
-  if KeySize <> TStreamUtilities.ReadFully(AInput, LData) then
-    raise EEndOfStreamCryptoLibException.CreateRes(@SEOFInPublicKey);
-  LPoint := TEd25519.ValidatePublicKeyPartialExport(LData, 0);
-  if LPoint = nil then
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidPublicKey);
-  FPublicPoint := LPoint;
-end;
-
-constructor TEd25519PublicKeyParameters.Create(const APublicPoint
-  : TEd25519.IPublicPoint);
-begin
-  Inherited Create(False);
-  if APublicPoint = nil then
-    raise EArgumentNilCryptoLibException.CreateRes(@SInvalidPublicKey);
-  FPublicPoint := APublicPoint;
-end;
-
-procedure TEd25519PublicKeyParameters.Encode(const ABuf: TCryptoLibByteArray;
-  AOff: Int32);
-begin
-  TEd25519.EncodePublicPoint(FPublicPoint, ABuf, AOff);
-end;
-
-function TEd25519PublicKeyParameters.GetEncoded: TCryptoLibByteArray;
-begin
-  System.SetLength(Result, KeySize);
-  Encode(Result, 0);
-end;
-
-function TEd25519PublicKeyParameters.Verify(AAlgorithm: TEd25519.TAlgorithm;
-  const ACtx, AMsg: TCryptoLibByteArray; AMsgOff, AMsgLen: Int32;
-  const ASig: TCryptoLibByteArray; ASigOff: Int32): Boolean;
-var
-  LEd25519: TEd25519;
-begin
-  LEd25519 := TEd25519.Create();
-  try
-    case AAlgorithm of
-      TEd25519.TAlgorithm.Ed25519:
-        begin
-          if ACtx <> nil then
-            raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SInvalidPublicKey);
-          Result := LEd25519.Verify(ASig, ASigOff, FPublicPoint, AMsg, AMsgOff,
-            AMsgLen);
-        end;
-      TEd25519.TAlgorithm.Ed25519ctx:
-        begin
-          // Note: In Pascal, nil and empty arrays are equivalent.
-          // We allow nil here, treating it as an empty context.
-          if System.Length(ACtx) > 255 then
-            raise EArgumentOutOfRangeCryptoLibException.CreateRes
-              (@SInvalidPublicKey);
-          Result := LEd25519.Verify(ASig, ASigOff, FPublicPoint, ACtx, AMsg,
-            AMsgOff, AMsgLen);
-        end;
-      TEd25519.TAlgorithm.Ed25519ph:
-        begin
-          // Note: In Pascal, nil and empty arrays are equivalent.
-          // We allow nil here, treating it as an empty context.
-          if System.Length(ACtx) > 255 then
-            raise EArgumentOutOfRangeCryptoLibException.CreateRes
-              (@SInvalidPublicKey);
-          if TEd25519.PrehashSize <> AMsgLen then
-            raise EArgumentOutOfRangeCryptoLibException.CreateRes
-              (@SInvalidPublicKey);
-          Result := LEd25519.VerifyPreHash(ASig, ASigOff, FPublicPoint, ACtx,
-            AMsg, AMsgOff);
-        end
-    else
-      raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SInvalidPublicKey);
-    end;
-  finally
-    LEd25519.Free;
-  end;
-end;
-
-function TEd25519PublicKeyParameters.Equals(const AOther
-  : IEd25519PublicKeyParameters): Boolean;
-var
-  LEncoded, LOtherEncoded: TCryptoLibByteArray;
-begin
-  if (AOther = Self as IEd25519PublicKeyParameters) then
-  begin
-    Result := True;
-    Exit;
-  end;
-
-  if (AOther = nil) then
-  begin
-    Result := False;
-    Exit;
-  end;
-  LEncoded := GetEncoded();
-  LOtherEncoded := AOther.GetEncoded();
-  Result := TArrayUtilities.FixedTimeEquals(LEncoded, LOtherEncoded);
-end;
-
-function TEd25519PublicKeyParameters.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
-{$ENDIF DELPHI}
-begin
-  Result := TArrayUtilities.GetArrayHashCode(GetEncoded());
-end;
-
-end.

+ 29 - 29
CryptoLib/src/Crypto/Parameters/ClpHkdfParameters.pas

@@ -39,11 +39,11 @@ type
 
   strict private
   var
-    Fikm, Fsalt, Finfo: TCryptoLibByteArray;
-    FskipExpand: Boolean;
+    FIkm, FSalt, FInfo: TCryptoLibByteArray;
+    FSkipExpand: Boolean;
 
-    constructor Create(const ikm: TCryptoLibByteArray; skip: Boolean;
-      const salt, info: TCryptoLibByteArray); overload;
+    constructor Create(const AIkm: TCryptoLibByteArray; ASkip: Boolean;
+      const ASalt, AInfo: TCryptoLibByteArray); overload;
 
   strict protected
 
@@ -70,7 +70,7 @@ type
     /// <param name="info">
     /// the info to use, may be null for an info field of zero bytes
     /// </param>
-    constructor Create(const ikm, salt, info: TCryptoLibByteArray); overload;
+    constructor Create(const AIkm, ASalt, AInfo: TCryptoLibByteArray); overload;
 
     /// <summary>
     /// Returns the input keying material or seed.
@@ -119,10 +119,10 @@ type
     /// <returns>
     /// that makes the implementation skip step 1
     /// </returns>
-    class function SkipExtractParameters(const ikm, info: TCryptoLibByteArray)
+    class function SkipExtractParameters(const AIkm, AInfo: TCryptoLibByteArray)
       : IHkdfParameters; static; inline;
 
-    class function DefaultParameters(const ikm: TCryptoLibByteArray)
+    class function DefaultParameters(const AIkm: TCryptoLibByteArray)
       : IHkdfParameters; static; inline;
 
   end;
@@ -131,69 +131,69 @@ implementation
 
 { THkdfParameters }
 
-constructor THkdfParameters.Create(const ikm: TCryptoLibByteArray;
-  skip: Boolean; const salt, info: TCryptoLibByteArray);
+constructor THkdfParameters.Create(const AIkm: TCryptoLibByteArray;
+  ASkip: Boolean; const ASalt, AInfo: TCryptoLibByteArray);
 begin
-  Inherited Create();
+  inherited Create();
 
-  if (ikm = Nil) then
+  if (AIkm = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SIKMNil);
   end;
 
-  Fikm := System.Copy(ikm);
-  FskipExpand := skip;
+  FIkm := System.Copy(AIkm);
+  FSkipExpand := ASkip;
 
-  if ((salt = Nil) or (System.Length(salt) = 0)) then
+  if ((ASalt = nil) or (System.Length(ASalt) = 0)) then
   begin
-    Fsalt := Nil;
+    FSalt := nil;
   end
   else
   begin
-    Fsalt := System.Copy(salt);
+    FSalt := System.Copy(ASalt);
   end;
 
-  if info <> Nil then
+  if AInfo <> nil then
   begin
-    Finfo := System.Copy(info);
+    FInfo := System.Copy(AInfo);
   end;
 end;
 
-constructor THkdfParameters.Create(const ikm, salt, info: TCryptoLibByteArray);
+constructor THkdfParameters.Create(const AIkm, ASalt, AInfo: TCryptoLibByteArray);
 begin
-  Create(ikm, false, salt, info);
+  Create(AIkm, False, ASalt, AInfo);
 end;
 
-class function THkdfParameters.DefaultParameters(const ikm: TCryptoLibByteArray)
+class function THkdfParameters.DefaultParameters(const AIkm: TCryptoLibByteArray)
   : IHkdfParameters;
 begin
-  result := THkdfParameters.Create(ikm, false, Nil, Nil);
+  Result := THkdfParameters.Create(AIkm, False, nil, nil);
 end;
 
 function THkdfParameters.GetIkm: TCryptoLibByteArray;
 begin
-  result := System.Copy(Fikm);
+  Result := System.Copy(FIkm);
 end;
 
 function THkdfParameters.GetInfo: TCryptoLibByteArray;
 begin
-  result := System.Copy(Finfo);
+  Result := System.Copy(FInfo);
 end;
 
 function THkdfParameters.GetSalt: TCryptoLibByteArray;
 begin
-  result := System.Copy(Fsalt);
+  Result := System.Copy(FSalt);
 end;
 
 function THkdfParameters.GetSkipExtract: Boolean;
 begin
-  result := FskipExpand;
+  Result := FSkipExpand;
 end;
 
-class function THkdfParameters.SkipExtractParameters(const ikm,
-  info: TCryptoLibByteArray): IHkdfParameters;
+class function THkdfParameters.SkipExtractParameters(const AIkm,
+  AInfo: TCryptoLibByteArray): IHkdfParameters;
 begin
-  result := THkdfParameters.Create(ikm, true, Nil, info);
+  Result := THkdfParameters.Create(AIkm, True, nil, AInfo);
 end;
 
 end.

+ 0 - 80
CryptoLib/src/Crypto/Parameters/ClpIesCipherParameters.pas

@@ -1,80 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpIesCipherParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpICipherParameters,
-  ClpIIESParameters,
-  ClpIIesCipherParameters;
-
-type
-  TIesCipherParameters = class sealed(TInterfacedObject, IIesCipherParameters,
-    ICipherParameters)
-
-  strict private
-  var
-    FPrivateKey: ICipherParameters;
-    FPublicKey: ICipherParameters;
-    FIesParameters: IIesParameters;
-
-    function GetPrivateKey: ICipherParameters; inline;
-    function GetPublicKey: ICipherParameters; inline;
-    function GetIesParameters: IIesParameters; inline;
-
-  public
-    constructor Create(const APrivateKey, APublicKey: ICipherParameters;
-      const AIesParameters: IIesParameters);
-
-    property PrivateKey: ICipherParameters read GetPrivateKey;
-    property PublicKey: ICipherParameters read GetPublicKey;
-    property IesParameters: IIesParameters read GetIesParameters;
-  end;
-
-implementation
-
-{ TIesCipherParameters }
-
-constructor TIesCipherParameters.Create(const APrivateKey,
-  APublicKey: ICipherParameters; const AIesParameters: IIesParameters);
-begin
-  Inherited Create();
-  FPrivateKey := APrivateKey;
-  FPublicKey := APublicKey;
-  FIesParameters := AIesParameters;
-end;
-
-function TIesCipherParameters.GetPrivateKey: ICipherParameters;
-begin
-  Result := FPrivateKey;
-end;
-
-function TIesCipherParameters.GetPublicKey: ICipherParameters;
-begin
-  Result := FPublicKey;
-end;
-
-function TIesCipherParameters.GetIesParameters: IIesParameters;
-begin
-  Result := FIesParameters;
-end;
-
-end.

+ 94 - 22
CryptoLib/src/Crypto/Parameters/ClpIesParameters.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpIESParameters;
+unit ClpIesParameters;
 
 {$I ..\..\Include\CryptoLib.inc}
 
@@ -23,66 +23,138 @@ interface
 
 uses
   ClpICipherParameters,
-  ClpIIESParameters,
+  ClpIIesParameters,
   ClpCryptoLibTypes;
 
 type
 
   /// <summary>
-  /// parameters for using an integrated cipher in stream mode.
+  /// Parameters for using an integrated cipher in stream mode.
   /// </summary>
   TIesParameters = class(TInterfacedObject, IIesParameters, ICipherParameters)
 
   strict private
   var
-    Fderivation, Fencoding: TCryptoLibByteArray;
-    FmacKeySize: Int32;
+    FDerivation, FEncoding: TCryptoLibByteArray;
+    FMacKeySize: Int32;
+
   strict protected
     function GetMacKeySize(): Int32; inline;
+
   public
     function GetDerivationV(): TCryptoLibByteArray; inline;
     function GetEncodingV(): TCryptoLibByteArray; inline;
+
     property MacKeySize: Int32 read GetMacKeySize;
 
-    /// <param name="ADerivation">
-    /// the derivation parameter for the KDF function.
-    /// </param>
-    /// <param name="AEncoding">
-    /// the encoding parameter for the KDF function.
-    /// </param>
-    /// <param name="AMacKeySize">
-    /// the size of the MAC key (in bits).
-    /// </param>
     constructor Create(const ADerivation, AEncoding: TCryptoLibByteArray;
       AMacKeySize: Int32);
   end;
 
+  TIesCipherParameters = class sealed(TInterfacedObject, IIesCipherParameters,
+    ICipherParameters)
+
+  strict private
+  var
+    FPrivateKey: ICipherParameters;
+    FPublicKey: ICipherParameters;
+    FIesParameters: IIesParameters;
+
+    function GetPrivateKey: ICipherParameters; inline;
+    function GetPublicKey: ICipherParameters; inline;
+    function GetIesParameters: IIesParameters; inline;
+
+  public
+    constructor Create(const APrivateKey, APublicKey: ICipherParameters;
+      const AIesParameters: IIesParameters);
+
+    property PrivateKey: ICipherParameters read GetPrivateKey;
+    property PublicKey: ICipherParameters read GetPublicKey;
+    property IesParameters: IIesParameters read GetIesParameters;
+  end;
+
+  TIesWithCipherParameters = class(TIesParameters, IIesParameters,
+    IIesWithCipherParameters)
+
+  strict private
+  var
+    FCipherKeySize: Int32;
+
+    function GetCipherKeySize: Int32; inline;
+
+  public
+    constructor Create(const ADerivation, AEncoding: TCryptoLibByteArray;
+      AMacKeySize, ACipherKeySize: Int32);
+
+    property CipherKeySize: Int32 read GetCipherKeySize;
+  end;
+
 implementation
 
-{ TIESParameters }
+{ TIesParameters }
 
 constructor TIesParameters.Create(const ADerivation,
   AEncoding: TCryptoLibByteArray; AMacKeySize: Int32);
 begin
-  Inherited Create();
-  Fderivation := ADerivation;
-  Fencoding := AEncoding;
-  FmacKeySize := AMacKeySize;
+  inherited Create();
+  FDerivation := ADerivation;
+  FEncoding := AEncoding;
+  FMacKeySize := AMacKeySize;
 end;
 
 function TIesParameters.GetDerivationV: TCryptoLibByteArray;
 begin
-  Result := System.Copy(Fderivation);
+  Result := System.Copy(FDerivation);
 end;
 
 function TIesParameters.GetEncodingV: TCryptoLibByteArray;
 begin
-  Result := System.Copy(Fencoding);
+  Result := System.Copy(FEncoding);
 end;
 
 function TIesParameters.GetMacKeySize: Int32;
 begin
-  Result := FmacKeySize;
+  Result := FMacKeySize;
+end;
+
+{ TIesCipherParameters }
+
+constructor TIesCipherParameters.Create(const APrivateKey,
+  APublicKey: ICipherParameters; const AIesParameters: IIesParameters);
+begin
+  inherited Create();
+  FPrivateKey := APrivateKey;
+  FPublicKey := APublicKey;
+  FIesParameters := AIesParameters;
+end;
+
+function TIesCipherParameters.GetPrivateKey: ICipherParameters;
+begin
+  Result := FPrivateKey;
+end;
+
+function TIesCipherParameters.GetPublicKey: ICipherParameters;
+begin
+  Result := FPublicKey;
+end;
+
+function TIesCipherParameters.GetIesParameters: IIesParameters;
+begin
+  Result := FIesParameters;
+end;
+
+{ TIesWithCipherParameters }
+
+function TIesWithCipherParameters.GetCipherKeySize: Int32;
+begin
+  Result := FCipherKeySize;
+end;
+
+constructor TIesWithCipherParameters.Create(const ADerivation,
+  AEncoding: TCryptoLibByteArray; AMacKeySize, ACipherKeySize: Int32);
+begin
+  inherited Create(ADerivation, AEncoding, AMacKeySize);
+  FCipherKeySize := ACipherKeySize;
 end;
 
 end.

+ 0 - 86
CryptoLib/src/Crypto/Parameters/ClpIesWithCipherParameters.pas

@@ -1,86 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpIesWithCipherParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIESParameters,
-  ClpIIESParameters,
-  ClpIIESWithCipherParameters,
-  ClpCryptoLibTypes;
-
-type
-
-  TIesWithCipherParameters = class(TIesParameters, IIesParameters,
-    IIesWithCipherParameters)
-
-  strict private
-  var
-    FcipherKeySize: Int32;
-
-    function GetCipherKeySize: Int32; inline;
-  public
-
-    /// <summary>
-    /// Set the IES engine parameters.
-    /// </summary>
-    /// <param name="ADerivation">
-    /// the optional derivation vector for the KDF.
-    /// </param>
-    /// <param name="AEncoding">
-    /// the optional encoding vector for the KDF.
-    /// </param>
-    /// <param name="AMacKeySize">
-    /// the key size (in bits) for the MAC.
-    /// </param>
-    /// <param name="ACipherKeySize">
-    /// the key size (in bits) for the block cipher.
-    /// </param>
-    constructor Create(const ADerivation, AEncoding: TCryptoLibByteArray;
-      AMacKeySize, ACipherKeySize: Int32);
-
-    /// <summary>
-    /// Return the key size in bits for the block cipher used with the message
-    /// </summary>
-    /// <value>
-    /// the key size in bits for the block cipher used with the message
-    /// </value>
-    property CipherKeySize: Int32 read GetCipherKeySize;
-
-  end;
-
-implementation
-
-{ TIESWithCipherParameters }
-
-function TIesWithCipherParameters.GetCipherKeySize: Int32;
-begin
-  Result := FcipherKeySize;
-end;
-
-constructor TIesWithCipherParameters.Create(const ADerivation,
-  AEncoding: TCryptoLibByteArray; AMacKeySize, ACipherKeySize: Int32);
-begin
-  Inherited Create(ADerivation, AEncoding, AMacKeySize);
-  FcipherKeySize := ACipherKeySize;
-end;
-
-end.

+ 6 - 6
CryptoLib/src/Crypto/Parameters/ClpIso18033KdfParameters.pas

@@ -35,27 +35,27 @@ type
     IDerivationParameters)
 
   strict private
-    Fseed: TCryptoLibByteArray;
+    FSeed: TCryptoLibByteArray;
 
   public
     function GetSeed(): TCryptoLibByteArray; inline;
 
-    constructor Create(const seed: TCryptoLibByteArray);
+    constructor Create(const ASeed: TCryptoLibByteArray);
   end;
 
 implementation
 
 { TIso18033KdfParameters }
 
-constructor TIso18033KdfParameters.Create(const seed: TCryptoLibByteArray);
+constructor TIso18033KdfParameters.Create(const ASeed: TCryptoLibByteArray);
 begin
-  Inherited Create();
-  Fseed := seed;
+  inherited Create();
+  FSeed := ASeed;
 end;
 
 function TIso18033KdfParameters.GetSeed: TCryptoLibByteArray;
 begin
-  result := Fseed;
+  Result := FSeed;
 end;
 
 end.

+ 8 - 8
CryptoLib/src/Crypto/Parameters/ClpKdfParameters.pas

@@ -35,34 +35,34 @@ type
     IDerivationParameters)
 
   strict private
-    Fiv, Fshared: TCryptoLibByteArray;
+    FIv, FShared: TCryptoLibByteArray;
 
   public
     function GetSharedSecret(): TCryptoLibByteArray; inline;
     function GetIV(): TCryptoLibByteArray; inline;
 
-    constructor Create(const shared, iv: TCryptoLibByteArray);
+    constructor Create(const AShared, AIv: TCryptoLibByteArray);
   end;
 
 implementation
 
 { TKdfParameters }
 
-constructor TKdfParameters.Create(const shared, iv: TCryptoLibByteArray);
+constructor TKdfParameters.Create(const AShared, AIv: TCryptoLibByteArray);
 begin
-  Inherited Create();
-  Fshared := shared;
-  Fiv := iv;
+  inherited Create();
+  FShared := AShared;
+  FIv := AIv;
 end;
 
 function TKdfParameters.GetIV: TCryptoLibByteArray;
 begin
-  result := Fiv;
+  Result := FIv;
 end;
 
 function TKdfParameters.GetSharedSecret: TCryptoLibByteArray;
 begin
-  result := Fshared;
+  Result := FShared;
 end;
 
 end.

+ 10 - 10
CryptoLib/src/Crypto/Parameters/ClpKeyGenerationParameters.pas

@@ -69,13 +69,13 @@ type
     /// initialise the generator with a source of randomness and a strength
     /// (in bits).
     /// </summary>
-    /// <param name="Random">
+    /// <param name="ARandom">
     /// the random byte source.
     /// </param>
-    /// <param name="Strength">
+    /// <param name="AStrength">
     /// the size, in bits, of the keys we want to produce.
     /// </param>
-    constructor Create(const Random: ISecureRandom; Strength: Int32);
+    constructor Create(const ARandom: ISecureRandom; AStrength: Int32);
 
   end;
 
@@ -83,18 +83,18 @@ implementation
 
 { TKeyGenerationParameters }
 
-constructor TKeyGenerationParameters.Create(const Random: ISecureRandom;
-  Strength: Int32);
+constructor TKeyGenerationParameters.Create(const ARandom: ISecureRandom;
+  AStrength: Int32);
 begin
-  if (Random = Nil) then
+  if (ARandom = nil) then
     raise EArgumentNilCryptoLibException.CreateRes(@SRandomNil);
 
-  if (Strength < 1) then
+  if (AStrength < 1) then
     raise EArgumentCryptoLibException.CreateResFmt(@SInvalidStrength,
-      [Strength]);
+      [AStrength]);
 
-  FRandom := Random;
-  FStrength := Strength;
+  FRandom := ARandom;
+  FStrength := AStrength;
 end;
 
 function TKeyGenerationParameters.GetRandom: ISecureRandom;

+ 18 - 18
CryptoLib/src/Crypto/Parameters/ClpKeyParameter.pas

@@ -38,12 +38,12 @@ type
 
   strict private
   var
-    Fkey: TCryptoLibByteArray;
+    FKey: TCryptoLibByteArray;
 
   public
-    constructor Create(const key: TCryptoLibByteArray); overload;
-    constructor Create(const key: TCryptoLibByteArray;
-      keyOff, keyLen: Int32); overload;
+    constructor Create(const AKey: TCryptoLibByteArray); overload;
+    constructor Create(const AKey: TCryptoLibByteArray;
+      AKeyOff, AKeyLen: Int32); overload;
     destructor Destroy; override;
     function GetKey(): TCryptoLibByteArray; inline;
     procedure Clear(); inline;
@@ -54,44 +54,44 @@ implementation
 
 { TKeyParameter }
 
-constructor TKeyParameter.Create(const key: TCryptoLibByteArray);
+constructor TKeyParameter.Create(const AKey: TCryptoLibByteArray);
 begin
-  Inherited Create();
+  inherited Create();
 
-  if (key = Nil) then
+  if (AKey = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SKeyNil);
   end;
-  Fkey := System.Copy(key);
+  FKey := System.Copy(AKey);
 end;
 
 procedure TKeyParameter.Clear;
 begin
-  TArrayUtilities.Fill<Byte>(Fkey, 0, System.Length(Fkey), Byte(0));
+  TArrayUtilities.Fill<Byte>(FKey, 0, System.Length(FKey), Byte(0));
 end;
 
-constructor TKeyParameter.Create(const key: TCryptoLibByteArray;
-  keyOff, keyLen: Int32);
+constructor TKeyParameter.Create(const AKey: TCryptoLibByteArray;
+  AKeyOff, AKeyLen: Int32);
 begin
-  Inherited Create();
+  inherited Create();
 
-  if (key = Nil) then
+  if (AKey = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SKeyNil);
   end;
 
-  if ((keyOff < 0) or (keyOff > System.Length(key))) then
+  if ((AKeyOff < 0) or (AKeyOff > System.Length(AKey))) then
   begin
     raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SInvalidKeyOffSet);
   end;
 
-  if ((keyLen < 0) or (keyLen > (System.Length(key) - keyOff))) then
+  if ((AKeyLen < 0) or (AKeyLen > (System.Length(AKey) - AKeyOff))) then
   begin
     raise EArgumentOutOfRangeCryptoLibException.CreateRes(@SInvalidKeyLength);
   end;
 
-  System.SetLength(Fkey, keyLen);
-  System.Move(key[keyOff], Fkey[0], keyLen);
+  System.SetLength(FKey, AKeyLen);
+  System.Move(AKey[AKeyOff], FKey[0], AKeyLen);
 
 end;
 
@@ -103,7 +103,7 @@ end;
 
 function TKeyParameter.GetKey: TCryptoLibByteArray;
 begin
-  result := System.Copy(Fkey);
+  Result := System.Copy(FKey);
 end;
 
 end.

+ 20 - 20
CryptoLib/src/Crypto/Parameters/ClpParametersWithIV.pas

@@ -36,19 +36,19 @@ type
 
   strict private
   var
-    Fparameters: ICipherParameters;
-    Fiv: TCryptoLibByteArray;
+    FParameters: ICipherParameters;
+    FIv: TCryptoLibByteArray;
 
     function GetParameters: ICipherParameters; inline;
 
   public
-    constructor Create(const parameters: ICipherParameters;
-      const iv: TCryptoLibByteArray); overload;
-    constructor Create(const parameters: ICipherParameters;
-      const iv: TCryptoLibByteArray; ivOff, ivLen: Int32); overload;
+    constructor Create(const AParameters: ICipherParameters;
+      const AIv: TCryptoLibByteArray); overload;
+    constructor Create(const AParameters: ICipherParameters;
+      const AIv: TCryptoLibByteArray; AIvOff, AIvLen: Int32); overload;
     destructor Destroy; override;
     function GetIV(): TCryptoLibByteArray; inline;
-    property parameters: ICipherParameters read GetParameters;
+    property Parameters: ICipherParameters read GetParameters;
     procedure Clear(); inline;
 
   end;
@@ -57,30 +57,30 @@ implementation
 
 { TParametersWithIV }
 
-constructor TParametersWithIV.Create(const parameters: ICipherParameters;
-  const iv: TCryptoLibByteArray);
+constructor TParametersWithIV.Create(const AParameters: ICipherParameters;
+  const AIv: TCryptoLibByteArray);
 begin
-  Inherited Create();
-  Create(parameters, iv, 0, System.Length(iv))
+  inherited Create();
+  Create(AParameters, AIv, 0, System.Length(AIv))
 end;
 
 procedure TParametersWithIV.Clear;
 begin
-  TArrayUtilities.Fill<Byte>(Fiv, 0, System.Length(Fiv), Byte(0));
+  TArrayUtilities.Fill<Byte>(FIv, 0, System.Length(FIv), Byte(0));
 end;
 
-constructor TParametersWithIV.Create(const parameters: ICipherParameters;
-  const iv: TCryptoLibByteArray; ivOff, ivLen: Int32);
+constructor TParametersWithIV.Create(const AParameters: ICipherParameters;
+  const AIv: TCryptoLibByteArray; AIvOff, AIvLen: Int32);
 begin
-  Inherited Create();
+  inherited Create();
   // NOTE: 'parameters' may be null to imply key re-use
-  if (iv = Nil) then
+  if (AIv = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SIVNil);
   end;
 
-  Fparameters := parameters;
-  Fiv := TArrayUtilities.CopyOfRange<Byte>(iv, ivOff, ivOff + ivLen);
+  FParameters := AParameters;
+  FIv := TArrayUtilities.CopyOfRange<Byte>(AIv, AIvOff, AIvOff + AIvLen);
 end;
 
 destructor TParametersWithIV.Destroy;
@@ -91,12 +91,12 @@ end;
 
 function TParametersWithIV.GetIV: TCryptoLibByteArray;
 begin
-  result := System.Copy(Fiv);
+  Result := System.Copy(FIv);
 end;
 
 function TParametersWithIV.GetParameters: ICipherParameters;
 begin
-  result := Fparameters;
+  Result := FParameters;
 end;
 
 end.

+ 17 - 17
CryptoLib/src/Crypto/Parameters/ClpParametersWithRandom.pas

@@ -38,21 +38,21 @@ type
 
   strict private
   var
-    Fparameters: ICipherParameters;
-    Frandom: ISecureRandom;
+    FParameters: ICipherParameters;
+    FRandom: ISecureRandom;
     function GetRandom: ISecureRandom; inline;
     function GetParameters: ICipherParameters; inline;
 
   public
 
-    constructor Create(const parameters: ICipherParameters); overload;
+    constructor Create(const AParameters: ICipherParameters); overload;
 
-    constructor Create(const parameters: ICipherParameters;
-      const random: ISecureRandom); overload;
+    constructor Create(const AParameters: ICipherParameters;
+      const ARandom: ISecureRandom); overload;
 
-    property random: ISecureRandom read GetRandom;
+    property Random: ISecureRandom read GetRandom;
 
-    property parameters: ICipherParameters read GetParameters;
+    property Parameters: ICipherParameters read GetParameters;
 
   end;
 
@@ -60,37 +60,37 @@ implementation
 
 { TParametersWithRandom }
 
-constructor TParametersWithRandom.Create(const parameters: ICipherParameters);
+constructor TParametersWithRandom.Create(const AParameters: ICipherParameters);
 begin
-  Create(parameters, TSecureRandom.Create() as ISecureRandom);
+  Create(AParameters, TSecureRandom.Create() as ISecureRandom);
 end;
 
-constructor TParametersWithRandom.Create(const parameters: ICipherParameters;
-  const random: ISecureRandom);
+constructor TParametersWithRandom.Create(const AParameters: ICipherParameters;
+  const ARandom: ISecureRandom);
 begin
   inherited Create();
-  if (parameters = Nil) then
+  if (AParameters = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SParameters);
   end;
 
-  if (random = Nil) then
+  if (ARandom = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SRandom);
   end;
 
-  Fparameters := parameters;
-  Frandom := random;
+  FParameters := AParameters;
+  FRandom := ARandom;
 end;
 
 function TParametersWithRandom.GetParameters: ICipherParameters;
 begin
-  Result := Fparameters;
+  Result := FParameters;
 end;
 
 function TParametersWithRandom.GetRandom: ISecureRandom;
 begin
-  Result := Frandom;
+  Result := FRandom;
 end;
 
 end.

+ 0 - 86
CryptoLib/src/Crypto/Parameters/ClpRsaBlindingParameters.pas

@@ -1,86 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpRsaBlindingParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpBigInteger,
-  ClpIRsaKeyParameters,
-  ClpIRsaBlindingParameters,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SPublicKeyRequired = 'RSA parameters should be for a public key';
-
-type
-  /// <summary>
-  /// Parameters for RSA blinding operations.
-  /// </summary>
-  TRsaBlindingParameters = class(TInterfacedObject, IRsaBlindingParameters)
-
-  strict private
-  var
-    FPublicKey: IRsaKeyParameters;
-    FBlindingFactor: TBigInteger;
-
-  strict protected
-    function GetPublicKey: IRsaKeyParameters;
-    function GetBlindingFactor: TBigInteger;
-
-  public
-    constructor Create(const publicKey: IRsaKeyParameters;
-      const blindingFactor: TBigInteger);
-
-    property PublicKey: IRsaKeyParameters read GetPublicKey;
-    property BlindingFactor: TBigInteger read GetBlindingFactor;
-
-  end;
-
-implementation
-
-{ TRsaBlindingParameters }
-
-constructor TRsaBlindingParameters.Create(const publicKey: IRsaKeyParameters;
-  const blindingFactor: TBigInteger);
-begin
-  inherited Create();
-
-  if publicKey.IsPrivate then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SPublicKeyRequired);
-  end;
-
-  FPublicKey := publicKey;
-  FBlindingFactor := blindingFactor;
-end;
-
-function TRsaBlindingParameters.GetBlindingFactor: TBigInteger;
-begin
-  Result := FBlindingFactor;
-end;
-
-function TRsaBlindingParameters.GetPublicKey: IRsaKeyParameters;
-begin
-  Result := FPublicKey;
-end;
-
-end.

+ 0 - 139
CryptoLib/src/Crypto/Parameters/ClpRsaKeyGenerationParameters.pas

@@ -1,139 +0,0 @@
-{ *********************************************************************************** }
-{ *                              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 ClpRsaKeyGenerationParameters;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpBigInteger,
-  ClpIRsaKeyGenerationParameters,
-  ClpKeyGenerationParameters,
-  ClpISecureRandom,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SPublicExponentNil = 'publicExponent';
-  SPublicExponentNotOdd = 'Public exponent must be an odd number';
-
-type
-  /// <summary>
-  /// RSA key generation parameters.
-  /// </summary>
-  TRsaKeyGenerationParameters = class(TKeyGenerationParameters,
-    IRsaKeyGenerationParameters)
-
-  strict private
-  const
-    DefaultTests = 100;
-
-  var
-    FPublicExponent: TBigInteger;
-    FCertainty: Int32;
-
-  strict protected
-    function GetPublicExponent: TBigInteger;
-    function GetCertainty: Int32;
-
-  public
-    /// <summary>
-    /// Create RSA key generation parameters.
-    /// </summary>
-    /// <param name="publicExponent">
-    /// The public exponent for generated keys, typically 0x10001 (65537).
-    /// </param>
-    /// <param name="random">
-    /// The random source for key generation.
-    /// </param>
-    /// <param name="strength">
-    /// The key size in bits.
-    /// </param>
-    /// <param name="certainty">
-    /// The certainty (number of iterations) for primality testing.
-    /// </param>
-    constructor Create(const publicExponent: TBigInteger;
-      const random: ISecureRandom; strength, certainty: Int32);
-
-    function Equals(const other: IRsaKeyGenerationParameters): Boolean;
-      reintroduce; overload;
-    function GetHashCode: {$IFDEF DELPHI}Int32;{$ELSE}PtrInt;{$ENDIF DELPHI} override;
-
-    property PublicExponent: TBigInteger read GetPublicExponent;
-    property Certainty: Int32 read GetCertainty;
-
-  end;
-
-implementation
-
-{ TRsaKeyGenerationParameters }
-
-constructor TRsaKeyGenerationParameters.Create(const publicExponent: TBigInteger;
-  const random: ISecureRandom; strength, certainty: Int32);
-begin
-  inherited Create(random, strength);
-
-  if not publicExponent.IsInitialized then
-  begin
-    raise EArgumentNilCryptoLibException.CreateRes(@SPublicExponentNil);
-  end;
-
-  if not publicExponent.TestBit(0) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SPublicExponentNotOdd);
-  end;
-
-  FPublicExponent := publicExponent;
-  FCertainty := certainty;
-end;
-
-function TRsaKeyGenerationParameters.GetCertainty: Int32;
-begin
-  Result := FCertainty;
-end;
-
-function TRsaKeyGenerationParameters.GetPublicExponent: TBigInteger;
-begin
-  Result := FPublicExponent;
-end;
-
-function TRsaKeyGenerationParameters.Equals(const other: IRsaKeyGenerationParameters): Boolean;
-begin
-  if other = nil then
-  begin
-    Result := False;
-    Exit;
-  end;
-
-  if (Self as IRsaKeyGenerationParameters) = other then
-  begin
-    Result := True;
-    Exit;
-  end;
-
-  Result := (FCertainty = other.Certainty) and
-    FPublicExponent.Equals(other.PublicExponent);
-end;
-
-function TRsaKeyGenerationParameters.GetHashCode: {$IFDEF DELPHI}Int32;{$ELSE}PtrInt;{$ENDIF DELPHI}
-begin
-  Result := FCertainty xor FPublicExponent.GetHashCode();
-end;
-
-end.

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно