2
0
Ugochukwu Mmaduekwe 5 өдөр өмнө
parent
commit
2f407afec3
66 өөрчлөгдсөн 1109 нэмэгдсэн , 940 устгасан
  1. 7 15
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr
  2. 2 2
      CryptoLib.Tests/src/Crypto/DSATests.pas
  3. 3 1
      CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP256R1FieldTests.pas
  4. 2 1
      CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP384R1FieldTests.pas
  5. 2 3
      CryptoLib.Tests/src/Math/EC/FixedPointTests.pas
  6. 2 2
      CryptoLib.Tests/src/Math/ECAlgorithmsTests.pas
  7. 2 2
      CryptoLib.Tests/src/Math/ECIESTests.pas
  8. 2 2
      CryptoLib.Tests/src/Math/ECNRTests.pas
  9. 4 3
      CryptoLib.Tests/src/Math/ECPointTests.pas
  10. 1 1
      CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas
  11. 1 1
      CryptoLib.Tests/src/Others/CertTests.pas
  12. 3 2
      CryptoLib.Tests/src/Others/ECDsa5Tests.pas
  13. 3 2
      CryptoLib.Tests/src/Others/ECTests.pas
  14. 3 2
      CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas
  15. 1 1
      CryptoLib/src/Asn1/Sec/ClpSecNamedCurves.pas
  16. 1 1
      CryptoLib/src/Asn1/TeleTrust/ClpTeleTrusTNamedCurves.pas
  17. 1 1
      CryptoLib/src/Crypto/Generators/ClpDHKeyGeneratorHelper.pas
  18. 1 1
      CryptoLib/src/Crypto/Generators/ClpDHParametersHelper.pas
  19. 1 1
      CryptoLib/src/Crypto/Generators/ClpDsaGenerators.pas
  20. 2 3
      CryptoLib/src/Crypto/Generators/ClpECGenerators.pas
  21. 1 1
      CryptoLib/src/Crypto/Generators/ClpRsaGenerators.pas
  22. 7 0
      CryptoLib/src/Interfaces/Math/EC/Abc/ClpIZTauElement.pas
  23. 58 63
      CryptoLib/src/Interfaces/Math/EC/ClpIECCore.pas
  24. 8 0
      CryptoLib/src/Interfaces/Math/EC/ClpIECFieldElement.pas
  25. 0 31
      CryptoLib/src/Interfaces/Math/EC/ClpIECPointMap.pas
  26. 17 0
      CryptoLib/src/Interfaces/Math/EC/Endo/ClpIEndoPreCompInfo.pas
  27. 7 0
      CryptoLib/src/Interfaces/Math/EC/Endo/ClpIGlvTypeBEndomorphism.pas
  28. 7 0
      CryptoLib/src/Interfaces/Math/EC/Endo/ClpIGlvTypeBParameters.pas
  29. 7 0
      CryptoLib/src/Interfaces/Math/EC/Endo/ClpIScalarSplitParameters.pas
  30. 7 0
      CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIFixedPointPreCompInfo.pas
  31. 7 0
      CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIPreCompCallback.pas
  32. 7 0
      CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIPreCompInfo.pas
  33. 7 0
      CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIValidityPreCompInfo.pas
  34. 7 0
      CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIWNafPreCompInfo.pas
  35. 7 0
      CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIWTauNafPreCompInfo.pas
  36. 7 0
      CryptoLib/src/Math/EC/Abc/ClpSimpleBigDecimal.pas
  37. 54 49
      CryptoLib/src/Math/EC/Abc/ClpTnaf.pas
  38. 7 0
      CryptoLib/src/Math/EC/Abc/ClpZTauElement.pas
  39. 0 43
      CryptoLib/src/Math/EC/ClpAbstractECLookupTable.pas
  40. 16 9
      CryptoLib/src/Math/EC/ClpECAlgorithms.pas
  41. 99 88
      CryptoLib/src/Math/EC/ClpECCurve.pas
  42. 7 0
      CryptoLib/src/Math/EC/ClpECCurveConstants.pas
  43. 3 1
      CryptoLib/src/Math/EC/ClpECFieldElement.pas
  44. 18 3
      CryptoLib/src/Math/EC/ClpECLookupTables.pas
  45. 55 43
      CryptoLib/src/Math/EC/ClpECPoint.pas
  46. 111 0
      CryptoLib/src/Math/EC/ClpECPointMaps.pas
  47. 0 43
      CryptoLib/src/Math/EC/ClpScaleXNegateYPointMap.pas
  48. 0 43
      CryptoLib/src/Math/EC/ClpScaleXPointMap.pas
  49. 0 50
      CryptoLib/src/Math/EC/ClpScaleYNegateXPointMap.pas
  50. 0 50
      CryptoLib/src/Math/EC/ClpScaleYPointMap.pas
  51. 17 0
      CryptoLib/src/Math/EC/Endo/ClpEndoPreCompInfo.pas
  52. 36 17
      CryptoLib/src/Math/EC/Endo/ClpEndoUtilities.pas
  53. 9 4
      CryptoLib/src/Math/EC/Endo/ClpGlvTypeBEndomorphism.pas
  54. 7 0
      CryptoLib/src/Math/EC/Endo/ClpGlvTypeBParameters.pas
  55. 7 0
      CryptoLib/src/Math/EC/Endo/ClpScalarSplitParameters.pas
  56. 7 0
      CryptoLib/src/Math/EC/Multiplier/ClpFixedPointPreCompInfo.pas
  57. 31 22
      CryptoLib/src/Math/EC/Multiplier/ClpFixedPointUtilities.pas
  58. 24 19
      CryptoLib/src/Math/EC/Multiplier/ClpMultipliers.pas
  59. 7 0
      CryptoLib/src/Math/EC/Multiplier/ClpValidityPreCompInfo.pas
  60. 7 0
      CryptoLib/src/Math/EC/Multiplier/ClpWNafPreCompInfo.pas
  61. 365 307
      CryptoLib/src/Math/EC/Multiplier/ClpWNafUtilities.pas
  62. 7 0
      CryptoLib/src/Math/EC/Multiplier/ClpWTauNafPreCompInfo.pas
  63. 1 0
      CryptoLib/src/Math/Field/ClpFiniteFields.pas
  64. 6 5
      CryptoLib/src/Math/Field/ClpGF2Polynomial.pas
  65. 2 1
      CryptoLib/src/Math/Field/ClpGenericPolynomialExtensionField.pas
  66. 1 1
      CryptoLib/src/Math/Field/ClpPrimeField.pas

+ 7 - 15
CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr

@@ -98,7 +98,6 @@ uses
   ClpEacObjectIdentifiers in '..\..\CryptoLib\src\Asn1\Eac\ClpEacObjectIdentifiers.pas',
   ClpECAlgorithms in '..\..\CryptoLib\src\Math\EC\ClpECAlgorithms.pas',
   ClpECCurve in '..\..\CryptoLib\src\Math\EC\ClpECCurve.pas',
-  ClpECCompUtilities in '..\..\CryptoLib\src\Math\EC\ClpECCompUtilities.pas',
   ClpECCurveConstants in '..\..\CryptoLib\src\Math\EC\ClpECCurveConstants.pas',
   ClpECDHBasicAgreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpECDHBasicAgreement.pas',
   ClpECDHCBasicAgreement in '..\..\CryptoLib\src\Crypto\Agreements\ClpECDHCBasicAgreement.pas',
@@ -128,8 +127,6 @@ uses
   ClpGenericPolynomialExtensionField in '..\..\CryptoLib\src\Math\Field\ClpGenericPolynomialExtensionField.pas',
   ClpGenericSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpGenericSigner.pas',
   ClpGF2Polynomial in '..\..\CryptoLib\src\Math\Field\ClpGF2Polynomial.pas',
-  ClpGlvTypeAEndomorphism in '..\..\CryptoLib\src\Math\EC\Endo\ClpGlvTypeAEndomorphism.pas',
-  ClpGlvTypeAParameters in '..\..\CryptoLib\src\Math\EC\Endo\ClpGlvTypeAParameters.pas',
   ClpGlvTypeBEndomorphism in '..\..\CryptoLib\src\Math\EC\Endo\ClpGlvTypeBEndomorphism.pas',
   ClpGlvTypeBParameters in '..\..\CryptoLib\src\Math\EC\Endo\ClpGlvTypeBParameters.pas',
   ClpHkdfBytesGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpHkdfBytesGenerator.pas',
@@ -206,9 +203,6 @@ uses
   ClpIGenericPolynomialExtensionField in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIGenericPolynomialExtensionField.pas',
   ClpIGenericSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIGenericSigner.pas',
   ClpIGF2Polynomial in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIGF2Polynomial.pas',
-  ClpIGlvEndomorphism in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIGlvEndomorphism.pas',
-  ClpIGlvTypeAEndomorphism in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIGlvTypeAEndomorphism.pas',
-  ClpIGlvTypeAParameters in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIGlvTypeAParameters.pas',
   ClpIGlvTypeBEndomorphism in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIGlvTypeBEndomorphism.pas',
   ClpIGlvTypeBParameters in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIGlvTypeBParameters.pas',
   ClpIHkdfBytesGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIHkdfBytesGenerator.pas',
@@ -229,7 +223,6 @@ uses
   ClpIKMac in '..\..\CryptoLib\src\Interfaces\Crypto\Macs\ClpIKMac.pas',
   ClpIMac in '..\..\CryptoLib\src\Interfaces\Crypto\Macs\ClpIMac.pas',
   ClpIMacFactory in '..\..\CryptoLib\src\Interfaces\Crypto\ClpIMacFactory.pas',
-  ClpIMultipliers in '..\..\CryptoLib\src\Interfaces\Math\EC\Multiplier\ClpIMultipliers.pas',
   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',
@@ -251,7 +244,7 @@ uses
   ClpIPkcsAsn1Objects in '..\..\CryptoLib\src\Interfaces\Asn1\Pkcs\ClpIPkcsAsn1Objects.pas',
   ClpIPolynomial in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIPolynomial.pas',
   ClpIPolynomialExtensionField in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIPolynomialExtensionField.pas',
-  ClpIPreCompCallBack in '..\..\CryptoLib\src\Interfaces\Math\EC\Multiplier\ClpIPreCompCallBack.pas',
+  ClpIPreCompCallback in '..\..\CryptoLib\src\Interfaces\Math\EC\Multiplier\ClpIPreCompCallback.pas',
   ClpIPreCompInfo in '..\..\CryptoLib\src\Interfaces\Math\EC\Multiplier\ClpIPreCompInfo.pas',
   ClpIPrehash in '..\..\CryptoLib\src\Interfaces\Crypto\Digests\ClpIPrehash.pas',
   ClpIPrimeField in '..\..\CryptoLib\src\Interfaces\Math\Field\ClpIPrimeField.pas',
@@ -271,9 +264,6 @@ uses
   ClpIRsaParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIRsaParameters.pas',
   ClpISalsa20Engine in '..\..\CryptoLib\src\Interfaces\Crypto\Engines\ClpISalsa20Engine.pas',
   ClpIScalarSplitParameters in '..\..\CryptoLib\src\Interfaces\Math\EC\Endo\ClpIScalarSplitParameters.pas',
-  ClpIScaleXNegateYPointMap in '..\..\CryptoLib\src\Interfaces\Math\EC\ClpIScaleXNegateYPointMap.pas',
-  ClpIScaleXPointMap in '..\..\CryptoLib\src\Interfaces\Math\EC\ClpIScaleXPointMap.pas',
-  ClpIScaleYNegateXPointMap in '..\..\CryptoLib\src\Interfaces\Math\EC\ClpIScaleYNegateXPointMap.pas',
   ClpIScryptParametersGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIScryptParametersGenerator.pas',
   ClpISecECAsn1Objects in '..\..\CryptoLib\src\Interfaces\Asn1\Sec\ClpISecECAsn1Objects.pas',
   ClpISecP256K1Custom in '..\..\CryptoLib\src\Interfaces\Math\EC\Custom\Sec\ClpISecP256K1Custom.pas',
@@ -367,9 +357,7 @@ uses
   ClpRsaParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpRsaParameters.pas',
   ClpSalsa20Engine in '..\..\CryptoLib\src\Crypto\Engines\ClpSalsa20Engine.pas',
   ClpScalarSplitParameters in '..\..\CryptoLib\src\Math\EC\Endo\ClpScalarSplitParameters.pas',
-  ClpScaleXNegateYPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleXNegateYPointMap.pas',
-  ClpScaleXPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleXPointMap.pas',
-  ClpScaleYNegateXPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleYNegateXPointMap.pas',
+  ClpECPointMaps in '..\..\CryptoLib\src\Math\EC\ClpECPointMaps.pas',
   ClpScryptParametersGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpScryptParametersGenerator.pas',
   ClpSecECAsn1Objects in '..\..\CryptoLib\src\Asn1\Sec\ClpSecECAsn1Objects.pas',
   ClpSecNamedCurves in '..\..\CryptoLib\src\Asn1\Sec\ClpSecNamedCurves.pas',
@@ -595,7 +583,11 @@ uses
   CertTests in '..\src\Others\CertTests.pas',
   CryptoLibTestBase in '..\src\CryptoLibTestBase.pas',
   ClpECPoint in '..\..\CryptoLib\src\Math\EC\ClpECPoint.pas',
-  ClpECFieldElement in '..\..\CryptoLib\src\Math\EC\ClpECFieldElement.pas';
+  ClpECFieldElement in '..\..\CryptoLib\src\Math\EC\ClpECFieldElement.pas',
+  ClpECLookupTables in '..\..\CryptoLib\src\Math\EC\ClpECLookupTables.pas',
+  ClpECCore in '..\..\CryptoLib\src\Math\EC\ClpECCore.pas',
+  ClpEndoUtilities in '..\..\CryptoLib\src\Math\EC\Endo\ClpEndoUtilities.pas',
+  ClpWNafUtilities in '..\..\CryptoLib\src\Math\EC\Multiplier\ClpWNafUtilities.pas';
 
 begin
 

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

@@ -36,8 +36,8 @@ uses
   ClpDsaSigner,
   ClpIDsaParameters,
   ClpDsaParameters,
-  ClpIECC,
-  ClpECC,
+  ClpECCurve,
+  ClpIECCore,
   ClpECParameters,
   ClpIECParameters,
   ClpIAsn1Objects,

+ 3 - 1
CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP256R1FieldTests.pas

@@ -37,7 +37,9 @@ uses
   ClpSecObjectIdentifiers,
   ClpPack,
   ClpCustomNamedCurves,
-  ClpIECC,
+  ClpECCurve,
+  ClpIECCore,
+  ClpIECFieldElement,
   ClpBigInteger,
   ClpCryptoLibTypes,
   CryptoLibTestBase;

+ 2 - 1
CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP384R1FieldTests.pas

@@ -37,7 +37,8 @@ uses
   ClpSecObjectIdentifiers,
   ClpPack,
   ClpCustomNamedCurves,
-  ClpIECC,
+  ClpIECCore,
+  ClpIECFieldElement,
   ClpBigInteger,
   ClpCryptoLibTypes,
   CryptoLibTestBase;

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

@@ -33,12 +33,11 @@ uses
   Generics.Collections,
   ClpSecureRandom,
   ClpISecureRandom,
-  ClpIECC,
+  ClpIECCore,
   ClpBigInteger,
   ClpECNamedCurveTable,
   ClpCustomNamedCurves,
   ClpMultipliers,
-  ClpIMultipliers,
   ClpECAlgorithms,
   ClpIX9ECAsn1Objects,
   ClpCryptoLibTypes,
@@ -86,7 +85,7 @@ var
   tempDict: TDictionary<String, String>;
   names: TCryptoLibStringArray;
   x9, X9A, X9B: IX9ECParameters;
-  M: IFixedPointCombMultiplier;
+  M: IECMultiplier;
   k: TBigInteger;
   pRef, pA, pB: IECPoint;
 

+ 2 - 2
CryptoLib.Tests/src/Math/ECAlgorithmsTests.pas

@@ -37,8 +37,8 @@ uses
   Generics.Collections,
   ClpSecureRandom,
   ClpISecureRandom,
-  ClpECC,
-  ClpIECC,
+  ClpECCurve,
+  ClpIECCore,
   ClpBigInteger,
   ClpECNamedCurveTable,
   ClpCustomNamedCurves,

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

@@ -31,8 +31,8 @@ uses
 {$ELSE}
   TestFramework,
 {$ENDIF FPC}
-  ClpECC,
-  ClpIECC,
+  ClpECCurve,
+  ClpIECCore,
   ClpIHMac,
   ClpHMac,
   ClpIESEngine,

+ 2 - 2
CryptoLib.Tests/src/Math/ECNRTests.pas

@@ -33,8 +33,8 @@ uses
 {$ENDIF FPC}
   ClpAsn1Objects,
   ClpIAsn1Objects,
-  ClpIECC,
-  ClpECC,
+  ClpECCurve,
+  ClpIECCore,
   ClpIDigest,
   ClpECNRSigner,
   ClpIECNRSigner,

+ 4 - 3
CryptoLib.Tests/src/Math/ECPointTests.pas

@@ -42,11 +42,12 @@ uses
   ClpBigInteger,
   ClpBigIntegers,
   ClpECAlgorithms,
-  ClpECCompUtilities,
+  ClpWNafUtilities,
   ClpIFiniteField,
   ClpIX9ECAsn1Objects,
-  ClpECC,
-  ClpIECC,
+  ClpIECCore,
+  ClpECCurve,
+  ClpIECFieldElement,
   ClpX9ECAsn1Objects,
   CryptoLibTestBase;
 

+ 1 - 1
CryptoLib.Tests/src/Math/PascalCoinECIESTests.pas

@@ -15,7 +15,7 @@ uses
 {$ELSE}
   TestFramework,
 {$ENDIF FPC}
-  ClpIECC,
+  ClpIECCore,
   ClpIESEngine,
   ClpIIESEngine,
   ClpIKeyParser,

+ 1 - 1
CryptoLib.Tests/src/Others/CertTests.pas

@@ -36,7 +36,7 @@ uses
   TestFramework,
 {$ENDIF FPC}
   ClpBigInteger,
-  ClpIECC,
+  ClpIECCore,
   ClpX509Asn1Objects,
   ClpIX509Asn1Objects,
   ClpIX509Extension,

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

@@ -35,7 +35,9 @@ uses
   ClpFixedSecureRandom,
   ClpISecureRandom,
   ClpSecureRandom,
-  ClpECC,
+  ClpECCurve,
+  ClpIECCore,
+  ClpIECFieldElement,
   ClpIECParameters,
   ClpECParameters,
   ClpECGenerators,
@@ -44,7 +46,6 @@ uses
   ClpIAsymmetricKeyParameter,
   ClpParametersWithRandom,
   ClpIParametersWithRandom,
-  ClpIECC,
   ClpSignerUtilities,
   ClpIAsn1Objects,
   ClpISigner,

+ 3 - 2
CryptoLib.Tests/src/Others/ECTests.pas

@@ -48,8 +48,9 @@ uses
   ClpIECGenerators,
   ClpECGenerators,
   ClpIAsymmetricCipherKeyPair,
-  ClpECC,
-  ClpIECC,
+  ClpECCurve,
+  ClpIECCore,
+  ClpIECFieldElement,
   ClpBigInteger,
   ClpBigIntegers,
   ClpCryptoLibTypes,

+ 3 - 2
CryptoLib.Tests/src/Others/SignerUtilitiesTests.pas

@@ -33,7 +33,9 @@ uses
 {$ENDIF FPC}
   ClpBigInteger,
   ClpISigner,
-  ClpECC,
+  ClpECCurve,
+  ClpIECCore,
+  ClpIECFieldElement,
   ClpIRandom,
   ClpSignerUtilities,
   ClpSecureRandom,
@@ -41,7 +43,6 @@ uses
   ClpECParameters,
   ClpICipherParameters,
   ClpIECParameters,
-  ClpIECC,
   ClpIDsaParameters,
   ClpDsaParameters,
   ClpRsaParameters,

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

@@ -31,7 +31,7 @@ uses
   ClpIGlvTypeBEndomorphism,
   ClpSecObjectIdentifiers,
   ClpCryptoLibTypes,
-  ClpECCompUtilities,
+  ClpWnafUtilities,
   ClpBigInteger,
   ClpECCurve,
   ClpIECCore,

+ 1 - 1
CryptoLib/src/Asn1/TeleTrust/ClpTeleTrusTNamedCurves.pas

@@ -30,7 +30,7 @@ uses
   ClpTeleTrusTObjectIdentifiers,
   ClpCryptoLibTypes,
   ClpBigInteger,
-  ClpECCompUtilities,
+  ClpWnafUtilities,
   ClpECCurve,
   ClpIECCore,
   ClpIAsn1Objects,

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

@@ -26,7 +26,7 @@ uses
   ClpBitOperations,
   ClpBigInteger,
   ClpBigIntegers,
-  ClpECCompUtilities,
+  ClpWNafUtilities,
   ClpIDHParameters;
 
 type

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

@@ -25,7 +25,7 @@ uses
   ClpISecureRandom,
   ClpBigInteger,
   ClpBigIntegers,
-  ClpECCompUtilities,
+  ClpWNafUtilities,
   ClpBitOperations,
   ClpCryptoLibTypes;
 

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

@@ -35,7 +35,7 @@ uses
   ClpBigInteger,
   ClpBigIntegers,
   ClpBitOperations,
-  ClpECCompUtilities,
+  ClpWNafUtilities,
   ClpAsymmetricCipherKeyPair,
   ClpIAsymmetricCipherKeyPair,
   ClpIKeyGenerationParameters,

+ 2 - 3
CryptoLib/src/Crypto/Generators/ClpECGenerators.pas

@@ -27,14 +27,13 @@ uses
   ClpBitOperations,
   ClpCryptoLibTypes,
   ClpECParameters,
-  ClpECCompUtilities,
   ClpIECGenerators,
   ClpIAsn1Objects,
+  ClpWNafUtilities,
   ClpIKeyGenerationParameters,
   ClpIECParameters,
   ClpIECCore,
   ClpMultipliers,
-  ClpIMultipliers,
   ClpSecObjectIdentifiers,
   ClpCustomNamedCurves,
   ClpECNamedCurveTable,
@@ -126,7 +125,7 @@ var
   LQ: IECPoint;
 begin
   LEc := APrivKey.Parameters;
-  LQ := (TFixedPointCombMultiplier.Create() as IFixedPointCombMultiplier).Multiply(LEc.G, APrivKey.D);
+  LQ := (TFixedPointCombMultiplier.Create() as IECMultiplier).Multiply(LEc.G, APrivKey.D);
   Result := TECPublicKeyParameters.Create(APrivKey.AlgorithmName, LQ, LEc);
 end;
 

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

@@ -34,7 +34,7 @@ uses
   ClpAsymmetricCipherKeyPair,
   ClpIAsymmetricCipherKeyPairGenerator,
   ClpIRsaGenerators,
-  ClpECCompUtilities,
+  ClpWNafUtilities,
   ClpICipherParameters,
   ClpParameterUtilities,
   ClpISecureRandom,

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Abc/ClpIZTauElement.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIZTauElement;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 58 - 63
CryptoLib/src/Interfaces/Math/EC/ClpIECCore.pas

@@ -33,43 +33,11 @@ uses
 type
   IECCurve = interface;
   IECCurveConfig = interface;
-  IECMultiplier = interface;
   IECPoint = interface;
-  IECPointBase = interface;
-  IAbstractFpPoint = interface;
-  IFpPoint = interface;
-  IAbstractF2mPoint = interface;
-  IF2mPoint = interface;
-
-  IECPointMap = interface(IInterface)
-    ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567822}']
-    function Map(const AP: IECPoint): IECPoint;
-  end;
-
-  IECEndomorphism = interface(IInterface)
-    ['{E5F6A7B8-C9D0-1234-E5F6-A7B8C9D01235}']
-    function GetPointMap: IECPointMap;
-    function GetHasEfficientPointMap: Boolean;
-    property PointMap: IECPointMap read GetPointMap;
-    property HasEfficientPointMap: Boolean read GetHasEfficientPointMap;
-  end;
-
-  IGlvEndomorphism = interface(IECEndomorphism)
-    ['{F6A7B8C9-D0E1-2345-F6A7-B8C9D0E12346}']
-    function DecomposeScalar(const AK: TBigInteger): TCryptoLibGenericArray<TBigInteger>;
-  end;
-
-  IECLookupTable = interface(IInterface)
-    ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567821}']
-    function GetSize: Int32;
-    function Lookup(AIndex: Int32): IECPoint;
-    function LookupVar(AIndex: Int32): IECPoint;
-    property Size: Int32 read GetSize;
-  end;
 
-  ISimpleLookupTable = interface(IECLookupTable)
-    ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567835}']
-  end;
+  IECMultiplier = interface;
+  IECEndomorphism = interface;
+  IECLookupTable = interface;
 
   IECCurve = interface(IInterface)
     ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567819}']
@@ -113,7 +81,43 @@ type
     function Precompute(const APoint: IECPoint; const AName: String; const ACallback: IPreCompCallback): IPreCompInfo; overload;
     function Precompute(const AName: String; const ACallback: IPreCompCallback): IPreCompInfo; overload;
     function DecodePoint(const AEncoded: TCryptoLibByteArray): IECPoint;
+    function SupportsCoordinateSystem(ACoord: Int32): Boolean;
     function Configure: IECCurveConfig;
+    procedure ApplyConfig(ACoord: Int32; const AEndomorphism: IECEndomorphism; const AMultiplier: IECMultiplier);
+    function CloneCurve: IECCurve;
+    function ValidatePoint(const AX, AY: TBigInteger): IECPoint;
+  end;
+
+  IECCurveConfig = interface(IInterface)
+    ['{C5D6E7F8-A9B0-1234-C5D6-E7F8A9B01236}']
+
+    function SetCoordinateSystem(ACoord: Int32): IECCurveConfig;
+    function SetEndomorphism(const AEndomorphism: IECEndomorphism): IECCurveConfig;
+    function SetMultiplier(const AMultiplier: IECMultiplier): IECCurveConfig;
+    function CreateCurve: IECCurve;
+  end;
+
+  IAbstractFpCurve = interface(IECCurve)
+    ['{B2C3D4E5-F6A7-8901-BCDE-F12345678901}']
+    function IsValidFieldElement(const AX: TBigInteger): Boolean;
+    function RandomFieldElement(const ARandom: ISecureRandom): IECFieldElement;
+    function RandomFieldElementMult(const ARandom: ISecureRandom): IECFieldElement;
+    function DecompressPoint(AYTilde: Int32; const AX1: TBigInteger): IECPoint;
+  end;
+
+  IFpCurve = interface(IAbstractFpCurve)
+    ['{B2C3D4E5-F6A7-8901-BCDE-F12345678902}']
+  end;
+
+  IAbstractF2mCurve = interface(IECCurve)
+    ['{B2C3D4E5-F6A7-8901-BCDE-F12345678901}']
+    function GetIsKoblitz: Boolean;
+    function SolveQuadraticEquation(const ABeta: IECFieldElement): IECFieldElement;
+    property IsKoblitz: Boolean read GetIsKoblitz;
+  end;
+
+  IF2mCurve = interface(IAbstractF2mCurve)
+    ['{C3D4E5F6-A7B8-9012-CDEF-123456789013}']
   end;
 
   IECPoint = interface(IInterface)
@@ -171,6 +175,7 @@ type
     function TwicePlus(const AB: IECPoint): IECPoint;
     function ThreeTimes: IECPoint;
     function Equals(const AOther: IECPoint): Boolean;
+    function GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt; {$ENDIF DELPHI}
   end;
 
   IECPointBase = interface(IECPoint)
@@ -195,36 +200,30 @@ type
     ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567834}']
   end;
 
-  IECCurveConfig = interface(IInterface)
-    ['{C5D6E7F8-A9B0-1234-C5D6-E7F8A9B01236}']
-
-    function SetCoordinateSystem(ACoord: Int32): IECCurveConfig;
-    function SetEndomorphism(const AEndomorphism: IECEndomorphism): IECCurveConfig;
-    function SetMultiplier(const AMultiplier: IECMultiplier): IECCurveConfig;
-    function CreateCurve: IECCurve;
-  end;
-
-  IAbstractFpCurve = interface(IECCurve)
-    ['{B2C3D4E5-F6A7-8901-BCDE-F12345678901}']
-    function IsValidFieldElement(const AX: TBigInteger): Boolean; override;
-    function RandomFieldElement(const ARandom: ISecureRandom): IECFieldElement; override;
-    function RandomFieldElementMult(const ARandom: ISecureRandom): IECFieldElement; override;
-    function DecompressPoint(AYTilde: Int32; const AX1: TBigInteger): IECPoint; override;
+  IECPointMap = interface(IInterface)
+    ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567822}']
+    function Map(const AP: IECPoint): IECPoint;
   end;
 
-  IFpCurve = interface(IAbstractFpCurve)
-    ['{B2C3D4E5-F6A7-8901-BCDE-F12345678902}']
+  IECEndomorphism = interface(IInterface)
+    ['{E5F6A7B8-C9D0-1234-E5F6-A7B8C9D01235}']
+    function GetPointMap: IECPointMap;
+    function GetHasEfficientPointMap: Boolean;
+    property PointMap: IECPointMap read GetPointMap;
+    property HasEfficientPointMap: Boolean read GetHasEfficientPointMap;
   end;
 
-  IAbstractF2mCurve = interface(IECCurve)
-    ['{B2C3D4E5-F6A7-8901-BCDE-F12345678901}']
-    function GetIsKoblitz: Boolean;
-    function SolveQuadraticEquation(const ABeta: IECFieldElement): IECFieldElement;
-    property IsKoblitz: Boolean read GetIsKoblitz;
+  IGlvEndomorphism = interface(IECEndomorphism)
+    ['{F6A7B8C9-D0E1-2345-F6A7-B8C9D0E12346}']
+    function DecomposeScalar(const AK: TBigInteger): TCryptoLibGenericArray<TBigInteger>;
   end;
 
-  IF2mCurve = interface(IAbstractF2mCurve)
-    ['{C3D4E5F6-A7B8-9012-CDEF-123456789013}']
+  IECLookupTable = interface(IInterface)
+    ['{A1B2C3D4-E5F6-7890-ABCD-EF1234567821}']
+    function GetSize: Int32;
+    function Lookup(AIndex: Int32): IECPoint;
+    function LookupVar(AIndex: Int32): IECPoint;
+    property Size: Int32 read GetSize;
   end;
 
   IECMultiplier = interface(IInterface)
@@ -233,10 +232,6 @@ type
     function Multiply(const APoint: IECPoint; const AK: TBigInteger): IECPoint;
   end;
 
-  IWNafL2RMultiplier = interface(IECMultiplier)
-    ['{E5F6A7B8-C9D0-2345-E5F6-A7B8C9D02346}']
-  end;
-
 implementation
 
 end.

+ 8 - 0
CryptoLib/src/Interfaces/Math/EC/ClpIECFieldElement.pas

@@ -13,6 +13,8 @@
 
 { * ******************************************************************************* * }
 
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
 unit ClpIECFieldElement;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -42,6 +44,8 @@ type
     procedure EncodeTo(var ABuf: TCryptoLibByteArray; AOff: Int32);
     function GetIsOne: Boolean;
     function GetIsZero: Boolean;
+    property IsOne: Boolean read GetIsOne;
+    property IsZero: Boolean read GetIsZero;
     function GetBitLength: Int32;
     function TestBitZero: Boolean;
     function Equals(const AOther: IECFieldElement): Boolean;
@@ -61,6 +65,10 @@ type
     function SquarePow(APow: Int32): IECFieldElement;
   end;
 
+  IAbstractFpFieldElement = interface(IECFieldElement)
+    ['{B4339FF2-E999-4AF2-BDD2-64F88DEAD1AA}']
+  end;
+
   IFpFieldElement = interface(IECFieldElement)
     ['{A1B2C3D4-E5F6-7890-ABCD-EF123456781A}']
 

+ 0 - 31
CryptoLib/src/Interfaces/Math/EC/ClpIECPointMap.pas

@@ -1,31 +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 ClpIECPointMap;
-
-{$I ..\..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIECCore;
-
-  { IECPointMap is declared in ClpIECCore to avoid circular unit reference. }
-
-implementation
-
-end.

+ 17 - 0
CryptoLib/src/Interfaces/Math/EC/Endo/ClpIEndoPreCompInfo.pas

@@ -1,3 +1,20 @@
+{ *********************************************************************************** }
+{ *                              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 ClpIEndoPreCompInfo;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Endo/ClpIGlvTypeBEndomorphism.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIGlvTypeBEndomorphism;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Endo/ClpIGlvTypeBParameters.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIGlvTypeBParameters;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Endo/ClpIScalarSplitParameters.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIScalarSplitParameters;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIFixedPointPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIFixedPointPreCompInfo;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIPreCompCallback.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIPreCompCallback;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIPreCompInfo;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIValidityPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIValidityPreCompInfo;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIWNafPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIWNafPreCompInfo;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Interfaces/Math/EC/Multiplier/ClpIWTauNafPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpIWTauNafPreCompInfo;
 
 {$I ..\..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Math/EC/Abc/ClpSimpleBigDecimal.pas

@@ -6,8 +6,15 @@
 { *  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 ClpSimpleBigDecimal;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 54 - 49
CryptoLib/src/Math/EC/Abc/ClpTnaf.pas

@@ -6,8 +6,15 @@
 { *  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 ClpTnaf;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -20,10 +27,13 @@ uses
   ClpIZTauElement,
   ClpZTauElement,
   ClpSimpleBigDecimal,
+  ClpECPoint,
   ClpIECCore,
   ClpIECFieldElement,
   ClpIPreCompCallback,
   ClpIPreCompInfo,
+  ClpArrayUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 resourcestring
@@ -36,6 +46,39 @@ resourcestring
 type
   TTnaf = class sealed(TObject)
   strict private
+    type
+      IPartModPreCompInfo = interface(IPreCompInfo)
+        ['{B1C2D3E4-F5A6-7890-BCDE-F23456789012}']
+        function GetLucas: TBigInteger;
+        function GetS0: TBigInteger;
+        function GetS1: TBigInteger;
+        property Lucas: TBigInteger read GetLucas;
+        property S0: TBigInteger read GetS0;
+        property S1: TBigInteger read GetS1;
+      end;
+
+      TPartModPreCompInfo = class sealed(TInterfacedObject, IPreCompInfo, IPartModPreCompInfo)
+      strict private
+        FLucas: TBigInteger;
+        FS0: TBigInteger;
+        FS1: TBigInteger;
+        function GetLucas: TBigInteger;
+        function GetS0: TBigInteger;
+        function GetS1: TBigInteger;
+      public
+        constructor Create(const ALucas, AS0, AS1: TBigInteger);
+      end;
+
+      TPartModPreCompCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FCurve: IAbstractF2mCurve;
+        FMu: ShortInt;
+        FDoV: Boolean;
+      public
+        constructor Create(const ACurve: IAbstractF2mCurve; AMu: ShortInt; ADoV: Boolean);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
+
     class var
       FMinusOne: TBigInteger;
       FMinusTwo: TBigInteger;
@@ -101,47 +144,9 @@ type
 
 implementation
 
-uses
-  ClpECPoint,
-  ClpArrayUtilities,
-  ClpBitOperations;
-
-type
-  IPartModPreCompInfo = interface(IPreCompInfo)
-    ['{B1C2D3E4-F5A6-7890-BCDE-F23456789012}']
-    function GetLucas: TBigInteger;
-    function GetS0: TBigInteger;
-    function GetS1: TBigInteger;
-    property Lucas: TBigInteger read GetLucas;
-    property S0: TBigInteger read GetS0;
-    property S1: TBigInteger read GetS1;
-  end;
-
-  TPartModPreCompInfo = class sealed(TInterfacedObject, IPreCompInfo, IPartModPreCompInfo)
-  strict private
-    FLucas: TBigInteger;
-    FS0: TBigInteger;
-    FS1: TBigInteger;
-    function GetLucas: TBigInteger;
-    function GetS0: TBigInteger;
-    function GetS1: TBigInteger;
-  public
-    constructor Create(const ALucas, AS0, AS1: TBigInteger);
-  end;
-
-  TPartModPreCompCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FCurve: IAbstractF2mCurve;
-    FMu: ShortInt;
-    FDoV: Boolean;
-  public
-    constructor Create(const ACurve: IAbstractF2mCurve; AMu: ShortInt; ADoV: Boolean);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
-
-{ TPartModPreCompInfo }
+{ TTnaf.TPartModPreCompInfo }
 
-constructor TPartModPreCompInfo.Create(const ALucas, AS0, AS1: TBigInteger);
+constructor TTnaf.TPartModPreCompInfo.Create(const ALucas, AS0, AS1: TBigInteger);
 begin
   inherited Create;
   FLucas := ALucas;
@@ -149,24 +154,24 @@ begin
   FS1 := AS1;
 end;
 
-function TPartModPreCompInfo.GetLucas: TBigInteger;
+function TTnaf.TPartModPreCompInfo.GetLucas: TBigInteger;
 begin
   Result := FLucas;
 end;
 
-function TPartModPreCompInfo.GetS0: TBigInteger;
+function TTnaf.TPartModPreCompInfo.GetS0: TBigInteger;
 begin
   Result := FS0;
 end;
 
-function TPartModPreCompInfo.GetS1: TBigInteger;
+function TTnaf.TPartModPreCompInfo.GetS1: TBigInteger;
 begin
   Result := FS1;
 end;
 
-{ TPartModPreCompCallback }
+{ TTnaf.TPartModPreCompCallback }
 
-constructor TPartModPreCompCallback.Create(const ACurve: IAbstractF2mCurve;
+constructor TTnaf.TPartModPreCompCallback.Create(const ACurve: IAbstractF2mCurve;
   AMu: ShortInt; ADoV: Boolean);
 begin
   inherited Create;
@@ -175,7 +180,7 @@ begin
   FDoV := ADoV;
 end;
 
-function TPartModPreCompCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+function TTnaf.TPartModPreCompCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
 var
   LPartMod: IPartModPreCompInfo;
   LLucas: TBigInteger;
@@ -198,7 +203,7 @@ begin
 
   LSi := TTnaf.GetSi(FCurve);
 
-  Result := TPartModPreCompInfo.Create(LLucas, LSi[0], LSi[1]);
+  Result := TTnaf.TPartModPreCompInfo.Create(LLucas, LSi[0], LSi[1]);
 end;
 
 { TTnaf }
@@ -596,7 +601,7 @@ class function TTnaf.GetShiftsForCofactor(const AH: TBigInteger): Int32;
 var
   LHi: Int32;
 begin
-  if (AH <> nil) and (AH.BitLength < 4) then
+  if (AH.IsInitialized) and (AH.BitLength < 4) then
   begin
     LHi := AH.Int32Value;
     if LHi = 2 then
@@ -619,7 +624,7 @@ var
   LQ: IZTauElement;
   LR0, LR1: TBigInteger;
 begin
-  LCallback := TPartModPreCompCallback.Create(ACurve, AMu, True);
+  LCallback := TTnaf.TPartModPreCompCallback.Create(ACurve, AMu, True);
   if not Supports(ACurve.Precompute(PRECOMP_NAME, LCallback), IPartModPreCompInfo, LPreCompInfo) then
     raise EInvalidOperationCryptoLibException.Create('PartMod precomp failed');
 

+ 7 - 0
CryptoLib/src/Math/EC/Abc/ClpZTauElement.pas

@@ -6,8 +6,15 @@
 { *  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 ClpZTauElement;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 0 - 43
CryptoLib/src/Math/EC/ClpAbstractECLookupTable.pas

@@ -1,43 +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 ClpAbstractECLookupTable;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIECCore;
-
-type
-  TAbstractECLookupTable = class abstract(TInterfacedObject, IECLookupTable)
-  public
-    function Lookup(AIndex: Int32): IECPoint; virtual; abstract;
-    function GetSize: Int32; virtual; abstract;
-    function LookupVar(AIndex: Int32): IECPoint; virtual;
-    property Size: Int32 read GetSize;
-  end;
-
-implementation
-
-function TAbstractECLookupTable.LookupVar(AIndex: Int32): IECPoint;
-begin
-  Result := Lookup(AIndex);
-end;
-
-end.

+ 16 - 9
CryptoLib/src/Math/EC/ClpECAlgorithms.pas

@@ -6,8 +6,15 @@
 { *  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 ClpECAlgorithms;
 
 {$I ..\..\Include\CryptoLib.inc}
@@ -21,6 +28,7 @@ uses
   ClpIECFieldElement,
   ClpIFiniteField,
   ClpIPolynomialExtensionField,
+  ClpIWNafPreCompInfo,
   ClpCryptoLibTypes;
 
 type
@@ -75,7 +83,7 @@ type
 implementation
 
 uses
-  System.Math,
+  Math,
   ClpBitOperations,
   ClpECCurve,
   ClpFixedPointUtilities,
@@ -85,8 +93,7 @@ uses
   ClpWNafUtilities,
   ClpWNafPreCompInfo,
   ClpEndoUtilities,
-  ClpNat,
-  ClpCryptoLibTypes;
+  ClpNat;
 
 { TECAlgorithms }
 
@@ -525,7 +532,7 @@ begin
     LSmallR := LInfinity;
     if LWiP <> 0 then
     begin
-      LnP := System.Math.Abs(LWiP);
+      LnP := System.Abs(LWiP);
       if LWiP < 0 then
         LTableP := APreCompNegP
       else
@@ -534,7 +541,7 @@ begin
     end;
     if LWiQ <> 0 then
     begin
-      LnQ := System.Math.Abs(LWiQ);
+      LnQ := System.Abs(LWiQ);
       if LWiQ < 0 then
         LTableQ := APreCompNegQ
       else
@@ -596,13 +603,13 @@ begin
   J := 0;
   for I := 0 to LLen - 1 do
   begin
-    LAbPair := AGlvEndomorphism.DecomposeScalar(AKs[I].Mod(LN));
+    LAbPair := AGlvEndomorphism.DecomposeScalar(AKs[I].&Mod(LN));
     LAbs[J] := LAbPair[0];
     Inc(J);
     LAbs[J] := LAbPair[1];
     Inc(J);
   end;
-  if AGlvEndomorphism.HasEfficientPointMap then
+  if (AGlvEndomorphism.HasEfficientPointMap) then
     Result := ImplSumOfMultiplies(AGlvEndomorphism as IECEndomorphism, APs, LAbs)
   else
   begin
@@ -639,6 +646,7 @@ begin
   System.SetLength(LNegs, LFullCount);
   System.SetLength(LInfos, LFullCount);
   System.SetLength(LWnafs, LFullCount);
+  LPointMap := AEndomorphism.PointMap;
   for I := 0 to LHalfCount - 1 do
   begin
     J0 := I shl 1;
@@ -654,7 +662,6 @@ begin
     LP := APs[I];
     LInfoP := TWNafUtilities.Precompute(LP, LMinWidth, True);
     LQ := TEndoUtilities.MapPoint(AEndomorphism, LP);
-    LPointMap := AEndomorphism.PointMap;
     LInfoQ := TWNafUtilities.PrecomputeWithPointMap(LQ, LPointMap, LInfoP, True);
     LWidthP := System.Math.Min(8, LInfoP.Width);
     LWidthQ := System.Math.Min(8, LInfoQ.Width);
@@ -700,7 +707,7 @@ begin
         LWi := 0;
       if LWi <> 0 then
       begin
-        LN := System.Math.Abs(LWi);
+        LN := System.Abs(LWi);
         LInfo := AInfos[J];
         if (LWi < 0) = ANegs[J] then
           LTable := LInfo.PreComp

+ 99 - 88
CryptoLib/src/Math/EC/ClpECCurve.pas

@@ -6,8 +6,15 @@
 { *  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 ClpECCurve;
 
 {$I ..\..\Include\CryptoLib.inc}
@@ -22,6 +29,11 @@ uses
   ClpIFiniteField,
   ClpIECCore,
   ClpLongArray,
+  ClpECAlgorithms,
+  ClpFiniteFields,
+  ClpPrimes,
+  ClpSecureRandom,
+  ClpECFieldElement,
   ClpIECFieldElement,
   ClpIPreCompCallback,
   ClpIPreCompInfo,
@@ -29,6 +41,7 @@ uses
   ClpArrayUtilities,
   ClpBitOperations,
   ClpBigIntegers,
+  ClpECLookupTables,
   ClpECCurveConstants,
   ClpCryptoLibTypes;
 
@@ -51,6 +64,21 @@ resourcestring
 
 type
   TECCurve = class abstract(TInterfacedObject, IECCurve)
+  strict private
+type
+  TDefaultLookupTable = class sealed(TAbstractECLookupTable, IECLookupTable)
+  strict private
+    FOuter: IECCurve;
+    FTable: TBytes;
+    FSize: Int32;
+    function CreatePoint(const AX, AY: TCryptoLibByteArray): IECPoint;
+  public
+    constructor Create(const AOuter: IECCurve; const ATable: TCryptoLibByteArray; ASize: Int32);
+    function GetSize: Int32; override;
+    function Lookup(AIndex: Int32): IECPoint; override;
+    function LookupVar(AIndex: Int32): IECPoint; override;
+  end;
+
   strict protected
     FField: IFiniteField;
     FA, FB: IECFieldElement;
@@ -68,8 +96,24 @@ type
     procedure CheckPoints(const APoints: TCryptoLibGenericArray<IECPoint>;
       AOff, ALen: Int32); overload; virtual;
     function DecompressPoint(AYTilde: Int32; const AX1: TBigInteger): IECPoint; virtual;
-    function CloneCurve: TECCurve; virtual; abstract;
+    function CloneCurve: IECCurve; virtual; abstract;
   public
+type
+  TECCurveConfig = class sealed(TInterfacedObject, IECCurveConfig)
+  strict private
+    FOuter: IECCurve;
+    FCoord: Int32;
+    FEndomorphism: IECEndomorphism;
+    FMultiplier: IECMultiplier;
+  public
+    constructor Create(const AOuter: IECCurve; ACoord: Int32;
+      const AEndomorphism: IECEndomorphism; const AMultiplier: IECMultiplier);
+    function SetCoordinateSystem(ACoord: Int32): IECCurveConfig;
+    function SetEndomorphism(const AEndomorphism: IECEndomorphism): IECCurveConfig;
+    function SetMultiplier(const AMultiplier: IECMultiplier): IECCurveConfig;
+    function CreateCurve: IECCurve;
+  end;
+
     constructor Create(const AField: IFiniteField);
     destructor Destroy; override;
 
@@ -117,21 +161,6 @@ type
     function GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt; {$ENDIF DELPHI} override;
   end;
 
-  TECCurveConfig = class sealed(TInterfacedObject, IECCurveConfig)
-  strict private
-    FOuter: TECCurve;
-    FCoord: Int32;
-    FEndomorphism: IECEndomorphism;
-    FMultiplier: IECMultiplier;
-  public
-    constructor Create(const AOuter: TECCurve; ACoord: Int32;
-      const AEndomorphism: IECEndomorphism; const AMultiplier: IECMultiplier);
-    function SetCoordinateSystem(ACoord: Int32): IECCurveConfig;
-    function SetEndomorphism(const AEndomorphism: IECEndomorphism): IECCurveConfig;
-    function SetMultiplier(const AMultiplier: IECMultiplier): IECCurveConfig;
-    function CreateCurve: IECCurve;
-  end;
-
   TAbstractFpCurve = class abstract(TECCurve, IECCurve, IAbstractFpCurve)
   strict private
     class var
@@ -171,7 +200,7 @@ type
       AIsInternal: Boolean); overload;
     constructor Create(const AQ, AR: TBigInteger; const AA, AB: IECFieldElement;
       const AOrder, ACofactor: TBigInteger); overload;
-    function CloneCurve: TECCurve; override;
+    function CloneCurve: IECCurve; override;
     function GetFieldSize: Int32; override;
     function ImportPoint(const AP: IECPoint): IECPoint; override;
     function GetInfinity: IECPoint; override;
@@ -208,13 +237,28 @@ type
     FKs: TCryptoLibInt32Array;
     FInfinity: IECPoint;
     function CreateDefaultMultiplier: IECMultiplier; override;
+  strict private
+type
+  TDefaultF2mLookupTable = class sealed(TAbstractECLookupTable, IECLookupTable)
+  strict private
+    FOuter: TF2mCurve;
+    FTable: TCryptoLibUInt64Array;
+    FSize: Int32;
+    function CreatePoint(const AX, AY: TCryptoLibUInt64Array): IECPoint;
+  public
+    constructor Create(const AOuter: TF2mCurve; const ATable: TCryptoLibUInt64Array; ASize: Int32);
+    function GetSize: Int32; override;
+    function Lookup(AIndex: Int32): IECPoint; override;
+    function LookupVar(AIndex: Int32): IECPoint; override;
+  end;
+
   public
     const F2M_DEFAULT_COORDS = TECCurveConstants.COORD_LAMBDA_PROJECTIVE;
     constructor Create(AM, AK: Int32; const AA, AB, AOrder, ACofactor: TBigInteger); overload;
     constructor Create(AM, AK1, AK2, AK3: Int32; const AA, AB, AOrder, ACofactor: TBigInteger); overload;
     constructor Create(AM, AK1, AK2, AK3: Int32; const AA, AB: IECFieldElement;
       const AOrder, ACofactor: TBigInteger); overload;
-    function CloneCurve: TECCurve; override;
+    function CloneCurve: IECCurve; override;
     function GetFieldSize: Int32; override;
     function GetInfinity: IECPoint; override;
     function FromBigInteger(const AX: TBigInteger): IECFieldElement; override;
@@ -237,31 +281,11 @@ implementation
 
 uses
   ClpECPoint,
-  ClpECFieldElement,
-  ClpECAlgorithms,
-  ClpAbstractECLookupTable,
-  ClpFiniteFields,
-  ClpPrimes,
-  ClpSecureRandom,
   ClpMultipliers;
 
-type
-  TDefaultLookupTable = class sealed(TAbstractECLookupTable)
-  strict private
-    FOuter: IECCurve;
-    FTable: TBytes;
-    FSize: Int32;
-    function CreatePoint(const AX, AY: TCryptoLibByteArray): IECPoint;
-  public
-    constructor Create(const AOuter: IECCurve; const ATable: TCryptoLibByteArray; ASize: Int32);
-    function GetSize: Int32; override;
-    function Lookup(AIndex: Int32): IECPoint; override;
-    function LookupVar(AIndex: Int32): IECPoint; override;
-  end;
-
-{ TDefaultLookupTable }
+{ TECCurve.TDefaultLookupTable }
 
-constructor TDefaultLookupTable.Create(const AOuter: IECCurve; const ATable: TCryptoLibByteArray; ASize: Int32);
+constructor TECCurve.TDefaultLookupTable.Create(const AOuter: IECCurve; const ATable: TCryptoLibByteArray; ASize: Int32);
 begin
   Inherited Create();
   FOuter := AOuter;
@@ -269,12 +293,12 @@ begin
   FSize := ASize;
 end;
 
-function TDefaultLookupTable.GetSize: Int32;
+function TECCurve.TDefaultLookupTable.GetSize: Int32;
 begin
   Result := FSize;
 end;
 
-function TDefaultLookupTable.Lookup(AIndex: Int32): IECPoint;
+function TECCurve.TDefaultLookupTable.Lookup(AIndex: Int32): IECPoint;
 var
   LFeBytes, LPos, I, J: Int32;
   LMask: Byte;
@@ -297,7 +321,7 @@ begin
   Result := CreatePoint(LX, LY);
 end;
 
-function TDefaultLookupTable.LookupVar(AIndex: Int32): IECPoint;
+function TECCurve.TDefaultLookupTable.LookupVar(AIndex: Int32): IECPoint;
 var
   LFeBytes, LPos, J: Int32;
   LX, LY: TBytes;
@@ -314,7 +338,7 @@ begin
   Result := CreatePoint(LX, LY);
 end;
 
-function TDefaultLookupTable.CreatePoint(const AX, AY: TBytes): IECPoint;
+function TECCurve.TDefaultLookupTable.CreatePoint(const AX, AY: TBytes): IECPoint;
 var
   LX, LY: IECFieldElement;
 begin
@@ -323,22 +347,9 @@ begin
   Result := FOuter.CreateRawPoint(LX, LY);
 end;
 
-  TDefaultF2mLookupTable = class sealed(TAbstractECLookupTable)
-  strict private
-    FOuter: TF2mCurve;
-    FTable: TCryptoLibUInt64Array;
-    FSize: Int32;
-    function CreatePoint(const AX, AY: TCryptoLibUInt64Array): IECPoint;
-  public
-    constructor Create(const AOuter: TF2mCurve; const ATable: TCryptoLibUInt64Array; ASize: Int32);
-    function GetSize: Int32; override;
-    function Lookup(AIndex: Int32): IECPoint; override;
-    function LookupVar(AIndex: Int32): IECPoint; override;
-  end;
-
-{ TDefaultF2mLookupTable }
+{ TF2mCurve.TDefaultF2mLookupTable }
 
-constructor TDefaultF2mLookupTable.Create(const AOuter: TF2mCurve; const ATable: TCryptoLibUInt64Array; ASize: Int32);
+constructor TF2mCurve.TDefaultF2mLookupTable.Create(const AOuter: TF2mCurve; const ATable: TCryptoLibUInt64Array; ASize: Int32);
 begin
   Inherited Create();
   FOuter := AOuter;
@@ -346,18 +357,18 @@ begin
   FSize := ASize;
 end;
 
-function TDefaultF2mLookupTable.GetSize: Int32;
+function TF2mCurve.TDefaultF2mLookupTable.GetSize: Int32;
 begin
   Result := FSize;
 end;
 
-function TDefaultF2mLookupTable.Lookup(AIndex: Int32): IECPoint;
+function TF2mCurve.TDefaultF2mLookupTable.Lookup(AIndex: Int32): IECPoint;
 var
   LFeLongs, LPos, I, J: Int32;
   LMask: UInt64;
   LX, LY: TCryptoLibUInt64Array;
 begin
-  LFeLongs := (FOuter.FM + 63) div 64;
+  LFeLongs := (FOuter.M + 63) div 64;
   System.SetLength(LX, LFeLongs);
   System.SetLength(LY, LFeLongs);
   LPos := 0;
@@ -378,12 +389,12 @@ begin
   Result := CreatePoint(LX, LY);
 end;
 
-function TDefaultF2mLookupTable.LookupVar(AIndex: Int32): IECPoint;
+function TF2mCurve.TDefaultF2mLookupTable.LookupVar(AIndex: Int32): IECPoint;
 var
   LFeLongs, LPos, J: Int32;
   LX, LY: TCryptoLibUInt64Array;
 begin
-  LFeLongs := (FOuter.FM + 63) div 64;
+  LFeLongs := (FOuter.M + 63) div 64;
   System.SetLength(LX, LFeLongs);
   System.SetLength(LY, LFeLongs);
   LPos := AIndex * LFeLongs * 2;
@@ -397,17 +408,17 @@ begin
   Result := CreatePoint(LX, LY);
 end;
 
-function TDefaultF2mLookupTable.CreatePoint(const AX, AY: TCryptoLibUInt64Array): IECPoint;
+function TF2mCurve.TDefaultF2mLookupTable.CreatePoint(const AX, AY: TCryptoLibUInt64Array): IECPoint;
 var
   LKs: TCryptoLibInt32Array;
   LXfe, LYfe: IECFieldElement;
 begin
   if FOuter.IsTrinomial then
-    LKs := TCryptoLibInt32Array.Create(FOuter.FK1)
+    LKs := TCryptoLibInt32Array.Create(FOuter.K1)
   else
-    LKs := TCryptoLibInt32Array.Create(FOuter.FK1, FOuter.FK2, FOuter.FK3);
-  LXfe := TF2mFieldElement.Create(FOuter.FM, LKs, TLongArray.Create(AX));
-  LYfe := TF2mFieldElement.Create(FOuter.FM, LKs, TLongArray.Create(AY));
+    LKs := TCryptoLibInt32Array.Create(FOuter.K1, FOuter.K2, FOuter.K3);
+  LXfe := TF2mFieldElement.Create(FOuter.M, LKs, TLongArray.Create(AX));
+  LYfe := TF2mFieldElement.Create(FOuter.M, LKs, TLongArray.Create(AY));
   Result := FOuter.CreateRawPoint(LXfe, LYfe);
 end;
 
@@ -702,9 +713,9 @@ begin
   FMultiplier := AMultiplier;
 end;
 
-{ TECCurveConfig }
+{ TECCurve.TECCurveConfig }
 
-constructor TECCurveConfig.Create(const AOuter: TECCurve; ACoord: Int32;
+constructor TECCurve.TECCurveConfig.Create(const AOuter: IECCurve; ACoord: Int32;
   const AEndomorphism: IECEndomorphism; const AMultiplier: IECMultiplier);
 begin
   inherited Create();
@@ -714,27 +725,27 @@ begin
   FMultiplier := AMultiplier;
 end;
 
-function TECCurveConfig.SetCoordinateSystem(ACoord: Int32): IECCurveConfig;
+function TECCurve.TECCurveConfig.SetCoordinateSystem(ACoord: Int32): IECCurveConfig;
 begin
   FCoord := ACoord;
   Result := Self;
 end;
 
-function TECCurveConfig.SetEndomorphism(const AEndomorphism: IECEndomorphism): IECCurveConfig;
+function TECCurve.TECCurveConfig.SetEndomorphism(const AEndomorphism: IECEndomorphism): IECCurveConfig;
 begin
   FEndomorphism := AEndomorphism;
   Result := Self;
 end;
 
-function TECCurveConfig.SetMultiplier(const AMultiplier: IECMultiplier): IECCurveConfig;
+function TECCurve.TECCurveConfig.SetMultiplier(const AMultiplier: IECMultiplier): IECCurveConfig;
 begin
   FMultiplier := AMultiplier;
   Result := Self;
 end;
 
-function TECCurveConfig.CreateCurve: IECCurve;
+function TECCurve.TECCurveConfig.CreateCurve: IECCurve;
 var
-  LClone: TECCurve;
+  LClone: IECCurve;
 begin
   if not FOuter.SupportsCoordinateSystem(FCoord) then
     raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
@@ -951,7 +962,7 @@ function TAbstractFpCurve.IsValidFieldElement(const AX: TBigInteger): Boolean;
 var
   LP: TBigInteger;
 begin
-  if (AX = nil) or (AX.SignValue < 0) then
+  if (not AX.IsInitialized) or (AX.SignValue < 0) then
     Exit(False);
   LP := FField.Characteristic;
   Result := AX.CompareTo(LP) < 0;
@@ -1028,7 +1039,7 @@ begin
   FCoord := FP_DEFAULT_COORDS;
 end;
 
-function TFpCurve.CloneCurve: TECCurve;
+function TFpCurve.CloneCurve: IECCurve;
 begin
   Result := TFpCurve.Create(FQ, FR, FA, FB, FOrder, FCofactor);
 end;
@@ -1067,7 +1078,7 @@ end;
 
 function TFpCurve.FromBigInteger(const AX: TBigInteger): IECFieldElement;
 begin
-  if (AX = nil) or (AX.SignValue < 0) or (AX.CompareTo(FQ) >= 0) then
+  if (not AX.IsInitialized) or (AX.SignValue < 0) or (AX.CompareTo(FQ) >= 0) then
     raise EArgumentCryptoLibException.Create('value invalid for Fp field element');
   Result := TFpFieldElement.Create(FQ, FR, AX);
 end;
@@ -1161,7 +1172,7 @@ end;
 
 function TAbstractF2mCurve.IsValidFieldElement(const AX: TBigInteger): Boolean;
 begin
-  Result := (AX <> nil) and (AX.SignValue >= 0) and (AX.BitLength <= GetFieldSize());
+  Result := (AX.IsInitialized) and (AX.SignValue >= 0) and (AX.BitLength <= GetFieldSize());
 end;
 
 function TAbstractF2mCurve.RandomFieldElement(const ARandom: ISecureRandom): IECFieldElement;
@@ -1234,13 +1245,13 @@ begin
   if (LM and 1) <> 0 then
   begin
     LR := LBetaF2m.HalfTrace();
-    if LFastTrace or LR.Square().Add(LR).Add(ABeta).GetIsZero then
+    if LFastTrace or LR.Square().Add(LR).Add(ABeta).IsZero then
       Exit(LR);
 
     Exit(nil);
   end;
 
-  if ABeta.GetIsZero then
+  if ABeta.IsZero then
     Exit(ABeta);
 
   LZeroElement := FromBigInteger(TBigInteger.Zero);
@@ -1255,10 +1266,10 @@ begin
       LZ := LZ.Square().Add(LW2.Multiply(LT));
       LW := LW2.Add(ABeta);
     end;
-    if not LW.GetIsZero then
+    if not LW.IsZero then
       Exit(nil);
     LGamma := LZ.Square().Add(LZ);
-  until not LGamma.GetIsZero;
+  until not LGamma.IsZero;
 
   Result := LZ;
 end;
@@ -1270,8 +1281,8 @@ end;
 
 function TAbstractF2mCurve.GetIsKoblitz: Boolean;
 begin
-  Result := (FOrder <> nil) and (FCofactor <> nil) and FB.IsOne
-    and (FA.GetIsZero or FA.IsOne);
+  Result := (FOrder.IsInitialized) and (FCofactor.IsInitialized) and FB.IsOne
+    and (FA.IsZero or FA.IsOne);
 end;
 
 { TF2mCurve }
@@ -1320,7 +1331,7 @@ begin
   FCoord := F2M_DEFAULT_COORDS;
 end;
 
-function TF2mCurve.CloneCurve: TECCurve;
+function TF2mCurve.CloneCurve: IECCurve;
 begin
   Result := TF2mCurve.Create(FM, FK1, FK2, FK3, FA, FB, FOrder, FCofactor);
 end;
@@ -1339,7 +1350,7 @@ function TF2mCurve.FromBigInteger(const AX: TBigInteger): IECFieldElement;
 var
   LX: TLongArray;
 begin
-  if (AX = nil) or (AX.SignValue < 0) or (AX.BitLength > FM) then
+  if (not AX.IsInitialized) or (AX.SignValue < 0) or (AX.BitLength > FM) then
     raise EArgumentCryptoLibException.Create('value invalid for F2m field element');
 
   LX := TLongArray.Create(AX);

+ 7 - 0
CryptoLib/src/Math/EC/ClpECCurveConstants.pas

@@ -6,8 +6,15 @@
 { *  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 ClpECCurveConstants;
 
 {$I ..\..\Include\CryptoLib.inc}

+ 3 - 1
CryptoLib/src/Math/EC/ClpECFieldElement.pas

@@ -13,6 +13,8 @@
 
 { * ******************************************************************************* * }
 
+(* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
+
 unit ClpECFieldElement;
 
 {$I ..\..\Include\CryptoLib.inc}
@@ -75,7 +77,7 @@ type
     property IsZero: Boolean read GetIsZero;
   end;
 
-  TAbstractFpFieldElement = class abstract(TECFieldElement)
+  TAbstractFpFieldElement = class abstract(TECFieldElement, IAbstractFpFieldElement)
   end;
 
   TFpFieldElement = class sealed(TAbstractFpFieldElement, IECFieldElement, IFpFieldElement)

+ 18 - 3
CryptoLib/src/Math/EC/ClpSimpleLookupTable.pas → CryptoLib/src/Math/EC/ClpECLookupTables.pas

@@ -15,7 +15,7 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpSimpleLookupTable;
+unit ClpECLookupTables;
 
 {$I ..\..\Include\CryptoLib.inc}
 
@@ -24,14 +24,22 @@ interface
 uses
   SysUtils,
   ClpIECCore,
-  ClpAbstractECLookupTable,
   ClpCryptoLibTypes;
 
 resourcestring
   SConstantTimeLookupNotSupported = 'Constant-time lookup not supported';
 
 type
-  TSimpleLookupTable = class(TAbstractECLookupTable, ISimpleLookupTable)
+  TAbstractECLookupTable = class abstract(TInterfacedObject, IECLookupTable)
+  public
+    function Lookup(AIndex: Int32): IECPoint; virtual; abstract;
+    function GetSize: Int32; virtual; abstract;
+    function LookupVar(AIndex: Int32): IECPoint; virtual;
+    property Size: Int32 read GetSize;
+  end;
+
+type
+  TSimpleLookupTable = class(TAbstractECLookupTable, IECLookupTable)
   strict private
     FPoints: TCryptoLibGenericArray<IECPoint>;
 
@@ -46,6 +54,13 @@ type
 
 implementation
 
+{ TAbstractECLookupTable }
+
+function TAbstractECLookupTable.LookupVar(AIndex: Int32): IECPoint;
+begin
+  Result := Lookup(AIndex);
+end;
+
 { TSimpleLookupTable }
 
 class function TSimpleLookupTable.CopyPoints(const APoints: TCryptoLibGenericArray<IECPoint>;

+ 55 - 43
CryptoLib/src/Math/EC/ClpECPoint.pas

@@ -6,8 +6,15 @@
 { *  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 ClpECPoint;
 
 {$I ..\..\Include\CryptoLib.inc}
@@ -18,6 +25,12 @@ uses
   SysUtils,
   SyncObjs,
   Generics.Collections,
+  ClpBitOperations,
+  ClpECAlgorithms,
+  ClpECFieldElement,
+  ClpECCurveConstants,
+  ClpIValidityPreCompInfo,
+  ClpValidityPreCompInfo,
   ClpBigInteger,
   ClpIECCore,
   ClpIECFieldElement,
@@ -27,9 +40,29 @@ uses
   ClpSecureRandom,
   ClpCryptoLibTypes;
 
+resourcestring
+  SPointNotInNormalForm = 'point not in normal form';
+  SUnknownCoordinateSystem = 'unknown coordinate system';
+  SUnsupportedCoordinateSystem = 'unsupported coordinate system';
+  SDetachedPointsMustBeInAffine = 'Detached points must be in affine coordinates';
+  SNotAProjectiveCoordinateSystem = 'not a projective coordinate system';
+  SInvalidTimesPow2Exponent = 'exponent cannot be negative';
+
 type
   TECPoint = class abstract(TInterfacedObject, IECPoint)
   strict private
+type
+  TValidityCallback = class sealed(TInterfacedObject, IPreCompCallback)
+  strict private
+    FOuter: IECPoint;
+    FDecompressed: Boolean;
+    FCheckOrder: Boolean;
+  public
+    constructor Create(const AOuter: IECPoint; ADecompressed, ACheckOrder: Boolean);
+    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+  end;
+
+  var
     FPreCompTable: TDictionary<String, IPreCompInfo>;
     FPointLock: TCriticalSection;
     FTableLock: TCriticalSection;
@@ -56,6 +89,8 @@ type
     function GetIsInfinity: Boolean; virtual;
     function GetXCoord: IECFieldElement; virtual;
     function GetYCoord: IECFieldElement; virtual;
+    property XCoord: IECFieldElement read GetXCoord;
+    property YCoord: IECFieldElement read GetYCoord;
     function GetRawXCoord: IECFieldElement; virtual;
     function GetRawYCoord: IECFieldElement; virtual;
     function GetZCoord(AIndex: Int32): IECFieldElement; virtual;
@@ -180,34 +215,11 @@ type
 implementation
 
 uses
-  ClpECAlgorithms,
-  ClpECFieldElement,
-  ClpECCurveConstants,
-  ClpIValidityPreCompInfo,
-  ClpValidityPreCompInfo,
   ClpECCurve;
 
-resourcestring
-  SPointNotInNormalForm = 'point not in normal form';
-  SUnknownCoordinateSystem = 'unknown coordinate system';
-  SDetachedPointsMustBeInAffine = 'Detached points must be in affine coordinates';
-  SNotAProjectiveCoordinateSystem = 'not a projective coordinate system';
-  SInvalidTimesPow2Exponent = 'exponent cannot be negative';
-
-{ TValidityCallback }
-
-type
-  TValidityCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FOuter: IECPoint;
-    FDecompressed: Boolean;
-    FCheckOrder: Boolean;
-  public
-    constructor Create(const AOuter: IECPoint; ADecompressed, ACheckOrder: Boolean);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
+{ TECPoint.TValidityCallback }
 
-constructor TValidityCallback.Create(const AOuter: IECPoint; ADecompressed,
+constructor TECPoint.TValidityCallback.Create(const AOuter: IECPoint; ADecompressed,
   ACheckOrder: Boolean);
 begin
   inherited Create;
@@ -216,7 +228,7 @@ begin
   FCheckOrder := ACheckOrder;
 end;
 
-function TValidityCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+function TECPoint.TValidityCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
 var
   LValidity: IValidityPreCompInfo;
 begin
@@ -824,7 +836,7 @@ begin
         end;
       end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
   Rhs := X.Square().Add(A).Multiply(X).Add(B);
   Result := Lhs.Equals(Rhs);
@@ -967,7 +979,7 @@ var
   LVSquared, LVCubed, LVSquaredV2, LA: IECFieldElement;
   LZ1IsOne, LZ2IsOne: Boolean;
   LZ1Squared, LS2, LZ2Squared, LS1, LH, LR: IECFieldElement;
-  LHSquared, LG, LV2: IECFieldElement;
+  LHSquared, LG: IECFieldElement;
   LZ1Cubed, LZ2Cubed, LU2b, LS2b, LU1b, LS1b: IECFieldElement;
   LC, LW1, LW2b, LA1: IECFieldElement;
   LZ3Squared, LW3: IECFieldElement;
@@ -1157,7 +1169,7 @@ begin
       Result := TFpPoint.Create(LCurve, X3, Y3, LZs);
     end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -1274,7 +1286,7 @@ begin
       Result := TwiceJacobianModified(True);
     end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -1283,7 +1295,7 @@ var
   LCurve: IECCurve;
   LCoord: Int32;
   X1, Y1, X2, Y2, Dx, Dy: IECFieldElement;
-  LX, LY, Ld, LD, LI, LL1, LL2, X4, Y4: IECFieldElement;
+  LX, LY, Ld, LBigD, LI, LL1, LL2, X4, Y4: IECFieldElement;
 begin
   if (Self as IECPoint) = AB then
     Exit(ThreeTimes());
@@ -1322,8 +1334,8 @@ begin
       if Ld.GetIsZero then
         Exit(LCurve.Infinity);
 
-      LD := Ld.Multiply(Dx);
-      LI := LD.Invert();
+      LBigD := Ld.Multiply(Dx);
+      LI := LBigD.Invert();
       LL1 := Ld.Multiply(LI).Multiply(Dy);
       LL2 := Two(Y1).Multiply(LX).Multiply(Dx).Multiply(LI).Subtract(LL1);
       X4 := LL2.Subtract(LL1).Multiply(LL1.Add(LL2)).Add(X2);
@@ -1346,7 +1358,7 @@ var
   LCurve: IECCurve;
   LCoord: Int32;
   X1, Y1: IECFieldElement;
-  L2Y1, LX, LZ, LY, Ld, LD, LI, LL1, LL2, X4, Y4: IECFieldElement;
+  L2Y1, LX, LZ, LY, Ld, LBigD, LI, LL1, LL2, X4, Y4: IECFieldElement;
 begin
   if GetIsInfinity then
     Exit(Self as IECPoint);
@@ -1372,8 +1384,8 @@ begin
       if Ld.GetIsZero then
         Exit(LCurve.Infinity);
 
-      LD := Ld.Multiply(L2Y1);
-      LI := LD.Invert();
+      LBigD := Ld.Multiply(L2Y1);
+      LI := LBigD.Invert();
       LL1 := Ld.Multiply(LI).Multiply(LZ);
       LL2 := LX.Square().Multiply(LI).Subtract(LL1);
 
@@ -1494,7 +1506,7 @@ begin
         TCryptoLibGenericArray<IECFieldElement>.Create(Z1, W1));
     end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -1583,7 +1595,7 @@ begin
         end;
       end;
     else
-      raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+      raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
     end;
 
     Rhs := X.Add(A).Multiply(X.Square()).Add(B);
@@ -1750,7 +1762,7 @@ begin
         TCryptoLibGenericArray<IECFieldElement>.Create(LZ1.Square())) as IAbstractF2mPoint;
     end
   else
-    raise EInvalidOperationCryptoLibException.Create('unsupported coordinate system');
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -1784,7 +1796,7 @@ begin
         TCryptoLibGenericArray<IECFieldElement>.Create(LZ1.SquarePow(APow))) as IAbstractF2mPoint;
     end
   else
-    raise EInvalidOperationCryptoLibException.Create('unsupported coordinate system');
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -2045,7 +2057,7 @@ begin
         TCryptoLibGenericArray<IECFieldElement>.Create(Z3));
     end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -2145,7 +2157,7 @@ begin
         TCryptoLibGenericArray<IECFieldElement>.Create(Z3));
     end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 
@@ -2256,7 +2268,7 @@ begin
         TCryptoLibGenericArray<IECFieldElement>.Create(LZ));
     end;
   else
-    raise EInvalidOperationCryptoLibException.Create(SUnknownCoordinateSystem);
+    raise EInvalidOperationCryptoLibException.Create(SUnsupportedCoordinateSystem);
   end;
 end;
 

+ 111 - 0
CryptoLib/src/Math/EC/ClpECPointMaps.pas

@@ -0,0 +1,111 @@
+{ *********************************************************************************** }
+{ *                              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.           * }
+
+{ * ******************************************************************************* * }
+
+unit ClpECPointMaps;
+
+{$I ..\..\Include\CryptoLib.inc}
+
+interface
+
+uses
+  ClpIECCore,
+  ClpIECFieldElement;
+
+type
+  TScaleXPointMap = class(TInterfacedObject, IECPointMap)
+  strict protected
+    FScale: IECFieldElement;
+  public
+    constructor Create(const AScale: IECFieldElement);
+    function Map(const AP: IECPoint): IECPoint; virtual;
+  end;
+
+type
+  TScaleYPointMap = class(TInterfacedObject, IECPointMap)
+  strict protected
+    FScale: IECFieldElement;
+  public
+    constructor Create(const AScale: IECFieldElement);
+    function Map(const AP: IECPoint): IECPoint; virtual;
+  end;
+
+type
+  TScaleXNegateYPointMap = class(TInterfacedObject, IECPointMap)
+  strict protected
+    FScale: IECFieldElement;
+  public
+    constructor Create(const AScale: IECFieldElement);
+    function Map(const AP: IECPoint): IECPoint; virtual;
+  end;
+
+type
+  TScaleYNegateXPointMap = class(TInterfacedObject, IECPointMap)
+  strict protected
+    FScale: IECFieldElement;
+  public
+    constructor Create(const AScale: IECFieldElement);
+    function Map(const AP: IECPoint): IECPoint; virtual;
+  end;
+
+implementation
+
+{ TScaleXPointMap }
+
+constructor TScaleXPointMap.Create(const AScale: IECFieldElement);
+begin
+  Inherited Create;
+  FScale := AScale;
+end;
+
+function TScaleXPointMap.Map(const AP: IECPoint): IECPoint;
+begin
+  Result := AP.ScaleX(FScale);
+end;
+
+{ TScaleYPointMap }
+
+constructor TScaleYPointMap.Create(const AScale: IECFieldElement);
+begin
+  Inherited Create;
+  FScale := AScale;
+end;
+
+function TScaleYPointMap.Map(const AP: IECPoint): IECPoint;
+begin
+  Result := AP.ScaleY(FScale);
+end;
+
+{ TScaleXNegateYPointMap }
+
+constructor TScaleXNegateYPointMap.Create(const AScale: IECFieldElement);
+begin
+  Inherited Create;
+  FScale := AScale;
+end;
+
+function TScaleXNegateYPointMap.Map(const AP: IECPoint): IECPoint;
+begin
+  Result := AP.ScaleXNegateY(FScale);
+end;
+
+{ TScaleYNegateXPointMap }
+
+constructor TScaleYNegateXPointMap.Create(const AScale: IECFieldElement);
+begin
+  Inherited Create;
+  FScale := AScale;
+end;
+
+function TScaleYNegateXPointMap.Map(const AP: IECPoint): IECPoint;
+begin
+  Result := AP.ScaleYNegateX(FScale);
+end;
+
+end.

+ 0 - 43
CryptoLib/src/Math/EC/ClpScaleXNegateYPointMap.pas

@@ -1,43 +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.           * }
-
-{ * ******************************************************************************* * }
-
-unit ClpScaleXNegateYPointMap;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIECCore,
-  ClpIECFieldElement;
-
-type
-  TScaleXNegateYPointMap = class(TInterfacedObject, IECPointMap)
-  strict protected
-    FScale: IECFieldElement;
-  public
-    constructor Create(const AScale: IECFieldElement);
-    function Map(const AP: IECPoint): IECPoint; virtual;
-  end;
-
-implementation
-
-constructor TScaleXNegateYPointMap.Create(const AScale: IECFieldElement);
-begin
-  Inherited Create;
-  FScale := AScale;
-end;
-
-function TScaleXNegateYPointMap.Map(const AP: IECPoint): IECPoint;
-begin
-  Result := AP.ScaleXNegateY(FScale);
-end;
-
-end.

+ 0 - 43
CryptoLib/src/Math/EC/ClpScaleXPointMap.pas

@@ -1,43 +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.           * }
-
-{ * ******************************************************************************* * }
-
-unit ClpScaleXPointMap;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIECCore,
-  ClpIECFieldElement;
-
-type
-  TScaleXPointMap = class(TInterfacedObject, IECPointMap)
-  strict protected
-    FScale: IECFieldElement;
-  public
-    constructor Create(const AScale: IECFieldElement);
-    function Map(const AP: IECPoint): IECPoint; virtual;
-  end;
-
-implementation
-
-constructor TScaleXPointMap.Create(const AScale: IECFieldElement);
-begin
-  Inherited Create;
-  FScale := AScale;
-end;
-
-function TScaleXPointMap.Map(const AP: IECPoint): IECPoint;
-begin
-  Result := AP.ScaleX(FScale);
-end;
-
-end.

+ 0 - 50
CryptoLib/src/Math/EC/ClpScaleYNegateXPointMap.pas

@@ -1,50 +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 ClpScaleYNegateXPointMap;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIECCore,
-  ClpIECFieldElement;
-
-type
-  TScaleYNegateXPointMap = class(TInterfacedObject, IECPointMap)
-  strict protected
-    FScale: IECFieldElement;
-  public
-    constructor Create(const AScale: IECFieldElement);
-    function Map(const AP: IECPoint): IECPoint; virtual;
-  end;
-
-implementation
-
-{ TScaleYNegateXPointMap }
-
-constructor TScaleYNegateXPointMap.Create(const AScale: IECFieldElement);
-begin
-  Inherited Create;
-  FScale := AScale;
-end;
-
-function TScaleYNegateXPointMap.Map(const AP: IECPoint): IECPoint;
-begin
-  Result := AP.ScaleYNegateX(FScale);
-end;
-
-end.

+ 0 - 50
CryptoLib/src/Math/EC/ClpScaleYPointMap.pas

@@ -1,50 +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 ClpScaleYPointMap;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIECCore,
-  ClpIECFieldElement;
-
-type
-  TScaleYPointMap = class(TInterfacedObject, IECPointMap)
-  strict protected
-    FScale: IECFieldElement;
-  public
-    constructor Create(const AScale: IECFieldElement);
-    function Map(const AP: IECPoint): IECPoint; virtual;
-  end;
-
-implementation
-
-{ TScaleYPointMap }
-
-constructor TScaleYPointMap.Create(const AScale: IECFieldElement);
-begin
-  Inherited Create;
-  FScale := AScale;
-end;
-
-function TScaleYPointMap.Map(const AP: IECPoint): IECPoint;
-begin
-  Result := AP.ScaleY(FScale);
-end;
-
-end.

+ 17 - 0
CryptoLib/src/Math/EC/Endo/ClpEndoPreCompInfo.pas

@@ -1,3 +1,20 @@
+{ *********************************************************************************** }
+{ *                              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 ClpEndoPreCompInfo;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 36 - 17
CryptoLib/src/Math/EC/Endo/ClpEndoUtilities.pas

@@ -1,3 +1,20 @@
+{ *********************************************************************************** }
+{ *                              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 ClpEndoUtilities;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -5,6 +22,7 @@ unit ClpEndoUtilities;
 interface
 
 uses
+  SysUtils,
   ClpBigInteger,
   ClpIECCore,
   ClpIPreCompCallback,
@@ -16,6 +34,18 @@ uses
 
 type
   TEndoUtilities = class sealed(TObject)
+  strict private
+    type
+      TMapPointCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FEndomorphism: IECEndomorphism;
+        FPoint: IECPoint;
+        function CheckExisting(const AExistingEndo: IEndoPreCompInfo;
+          const AEndomorphism: IECEndomorphism): Boolean;
+      public
+        constructor Create(const AEndomorphism: IECEndomorphism; const APoint: IECPoint);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
   public
     const PRECOMP_NAME = 'bc_endo';
     class function DecomposeScalar(const AP: IScalarSplitParameters;
@@ -29,19 +59,7 @@ type
 
 implementation
 
-type
-  TMapPointCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FEndomorphism: IECEndomorphism;
-    FPoint: IECPoint;
-    function CheckExisting(const AExistingEndo: IEndoPreCompInfo;
-      const AEndomorphism: IECEndomorphism): Boolean;
-  public
-    constructor Create(const AEndomorphism: IECEndomorphism; const APoint: IECPoint);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
-
-constructor TMapPointCallback.Create(const AEndomorphism: IECEndomorphism;
+constructor TEndoUtilities.TMapPointCallback.Create(const AEndomorphism: IECEndomorphism;
   const APoint: IECPoint);
 begin
   inherited Create;
@@ -49,14 +67,14 @@ begin
   FPoint := APoint;
 end;
 
-function TMapPointCallback.CheckExisting(const AExistingEndo: IEndoPreCompInfo;
+function TEndoUtilities.TMapPointCallback.CheckExisting(const AExistingEndo: IEndoPreCompInfo;
   const AEndomorphism: IECEndomorphism): Boolean;
 begin
   Result := (AExistingEndo <> nil) and (AExistingEndo.Endomorphism = AEndomorphism) and
     (AExistingEndo.MappedPoint <> nil);
 end;
 
-function TMapPointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+function TEndoUtilities.TMapPointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
 var
   LExistingEndo: IEndoPreCompInfo;
   LResult: TEndoPreCompInfo;
@@ -109,9 +127,10 @@ class function TEndoUtilities.MapPoint(const AEndomorphism: IECEndomorphism;
 var
   LPrecomp: IPreCompInfo;
   LEndo: IEndoPreCompInfo;
+  LPreCompCallback: IPreCompCallback;
 begin
-  LPrecomp := AP.Curve.Precompute(AP, PRECOMP_NAME,
-    TMapPointCallback.Create(AEndomorphism, AP) as IPreCompCallback);
+  LPreCompCallback := TEndoUtilities.TMapPointCallback.Create(AEndomorphism, AP);
+  LPrecomp := AP.Curve.Precompute(AP, PRECOMP_NAME, LPreCompCallback);
   if not Supports(LPrecomp, IEndoPreCompInfo, LEndo) then
     raise EInvalidCastCryptoLibException.Create('Expected EndoPreCompInfo');
   Result := LEndo.MappedPoint;

+ 9 - 4
CryptoLib/src/Math/EC/Endo/ClpGlvTypeBEndomorphism.pas

@@ -6,8 +6,15 @@
 { *  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 ClpGlvTypeBEndomorphism;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -19,6 +26,8 @@ uses
   ClpIECCore,
   ClpIGlvTypeBParameters,
   ClpIGlvTypeBEndomorphism,
+  ClpEndoUtilities,
+  ClpECPointMaps,
   ClpCryptoLibTypes;
 
 type
@@ -37,10 +46,6 @@ type
 
 implementation
 
-uses
-  ClpEndoUtilities,
-  ClpScaleXPointMap;
-
 { TGlvTypeBEndomorphism }
 
 constructor TGlvTypeBEndomorphism.Create(const ACurve: IECCurve;

+ 7 - 0
CryptoLib/src/Math/EC/Endo/ClpGlvTypeBParameters.pas

@@ -6,8 +6,15 @@
 { *  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 ClpGlvTypeBParameters;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Math/EC/Endo/ClpScalarSplitParameters.pas

@@ -6,8 +6,15 @@
 { *  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 ClpScalarSplitParameters;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Math/EC/Multiplier/ClpFixedPointPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpFixedPointPreCompInfo;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 31 - 22
CryptoLib/src/Math/EC/Multiplier/ClpFixedPointUtilities.pas

@@ -6,8 +6,15 @@
 { *  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 ClpFixedPointUtilities;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -15,15 +22,28 @@ unit ClpFixedPointUtilities;
 interface
 
 uses
+  SysUtils,
   ClpBigInteger,
   ClpIECCore,
   ClpIPreCompCallback,
   ClpIPreCompInfo,
   ClpIFixedPointPreCompInfo,
+  ClpFixedPointPreCompInfo,
   ClpCryptoLibTypes;
 
 type
   TFixedPointUtilities = class sealed(TObject)
+  strict private
+    type
+      TFixedPointCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FP: IECPoint;
+        function CheckExisting(const AExistingFP: IFixedPointPreCompInfo; AN: Int32): Boolean;
+        function CheckTable(const ATable: IECLookupTable; AN: Int32): Boolean;
+      public
+        constructor Create(const AP: IECPoint);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
   public
     const PRECOMP_NAME = 'bc_fixed_point';
     class function GetCombSize(const AC: IECCurve): Int32; static;
@@ -33,46 +53,32 @@ type
 
 implementation
 
-uses
-  ClpFixedPointPreCompInfo,
-  ClpECCurve,
-  ClpCryptoLibTypes;
+{ TFixedPointUtilities.TFixedPointCallback }
 
-type
-  TFixedPointCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FP: IECPoint;
-    function CheckExisting(const AExistingFP: IFixedPointPreCompInfo; AN: Int32): Boolean;
-    function CheckTable(const ATable: IECLookupTable; AN: Int32): Boolean;
-  public
-    constructor Create(const AP: IECPoint);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
-
-constructor TFixedPointCallback.Create(const AP: IECPoint);
+constructor TFixedPointUtilities.TFixedPointCallback.Create(const AP: IECPoint);
 begin
   Inherited Create;
   FP := AP;
 end;
 
-function TFixedPointCallback.CheckTable(const ATable: IECLookupTable; AN: Int32): Boolean;
+function TFixedPointUtilities.TFixedPointCallback.CheckTable(const ATable: IECLookupTable; AN: Int32): Boolean;
 begin
   Result := (ATable <> nil) and (ATable.Size >= AN);
 end;
 
-function TFixedPointCallback.CheckExisting(const AExistingFP: IFixedPointPreCompInfo; AN: Int32): Boolean;
+function TFixedPointUtilities.TFixedPointCallback.CheckExisting(const AExistingFP: IFixedPointPreCompInfo; AN: Int32): Boolean;
 begin
   Result := (AExistingFP <> nil) and CheckTable(AExistingFP.LookupTable, AN);
 end;
 
-function TFixedPointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+function TFixedPointUtilities.TFixedPointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
 var
   LExistingFP: IFixedPointPreCompInfo;
   LC: IECCurve;
   LBits, LMinWidth, LN, LD, LBit, LStep, LI: Int32;
   LPow2Table, LLookupTable: TCryptoLibGenericArray<IECPoint>;
   LPow2: IECPoint;
-  LResult: TFixedPointPreCompInfo;
+  LResult: IFixedPointPreCompInfo;
 begin
   if not Supports(AExisting, IFixedPointPreCompInfo, LExistingFP) then
     LExistingFP := nil;
@@ -122,6 +128,8 @@ begin
   Result := LResult;
 end;
 
+{ TFixedPointUtilities }
+
 class function TFixedPointUtilities.GetCombSize(const AC: IECCurve): Int32;
 var
   LOrder: TBigInteger;
@@ -147,9 +155,10 @@ class function TFixedPointUtilities.Precompute(const AP: IECPoint): IFixedPointP
 var
   LPrecomp: IPreCompInfo;
   LFP: IFixedPointPreCompInfo;
+  LPrecompCallback: IPreCompCallback;
 begin
-  LPrecomp := AP.Curve.Precompute(AP, PRECOMP_NAME,
-    TFixedPointCallback.Create(AP) as IPreCompCallback);
+  LPrecompCallback := TFixedPointUtilities.TFixedPointCallback.Create(AP);
+  LPrecomp := AP.Curve.Precompute(AP, PRECOMP_NAME, LPrecompCallback);
   if Supports(LPrecomp, IFixedPointPreCompInfo, LFP) then
     Result := LFP
   else

+ 24 - 19
CryptoLib/src/Math/EC/Multiplier/ClpMultipliers.pas

@@ -6,8 +6,15 @@
 { *  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 ClpMultipliers;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -15,6 +22,18 @@ unit ClpMultipliers;
 interface
 
 uses
+  SysUtils,
+  Math,
+  ClpECAlgorithms,
+  ClpECPoint,
+  ClpEndoUtilities,
+  ClpFixedPointUtilities,
+  ClpIFixedPointPreCompInfo,
+  ClpNat,
+  ClpBitOperations,
+  ClpTnaf,
+  ClpIWTauNafPreCompInfo,
+  ClpWTauNafPreCompInfo,
   ClpBigInteger,
   ClpIECCore,
   ClpIECFieldElement,
@@ -34,7 +53,7 @@ type
     function Multiply(const APoint: IECPoint; const AK: TBigInteger): IECPoint; virtual;
   end;
 
-  TWNafL2RMultiplier = class sealed(TAbstractECMultiplier, IECMultiplier, IWNafL2RMultiplier)
+  TWNafL2RMultiplier = class sealed(TAbstractECMultiplier, IECMultiplier)
   strict protected
     function MultiplyPositive(const AP: IECPoint; const AK: TBigInteger): IECPoint; override;
   end;
@@ -68,20 +87,6 @@ type
 
 implementation
 
-uses
-  System.Math,
-  ClpCryptoLibTypes,
-  ClpECAlgorithms,
-  ClpECPoint,
-  ClpEndoUtilities,
-  ClpFixedPointUtilities,
-  ClpIFixedPointPreCompInfo,
-  ClpNat,
-  ClpBitOperations,
-  ClpTnaf,
-  ClpIWTauNafPreCompInfo,
-  ClpWTauNafPreCompInfo;
-
 { TAbstractECMultiplier }
 
 function TAbstractECMultiplier.CheckResult(const AP: IECPoint): IECPoint;
@@ -133,7 +138,7 @@ begin
     LDigit := TBitOperations.Asr32(LWi, 16);
     LZeroes := LWi and $FFFF;
 
-    LN := System.Math.Abs(LDigit);
+    LN := System.Abs(LDigit);
     if LDigit < 0 then
       LTable := LPreCompNeg
     else
@@ -162,7 +167,7 @@ begin
     LDigit := TBitOperations.Asr32(LWi, 16);
     LZeroes := LWi and $FFFF;
 
-    LN := System.Math.Abs(LDigit);
+    LN := System.Abs(LDigit);
     if LDigit < 0 then
       LTable := LPreCompNeg
     else
@@ -197,7 +202,7 @@ begin
   if not FCurve.Equals(AP.Curve) then
     raise EInvalidOperationCryptoLibException.Create('');
   LN := AP.Curve.Order;
-  LAB := FGlvEndomorphism.DecomposeScalar(AK.Mod(LN));
+  LAB := FGlvEndomorphism.DecomposeScalar(AK.&Mod(LN));
   LA := LAB[0];
   LB := LAB[1];
   if FGlvEndomorphism.HasEfficientPointMap then
@@ -231,7 +236,7 @@ end;
 function TWTauNafCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
 var
   LExisting: IWTauNafPreCompInfo;
-  LResult: TWTauNafPreCompInfo;
+  LResult: IWTauNafPreCompInfo;
 begin
   if Supports(AExisting, IWTauNafPreCompInfo, LExisting) then
     Exit(AExisting);

+ 7 - 0
CryptoLib/src/Math/EC/Multiplier/ClpValidityPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpValidityPreCompInfo;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 7 - 0
CryptoLib/src/Math/EC/Multiplier/ClpWNafPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpWNafPreCompInfo;
 
 {$I ..\..\..\Include\CryptoLib.inc}

+ 365 - 307
CryptoLib/src/Math/EC/Multiplier/ClpWNafUtilities.pas

@@ -6,8 +6,15 @@
 { *  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 ClpWNafUtilities;
 
 {$I ..\..\..\Include\CryptoLib.inc}
@@ -15,8 +22,17 @@ unit ClpWNafUtilities;
 interface
 
 uses
+  SysUtils,
+  Math,
+  ClpArrayUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpIECCore,
+  ClpECCurve,
+  ClpECCurveConstants,
+  ClpECAlgorithms,
+  ClpECPoint,
+  ClpIECFieldElement,
   ClpIPreCompCallback,
   ClpIPreCompInfo,
   ClpIWNafPreCompInfo,
@@ -26,14 +42,62 @@ uses
 type
   TWNafUtilities = class sealed(TObject)
   strict private
+    type
+      TConfigureBasepointCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FCurve: IECCurve;
+        FConfWidth: Int32;
+      public
+        constructor Create(const ACurve: IECCurve; AConfWidth: Int32);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
+
+      TMapPointCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FInfoP: IWNafPreCompInfo;
+        FIncludeNegated: Boolean;
+        FPointMap: IECPointMap;
+      public
+        constructor Create(const AInfoP: IWNafPreCompInfo; AIncludeNegated: Boolean;
+          const APointMap: IECPointMap);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
+
+      TPrecomputeCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FP: IECPoint;
+        FMinWidth: Int32;
+        FIncludeNegated: Boolean;
+        function CheckExisting(const AExistingWNaf: IWNafPreCompInfo; AWidth, AReqPreCompLen: Int32;
+          AIncludeNegated: Boolean): Boolean;
+        function CheckTable(const ATable: TCryptoLibGenericArray<IECPoint>; AReqLen: Int32): Boolean;
+      public
+        constructor Create(const AP: IECPoint; AMinWidth: Int32; AIncludeNegated: Boolean);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
+
+      TPrecomputeWithPointMapCallback = class sealed(TInterfacedObject, IPreCompCallback)
+      strict private
+        FPoint: IECPoint;
+        FPointMap: IECPointMap;
+        FFromWNaf: IWNafPreCompInfo;
+        FIncludeNegated: Boolean;
+        function CheckTable(const ATable: TCryptoLibGenericArray<IECPoint>; AReqLen: Int32): Boolean;
+        function CheckExisting(const AExistingWNaf: IWNafPreCompInfo; AWidth, AReqPreCompLen: Int32;
+          AIncludeNegated: Boolean): Boolean;
+      public
+        constructor Create(const APoint: IECPoint; const APointMap: IECPointMap;
+          const AFromWNaf: IWNafPreCompInfo; AIncludeNegated: Boolean);
+        function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+      end;
+
     class var
       FDefaultWindowSizeCutoffs: TCryptoLibInt32Array;
     class function GetWindowSize(ABits: Int32; const AWindowSizeCutoffs: TCryptoLibInt32Array;
       AMaxWidth: Int32): Int32; overload; static;
-    class function Trim(const AArray: TCryptoLibInt32Array; ALength: Int32): TCryptoLibInt32Array; static;
-    class function TrimBytes(const AArray: TCryptoLibByteArray; ALength: Int32): TCryptoLibByteArray; static;
-    class function ResizeTable(const AArray: TCryptoLibGenericArray<IECPoint>;
-      ALength: Int32): TCryptoLibGenericArray<IECPoint>; static;
+    class function Trim(const AArray: TCryptoLibInt32Array; ALength: Int32): TCryptoLibInt32Array; overload; static;
+    class function Trim(const AArray: TCryptoLibByteArray; ALength: Int32): TCryptoLibByteArray; overload; static;
+    class function ResizeTable(const AArray: TCryptoLibGenericArray<IECPoint>; ALength: Int32): TCryptoLibGenericArray<IECPoint>; static;
   public
     const
       PRECOMP_NAME = 'bc_wnaf';
@@ -59,33 +123,14 @@ type
 
 implementation
 
-uses
-  System.Math,
-  ClpArrayUtilities,
-  ClpBitOperations,
-  ClpECCurve,
-  ClpECCurveConstants,
-  ClpECAlgorithms,
-  ClpECPoint;
-
-type
-  TConfigureBasepointCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FCurve: IECCurve;
-    FConfWidth: Int32;
-  public
-    constructor Create(const ACurve: IECCurve; AConfWidth: Int32);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
-
-constructor TConfigureBasepointCallback.Create(const ACurve: IECCurve; AConfWidth: Int32);
+constructor TWNafUtilities.TConfigureBasepointCallback.Create(const ACurve: IECCurve; AConfWidth: Int32);
 begin
   Inherited Create;
   FCurve := ACurve;
   FConfWidth := AConfWidth;
 end;
 
-function TConfigureBasepointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+function TWNafUtilities.TConfigureBasepointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
 var
   LExistingWNaf: IWNafPreCompInfo;
   LResult: IWNafPreCompInfo;
@@ -100,7 +145,7 @@ begin
     Exit;
   end;
 
-  LResult := TWNafPreCompInfo.Create as IWNafPreCompInfo;
+  LResult := TWNafPreCompInfo.Create;
   LResult.PromotionCountdown := 0;
   LResult.ConfWidth := FConfWidth;
 
@@ -115,6 +160,272 @@ begin
   Result := LResult;
 end;
 
+constructor TWNafUtilities.TMapPointCallback.Create(const AInfoP: IWNafPreCompInfo;
+  AIncludeNegated: Boolean; const APointMap: IECPointMap);
+begin
+  Inherited Create;
+  FInfoP := AInfoP;
+  FIncludeNegated := AIncludeNegated;
+  FPointMap := APointMap;
+end;
+
+function TWNafUtilities.TMapPointCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+var
+  LResult: IWNafPreCompInfo;
+  LTwiceP: IECPoint;
+  LPreCompP, LPreCompQ, LPreCompNegQ: TCryptoLibGenericArray<IECPoint>;
+  LI: Int32;
+begin
+  LResult := TWNafPreCompInfo.Create;
+  LResult.ConfWidth := FInfoP.ConfWidth;
+
+  LTwiceP := FInfoP.Twice;
+  if LTwiceP <> nil then
+    LResult.Twice := FPointMap.Map(LTwiceP);
+
+  LPreCompP := FInfoP.PreComp;
+  System.SetLength(LPreCompQ, System.Length(LPreCompP));
+  for LI := 0 to System.Length(LPreCompP) - 1 do
+    LPreCompQ[LI] := FPointMap.Map(LPreCompP[LI]);
+  LResult.PreComp := LPreCompQ;
+  LResult.Width := FInfoP.Width;
+
+  if FIncludeNegated then
+  begin
+    System.SetLength(LPreCompNegQ, System.Length(LPreCompQ));
+    for LI := 0 to System.Length(LPreCompNegQ) - 1 do
+      LPreCompNegQ[LI] := LPreCompQ[LI].Negate();
+    LResult.PreCompNeg := LPreCompNegQ;
+  end;
+
+  Result := LResult;
+end;
+
+constructor TWNafUtilities.TPrecomputeCallback.Create(const AP: IECPoint; AMinWidth: Int32; AIncludeNegated: Boolean);
+begin
+  inherited Create;
+  FP := AP;
+  FMinWidth := AMinWidth;
+  FIncludeNegated := AIncludeNegated;
+end;
+
+function TWNafUtilities.TPrecomputeCallback.CheckTable(const ATable: TCryptoLibGenericArray<IECPoint>;
+  AReqLen: Int32): Boolean;
+begin
+  Result := (ATable <> nil) and (System.Length(ATable) >= AReqLen);
+end;
+
+function TWNafUtilities.TPrecomputeCallback.CheckExisting(const AExistingWNaf: IWNafPreCompInfo;
+  AWidth, AReqPreCompLen: Int32; AIncludeNegated: Boolean): Boolean;
+var
+  LConfWidth: Int32;
+begin
+  if AExistingWNaf = nil then
+    Exit(False);
+  LConfWidth := AExistingWNaf.ConfWidth;
+  Result := (AExistingWNaf.Width >= Math.Max(LConfWidth, AWidth)) and
+    CheckTable(AExistingWNaf.PreComp, AReqPreCompLen) and
+    (not AIncludeNegated or CheckTable(AExistingWNaf.PreCompNeg, AReqPreCompLen));
+end;
+
+function TWNafUtilities.TPrecomputeCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+var
+  LExistingWNaf: IWNafPreCompInfo;
+  LResultInfo: IWNafPreCompInfo;
+  LC: IECCurve;
+  LPreComp, LPreCompNeg: TCryptoLibGenericArray<IECPoint>;
+  LTwiceP: IECPoint;
+  LWidth, LReqPreCompLen, LIniPreCompLen, LCurPreCompLen, LPos: Int32;
+  LLast, LIsoTwiceP: IECPoint;
+  LIso, LIso2, LIso3: IECFieldElement;
+begin
+  if not Supports(AExisting, IWNafPreCompInfo, LExistingWNaf) then
+    LExistingWNaf := nil;
+
+  LWidth := Math.Max(2, Math.Min(TWNafUtilities.MAX_WIDTH, FMinWidth));
+  LReqPreCompLen := 1 shl (LWidth - 2);
+
+  if CheckExisting(LExistingWNaf, LWidth, LReqPreCompLen, FIncludeNegated) then
+  begin
+    LExistingWNaf.DecrementPromotionCountdown;
+    Result := LExistingWNaf;
+    Exit;
+  end;
+
+  LResultInfo := TWNafPreCompInfo.Create;
+  LC := FP.Curve;
+  LPreComp := nil;
+  LPreCompNeg := nil;
+  LTwiceP := nil;
+
+  if LExistingWNaf <> nil then
+  begin
+    LResultInfo.PromotionCountdown := LExistingWNaf.DecrementPromotionCountdown;
+    LResultInfo.ConfWidth := LExistingWNaf.ConfWidth;
+    LPreComp := LExistingWNaf.PreComp;
+    LPreCompNeg := LExistingWNaf.PreCompNeg;
+    LTwiceP := LExistingWNaf.Twice;
+  end;
+
+  LWidth := Math.Min(TWNafUtilities.MAX_WIDTH, Math.Max(LResultInfo.ConfWidth, LWidth));
+  LReqPreCompLen := 1 shl (LWidth - 2);
+
+  LIniPreCompLen := 0;
+  if LPreComp <> nil then
+    LIniPreCompLen := System.Length(LPreComp);
+
+  LIso := nil;
+  if LIniPreCompLen < LReqPreCompLen then
+  begin
+    LPreComp := TWNafUtilities.ResizeTable(LPreComp, LReqPreCompLen);
+
+    if LReqPreCompLen = 1 then
+      LPreComp[0] := FP.Normalize()
+    else
+    begin
+      LCurPreCompLen := LIniPreCompLen;
+      if LCurPreCompLen = 0 then
+      begin
+        LPreComp[0] := FP;
+        LCurPreCompLen := 1;
+      end;
+
+      if LReqPreCompLen = 2 then
+        LPreComp[1] := FP.ThreeTimes()
+      else
+      begin
+        LLast := LPreComp[LCurPreCompLen - 1];
+        if LTwiceP = nil then
+        begin
+          LIsoTwiceP := LPreComp[0].Twice();
+          LTwiceP := LIsoTwiceP;
+          { Fp quasi-isomorphism: affine twiceP and scale last for cheaper additions }
+          if (not LIsoTwiceP.GetIsInfinity) and TECAlgorithms.IsFpCurve(LC) and
+            (LC.FieldSize >= 64) then
+            case LC.CoordinateSystem of
+              TECCurveConstants.COORD_JACOBIAN, TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
+              TECCurveConstants.COORD_JACOBIAN_MODIFIED:
+                begin
+                  LIso := LIsoTwiceP.GetZCoord(0);
+                  LIsoTwiceP := LC.CreatePoint(LIsoTwiceP.XCoord.ToBigInteger(),
+                    LIsoTwiceP.YCoord.ToBigInteger());
+                  LIso2 := LIso.Square();
+                  LIso3 := LIso2.Multiply(LIso);
+                  LLast := LLast.ScaleX(LIso2).ScaleY(LIso3);
+                  if LIniPreCompLen = 0 then
+                    LPreComp[0] := LLast;
+                end;
+            end;
+        end
+        else
+          LIsoTwiceP := LTwiceP;
+        while LCurPreCompLen < LReqPreCompLen do
+        begin
+          LPreComp[LCurPreCompLen] := LLast.Add(LIsoTwiceP);
+          LLast := LPreComp[LCurPreCompLen];
+          Inc(LCurPreCompLen);
+        end;
+      end;
+
+      LC.NormalizeAll(LPreComp, LIniPreCompLen, LReqPreCompLen - LIniPreCompLen, LIso);
+    end;
+  end;
+
+  if FIncludeNegated then
+  begin
+    if LPreCompNeg = nil then
+      LPos := 0
+    else
+      LPos := System.Length(LPreCompNeg);
+    if LPos < LReqPreCompLen then
+    begin
+      SetLength(LPreCompNeg, LReqPreCompLen);
+      while LPos < LReqPreCompLen do
+      begin
+        LPreCompNeg[LPos] := LPreComp[LPos].Negate();
+        Inc(LPos);
+      end;
+    end;
+  end;
+
+  LResultInfo.PreComp := LPreComp;
+  LResultInfo.PreCompNeg := LPreCompNeg;
+  LResultInfo.Twice := LTwiceP;
+  LResultInfo.Width := LWidth;
+  Result := LResultInfo;
+end;
+
+constructor TWNafUtilities.TPrecomputeWithPointMapCallback.Create(const APoint: IECPoint;
+  const APointMap: IECPointMap; const AFromWNaf: IWNafPreCompInfo; AIncludeNegated: Boolean);
+begin
+  inherited Create;
+  FPoint := APoint;
+  FPointMap := APointMap;
+  FFromWNaf := AFromWNaf;
+  FIncludeNegated := AIncludeNegated;
+end;
+
+function TWNafUtilities.TPrecomputeWithPointMapCallback.CheckTable(
+  const ATable: TCryptoLibGenericArray<IECPoint>; AReqLen: Int32): Boolean;
+begin
+  Result := (ATable <> nil) and (System.Length(ATable) >= AReqLen);
+end;
+
+function TWNafUtilities.TPrecomputeWithPointMapCallback.CheckExisting(
+  const AExistingWNaf: IWNafPreCompInfo; AWidth, AReqPreCompLen: Int32;
+  AIncludeNegated: Boolean): Boolean;
+begin
+  Result := (AExistingWNaf <> nil) and (AExistingWNaf.Width >= AWidth) and
+    CheckTable(AExistingWNaf.PreComp, AReqPreCompLen) and
+    (not AIncludeNegated or CheckTable(AExistingWNaf.PreCompNeg, AReqPreCompLen));
+end;
+
+function TWNafUtilities.TPrecomputeWithPointMapCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
+var
+  LExistingWNaf: IWNafPreCompInfo;
+  LResultInfo: IWNafPreCompInfo;
+  LWidth, LReqPreCompLen, LI: Int32;
+  LPreCompFrom, LPreComp, LPreCompNeg: TCryptoLibGenericArray<IECPoint>;
+  LTwiceFrom: IECPoint;
+begin
+  if not Supports(AExisting, IWNafPreCompInfo, LExistingWNaf) then
+    LExistingWNaf := nil;
+
+  LWidth := FFromWNaf.Width;
+  LReqPreCompLen := System.Length(FFromWNaf.PreComp);
+
+  if CheckExisting(LExistingWNaf, LWidth, LReqPreCompLen, FIncludeNegated) then
+  begin
+    LExistingWNaf.DecrementPromotionCountdown;
+    Result := LExistingWNaf;
+    Exit;
+  end;
+
+  LResultInfo := TWNafPreCompInfo.Create;
+  LResultInfo.PromotionCountdown := FFromWNaf.PromotionCountdown;
+
+  LTwiceFrom := FFromWNaf.Twice;
+  if LTwiceFrom <> nil then
+    LResultInfo.Twice := FPointMap.Map(LTwiceFrom);
+
+  LPreCompFrom := FFromWNaf.PreComp;
+  System.SetLength(LPreComp, System.Length(LPreCompFrom));
+  for LI := 0 to System.High(LPreCompFrom) do
+    LPreComp[LI] := FPointMap.Map(LPreCompFrom[LI]);
+  LResultInfo.PreComp := LPreComp;
+  LResultInfo.Width := LWidth;
+
+  if FIncludeNegated then
+  begin
+    System.SetLength(LPreCompNeg, System.Length(LPreComp));
+    for LI := 0 to System.High(LPreComp) do
+      LPreCompNeg[LI] := LPreComp[LI].Negate();
+    LResultInfo.PreCompNeg := LPreCompNeg;
+  end;
+
+  Result := LResultInfo;
+end;
+
 { TWNafUtilities }
 
 class procedure TWNafUtilities.ConfigureBasepoint(const AP: IECPoint);
@@ -134,9 +445,9 @@ begin
   else
     LBits := LOrder.BitLength;
 
-  LConfWidth := System.Math.Min(MAX_WIDTH, GetWindowSize(LBits) + 3);
+  LConfWidth := Math.Min(MAX_WIDTH, GetWindowSize(LBits) + 3);
   LC.Precompute(AP, PRECOMP_NAME,
-    TConfigureBasepointCallback.Create(LC, LConfWidth) as IPreCompCallback);
+    TWNafUtilities.TConfigureBasepointCallback.Create(LC, LConfWidth) as IPreCompCallback);
 end;
 
 class function TWNafUtilities.GetWindowSize(ABits: Int32): Int32;
@@ -166,7 +477,7 @@ begin
   LW := 0;
   while (LW < System.Length(AWindowSizeCutoffs)) and (ABits >= AWindowSizeCutoffs[LW]) do
     Inc(LW);
-  Result := System.Math.Max(2, System.Math.Min(AMaxWidth, LW + 2));
+  Result := Math.Max(2, Math.Min(AMaxWidth, LW + 2));
 end;
 
 class function TWNafUtilities.Trim(const AArray: TCryptoLibInt32Array;
@@ -179,6 +490,16 @@ begin
     Result[LI] := AArray[LI];
 end;
 
+class function TWNafUtilities.Trim(const AArray: TCryptoLibByteArray;
+  ALength: Int32): TCryptoLibByteArray;
+var
+  LI: Int32;
+begin
+  System.SetLength(Result, ALength);
+  for LI := 0 to ALength - 1 do
+    Result[LI] := AArray[LI];
+end;
+
 class function TWNafUtilities.ResizeTable(const AArray: TCryptoLibGenericArray<IECPoint>;
   ALength: Int32): TCryptoLibGenericArray<IECPoint>;
 var
@@ -187,22 +508,12 @@ begin
   System.SetLength(Result, ALength);
   if AArray <> nil then
   begin
-    LLen := System.Math.Min(System.Length(AArray), ALength);
+    LLen := Math.Min(System.Length(AArray), ALength);
     for LI := 0 to LLen - 1 do
       Result[LI] := AArray[LI];
   end;
 end;
 
-class function TWNafUtilities.TrimBytes(const AArray: TCryptoLibByteArray;
-  ALength: Int32): TCryptoLibByteArray;
-var
-  LI: Int32;
-begin
-  System.SetLength(Result, ALength);
-  for LI := 0 to ALength - 1 do
-    Result[LI] := AArray[LI];
-end;
-
 class function TWNafUtilities.GenerateNaf(const AK: TBigInteger): TCryptoLibByteArray;
 var
   L3k, LDiff: TBigInteger;
@@ -218,7 +529,7 @@ begin
   LDigits := L3k.BitLength - 1;
   System.SetLength(Result, LDigits);
   TArrayUtilities.Fill<Byte>(Result, 0, LDigits, Byte(0));
-  LDiff := L3k.Xor(AK);
+  LDiff := L3k.&Xor(AK);
   LI := 1;
   while LI < LDigits do
   begin
@@ -287,7 +598,7 @@ begin
     LPos := AWidth;
   end;
   if System.Length(Result) > LLength then
-    Result := TrimBytes(Result, LLength);
+    Result := Trim(Result, LLength);
 end;
 
 class function TWNafUtilities.GenerateJsf(const AG, AH: TBigInteger): TCryptoLibByteArray;
@@ -296,7 +607,7 @@ var
   LJsf: TCryptoLibByteArray;
   LK0, LK1: TBigInteger;
 begin
-  LDigits := System.Math.Max(AG.BitLength, AH.BitLength) + 1;
+  LDigits := Math.Max(AG.BitLength, AH.BitLength) + 1;
   System.SetLength(LJsf, LDigits);
   LK0 := AG;
   LK1 := AH;
@@ -306,8 +617,8 @@ begin
   LOffset := 0;
   while ((Ld0 or Ld1) <> 0) or (LK0.BitLength > LOffset) or (LK1.BitLength > LOffset) do
   begin
-    Ln0 := (Int32(UInt32(LK0.GetInt32Value) shr LOffset) + Ld0) and 7;
-    Ln1 := (Int32(UInt32(LK1.GetInt32Value) shr LOffset) + Ld1) and 7;
+    Ln0 := (Int32(UInt32(LK0.Int32Value) shr LOffset) + Ld0) and 7;
+    Ln1 := (Int32(UInt32(LK1.Int32Value) shr LOffset) + Ld1) and 7;
     Lu0 := Ln0 and 1;
     if Lu0 <> 0 then
     begin
@@ -337,7 +648,7 @@ begin
     Inc(LJ);
   end;
   if System.Length(LJsf) > LJ then
-    Result := TrimBytes(LJsf, LJ)
+    Result := Trim(LJsf, LJ)
   else
     Result := LJsf;
 end;
@@ -349,7 +660,7 @@ begin
   if AK.SignValue = 0 then
     Exit(0);
   L3k := AK.ShiftLeft(1).Add(AK);
-  LDiff := L3k.Xor(AK);
+  LDiff := L3k.&Xor(AK);
   Result := LDiff.BitCount;
 end;
 
@@ -384,7 +695,7 @@ begin
   L3k := AK.ShiftLeft(1).Add(AK);
   LBits := L3k.BitLength;
   System.SetLength(Result, TBitOperations.Asr32(LBits, 1));
-  LDiff := L3k.Xor(AK);
+  LDiff := L3k.&Xor(AK);
   LHighBit := LBits - 1;
   LLength := 0;
   LZeroes := 0;
@@ -469,270 +780,16 @@ begin
     Result := Trim(Result, LLength);
 end;
 
-type
-  TPrecomputeCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FP: IECPoint;
-    FMinWidth: Int32;
-    FIncludeNegated: Boolean;
-    function CheckExisting(const AExistingWNaf: IWNafPreCompInfo; AWidth, AReqPreCompLen: Int32;
-      AIncludeNegated: Boolean): Boolean;
-    function CheckTable(const ATable: TCryptoLibGenericArray<IECPoint>; AReqLen: Int32): Boolean;
-  public
-    constructor Create(const AP: IECPoint; AMinWidth: Int32; AIncludeNegated: Boolean);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
-
-constructor TPrecomputeCallback.Create(const AP: IECPoint; AMinWidth: Int32; AIncludeNegated: Boolean);
-begin
-  inherited Create;
-  FP := AP;
-  FMinWidth := AMinWidth;
-  FIncludeNegated := AIncludeNegated;
-end;
-
-function TPrecomputeCallback.CheckTable(const ATable: TCryptoLibGenericArray<IECPoint>;
-  AReqLen: Int32): Boolean;
-begin
-  Result := (ATable <> nil) and (System.Length(ATable) >= AReqLen);
-end;
-
-function TPrecomputeCallback.CheckExisting(const AExistingWNaf: IWNafPreCompInfo;
-  AWidth, AReqPreCompLen: Int32; AIncludeNegated: Boolean): Boolean;
-var
-  LConfWidth: Int32;
-begin
-  if AExistingWNaf = nil then
-    Exit(False);
-  LConfWidth := AExistingWNaf.ConfWidth;
-  Result := (AExistingWNaf.Width >= System.Math.Max(LConfWidth, AWidth)) and
-    CheckTable(AExistingWNaf.PreComp, AReqPreCompLen) and
-    (not AIncludeNegated or CheckTable(AExistingWNaf.PreCompNeg, AReqPreCompLen));
-end;
-
-function TPrecomputeCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-var
-  LExistingWNaf: IWNafPreCompInfo;
-  LResultInfo: IWNafPreCompInfo;
-  LC: IECCurve;
-  LPreComp, LPreCompNeg: TCryptoLibGenericArray<IECPoint>;
-  LTwiceP: IECPoint;
-  LWidth, LReqPreCompLen, LIniPreCompLen, LCurPreCompLen, LPos: Int32;
-  LLast, LIsoTwiceP: IECPoint;
-  LIso, LIso2, LIso3: IECFieldElement;
-begin
-  if not Supports(AExisting, IWNafPreCompInfo, LExistingWNaf) then
-    LExistingWNaf := nil;
-
-  LWidth := System.Math.Max(2, System.Math.Min(TWNafUtilities.MAX_WIDTH, FMinWidth));
-  LReqPreCompLen := 1 shl (LWidth - 2);
-
-  if CheckExisting(LExistingWNaf, LWidth, LReqPreCompLen, FIncludeNegated) then
-  begin
-    LExistingWNaf.DecrementPromotionCountdown;
-    Result := LExistingWNaf;
-    Exit;
-  end;
-
-  LResultInfo := TWNafPreCompInfo.Create as IWNafPreCompInfo;
-  LC := FP.Curve;
-  LPreComp := nil;
-  LPreCompNeg := nil;
-  LTwiceP := nil;
-
-  if LExistingWNaf <> nil then
-  begin
-    LResultInfo.PromotionCountdown := LExistingWNaf.DecrementPromotionCountdown;
-    LResultInfo.ConfWidth := LExistingWNaf.ConfWidth;
-    LPreComp := LExistingWNaf.PreComp;
-    LPreCompNeg := LExistingWNaf.PreCompNeg;
-    LTwiceP := LExistingWNaf.Twice;
-  end;
-
-  LWidth := System.Math.Min(TWNafUtilities.MAX_WIDTH, System.Math.Max(LResultInfo.ConfWidth, LWidth));
-  LReqPreCompLen := 1 shl (LWidth - 2);
-
-  LIniPreCompLen := 0;
-  if LPreComp <> nil then
-    LIniPreCompLen := System.Length(LPreComp);
-
-  LIso := nil;
-  if LIniPreCompLen < LReqPreCompLen then
-  begin
-    LPreComp := TWNafUtilities.ResizeTable(LPreComp, LReqPreCompLen);
-
-    if LReqPreCompLen = 1 then
-      LPreComp[0] := FP.Normalize()
-    else
-    begin
-      LCurPreCompLen := LIniPreCompLen;
-      if LCurPreCompLen = 0 then
-      begin
-        LPreComp[0] := FP;
-        LCurPreCompLen := 1;
-      end;
-
-      if LReqPreCompLen = 2 then
-        LPreComp[1] := FP.ThreeTimes()
-      else
-      begin
-        LLast := LPreComp[LCurPreCompLen - 1];
-        if LTwiceP = nil then
-        begin
-          LIsoTwiceP := LPreComp[0].Twice();
-          LTwiceP := LIsoTwiceP;
-          { Fp quasi-isomorphism: affine twiceP and scale last for cheaper additions }
-          if (not LIsoTwiceP.GetIsInfinity) and TECAlgorithms.IsFpCurve(LC) and
-            (LC.FieldSize >= 64) then
-            case LC.CoordinateSystem of
-              TECCurveConstants.COORD_JACOBIAN, TECCurveConstants.COORD_JACOBIAN_CHUDNOVSKY,
-              TECCurveConstants.COORD_JACOBIAN_MODIFIED:
-                begin
-                  LIso := LIsoTwiceP.GetZCoord(0);
-                  LIsoTwiceP := LC.CreatePoint(LIsoTwiceP.XCoord.ToBigInteger(),
-                    LIsoTwiceP.YCoord.ToBigInteger());
-                  LIso2 := LIso.Square();
-                  LIso3 := LIso2.Multiply(LIso);
-                  LLast := LLast.ScaleX(LIso2).ScaleY(LIso3);
-                  if LIniPreCompLen = 0 then
-                    LPreComp[0] := LLast;
-                end;
-            end;
-        end
-        else
-          LIsoTwiceP := LTwiceP;
-        while LCurPreCompLen < LReqPreCompLen do
-        begin
-          LPreComp[LCurPreCompLen] := LLast.Add(LIsoTwiceP);
-          LLast := LPreComp[LCurPreCompLen];
-          Inc(LCurPreCompLen);
-        end;
-      end;
-
-      LC.NormalizeAll(LPreComp, LIniPreCompLen, LReqPreCompLen - LIniPreCompLen, LIso);
-    end;
-  end;
-
-  if FIncludeNegated then
-  begin
-    if LPreCompNeg = nil then
-      LPos := 0
-    else
-      LPos := System.Length(LPreCompNeg);
-    if LPos < LReqPreCompLen then
-    begin
-      SetLength(LPreCompNeg, LReqPreCompLen);
-      while LPos < LReqPreCompLen do
-      begin
-        LPreCompNeg[LPos] := LPreComp[LPos].Negate();
-        Inc(LPos);
-      end;
-    end;
-  end;
-
-  LResultInfo.PreComp := LPreComp;
-  LResultInfo.PreCompNeg := LPreCompNeg;
-  LResultInfo.Twice := LTwiceP;
-  LResultInfo.Width := LWidth;
-  Result := LResultInfo;
-end;
-
-type
-  TPrecomputeWithPointMapCallback = class sealed(TInterfacedObject, IPreCompCallback)
-  strict private
-    FPoint: IECPoint;
-    FPointMap: IECPointMap;
-    FFromWNaf: IWNafPreCompInfo;
-    FIncludeNegated: Boolean;
-    function CheckTable(const ATable: TCryptoLibGenericArray<IECPoint>; AReqLen: Int32): Boolean;
-    function CheckExisting(const AExistingWNaf: IWNafPreCompInfo; AWidth, AReqPreCompLen: Int32;
-      AIncludeNegated: Boolean): Boolean;
-  public
-    constructor Create(const APoint: IECPoint; const APointMap: IECPointMap;
-      const AFromWNaf: IWNafPreCompInfo; AIncludeNegated: Boolean);
-    function Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-  end;
-
-constructor TPrecomputeWithPointMapCallback.Create(const APoint: IECPoint;
-  const APointMap: IECPointMap; const AFromWNaf: IWNafPreCompInfo; AIncludeNegated: Boolean);
-begin
-  inherited Create;
-  FPoint := APoint;
-  FPointMap := APointMap;
-  FFromWNaf := AFromWNaf;
-  FIncludeNegated := AIncludeNegated;
-end;
-
-function TPrecomputeWithPointMapCallback.CheckTable(
-  const ATable: TCryptoLibGenericArray<IECPoint>; AReqLen: Int32): Boolean;
-begin
-  Result := (ATable <> nil) and (System.Length(ATable) >= AReqLen);
-end;
-
-function TPrecomputeWithPointMapCallback.CheckExisting(
-  const AExistingWNaf: IWNafPreCompInfo; AWidth, AReqPreCompLen: Int32;
-  AIncludeNegated: Boolean): Boolean;
-begin
-  Result := (AExistingWNaf <> nil) and (AExistingWNaf.Width >= AWidth) and
-    CheckTable(AExistingWNaf.PreComp, AReqPreCompLen) and
-    (not AIncludeNegated or CheckTable(AExistingWNaf.PreCompNeg, AReqPreCompLen));
-end;
-
-function TPrecomputeWithPointMapCallback.Precompute(const AExisting: IPreCompInfo): IPreCompInfo;
-var
-  LExistingWNaf: IWNafPreCompInfo;
-  LResultInfo: IWNafPreCompInfo;
-  LWidth, LReqPreCompLen, LI: Int32;
-  LPreCompFrom, LPreComp, LPreCompNeg: TCryptoLibGenericArray<IECPoint>;
-  LTwiceFrom: IECPoint;
-begin
-  if not Supports(AExisting, IWNafPreCompInfo, LExistingWNaf) then
-    LExistingWNaf := nil;
-
-  LWidth := FFromWNaf.Width;
-  LReqPreCompLen := System.Length(FFromWNaf.PreComp);
-
-  if CheckExisting(LExistingWNaf, LWidth, LReqPreCompLen, FIncludeNegated) then
-  begin
-    LExistingWNaf.DecrementPromotionCountdown;
-    Result := LExistingWNaf;
-    Exit;
-  end;
-
-  LResultInfo := TWNafPreCompInfo.Create as IWNafPreCompInfo;
-  LResultInfo.PromotionCountdown := FFromWNaf.PromotionCountdown;
-
-  LTwiceFrom := FFromWNaf.Twice;
-  if LTwiceFrom <> nil then
-    LResultInfo.Twice := FPointMap.Map(LTwiceFrom);
-
-  LPreCompFrom := FFromWNaf.PreComp;
-  System.SetLength(LPreComp, System.Length(LPreCompFrom));
-  for LI := 0 to System.High(LPreCompFrom) do
-    LPreComp[LI] := FPointMap.Map(LPreCompFrom[LI]);
-  LResultInfo.PreComp := LPreComp;
-  LResultInfo.Width := LWidth;
-
-  if FIncludeNegated then
-  begin
-    System.SetLength(LPreCompNeg, System.Length(LPreComp));
-    for LI := 0 to System.High(LPreComp) do
-      LPreCompNeg[LI] := LPreComp[LI].Negate();
-    LResultInfo.PreCompNeg := LPreCompNeg;
-  end;
-
-  Result := LResultInfo;
-end;
-
 class function TWNafUtilities.PrecomputeWithPointMap(const AP: IECPoint;
   const APointMap: IECPointMap; const AFromWNaf: IWNafPreCompInfo;
   AIncludeNegated: Boolean): IWNafPreCompInfo;
 var
   LResult: IPreCompInfo;
+  LPreCompCallback: IPreCompCallback;
   LWNaf: IWNafPreCompInfo;
 begin
-  LResult := AP.Curve.Precompute(AP, PRECOMP_NAME,
-    TPrecomputeWithPointMapCallback.Create(AP, APointMap, AFromWNaf, AIncludeNegated) as IPreCompCallback);
+  LPreCompCallback := TWNafUtilities.TPrecomputeWithPointMapCallback.Create(AP, APointMap, AFromWNaf, AIncludeNegated);
+  LResult := AP.Curve.Precompute(AP, PRECOMP_NAME, LPreCompCallback);
   if not Supports(LResult, IWNafPreCompInfo, LWNaf) then
     raise EInvalidCastCryptoLibException.Create('Expected IWNafPreCompInfo');
   Result := LWNaf;
@@ -742,10 +799,11 @@ class function TWNafUtilities.Precompute(const AP: IECPoint; AMinWidth: Int32;
   AIncludeNegated: Boolean): IWNafPreCompInfo;
 var
   LResult: IPreCompInfo;
+  LPreCompCallback: IPreCompCallback;
   LWNaf: IWNafPreCompInfo;
 begin
-  LResult := AP.Curve.Precompute(AP, PRECOMP_NAME,
-    TPrecomputeCallback.Create(AP, AMinWidth, AIncludeNegated) as IPreCompCallback);
+  LPreCompCallback := TWNafUtilities.TPrecomputeCallback.Create(AP, AMinWidth, AIncludeNegated);
+  LResult := AP.Curve.Precompute(AP, PRECOMP_NAME, LPreCompCallback);
   if not Supports(LResult, IWNafPreCompInfo, LWNaf) then
     raise EInvalidCastCryptoLibException.Create('Expected IWNafPreCompInfo');
   Result := LWNaf;

+ 7 - 0
CryptoLib/src/Math/EC/Multiplier/ClpWTauNafPreCompInfo.pas

@@ -6,8 +6,15 @@
 { *  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 ClpWTauNafPreCompInfo;
 
 {$I ..\..\..\Include\CryptoLib.inc}

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

@@ -26,6 +26,7 @@ uses
   ClpBigInteger,
   ClpCryptoLibTypes,
   ClpIFiniteField,
+  ClpIPolynomial,
   ClpIPolynomialExtensionField,
   ClpPrimeField,
   ClpGF2Polynomial,

+ 6 - 5
CryptoLib/src/Math/Field/ClpGF2Polynomial.pas

@@ -50,7 +50,7 @@ implementation
 constructor TGF2Polynomial.Create(const AExponents: TCryptoLibInt32Array);
 begin
   Inherited Create();
-  FExponents := TArrayUtilities.CopyOf(AExponents, System.Length(AExponents));
+  FExponents := System.Copy(AExponents);
 end;
 
 function TGF2Polynomial.GetDegree: Int32;
@@ -60,18 +60,19 @@ end;
 
 function TGF2Polynomial.GetExponentsPresent: TCryptoLibInt32Array;
 begin
-  Result := TArrayUtilities.CopyOf(FExponents, System.Length(FExponents));
+  Result := System.Copy(FExponents);
 end;
 
 function TGF2Polynomial.Equals(const AOther: IPolynomial): Boolean;
 begin
   if AOther = nil then
     Exit(False);
-  Result := (Degree = AOther.Degree) and
-    TArrayUtilities.AreEqual<Int32>(FExponents, AOther.ExponentsPresent);
+  if (Self as IGF2Polynomial) = (AOther as IGF2Polynomial) then
+    Exit(True);
+  Result := TArrayUtilities.AreEqual<Int32>(FExponents, AOther.ExponentsPresent);
 end;
 
-function TGF2Polynomial.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt; {$ENDIF DELPHI};
+function TGF2Polynomial.GetHashCode: {$IFDEF DELPHI}Int32 {$ELSE}PtrInt {$ENDIF DELPHI};
 begin
   Result := TArrayUtilities.GetArrayHashCode(FExponents);
 end;

+ 2 - 1
CryptoLib/src/Math/Field/ClpGenericPolynomialExtensionField.pas

@@ -22,6 +22,7 @@ unit ClpGenericPolynomialExtensionField;
 interface
 
 uses
+  SysUtils,
   ClpBigInteger,
   ClpCryptoLibTypes,
   ClpBitOperations,
@@ -108,7 +109,7 @@ begin
     FMinimalPolynomial.Equals(LOther.MinimalPolynomial);
 end;
 
-function TGenericPolynomialExtensionField.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt; {$ENDIF DELPHI};
+function TGenericPolynomialExtensionField.GetHashCode: {$IFDEF DELPHI}Int32 {$ELSE}PtrInt {$ENDIF DELPHI};
 begin
   Result := Int32(UInt32(FSubfield.GetHashCode) xor
     TBitOperations.RotateLeft32(UInt32(FMinimalPolynomial.GetHashCode), 16));

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

@@ -70,7 +70,7 @@ begin
   Result := FCharacteristic.Equals(AOther.Characteristic);
 end;
 
-function TPrimeField.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt; {$ENDIF DELPHI};
+function TPrimeField.GetHashCode: {$IFDEF DELPHI}Int32{$ELSE}PtrInt{$ENDIF};
 begin
   Result := FCharacteristic.GetHashCode();
 end;