Ver código fonte

some refactorings

Ugochukwu Mmaduekwe 6 dias atrás
pai
commit
7ef80af1ff
72 arquivos alterados com 2688 adições e 2975 exclusões
  1. 27 6
      CryptoLib.Samples/Delphi.Samples/UsageSamples.dpr
  2. 22 4
      CryptoLib.Samples/src/UsageExamples.pas
  3. 27 6
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr
  4. 10 2
      CryptoLib.Tests/src/Crypto/AESTests.pas
  5. 10 2
      CryptoLib.Tests/src/Crypto/CTSTests.pas
  6. 12 2
      CryptoLib.Tests/src/Crypto/PaddingTests.pas
  7. 10 2
      CryptoLib.Tests/src/Crypto/SPECKTests.pas
  8. 10 2
      CryptoLib.Tests/src/Math/ECIESTests.pas
  9. 22 4
      CryptoLib.Tests/src/Math/IESCipherTests.pas
  10. 22 4
      CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas
  11. 3 3
      CryptoLib/src/Crypto/Agreements/ClpDHAgreement.pas
  12. 4 4
      CryptoLib/src/Crypto/Agreements/ClpDHBasicAgreement.pas
  13. 4 4
      CryptoLib/src/Crypto/Agreements/ClpECDHBasicAgreement.pas
  14. 4 4
      CryptoLib/src/Crypto/Agreements/ClpECDHCBasicAgreement.pas
  15. 0 1515
      CryptoLib/src/Crypto/Ciphers/ClpBlockCipherModes.pas
  16. 156 156
      CryptoLib/src/Crypto/Ciphers/ClpBufferedBlockCipher.pas
  17. 7 7
      CryptoLib/src/Crypto/Ciphers/ClpBufferedIesCipher.pas
  18. 54 54
      CryptoLib/src/Crypto/Ciphers/ClpBufferedStreamCipher.pas
  19. 178 0
      CryptoLib/src/Crypto/Ciphers/ClpCbcBlockCipher.pas
  20. 195 0
      CryptoLib/src/Crypto/Ciphers/ClpCfbBlockCipher.pas
  21. 22 4
      CryptoLib/src/Crypto/Ciphers/ClpCipherUtilities.pas
  22. 255 0
      CryptoLib/src/Crypto/Ciphers/ClpCtsBlockCipher.pas
  23. 161 0
      CryptoLib/src/Crypto/Ciphers/ClpOfbBlockCipher.pas
  24. 175 0
      CryptoLib/src/Crypto/Ciphers/ClpSicBlockCipher.pas
  25. 1 1
      CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas
  26. 1 1
      CryptoLib/src/Crypto/Generators/ClpDHBasicKeyPairGenerator.pas
  27. 1 1
      CryptoLib/src/Crypto/Generators/ClpDHKeyPairGenerator.pas
  28. 2 2
      CryptoLib/src/Crypto/Generators/ClpDsaKeyPairGenerator.pas
  29. 1 1
      CryptoLib/src/Crypto/Generators/ClpDsaParametersGenerator.pas
  30. 2 2
      CryptoLib/src/Crypto/Generators/ClpECKeyPairGenerator.pas
  31. 1 1
      CryptoLib/src/Crypto/Generators/ClpX25519KeyPairGenerator.pas
  32. 87 0
      CryptoLib/src/Crypto/Paddings/ClpISO10126d2Padding.pas
  33. 86 0
      CryptoLib/src/Crypto/Paddings/ClpISO7816d4Padding.pas
  34. 119 109
      CryptoLib/src/Crypto/Paddings/ClpPaddedBufferedBlockCipher.pas
  35. 0 734
      CryptoLib/src/Crypto/Paddings/ClpPaddingModes.pas
  36. 89 0
      CryptoLib/src/Crypto/Paddings/ClpPkcs7Padding.pas
  37. 96 0
      CryptoLib/src/Crypto/Paddings/ClpTBCPadding.pas
  38. 86 0
      CryptoLib/src/Crypto/Paddings/ClpX923Padding.pas
  39. 89 0
      CryptoLib/src/Crypto/Paddings/ClpZeroBytePadding.pas
  40. 1 1
      CryptoLib/src/Crypto/Parameters/ClpDHKeyParameters.pas
  41. 4 4
      CryptoLib/src/Crypto/Parameters/ClpDsaKeyParameters.pas
  42. 1 1
      CryptoLib/src/Crypto/Parameters/ClpECKeyParameters.pas
  43. 5 2
      CryptoLib/src/Crypto/Signers/ClpDsaDigestSigner.pas
  44. 5 1
      CryptoLib/src/Crypto/Signers/ClpSignerUtilities.pas
  45. 6 110
      CryptoLib/src/Crypto/Signers/SignerEncodings/ClpPlainDsaEncoding.pas
  46. 126 0
      CryptoLib/src/Crypto/Signers/SignerEncodings/ClpStandardDsaEncoding.pas
  47. 1 1
      CryptoLib/src/Factories/ClpSubjectPublicKeyInfoFactory.pas
  48. 8 8
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIAsymmetricBlockCipher.pas
  49. 9 9
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIBlockCipher.pas
  50. 35 0
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpICbcBlockCipher.pas
  51. 35 0
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpICfbBlockCipher.pas
  52. 35 0
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpICtsBlockCipher.pas
  53. 2 56
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIOfbBlockCipher.pas
  54. 43 0
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpISicBlockCipher.pas
  55. 12 12
      CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIStreamCipher.pas
  56. 7 7
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpIBlockCipherPadding.pas
  57. 1 38
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpIISO10126d2Padding.pas
  58. 34 0
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpIISO7816d4Padding.pas
  59. 34 0
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpIPkcs7Padding.pas
  60. 34 0
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpITBCPadding.pas
  61. 34 0
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpIX923Padding.pas
  62. 34 0
      CryptoLib/src/Interfaces/Crypto/Paddings/ClpIZeroBytePadding.pas
  63. 1 1
      CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDHKeyGenerationParameters.pas
  64. 1 1
      CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDHKeyParameters.pas
  65. 1 1
      CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDsaKeyGenerationParameters.pas
  66. 1 1
      CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDsaKeyParameters.pas
  67. 1 1
      CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDsaParameterGenerationParameters.pas
  68. 2 2
      CryptoLib/src/Interfaces/Crypto/Parameters/ClpIParametersWithRandom.pas
  69. 40 0
      CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpIDsaEncoding.pas
  70. 42 0
      CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpIPlainDsaEncoding.pas
  71. 0 81
      CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpISignersEncodings.pas
  72. 42 0
      CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpIStandardDsaEncoding.pas

+ 27 - 6
CryptoLib.Samples/Delphi.Samples/UsageSamples.dpr

@@ -230,7 +230,9 @@ uses
   ClpNat512 in '..\..\CryptoLib\src\Math\Raw\ClpNat512.pas',
   ClpInterleave in '..\..\CryptoLib\src\Math\Raw\ClpInterleave.pas',
   ClpIDsaExt in '..\..\CryptoLib\src\Interfaces\ClpIDsaExt.pas',
-  ClpISignersEncodings in '..\..\CryptoLib\src\Interfaces\ClpISignersEncodings.pas',
+  ClpIDsaEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpIDsaEncoding.pas',
+  ClpIStandardDsaEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpIStandardDsaEncoding.pas',
+  ClpIPlainDsaEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpIPlainDsaEncoding.pas',
   ClpBsiObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Bsi\ClpBsiObjectIdentifiers.pas',
   ClpEacObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Eac\ClpEacObjectIdentifiers.pas',
   ClpSchnorrDigestSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpSchnorrDigestSigner.pas',
@@ -253,10 +255,28 @@ uses
   ClpSecT283Custom in '..\..\CryptoLib\src\Math\EC\Custom\Sec\ClpSecT283Custom.pas',
   ClpISecT283Custom in '..\..\CryptoLib\src\Interfaces\ClpISecT283Custom.pas',
   ClpISecP384R1Custom in '..\..\CryptoLib\src\Interfaces\ClpISecP384R1Custom.pas',
-  ClpBlockCipherModes in '..\..\CryptoLib\src\Crypto\Modes\ClpBlockCipherModes.pas',
-  ClpIBlockCipherModes in '..\..\CryptoLib\src\Interfaces\ClpIBlockCipherModes.pas',
-  ClpPaddingModes in '..\..\CryptoLib\src\Crypto\Paddings\ClpPaddingModes.pas',
-  ClpIPaddingModes in '..\..\CryptoLib\src\Interfaces\ClpIPaddingModes.pas',
+  ClpCbcBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpCbcBlockCipher.pas',
+  ClpCfbBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpCfbBlockCipher.pas',
+  ClpCtsBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpCtsBlockCipher.pas',
+  ClpOfbBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpOfbBlockCipher.pas',
+  ClpSicBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpSicBlockCipher.pas',
+  ClpICbcBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpICbcBlockCipher.pas',
+  ClpICfbBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpICfbBlockCipher.pas',
+  ClpICtsBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpICtsBlockCipher.pas',
+  ClpIOfbBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpIOfbBlockCipher.pas',
+  ClpISicBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpISicBlockCipher.pas',
+  ClpISO10126d2Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpISO10126d2Padding.pas',
+  ClpISO7816d4Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpISO7816d4Padding.pas',
+  ClpPkcs7Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpPkcs7Padding.pas',
+  ClpTBCPadding in '..\..\CryptoLib\src\Crypto\Paddings\ClpTBCPadding.pas',
+  ClpX923Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpX923Padding.pas',
+  ClpZeroBytePadding in '..\..\CryptoLib\src\Crypto\Paddings\ClpZeroBytePadding.pas',
+  ClpIISO10126d2Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIISO10126d2Padding.pas',
+  ClpIISO7816d4Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIISO7816d4Padding.pas',
+  ClpIPkcs7Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIPkcs7Padding.pas',
+  ClpITBCPadding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpITBCPadding.pas',
+  ClpIX923Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIX923Padding.pas',
+  ClpIZeroBytePadding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIZeroBytePadding.pas',
   ClpECC in '..\..\CryptoLib\src\Math\EC\ClpECC.pas',
   ClpX9ECC in '..\..\CryptoLib\src\Asn1\X9\ClpX9ECC.pas',
   ClpIX9ECC in '..\..\CryptoLib\src\Interfaces\ClpIX9ECC.pas',
@@ -264,7 +284,8 @@ uses
   ClpAsn1Objects in '..\..\CryptoLib\src\Asn1\ClpAsn1Objects.pas',
   ClpAsn1Utilities in '..\..\CryptoLib\src\Asn1\ClpAsn1Utilities.pas',
   ClpAsn1Streams in '..\..\CryptoLib\src\Asn1\ClpAsn1Streams.pas',
-  ClpSignersEncodings in '..\..\CryptoLib\src\Crypto\Signers\SignersEncodings\ClpSignersEncodings.pas',
+  ClpStandardDsaEncoding in '..\..\CryptoLib\src\Crypto\Signers\SignerEncodings\ClpStandardDsaEncoding.pas',
+  ClpPlainDsaEncoding in '..\..\CryptoLib\src\Crypto\Signers\SignerEncodings\ClpPlainDsaEncoding.pas',
   ClpIStreamCipher in '..\..\CryptoLib\src\Interfaces\ClpIStreamCipher.pas',
   ClpBufferedStreamCipher in '..\..\CryptoLib\src\Crypto\ClpBufferedStreamCipher.pas',
   ClpIBufferedStreamCipher in '..\..\CryptoLib\src\Interfaces\ClpIBufferedStreamCipher.pas',

+ 22 - 4
CryptoLib.Samples/src/UsageExamples.pas

@@ -78,10 +78,28 @@ uses
   ClpIParametersWithIV,
   ClpIAesEngine,
   ClpAesEngine,
-  ClpIBlockCipherModes,
-  ClpBlockCipherModes,
-  ClpIPaddingModes,
-  ClpPaddingModes,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpIISO10126d2Padding,
+  ClpIISO7816d4Padding,
+  ClpIPkcs7Padding,
+  ClpITBCPadding,
+  ClpIX923Padding,
+  ClpIZeroBytePadding,
+  ClpISO10126d2Padding,
+  ClpISO7816d4Padding,
+  ClpPkcs7Padding,
+  ClpTBCPadding,
+  ClpX923Padding,
+  ClpZeroBytePadding,
   ClpIECDHBasicAgreement,
   ClpECDHBasicAgreement,
   ClpIPascalCoinECIESKdfBytesGenerator,

+ 27 - 6
CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr

@@ -48,7 +48,11 @@ uses
   ClpBigIntegers in '..\..\CryptoLib\src\Math\ClpBigIntegers.pas',
   ClpPrimes in '..\..\CryptoLib\src\Math\ClpPrimes.pas',
   ClpBitConverter in '..\..\CryptoLib\src\Misc\ClpBitConverter.pas',
-  ClpBlockCipherModes in '..\..\CryptoLib\src\Crypto\Ciphers\ClpBlockCipherModes.pas',
+  ClpCbcBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpCbcBlockCipher.pas',
+  ClpCfbBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpCfbBlockCipher.pas',
+  ClpCtsBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpCtsBlockCipher.pas',
+  ClpOfbBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpOfbBlockCipher.pas',
+  ClpSicBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpSicBlockCipher.pas',
   ClpBlowfishEngine in '..\..\CryptoLib\src\Crypto\Engines\ClpBlowfishEngine.pas',
   ClpBsiObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Bsi\ClpBsiObjectIdentifiers.pas',
   ClpBufferedAsymmetricBlockCipher in '..\..\CryptoLib\src\Crypto\Ciphers\ClpBufferedAsymmetricBlockCipher.pas',
@@ -164,7 +168,11 @@ uses
   ClpIBaseKdfBytesGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIBaseKdfBytesGenerator.pas',
   ClpIBasicAgreement in '..\..\CryptoLib\src\Interfaces\Crypto\Agreements\ClpIBasicAgreement.pas',
   ClpIBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpIBlockCipher.pas',
-  ClpIBlockCipherModes in '..\..\CryptoLib\src\Interfaces\Crypto\Modes\ClpIBlockCipherModes.pas',
+  ClpICbcBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpICbcBlockCipher.pas',
+  ClpICfbBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpICfbBlockCipher.pas',
+  ClpICtsBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpICtsBlockCipher.pas',
+  ClpIOfbBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpIOfbBlockCipher.pas',
+  ClpISicBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Ciphers\ClpISicBlockCipher.pas',
   ClpIBlockCipherPadding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIBlockCipherPadding.pas',
   ClpIBlockResult in '..\..\CryptoLib\src\Interfaces\Crypto\Operators\ClpIBlockResult.pas',
   ClpIBlowfishEngine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpIBlowfishEngine.pas',
@@ -270,7 +278,12 @@ uses
   ClpIOaepEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Encodings\ClpIOaepEncoding.pas',
   ClpIOidTokenizer in '..\..\CryptoLib\src\Interfaces\Asn1\ClpIOidTokenizer.pas',
   ClpIPaddedBufferedBlockCipher in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIPaddedBufferedBlockCipher.pas',
-  ClpIPaddingModes in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIPaddingModes.pas',
+  ClpIISO10126d2Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIISO10126d2Padding.pas',
+  ClpIISO7816d4Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIISO7816d4Padding.pas',
+  ClpIPkcs7Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIPkcs7Padding.pas',
+  ClpITBCPadding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpITBCPadding.pas',
+  ClpIX923Padding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIX923Padding.pas',
+  ClpIZeroBytePadding in '..\..\CryptoLib\src\Interfaces\Crypto\Paddings\ClpIZeroBytePadding.pas',
   ClpIPAddressUtilities in '..\..\CryptoLib\src\Net\ClpIPAddressUtilities.pas',
   ClpIParametersWithIV in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIParametersWithIV.pas',
   ClpIParametersWithRandom in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIParametersWithRandom.pas',
@@ -320,7 +333,9 @@ uses
   ClpISecureRandom in '..\..\CryptoLib\src\Interfaces\Crypto\Randoms\ClpISecureRandom.pas',
   ClpISignatureFactory in '..\..\CryptoLib\src\Interfaces\Crypto\Operators\ClpISignatureFactory.pas',
   ClpISigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpISigner.pas',
-  ClpISignersEncodings in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpISignersEncodings.pas',
+  ClpIDsaEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpIDsaEncoding.pas',
+  ClpIStandardDsaEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpIStandardDsaEncoding.pas',
+  ClpIPlainDsaEncoding in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\SignerEncodings\ClpIPlainDsaEncoding.pas',
   ClpIso18033KdfParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpIso18033KdfParameters.pas',
   ClpISO9796d1Encoding in '..\..\CryptoLib\src\Crypto\Encodings\ClpISO9796d1Encoding.pas',
   ClpIsoTrailers in '..\..\CryptoLib\src\Crypto\Signers\ClpIsoTrailers.pas',
@@ -366,7 +381,12 @@ uses
   ClpOidTokenizer in '..\..\CryptoLib\src\Asn1\ClpOidTokenizer.pas',
   ClpOiwObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Oiw\ClpOiwObjectIdentifiers.pas',
   ClpPaddedBufferedBlockCipher in '..\..\CryptoLib\src\Crypto\Paddings\ClpPaddedBufferedBlockCipher.pas',
-  ClpPaddingModes in '..\..\CryptoLib\src\Crypto\Paddings\ClpPaddingModes.pas',
+  ClpISO10126d2Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpISO10126d2Padding.pas',
+  ClpISO7816d4Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpISO7816d4Padding.pas',
+  ClpPkcs7Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpPkcs7Padding.pas',
+  ClpTBCPadding in '..\..\CryptoLib\src\Crypto\Paddings\ClpTBCPadding.pas',
+  ClpX923Padding in '..\..\CryptoLib\src\Crypto\Paddings\ClpX923Padding.pas',
+  ClpZeroBytePadding in '..\..\CryptoLib\src\Crypto\Paddings\ClpZeroBytePadding.pas',
   ClpParametersWithIV in '..\..\CryptoLib\src\Crypto\Parameters\ClpParametersWithIV.pas',
   ClpParametersWithRandom in '..\..\CryptoLib\src\Crypto\Parameters\ClpParametersWithRandom.pas',
   ClpParameterUtilities in '..\..\CryptoLib\src\Crypto\Parameters\ClpParameterUtilities.pas',
@@ -417,7 +437,8 @@ uses
   ClpSecureRandom in '..\..\CryptoLib\src\Crypto\Randoms\ClpSecureRandom.pas',
   ClpSetWeakRef in '..\..\CryptoLib\src\Misc\ClpSetWeakRef.pas',
   ClpWeakRef in '..\..\CryptoLib\src\Misc\ClpWeakRef.pas',
-  ClpSignersEncodings in '..\..\CryptoLib\src\Crypto\Signers\SignerEncodings\ClpSignersEncodings.pas',
+  ClpStandardDsaEncoding in '..\..\CryptoLib\src\Crypto\Signers\SignerEncodings\ClpStandardDsaEncoding.pas',
+  ClpPlainDsaEncoding in '..\..\CryptoLib\src\Crypto\Signers\SignerEncodings\ClpPlainDsaEncoding.pas',
   ClpSignerSink in '..\..\CryptoLib\src\Crypto\IO\ClpSignerSink.pas',
   ClpScalar25519 in '..\..\CryptoLib\src\Math\EC\Rfc8032\ClpScalar25519.pas',
   ClpScalarUtilities in '..\..\CryptoLib\src\Math\EC\Rfc8032\ClpScalarUtilities.pas',

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

@@ -44,8 +44,16 @@ uses
   ClpParameterUtilities,
   ClpCipherUtilities,
   ClpNistObjectIdentifiers,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
   ClpIBlockCipher,
   ClpBufferedBlockCipher,
   ClpIBufferedBlockCipher,

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

@@ -45,8 +45,16 @@ uses
   // ClpParameterUtilities,
   // ClpCipherUtilities,
   // ClpNistObjectIdentifiers,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
   ClpIBlockCipher,
   // ClpBufferedBlockCipher,
   // ClpIBufferedBlockCipher,

+ 12 - 2
CryptoLib.Tests/src/Crypto/PaddingTests.pas

@@ -38,8 +38,18 @@ uses
   ClpIBlockCipherPadding,
   ClpAesEngine,
   ClpIAesEngine,
-  ClpPaddingModes,
-  ClpIPaddingModes,
+  ClpISO10126d2Padding,
+  ClpISO7816d4Padding,
+  ClpPkcs7Padding,
+  ClpTBCPadding,
+  ClpX923Padding,
+  ClpZeroBytePadding,
+  ClpIISO10126d2Padding,
+  ClpIISO7816d4Padding,
+  ClpIPkcs7Padding,
+  ClpITBCPadding,
+  ClpIX923Padding,
+  ClpIZeroBytePadding,
   ClpPaddedBufferedBlockCipher,
   ClpIPaddedBufferedBlockCipher,
   ClpCryptoLibTypes,

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

@@ -40,8 +40,16 @@ uses
   ClpIParametersWithIV,
   ClpIBufferedCipher,
   ClpICipherParameters,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
   ClpIBlockCipher,
   ClpBufferedBlockCipher,
   ClpIBufferedBlockCipher,

+ 10 - 2
CryptoLib.Tests/src/Math/ECIESTests.pas

@@ -66,8 +66,16 @@ uses
   ClpIEphemeralKeyPairGenerator,
   ClpECIESPublicKeyParser,
   ClpIECIESPublicKeyParser,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
   ClpKeyEncoder,
   ClpIKeyEncoder,
   ClpAesEngine,

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

@@ -50,15 +50,33 @@ uses
   ClpIBufferedBlockCipher,
   // ClpParameterUtilities,
   // ClpCipherUtilities,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
   ClpPaddedBufferedBlockCipher,
   ClpECDHBasicAgreement,
   ClpIECDHBasicAgreement,
   ClpIESEngine,
   ClpIIESEngine,
-  ClpPaddingModes,
-  ClpIPaddingModes,
+  ClpISO10126d2Padding,
+  ClpISO7816d4Padding,
+  ClpPkcs7Padding,
+  ClpTBCPadding,
+  ClpX923Padding,
+  ClpZeroBytePadding,
+  ClpIISO10126d2Padding,
+  ClpIISO7816d4Padding,
+  ClpIPkcs7Padding,
+  ClpITBCPadding,
+  ClpIX923Padding,
+  ClpIZeroBytePadding,
   ClpKdf2BytesGenerator,
   ClpIKdf2BytesGenerator,
   ClpIX9ECAsn1Objects,

+ 22 - 4
CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas

@@ -41,8 +41,16 @@ uses
   ClpIECDomainParameters,
   ClpIBufferedBlockCipher,
   ClpPaddedBufferedBlockCipher,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpCbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpCtsBlockCipher,
+  ClpOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICtsBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
   ClpAesEngine,
   ClpIAesEngine,
   ClpBigInteger,
@@ -59,8 +67,18 @@ uses
   ClpPascalCoinIESEngine,
   ClpPascalCoinECIESKdfBytesGenerator,
   ClpIPascalCoinECIESKdfBytesGenerator,
-  ClpPaddingModes,
-  ClpIPaddingModes,
+  ClpISO10126d2Padding,
+  ClpISO7816d4Padding,
+  ClpPkcs7Padding,
+  ClpTBCPadding,
+  ClpX923Padding,
+  ClpZeroBytePadding,
+  ClpIISO10126d2Padding,
+  ClpIISO7816d4Padding,
+  ClpIPkcs7Padding,
+  ClpITBCPadding,
+  ClpIX923Padding,
+  ClpIZeroBytePadding,
   ClpIMac,
   ClpMacUtilities,
   ClpIX9ECAsn1Objects,

+ 3 - 3
CryptoLib/src/Crypto/Agreements/ClpDHAgreement.pas

@@ -117,7 +117,7 @@ begin
       (@SMessageNotInitialized);
   end;
 
-  if (not(pub.parameters.Equals(FdhParams))) then
+  if (not(pub.Parameters.Equals(FdhParams))) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SDHPublicKeyWrongParameter);
   end;
@@ -167,7 +167,7 @@ begin
   if Supports(parameters, IParametersWithRandom, rParam) then
   begin
     Frandom := rParam.Random;
-    kParam := rParam.parameters as IAsymmetricKeyParameter;
+    kParam := rParam.Parameters as IAsymmetricKeyParameter;
   end
   else
   begin
@@ -181,7 +181,7 @@ begin
   end;
 
   Fkey := kParam as IDHPrivateKeyParameters;
-  FdhParams := Fkey.parameters;
+  FdhParams := Fkey.Parameters;
 end;
 
 end.

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

@@ -98,7 +98,7 @@ begin
 
   pub := pubKey as IDHPublicKeyParameters;
 
-  if (not(pub.parameters.Equals(FdhParams))) then
+  if (not(pub.Parameters.Equals(FdhParams))) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SDHPublicKeyWrongParameter);
   end;
@@ -123,7 +123,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);
@@ -133,7 +133,7 @@ begin
   Lparameters := parameters;
   if Supports(Lparameters, IParametersWithRandom) then
   begin
-    Lparameters := (Lparameters as IParametersWithRandom).parameters;
+    Lparameters := (Lparameters as IParametersWithRandom).Parameters;
   end;
 
   if (not Supports(Lparameters, IDHPrivateKeyParameters)) then
@@ -142,7 +142,7 @@ begin
   end;
 
   Fkey := Lparameters as IDHPrivateKeyParameters;
-  FdhParams := Fkey.parameters;
+  FdhParams := Fkey.Parameters;
 end;
 
 end.

+ 4 - 4
CryptoLib/src/Crypto/Agreements/ClpECDHBasicAgreement.pas

@@ -92,8 +92,8 @@ var
   d, h: TBigInteger;
 begin
   pub := pubKey as IECPublicKeyParameters;
-  params := FprivKey.parameters;
-  if (not(params.Equals(pub.parameters))) then
+  params := FprivKey.Parameters;
+  if (not(params.Equals(pub.Parameters))) then
   begin
     raise EInvalidOperationCryptoLibException.CreateRes(@SWrongDomainParameter);
 
@@ -132,7 +132,7 @@ end;
 
 function TECDHBasicAgreement.GetFieldSize: Int32;
 begin
-  result := (FprivKey.parameters.Curve.FieldSize + 7) div 8;
+  result := (FprivKey.Parameters.Curve.FieldSize + 7) div 8;
 end;
 
 procedure TECDHBasicAgreement.Init(const parameters: ICipherParameters);
@@ -142,7 +142,7 @@ begin
   Lparameters := parameters;
   if Supports(Lparameters, IParametersWithRandom) then
   begin
-    Lparameters := (Lparameters as IParametersWithRandom).parameters;
+    Lparameters := (Lparameters as IParametersWithRandom).Parameters;
   end;
 
   FprivKey := Lparameters as IECPrivateKeyParameters;

+ 4 - 4
CryptoLib/src/Crypto/Agreements/ClpECDHCBasicAgreement.pas

@@ -97,8 +97,8 @@ var
   P, pubPoint: IECPoint;
 begin
   pub := pubKey as IECPublicKeyParameters;
-  params := FprivKey.parameters;
-  if (not(params.Equals(pub.parameters))) then
+  params := FprivKey.Parameters;
+  if (not(params.Equals(pub.Parameters))) then
   begin
     raise EInvalidOperationCryptoLibException.CreateRes(@SWrongDomainParameter);
 
@@ -128,7 +128,7 @@ end;
 
 function TECDHCBasicAgreement.GetFieldSize: Int32;
 begin
-  result := (FprivKey.parameters.Curve.FieldSize + 7) div 8;
+  result := (FprivKey.Parameters.Curve.FieldSize + 7) div 8;
 end;
 
 procedure TECDHCBasicAgreement.Init(const parameters: ICipherParameters);
@@ -138,7 +138,7 @@ begin
   Lparameters := parameters;
   if Supports(Lparameters, IParametersWithRandom) then
   begin
-    Lparameters := (Lparameters as IParametersWithRandom).parameters;
+    Lparameters := (Lparameters as IParametersWithRandom).Parameters;
   end;
 
   FprivKey := Lparameters as IECPrivateKeyParameters;

+ 0 - 1515
CryptoLib/src/Crypto/Ciphers/ClpBlockCipherModes.pas

@@ -1,1515 +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 ClpBlockCipherModes;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  Math,
-  SysUtils,
-  ClpIBlockCipher,
-  ClpBufferedBlockCipher,
-  ClpICipherParameters,
-  ClpIParametersWithIV,
-  ClpArrayUtilities,
-  ClpCryptoLibTypes,
-  ClpIBlockCipherModes;
-
-resourcestring
-  SInvalidIVLength =
-    'Initialisation Vector Must be the Same Length as Block Size';
-  SInvalidChangeState = 'Cannot Change Encrypting State Without Providing Key.';
-  SInputBufferTooShort = 'Input Buffer too Short';
-  SOutputBufferTooShort = 'Output Buffer too Short';
-{$IFNDEF _FIXINSIGHT_}
-  SInvalidParameterArgument = 'CTR/SIC Mode Requires ParametersWithIV';
-  SInvalidTooLargeIVLength =
-    'CTR/SIC mode requires IV no greater than: %u bytes';
-  SInvalidTooSmallIVLength = 'CTR/SIC mode requires IV of at least: %u bytes';
-{$ENDIF}
-  SUnsupportedCipher = 'CtsBlockCipher Can Only Accept ECB or CBC Ciphers';
-  SNegativeInputLength = 'Can''t Have a Negative Input Length!';
-  SCTSDoFinalError = 'Need at Least One Block of Input For CTS';
-
-type
-
-  /// <summary>
-  /// implements Cipher-Block-Chaining (CBC) mode on top of a simple cipher.
-  /// </summary>
-  TCbcBlockCipher = class sealed(TInterfacedObject, ICbcBlockCipher,
-    IBlockCipher)
-
-  strict private
-
-  var
-    FIV, FcbcV, FcbcNextV: TCryptoLibByteArray;
-    FblockSize: Int32;
-    Fcipher: IBlockCipher;
-    Fencrypting: Boolean;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <returns>
-    /// return the name of the underlying algorithm followed by "/CBC"
-    /// </returns>
-    function GetAlgorithmName: String; inline;
-
-    function GetIsPartialBlockOkay: Boolean; inline;
-
-    /// <summary>
-    /// Do the appropriate chaining step for CBC mode encryption.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the data to be encrypted.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the in array the data starts at.
-    /// </param>
-    /// <param name="outBytes">
-    /// the array the encrypted data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the out array the output will start at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function EncryptBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-
-    /// <summary>
-    /// Do the appropriate chaining step for CBC mode decryption.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the data to be decrypted.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the in array the data starts at.
-    /// </param>
-    /// <param name="outBytes">
-    /// the array the decrypted data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the out array the output will start at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function DecryptBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-
-  public
-
-    /// <summary>
-    /// Basic constructor.
-    /// </summary>
-    /// <param name="cipher">
-    /// the block cipher to be used as the basis of chaining.
-    /// </param>
-    constructor Create(const cipher: IBlockCipher);
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-    /// <summary>
-    /// Initialise the cipher and, possibly, the initialisation vector (IV). <br />
-    /// If an IV isn't passed as part of the parameter, the IV will be all
-    /// zeros.
-    /// </summary>
-    /// <param name="forEncryption">
-    /// forEncryption if true the cipher is initialised for encryption, if
-    /// false for decryption.
-    /// </param>
-    /// <param name="parameters">
-    /// the key and other data required by the cipher.
-    /// </param>
-    /// <exception cref="EArgumentCryptoLibException">
-    /// if the parameters argument is inappropriate
-    /// </exception>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
-
-    /// <summary>
-    /// return the block size of the underlying cipher.
-    /// </summary>
-    /// <returns>
-    /// return the block size of the underlying cipher.
-    /// </returns>
-    function GetBlockSize(): Int32; inline;
-
-    /// <summary>
-    /// Process one block of input from the input array and write it to the
-    /// output array.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the input data.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the input array the data starts at.
-    /// </param>
-    /// <param name="output">
-    /// the array the output data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the output array the data starts at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function ProcessBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const output: TCryptoLibByteArray; outOff: Int32): Int32;
-
-    /// <summary>
-    /// reset the chaining vector back to the IV and reset the underlying
-    /// cipher.
-    /// </summary>
-    procedure Reset(); inline;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <value>
-    /// return the name of the underlying algorithm followed by "/CBC"
-    /// </value>
-    property AlgorithmName: String read GetAlgorithmName;
-
-    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
-
-  end;
-
-type
-
-  /// <summary>
-  /// implements a Cipher-FeedBack (CFB) mode on top of a simple cipher.
-  /// </summary>
-  TCfbBlockCipher = class sealed(TInterfacedObject, ICfbBlockCipher,
-    IBlockCipher)
-
-  strict private
-
-  var
-    FIV, FcfbV, FcfbOutV: TCryptoLibByteArray;
-    FblockSize: Int32;
-    Fcipher: IBlockCipher;
-    Fencrypting: Boolean;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <returns>
-    /// return the name of the underlying algorithm followed by "/CFB"
-    /// </returns>
-    function GetAlgorithmName: String; inline;
-
-    function GetIsPartialBlockOkay: Boolean; inline;
-
-    /// <summary>
-    /// Do the appropriate processing for CFB mode encryption.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the data to be encrypted.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the in array the data starts at.
-    /// </param>
-    /// <param name="outBytes">
-    /// the array the encrypted data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the out array the output will start at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function EncryptBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-
-    /// <summary>
-    /// Do the appropriate chaining step for CBC mode decryption.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the data to be decrypted.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the in array the data starts at.
-    /// </param>
-    /// <param name="outBytes">
-    /// the array the decrypted data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the out array the output will start at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function DecryptBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-
-  public
-
-    /// <summary>
-    /// Basic constructor.
-    /// </summary>
-    /// <param name="cipher">
-    /// the block cipher to be used as the basis of the feedback mode.
-    /// </param>
-    /// <param name="bitBlockSize">
-    /// the block size in bits (note: a multiple of 8)
-    /// </param>
-    constructor Create(const cipher: IBlockCipher; bitBlockSize: Int32);
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-    /// <summary>
-    /// Initialise the cipher and, possibly, the initialisation vector (IV). <br />
-    /// If an IV isn't passed as part of the parameter, the IV will be all
-    /// zeros.
-    /// An IV which is too short is handled in FIPS compliant fashion.
-    /// </summary>
-    /// <param name="forEncryption">
-    /// forEncryption if true the cipher is initialised for encryption, if
-    /// false for decryption.
-    /// </param>
-    /// <param name="parameters">
-    /// the key and other data required by the cipher.
-    /// </param>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
-
-    /// <summary>
-    /// return the block size we are operating at.
-    /// </summary>
-    /// <returns>
-    /// the block size we are operating at (in bytes).
-    /// </returns>
-    function GetBlockSize(): Int32; inline;
-
-    /// <summary>
-    /// Process one block of input from the input array and write it to the
-    /// output array.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the input data.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the input array the data starts at.
-    /// </param>
-    /// <param name="output">
-    /// the array the output data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the output array the data starts at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function ProcessBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const output: TCryptoLibByteArray; outOff: Int32): Int32;
-
-    /// <summary>
-    /// reset the chaining vector back to the IV and reset the underlying
-    /// cipher.
-    /// </summary>
-    procedure Reset(); inline;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <value>
-    /// return the name of the underlying algorithm followed by "/CFB"
-    /// </value>
-    property AlgorithmName: String read GetAlgorithmName;
-
-    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
-
-  end;
-
-type
-
-  /// <summary>
-  /// implements a Output-FeedBack (OFB) mode on top of a simple cipher.
-  /// </summary>
-  TOfbBlockCipher = class sealed(TInterfacedObject, IOfbBlockCipher,
-    IBlockCipher)
-
-  strict private
-
-  var
-    FIV, FofbV, FofbOutV: TCryptoLibByteArray;
-    FblockSize: Int32;
-    Fcipher: IBlockCipher;
-    Fencrypting: Boolean;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <returns>
-    /// return the name of the underlying algorithm followed by "/OFB"
-    /// </returns>
-    function GetAlgorithmName: String; inline;
-
-    function GetIsPartialBlockOkay: Boolean; inline;
-
-  public
-
-    /// <summary>
-    /// Basic constructor.
-    /// </summary>
-    /// <param name="cipher">
-    /// the block cipher to be used as the basis of the feedback mode.
-    /// </param>
-    /// <param name="blockSize">
-    /// the block size in bits (note: a multiple of 8)
-    /// </param>
-    constructor Create(const cipher: IBlockCipher; blockSize: Int32);
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-    /// <summary>
-    /// Initialise the cipher and, possibly, the initialisation vector (IV). <br />
-    /// If an IV isn't passed as part of the parameter, the IV will be all
-    /// zeros.
-    /// An IV which is too short is handled in FIPS compliant fashion.
-    /// </summary>
-    /// <param name="forEncryption">
-    /// forEncryption if true the cipher is initialised for encryption, if
-    /// false for decryption.
-    /// ignored by this OFB mode though
-    /// </param>
-    /// <param name="parameters">
-    /// the key and other data required by the cipher.
-    /// </param>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
-
-    /// <summary>
-    /// return the block size we are operating at.
-    /// </summary>
-    /// <returns>
-    /// the block size we are operating at (in bytes).
-    /// </returns>
-    function GetBlockSize(): Int32; inline;
-
-    /// <summary>
-    /// Process one block of input from the input array and write it to the
-    /// output array.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the input data.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the input array the data starts at.
-    /// </param>
-    /// <param name="output">
-    /// the array the output data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the output array the data starts at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function ProcessBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const output: TCryptoLibByteArray; outOff: Int32): Int32;
-
-    /// <summary>
-    /// reset the chaining vector back to the IV and reset the underlying
-    /// cipher.
-    /// </summary>
-    procedure Reset(); inline;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <value>
-    /// return the name of the underlying algorithm followed by "/OFB"
-    /// </value>
-    property AlgorithmName: String read GetAlgorithmName;
-
-    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
-
-  end;
-
-type
-
-  /// <summary>
-  /// Implements the Segmented Integer Counter (SIC) mode on top of a simple block cipher.
-  /// </summary>
-  TSicBlockCipher = class sealed(TInterfacedObject, ISicBlockCipher,
-    IBlockCipher)
-
-  strict private
-
-  var
-    FIV, Fcounter, FcounterOut: TCryptoLibByteArray;
-    FblockSize: Int32;
-    Fcipher: IBlockCipher;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <returns>
-    /// return the name of the underlying algorithm followed by "/SIC"
-    /// </returns>
-    function GetAlgorithmName: String; inline;
-
-    function GetIsPartialBlockOkay: Boolean; inline;
-
-  public
-
-    /// <summary>
-    /// Basic constructor.
-    /// </summary>
-    /// <param name="cipher">
-    /// the block cipher to be used.
-    /// </param>
-    constructor Create(const cipher: IBlockCipher);
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-    /// <summary>
-    /// Initialise the cipher and, possibly, the initialisation vector (IV). <br />
-    /// If an IV isn't passed as part of the parameter, the IV will be all
-    /// zeros.
-    /// An IV which is required in this mode.
-    /// </summary>
-    /// <param name="forEncryption">
-    /// forEncryption if true the cipher is initialised for encryption, if
-    /// false for decryption.
-    /// ignored by this CTR mode though
-    /// </param>
-    /// <param name="parameters">
-    /// the key and other data required by the cipher.
-    /// </param>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
-
-    /// <summary>
-    /// return the block size we are operating at.
-    /// </summary>
-    /// <returns>
-    /// the block size we are operating at (in bytes).
-    /// </returns>
-    function GetBlockSize(): Int32; inline;
-
-    /// <summary>
-    /// Process one block of input from the input array and write it to the
-    /// output array.
-    /// </summary>
-    /// <param name="input">
-    /// the array containing the input data.
-    /// </param>
-    /// <param name="inOff">
-    /// offset into the input array the data starts at.
-    /// </param>
-    /// <param name="output">
-    /// the array the output data will be copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset into the output array the data starts at.
-    /// </param>
-    /// <returns>
-    /// the number of bytes processed and produced.
-    /// </returns>
-    /// <exception cref="EDataLengthCryptoLibException">
-    /// if there isn't enough data in input, or space in output.
-    /// </exception>
-    /// <exception cref="EInvalidOperationCryptoLibException">
-    /// if the cipher isn't initialised.
-    /// </exception>
-    function ProcessBlock(const input: TCryptoLibByteArray; inOff: Int32;
-      const output: TCryptoLibByteArray; outOff: Int32): Int32;
-
-    /// <summary>
-    /// reset the chaining vector back to the IV and reset the underlying
-    /// cipher.
-    /// </summary>
-    procedure Reset(); inline;
-
-    /// <summary>
-    /// return the algorithm name and mode.
-    /// </summary>
-    /// <value>
-    /// return the name of the underlying algorithm followed by "/SIC"
-    /// </value>
-    property AlgorithmName: String read GetAlgorithmName;
-
-    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
-
-  end;
-
-type
-
-  /// <summary>
-  /// A Cipher Text Stealing (CTS) mode cipher. CTS allows block ciphers to
-  /// be used to produce cipher text which is the same outLength as the plain
-  /// text.
-  /// </summary>
-  TCtsBlockCipher = class sealed(TBufferedBlockCipher, ICtsBlockCipher)
-
-  strict private
-  var
-    FblockSize: Int32;
-
-  public
-
-    /// <summary>
-    /// Create a buffered block cipher that uses Cipher Text Stealing
-    /// </summary>
-    /// <param name="cipher">
-    /// the underlying block cipher this buffering object wraps.
-    /// </param>
-    constructor Create(const cipher: IBlockCipher);
-
-    /// <summary>
-    /// return the size of the output buffer required for an update plus a
-    /// doFinal with an input of len bytes.
-    /// </summary>
-    /// <param name="inputLen">
-    /// the outLength of the input.
-    /// </param>
-    /// <returns>
-    /// the space required to accommodate a call to update and doFinal with
-    /// length bytes of input.
-    /// </returns>
-    function GetOutputSize(inputLen: Int32): Int32; override;
-
-    /// <summary>
-    /// return the size of the output buffer required for an update an input
-    /// of len bytes.
-    /// </summary>
-    /// <param name="inputLen">
-    /// the outLength of the input.
-    /// </param>
-    /// <returns>
-    /// the space required to accommodate a call to update with length bytes
-    /// of input.
-    /// </returns>
-    function GetUpdateOutputSize(inputLen: Int32): Int32; override;
-
-    function ProcessByte(input: Byte; const output: TCryptoLibByteArray;
-      outOff: Int32): Int32; override;
-
-    /// <summary>
-    /// process an array of bytes, producing output if necessary.
-    /// </summary>
-    /// <param name="input">
-    /// the input byte array.
-    /// </param>
-    /// <param name="inOff">
-    /// the offset at which the input data starts.
-    /// </param>
-    /// <param name="Length">
-    /// the number of bytes to be copied out of the input array.
-    /// </param>
-    /// <param name="output">
-    /// the space for any output that might be produced.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset from which the output will be copied.
-    /// </param>
-    /// <returns>
-    /// the number of output bytes copied to out.
-    /// </returns>
-    function ProcessBytes(const input: TCryptoLibByteArray; inOff, len: Int32;
-      const output: TCryptoLibByteArray; outOff: Int32): Int32; override;
-
-    /// <summary>
-    /// Process the last block in the buffer.
-    /// </summary>
-    /// <param name="output">
-    /// the array the block currently being held is copied into.
-    /// </param>
-    /// <param name="outOff">
-    /// the offset at which the copying starts.
-    /// </param>
-    /// <returns>
-    /// the number of output bytes copied to out.
-    /// </returns>
-    function DoFinal(const output: TCryptoLibByteArray; outOff: Int32)
-      : Int32; override;
-
-  end;
-
-implementation
-
-{ TCbcBlockCipher }
-
-constructor TCbcBlockCipher.Create(const cipher: IBlockCipher);
-begin
-  inherited Create();
-  Fcipher := cipher;
-  FblockSize := cipher.GetBlockSize();
-
-  System.SetLength(FIV, FblockSize);
-  System.SetLength(FcbcV, FblockSize);
-  System.SetLength(FcbcNextV, FblockSize);
-end;
-
-function TCbcBlockCipher.DecryptBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  Length, I: Int32;
-  tmp: TCryptoLibByteArray;
-begin
-  if ((inOff + FblockSize) > System.Length(input)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
-  end;
-
-  System.Move(input[inOff], FcbcNextV[0], FblockSize * System.SizeOf(Byte));
-
-  Length := Fcipher.ProcessBlock(input, inOff, outBytes, outOff);
-
-
-  // XOR the FcbcV and the output
-
-  for I := 0 to System.Pred(FblockSize) do
-  begin
-    outBytes[outOff + I] := outBytes[outOff + I] xor FcbcV[I];
-  end;
-
-
-  // swap the back up buffer into next position
-
-  tmp := FcbcV;
-  FcbcV := FcbcNextV;
-  FcbcNextV := tmp;
-
-  result := &length;
-end;
-
-function TCbcBlockCipher.EncryptBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  I, &length: Int32;
-begin
-  if ((inOff + FblockSize) > System.Length(input)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
-  end;
-
-  // XOR the FcbcV and the input, then encrypt the FcbcV
-
-  for I := 0 to System.Pred(FblockSize) do
-  begin
-    FcbcV[I] := FcbcV[I] xor input[inOff + I];
-  end;
-
-  &length := Fcipher.ProcessBlock(FcbcV, 0, outBytes, outOff);
-
-
-  // copy ciphertext to FcbcV
-
-  System.Move(outBytes[outOff], FcbcV[0], System.Length(FcbcV) *
-    System.SizeOf(Byte));
-
-  result := &length;
-end;
-
-procedure TCbcBlockCipher.Reset;
-begin
-  System.Move(FIV[0], FcbcV[0], System.Length(FIV));
-  TArrayUtilities.Fill<Byte>(FcbcNextV, 0, System.Length(FcbcNextV), Byte(0));
-
-  Fcipher.Reset();
-end;
-
-function TCbcBlockCipher.GetAlgorithmName: String;
-begin
-  result := Fcipher.AlgorithmName + '/CBC';
-end;
-
-function TCbcBlockCipher.GetBlockSize: Int32;
-begin
-  result := Fcipher.GetBlockSize();
-end;
-
-function TCbcBlockCipher.GetIsPartialBlockOkay: Boolean;
-begin
-  result := false;
-end;
-
-function TCbcBlockCipher.GetUnderlyingCipher: IBlockCipher;
-begin
-  result := Fcipher;
-end;
-
-procedure TCbcBlockCipher.Init(forEncryption: Boolean;
-  const parameters: ICipherParameters);
-var
-  oldEncrypting: Boolean;
-  ivParam: IParametersWithIV;
-  iv: TCryptoLibByteArray;
-  Lparameters: ICipherParameters;
-begin
-  oldEncrypting := Fencrypting;
-  Fencrypting := forEncryption;
-  Lparameters := parameters;
-
-  if Supports(Lparameters, IParametersWithIV, ivParam) then
-  begin
-    iv := ivParam.GetIV();
-
-    if (System.Length(iv) <> FblockSize) then
-    begin
-      raise EArgumentCryptoLibException.CreateRes(@SInvalidIVLength);
-    end;
-
-    System.Move(iv[0], FIV[0], System.Length(iv) * System.SizeOf(Byte));
-
-    Lparameters := ivParam.parameters;
-  end;
-
-  Reset();
-
-  // if Nil it's an IV changed only.
-  if (Lparameters <> Nil) then
-  begin
-    Fcipher.Init(Fencrypting, Lparameters);
-  end
-  else if (oldEncrypting <> Fencrypting) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidChangeState);
-  end;
-
-end;
-
-function TCbcBlockCipher.ProcessBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const output: TCryptoLibByteArray; outOff: Int32): Int32;
-begin
-  if Fencrypting then
-  begin
-    result := EncryptBlock(input, inOff, output, outOff);
-  end
-  else
-  begin
-    result := DecryptBlock(input, inOff, output, outOff);
-  end;
-end;
-
-{ TCfbBlockCipher }
-
-constructor TCfbBlockCipher.Create(const cipher: IBlockCipher;
-  bitBlockSize: Int32);
-begin
-  inherited Create();
-  Fcipher := cipher;
-  FblockSize := bitBlockSize div 8;
-
-  System.SetLength(FIV, Fcipher.GetBlockSize);
-  System.SetLength(FcfbV, Fcipher.GetBlockSize);
-  System.SetLength(FcfbOutV, Fcipher.GetBlockSize);
-end;
-
-function TCfbBlockCipher.DecryptBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  I, count: Int32;
-begin
-  if ((inOff + FblockSize) > System.Length(input)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
-  end;
-
-  if ((outOff + FblockSize) > System.Length(outBytes)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
-  end;
-
-  Fcipher.ProcessBlock(FcfbV, 0, FcfbOutV, 0);
-
-  //
-  // change over the input block.
-  //
-  count := (System.Length(FcfbV) - FblockSize) * System.SizeOf(Byte);
-  if count > 0 then
-  begin
-    System.Move(FcfbV[FblockSize], FcfbV[0], count);
-  end;
-
-  System.Move(input[inOff], FcfbV[(System.Length(FcfbV) - FblockSize)],
-    FblockSize * System.SizeOf(Byte));
-
-  // XOR the FcfbV with the ciphertext producing the plaintext
-
-  for I := 0 to System.Pred(FblockSize) do
-  begin
-    outBytes[outOff + I] := Byte(FcfbOutV[I] xor input[inOff + I]);
-  end;
-
-  result := FblockSize;
-end;
-
-function TCfbBlockCipher.EncryptBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const outBytes: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  I, count: Int32;
-begin
-  if ((inOff + FblockSize) > System.Length(input)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
-  end;
-
-  if ((outOff + FblockSize) > System.Length(outBytes)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
-  end;
-
-  Fcipher.ProcessBlock(FcfbV, 0, FcfbOutV, 0);
-
-  // XOR the FcfbV with the plaintext producing the ciphertext
-
-  for I := 0 to System.Pred(FblockSize) do
-  begin
-    outBytes[outOff + I] := Byte(FcfbOutV[I] xor input[inOff + I]);
-  end;
-
-  //
-  // change over the input block.
-  //
-  count := (System.Length(FcfbV) - FblockSize) * System.SizeOf(Byte);
-
-  if count > 0 then
-  begin
-    System.Move(FcfbV[FblockSize], FcfbV[0], count);
-  end;
-
-  System.Move(outBytes[outOff], FcfbV[(System.Length(FcfbV) - FblockSize)],
-    FblockSize * System.SizeOf(Byte));
-
-  result := FblockSize;
-end;
-
-procedure TCfbBlockCipher.Reset;
-begin
-  System.Move(FIV[0], FcfbV[0], System.Length(FIV));
-
-  Fcipher.Reset();
-end;
-
-function TCfbBlockCipher.GetAlgorithmName: String;
-begin
-  result := Fcipher.AlgorithmName + '/CFB' + IntToStr(FblockSize * 8);
-end;
-
-function TCfbBlockCipher.GetBlockSize: Int32;
-begin
-  result := FblockSize;
-end;
-
-function TCfbBlockCipher.GetIsPartialBlockOkay: Boolean;
-begin
-  result := true;
-end;
-
-function TCfbBlockCipher.GetUnderlyingCipher: IBlockCipher;
-begin
-  result := Fcipher;
-end;
-
-procedure TCfbBlockCipher.Init(forEncryption: Boolean;
-  const parameters: ICipherParameters);
-var
-  ivParam: IParametersWithIV;
-  iv: TCryptoLibByteArray;
-  Lparameters: ICipherParameters;
-  diff: Int32;
-begin
-  Fencrypting := forEncryption;
-  Lparameters := parameters;
-
-  if Supports(Lparameters, IParametersWithIV, ivParam) then
-  begin
-    iv := ivParam.GetIV();
-
-    diff := System.Length(FIV) - System.Length(iv);
-
-    System.Move(iv[0], FIV[diff], System.Length(iv) * System.SizeOf(Byte));
-    TArrayUtilities.Fill<Byte>(FIV, 0, diff, Byte(0));
-
-    Lparameters := ivParam.parameters;
-  end;
-
-  Reset();
-
-  // if it's Nil, key is to be reused.
-  if (Lparameters <> Nil) then
-  begin
-    Fcipher.Init(true, Lparameters);
-  end;
-
-end;
-
-function TCfbBlockCipher.ProcessBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const output: TCryptoLibByteArray; outOff: Int32): Int32;
-begin
-  if Fencrypting then
-  begin
-    result := EncryptBlock(input, inOff, output, outOff);
-  end
-  else
-  begin
-    result := DecryptBlock(input, inOff, output, outOff);
-  end;
-end;
-
-{ TOfbBlockCipher }
-
-constructor TOfbBlockCipher.Create(const cipher: IBlockCipher;
-  blockSize: Int32);
-begin
-  inherited Create();
-  Fcipher := cipher;
-  FblockSize := blockSize div 8;
-
-  System.SetLength(FIV, Fcipher.GetBlockSize);
-  System.SetLength(FofbV, Fcipher.GetBlockSize);
-  System.SetLength(FofbOutV, Fcipher.GetBlockSize);
-end;
-
-procedure TOfbBlockCipher.Reset;
-begin
-  System.Move(FIV[0], FofbV[0], System.Length(FIV));
-
-  Fcipher.Reset();
-
-end;
-
-function TOfbBlockCipher.GetAlgorithmName: String;
-begin
-  result := Fcipher.AlgorithmName + '/OFB' + IntToStr(FblockSize * 8);
-end;
-
-function TOfbBlockCipher.GetBlockSize: Int32;
-begin
-  result := FblockSize;
-end;
-
-function TOfbBlockCipher.GetIsPartialBlockOkay: Boolean;
-begin
-  result := true;
-end;
-
-function TOfbBlockCipher.GetUnderlyingCipher: IBlockCipher;
-begin
-  result := Fcipher;
-end;
-
-procedure TOfbBlockCipher.Init(forEncryption: Boolean;
-  // forEncryption ignored by this OFB mode
-  const parameters: ICipherParameters);
-var
-  ivParam: IParametersWithIV;
-  iv: TCryptoLibByteArray;
-  Lparameters: ICipherParameters;
-  I: Int32;
-begin
-  Fencrypting := forEncryption;
-  Lparameters := parameters;
-
-  if Supports(Lparameters, IParametersWithIV, ivParam) then
-  begin
-    iv := ivParam.GetIV();
-
-    if (System.Length(iv) < System.Length(FIV)) then
-    begin
-      // prepend the supplied IV with zeros (per FIPS PUB 81)
-      System.Move(iv[0], FIV[System.Length(FIV) - System.Length(iv)],
-        System.Length(iv) * System.SizeOf(Byte));
-
-      for I := 0 to System.Pred(System.Length(FIV) - System.Length(iv)) do
-      begin
-        FIV[I] := 0;
-      end;
-
-    end
-    else
-    begin
-      System.Move(iv[0], FIV[0], System.Length(FIV) * System.SizeOf(Byte));
-    end;
-
-    Lparameters := ivParam.parameters;
-  end;
-
-  Reset();
-
-  // if it's Nil, key is to be reused.
-  if (Lparameters <> Nil) then
-  begin
-    Fcipher.Init(true, Lparameters);
-  end;
-
-end;
-
-function TOfbBlockCipher.ProcessBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const output: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  I, count: Int32;
-begin
-  if ((inOff + FblockSize) > System.Length(input)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
-  end;
-
-  if ((outOff + FblockSize) > System.Length(output)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
-  end;
-
-  Fcipher.ProcessBlock(FofbV, 0, FofbOutV, 0);
-
-  //
-  // XOR the ofbV with the plaintext producing the cipher text (and
-  // the next input block).
-  //
-
-  for I := 0 to System.Pred(FblockSize) do
-  begin
-    output[outOff + I] := Byte(FofbOutV[I] xor input[inOff + I]);
-  end;
-
-  //
-  // change over the input block.
-  //
-  count := (System.Length(FofbV) - FblockSize) * System.SizeOf(Byte);
-
-  if count > 0 then
-  begin
-    System.Move(FofbV[FblockSize], FofbV[0], count);
-  end;
-
-  System.Move(FofbOutV[0], FofbV[(System.Length(FofbV) - FblockSize)],
-    FblockSize * System.SizeOf(Byte));
-
-  result := FblockSize;
-end;
-
-{ TSicBlockCipher }
-
-constructor TSicBlockCipher.Create(const cipher: IBlockCipher);
-begin
-  inherited Create();
-  Fcipher := cipher;
-  FblockSize := Fcipher.GetBlockSize;
-
-  System.SetLength(Fcounter, FblockSize);
-  System.SetLength(FcounterOut, FblockSize);
-  System.SetLength(FIV, FblockSize);
-end;
-
-procedure TSicBlockCipher.Reset;
-begin
-  TArrayUtilities.Fill<Byte>(Fcounter, 0, System.Length(Fcounter), Byte(0));
-  System.Move(FIV[0], Fcounter[0], System.Length(FIV) * System.SizeOf(Byte));
-
-  Fcipher.Reset();
-
-end;
-
-function TSicBlockCipher.GetAlgorithmName: String;
-begin
-  result := Fcipher.AlgorithmName + '/SIC';
-end;
-
-function TSicBlockCipher.GetBlockSize: Int32;
-begin
-  result := Fcipher.GetBlockSize();
-end;
-
-function TSicBlockCipher.GetIsPartialBlockOkay: Boolean;
-begin
-  result := true;
-end;
-
-function TSicBlockCipher.GetUnderlyingCipher: IBlockCipher;
-begin
-  result := Fcipher;
-end;
-
-{$IFNDEF _FIXINSIGHT_}
-
-procedure TSicBlockCipher.Init(forEncryption: Boolean;
-  // forEncryption ignored by this CTR mode
-  const parameters: ICipherParameters);
-var
-  ivParam: IParametersWithIV;
-  Lparameters: ICipherParameters;
-  maxCounterSize: Int32;
-begin
-  Lparameters := parameters;
-
-  if Supports(Lparameters, IParametersWithIV, ivParam) then
-  begin
-    FIV := ivParam.GetIV();
-
-    if (FblockSize < System.Length(FIV)) then
-    begin
-      raise EArgumentCryptoLibException.CreateResFmt(@SInvalidTooLargeIVLength,
-        [FblockSize]);
-    end;
-
-    maxCounterSize := Min(8, FblockSize div 2);
-
-    if ((FblockSize - System.Length(FIV)) > maxCounterSize) then
-    begin
-      raise EArgumentCryptoLibException.CreateResFmt(@SInvalidTooSmallIVLength,
-        [FblockSize - maxCounterSize]);
-    end;
-
-    Lparameters := ivParam.parameters;
-  end
-  else
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidParameterArgument);
-  end;
-
-  // if it's Nil, key is to be reused.
-  if (Lparameters <> Nil) then
-  begin
-    Fcipher.Init(true, Lparameters);
-  end;
-
-  Reset();
-
-end;
-{$ENDIF}
-
-function TSicBlockCipher.ProcessBlock(const input: TCryptoLibByteArray;
-  inOff: Int32; const output: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  I, J: Int32;
-begin
-
-  if ((inOff + FblockSize) > System.Length(input)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
-  end;
-
-  if ((outOff + FblockSize) > System.Length(output)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
-  end;
-
-  Fcipher.ProcessBlock(Fcounter, 0, FcounterOut, 0);
-
-  //
-  // XOR the counterOut with the plaintext producing the cipher text
-  //
-  for I := 0 to System.Pred(System.Length(FcounterOut)) do
-  begin
-
-    output[outOff + I] := Byte(FcounterOut[I] xor input[inOff + I]);
-  end;
-
-  // Increment the counter
-  J := System.Length(Fcounter);
-  System.Dec(J);
-  System.Inc(Fcounter[J]);
-  while ((J >= 0) and (Fcounter[J] = 0)) do
-  begin
-    System.Dec(J);
-    System.Inc(Fcounter[J]);
-  end;
-
-  result := System.Length(Fcounter);
-end;
-
-{ TCtsBlockCipher }
-
-constructor TCtsBlockCipher.Create(const cipher: IBlockCipher);
-begin
-  Inherited Create();
-  if Supports(cipher, ICfbBlockCipher) or Supports(cipher, IOfbBlockCipher) or
-    Supports(cipher, ISicBlockCipher) or Supports(cipher, ICtsBlockCipher) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SUnsupportedCipher);
-  end;
-
-  Fcipher := cipher;
-
-  FblockSize := Fcipher.GetBlockSize();
-  System.SetLength(Fbuf, FblockSize * 2);
-  FbufOff := 0;
-end;
-
-function TCtsBlockCipher.DoFinal(const output: TCryptoLibByteArray;
-  outOff: Int32): Int32;
-var
-  blockSize, len, I: Int32;
-  block, lastBlock: TCryptoLibByteArray;
-  c: IBlockCipher;
-begin
-  if ((FbufOff + outOff) > System.Length(output)) then
-  begin
-    raise EDataLengthCryptoLibException.CreateRes
-      (@SOutputBufferTooSmallForDoFinal);
-  end;
-
-  blockSize := Fcipher.GetBlockSize();
-  len := FbufOff - blockSize;
-  System.SetLength(block, blockSize);
-
-  if (FforEncryption) then
-  begin
-    if (FbufOff < blockSize) then
-    begin
-      raise EDataLengthCryptoLibException.CreateRes(@SCTSDoFinalError);
-    end;
-
-    Fcipher.ProcessBlock(Fbuf, 0, block, 0);
-
-    if (FbufOff > blockSize) then
-    begin
-
-      I := FbufOff;
-      while I <> System.Length(Fbuf) do
-      begin
-        Fbuf[I] := block[I - blockSize];
-        System.Inc(I);
-      end;
-
-      I := blockSize;
-      while I <> FbufOff do
-      begin
-        Fbuf[I] := Fbuf[I] xor (block[I - blockSize]);
-        System.Inc(I);
-      end;
-
-      if Supports(Fcipher, ICbcBlockCipher) then
-      begin
-        c := (Fcipher as ICbcBlockCipher).GetUnderlyingCipher();
-
-        c.ProcessBlock(Fbuf, blockSize, output, outOff);
-      end
-      else
-      begin
-        Fcipher.ProcessBlock(Fbuf, blockSize, output, outOff);
-      end;
-
-      System.Move(block[0], output[outOff + blockSize],
-        len * System.SizeOf(Byte));
-    end
-    else
-    begin
-      System.Move(block[0], output[outOff], blockSize * System.SizeOf(Byte));
-    end;
-  end
-  else
-  begin
-
-    if (FbufOff < blockSize) then
-    begin
-      raise EDataLengthCryptoLibException.CreateRes(@SCTSDoFinalError);
-    end;
-
-    System.SetLength(lastBlock, blockSize);
-
-    if (FbufOff > blockSize) then
-    begin
-
-      if Supports(Fcipher, ICbcBlockCipher) then
-      begin
-        c := (Fcipher as ICbcBlockCipher).GetUnderlyingCipher();
-
-        c.ProcessBlock(Fbuf, 0, block, 0);
-      end
-      else
-      begin
-        Fcipher.ProcessBlock(Fbuf, 0, block, 0);
-      end;
-
-      I := blockSize;
-      while I <> FbufOff do
-      begin
-        lastBlock[I - blockSize] := Byte(block[I - blockSize] xor Fbuf[I]);
-        System.Inc(I);
-      end;
-
-      System.Move(Fbuf[blockSize], block[0], len * System.SizeOf(Byte));
-      Fcipher.ProcessBlock(block, 0, output, outOff);
-      System.Move(lastBlock[0], output[outOff + blockSize],
-        len * System.SizeOf(Byte));
-    end
-    else
-    begin
-      Fcipher.ProcessBlock(Fbuf, 0, block, 0);
-      System.Move(block[0], output[outOff], blockSize * System.SizeOf(Byte));
-    end;
-
-  end;
-
-  result := FbufOff;
-
-  Reset();
-end;
-
-function TCtsBlockCipher.GetOutputSize(inputLen: Int32): Int32;
-begin
-  result := inputLen + FbufOff;
-end;
-
-function TCtsBlockCipher.GetUpdateOutputSize(inputLen: Int32): Int32;
-var
-  total, leftOver: Int32;
-begin
-  total := inputLen + FbufOff;
-  leftOver := total mod System.Length(Fbuf);
-
-  if (leftOver = 0) then
-  begin
-    result := total - System.Length(Fbuf);
-    Exit;
-  end;
-  result := total - leftOver;
-end;
-
-function TCtsBlockCipher.ProcessByte(input: Byte;
-  const output: TCryptoLibByteArray; outOff: Int32): Int32;
-begin
-  result := 0;
-
-  if (FbufOff = System.Length(Fbuf)) then
-  begin
-    result := Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
-    System.Move(Fbuf[FblockSize], Fbuf[0], FblockSize * System.SizeOf(Byte));
-    FbufOff := FblockSize;
-  end;
-
-  Fbuf[FbufOff] := input;
-  System.Inc(FbufOff);
-end;
-
-function TCtsBlockCipher.ProcessBytes(const input: TCryptoLibByteArray;
-  inOff, len: Int32; const output: TCryptoLibByteArray; outOff: Int32): Int32;
-var
-  blockSize, Length, gapLen: Int32;
-begin
-  if (len < 0) then
-  begin
-    raise EInvalidArgument.CreateRes(@SNegativeInputLength);
-  end;
-
-  blockSize := GetBlockSize();
-  Length := GetUpdateOutputSize(len);
-
-  if (Length > 0) then
-  begin
-    if ((outOff + Length) > System.Length(output)) then
-    begin
-      raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
-    end;
-  end;
-
-  result := 0;
-  gapLen := System.Length(Fbuf) - FbufOff;
-
-  if (len > gapLen) then
-  begin
-    System.Move(input[inOff], Fbuf[FbufOff], gapLen * System.SizeOf(Byte));
-
-    result := result + Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
-    System.Move(Fbuf[blockSize], Fbuf[0], blockSize * System.SizeOf(Byte));
-
-    FbufOff := blockSize;
-
-    len := len - gapLen;
-    inOff := inOff + gapLen;
-
-    while (len > blockSize) do
-    begin
-      System.Move(input[inOff], Fbuf[FbufOff], blockSize * System.SizeOf(Byte));
-      result := result + Fcipher.ProcessBlock(Fbuf, 0, output, outOff + result);
-      System.Move(Fbuf[blockSize], Fbuf[0], blockSize * System.SizeOf(Byte));
-
-      len := len - blockSize;
-      inOff := inOff + blockSize;
-    end;
-  end;
-
-  System.Move(input[inOff], Fbuf[FbufOff], len * System.SizeOf(Byte));
-
-  FbufOff := FbufOff + len;
-
-end;
-
-end.

+ 156 - 156
CryptoLib/src/Crypto/Ciphers/ClpBufferedBlockCipher.pas

@@ -59,10 +59,10 @@ type
 
   strict protected
   var
-    Fbuf: TCryptoLibByteArray;
-    FbufOff: Int32;
-    FforEncryption: Boolean;
-    Fcipher: IBlockCipher;
+    FBuf: TCryptoLibByteArray;
+    FBufOff: Int32;
+    FForEncryption: Boolean;
+    FCipher: IBlockCipher;
 
     /// <summary>
     /// constructor for subclasses
@@ -73,27 +73,27 @@ type
     /// <summary>
     /// Create a buffered block cipher without padding.
     /// </summary>
-    /// <param name="cipher">
+    /// <param name="ACipher">
     /// the underlying block cipher this buffering object wraps.
     /// </param>
-    constructor Create(const cipher: IBlockCipher); overload;
+    constructor Create(const ACipher: IBlockCipher); overload;
 
     /// <summary>
     /// initialise the cipher.
     /// </summary>
-    /// <param name="forEncryption">
+    /// <param name="AForEncryption">
     /// forEncryption if true the cipher is initialised for encryption, if
     /// false for decryption.
     /// </param>
-    /// <param name="parameters">
+    /// <param name="AParameters">
     /// the key and other data required by the cipher.
     /// </param>
     /// <exception cref="EArgumentCryptoLibException">
     /// if the parameters argument is inappropriate.
     /// </exception>
     // Note: This doubles as the Init in the event that this cipher is being used as an IWrapper
-    procedure Init(forEncryption: Boolean;
-      const parameters: ICipherParameters); override;
+    procedure Init(AForEncryption: Boolean;
+      const AParameters: ICipherParameters); override;
 
     /// <summary>
     /// return the blocksize for the underlying cipher.
@@ -114,7 +114,7 @@ type
     /// return the space required to accommodate a call to update with length
     /// bytes of input.
     /// </returns>
-    function GetUpdateOutputSize(length: Int32): Int32; override;
+    function GetUpdateOutputSize(ALength: Int32): Int32; override;
 
     /// <summary>
     /// return the size of the output buffer required for an update plus a
@@ -127,7 +127,7 @@ type
     /// the space required to accommodate a call to update and doFinal with
     /// length bytes of input.
     /// </returns>
-    function GetOutputSize(length: Int32): Int32; override;
+    function GetOutputSize(ALength: Int32): Int32; override;
 
     /// <summary>
     /// process a single byte, producing an output block if necessary.
@@ -150,13 +150,13 @@ type
     /// <exception cref="EInvalidOperationCryptoLibException">
     /// if the cipher isn't initialised.
     /// </exception>
-    function ProcessByte(input: Byte; const output: TCryptoLibByteArray;
-      outOff: Int32): Int32; overload; override;
+    function ProcessByte(AInput: Byte; const AOutput: TCryptoLibByteArray;
+      AOutOff: Int32): Int32; overload; override;
 
-    function ProcessByte(input: Byte): TCryptoLibByteArray; overload; override;
+    function ProcessByte(AInput: Byte): TCryptoLibByteArray; overload; override;
 
-    function ProcessBytes(const input: TCryptoLibByteArray;
-      inOff, length: Int32): TCryptoLibByteArray; overload; override;
+    function ProcessBytes(const AInput: TCryptoLibByteArray;
+      AInOff, ALength: Int32): TCryptoLibByteArray; overload; override;
 
     /// <summary>
     /// process an array of bytes, producing output if necessary.
@@ -184,12 +184,12 @@ type
     /// <exception cref="EInvalidOperationCryptoLibException">
     /// if the cipher isn't initialised.
     /// </exception>
-    function ProcessBytes(const input: TCryptoLibByteArray;
-      inOff, length: Int32; const output: TCryptoLibByteArray; outOff: Int32)
+    function ProcessBytes(const AInput: TCryptoLibByteArray;
+      AInOff, ALength: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32)
       : Int32; overload; override;
 
     function DoFinal(): TCryptoLibByteArray; overload; override;
-    function DoFinal(const input: TCryptoLibByteArray; inOff, inLen: Int32)
+    function DoFinal(const AInput: TCryptoLibByteArray; AInOff, AInLen: Int32)
       : TCryptoLibByteArray; overload; override;
 
     /// <summary>
@@ -217,7 +217,7 @@ type
     /// <exception cref="EDataLengthCryptoLibException">
     /// if the input is not block size aligned.
     /// </exception>
-    function DoFinal(const output: TCryptoLibByteArray; outOff: Int32): Int32;
+    function DoFinal(const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
       overload; override;
 
     /// <summary>
@@ -235,17 +235,17 @@ implementation
 
 { TBufferedBlockCipher }
 
-constructor TBufferedBlockCipher.Create(const cipher: IBlockCipher);
+constructor TBufferedBlockCipher.Create(const ACipher: IBlockCipher);
 begin
   Inherited Create();
-  if (cipher = Nil) then
+  if (ACipher = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SCipherNil);
   end;
 
-  Fcipher := cipher;
-  System.SetLength(Fbuf, cipher.GetBlockSize());
-  FbufOff := 0;
+  FCipher := ACipher;
+  System.SetLength(FBuf, ACipher.GetBlockSize());
+  FBufOff := 0;
 end;
 
 constructor TBufferedBlockCipher.Create;
@@ -253,64 +253,64 @@ begin
   Inherited Create();
 end;
 
-function TBufferedBlockCipher.DoFinal(const output: TCryptoLibByteArray;
-  outOff: Int32): Int32;
+function TBufferedBlockCipher.DoFinal(const AOutput: TCryptoLibByteArray;
+  AOutOff: Int32): Int32;
 begin
   try
-    if (FbufOff <> 0) then
+    if (FBufOff <> 0) then
     begin
-      TCheck.DataLength(not Fcipher.IsPartialBlockOkay,
+      TCheck.DataLength(not FCipher.IsPartialBlockOkay,
         SDataNotBlockSizeAligned);
-      TCheck.OutputLength(output, outOff, FbufOff,
+      TCheck.OutputLength(AOutput, AOutOff, FBufOff,
         SOutputBufferTooSmallForDoFinal);
 
       // NB: Can't copy directly, or we may write too much output
-      Fcipher.ProcessBlock(Fbuf, 0, Fbuf, 0);
-      System.Move(Fbuf[0], output[outOff], FbufOff * System.SizeOf(Byte));
+      FCipher.ProcessBlock(FBuf, 0, FBuf, 0);
+      System.Move(FBuf[0], AOutput[AOutOff], FBufOff * System.SizeOf(Byte));
     end;
 
-    result := FbufOff;
+    Result := FBufOff;
     Exit;
   finally
     Reset();
   end;
 end;
 
-function TBufferedBlockCipher.DoFinal(const input: TCryptoLibByteArray;
-  inOff, inLen: Int32): TCryptoLibByteArray;
+function TBufferedBlockCipher.DoFinal(const AInput: TCryptoLibByteArray;
+  AInOff, AInLen: Int32): TCryptoLibByteArray;
 var
-  &length, &pos: Int32;
-  outBytes, tmp: TCryptoLibByteArray;
+  LLength, LPos: Int32;
+  LOutBytes, LTmp: TCryptoLibByteArray;
 begin
-  if (input = Nil) then
+  if (AInput = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SInputNil);
   end;
 
-  &length := GetOutputSize(inLen);
+  LLength := GetOutputSize(AInLen);
 
-  outBytes := EmptyBuffer;
+  LOutBytes := EmptyBuffer;
 
-  if (&length > 0) then
+  if (LLength > 0) then
   begin
-    System.SetLength(outBytes, length);
+    System.SetLength(LOutBytes, LLength);
 
-    if (inLen > 0) then
+    if (AInLen > 0) then
     begin
-      &pos := ProcessBytes(input, inOff, inLen, outBytes, 0);
+      LPos := ProcessBytes(AInput, AInOff, AInLen, LOutBytes, 0);
     end
     else
     begin
-      &pos := 0;
+      LPos := 0;
     end;
 
-    &pos := &pos + DoFinal(outBytes, &pos);
+    LPos := LPos + DoFinal(LOutBytes, LPos);
 
-    if (&pos < System.length(outBytes)) then
+    if (LPos < System.Length(LOutBytes)) then
     begin
-      System.SetLength(tmp, &pos);
-      System.Move(outBytes[0], tmp[0], &pos * System.SizeOf(Byte));
-      outBytes := tmp;
+      System.SetLength(LTmp, LPos);
+      System.Move(LOutBytes[0], LTmp[0], LPos * System.SizeOf(Byte));
+      LOutBytes := LTmp;
     end
   end
   else
@@ -318,27 +318,27 @@ begin
     Reset();
   end;
 
-  result := outBytes;
+  Result := LOutBytes;
 end;
 
 function TBufferedBlockCipher.DoFinal: TCryptoLibByteArray;
 var
-  outBytes, tmp: TCryptoLibByteArray;
-  &length, &pos: Int32;
+  LOutBytes, LTmp: TCryptoLibByteArray;
+  LLength, LPos: Int32;
 begin
-  outBytes := EmptyBuffer;
+  LOutBytes := EmptyBuffer;
 
-  &length := GetOutputSize(0);
-  if (&length > 0) then
+  LLength := GetOutputSize(0);
+  if (LLength > 0) then
   begin
-    System.SetLength(outBytes, &length);
+    System.SetLength(LOutBytes, LLength);
 
-    &pos := DoFinal(outBytes, 0);
-    if (&pos < System.length(outBytes)) then
+    LPos := DoFinal(LOutBytes, 0);
+    if (LPos < System.Length(LOutBytes)) then
     begin
-      System.SetLength(tmp, &pos);
-      System.Move(outBytes[0], tmp[0], &pos * System.SizeOf(Byte));
-      outBytes := tmp;
+      System.SetLength(LTmp, LPos);
+      System.Move(LOutBytes[0], LTmp[0], LPos * System.SizeOf(Byte));
+      LOutBytes := LTmp;
     end
   end
   else
@@ -346,204 +346,204 @@ begin
     Reset();
   end;
 
-  result := outBytes;
+  Result := LOutBytes;
 end;
 
 function TBufferedBlockCipher.GetAlgorithmName: String;
 begin
-  result := Fcipher.AlgorithmName;
+  Result := FCipher.AlgorithmName;
 end;
 
 function TBufferedBlockCipher.GetBlockSize: Int32;
 begin
-  result := Fcipher.GetBlockSize();
+  Result := FCipher.GetBlockSize();
 end;
 
-function TBufferedBlockCipher.GetOutputSize(length: Int32): Int32;
+function TBufferedBlockCipher.GetOutputSize(ALength: Int32): Int32;
 begin
   // Note: Can assume IsPartialBlockOkay is true for purposes of this calculation
-  result := length + FbufOff;
+  Result := ALength + FBufOff;
 end;
 
-function TBufferedBlockCipher.GetUpdateOutputSize(length: Int32): Int32;
+function TBufferedBlockCipher.GetUpdateOutputSize(ALength: Int32): Int32;
 var
-  total, leftOver: Int32;
+  LTotal, LLeftOver: Int32;
 begin
-  total := length + FbufOff;
-  leftOver := total mod System.length(Fbuf);
-  result := total - leftOver;
+  LTotal := ALength + FBufOff;
+  LLeftOver := LTotal mod System.Length(FBuf);
+  Result := LTotal - LLeftOver;
 end;
 
-procedure TBufferedBlockCipher.Init(forEncryption: Boolean;
-  const parameters: ICipherParameters);
+procedure TBufferedBlockCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
 var
-  pwr: IParametersWithRandom;
-  Lparameters: ICipherParameters;
+  LPwr: IParametersWithRandom;
+  LParameters: ICipherParameters;
 begin
-  FforEncryption := forEncryption;
-  Lparameters := parameters;
+  FForEncryption := AForEncryption;
+  LParameters := AParameters;
 
-  if Supports(Lparameters, IParametersWithRandom, pwr) then
+  if Supports(LParameters, IParametersWithRandom, LPwr) then
   begin
-    Lparameters := pwr.parameters;
-  end;;
+    LParameters := LPwr.Parameters;
+  end;
 
   Reset();
 
-  Fcipher.Init(forEncryption, Lparameters);
+  FCipher.Init(AForEncryption, LParameters);
 
 end;
 
-function TBufferedBlockCipher.ProcessByte(input: Byte;
-  const output: TCryptoLibByteArray; outOff: Int32): Int32;
+function TBufferedBlockCipher.ProcessByte(AInput: Byte;
+  const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
 begin
 
-  Fbuf[FbufOff] := input;
-  System.Inc(FbufOff);
+  FBuf[FBufOff] := AInput;
+  System.Inc(FBufOff);
 
-  if (FbufOff = System.length(Fbuf)) then
+  if (FBufOff = System.Length(FBuf)) then
   begin
-    if ((outOff + System.length(Fbuf)) > System.length(output)) then
+    if ((AOutOff + System.Length(FBuf)) > System.Length(AOutput)) then
     begin
       raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooSmall);
     end;
 
-    FbufOff := 0;
-    result := Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
+    FBufOff := 0;
+    Result := FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
     Exit;
   end;
 
-  result := 0;
+  Result := 0;
 end;
 
-function TBufferedBlockCipher.ProcessByte(input: Byte): TCryptoLibByteArray;
+function TBufferedBlockCipher.ProcessByte(AInput: Byte): TCryptoLibByteArray;
 var
-  outLength, &pos: Int32;
-  outBytes, tmp: TCryptoLibByteArray;
+  LOutLength, LPos: Int32;
+  LOutBytes, LTmp: TCryptoLibByteArray;
 begin
-  outLength := GetUpdateOutputSize(1);
+  LOutLength := GetUpdateOutputSize(1);
 
-  if outLength > 0 then
+  if LOutLength > 0 then
   begin
-    System.SetLength(outBytes, outLength);
+    System.SetLength(LOutBytes, LOutLength);
   end
   else
   begin
-    outBytes := Nil;
+    LOutBytes := nil;
   end;
 
-  &pos := ProcessByte(input, outBytes, 0);
+  LPos := ProcessByte(AInput, LOutBytes, 0);
 
-  if ((outLength > 0) and (pos < outLength)) then
+  if ((LOutLength > 0) and (LPos < LOutLength)) then
   begin
-    System.SetLength(tmp, &pos);
-    System.Move(outBytes[0], tmp[0], &pos * System.SizeOf(Byte));
+    System.SetLength(LTmp, LPos);
+    System.Move(LOutBytes[0], LTmp[0], LPos * System.SizeOf(Byte));
 
-    outBytes := tmp;
+    LOutBytes := LTmp;
   end;
 
-  result := outBytes;
+  Result := LOutBytes;
 end;
 
-function TBufferedBlockCipher.ProcessBytes(const input: TCryptoLibByteArray;
-  inOff, length: Int32; const output: TCryptoLibByteArray;
-  outOff: Int32): Int32;
+function TBufferedBlockCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
+  AInOff, ALength: Int32; const AOutput: TCryptoLibByteArray;
+  AOutOff: Int32): Int32;
 var
-  blockSize, outLength, resultLen, gapLen: Int32;
+  LBlockSize, LOutLength, LResultLen, LGapLen: Int32;
 begin
-  if (length < 1) then
+  if (ALength < 1) then
   begin
-    if (length < 0) then
+    if (ALength < 0) then
     begin
       raise EArgumentCryptoLibException.CreateRes(@SInvalidLength);
     end;
-    result := 0;
+    Result := 0;
     Exit;
   end;
 
-  blockSize := GetBlockSize();
-  outLength := GetUpdateOutputSize(length);
+  LBlockSize := GetBlockSize();
+  LOutLength := GetUpdateOutputSize(ALength);
 
-  if (outLength > 0) then
+  if (LOutLength > 0) then
   begin
-    TCheck.OutputLength(output, outOff, outLength, SOutputBufferTooSmall);
+    TCheck.OutputLength(AOutput, AOutOff, LOutLength, SOutputBufferTooSmall);
   end;
 
-  resultLen := 0;
-  gapLen := System.length(Fbuf) - FbufOff;
-  if (length > gapLen) then
+  LResultLen := 0;
+  LGapLen := System.Length(FBuf) - FBufOff;
+  if (ALength > LGapLen) then
   begin
-    System.Move(input[inOff], Fbuf[FbufOff], gapLen * System.SizeOf(Byte));
-    resultLen := resultLen + Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
-    FbufOff := 0;
-    length := length - gapLen;
-    inOff := inOff + gapLen;
-    while (length > System.length(Fbuf)) do
+    System.Move(AInput[AInOff], FBuf[FBufOff], LGapLen * System.SizeOf(Byte));
+    LResultLen := LResultLen + FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
+    FBufOff := 0;
+    ALength := ALength - LGapLen;
+    AInOff := AInOff + LGapLen;
+    while (ALength > System.Length(FBuf)) do
     begin
-      resultLen := resultLen + Fcipher.ProcessBlock(input, inOff, output,
-        outOff + resultLen);
-      length := length - blockSize;
-      inOff := inOff + blockSize;
+      LResultLen := LResultLen + FCipher.ProcessBlock(AInput, AInOff, AOutput,
+        AOutOff + LResultLen);
+      ALength := ALength - LBlockSize;
+      AInOff := AInOff + LBlockSize;
     end;
   end;
-  System.Move(input[inOff], Fbuf[FbufOff], length * System.SizeOf(Byte));
-  FbufOff := FbufOff + length;
-  if (FbufOff = System.length(Fbuf)) then
+  System.Move(AInput[AInOff], FBuf[FBufOff], ALength * System.SizeOf(Byte));
+  FBufOff := FBufOff + ALength;
+  if (FBufOff = System.Length(FBuf)) then
   begin
-    resultLen := resultLen + Fcipher.ProcessBlock(Fbuf, 0, output,
-      outOff + resultLen);
-    FbufOff := 0;
+    LResultLen := LResultLen + FCipher.ProcessBlock(FBuf, 0, AOutput,
+      AOutOff + LResultLen);
+    FBufOff := 0;
   end;
-  result := resultLen;
+  Result := LResultLen;
 end;
 
-function TBufferedBlockCipher.ProcessBytes(const input: TCryptoLibByteArray;
-  inOff, length: Int32): TCryptoLibByteArray;
+function TBufferedBlockCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
+  AInOff, ALength: Int32): TCryptoLibByteArray;
 var
-  outLength, &pos: Int32;
-  outBytes, tmp: TCryptoLibByteArray;
+  LOutLength, LPos: Int32;
+  LOutBytes, LTmp: TCryptoLibByteArray;
 begin
-  if (input = Nil) then
+  if (AInput = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SInputNil);
   end;
-  if (length < 1) then
+  if (ALength < 1) then
   begin
-    result := Nil;
+    Result := nil;
     Exit;
   end;
 
-  outLength := GetUpdateOutputSize(length);
+  LOutLength := GetUpdateOutputSize(ALength);
 
-  if outLength > 0 then
+  if LOutLength > 0 then
   begin
-    System.SetLength(outBytes, outLength);
+    System.SetLength(LOutBytes, LOutLength);
   end
   else
   begin
-    outBytes := Nil;
+    LOutBytes := nil;
   end;
 
-  &pos := ProcessBytes(input, inOff, length, outBytes, 0);
+  LPos := ProcessBytes(AInput, AInOff, ALength, LOutBytes, 0);
 
-  if ((outLength > 0) and (pos < outLength)) then
+  if ((LOutLength > 0) and (LPos < LOutLength)) then
   begin
-    System.SetLength(tmp, &pos);
-    System.Move(outBytes[0], tmp[0], &pos * System.SizeOf(Byte));
+    System.SetLength(LTmp, LPos);
+    System.Move(LOutBytes[0], LTmp[0], LPos * System.SizeOf(Byte));
 
-    outBytes := tmp;
+    LOutBytes := LTmp;
   end;
 
-  result := outBytes;
+  Result := LOutBytes;
 
 end;
 
 procedure TBufferedBlockCipher.Reset;
 begin
-  TArrayUtilities.Fill<Byte>(Fbuf, 0, System.Length(Fbuf), Byte(0));
-  FbufOff := 0;
+  TArrayUtilities.Fill<Byte>(FBuf, 0, System.Length(FBuf), Byte(0));
+  FBufOff := 0;
 
-  Fcipher.Reset();
+  FCipher.Reset();
 end;
 
 end.

+ 7 - 7
CryptoLib/src/Crypto/Ciphers/ClpBufferedIesCipher.pas

@@ -83,7 +83,7 @@ const
 constructor TBufferedIesCipher.Create(const AEngine: IIesEngine);
 begin
   Inherited Create();
-  if AEngine = Nil then
+  if AEngine = nil then
     raise EArgumentNilCryptoLibException.CreateRes(@SEngineNil);
   FEngine := AEngine;
   FBufferLen := 0;
@@ -97,7 +97,7 @@ var
   LIesParams: IIesParameters;
 begin
   FForEncryption := AForEncryption;
-  if AParameters = Nil then
+  if AParameters = nil then
     raise EArgumentNilCryptoLibException.CreateRes(@SIesCipherParametersRequired);
   if not Supports(AParameters, IIesCipherParameters, LParams) then
     raise EArgumentCryptoLibException.CreateRes(@SIesCipherParametersRequired);
@@ -122,7 +122,7 @@ function TBufferedIesCipher.GetOutputSize(AInputLen: Int32): Int32;
 var
   LBaseLen: Int32;
 begin
-  if FEngine = Nil then
+  if FEngine = nil then
     raise EInvalidOperationCryptoLibException.CreateRes(@SCipherNotInitialised);
   LBaseLen := AInputLen + FBufferLen;
   if FForEncryption then
@@ -144,7 +144,7 @@ begin
     System.SetLength(FBuffer, Math.Max(256, FBufferLen * 2));
   FBuffer[FBufferLen] := AInput;
   System.Inc(FBufferLen);
-  Result := Nil;
+  Result := nil;
 end;
 
 function TBufferedIesCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
@@ -152,14 +152,14 @@ function TBufferedIesCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
 var
   LNewLen: Int32;
 begin
-  if AInput = Nil then
+  if AInput = nil then
     raise EArgumentNilCryptoLibException.Create('input');
   if (AInOff < 0) or (ALength < 0) or
     (AInOff + ALength > System.Length(AInput)) then
     raise EArgumentCryptoLibException.Create('invalid offset/length');
   if ALength = 0 then
   begin
-    Result := Nil;
+    Result := nil;
     Exit;
   end;
   LNewLen := FBufferLen + ALength;
@@ -167,7 +167,7 @@ begin
     System.SetLength(FBuffer, LNewLen);
   System.Move(AInput[AInOff], FBuffer[FBufferLen], ALength * System.SizeOf(Byte));
   FBufferLen := LNewLen;
-  Result := Nil;
+  Result := nil;
 end;
 
 function TBufferedIesCipher.DoFinal: TCryptoLibByteArray;

+ 54 - 54
CryptoLib/src/Crypto/Ciphers/ClpBufferedStreamCipher.pas

@@ -44,29 +44,29 @@ type
     function GetAlgorithmName: String; override;
 
   public
-    constructor Create(const cipher: IStreamCipher);
+    constructor Create(const ACipher: IStreamCipher);
 
-    procedure Init(forEncryption: Boolean;
-      const parameters: ICipherParameters); override;
+    procedure Init(AForEncryption: Boolean;
+      const AParameters: ICipherParameters); override;
 
     function GetBlockSize(): Int32; override;
 
-    function GetOutputSize(inputLen: Int32): Int32; override;
+    function GetOutputSize(AInputLen: Int32): Int32; override;
 
-    function GetUpdateOutputSize(inputLen: Int32): Int32; override;
+    function GetUpdateOutputSize(AInputLen: Int32): Int32; override;
 
-    function ProcessByte(input: Byte): TCryptoLibByteArray; overload; override;
-    function ProcessByte(input: Byte; const output: TCryptoLibByteArray;
-      outOff: Int32): Int32; overload; override;
+    function ProcessByte(AInput: Byte): TCryptoLibByteArray; overload; override;
+    function ProcessByte(AInput: Byte; const AOutput: TCryptoLibByteArray;
+      AOutOff: Int32): Int32; overload; override;
 
-    function ProcessBytes(const input: TCryptoLibByteArray;
-      inOff, Length: Int32): TCryptoLibByteArray; overload; override;
-    function ProcessBytes(const input: TCryptoLibByteArray;
-      inOff, Length: Int32; const output: TCryptoLibByteArray; outOff: Int32)
+    function ProcessBytes(const AInput: TCryptoLibByteArray;
+      AInOff, ALength: Int32): TCryptoLibByteArray; overload; override;
+    function ProcessBytes(const AInput: TCryptoLibByteArray;
+      AInOff, ALength: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32)
       : Int32; overload; override;
 
     function DoFinal(): TCryptoLibByteArray; overload; override;
-    function DoFinal(const input: TCryptoLibByteArray; inOff, Length: Int32)
+    function DoFinal(const AInput: TCryptoLibByteArray; AInOff, ALength: Int32)
       : TCryptoLibByteArray; overload; override;
 
     procedure Reset(); override;
@@ -79,111 +79,111 @@ implementation
 
 { TBufferedStreamCipher }
 
-constructor TBufferedStreamCipher.Create(const cipher: IStreamCipher);
+constructor TBufferedStreamCipher.Create(const ACipher: IStreamCipher);
 begin
   Inherited Create();
-  if (cipher = Nil) then
+  if (ACipher = nil) then
   begin
     raise EArgumentNilCryptoLibException.CreateRes(@SCipherNil);
   end;
 
-  FCipher := cipher;
+  FCipher := ACipher;
 end;
 
 function TBufferedStreamCipher.GetAlgorithmName: String;
 begin
-  result := FCipher.AlgorithmName;
+  Result := FCipher.AlgorithmName;
 end;
 
 function TBufferedStreamCipher.GetBlockSize: Int32;
 begin
-  result := 0;
+  Result := 0;
 end;
 
-function TBufferedStreamCipher.GetOutputSize(inputLen: Int32): Int32;
+function TBufferedStreamCipher.GetOutputSize(AInputLen: Int32): Int32;
 begin
-  result := inputLen;
+  Result := AInputLen;
 end;
 
-function TBufferedStreamCipher.GetUpdateOutputSize(inputLen: Int32): Int32;
+function TBufferedStreamCipher.GetUpdateOutputSize(AInputLen: Int32): Int32;
 begin
-  result := inputLen;
+  Result := AInputLen;
 end;
 
-procedure TBufferedStreamCipher.Init(forEncryption: Boolean;
-  const parameters: ICipherParameters);
+procedure TBufferedStreamCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
 var
   LParameters: ICipherParameters;
 begin
-  LParameters := parameters;
+  LParameters := AParameters;
   if Supports(LParameters, IParametersWithRandom) then
   begin
-    LParameters := (LParameters as IParametersWithRandom).parameters;
+    LParameters := (LParameters as IParametersWithRandom).Parameters;
   end;
-  FCipher.Init(forEncryption, LParameters);
+  FCipher.Init(AForEncryption, LParameters);
 end;
 
-function TBufferedStreamCipher.ProcessByte(input: Byte;
-  const output: TCryptoLibByteArray; outOff: Int32): Int32;
+function TBufferedStreamCipher.ProcessByte(AInput: Byte;
+  const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
 begin
-  if (outOff >= System.Length(output)) then
+  if (AOutOff >= System.Length(AOutput)) then
   begin
     raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooSmall);
   end;
-  output[outOff] := FCipher.ReturnByte(input);
-  result := 1;
+  AOutput[AOutOff] := FCipher.ReturnByte(AInput);
+  Result := 1;
 end;
 
-function TBufferedStreamCipher.ProcessByte(input: Byte): TCryptoLibByteArray;
+function TBufferedStreamCipher.ProcessByte(AInput: Byte): TCryptoLibByteArray;
 begin
-  result := TCryptoLibByteArray.Create(FCipher.ReturnByte(input));
+  Result := TCryptoLibByteArray.Create(FCipher.ReturnByte(AInput));
 end;
 
-function TBufferedStreamCipher.ProcessBytes(const input: TCryptoLibByteArray;
-  inOff, Length: Int32; const output: TCryptoLibByteArray;
-  outOff: Int32): Int32;
+function TBufferedStreamCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
+  AInOff, ALength: Int32; const AOutput: TCryptoLibByteArray;
+  AOutOff: Int32): Int32;
 begin
-  if (Length < 1) then
+  if (ALength < 1) then
   begin
-    result := 0;
+    Result := 0;
     Exit;
   end;
 
-  if (Length > 0) then
+  if (ALength > 0) then
   begin
-    FCipher.ProcessBytes(input, inOff, Length, output, outOff);
+    FCipher.ProcessBytes(AInput, AInOff, ALength, AOutput, AOutOff);
   end;
 
-  result := Length;
+  Result := ALength;
 end;
 
-function TBufferedStreamCipher.ProcessBytes(const input: TCryptoLibByteArray;
-  inOff, Length: Int32): TCryptoLibByteArray;
+function TBufferedStreamCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
+  AInOff, ALength: Int32): TCryptoLibByteArray;
 begin
-  if (Length < 1) then
+  if (ALength < 1) then
   begin
-    result := Nil;
+    Result := nil;
     Exit;
   end;
-  System.SetLength(result, Length);
-  FCipher.ProcessBytes(input, inOff, Length, result, 0);
+  System.SetLength(Result, ALength);
+  FCipher.ProcessBytes(AInput, AInOff, ALength, Result, 0);
 end;
 
 function TBufferedStreamCipher.DoFinal: TCryptoLibByteArray;
 begin
   Reset();
-  result := EmptyBuffer;
+  Result := EmptyBuffer;
 end;
 
-function TBufferedStreamCipher.DoFinal(const input: TCryptoLibByteArray;
-  inOff, Length: Int32): TCryptoLibByteArray;
+function TBufferedStreamCipher.DoFinal(const AInput: TCryptoLibByteArray;
+  AInOff, ALength: Int32): TCryptoLibByteArray;
 begin
-  if (Length < 1) then
+  if (ALength < 1) then
   begin
-    result := EmptyBuffer;
+    Result := EmptyBuffer;
     Exit;
   end;
-  result := ProcessBytes(input, inOff, Length);
+  Result := ProcessBytes(AInput, AInOff, ALength);
   Reset();
 end;
 

+ 178 - 0
CryptoLib/src/Crypto/Ciphers/ClpCbcBlockCipher.pas

@@ -0,0 +1,178 @@
+{ *********************************************************************************** }
+{ *                              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 ClpCbcBlockCipher;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpIBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICipherParameters,
+  ClpIParametersWithIV,
+  ClpArrayUtilities,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SInvalidIVLength =
+    'Initialisation Vector Must be the Same Length as Block Size';
+  SInvalidChangeState = 'Cannot Change Encrypting State Without Providing Key.';
+  SInputBufferTooShort = 'Input Buffer too Short';
+  SOutputBufferTooShort = 'Output Buffer too Short';
+
+type
+  TCbcBlockCipher = class sealed(TInterfacedObject, ICbcBlockCipher,
+    IBlockCipher)
+
+  strict private
+  var
+    FIV, FCbcV, FCbcNextV: TCryptoLibByteArray;
+    FBlockSize: Int32;
+    FCipher: IBlockCipher;
+    FEncrypting: Boolean;
+
+    function GetAlgorithmName: String; inline;
+    function GetIsPartialBlockOkay: Boolean; inline;
+    function EncryptBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+    function DecryptBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+
+  public
+    constructor Create(const ACipher: IBlockCipher);
+    function GetUnderlyingCipher(): IBlockCipher;
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
+    function GetBlockSize(): Int32; inline;
+    function ProcessBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+    procedure Reset(); inline;
+    property AlgorithmName: String read GetAlgorithmName;
+    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
+  end;
+
+implementation
+
+{ TCbcBlockCipher }
+
+constructor TCbcBlockCipher.Create(const ACipher: IBlockCipher);
+begin
+  inherited Create();
+  FCipher := ACipher;
+  FBlockSize := ACipher.GetBlockSize();
+  System.SetLength(FIV, FBlockSize);
+  System.SetLength(FCbcV, FBlockSize);
+  System.SetLength(FCbcNextV, FBlockSize);
+end;
+
+function TCbcBlockCipher.DecryptBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LLength, LI: Int32;
+  LTmp: TCryptoLibByteArray;
+begin
+  if ((AInOff + FBlockSize) > System.Length(AInput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
+  System.Move(AInput[AInOff], FCbcNextV[0], FBlockSize * System.SizeOf(Byte));
+  LLength := FCipher.ProcessBlock(AInput, AInOff, AOutBytes, AOutOff);
+  for LI := 0 to System.Pred(FBlockSize) do
+    AOutBytes[AOutOff + LI] := AOutBytes[AOutOff + LI] xor FCbcV[LI];
+  LTmp := FCbcV;
+  FCbcV := FCbcNextV;
+  FCbcNextV := LTmp;
+  Result := LLength;
+end;
+
+function TCbcBlockCipher.EncryptBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LI, LLen: Int32;
+begin
+  if ((AInOff + FBlockSize) > System.Length(AInput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
+  for LI := 0 to System.Pred(FBlockSize) do
+    FCbcV[LI] := FCbcV[LI] xor AInput[AInOff + LI];
+  LLen := FCipher.ProcessBlock(FCbcV, 0, AOutBytes, AOutOff);
+  System.Move(AOutBytes[AOutOff], FCbcV[0], System.Length(FCbcV) * System.SizeOf(Byte));
+  Result := LLen;
+end;
+
+procedure TCbcBlockCipher.Reset;
+begin
+  System.Move(FIV[0], FCbcV[0], System.Length(FIV));
+  TArrayUtilities.Fill<Byte>(FCbcNextV, 0, System.Length(FCbcNextV), Byte(0));
+  FCipher.Reset();
+end;
+
+function TCbcBlockCipher.GetAlgorithmName: String;
+begin
+  Result := FCipher.AlgorithmName + '/CBC';
+end;
+
+function TCbcBlockCipher.GetBlockSize: Int32;
+begin
+  Result := FCipher.GetBlockSize();
+end;
+
+function TCbcBlockCipher.GetIsPartialBlockOkay: Boolean;
+begin
+  Result := False;
+end;
+
+function TCbcBlockCipher.GetUnderlyingCipher: IBlockCipher;
+begin
+  Result := FCipher;
+end;
+
+procedure TCbcBlockCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
+var
+  LOldEncrypting: Boolean;
+  LIvParam: IParametersWithIV;
+  LIv: TCryptoLibByteArray;
+  LParameters: ICipherParameters;
+begin
+  LOldEncrypting := FEncrypting;
+  FEncrypting := AForEncryption;
+  LParameters := AParameters;
+  if Supports(LParameters, IParametersWithIV, LIvParam) then
+  begin
+    LIv := LIvParam.GetIV();
+    if (System.Length(LIv) <> FBlockSize) then
+      raise EArgumentCryptoLibException.CreateRes(@SInvalidIVLength);
+    System.Move(LIv[0], FIV[0], System.Length(LIv) * System.SizeOf(Byte));
+    LParameters := LIvParam.Parameters;
+  end;
+  Reset();
+  if (LParameters <> nil) then
+    FCipher.Init(FEncrypting, LParameters)
+  else if (LOldEncrypting <> FEncrypting) then
+    raise EArgumentCryptoLibException.CreateRes(@SInvalidChangeState);
+end;
+
+function TCbcBlockCipher.ProcessBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+begin
+  if FEncrypting then
+    Result := EncryptBlock(AInput, AInOff, AOutput, AOutOff)
+  else
+    Result := DecryptBlock(AInput, AInOff, AOutput, AOutOff);
+end;
+
+end.

+ 195 - 0
CryptoLib/src/Crypto/Ciphers/ClpCfbBlockCipher.pas

@@ -0,0 +1,195 @@
+{ *********************************************************************************** }
+{ *                              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 ClpCfbBlockCipher;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpIBlockCipher,
+  ClpICfbBlockCipher,
+  ClpICipherParameters,
+  ClpIParametersWithIV,
+  ClpArrayUtilities,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SInputBufferTooShort = 'Input Buffer too Short';
+  SOutputBufferTooShort = 'Output Buffer too Short';
+
+type
+  TCfbBlockCipher = class sealed(TInterfacedObject, ICfbBlockCipher,
+    IBlockCipher)
+
+  strict private
+  var
+    FIV, FCfbV, FCfbOutV: TCryptoLibByteArray;
+    FBlockSize: Int32;
+    FCipher: IBlockCipher;
+    FEncrypting: Boolean;
+
+    function GetAlgorithmName: String; inline;
+    function GetIsPartialBlockOkay: Boolean; inline;
+    function EncryptBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+    function DecryptBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+
+  public
+    constructor Create(const ACipher: IBlockCipher; ABitBlockSize: Int32);
+    function GetUnderlyingCipher(): IBlockCipher;
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
+    function GetBlockSize(): Int32; inline;
+    function ProcessBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+    procedure Reset(); inline;
+    property AlgorithmName: String read GetAlgorithmName;
+    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
+  end;
+
+implementation
+
+{ TCfbBlockCipher }
+
+constructor TCfbBlockCipher.Create(const ACipher: IBlockCipher;
+  ABitBlockSize: Int32);
+begin
+  inherited Create();
+  FCipher := ACipher;
+  FBlockSize := ABitBlockSize div 8;
+
+  System.SetLength(FIV, FCipher.GetBlockSize());
+  System.SetLength(FCfbV, FCipher.GetBlockSize());
+  System.SetLength(FCfbOutV, FCipher.GetBlockSize());
+end;
+
+function TCfbBlockCipher.DecryptBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LI, LCount: Int32;
+begin
+  if ((AInOff + FBlockSize) > System.Length(AInput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
+
+  if ((AOutOff + FBlockSize) > System.Length(AOutBytes)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
+
+  FCipher.ProcessBlock(FCfbV, 0, FCfbOutV, 0);
+
+  LCount := (System.Length(FCfbV) - FBlockSize) * System.SizeOf(Byte);
+  if LCount > 0 then
+    System.Move(FCfbV[FBlockSize], FCfbV[0], LCount);
+
+  System.Move(AInput[AInOff], FCfbV[(System.Length(FCfbV) - FBlockSize)],
+    FBlockSize * System.SizeOf(Byte));
+
+  for LI := 0 to System.Pred(FBlockSize) do
+    AOutBytes[AOutOff + LI] := Byte(FCfbOutV[LI] xor AInput[AInOff + LI]);
+
+  Result := FBlockSize;
+end;
+
+function TCfbBlockCipher.EncryptBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutBytes: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LI, LCount: Int32;
+begin
+  if ((AInOff + FBlockSize) > System.Length(AInput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
+
+  if ((AOutOff + FBlockSize) > System.Length(AOutBytes)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
+
+  FCipher.ProcessBlock(FCfbV, 0, FCfbOutV, 0);
+
+  for LI := 0 to System.Pred(FBlockSize) do
+    AOutBytes[AOutOff + LI] := Byte(FCfbOutV[LI] xor AInput[AInOff + LI]);
+
+  LCount := (System.Length(FCfbV) - FBlockSize) * System.SizeOf(Byte);
+  if LCount > 0 then
+    System.Move(FCfbV[FBlockSize], FCfbV[0], LCount);
+
+  System.Move(AOutBytes[AOutOff], FCfbV[(System.Length(FCfbV) - FBlockSize)],
+    FBlockSize * System.SizeOf(Byte));
+
+  Result := FBlockSize;
+end;
+
+procedure TCfbBlockCipher.Reset;
+begin
+  System.Move(FIV[0], FCfbV[0], System.Length(FIV));
+  FCipher.Reset();
+end;
+
+function TCfbBlockCipher.GetAlgorithmName: String;
+begin
+  Result := FCipher.AlgorithmName + '/CFB' + IntToStr(FBlockSize * 8);
+end;
+
+function TCfbBlockCipher.GetBlockSize: Int32;
+begin
+  Result := FBlockSize;
+end;
+
+function TCfbBlockCipher.GetIsPartialBlockOkay: Boolean;
+begin
+  Result := True;
+end;
+
+function TCfbBlockCipher.GetUnderlyingCipher: IBlockCipher;
+begin
+  Result := FCipher;
+end;
+
+procedure TCfbBlockCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
+var
+  LIvParam: IParametersWithIV;
+  LIv: TCryptoLibByteArray;
+  LParameters: ICipherParameters;
+  LDiff: Int32;
+begin
+  FEncrypting := AForEncryption;
+  LParameters := AParameters;
+
+  if Supports(LParameters, IParametersWithIV, LIvParam) then
+  begin
+    LIv := LIvParam.GetIV();
+    LDiff := System.Length(FIV) - System.Length(LIv);
+    System.Move(LIv[0], FIV[LDiff], System.Length(LIv) * System.SizeOf(Byte));
+    TArrayUtilities.Fill<Byte>(FIV, 0, LDiff, Byte(0));
+    LParameters := LIvParam.Parameters;
+  end;
+
+  Reset();
+  if (LParameters <> nil) then
+    FCipher.Init(True, LParameters);
+end;
+
+function TCfbBlockCipher.ProcessBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+begin
+  if FEncrypting then
+    Result := EncryptBlock(AInput, AInOff, AOutput, AOutOff)
+  else
+    Result := DecryptBlock(AInput, AInOff, AOutput, AOutOff);
+end;
+
+end.

+ 22 - 4
CryptoLib/src/Crypto/Ciphers/ClpCipherUtilities.pas

@@ -40,10 +40,28 @@ uses
   ClpNistObjectIdentifiers,
   ClpPkcsObjectIdentifiers,
   ClpStringUtilities,
-  ClpPaddingModes,
-  ClpIPaddingModes,
-  ClpBlockCipherModes,
-  ClpIBlockCipherModes,
+  ClpISO10126d2Padding,
+  ClpIISO10126d2Padding,
+  ClpISO7816d4Padding,
+  ClpIISO7816d4Padding,
+  ClpPkcs7Padding,
+  ClpIPkcs7Padding,
+  ClpTBCPadding,
+  ClpITBCPadding,
+  ClpX923Padding,
+  ClpIX923Padding,
+  ClpZeroBytePadding,
+  ClpIZeroBytePadding,
+  ClpCbcBlockCipher,
+  ClpICbcBlockCipher,
+  ClpCfbBlockCipher,
+  ClpICfbBlockCipher,
+  ClpOfbBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpSicBlockCipher,
+  ClpISicBlockCipher,
+  ClpCtsBlockCipher,
+  ClpICtsBlockCipher,
   ClpBufferedBlockCipher,
   ClpIBufferedBlockCipher,
   ClpBufferedStreamCipher,

+ 255 - 0
CryptoLib/src/Crypto/Ciphers/ClpCtsBlockCipher.pas

@@ -0,0 +1,255 @@
+{ *********************************************************************************** }
+{ *                              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 ClpCtsBlockCipher;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpIBlockCipher,
+  ClpIBufferedBlockCipher,
+  ClpICtsBlockCipher,
+  ClpICbcBlockCipher,
+  ClpICfbBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpISicBlockCipher,
+  ClpBufferedBlockCipher,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SUnsupportedCipher = 'CtsBlockCipher Can Only Accept ECB or CBC Ciphers';
+  SNegativeInputLength = 'Can''t Have a Negative Input Length!';
+  SCTSDoFinalError = 'Need at Least One Block of Input For CTS';
+  SOutputBufferTooShort = 'Output Buffer too Short';
+  SOutputBufferTooSmallForDoFinal = 'Output Buffer too Short for DoFinal()';
+
+type
+  TCtsBlockCipher = class sealed(TBufferedBlockCipher, ICtsBlockCipher)
+
+  strict private
+  var
+    FBlockSize: Int32;
+
+  public
+    constructor Create(const ACipher: IBlockCipher);
+    function GetOutputSize(AInputLen: Int32): Int32; override;
+    function GetUpdateOutputSize(AInputLen: Int32): Int32; override;
+    function ProcessByte(AInput: Byte; const AOutput: TCryptoLibByteArray;
+      AOutOff: Int32): Int32; override;
+    function ProcessBytes(const AInput: TCryptoLibByteArray; AInOff, ALen: Int32;
+      const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32; override;
+    function DoFinal(const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+      override;
+  end;
+
+implementation
+
+{ TCtsBlockCipher }
+
+constructor TCtsBlockCipher.Create(const ACipher: IBlockCipher);
+begin
+  Inherited Create();
+  if Supports(ACipher, ICfbBlockCipher) or Supports(ACipher, IOfbBlockCipher) or
+    Supports(ACipher, ISicBlockCipher) or Supports(ACipher, ICtsBlockCipher) then
+    raise EArgumentCryptoLibException.CreateRes(@SUnsupportedCipher);
+
+  FCipher := ACipher;
+  FBlockSize := FCipher.GetBlockSize();
+  System.SetLength(FBuf, FBlockSize * 2);
+  FBufOff := 0;
+end;
+
+function TCtsBlockCipher.DoFinal(const AOutput: TCryptoLibByteArray;
+  AOutOff: Int32): Int32;
+var
+  LBlockSize, LLen, LI: Int32;
+  LBlock, LLastBlock: TCryptoLibByteArray;
+  LCipher: IBlockCipher;
+begin
+  if ((FBufOff + AOutOff) > System.Length(AOutput)) then
+    raise EDataLengthCryptoLibException.CreateRes
+      (@SOutputBufferTooSmallForDoFinal);
+
+  LBlockSize := FCipher.GetBlockSize();
+  LLen := FBufOff - LBlockSize;
+  System.SetLength(LBlock, LBlockSize);
+
+  if (FForEncryption) then
+  begin
+    if (FBufOff < LBlockSize) then
+      raise EDataLengthCryptoLibException.CreateRes(@SCTSDoFinalError);
+
+    FCipher.ProcessBlock(FBuf, 0, LBlock, 0);
+
+    if (FBufOff > LBlockSize) then
+    begin
+      LI := FBufOff;
+      while LI <> System.Length(FBuf) do
+      begin
+        FBuf[LI] := LBlock[LI - LBlockSize];
+        System.Inc(LI);
+      end;
+
+      LI := LBlockSize;
+      while LI <> FBufOff do
+      begin
+        FBuf[LI] := FBuf[LI] xor (LBlock[LI - LBlockSize]);
+        System.Inc(LI);
+      end;
+
+      if Supports(FCipher, ICbcBlockCipher) then
+      begin
+        LCipher := (FCipher as ICbcBlockCipher).GetUnderlyingCipher();
+        LCipher.ProcessBlock(FBuf, LBlockSize, AOutput, AOutOff);
+      end
+      else
+        FCipher.ProcessBlock(FBuf, LBlockSize, AOutput, AOutOff);
+
+      System.Move(LBlock[0], AOutput[AOutOff + LBlockSize],
+        LLen * System.SizeOf(Byte));
+    end
+    else
+      System.Move(LBlock[0], AOutput[AOutOff], LBlockSize * System.SizeOf(Byte));
+  end
+  else
+  begin
+    if (FBufOff < LBlockSize) then
+      raise EDataLengthCryptoLibException.CreateRes(@SCTSDoFinalError);
+
+    System.SetLength(LLastBlock, LBlockSize);
+
+    if (FBufOff > LBlockSize) then
+    begin
+      if Supports(FCipher, ICbcBlockCipher) then
+      begin
+        LCipher := (FCipher as ICbcBlockCipher).GetUnderlyingCipher();
+        LCipher.ProcessBlock(FBuf, 0, LBlock, 0);
+      end
+      else
+        FCipher.ProcessBlock(FBuf, 0, LBlock, 0);
+
+      LI := LBlockSize;
+      while LI <> FBufOff do
+      begin
+        LLastBlock[LI - LBlockSize] := Byte(LBlock[LI - LBlockSize] xor FBuf[LI]);
+        System.Inc(LI);
+      end;
+
+      System.Move(FBuf[LBlockSize], LBlock[0], LLen * System.SizeOf(Byte));
+      FCipher.ProcessBlock(LBlock, 0, AOutput, AOutOff);
+      System.Move(LLastBlock[0], AOutput[AOutOff + LBlockSize],
+        LLen * System.SizeOf(Byte));
+    end
+    else
+    begin
+      FCipher.ProcessBlock(FBuf, 0, LBlock, 0);
+      System.Move(LBlock[0], AOutput[AOutOff], LBlockSize * System.SizeOf(Byte));
+    end;
+  end;
+
+  Result := FBufOff;
+  Reset();
+end;
+
+function TCtsBlockCipher.GetOutputSize(AInputLen: Int32): Int32;
+begin
+  Result := AInputLen + FBufOff;
+end;
+
+function TCtsBlockCipher.GetUpdateOutputSize(AInputLen: Int32): Int32;
+var
+  LTotal, LLeftOver: Int32;
+begin
+  LTotal := AInputLen + FBufOff;
+  LLeftOver := LTotal mod System.Length(FBuf);
+
+  if (LLeftOver = 0) then
+  begin
+    Result := LTotal - System.Length(FBuf);
+    Exit;
+  end;
+  Result := LTotal - LLeftOver;
+end;
+
+function TCtsBlockCipher.ProcessByte(AInput: Byte;
+  const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+begin
+  Result := 0;
+
+  if (FBufOff = System.Length(FBuf)) then
+  begin
+    Result := FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
+    System.Move(FBuf[FBlockSize], FBuf[0], FBlockSize * System.SizeOf(Byte));
+    FBufOff := FBlockSize;
+  end;
+
+  FBuf[FBufOff] := AInput;
+  System.Inc(FBufOff);
+end;
+
+function TCtsBlockCipher.ProcessBytes(const AInput: TCryptoLibByteArray;
+  AInOff, ALen: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LBlockSize, LLength, LGapLen: Int32;
+begin
+  if (ALen < 0) then
+    raise EArgumentCryptoLibException.CreateRes(@SNegativeInputLength);
+
+  LBlockSize := GetBlockSize();
+  LLength := GetUpdateOutputSize(ALen);
+
+  if (LLength > 0) then
+  begin
+    if ((AOutOff + LLength) > System.Length(AOutput)) then
+      raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
+  end;
+
+  Result := 0;
+  LGapLen := System.Length(FBuf) - FBufOff;
+
+  if (ALen > LGapLen) then
+  begin
+    System.Move(AInput[AInOff], FBuf[FBufOff], LGapLen * System.SizeOf(Byte));
+
+    Result := Result + FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
+    System.Move(FBuf[LBlockSize], FBuf[0], LBlockSize * System.SizeOf(Byte));
+
+    FBufOff := LBlockSize;
+
+    ALen := ALen - LGapLen;
+    AInOff := AInOff + LGapLen;
+
+    while (ALen > LBlockSize) do
+    begin
+      System.Move(AInput[AInOff], FBuf[FBufOff], LBlockSize * System.SizeOf(Byte));
+      Result := Result + FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff + Result);
+      System.Move(FBuf[LBlockSize], FBuf[0], LBlockSize * System.SizeOf(Byte));
+
+      ALen := ALen - LBlockSize;
+      AInOff := AInOff + LBlockSize;
+    end;
+  end;
+
+  System.Move(AInput[AInOff], FBuf[FBufOff], ALen * System.SizeOf(Byte));
+
+  FBufOff := FBufOff + ALen;
+end;
+
+end.

+ 161 - 0
CryptoLib/src/Crypto/Ciphers/ClpOfbBlockCipher.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 ClpOfbBlockCipher;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  SysUtils,
+  ClpIBlockCipher,
+  ClpIOfbBlockCipher,
+  ClpICipherParameters,
+  ClpIParametersWithIV,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SInputBufferTooShort = 'Input Buffer too Short';
+  SOutputBufferTooShort = 'Output Buffer too Short';
+
+type
+  TOfbBlockCipher = class sealed(TInterfacedObject, IOfbBlockCipher,
+    IBlockCipher)
+
+  strict private
+  var
+    FIV, FOfbV, FOfbOutV: TCryptoLibByteArray;
+    FBlockSize: Int32;
+    FCipher: IBlockCipher;
+    FEncrypting: Boolean;
+
+    function GetAlgorithmName: String; inline;
+    function GetIsPartialBlockOkay: Boolean; inline;
+
+  public
+    constructor Create(const ACipher: IBlockCipher; ABlockSize: Int32);
+    function GetUnderlyingCipher(): IBlockCipher;
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
+    function GetBlockSize(): Int32; inline;
+    function ProcessBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+    procedure Reset(); inline;
+    property AlgorithmName: String read GetAlgorithmName;
+    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
+  end;
+
+implementation
+
+{ TOfbBlockCipher }
+
+constructor TOfbBlockCipher.Create(const ACipher: IBlockCipher;
+  ABlockSize: Int32);
+begin
+  inherited Create();
+  FCipher := ACipher;
+  FBlockSize := ABlockSize div 8;
+
+  System.SetLength(FIV, FCipher.GetBlockSize());
+  System.SetLength(FOfbV, FCipher.GetBlockSize());
+  System.SetLength(FOfbOutV, FCipher.GetBlockSize());
+end;
+
+procedure TOfbBlockCipher.Reset;
+begin
+  System.Move(FIV[0], FOfbV[0], System.Length(FIV));
+  FCipher.Reset();
+end;
+
+function TOfbBlockCipher.GetAlgorithmName: String;
+begin
+  Result := FCipher.AlgorithmName + '/OFB' + IntToStr(FBlockSize * 8);
+end;
+
+function TOfbBlockCipher.GetBlockSize: Int32;
+begin
+  Result := FBlockSize;
+end;
+
+function TOfbBlockCipher.GetIsPartialBlockOkay: Boolean;
+begin
+  Result := True;
+end;
+
+function TOfbBlockCipher.GetUnderlyingCipher: IBlockCipher;
+begin
+  Result := FCipher;
+end;
+
+procedure TOfbBlockCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
+var
+  LIvParam: IParametersWithIV;
+  LIv: TCryptoLibByteArray;
+  LParameters: ICipherParameters;
+  LI: Int32;
+begin
+  FEncrypting := AForEncryption;
+  LParameters := AParameters;
+
+  if Supports(LParameters, IParametersWithIV, LIvParam) then
+  begin
+    LIv := LIvParam.GetIV();
+    if (System.Length(LIv) < System.Length(FIV)) then
+    begin
+      System.Move(LIv[0], FIV[System.Length(FIV) - System.Length(LIv)],
+        System.Length(LIv) * System.SizeOf(Byte));
+      for LI := 0 to System.Pred(System.Length(FIV) - System.Length(LIv)) do
+        FIV[LI] := 0;
+    end
+    else
+      System.Move(LIv[0], FIV[0], System.Length(FIV) * System.SizeOf(Byte));
+    LParameters := LIvParam.Parameters;
+  end;
+
+  Reset();
+  if (LParameters <> nil) then
+    FCipher.Init(True, LParameters);
+end;
+
+function TOfbBlockCipher.ProcessBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LI, LCount: Int32;
+begin
+  if ((AInOff + FBlockSize) > System.Length(AInput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
+
+  if ((AOutOff + FBlockSize) > System.Length(AOutput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
+
+  FCipher.ProcessBlock(FOfbV, 0, FOfbOutV, 0);
+
+  for LI := 0 to System.Pred(FBlockSize) do
+    AOutput[AOutOff + LI] := Byte(FOfbOutV[LI] xor AInput[AInOff + LI]);
+
+  LCount := (System.Length(FOfbV) - FBlockSize) * System.SizeOf(Byte);
+  if LCount > 0 then
+    System.Move(FOfbV[FBlockSize], FOfbV[0], LCount);
+
+  System.Move(FOfbOutV[0], FOfbV[(System.Length(FOfbV) - FBlockSize)],
+    FBlockSize * System.SizeOf(Byte));
+
+  Result := FBlockSize;
+end;
+
+end.

+ 175 - 0
CryptoLib/src/Crypto/Ciphers/ClpSicBlockCipher.pas

@@ -0,0 +1,175 @@
+{ *********************************************************************************** }
+{ *                              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 ClpSicBlockCipher;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  Math,
+  SysUtils,
+  ClpIBlockCipher,
+  ClpISicBlockCipher,
+  ClpICipherParameters,
+  ClpIParametersWithIV,
+  ClpArrayUtilities,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SInputBufferTooShort = 'Input Buffer too Short';
+  SOutputBufferTooShort = 'Output Buffer too Short';
+{$IFNDEF _FIXINSIGHT_}
+  SInvalidParameterArgument = 'CTR/SIC Mode Requires ParametersWithIV';
+  SInvalidTooLargeIVLength =
+    'CTR/SIC mode requires IV no greater than: %u bytes';
+  SInvalidTooSmallIVLength = 'CTR/SIC mode requires IV of at least: %u bytes';
+{$ENDIF}
+
+type
+  TSicBlockCipher = class sealed(TInterfacedObject, ISicBlockCipher,
+    IBlockCipher)
+
+  strict private
+  var
+    FIV, FCounter, FCounterOut: TCryptoLibByteArray;
+    FBlockSize: Int32;
+    FCipher: IBlockCipher;
+
+    function GetAlgorithmName: String; inline;
+    function GetIsPartialBlockOkay: Boolean; inline;
+
+  public
+    constructor Create(const ACipher: IBlockCipher);
+    function GetUnderlyingCipher(): IBlockCipher;
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
+    function GetBlockSize(): Int32; inline;
+    function ProcessBlock(const AInput: TCryptoLibByteArray; AInOff: Int32;
+      const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+    procedure Reset(); inline;
+    property AlgorithmName: String read GetAlgorithmName;
+    property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
+  end;
+
+implementation
+
+{ TSicBlockCipher }
+
+constructor TSicBlockCipher.Create(const ACipher: IBlockCipher);
+begin
+  inherited Create();
+  FCipher := ACipher;
+  FBlockSize := FCipher.GetBlockSize();
+
+  System.SetLength(FCounter, FBlockSize);
+  System.SetLength(FCounterOut, FBlockSize);
+  System.SetLength(FIV, FBlockSize);
+end;
+
+procedure TSicBlockCipher.Reset;
+begin
+  TArrayUtilities.Fill<Byte>(FCounter, 0, System.Length(FCounter), Byte(0));
+  System.Move(FIV[0], FCounter[0], System.Length(FIV) * System.SizeOf(Byte));
+  FCipher.Reset();
+end;
+
+function TSicBlockCipher.GetAlgorithmName: String;
+begin
+  Result := FCipher.AlgorithmName + '/SIC';
+end;
+
+function TSicBlockCipher.GetBlockSize: Int32;
+begin
+  Result := FCipher.GetBlockSize();
+end;
+
+function TSicBlockCipher.GetIsPartialBlockOkay: Boolean;
+begin
+  Result := True;
+end;
+
+function TSicBlockCipher.GetUnderlyingCipher: IBlockCipher;
+begin
+  Result := FCipher;
+end;
+
+{$IFNDEF _FIXINSIGHT_}
+procedure TSicBlockCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
+var
+  LIvParam: IParametersWithIV;
+  LParameters: ICipherParameters;
+  LMaxCounterSize: Int32;
+begin
+  LParameters := AParameters;
+
+  if Supports(LParameters, IParametersWithIV, LIvParam) then
+  begin
+    FIV := LIvParam.GetIV();
+
+    if (FBlockSize < System.Length(FIV)) then
+      raise EArgumentCryptoLibException.CreateResFmt(@SInvalidTooLargeIVLength,
+        [FBlockSize]);
+
+    LMaxCounterSize := Min(8, FBlockSize div 2);
+
+    if ((FBlockSize - System.Length(FIV)) > LMaxCounterSize) then
+      raise EArgumentCryptoLibException.CreateResFmt(@SInvalidTooSmallIVLength,
+        [FBlockSize - LMaxCounterSize]);
+
+    LParameters := LIvParam.Parameters;
+  end
+  else
+    raise EArgumentCryptoLibException.CreateRes(@SInvalidParameterArgument);
+
+  if (LParameters <> nil) then
+    FCipher.Init(True, LParameters);
+
+  Reset();
+end;
+{$ENDIF}
+
+function TSicBlockCipher.ProcessBlock(const AInput: TCryptoLibByteArray;
+  AInOff: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
+var
+  LI, LJ: Int32;
+begin
+  if ((AInOff + FBlockSize) > System.Length(AInput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SInputBufferTooShort);
+
+  if ((AOutOff + FBlockSize) > System.Length(AOutput)) then
+    raise EDataLengthCryptoLibException.CreateRes(@SOutputBufferTooShort);
+
+  FCipher.ProcessBlock(FCounter, 0, FCounterOut, 0);
+
+  for LI := 0 to System.Pred(System.Length(FCounterOut)) do
+    AOutput[AOutOff + LI] := Byte(FCounterOut[LI] xor AInput[AInOff + LI]);
+
+  LJ := System.Length(FCounter);
+  System.Dec(LJ);
+  System.Inc(FCounter[LJ]);
+  while ((LJ >= 0) and (FCounter[LJ] = 0)) do
+  begin
+    System.Dec(LJ);
+    System.Inc(FCounter[LJ]);
+  end;
+
+  Result := System.Length(FCounter);
+end;
+
+end.

+ 1 - 1
CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas

@@ -220,7 +220,7 @@ begin
       [AlgorithmName, NonceSize]);
   end;
 
-  keyParam := ivParams.parameters;
+  keyParam := ivParams.Parameters;
   if (keyParam = Nil) then
   begin
     if (not FInitialised) then

+ 1 - 1
CryptoLib/src/Crypto/Generators/ClpDHBasicKeyPairGenerator.pas

@@ -80,7 +80,7 @@ var
 begin
 
   helper := TDHKeyGeneratorHelper.Instance;
-  dhp := Fparam.parameters;
+  dhp := Fparam.Parameters;
 
   x := helper.CalculatePrivate(dhp, Fparam.Random);
   y := helper.CalculatePublic(dhp, x);

+ 1 - 1
CryptoLib/src/Crypto/Generators/ClpDHKeyPairGenerator.pas

@@ -81,7 +81,7 @@ var
 begin
 
   helper := TDHKeyGeneratorHelper.Instance;
-  dhp := Fparam.parameters;
+  dhp := Fparam.Parameters;
 
   x := helper.CalculatePrivate(dhp, Fparam.Random);
   y := helper.CalculatePublic(dhp, x);

+ 2 - 2
CryptoLib/src/Crypto/Generators/ClpDsaKeyPairGenerator.pas

@@ -91,9 +91,9 @@ var
   dsaParams: IDsaParameters;
   x, y: TBigInteger;
 begin
-  dsaParams := Fparam.parameters;
+  dsaParams := Fparam.Parameters;
 
-  x := GeneratePrivateKey(dsaParams.q, Fparam.random);
+  x := GeneratePrivateKey(dsaParams.q, Fparam.Random);
   y := CalculatePublicKey(dsaParams.p, dsaParams.g, x);
 
   result := TAsymmetricCipherKeyPair.Create(TDsaPublicKeyParameters.Create(y,

+ 1 - 1
CryptoLib/src/Crypto/Generators/ClpDsaParametersGenerator.pas

@@ -611,7 +611,7 @@ begin
   FN := n;
   Fcertainty := params.certainty;
   Fiterations := Max(GetMinimumIterations(L), (Fcertainty + 1) div 2);
-  Frandom := params.random;
+  Frandom := params.Random;
   Fuse186_3 := True;
   FusageIndex := params.UsageIndex;
 end;

+ 2 - 2
CryptoLib/src/Crypto/Generators/ClpECKeyPairGenerator.pas

@@ -165,7 +165,7 @@ var
   ec: IECDomainParameters;
   q: IECPoint;
 begin
-  ec := privKey.parameters;
+  ec := privKey.Parameters;
   q := (TFixedPointCombMultiplier.Create() as IFixedPointCombMultiplier)
     .Multiply(ec.G, privKey.d);
 
@@ -209,7 +209,7 @@ begin
       ecps.H, ecps.GetSeed());
   end;
 
-  Frandom := parameters.random;
+  Frandom := parameters.Random;
 
   if (Frandom = Nil) then
   begin

+ 1 - 1
CryptoLib/src/Crypto/Generators/ClpX25519KeyPairGenerator.pas

@@ -64,7 +64,7 @@ end;
 procedure TX25519KeyPairGenerator.Init(const parameters
   : IKeyGenerationParameters);
 begin
-  FRandom := parameters.random;
+  FRandom := parameters.Random;
 end;
 
 end.

+ 87 - 0
CryptoLib/src/Crypto/Paddings/ClpISO10126d2Padding.pas

@@ -0,0 +1,87 @@
+{ *********************************************************************************** }
+{ *                              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 ClpISO10126d2Padding;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding,
+  ClpIISO10126d2Padding,
+  ClpSecureRandom,
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SCorruptedPadBlock = 'Pad Block Corrupted';
+
+type
+  TISO10126d2Padding = class sealed(TInterfacedObject, IISO10126d2Padding,
+    IBlockCipherPadding)
+  strict private
+    FRandom: ISecureRandom;
+    function GetPaddingName: String; inline;
+  public
+    procedure Init(const ARandom: ISecureRandom);
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
+    property PaddingName: String read GetPaddingName;
+  end;
+
+implementation
+
+function TISO10126d2Padding.AddPadding(const AInput: TCryptoLibByteArray;
+  AInOff: Int32): Int32;
+var
+  LCode: Byte;
+begin
+  LCode := Byte(System.Length(AInput) - AInOff);
+  while (AInOff < (System.Length(AInput) - 1)) do
+  begin
+    AInput[AInOff] := Byte(FRandom.NextInt32);
+    System.Inc(AInOff);
+  end;
+  AInput[AInOff] := LCode;
+  Result := LCode;
+end;
+
+function TISO10126d2Padding.GetPaddingName: String;
+begin
+  Result := 'ISO10126-2';
+end;
+
+procedure TISO10126d2Padding.Init(const ARandom: ISecureRandom);
+begin
+  if ARandom <> nil then
+    FRandom := ARandom
+  else
+    FRandom := TSecureRandom.Create();
+end;
+
+function TISO10126d2Padding.PadCount(const AInput: TCryptoLibByteArray): Int32;
+var
+  LCount: Int32;
+begin
+  LCount := AInput[System.Length(AInput) - 1] and $FF;
+  if (LCount > System.Length(AInput)) then
+    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
+  Result := LCount;
+end;
+
+end.

+ 86 - 0
CryptoLib/src/Crypto/Paddings/ClpISO7816d4Padding.pas

@@ -0,0 +1,86 @@
+{ *********************************************************************************** }
+{ *                              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 ClpISO7816d4Padding;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding,
+  ClpIISO7816d4Padding,
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SCorruptedPadBlock = 'Pad Block Corrupted';
+
+type
+  TISO7816d4Padding = class sealed(TInterfacedObject, IISO7816d4Padding,
+    IBlockCipherPadding)
+  strict private
+    function GetPaddingName: String; inline;
+  public
+    procedure Init(const ARandom: ISecureRandom);
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
+    property PaddingName: String read GetPaddingName;
+  end;
+
+implementation
+
+function TISO7816d4Padding.AddPadding(const AInput: TCryptoLibByteArray;
+  AInOff: Int32): Int32;
+var
+  LAdded: Int32;
+begin
+  LAdded := (System.Length(AInput) - AInOff);
+  AInput[AInOff] := Byte($80);
+  System.Inc(AInOff);
+  while (AInOff < System.Length(AInput)) do
+  begin
+    AInput[AInOff] := Byte(0);
+    System.Inc(AInOff);
+  end;
+  Result := LAdded;
+end;
+
+function TISO7816d4Padding.GetPaddingName: String;
+begin
+  Result := 'ISO7816-4';
+end;
+
+{$IFNDEF _FIXINSIGHT_}
+procedure TISO7816d4Padding.Init(const ARandom: ISecureRandom);
+begin
+end;
+{$ENDIF}
+
+function TISO7816d4Padding.PadCount(const AInput: TCryptoLibByteArray): Int32;
+var
+  LCount: Int32;
+begin
+  LCount := System.Length(AInput) - 1;
+  while ((LCount > 0) and (AInput[LCount] = 0)) do
+    System.Dec(LCount);
+  if (AInput[LCount] <> Byte($80)) then
+    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
+  Result := System.Length(AInput) - LCount;
+end;
+
+end.

+ 119 - 109
CryptoLib/src/Crypto/Paddings/ClpPaddedBufferedBlockCipher.pas

@@ -26,8 +26,18 @@ uses
   Math,
   ClpCheck,
   ClpIBlockCipher,
-  ClpPaddingModes,
-  ClpIPaddingModes,
+  ClpISO10126d2Padding,
+  ClpIISO10126d2Padding,
+  ClpISO7816d4Padding,
+  ClpIISO7816d4Padding,
+  ClpPkcs7Padding,
+  ClpIPkcs7Padding,
+  ClpTBCPadding,
+  ClpITBCPadding,
+  ClpX923Padding,
+  ClpIX923Padding,
+  ClpZeroBytePadding,
+  ClpIZeroBytePadding,
   ClpBufferedBlockCipher,
   ClpIPaddedBufferedBlockCipher,
   ClpIBlockCipherPadding,
@@ -59,7 +69,7 @@ type
     IPaddedBufferedBlockCipher)
 
   strict private
-    Fpadding: IBlockCipherPadding;
+    FPadding: IBlockCipherPadding;
 
   public
 
@@ -72,16 +82,16 @@ type
     /// <param name="padding">
     /// the padding type.
     /// </param>
-    constructor Create(const cipher: IBlockCipher;
-      const padding: IBlockCipherPadding); overload;
+    constructor Create(const ACipher: IBlockCipher;
+      const APadding: IBlockCipherPadding); overload;
 
     /// <summary>
     /// Create a buffered block cipher Pkcs7 padding
     /// </summary>
-    /// <param name="cipher">
+    /// <param name="ACipher">
     /// the underlying block cipher this buffering object wraps.
     /// </param>
-    constructor Create(const cipher: IBlockCipher); overload;
+    constructor Create(const ACipher: IBlockCipher); overload;
 
     /// <summary>
     /// initialise the cipher.
@@ -96,8 +106,8 @@ type
     /// <exception cref="EArgumentCryptoLibException">
     /// if the parameters argument is inappropriate.
     /// </exception>
-    procedure Init(forEncryption: Boolean;
-      const parameters: ICipherParameters); override;
+    procedure Init(AForEncryption: Boolean;
+      const AParameters: ICipherParameters); override;
 
     /// <summary>
     /// return the minimum size of the output buffer required for an update
@@ -110,7 +120,7 @@ type
     /// the space required to accommodate a call to update and doFinal with
     /// len bytes of input.
     /// </returns>
-    function GetOutputSize(length: Int32): Int32; override;
+    function GetOutputSize(ALength: Int32): Int32; override;
 
     /// <summary>
     /// return the size of the output buffer required for an update an input
@@ -123,7 +133,7 @@ type
     /// the space required to accommodate a call to update with length bytes
     /// of input.
     /// </returns>
-    function GetUpdateOutputSize(length: Int32): Int32; override;
+    function GetUpdateOutputSize(ALength: Int32): Int32; override;
 
     /// <summary>
     /// process a single byte, producing an output block if necessary.
@@ -146,8 +156,8 @@ type
     /// <exception cref="EInvalidOperationCryptoLibException">
     /// if the cipher isn't initialised.
     /// </exception>
-    function ProcessByte(input: Byte; const output: TCryptoLibByteArray;
-      outOff: Int32): Int32; override;
+    function ProcessByte(AInput: Byte; const AOutput: TCryptoLibByteArray;
+      AOutOff: Int32): Int32; override;
 
     /// <summary>
     /// process an array of bytes, producing output if necessary.
@@ -176,8 +186,8 @@ type
     /// <exception cref="EInvalidOperationCryptoLibException">
     /// if the cipher isn't initialised.
     /// </exception>
-    function ProcessBytes(const input: TCryptoLibByteArray;
-      inOff, length: Int32; const output: TCryptoLibByteArray; outOff: Int32)
+    function ProcessBytes(const AInput: TCryptoLibByteArray;
+      AInOff, ALength: Int32; const AOutput: TCryptoLibByteArray; AOutOff: Int32)
       : Int32; override;
 
     /// <summary>
@@ -204,7 +214,7 @@ type
     /// <exception cref="EInvalidCipherTextCryptoLibException">
     /// if padding is expected and not found.
     /// </exception>
-    function DoFinal(const output: TCryptoLibByteArray; outOff: Int32)
+    function DoFinal(const AOutput: TCryptoLibByteArray; AOutOff: Int32)
       : Int32; override;
 
   end;
@@ -213,58 +223,58 @@ implementation
 
 { TPaddedBufferedBlockCipher }
 
-constructor TPaddedBufferedBlockCipher.Create(const cipher: IBlockCipher;
-  const padding: IBlockCipherPadding);
+constructor TPaddedBufferedBlockCipher.Create(const ACipher: IBlockCipher;
+  const APadding: IBlockCipherPadding);
 begin
   Inherited Create();
-  Fcipher := cipher;
-  Fpadding := padding;
+  FCipher := ACipher;
+  FPadding := APadding;
 
-  System.SetLength(Fbuf, cipher.GetBlockSize());
-  FbufOff := 0;
+  System.SetLength(FBuf, ACipher.GetBlockSize());
+  FBufOff := 0;
 end;
 
-constructor TPaddedBufferedBlockCipher.Create(const cipher: IBlockCipher);
+constructor TPaddedBufferedBlockCipher.Create(const ACipher: IBlockCipher);
 begin
-  Create(cipher, TPkcs7Padding.Create() as IPkcs7Padding);
+  Create(ACipher, TPkcs7Padding.Create() as IPkcs7Padding);
 end;
 
-function TPaddedBufferedBlockCipher.DoFinal(const output: TCryptoLibByteArray;
-  outOff: Int32): Int32;
+function TPaddedBufferedBlockCipher.DoFinal(const AOutput: TCryptoLibByteArray;
+  AOutOff: Int32): Int32;
 var
-  blockSize, resultLen, resultTotalLen: Int32;
+  LBlockSize, LResultLen, LResultTotalLen: Int32;
 begin
-  blockSize := Fcipher.GetBlockSize();
-  resultLen := 0;
+  LBlockSize := FCipher.GetBlockSize();
+  LResultLen := 0;
 
-  if (FforEncryption) then
+  if (FForEncryption) then
   begin
-    if (FbufOff = blockSize) then
+    if (FBufOff = LBlockSize) then
     begin
-      if ((outOff + 2 * blockSize) > System.length(output)) then
+      if ((AOutOff + 2 * LBlockSize) > System.Length(AOutput)) then
       begin
         Reset();
 
         raise EOutputLengthCryptoLibException.CreateRes(@SOutputBufferTooSmall);
       end;
 
-      resultLen := Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
-      FbufOff := 0;
+      LResultLen := FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
+      FBufOff := 0;
     end;
 
-    Fpadding.AddPadding(Fbuf, FbufOff);
+    FPadding.AddPadding(FBuf, FBufOff);
 
-    resultLen := resultLen + Fcipher.ProcessBlock(Fbuf, 0, output,
-      outOff + resultLen);
+    LResultLen := LResultLen + FCipher.ProcessBlock(FBuf, 0, AOutput,
+      AOutOff + LResultLen);
 
     Reset();
   end
   else
   begin
-    if (FbufOff = blockSize) then
+    if (FBufOff = LBlockSize) then
     begin
-      resultLen := Fcipher.ProcessBlock(Fbuf, 0, Fbuf, 0);
-      FbufOff := 0;
+      LResultLen := FCipher.ProcessBlock(FBuf, 0, FBuf, 0);
+      FBufOff := 0;
     end
     else
     begin
@@ -275,11 +285,11 @@ begin
     end;
 
     try
-      resultLen := resultLen - Fpadding.PadCount(Fbuf);
-      resultTotalLen := resultLen * System.SizeOf(Byte);
-      if resultTotalLen > 0 then
+      LResultLen := LResultLen - FPadding.PadCount(FBuf);
+      LResultTotalLen := LResultLen * System.SizeOf(Byte);
+      if LResultTotalLen > 0 then
       begin
-        System.Move(Fbuf[0], output[outOff], resultTotalLen);
+        System.Move(FBuf[0], AOutput[AOutOff], LResultTotalLen);
       end;
 
     finally
@@ -288,135 +298,135 @@ begin
 
   end;
 
-  result := resultLen;
+  Result := LResultLen;
 end;
 
-function TPaddedBufferedBlockCipher.GetOutputSize(length: Int32): Int32;
+function TPaddedBufferedBlockCipher.GetOutputSize(ALength: Int32): Int32;
 var
-  total, leftOver: Int32;
+  LTotal, LLeftOver: Int32;
 begin
-  total := length + FbufOff;
-  leftOver := total mod System.length(Fbuf);
+  LTotal := ALength + FBufOff;
+  LLeftOver := LTotal mod System.Length(FBuf);
 
-  if (leftOver = 0) then
+  if (LLeftOver = 0) then
   begin
-    if (FforEncryption) then
+    if (FForEncryption) then
     begin
-      result := total + System.length(Fbuf);
+      Result := LTotal + System.Length(FBuf);
       Exit;
     end;
 
-    result := total;
+    Result := LTotal;
     Exit;
   end;
 
-  result := total - leftOver + System.length(Fbuf);
+  Result := LTotal - LLeftOver + System.Length(FBuf);
 end;
 
-function TPaddedBufferedBlockCipher.GetUpdateOutputSize(length: Int32): Int32;
+function TPaddedBufferedBlockCipher.GetUpdateOutputSize(ALength: Int32): Int32;
 var
-  total, leftOver: Int32;
+  LTotal, LLeftOver: Int32;
 begin
-  total := length + FbufOff;
-  leftOver := total mod System.length(Fbuf);
+  LTotal := ALength + FBufOff;
+  LLeftOver := LTotal mod System.Length(FBuf);
 
-  if (leftOver = 0) then
+  if (LLeftOver = 0) then
   begin
-    result := Max(0, total - System.length(Fbuf));
+    Result := Max(0, LTotal - System.Length(FBuf));
     Exit;
   end;
 
-  result := total - leftOver;
+  Result := LTotal - LLeftOver;
 end;
 
-procedure TPaddedBufferedBlockCipher.Init(forEncryption: Boolean;
-  const parameters: ICipherParameters);
+procedure TPaddedBufferedBlockCipher.Init(AForEncryption: Boolean;
+  const AParameters: ICipherParameters);
 var
-  initRandom: ISecureRandom;
-  Lparameters: ICipherParameters;
-  p: IParametersWithRandom;
+  LInitRandom: ISecureRandom;
+  LParameters: ICipherParameters;
+  LP: IParametersWithRandom;
 begin
-  FforEncryption := forEncryption;
-  Lparameters := parameters;
-  initRandom := Nil;
+  FForEncryption := AForEncryption;
+  LParameters := AParameters;
+  LInitRandom := nil;
 
-  if Supports(Lparameters, IParametersWithRandom, p) then
+  if Supports(LParameters, IParametersWithRandom, LP) then
   begin
-    initRandom := p.Random;
-    Lparameters := p.parameters;
+    LInitRandom := LP.Random;
+    LParameters := LP.Parameters;
   end;
 
   Reset();
-  Fpadding.Init(initRandom);
-  Fcipher.Init(forEncryption, Lparameters);
+  FPadding.Init(LInitRandom);
+  FCipher.Init(AForEncryption, LParameters);
 end;
 
-function TPaddedBufferedBlockCipher.ProcessByte(input: Byte;
-  const output: TCryptoLibByteArray; outOff: Int32): Int32;
+function TPaddedBufferedBlockCipher.ProcessByte(AInput: Byte;
+  const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
 var
-  resultLen: Int32;
+  LResultLen: Int32;
 begin
-  resultLen := 0;
+  LResultLen := 0;
 
-  if (FbufOff = System.length(Fbuf)) then
+  if (FBufOff = System.Length(FBuf)) then
   begin
-    resultLen := Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
-    FbufOff := 0;
+    LResultLen := FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
+    FBufOff := 0;
   end;
 
-  Fbuf[FbufOff] := input;
-  System.Inc(FbufOff);
+  FBuf[FBufOff] := AInput;
+  System.Inc(FBufOff);
 
-  result := resultLen;
+  Result := LResultLen;
 end;
 
-function TPaddedBufferedBlockCipher.ProcessBytes(const input
-  : TCryptoLibByteArray; inOff, length: Int32;
-  const output: TCryptoLibByteArray; outOff: Int32): Int32;
+function TPaddedBufferedBlockCipher.ProcessBytes(const AInput
+  : TCryptoLibByteArray; AInOff, ALength: Int32;
+  const AOutput: TCryptoLibByteArray; AOutOff: Int32): Int32;
 var
-  blockSize, outLength, resultLen, gapLen: Int32;
+  LBlockSize, LOutLength, LResultLen, LGapLen: Int32;
 begin
-  if (length < 0) then
+  if (ALength < 0) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SNegativeInputLength);
   end;
 
-  blockSize := GetBlockSize();
-  outLength := GetUpdateOutputSize(length);
+  LBlockSize := GetBlockSize();
+  LOutLength := GetUpdateOutputSize(ALength);
 
-  if (outLength > 0) then
+  if (LOutLength > 0) then
   begin
-    TCheck.OutputLength(output, outOff, outLength, SOutputBufferTooSmall);
+    TCheck.OutputLength(AOutput, AOutOff, LOutLength, SOutputBufferTooSmall);
   end;
 
-  resultLen := 0;
-  gapLen := System.length(Fbuf) - FbufOff;
+  LResultLen := 0;
+  LGapLen := System.Length(FBuf) - FBufOff;
 
-  if (length > gapLen) then
+  if (ALength > LGapLen) then
   begin
-    System.Move(input[inOff], Fbuf[FbufOff], gapLen * System.SizeOf(Byte));
+    System.Move(AInput[AInOff], FBuf[FBufOff], LGapLen * System.SizeOf(Byte));
 
-    resultLen := resultLen + Fcipher.ProcessBlock(Fbuf, 0, output, outOff);
+    LResultLen := LResultLen + FCipher.ProcessBlock(FBuf, 0, AOutput, AOutOff);
 
-    FbufOff := 0;
-    length := length - gapLen;
-    inOff := inOff + gapLen;
+    FBufOff := 0;
+    ALength := ALength - LGapLen;
+    AInOff := AInOff + LGapLen;
 
-    while (length > System.length(Fbuf)) do
+    while (ALength > System.Length(FBuf)) do
     begin
-      resultLen := resultLen + Fcipher.ProcessBlock(input, inOff, output,
-        outOff + resultLen);
+      LResultLen := LResultLen + FCipher.ProcessBlock(AInput, AInOff, AOutput,
+        AOutOff + LResultLen);
 
-      length := length - blockSize;
-      inOff := inOff + blockSize;
+      ALength := ALength - LBlockSize;
+      AInOff := AInOff + LBlockSize;
     end;
   end;
 
-  System.Move(input[inOff], Fbuf[FbufOff], length * System.SizeOf(Byte));
+  System.Move(AInput[AInOff], FBuf[FBufOff], ALength * System.SizeOf(Byte));
 
-  FbufOff := FbufOff + length;
+  FBufOff := FBufOff + ALength;
 
-  result := resultLen;
+  Result := LResultLen;
 end;
 
 end.

+ 0 - 734
CryptoLib/src/Crypto/Paddings/ClpPaddingModes.pas

@@ -1,734 +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 ClpPaddingModes;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIBlockCipherPadding,
-  ClpSecureRandom,
-  ClpISecureRandom,
-  ClpCryptoLibTypes,
-  ClpIPaddingModes;
-
-resourcestring
-  SCorruptedPadBlock = 'Pad Block Corrupted';
-
-type
-
-  /// <summary>
-  /// A padder that adds ISO10126-2 padding to a block.
-  /// </summary>
-  TISO10126d2Padding = class sealed(TInterfacedObject, IISO10126d2Padding,
-    IBlockCipherPadding)
-
-  strict private
-
-  var
-    FRandom: ISecureRandom;
-    /// <returns>
-    /// return the name of the algorithm the cipher implements.
-    /// </returns>
-    function GetPaddingName: String; inline;
-
-  public
-    /// <summary>
-    /// Initialise the padder.
-    /// </summary>
-    /// <param name="random">
-    /// a SecureRandom if available.
-    /// </param>
-    procedure Init(const random: ISecureRandom);
-
-    /// <summary>
-    /// Return the name of the algorithm the cipher implements.
-    /// </summary>
-    property PaddingName: String read GetPaddingName;
-
-    /// <summary>
-    /// add the pad bytes to the passed in block, returning the number of
-    /// bytes added.
-    /// </summary>
-    /// <param name="input">
-    /// input block to pad
-    /// </param>
-    /// <param name="inOff">
-    /// offset to start the padding from in the block
-    /// </param>
-    /// <returns>
-    /// returns number of bytes added
-    /// </returns>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
-
-    /// <summary>
-    /// return the number of pad bytes present in the block.
-    /// </summary>
-    /// <param name="input">
-    /// block to count pad bytes in
-    /// </param>
-    /// <returns>
-    /// the number of pad bytes present in the block.
-    /// </returns>
-    /// <exception cref="EInvalidCipherTextCryptoLibException">
-    /// if the padding is badly formed or invalid.
-    /// </exception>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
-
-  end;
-
-type
-
-  /// <summary>
-  /// A padder that adds the padding according to the scheme referenced in
-  /// ISO 7814-4 - scheme 2 from ISO 9797-1. The first byte is $80, rest is $00
-  /// </summary>
-  TISO7816d4Padding = class sealed(TInterfacedObject, IISO7816d4Padding,
-    IBlockCipherPadding)
-
-  strict private
-    /// <returns>
-    /// return the name of the algorithm the cipher implements.
-    /// </returns>
-    function GetPaddingName: String; inline;
-
-  public
-    /// <summary>
-    /// Initialise the padder.
-    /// </summary>
-    /// <param name="random">
-    /// a SecureRandom if available.
-    /// </param>
-    procedure Init(const random: ISecureRandom);
-
-    /// <summary>
-    /// Return the name of the algorithm the cipher implements.
-    /// </summary>
-    property PaddingName: String read GetPaddingName;
-
-    /// <summary>
-    /// add the pad bytes to the passed in block, returning the number of
-    /// bytes added.
-    /// </summary>
-    /// <param name="input">
-    /// input block to pad
-    /// </param>
-    /// <param name="inOff">
-    /// offset to start the padding from in the block
-    /// </param>
-    /// <returns>
-    /// returns number of bytes added
-    /// </returns>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
-
-    /// <summary>
-    /// return the number of pad bytes present in the block.
-    /// </summary>
-    /// <param name="input">
-    /// block to count pad bytes in
-    /// </param>
-    /// <returns>
-    /// the number of pad bytes present in the block.
-    /// </returns>
-    /// <exception cref="EInvalidCipherTextCryptoLibException">
-    /// if the padding is badly formed or invalid.
-    /// </exception>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
-
-  end;
-
-type
-  TPkcs7Padding = class sealed(TInterfacedObject, IPkcs7Padding,
-    IBlockCipherPadding)
-
-  strict private
-
-    /// <returns>
-    /// return the name of the algorithm the cipher implements.
-    /// </returns>
-    function GetPaddingName: String; inline;
-
-  public
-    /// <summary>
-    /// Initialise the padder.
-    /// </summary>
-    /// <param name="random">
-    /// a SecureRandom if available.
-    /// </param>
-    procedure Init(const random: ISecureRandom);
-
-    /// <summary>
-    /// Return the name of the algorithm the cipher implements.
-    /// </summary>
-    property PaddingName: String read GetPaddingName;
-
-    /// <summary>
-    /// add the pad bytes to the passed in block, returning the number of
-    /// bytes added.
-    /// </summary>
-    /// <param name="input">
-    /// input block to pad
-    /// </param>
-    /// <param name="inOff">
-    /// offset to start the padding from in the block
-    /// </param>
-    /// <returns>
-    /// returns number of bytes added
-    /// </returns>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
-
-    /// <summary>
-    /// return the number of pad bytes present in the block.
-    /// </summary>
-    /// <param name="input">
-    /// block to count pad bytes in
-    /// </param>
-    /// <returns>
-    /// the number of pad bytes present in the block.
-    /// </returns>
-    /// <exception cref="EInvalidCipherTextCryptoLibException">
-    /// if the padding is badly formed or invalid.
-    /// </exception>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
-
-  end;
-
-type
-
-  /// <summary> A padder that adds Trailing-Bit-Compliment padding to a block.
-  /// <p>
-  /// This padding pads the block out compliment of the last bit
-  /// of the plain text.
-  /// </p>
-  /// </summary>
-  TTBCPadding = class sealed(TInterfacedObject, ITBCPadding,
-    IBlockCipherPadding)
-
-  strict private
-    /// <returns>
-    /// return the name of the algorithm the cipher implements.
-    /// </returns>
-    function GetPaddingName: String; inline;
-
-  public
-    /// <summary>
-    /// Initialise the padder.
-    /// </summary>
-    /// <param name="random">
-    /// a SecureRandom if available.
-    /// </param>
-    procedure Init(const random: ISecureRandom);
-
-    /// <summary>
-    /// Return the name of the algorithm the cipher implements.
-    /// </summary>
-    property PaddingName: String read GetPaddingName;
-
-    /// <summary> add the pad bytes to the passed in block, returning the
-    /// number of bytes added.
-    /// <p>
-    /// Note: this assumes that the last block of plain text is always
-    /// passed to it inside in. i.e. if inOff is zero, indicating the
-    /// entire block is to be overwritten with padding the value of in
-    /// should be the same as the last block of plain text.
-    /// </p>
-    /// </summary>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
-
-    /// <summary>
-    /// return the number of pad bytes present in the block.
-    /// </summary>
-    /// <param name="input">
-    /// block to count pad bytes in
-    /// </param>
-    /// <returns>
-    /// the number of pad bytes present in the block.
-    /// </returns>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
-
-  end;
-
-type
-
-  /// <summary>
-  /// A padder that adds X9.23 padding to a block - if a SecureRandom is
-  /// passed in random padding is assumed, otherwise padding with zeros is
-  /// used.
-  /// </summary>
-  TX923Padding = class sealed(TInterfacedObject, IX923Padding,
-    IBlockCipherPadding)
-
-  strict private
-  var
-    FRandom: ISecureRandom;
-
-    /// <returns>
-    /// return the name of the algorithm the cipher implements.
-    /// </returns>
-    function GetPaddingName: String; inline;
-
-  public
-    /// <summary>
-    /// Initialise the padder.
-    /// </summary>
-    /// <param name="random">
-    /// a SecureRandom if available.
-    /// </param>
-    procedure Init(const random: ISecureRandom);
-
-    /// <summary>
-    /// Return the name of the algorithm the cipher implements.
-    /// </summary>
-    property PaddingName: String read GetPaddingName;
-
-    /// <summary>
-    /// add the pad bytes to the passed in block, returning the number of
-    /// bytes added.
-    /// </summary>
-    /// <param name="input">
-    /// input block to pad
-    /// </param>
-    /// <param name="inOff">
-    /// offset to start the padding from in the block
-    /// </param>
-    /// <returns>
-    /// returns number of bytes added
-    /// </returns>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
-
-    /// <summary>
-    /// return the number of pad bytes present in the block.
-    /// </summary>
-    /// <param name="input">
-    /// block to count pad bytes in
-    /// </param>
-    /// <returns>
-    /// the number of pad bytes present in the block.
-    /// </returns>
-    /// <exception cref="EInvalidCipherTextCryptoLibException">
-    /// if the padding is badly formed or invalid.
-    /// </exception>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
-
-  end;
-
-type
-
-  /// <summary>
-  /// A padder that adds Null byte padding to a block.
-  /// </summary>
-  TZeroBytePadding = class sealed(TInterfacedObject, IZeroBytePadding,
-    IBlockCipherPadding)
-
-  strict private
-
-    /// <returns>
-    /// return the name of the algorithm the cipher implements.
-    /// </returns>
-    function GetPaddingName: String; inline;
-
-  public
-    /// <summary>
-    /// Initialise the padder.
-    /// </summary>
-    /// <param name="random">
-    /// a SecureRandom if available.
-    /// </param>
-    procedure Init(const random: ISecureRandom);
-
-    /// <summary>
-    /// Return the name of the algorithm the cipher implements.
-    /// </summary>
-    property PaddingName: String read GetPaddingName;
-
-    /// <summary>
-    /// add the pad bytes to the passed in block, returning the number of
-    /// bytes added.
-    /// </summary>
-    /// <param name="input">
-    /// input block to pad
-    /// </param>
-    /// <param name="inOff">
-    /// offset to start the padding from in the block
-    /// </param>
-    /// <returns>
-    /// returns number of bytes added
-    /// </returns>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
-
-    /// <summary>
-    /// return the number of pad bytes present in the block.
-    /// </summary>
-    /// <param name="input">
-    /// block to count pad bytes in
-    /// </param>
-    /// <returns>
-    /// the number of pad bytes present in the block.
-    /// </returns>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
-
-  end;
-
-implementation
-
-{ TISO10126d2Padding }
-
-function TISO10126d2Padding.AddPadding(const input: TCryptoLibByteArray;
-  inOff: Int32): Int32;
-var
-  code: Byte;
-begin
-  code := Byte(System.Length(input) - inOff);
-
-  while (inOff < (System.Length(input) - 1)) do
-  begin
-    input[inOff] := Byte(FRandom.NextInt32);
-    System.Inc(inOff);
-  end;
-
-  input[inOff] := code;
-
-  result := code;
-end;
-
-function TISO10126d2Padding.GetPaddingName: String;
-begin
-  result := 'ISO10126-2';
-end;
-
-procedure TISO10126d2Padding.Init(const random: ISecureRandom);
-begin
-  if random <> Nil then
-  begin
-    FRandom := random;
-  end
-  else
-  begin
-    FRandom := TSecureRandom.Create();
-  end;
-end;
-
-function TISO10126d2Padding.PadCount(const input: TCryptoLibByteArray): Int32;
-var
-  count: Int32;
-begin
-
-  count := input[System.Length(input) - 1] and $FF;
-
-  if (count > System.Length(input)) then
-  begin
-    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
-  end;
-
-  result := count;
-
-end;
-
-{ TISO7816d4Padding }
-
-function TISO7816d4Padding.AddPadding(const input: TCryptoLibByteArray;
-  inOff: Int32): Int32;
-var
-  added: Int32;
-begin
-  added := (System.Length(input) - inOff);
-
-  input[inOff] := Byte($80);
-  System.Inc(inOff);
-
-  while (inOff < System.Length(input)) do
-  begin
-    input[inOff] := Byte(0);
-    System.Inc(inOff);
-  end;
-
-  result := added;
-end;
-
-function TISO7816d4Padding.GetPaddingName: String;
-begin
-  result := 'ISO7816-4';
-end;
-
-{$IFNDEF _FIXINSIGHT_}
-
-procedure TISO7816d4Padding.Init(const random: ISecureRandom);
-begin
-  // nothing to do.
-end;
-{$ENDIF}
-
-function TISO7816d4Padding.PadCount(const input: TCryptoLibByteArray): Int32;
-var
-  count: Int32;
-begin
-
-  count := System.Length(input) - 1;
-
-  while ((count > 0) and (input[count] = 0)) do
-  begin
-    System.Dec(count);
-  end;
-
-  if (input[count] <> Byte($80)) then
-  begin
-    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
-  end;
-
-  result := System.Length(input) - count;
-
-end;
-
-{ TPkcs7Padding }
-
-function TPkcs7Padding.AddPadding(const input: TCryptoLibByteArray;
-  inOff: Int32): Int32;
-var
-  code: Byte;
-begin
-  code := Byte(System.Length(input) - inOff);
-
-  while (inOff < System.Length(input)) do
-  begin
-    input[inOff] := code;
-    System.Inc(inOff);
-  end;
-
-  result := code;
-end;
-
-function TPkcs7Padding.GetPaddingName: String;
-begin
-  result := 'PKCS7';
-end;
-
-{$IFNDEF _FIXINSIGHT_}
-
-procedure TPkcs7Padding.Init(const random: ISecureRandom);
-begin
-  // nothing to do.
-end;
-{$ENDIF}
-
-function TPkcs7Padding.PadCount(const input: TCryptoLibByteArray): Int32;
-var
-  countAsByte: Byte;
-  count, i: Int32;
-  failed: Boolean;
-begin
-
-  count := input[System.Length(input) - 1] and $FF;
-  countAsByte := Byte(count);
-
-  // constant time version
-  failed := ((count > System.Length(input)) or (count = 0));
-
-  for i := 0 to System.Pred(System.Length(input)) do
-  begin
-    failed := failed or ((System.Length(input) - i <= count) and
-      (input[i] <> countAsByte));
-  end;
-
-  if (failed) then
-  begin
-    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
-  end;
-
-  result := count;
-
-end;
-
-{ TTBCPadding }
-
-function TTBCPadding.AddPadding(const input: TCryptoLibByteArray;
-  inOff: Int32): Int32;
-var
-  count: Int32;
-  code: Byte;
-begin
-  count := System.Length(input) - inOff;
-
-  if (inOff > 0) then
-  begin
-    if (input[inOff - 1] and $01) = 0 then
-    begin
-      code := Byte($FF)
-    end
-    else
-    begin
-      code := Byte($00)
-    end;
-
-  end
-  else
-  begin
-
-    if (input[System.Length(input) - 1] and $01) = 0 then
-    begin
-      code := Byte($FF)
-    end
-    else
-    begin
-      code := Byte($00)
-    end;
-
-  end;
-
-  while (inOff < System.Length(input)) do
-  begin
-    input[inOff] := code;
-    System.Inc(inOff);
-  end;
-
-  result := count;
-end;
-
-function TTBCPadding.GetPaddingName: String;
-begin
-  result := 'TBC';
-end;
-
-{$IFNDEF _FIXINSIGHT_}
-
-procedure TTBCPadding.Init(const random: ISecureRandom);
-begin
-  // nothing to do.
-end;
-{$ENDIF}
-
-function TTBCPadding.PadCount(const input: TCryptoLibByteArray): Int32;
-var
-  code: Byte;
-  index: Int32;
-begin
-
-  code := input[System.Length(input) - 1];
-
-  index := System.Length(input) - 1;
-  while ((index > 0) and (input[index - 1] = code)) do
-  begin
-    System.Dec(index);
-  end;
-
-  result := System.Length(input) - index;
-
-end;
-
-{ TX923Padding }
-
-function TX923Padding.AddPadding(const input: TCryptoLibByteArray;
-  inOff: Int32): Int32;
-var
-  code: Byte;
-begin
-  code := Byte(System.Length(input) - inOff);
-
-  while (inOff < (System.Length(input) - 1)) do
-  begin
-    if (FRandom = Nil) then
-    begin
-      input[inOff] := 0;
-    end
-    else
-    begin
-      input[inOff] := Byte(FRandom.NextInt32);
-    end;
-    System.Inc(inOff);
-  end;
-
-  input[inOff] := code;
-  result := code;
-end;
-
-function TX923Padding.GetPaddingName: String;
-begin
-  result := 'X9.23';
-end;
-
-procedure TX923Padding.Init(const random: ISecureRandom);
-begin
-  FRandom := random;
-end;
-
-function TX923Padding.PadCount(const input: TCryptoLibByteArray): Int32;
-var
-  count: Int32;
-begin
-
-  count := input[System.Length(input) - 1] and $FF;
-
-  if (count > System.Length(input)) then
-  begin
-    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
-  end;
-
-  result := count;
-
-end;
-
-{ TZeroBytePadding }
-
-function TZeroBytePadding.AddPadding(const input: TCryptoLibByteArray;
-  inOff: Int32): Int32;
-var
-  added: Int32;
-begin
-  added := System.Length(input) - inOff;
-
-  while (inOff < System.Length(input)) do
-  begin
-    input[inOff] := Byte(0);
-    System.Inc(inOff);
-  end;
-
-  result := added;
-end;
-
-function TZeroBytePadding.GetPaddingName: String;
-begin
-  result := 'ZeroBytePadding';
-end;
-
-{$IFNDEF _FIXINSIGHT_}
-
-procedure TZeroBytePadding.Init(const random: ISecureRandom);
-begin
-  // nothing to do.
-end;
-{$ENDIF}
-
-function TZeroBytePadding.PadCount(const input: TCryptoLibByteArray): Int32;
-var
-  count: Int32;
-begin
-  count := System.Length(input);
-  while (count > 0) do
-  begin
-    if (input[count - 1] <> 0) then
-    begin
-      break;
-    end;
-
-    System.Dec(count);
-  end;
-
-  result := System.Length(input) - count;
-end;
-
-end.

+ 89 - 0
CryptoLib/src/Crypto/Paddings/ClpPkcs7Padding.pas

@@ -0,0 +1,89 @@
+{ *********************************************************************************** }
+{ *                              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 ClpPkcs7Padding;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding,
+  ClpIPkcs7Padding,
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SCorruptedPadBlock = 'Pad Block Corrupted';
+
+type
+  TPkcs7Padding = class sealed(TInterfacedObject, IPkcs7Padding,
+    IBlockCipherPadding)
+  strict private
+    function GetPaddingName: String; inline;
+  public
+    procedure Init(const ARandom: ISecureRandom);
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
+    property PaddingName: String read GetPaddingName;
+  end;
+
+implementation
+
+function TPkcs7Padding.AddPadding(const AInput: TCryptoLibByteArray;
+  AInOff: Int32): Int32;
+var
+  LCode: Byte;
+begin
+  LCode := Byte(System.Length(AInput) - AInOff);
+  while (AInOff < System.Length(AInput)) do
+  begin
+    AInput[AInOff] := LCode;
+    System.Inc(AInOff);
+  end;
+  Result := LCode;
+end;
+
+function TPkcs7Padding.GetPaddingName: String;
+begin
+  Result := 'PKCS7';
+end;
+
+{$IFNDEF _FIXINSIGHT_}
+procedure TPkcs7Padding.Init(const ARandom: ISecureRandom);
+begin
+end;
+{$ENDIF}
+
+function TPkcs7Padding.PadCount(const AInput: TCryptoLibByteArray): Int32;
+var
+  LCountAsByte: Byte;
+  LCount, LI: Int32;
+  LFailed: Boolean;
+begin
+  LCount := AInput[System.Length(AInput) - 1] and $FF;
+  LCountAsByte := Byte(LCount);
+  LFailed := ((LCount > System.Length(AInput)) or (LCount = 0));
+  for LI := 0 to System.Pred(System.Length(AInput)) do
+    LFailed := LFailed or ((System.Length(AInput) - LI <= LCount) and
+      (AInput[LI] <> LCountAsByte));
+  if (LFailed) then
+    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
+  Result := LCount;
+end;
+
+end.

+ 96 - 0
CryptoLib/src/Crypto/Paddings/ClpTBCPadding.pas

@@ -0,0 +1,96 @@
+{ *********************************************************************************** }
+{ *                              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 ClpTBCPadding;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding,
+  ClpITBCPadding,
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
+
+type
+  TTBCPadding = class sealed(TInterfacedObject, ITBCPadding,
+    IBlockCipherPadding)
+  strict private
+    function GetPaddingName: String; inline;
+  public
+    procedure Init(const ARandom: ISecureRandom);
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
+    property PaddingName: String read GetPaddingName;
+  end;
+
+implementation
+
+function TTBCPadding.AddPadding(const AInput: TCryptoLibByteArray;
+  AInOff: Int32): Int32;
+var
+  LCount: Int32;
+  LCode: Byte;
+begin
+  LCount := System.Length(AInput) - AInOff;
+  if (AInOff > 0) then
+  begin
+    if (AInput[AInOff - 1] and $01) = 0 then
+      LCode := Byte($FF)
+    else
+      LCode := Byte($00);
+  end
+  else
+  begin
+    if (AInput[System.Length(AInput) - 1] and $01) = 0 then
+      LCode := Byte($FF)
+    else
+      LCode := Byte($00);
+  end;
+  while (AInOff < System.Length(AInput)) do
+  begin
+    AInput[AInOff] := LCode;
+    System.Inc(AInOff);
+  end;
+  Result := LCount;
+end;
+
+function TTBCPadding.GetPaddingName: String;
+begin
+  Result := 'TBC';
+end;
+
+{$IFNDEF _FIXINSIGHT_}
+procedure TTBCPadding.Init(const ARandom: ISecureRandom);
+begin
+end;
+{$ENDIF}
+
+function TTBCPadding.PadCount(const AInput: TCryptoLibByteArray): Int32;
+var
+  LCode: Byte;
+  LIndex: Int32;
+begin
+  LCode := AInput[System.Length(AInput) - 1];
+  LIndex := System.Length(AInput) - 1;
+  while ((LIndex > 0) and (AInput[LIndex - 1] = LCode)) do
+    System.Dec(LIndex);
+  Result := System.Length(AInput) - LIndex;
+end;
+
+end.

+ 86 - 0
CryptoLib/src/Crypto/Paddings/ClpX923Padding.pas

@@ -0,0 +1,86 @@
+{ *********************************************************************************** }
+{ *                              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 ClpX923Padding;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding,
+  ClpIX923Padding,
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SCorruptedPadBlock = 'Pad Block Corrupted';
+
+type
+  TX923Padding = class sealed(TInterfacedObject, IX923Padding,
+    IBlockCipherPadding)
+  strict private
+    FRandom: ISecureRandom;
+    function GetPaddingName: String; inline;
+  public
+    procedure Init(const ARandom: ISecureRandom);
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
+    property PaddingName: String read GetPaddingName;
+  end;
+
+implementation
+
+function TX923Padding.AddPadding(const AInput: TCryptoLibByteArray;
+  AInOff: Int32): Int32;
+var
+  LCode: Byte;
+begin
+  LCode := Byte(System.Length(AInput) - AInOff);
+  while (AInOff < (System.Length(AInput) - 1)) do
+  begin
+    if (FRandom = nil) then
+      AInput[AInOff] := 0
+    else
+      AInput[AInOff] := Byte(FRandom.NextInt32);
+    System.Inc(AInOff);
+  end;
+  AInput[AInOff] := LCode;
+  Result := LCode;
+end;
+
+function TX923Padding.GetPaddingName: String;
+begin
+  Result := 'X9.23';
+end;
+
+procedure TX923Padding.Init(const ARandom: ISecureRandom);
+begin
+  FRandom := ARandom;
+end;
+
+function TX923Padding.PadCount(const AInput: TCryptoLibByteArray): Int32;
+var
+  LCount: Int32;
+begin
+  LCount := AInput[System.Length(AInput) - 1] and $FF;
+  if (LCount > System.Length(AInput)) then
+    raise EInvalidCipherTextCryptoLibException.CreateRes(@SCorruptedPadBlock);
+  Result := LCount;
+end;
+
+end.

+ 89 - 0
CryptoLib/src/Crypto/Paddings/ClpZeroBytePadding.pas

@@ -0,0 +1,89 @@
+{ *********************************************************************************** }
+{ *                              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 ClpZeroBytePadding;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding,
+  ClpIZeroBytePadding,
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
+
+type
+  TZeroBytePadding = class sealed(TInterfacedObject, IZeroBytePadding,
+    IBlockCipherPadding)
+
+  strict private
+    function GetPaddingName: String; inline;
+
+  public
+    procedure Init(const ARandom: ISecureRandom);
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
+    property PaddingName: String read GetPaddingName;
+  end;
+
+implementation
+
+function TZeroBytePadding.AddPadding(const AInput: TCryptoLibByteArray;
+  AInOff: Int32): Int32;
+var
+  LAdded: Int32;
+begin
+  LAdded := System.Length(AInput) - AInOff;
+
+  while (AInOff < System.Length(AInput)) do
+  begin
+    AInput[AInOff] := Byte(0);
+    System.Inc(AInOff);
+  end;
+
+  Result := LAdded;
+end;
+
+function TZeroBytePadding.GetPaddingName: String;
+begin
+  Result := 'ZeroBytePadding';
+end;
+
+{$IFNDEF _FIXINSIGHT_}
+procedure TZeroBytePadding.Init(const ARandom: ISecureRandom);
+begin
+  // nothing to do.
+end;
+{$ENDIF}
+
+function TZeroBytePadding.PadCount(const AInput: TCryptoLibByteArray): Int32;
+var
+  LCount: Int32;
+begin
+  LCount := System.Length(AInput);
+  while (LCount > 0) do
+  begin
+    if (AInput[LCount - 1] <> 0) then
+      break;
+    System.Dec(LCount);
+  end;
+
+  Result := System.Length(AInput) - LCount;
+end;
+
+end.

+ 1 - 1
CryptoLib/src/Crypto/Parameters/ClpDHKeyParameters.pas

@@ -98,7 +98,7 @@ begin
     Exit;
   end;
 
-  result := parameters.Equals(other.parameters) and (Inherited Equals(other));
+  result := Parameters.Equals(other.Parameters) and (Inherited Equals(other));
 end;
 
 function TDHKeyParameters.GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;

+ 4 - 4
CryptoLib/src/Crypto/Parameters/ClpDsaKeyParameters.pas

@@ -42,7 +42,7 @@ type
     function GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}override;
 
-    property parameters: IDsaParameters read GetParameters;
+    property Parameters: IDsaParameters read GetParameters;
 
   end;
 
@@ -71,7 +71,7 @@ begin
     Exit;
   end;
 
-  result := parameters.Equals(other.parameters) and (Inherited Equals(other));
+  result := Parameters.Equals(other.Parameters) and (Inherited Equals(other));
 end;
 
 function TDsaKeyParameters.GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
@@ -79,9 +79,9 @@ function TDsaKeyParameters.GetHashCode(): {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 begin
   result := Inherited GetHashCode();
 
-  if (parameters <> Nil) then
+  if (Parameters <> Nil) then
   begin
-    result := result xor parameters.GetHashCode();
+    result := result xor Parameters.GetHashCode();
   end;
 
 end;

+ 1 - 1
CryptoLib/src/Crypto/Parameters/ClpECKeyParameters.pas

@@ -138,7 +138,7 @@ begin
     result := false;
     Exit;
   end;
-  result := Fparameters.Equals(other.parameters) and (inherited Equals(other));
+  result := Fparameters.Equals(other.Parameters) and (inherited Equals(other));
 end;
 
 function TECKeyParameters.GetAlgorithmName: String;

+ 5 - 2
CryptoLib/src/Crypto/Signers/ClpDsaDigestSigner.pas

@@ -29,11 +29,14 @@ uses
   ClpBigInteger,
   ClpCryptoLibTypes,
   ClpParameterUtilities,
-  ClpSignersEncodings,
+  ClpStandardDsaEncoding,
+  ClpPlainDsaEncoding,
+  ClpIDsaEncoding,
+  ClpIStandardDsaEncoding,
+  ClpIPlainDsaEncoding,
   ClpIAsymmetricKeyParameter,
   ClpICipherParameters,
   ClpISigner,
-  ClpISignersEncodings,
   ClpIDsaDigestSigner;
 
 resourcestring

+ 5 - 1
CryptoLib/src/Crypto/Signers/ClpSignerUtilities.pas

@@ -60,7 +60,11 @@ uses
   ClpISigner,
   ClpISecureRandom,
   ClpIAsn1Objects,
-  ClpSignersEncodings,
+  ClpStandardDsaEncoding,
+  ClpPlainDsaEncoding,
+  ClpIDsaEncoding,
+  ClpIStandardDsaEncoding,
+  ClpIPlainDsaEncoding,
   ClpRsaDigestSigner,
   ClpPssSigner,
   ClpGenericSigner,

+ 6 - 110
CryptoLib/src/Crypto/Signers/SignerEncodings/ClpSignersEncodings.pas → CryptoLib/src/Crypto/Signers/SignerEncodings/ClpPlainDsaEncoding.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpSignersEncodings;
+unit ClpPlainDsaEncoding;
 
 {$I ..\..\..\Include\CryptoLib.inc}
 
@@ -23,57 +23,25 @@ interface
 
 uses
   Math,
-  ClpAsn1Objects,
   ClpBigInteger,
-  ClpAsn1Core,
-  ClpISignersEncodings,
+  ClpIDsaEncoding,
+  ClpIPlainDsaEncoding,
   ClpIAsn1Objects,
   ClpArrayUtilities,
   ClpBigIntegers,
   ClpCryptoLibTypes;
 
 resourcestring
-  SMalformedSignature = 'Malformed signature, "%s"';
   SValueOutOfRange = 'Value out of range, "%s"';
   SInvalidEncodingLength = 'Encoding has incorrect length, "%s"';
 
-type
-  TStandardDsaEncoding = class(TInterfacedObject, IDsaEncoding,
-    IStandardDsaEncoding)
-
-  strict private
-
-    class function GetInstance: IStandardDsaEncoding; static; inline;
-
-  strict protected
-
-    function CheckValue(const AN, AX: TBigInteger): TBigInteger; virtual;
-    function DecodeValue(const AN: TBigInteger; const &AS: IAsn1Sequence;
-      APos: Int32): TBigInteger; virtual;
-    function EncodeValue(const AN, AX: TBigInteger): IDerInteger; virtual;
-
-  public
-
-    function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
-      : TCryptoLibGenericArray<TBigInteger>; virtual;
-
-    function Encode(const AN, AR, &AS: TBigInteger): TCryptoLibByteArray; virtual;
-
-    function GetMaxEncodingSize(const AN: TBigInteger): Int32; virtual;
-
-    class property Instance: IStandardDsaEncoding read GetInstance;
-
-  end;
-
 type
   TPlainDsaEncoding = class(TInterfacedObject, IDsaEncoding, IPlainDsaEncoding)
 
   strict private
-
     class function GetInstance: IPlainDsaEncoding; static; inline;
 
   strict protected
-
     function CheckValue(const AN, AX: TBigInteger): TBigInteger; virtual;
     function DecodeValue(const AN: TBigInteger; const ABuf: TCryptoLibByteArray;
       AOff, ALength: Int32): TBigInteger; virtual;
@@ -81,7 +49,6 @@ type
       const ABuf: TCryptoLibByteArray; AOff, ALength: Int32); virtual;
 
   public
-
     function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
       : TCryptoLibGenericArray<TBigInteger>; virtual;
 
@@ -95,79 +62,10 @@ type
 
 implementation
 
-{ TStandardDsaEncoding }
-
-function TStandardDsaEncoding.CheckValue(const AN, AX: TBigInteger): TBigInteger;
-begin
-  if ((AX.SignValue < 0) or ((AN.IsInitialized) and (AX.CompareTo(AN) >= 0))) then
-  begin
-    raise EArgumentCryptoLibException.CreateResFmt(@SValueOutOfRange, ['x']);
-  end;
-  Result := AX;
-end;
-
-function TStandardDsaEncoding.Decode(const AN: TBigInteger;
-  const AEncoding: TCryptoLibByteArray): TCryptoLibGenericArray<TBigInteger>;
-var
-  LSeq: IAsn1Sequence;
-  LR, LS: TBigInteger;
-  LExpectedEncoding: TCryptoLibByteArray;
-begin
-  LSeq := TAsn1Object.FromByteArray(AEncoding) as IAsn1Sequence;
-  if (LSeq.Count = 2) then
-  begin
-    LR := DecodeValue(AN, LSeq, 0);
-    LS := DecodeValue(AN, LSeq, 1);
-    LExpectedEncoding := Encode(AN, LR, LS);
-    if TArrayUtilities.AreEqual<Byte>(LExpectedEncoding, AEncoding) then
-    begin
-      Result := TCryptoLibGenericArray<TBigInteger>.Create(LR, LS);
-      Exit;
-    end;
-  end;
-  raise EArgumentCryptoLibException.CreateResFmt(@SMalformedSignature,
-    ['encoding']);
-end;
-
-function TStandardDsaEncoding.DecodeValue(const AN: TBigInteger;
-  const &AS: IAsn1Sequence; APos: Int32): TBigInteger;
-begin
-  Result := CheckValue(AN, (&AS[APos] as IDerInteger).Value);
-end;
-
-function TStandardDsaEncoding.Encode(const AN, AR, &AS: TBigInteger)
-  : TCryptoLibByteArray;
-var
-  LTemp: IDerSequence;
-begin
-  LTemp := TDerSequence.Create([EncodeValue(AN, AR), EncodeValue(AN, &AS)])
-    as IDerSequence;
-  Result := LTemp.GetEncoded(TAsn1Encodable.Der);
-end;
-
-function TStandardDsaEncoding.EncodeValue(const AN, AX: TBigInteger): IDerInteger;
-begin
-  Result := TDerInteger.Create(CheckValue(AN, AX));
-end;
-
-function TStandardDsaEncoding.GetMaxEncodingSize(const AN: TBigInteger): Int32;
-begin
-  Result := TDerSequence.GetEncodingLength(TDerInteger.GetEncodingLength(AN) * 2);
-end;
-
-class function TStandardDsaEncoding.GetInstance: IStandardDsaEncoding;
-begin
-  Result := TStandardDsaEncoding.Create();
-end;
-
-{ TPlainDsaEncoding }
-
 function TPlainDsaEncoding.CheckValue(const AN, AX: TBigInteger): TBigInteger;
 begin
   if ((AX.SignValue < 0) or ((AX.CompareTo(AN) >= 0))) then
-  begin
     raise EArgumentCryptoLibException.CreateResFmt(@SValueOutOfRange, ['x']);
-  end;
   Result := AX;
 end;
 
@@ -178,10 +76,8 @@ var
 begin
   LValueLength := TBigIntegers.GetUnsignedByteLength(AN);
   if (System.Length(AEncoding) <> (LValueLength * 2)) then
-  begin
     raise EArgumentCryptoLibException.CreateResFmt(@SInvalidEncodingLength,
       ['encoding']);
-  end;
   Result := TCryptoLibGenericArray<TBigInteger>.Create
     (DecodeValue(AN, AEncoding, 0, LValueLength), DecodeValue(AN, AEncoding,
     LValueLength, LValueLength));
@@ -199,9 +95,9 @@ var
   LValueLength: Int32;
 begin
   LValueLength := TBigIntegers.GetUnsignedByteLength(AN);
-  System.SetLength(result, LValueLength * 2);
-  EncodeValue(AN, AR, result, 0, LValueLength);
-  EncodeValue(AN, &AS, result, LValueLength, LValueLength);
+  System.SetLength(Result, LValueLength * 2);
+  EncodeValue(AN, AR, Result, 0, LValueLength);
+  EncodeValue(AN, &AS, Result, LValueLength, LValueLength);
 end;
 
 procedure TPlainDsaEncoding.EncodeValue(const AN, AX: TBigInteger;

+ 126 - 0
CryptoLib/src/Crypto/Signers/SignerEncodings/ClpStandardDsaEncoding.pas

@@ -0,0 +1,126 @@
+{ *********************************************************************************** }
+{ *                              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 ClpStandardDsaEncoding;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpAsn1Objects,
+  ClpBigInteger,
+  ClpAsn1Core,
+  ClpIDsaEncoding,
+  ClpIStandardDsaEncoding,
+  ClpIAsn1Objects,
+  ClpArrayUtilities,
+  ClpCryptoLibTypes;
+
+resourcestring
+  SMalformedSignature = 'Malformed signature, "%s"';
+  SValueOutOfRange = 'Value out of range, "%s"';
+
+type
+  TStandardDsaEncoding = class(TInterfacedObject, IDsaEncoding,
+    IStandardDsaEncoding)
+
+  strict private
+    class function GetInstance: IStandardDsaEncoding; static; inline;
+
+  strict protected
+    function CheckValue(const AN, AX: TBigInteger): TBigInteger; virtual;
+    function DecodeValue(const AN: TBigInteger; const &AS: IAsn1Sequence;
+      APos: Int32): TBigInteger; virtual;
+    function EncodeValue(const AN, AX: TBigInteger): IDerInteger; virtual;
+
+  public
+    function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
+      : TCryptoLibGenericArray<TBigInteger>; virtual;
+
+    function Encode(const AN, AR, &AS: TBigInteger): TCryptoLibByteArray; virtual;
+
+    function GetMaxEncodingSize(const AN: TBigInteger): Int32; virtual;
+
+    class property Instance: IStandardDsaEncoding read GetInstance;
+
+  end;
+
+implementation
+
+function TStandardDsaEncoding.CheckValue(const AN, AX: TBigInteger): TBigInteger;
+begin
+  if ((AX.SignValue < 0) or ((AN.IsInitialized) and (AX.CompareTo(AN) >= 0))) then
+    raise EArgumentCryptoLibException.CreateResFmt(@SValueOutOfRange, ['x']);
+  Result := AX;
+end;
+
+function TStandardDsaEncoding.Decode(const AN: TBigInteger;
+  const AEncoding: TCryptoLibByteArray): TCryptoLibGenericArray<TBigInteger>;
+var
+  LSeq: IAsn1Sequence;
+  LR, LS: TBigInteger;
+  LExpectedEncoding: TCryptoLibByteArray;
+begin
+  LSeq := TAsn1Object.FromByteArray(AEncoding) as IAsn1Sequence;
+  if (LSeq.Count = 2) then
+  begin
+    LR := DecodeValue(AN, LSeq, 0);
+    LS := DecodeValue(AN, LSeq, 1);
+    LExpectedEncoding := Encode(AN, LR, LS);
+    if TArrayUtilities.AreEqual<Byte>(LExpectedEncoding, AEncoding) then
+    begin
+      Result := TCryptoLibGenericArray<TBigInteger>.Create(LR, LS);
+      Exit;
+    end;
+  end;
+  raise EArgumentCryptoLibException.CreateResFmt(@SMalformedSignature,
+    ['encoding']);
+end;
+
+function TStandardDsaEncoding.DecodeValue(const AN: TBigInteger;
+  const &AS: IAsn1Sequence; APos: Int32): TBigInteger;
+begin
+  Result := CheckValue(AN, (&AS[APos] as IDerInteger).Value);
+end;
+
+function TStandardDsaEncoding.Encode(const AN, AR, &AS: TBigInteger)
+  : TCryptoLibByteArray;
+var
+  LTemp: IDerSequence;
+begin
+  LTemp := TDerSequence.Create([EncodeValue(AN, AR), EncodeValue(AN, &AS)])
+    as IDerSequence;
+  Result := LTemp.GetEncoded(TAsn1Encodable.Der);
+end;
+
+function TStandardDsaEncoding.EncodeValue(const AN, AX: TBigInteger): IDerInteger;
+begin
+  Result := TDerInteger.Create(CheckValue(AN, AX));
+end;
+
+function TStandardDsaEncoding.GetMaxEncodingSize(const AN: TBigInteger): Int32;
+begin
+  Result := TDerSequence.GetEncodingLength(TDerInteger.GetEncodingLength(AN) * 2);
+end;
+
+class function TStandardDsaEncoding.GetInstance: IStandardDsaEncoding;
+begin
+  Result := TStandardDsaEncoding.Create();
+end;
+
+end.

+ 1 - 1
CryptoLib/src/Factories/ClpSubjectPublicKeyInfoFactory.pas

@@ -91,7 +91,7 @@ begin
 
   if Supports(APublicKey, IDsaPublicKeyParameters, LDsaKey) then
   begin
-    LKp := LDsaKey.parameters;
+    LKp := LDsaKey.Parameters;
     if LKp = nil then
       raise EArgumentCryptoLibException.Create('DSA public key requires parameters.');
     LAlgID := TAlgorithmIdentifier.Create(TX9ObjectIdentifiers.IdDsa,

+ 8 - 8
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIAsymmetricBlockCipher.pas

@@ -40,13 +40,13 @@ type
     /// <summary>
     /// Initialise the cipher.
     /// </summary>
-    /// <param name="forEncryption">
+    /// <param name="AForEncryption">
     /// Initialise for encryption if true, for decryption if false.
     /// </param>
-    /// <param name="parameters">
+    /// <param name="AParameters">
     /// The key or other data required by the cipher.
     /// </param>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
 
     /// <summary>
     /// The maximum size, in bytes, an input block may be.
@@ -61,12 +61,12 @@ type
     /// <summary>
     /// Process a block.
     /// </summary>
-    /// <param name="inBuf">The input buffer.</param>
-    /// <param name="inOff">The offset into inBuf that the input block begins.</param>
-    /// <param name="inLen">The length of the input block.</param>
+    /// <param name="AInBuf">The input buffer.</param>
+    /// <param name="AInOff">The offset into inBuf that the input block begins.</param>
+    /// <param name="AInLen">The length of the input block.</param>
     /// <returns>The processed block.</returns>
-    function ProcessBlock(const inBuf: TCryptoLibByteArray;
-      inOff, inLen: Int32): TCryptoLibByteArray;
+    function ProcessBlock(const AInBuf: TCryptoLibByteArray;
+      AInOff, AInLen: Int32): TCryptoLibByteArray;
 
     property AlgorithmName: String read GetAlgorithmName;
     property InputBlockSize: Int32 read GetInputBlockSize;

+ 9 - 9
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIBlockCipher.pas

@@ -35,9 +35,9 @@ type
     property AlgorithmName: String read GetAlgorithmName;
 
     /// <summary>Initialise the cipher.</summary>
-    /// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
-    /// <param name="parameters">The key or other data required by the cipher.</param>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
+    /// <param name="AForEncryption">Initialise for encryption if true, for decryption if false.</param>
+    /// <param name="AParameters">The key or other data required by the cipher.</param>
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
 
     /// <returns>The block size for this cipher, in bytes.</returns>
     function GetBlockSize(): Int32;
@@ -47,14 +47,14 @@ type
     property IsPartialBlockOkay: Boolean read GetIsPartialBlockOkay;
 
     /// <summary>Process a block.</summary>
-    /// <param name="inBuf">The input buffer.</param>
-    /// <param name="inOff">The offset into <paramref>inBuf</paramref> that the input block begins.</param>
-    /// <param name="outBuf">The output buffer.</param>
-    /// <param name="outOff">The offset into <paramref>outBuf</paramref> to write the output block.</param>
+    /// <param name="AInBuf">The input buffer.</param>
+    /// <param name="AInOff">The offset into <paramref>inBuf</paramref> that the input block begins.</param>
+    /// <param name="AOutBuf">The output buffer.</param>
+    /// <param name="AOutOff">The offset into <paramref>outBuf</paramref> to write the output block.</param>
     /// <exception cref="DataLengthException">If input block is wrong size, or outBuf too small.</exception>
     /// <returns>The number of bytes processed and produced.</returns>
-    function ProcessBlock(const inBuf: TCryptoLibByteArray; inOff: Int32;
-      const outBuf: TCryptoLibByteArray; outOff: Int32): Int32;
+    function ProcessBlock(const AInBuf: TCryptoLibByteArray; AInOff: Int32;
+      const AOutBuf: TCryptoLibByteArray; AOutOff: Int32): Int32;
 
     /// <summary>
     /// Reset the cipher to the same state as it was after the last init (if there was one).

+ 35 - 0
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpICbcBlockCipher.pas

@@ -0,0 +1,35 @@
+{ *********************************************************************************** }
+{ *                              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 ClpICbcBlockCipher;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipher;
+
+type
+  ICbcBlockCipher = interface(IBlockCipher)
+    ['{A95FD7C2-02FE-4600-B496-B7A757737BFF}']
+    function GetUnderlyingCipher(): IBlockCipher;
+  end;
+
+implementation
+
+end.

+ 35 - 0
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpICfbBlockCipher.pas

@@ -0,0 +1,35 @@
+{ *********************************************************************************** }
+{ *                              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 ClpICfbBlockCipher;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipher;
+
+type
+  ICfbBlockCipher = interface(IBlockCipher)
+    ['{A58FD8F1-EECF-402F-9007-4E884FF7D325}']
+    function GetUnderlyingCipher(): IBlockCipher;
+  end;
+
+implementation
+
+end.

+ 35 - 0
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpICtsBlockCipher.pas

@@ -0,0 +1,35 @@
+{ *********************************************************************************** }
+{ *                              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 ClpICtsBlockCipher;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBufferedBlockCipher;
+
+type
+  ICtsBlockCipher = interface(IBufferedBlockCipher)
+    ['{4D02FD0B-47D6-4914-B31F-5869FF364558}']
+
+  end;
+
+implementation
+
+end.

+ 2 - 56
CryptoLib/src/Interfaces/Crypto/Modes/ClpIBlockCipherModes.pas → CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIOfbBlockCipher.pas

@@ -15,49 +15,17 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpIBlockCipherModes;
+unit ClpIOfbBlockCipher;
 
 {$I ..\..\..\Include\CryptoLib.inc}
 
 interface
 
 uses
-  ClpIBlockCipher,
-  ClpIBufferedBlockCipher;
-
-type
-  ICbcBlockCipher = interface(IBlockCipher)
-
-    ['{A95FD7C2-02FE-4600-B496-B7A757737BFF}']
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-  end;
-
-type
-  ICfbBlockCipher = interface(IBlockCipher)
-
-    ['{A58FD8F1-EECF-402F-9007-4E884FF7D325}']
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-  end;
+  ClpIBlockCipher;
 
 type
   IOfbBlockCipher = interface(IBlockCipher)
-
     ['{17D4977F-C9D8-466D-8E46-7E23A03471FC}']
 
     /// <summary>
@@ -70,28 +38,6 @@ type
 
   end;
 
-type
-  ISicBlockCipher = interface(IBlockCipher)
-
-    ['{85CC4B84-8E49-40E1-B2F9-6C271C1FB5E7}']
-
-    /// <summary>
-    /// return the underlying block cipher that we are wrapping.
-    /// </summary>
-    /// <returns>
-    /// return the underlying block cipher that we are wrapping.
-    /// </returns>
-    function GetUnderlyingCipher(): IBlockCipher;
-
-  end;
-
-type
-  ICtsBlockCipher = interface(IBufferedBlockCipher)
-
-    ['{4D02FD0B-47D6-4914-B31F-5869FF364558}']
-
-  end;
-
 implementation
 
 end.

+ 43 - 0
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpISicBlockCipher.pas

@@ -0,0 +1,43 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpISicBlockCipher;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipher;
+
+type
+  ISicBlockCipher = interface(IBlockCipher)
+    ['{85CC4B84-8E49-40E1-B2F9-6C271C1FB5E7}']
+
+    /// <summary>
+    /// return the underlying block cipher that we are wrapping.
+    /// </summary>
+    /// <returns>
+    /// return the underlying block cipher that we are wrapping.
+    /// </returns>
+    function GetUnderlyingCipher(): IBlockCipher;
+
+  end;
+
+implementation
+
+end.

+ 12 - 12
CryptoLib/src/Interfaces/Crypto/Ciphers/ClpIStreamCipher.pas

@@ -35,39 +35,39 @@ type
     property AlgorithmName: String read GetAlgorithmName;
 
     /// <summary>Initialise the cipher.</summary>
-    /// <param name="forEncryption">Initialise for encryption if true, for decryption if false.</param>
-    /// <param name="parameters">The key or other data required by the cipher.</param>
-    procedure Init(forEncryption: Boolean; const parameters: ICipherParameters);
+    /// <param name="AForEncryption">Initialise for encryption if true, for decryption if false.</param>
+    /// <param name="AParameters">The key or other data required by the cipher.</param>
+    procedure Init(AForEncryption: Boolean; const AParameters: ICipherParameters);
 
     /// <summary>encrypt/decrypt a single byte returning the result.</summary>
-    /// <param name="input">the byte to be processed.</param>
+    /// <param name="AInput">the byte to be processed.</param>
     /// <returns>the result of processing the input byte.</returns>
-    function ReturnByte(input: Byte): Byte;
+    function ReturnByte(AInput: Byte): Byte;
 
     /// <summary>
     /// Process a block of bytes from <c>input</c> putting the result into <c>
     /// output</c>.
     /// </summary>
-    /// <param name="inBytes">
+    /// <param name="AInBytes">
     /// The input byte array.
     /// </param>
-    /// <param name="inOff">
+    /// <param name="AInOff">
     /// The offset into <c>input</c> where the data to be processed starts.
     /// </param>
-    /// <param name="len">
+    /// <param name="ALen">
     /// The number of bytes to be processed.
     /// </param>
-    /// <param name="outBytes">
+    /// <param name="AOutBytes">
     /// The output buffer the processed bytes go into.
     /// </param>
-    /// <param name="outOff">
+    /// <param name="AOutOff">
     /// The offset into <c>output</c> the processed data starts at.
     /// </param>
     /// <exception cref="EDataLengthCryptoLibException">
     /// If the output buffer is too small.
     /// </exception>
-    procedure ProcessBytes(const inBytes: TCryptoLibByteArray;
-      inOff, len: Int32; const outBytes: TCryptoLibByteArray; outOff: Int32);
+    procedure ProcessBytes(const AInBytes: TCryptoLibByteArray;
+      AInOff, ALen: Int32; const AOutBytes: TCryptoLibByteArray; AOutOff: Int32);
 
     /// <summary>
     /// Reset the cipher to the same state as it was after the last init (if there was one).

+ 7 - 7
CryptoLib/src/Interfaces/Crypto/Paddings/ClpIBlockCipherPadding.pas

@@ -33,10 +33,10 @@ type
     /// <summary>
     /// Initialise the padder.
     /// </summary>
-    /// <param name="random">
+    /// <param name="ARandom">
     /// param parameters, if any required.
     /// </param>
-    procedure Init(const random: ISecureRandom);
+    procedure Init(const ARandom: ISecureRandom);
 
     /// <returns>
     /// return the name of the algorithm the cipher implements.
@@ -52,21 +52,21 @@ type
     /// add the pad bytes to the passed in block, returning the number of
     /// bytes added.
     /// </summary>
-    /// <param name="input">
+    /// <param name="AInput">
     /// input block to pad
     /// </param>
-    /// <param name="inOff">
+    /// <param name="AInOff">
     /// offset to start the padding from in the block
     /// </param>
     /// <returns>
     /// returns number of bytes added
     /// </returns>
-    function AddPadding(const input: TCryptoLibByteArray; inOff: Int32): Int32;
+    function AddPadding(const AInput: TCryptoLibByteArray; AInOff: Int32): Int32;
 
     /// <summary>
     /// return the number of pad bytes present in the block.
     /// </summary>
-    /// <param name="input">
+    /// <param name="AInput">
     /// block to count pad bytes in
     /// </param>
     /// <returns>
@@ -75,7 +75,7 @@ type
     /// <exception cref="EInvalidCipherTextCryptoLibException">
     /// if the padding is badly formed or invalid.
     /// </exception>
-    function PadCount(const input: TCryptoLibByteArray): Int32;
+    function PadCount(const AInput: TCryptoLibByteArray): Int32;
 
   end;
 

+ 1 - 38
CryptoLib/src/Interfaces/Crypto/Paddings/ClpIPaddingModes.pas → CryptoLib/src/Interfaces/Crypto/Paddings/ClpIISO10126d2Padding.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpIPaddingModes;
+unit ClpIISO10126d2Padding;
 
 {$I ..\..\..\Include\CryptoLib.inc}
 
@@ -26,44 +26,7 @@ uses
 
 type
   IISO10126d2Padding = interface(IBlockCipherPadding)
-
     ['{42C927E4-57D2-4179-BEB0-250B7E2F7166}']
-
-  end;
-
-type
-  IISO7816d4Padding = interface(IBlockCipherPadding)
-
-    ['{0550BE74-BEDB-4723-9D31-F9E145C8C7AE}']
-
-  end;
-
-type
-  IPkcs7Padding = interface(IBlockCipherPadding)
-
-    ['{131D8DF8-27C6-43EC-A6C0-2B2E02E23996}']
-
-  end;
-
-type
-  ITBCPadding = interface(IBlockCipherPadding)
-
-    ['{D279C067-7DB6-406C-82CC-607DECD79F60}']
-
-  end;
-
-type
-  IX923Padding = interface(IBlockCipherPadding)
-
-    ['{8815D63C-936C-497F-9B00-29F6F9E178A7}']
-
-  end;
-
-type
-  IZeroBytePadding = interface(IBlockCipherPadding)
-
-    ['{7B154AD1-F4DD-48A4-81B6-63A1DA8BB5A3}']
-
   end;
 
 implementation

+ 34 - 0
CryptoLib/src/Interfaces/Crypto/Paddings/ClpIISO7816d4Padding.pas

@@ -0,0 +1,34 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIISO7816d4Padding;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding;
+
+type
+  IISO7816d4Padding = interface(IBlockCipherPadding)
+    ['{0550BE74-BEDB-4723-9D31-F9E145C8C7AE}']
+  end;
+
+implementation
+
+end.

+ 34 - 0
CryptoLib/src/Interfaces/Crypto/Paddings/ClpIPkcs7Padding.pas

@@ -0,0 +1,34 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIPkcs7Padding;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding;
+
+type
+  IPkcs7Padding = interface(IBlockCipherPadding)
+    ['{131D8DF8-27C6-43EC-A6C0-2B2E02E23996}']
+  end;
+
+implementation
+
+end.

+ 34 - 0
CryptoLib/src/Interfaces/Crypto/Paddings/ClpITBCPadding.pas

@@ -0,0 +1,34 @@
+{ *********************************************************************************** }
+{ *                              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 ClpITBCPadding;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding;
+
+type
+  ITBCPadding = interface(IBlockCipherPadding)
+    ['{D279C067-7DB6-406C-82CC-607DECD79F60}']
+  end;
+
+implementation
+
+end.

+ 34 - 0
CryptoLib/src/Interfaces/Crypto/Paddings/ClpIX923Padding.pas

@@ -0,0 +1,34 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIX923Padding;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding;
+
+type
+  IX923Padding = interface(IBlockCipherPadding)
+    ['{8815D63C-936C-497F-9B00-29F6F9E178A7}']
+  end;
+
+implementation
+
+end.

+ 34 - 0
CryptoLib/src/Interfaces/Crypto/Paddings/ClpIZeroBytePadding.pas

@@ -0,0 +1,34 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIZeroBytePadding;
+
+{$I ..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIBlockCipherPadding;
+
+type
+  IZeroBytePadding = interface(IBlockCipherPadding)
+    ['{7B154AD1-F4DD-48A4-81B6-63A1DA8BB5A3}']
+  end;
+
+implementation
+
+end.

+ 1 - 1
CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDHKeyGenerationParameters.pas

@@ -31,7 +31,7 @@ type
 
     function GetParameters: IDHParameters;
 
-    property parameters: IDHParameters read GetParameters;
+    property Parameters: IDHParameters read GetParameters;
 
   end;
 

+ 1 - 1
CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDHKeyParameters.pas

@@ -34,7 +34,7 @@ type
     function GetAlgorithmOid: IDerObjectIdentifier;
 
     function Equals(const other: IDHKeyParameters): Boolean; overload;
-    property parameters: IDHParameters read GetParameters;
+    property Parameters: IDHParameters read GetParameters;
     property AlgorithmOid: IDerObjectIdentifier read GetAlgorithmOid;
 
   end;

+ 1 - 1
CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDsaKeyGenerationParameters.pas

@@ -31,7 +31,7 @@ type
 
     function GetParameters: IDsaParameters;
 
-    property parameters: IDsaParameters read GetParameters;
+    property Parameters: IDsaParameters read GetParameters;
 
   end;
 

+ 1 - 1
CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDsaKeyParameters.pas

@@ -32,7 +32,7 @@ type
     function GetParameters: IDsaParameters;
 
     function Equals(const other: IDsaKeyParameters): Boolean; overload;
-    property parameters: IDsaParameters read GetParameters;
+    property Parameters: IDsaParameters read GetParameters;
 
   end;
 

+ 1 - 1
CryptoLib/src/Interfaces/Crypto/Parameters/ClpIDsaParameterGenerationParameters.pas

@@ -41,7 +41,7 @@ type
     property certainty: Int32 read GetCertainty;
 
     function GetRandom: ISecureRandom;
-    property random: ISecureRandom read GetRandom;
+    property Random: ISecureRandom read GetRandom;
   end;
 
 implementation

+ 2 - 2
CryptoLib/src/Interfaces/Crypto/Parameters/ClpIParametersWithRandom.pas

@@ -33,9 +33,9 @@ type
     function GetRandom: ISecureRandom;
     function GetParameters: ICipherParameters;
 
-    property random: ISecureRandom read GetRandom;
+    property Random: ISecureRandom read GetRandom;
 
-    property parameters: ICipherParameters read GetParameters;
+    property Parameters: ICipherParameters read GetParameters;
 
   end;
 

+ 40 - 0
CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpIDsaEncoding.pas

@@ -0,0 +1,40 @@
+{ *********************************************************************************** }
+{ *                              CryptoLib Library                                  * }
+{ *                Copyright (c) 2018 - 20XX Ugochukwu Mmaduekwe                    * }
+{ *                 Github Repository <https://github.com/Xor-el>                   * }
+
+{ *  Distributed under the MIT software license, see the accompanying file LICENSE  * }
+{ *          or visit http://www.opensource.org/licenses/mit-license.php.           * }
+
+{ *                              Acknowledgements:                                  * }
+{ *                                                                                 * }
+{ *      Thanks to Sphere 10 Software (http://www.sphere10.com/) for sponsoring     * }
+{ *                           development of this library                           * }
+
+{ * ******************************************************************************* * }
+
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
+unit ClpIDsaEncoding;
+
+{$I ..\..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpBigInteger,
+  ClpCryptoLibTypes;
+
+type
+  IDsaEncoding = interface(IInterface)
+    ['{1331AB87-6BD4-46AF-A45D-440295E11AD7}']
+
+    function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
+      : TCryptoLibGenericArray<TBigInteger>;
+    function Encode(const AN, AR, &AS: TBigInteger): TCryptoLibByteArray;
+    function GetMaxEncodingSize(const AN: TBigInteger): Int32;
+  end;
+
+implementation
+
+end.

+ 42 - 0
CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpIPlainDsaEncoding.pas

@@ -0,0 +1,42 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIPlainDsaEncoding;
+
+{$I ..\..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpBigInteger,
+  ClpIDsaEncoding,
+  ClpCryptoLibTypes;
+
+type
+  IPlainDsaEncoding = interface(IDsaEncoding)
+    ['{72DC1571-BE91-461B-BD2F-A0CCAA15DD59}']
+
+    function CheckValue(const AN, AX: TBigInteger): TBigInteger;
+    function DecodeValue(const AN: TBigInteger; const ABuf: TCryptoLibByteArray;
+      AOff, ALength: Int32): TBigInteger;
+    procedure EncodeValue(const AN, AX: TBigInteger;
+      const ABuf: TCryptoLibByteArray; AOff, ALength: Int32);
+  end;
+
+implementation
+
+end.

+ 0 - 81
CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpISignersEncodings.pas

@@ -1,81 +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 ClpISignersEncodings;
-
-{$I ..\..\..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpBigInteger,
-  ClpIAsn1Objects,
-  ClpCryptoLibTypes;
-
-type
-  /// <summary>
-  /// An interface for different encoding formats for DSA signatures.
-  /// </summary>
-  IDsaEncoding = interface(IInterface)
-    ['{1331AB87-6BD4-46AF-A45D-440295E11AD7}']
-
-    /// <summary>Decode the (r, s) pair of a DSA signature.</summary>
-    /// <param name="n">The order of the group that r, s belong to.</param>
-    /// <param name="encoding">An encoding of the (r, s) pair of a DSA signature.</param>
-    /// <returns>The (r, s) of a DSA signature, stored in an array of exactly two elements, r followed by s.</returns>
-    function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
-      : TCryptoLibGenericArray<TBigInteger>;
-    /// <summary>Encode the (r, s) pair of a DSA signature.</summary>
-    /// <param name="n">The order of the group that r, s belong to.</param>
-    /// <param name="r">The r value of a DSA signature.</param>
-    /// <param name="s">The s value of a DSA signature.</param>
-    /// <returns>An encoding of the DSA signature given by the provided (r, s) pair.</returns>
-    function Encode(const AN, AR, &AS: TBigInteger): TCryptoLibByteArray;
-
-    /// <summary>Get the maximum encoding size for a given order.</summary>
-    /// <param name="n">The order of the group.</param>
-    /// <returns>The maximum size in bytes for an encoding.</returns>
-    function GetMaxEncodingSize(const AN: TBigInteger): Int32;
-
-  end;
-
-type
-  IStandardDsaEncoding = interface(IDsaEncoding)
-    ['{A8662374-922B-4D72-B956-FE0ED3505C68}']
-
-    function CheckValue(const AN, AX: TBigInteger): TBigInteger;
-    function DecodeValue(const AN: TBigInteger; const &AS: IAsn1Sequence;
-      APos: Int32): TBigInteger;
-    function EncodeValue(const AN, AX: TBigInteger): IDerInteger;
-
-  end;
-
-type
-  IPlainDsaEncoding = interface(IDsaEncoding)
-    ['{72DC1571-BE91-461B-BD2F-A0CCAA15DD59}']
-
-    function CheckValue(const AN, AX: TBigInteger): TBigInteger;
-    function DecodeValue(const AN: TBigInteger; const ABuf: TCryptoLibByteArray;
-      AOff, ALength: Int32): TBigInteger;
-    procedure EncodeValue(const AN, AX: TBigInteger;
-      const ABuf: TCryptoLibByteArray; AOff, ALength: Int32);
-
-  end;
-
-implementation
-
-end.

+ 42 - 0
CryptoLib/src/Interfaces/Crypto/Signers/SignerEncodings/ClpIStandardDsaEncoding.pas

@@ -0,0 +1,42 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIStandardDsaEncoding;
+
+{$I ..\..\..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpBigInteger,
+  ClpIDsaEncoding,
+  ClpIAsn1Objects,
+  ClpCryptoLibTypes;
+
+type
+  IStandardDsaEncoding = interface(IDsaEncoding)
+    ['{A8662374-922B-4D72-B956-FE0ED3505C68}']
+
+    function CheckValue(const AN, AX: TBigInteger): TBigInteger;
+    function DecodeValue(const AN: TBigInteger; const &AS: IAsn1Sequence;
+      APos: Int32): TBigInteger;
+    function EncodeValue(const AN, AX: TBigInteger): IDerInteger;
+  end;
+
+implementation
+
+end.