Просмотр исходного кода

remove Schnorr, Ed25519Blake2b, update TBigIntegers

Ugochukwu Mmaduekwe 2 недель назад
Родитель
Сommit
ff1f7f53b1

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

@@ -130,7 +130,6 @@ uses
   ClpECNRSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECNRSigner.pas',
   ClpECPrivateKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECPrivateKeyParameters.pas',
   ClpECPublicKeyParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpECPublicKeyParameters.pas',
-  ClpECSchnorrSipaSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpECSchnorrSipaSigner.pas',
   ClpEd25519 in '..\..\CryptoLib\src\Math\EC\Rfc8032\ClpEd25519.pas',
   ClpEd25519CtxSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpEd25519CtxSigner.pas',
   ClpEd25519KeyGenerationParameters in '..\..\CryptoLib\src\Crypto\Parameters\ClpEd25519KeyGenerationParameters.pas',
@@ -234,7 +233,6 @@ uses
   ClpIECNRSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIECNRSigner.pas',
   ClpIECPrivateKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECPrivateKeyParameters.pas',
   ClpIECPublicKeyParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIECPublicKeyParameters.pas',
-  ClpIECSchnorrSipaSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIECSchnorrSipaSigner.pas',
   ClpIEd25519 in '..\..\CryptoLib\src\Interfaces\Math\EC\Rfc8032\ClpIEd25519.pas',
   ClpIEd25519CtxSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpIEd25519CtxSigner.pas',
   ClpIEd25519KeyGenerationParameters in '..\..\CryptoLib\src\Interfaces\Crypto\Parameters\ClpIEd25519KeyGenerationParameters.pas',
@@ -329,9 +327,6 @@ uses
   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',
-  ClpISchnorr in '..\..\CryptoLib\src\Interfaces\ClpISchnorr.pas',
-  ClpISchnorrDigestSigner in '..\..\CryptoLib\src\Interfaces\Crypto\Signers\ClpISchnorrDigestSigner.pas',
-  ClpISchnorrExt in '..\..\CryptoLib\src\Interfaces\ClpISchnorrExt.pas',
   ClpIScryptParametersGenerator in '..\..\CryptoLib\src\Interfaces\Crypto\Generators\ClpIScryptParametersGenerator.pas',
   ClpISecAsn1Objects in '..\..\CryptoLib\src\Interfaces\Asn1\Sec\ClpISecAsn1Objects.pas',
   ClpISecP256K1Custom in '..\..\CryptoLib\src\Interfaces\Math\EC\Custom\Sec\ClpISecP256K1Custom.pas',
@@ -439,7 +434,6 @@ uses
   ClpScaleXNegateYPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleXNegateYPointMap.pas',
   ClpScaleXPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleXPointMap.pas',
   ClpScaleYNegateXPointMap in '..\..\CryptoLib\src\Math\EC\ClpScaleYNegateXPointMap.pas',
-  ClpSchnorrDigestSigner in '..\..\CryptoLib\src\Crypto\Signers\ClpSchnorrDigestSigner.pas',
   ClpScryptParametersGenerator in '..\..\CryptoLib\src\Crypto\Generators\ClpScryptParametersGenerator.pas',
   ClpSecAsn1Objects in '..\..\CryptoLib\src\Asn1\Sec\ClpSecAsn1Objects.pas',
   ClpSecNamedCurves in '..\..\CryptoLib\src\Asn1\Sec\ClpSecNamedCurves.pas',
@@ -544,12 +538,15 @@ uses
   BigIntegerTests in '..\src\Math\BigIntegerTests.pas',
   ECAlgorithmsTests in '..\src\Math\ECAlgorithmsTests.pas',
   ECPointTests in '..\src\Math\ECPointTests.pas',
+  SecP384R1FieldTests in '..\src\Math\EC\Custom\Sec\SecP384R1FieldTests.pas',
+  DigestTests in '..\src\Others\DigestTests.pas',
   ECDsa5Tests in '..\src\Others\ECDsa5Tests.pas',
+  ECTests in '..\src\Others\ECTests.pas',
+  Ed25519HigherLevelTests in '..\src\Others\Ed25519HigherLevelTests.pas',
   NamedCurveTests in '..\src\Others\NamedCurveTests.pas',
+  ShortenedDigestTests in '..\src\Others\ShortenedDigestTests.pas',
   SignerUtilitiesTests in '..\src\Others\SignerUtilitiesTests.pas',
-  SecP384R1FieldTests in '..\src\Math\EC\Custom\Sec\SecP384R1FieldTests.pas',
-  ECTests in '..\src\Others\ECTests.pas',
-  ECSchnorrTests in '..\src\Others\ECSchnorrTests.pas',
+  X25519HigherLevelTests in '..\src\Others\X25519HigherLevelTests.pas',
   DigestRandomNumberTests in '..\src\Crypto\DigestRandomNumberTests.pas',
   FixedPointTests in '..\src\Math\EC\FixedPointTests.pas',
   AESTests in '..\src\Crypto\AESTests.pas',
@@ -582,14 +579,10 @@ uses
   PascalCoinECIESTests in '..\src\Math\PascalCoinECIESTests.pas',
   X25519Tests in '..\src\Math\EC\Rfc7748\X25519Tests.pas',
   Ed25519Tests in '..\src\Math\EC\Rfc8032\Ed25519Tests.pas',
-  X25519HigherLevelTests in '..\src\Others\X25519HigherLevelTests.pas',
-  Ed25519HigherLevelTests in '..\src\Others\Ed25519HigherLevelTests.pas',
-  ShortenedDigestTests in '..\src\Others\ShortenedDigestTests.pas',
   Kdf1GeneratorTests in '..\src\Crypto\Kdf1GeneratorTests.pas',
   Kdf2GeneratorTests in '..\src\Crypto\Kdf2GeneratorTests.pas',
   Argon2Tests in '..\src\Crypto\Argon2Tests.pas',
   DigestUtilitiesTests in '..\src\Security\DigestUtilitiesTests.pas',
-  DigestTests in '..\src\Others\DigestTests.pas',
   ScryptTests in '..\src\Crypto\ScryptTests.pas',
   DHTests in '..\src\Crypto\DHTests.pas',
   KMacTests in '..\src\Crypto\KMacTests.pas',

+ 0 - 422
CryptoLib.Tests/src/Others/ECSchnorrTests.pas

@@ -1,422 +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 ECSchnorrTests;
-
-interface
-
-{$IFDEF FPC}
-{$MODE DELPHI}
-{$ENDIF FPC}
-
-uses
-  SysUtils,
-{$IFDEF FPC}
-  fpcunit,
-  testregistry,
-{$ELSE}
-  TestFramework,
-{$ENDIF FPC}
-  ClpSecureRandom,
-  ClpISecureRandom,
-  ClpISigner,
-  ClpECPublicKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpECPrivateKeyParameters,
-  ClpIECPrivateKeyParameters,
-  ClpECDomainParameters,
-  ClpIECDomainParameters,
-  ClpIECKeyPairGenerator,
-  ClpECKeyPairGenerator,
-  ClpIECKeyGenerationParameters,
-  ClpIParametersWithRandom,
-  ClpParametersWithRandom,
-  ClpECKeyGenerationParameters,
-  ClpIAsymmetricCipherKeyPair,
-  ClpIX9ECParameters,
-  ClpIECC,
-  ClpSecNamedCurves,
-  ClpBigInteger,
-  ClpSignerUtilities,
-  ClpConverters,
-  ClpCryptoLibTypes,
-  CryptoLibTestBase;
-
-type
-
-  /// <summary>
-  /// ECSchnorr tests.
-  /// </summary>
-  TTestECSchnorr = class(TCryptoLibAlgorithmTestCase)
-  private
-
-  var
-    FRandom: ISecureRandom;
-    FECSchnorrSipaSigningPassTestVector,
-      FECSchnorrSipaVerificationPassTestVector,
-      FECSchnorrSipaVerificationFailTestVector
-      : TCryptoLibGenericArray<TCryptoLibStringArray>;
-
-  protected
-    procedure SetUp; override;
-    procedure TearDown; override;
-  published
-
-    procedure TestECSchnorrSIPASigningShouldPass;
-    procedure TestECSchnorrSIPAVerificationShouldPass;
-    procedure TestECSchnorrSIPAVerificationShouldFail;
-    //procedure TestECSchnorrSIPASigningandVerifyingSecp521R1;
-
-  end;
-
-implementation
-
-{ TTestECSchnorr }
-
-procedure TTestECSchnorr.SetUp;
-begin
-  inherited;
-  FRandom := TSecureRandom.Create();
-  FECSchnorrSipaSigningPassTestVector :=
-    TCryptoLibGenericArray<TCryptoLibStringArray>.Create
-    (TCryptoLibStringArray.Create('Test vector 1',
-    '0000000000000000000000000000000000000000000000000000000000000001',
-    '0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798',
-    '0000000000000000000000000000000000000000000000000000000000000000',
-    '787A848E71043D280C50470E8E1532B2DD5D20EE912A45DBDD2BD1DFBF187EF67031A98831859DC34DFFEEDDA86831842CCD0079E1F92AF177F7F22CC1DCED05'),
-
-    TCryptoLibStringArray.Create('Test vector 2',
-    'B7E151628AED2A6ABF7158809CF4F3C762E7160F38B4DA56A784D9045190CFEF',
-    '02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    '2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD'),
-    TCryptoLibStringArray.Create('Test vector 3',
-    'C90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B14E5C7',
-    '03FAC2114C2FBB091527EB7C64ECB11F8021CB45E8E7809D3C0938E4B8C0E5F84B',
-    '5E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C',
-    '00DA9B08172A9B6F0466A2DEFD817F2D7AB437E0D253CB5395A963866B3574BE00880371D01766935B92D2AB4CD5C8A2A5837EC57FED7660773A05F0DE142380')
-    );
-
-  FECSchnorrSipaVerificationPassTestVector :=
-    TCryptoLibGenericArray<TCryptoLibStringArray>.Create
-    (TCryptoLibStringArray.Create('Test vector 4A',
-    '03DEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34',
-    '4DF3C3F68FCC83B27E9D42C90431A72499F17875C81A599B566C9889B9696703',
-    '00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C6302A8DC32E64E86A333F20EF56EAC9BA30B7246D6D25E22ADB8C6BE1AEB08D49D'),
-
-    TCryptoLibStringArray.Create('Test vector 4B',
-    '031B84C5567B126440995D3ED5AABA0565D71E1834604819FF9C17F5E9D5DD078F',
-    '0000000000000000000000000000000000000000000000000000000000000000',
-    '52818579ACA59767E3291D91B76B637BEF062083284992F2D95F564CA6CB4E3530B1DA849C8E8304ADC0CFE870660334B3CFC18E825EF1DB34CFAE3DFC5D8187')
-    );
-
-  FECSchnorrSipaVerificationFailTestVector :=
-    TCryptoLibGenericArray<TCryptoLibStringArray>.Create(
-
-    TCryptoLibStringArray.Create('Test vector 5',
-    '03EEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34',
-    '4DF3C3F68FCC83B27E9D42C90431A72499F17875C81A599B566C9889B9696703',
-    '00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C6302A8DC32E64E86A333F20EF56EAC9BA30B7246D6D25E22ADB8C6BE1AEB08D49D',
-    'public key not on the curve'),
-
-    TCryptoLibStringArray.Create('Test vector 6',
-    '02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    '2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1DFA16AEE06609280A19B67A24E1977E4697712B5FD2943914ECD5F730901B4AB7',
-    'incorrect R residuosity'),
-
-    TCryptoLibStringArray.Create('Test vector 7',
-    '03FAC2114C2FBB091527EB7C64ECB11F8021CB45E8E7809D3C0938E4B8C0E5F84B',
-    '5E2D58D8B3BCDF1ABADEC7829054F90DDA9805AAB56C77333024B9D0A508B75C',
-    '00DA9B08172A9B6F0466A2DEFD817F2D7AB437E0D253CB5395A963866B3574BED092F9D860F1776A1F7412AD8A1EB50DACCC222BC8C0E26B2056DF2F273EFDEC',
-    'negated message hash'),
-
-    TCryptoLibStringArray.Create('Test vector 8',
-    '0279BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798',
-    '0000000000000000000000000000000000000000000000000000000000000000',
-    '787A848E71043D280C50470E8E1532B2DD5D20EE912A45DBDD2BD1DFBF187EF68FCE5677CE7A623CB20011225797CE7A8DE1DC6CCD4F754A47DA6C600E59543C',
-    'negated s value'),
-
-    TCryptoLibStringArray.Create('Test vector 9',
-    '03DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    '2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD',
-    'negated public key'),
-
-    TCryptoLibStringArray.Create('Test vector 10',
-    '02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    '2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D8C3428869A663ED1E954705B020CBB3E7BB6AC31965B9EA4C73E227B17C5AF5A',
-    'sG - eP is infinite'),
-
-    TCryptoLibStringArray.Create('Test vector 11',
-    '02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    '4A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1D1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD',
-    'sig[0:32] is not an X coordinate on the curve'),
-
-    TCryptoLibStringArray.Create('Test vector 12',
-    '02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC2F1E51A22CCEC35599B8F266912281F8365FFC2D035A230434A1A64DC59F7013FD',
-    'sig[0:32] is equal to field size'),
-
-    TCryptoLibStringArray.Create('Test vector 13',
-    '02DFF1D77F2A671C5F36183726DB2341BE58FEAE1DA2DECED843240F7B502BA659',
-    '243F6A8885A308D313198A2E03707344A4093822299F31D0082EFA98EC4E6C89',
-    '2A298DACAE57395A15D0795DDBFD1DCB564DA82B0F269BC70A74F8220429BA1DFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141',
-    'sig[32:64] is equal to curve order')
-
-    );
-end;
-
-procedure TTestECSchnorr.TearDown;
-begin
-  inherited;
-
-end;
-
-(*
-procedure TTestECSchnorr.TestECSchnorrSIPASigningandVerifyingSecp521R1;
-var
-  LCurve: IX9ECParameters;
-  domain: IECDomainParameters;
-  generator: IECKeyPairGenerator;
-  keygenParams: IECKeyGenerationParameters;
-  keypair: IAsymmetricCipherKeyPair;
-  privParams: IECPrivateKeyParameters;
-  pubParams: IECPublicKeyParameters;
-  signer: ISigner;
-  &message, sigBytes: TBytes;
-
-begin
-
-  LCurve := TSecNamedCurves.GetByName('secp521r1');
-
-  domain := TECDomainParameters.Create(LCurve.Curve, LCurve.G, LCurve.N,
-    LCurve.H, LCurve.GetSeed);
-  generator := TECKeyPairGenerator.Create('ECSCHNORR');
-  keygenParams := TECKeyGenerationParameters.Create(domain, FRandom);
-  generator.Init(keygenParams);
-
-  keypair := generator.GenerateKeyPair();
-  privParams := keypair.Private as IECPrivateKeyParameters; // for signing
-  pubParams := keypair.Public as IECPublicKeyParameters; // for verifying
-
-  signer := TSignerUtilities.GetSigner('SHA-256withECSCHNORRSIPA');
-
-  // sign
-
-  signer.Init(true, privParams);
-
-  &message := TConverters.ConvertStringToBytes('PascalECSCHNORR',
-    TEncoding.UTF8);
-
-  signer.BlockUpdate(&message, 0, System.Length(&message));
-
-  sigBytes := signer.GenerateSignature();
-
-  // verify
-
-  signer.Init(false, pubParams);
-
-  signer.BlockUpdate(&message, 0, System.Length(&message));
-
-  CheckTrue(signer.VerifySignature(sigBytes));
-
-end;
-*)
-
-procedure TTestECSchnorr.TestECSchnorrSIPASigningShouldPass;
-var
-  domain: IECDomainParameters;
-  RegeneratedPrivateKey: IECPrivateKeyParameters;
-  RegeneratedPublicKey: IECPublicKeyParameters;
-  PrivateKeyByteArray, PublicKeyByteArray, &message, sigBytes,
-    expectedSignature: TBytes;
-  point: IECPoint;
-  LCurve: IX9ECParameters;
-  signer: ISigner;
-  param: IParametersWithRandom;
-  vector: TCryptoLibStringArray;
-begin
-
-  LCurve := TSecNamedCurves.GetByName('secp256k1');
-
-  domain := TECDomainParameters.Create(LCurve.Curve, LCurve.G, LCurve.N,
-    LCurve.H, LCurve.GetSeed);
-
-  for vector in FECSchnorrSipaSigningPassTestVector do
-  begin
-
-    PrivateKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
-    PublicKeyByteArray := TBigInteger.Create(vector[2], 16).ToByteArray;
-    &message := DecodeHex(vector[3]);
-    expectedSignature := DecodeHex(vector[4]);
-
-    point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
-
-    RegeneratedPrivateKey := TECPrivateKeyParameters.Create('ECSCHNORR',
-      TBigInteger.Create(PrivateKeyByteArray), domain);
-
-    RegeneratedPublicKey := TECPublicKeyParameters.Create('ECSCHNORR',
-      point, domain);
-
-    param := TParametersWithRandom.Create(RegeneratedPrivateKey, FRandom);
-
-    signer := TSignerUtilities.GetSigner('SHA-256withECSCHNORRSIPA');
-
-    // sign
-
-    signer.Init(true, param);
-
-    signer.BlockUpdate(&message, 0, System.Length(&message));
-
-    sigBytes := signer.GenerateSignature();
-
-    CheckTrue(AreEqual(expectedSignature, sigBytes),
-      vector[0] + ' Signature did not match Output');
-
-    // verify
-
-    signer.Init(false, RegeneratedPublicKey);
-
-    signer.BlockUpdate(&message, 0, System.Length(&message));
-
-    CheckTrue(signer.VerifySignature(sigBytes),
-      vector[0] + ' Signature verification Failed');
-  end;
-
-end;
-
-procedure TTestECSchnorr.TestECSchnorrSIPAVerificationShouldFail;
-var
-  domain: IECDomainParameters;
-  RegeneratedPublicKey: IECPublicKeyParameters;
-  PublicKeyByteArray, &message, expectedSignature: TBytes;
-  point: IECPoint;
-  LCurve: IX9ECParameters;
-  signer: ISigner;
-  vector: TCryptoLibStringArray;
-begin
-
-  LCurve := TSecNamedCurves.GetByName('secp256k1');
-
-  domain := TECDomainParameters.Create(LCurve.Curve, LCurve.G, LCurve.N,
-    LCurve.H, LCurve.GetSeed);
-
-  for vector in FECSchnorrSipaVerificationFailTestVector do
-  begin
-
-    PublicKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
-    &message := DecodeHex(vector[2]);
-    expectedSignature := DecodeHex(vector[3]);
-
-    if vector[0] = 'Test vector 5' then
-    begin
-
-      try
-        point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
-        Fail(vector[4]);
-      except
-        on E: EArgumentCryptoLibException do
-        begin
-
-          if E.Message <> 'Invalid Point Compression' then
-          begin
-            Fail('Invalid Exception Thrown');
-          end;
-          Continue;
-        end;
-
-      end;
-
-    end
-    else
-    begin
-      point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
-    end;
-
-    RegeneratedPublicKey := TECPublicKeyParameters.Create('ECSCHNORR',
-      point, domain);
-
-    signer := TSignerUtilities.GetSigner('SHA-256withECSCHNORRSIPA');
-
-    // verify
-
-    signer.Init(false, RegeneratedPublicKey);
-
-    signer.BlockUpdate(&message, 0, System.Length(&message));
-
-    CheckFalse(signer.VerifySignature(expectedSignature), vector[4]);
-  end;
-
-end;
-
-procedure TTestECSchnorr.TestECSchnorrSIPAVerificationShouldPass;
-var
-  domain: IECDomainParameters;
-  RegeneratedPublicKey: IECPublicKeyParameters;
-  PublicKeyByteArray, &message, expectedSignature: TBytes;
-  point: IECPoint;
-  LCurve: IX9ECParameters;
-  signer: ISigner;
-  vector: TCryptoLibStringArray;
-begin
-
-  LCurve := TSecNamedCurves.GetByName('secp256k1');
-
-  domain := TECDomainParameters.Create(LCurve.Curve, LCurve.G, LCurve.N,
-    LCurve.H, LCurve.GetSeed);
-
-  for vector in FECSchnorrSipaVerificationPassTestVector do
-  begin
-
-    PublicKeyByteArray := TBigInteger.Create(vector[1], 16).ToByteArray;
-    &message := DecodeHex(vector[2]);
-    expectedSignature := DecodeHex(vector[3]);
-
-    point := LCurve.Curve.DecodePoint(PublicKeyByteArray);
-
-    RegeneratedPublicKey := TECPublicKeyParameters.Create('ECSCHNORR',
-      point, domain);
-
-    signer := TSignerUtilities.GetSigner('SHA-256withECSCHNORRSIPA');
-
-    // verify
-
-    signer.Init(false, RegeneratedPublicKey);
-
-    signer.BlockUpdate(&message, 0, System.Length(&message));
-
-    CheckTrue(signer.VerifySignature(expectedSignature),
-      vector[0] + ' Signature verification Failed');
-  end;
-
-end;
-
-initialization
-
-// Register any test cases with the test runner
-
-{$IFDEF FPC}
-  RegisterTest(TTestECSchnorr);
-{$ELSE}
-  RegisterTest(TTestECSchnorr.Suite);
-{$ENDIF FPC}
-
-end.

+ 1 - 55
CryptoLib.Tests/src/Others/Ed25519HigherLevelTests.pas

@@ -70,7 +70,7 @@ type
 
   type
 {$SCOPEDENUMS ON}
-    TEd25519SignerAlgorithm = (Ed25519, Ed25519Blake2B);
+    TEd25519SignerAlgorithm = (Ed25519);
 {$SCOPEDENUMS OFF}
   function CreateSigner(algorithm: TEd25519.TEd25519Algorithm;
     const context: TBytes): ISigner;
@@ -165,24 +165,6 @@ begin
             [id, EncodeHex(LPk), EncodeHex(LKey)]));
         end;
       end;
-    TTestEd25519HigherLevel.TEd25519SignerAlgorithm.Ed25519Blake2B:
-      begin
-        LKey := (LKeyPair.Private as IEd25519PrivateKeyParameters).GetEncoded();
-        if not AreEqual(LKey, System.Copy(LSk, 0, 32)) then
-        begin
-          Fail(Format
-            ('Test with Id %d Failed on PrivateKey Reconstruction Comparison, Expected "%s" but got "%s"',
-            [id, EncodeHex(LSk), EncodeHex(LKey)]));
-        end;
-
-        LKey := (LKeyPair.Public as IEd25519PublicKeyParameters).GetEncoded();
-        if not AreEqual(LKey, System.Copy(LPk, 0, 64)) then
-        begin
-          Fail(Format
-            ('Test with Id %d Failed on PublicKey Reconstruction Comparison, Expected "%s" but got "%s"',
-            [id, EncodeHex(LPk), EncodeHex(LKey)]));
-        end;
-      end
   else
     begin
       raise EArgumentCryptoLibException.Create('algorithm');
@@ -301,14 +283,6 @@ begin
           TEd25519PrivateKeyParameters.Create(TEd25519.Create() as IEd25519, sk,
           0) as IEd25519PrivateKeyParameters);
       end;
-    TTestEd25519HigherLevel.TEd25519SignerAlgorithm.Ed25519Blake2B:
-      begin
-        Result := TAsymmetricCipherKeyPair.Create
-          (TEd25519PublicKeyParameters.Create(pk, 0)
-          as IEd25519PublicKeyParameters,
-          TEd25519PrivateKeyParameters.Create(TEd25519Blake2B.Create()
-          as IEd25519Blake2B, sk, 0) as IEd25519PrivateKeyParameters);
-      end
   else
     begin
       raise EArgumentCryptoLibException.Create('algorithm');
@@ -375,34 +349,6 @@ begin
     'c0dac102c4533186e25dc43128472353eaabdb878b152aeb8e001f92d90233a7',
     '5f4c8989',
     '124f6fc6b0d100842769e71bd530664d888df8507df6c56dedfdb509aeb93416e26b918d38aa06305df3095697c18b2aa832eaa52edc0ae49fbae5a85e150c075f4c8989');
-
-  // TEd25519SignerAlgorithm.Ed25519Blake2B
-
-  DoEd25519Test(6, TEd25519SignerAlgorithm.Ed25519Blake2B,
-    '9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60',
-    '78e65bf30f893d32fc57ef051c341bdede242544fc2a2112f0fa2c7afdebc02f', '',
-    '99a523bd4616c8161144d6a99d3c32400cb4a326f4d79e307340f6afa11750a0085d7d84626bc9e4b153fc0e396d15ce44c39bae4533804db1fe5b52f2b1b805');
-
-  DoEd25519Test(7, TEd25519SignerAlgorithm.Ed25519Blake2B,
-    '4ccd089b28ff96da9db6c346ec114e0f5b8a319f35aba624da8cf6ed4fb8a6fb',
-    '5e71392d91e6a58fedeb0850364f56cd158a60447557d7890389c9b3d4576d4d', '72',
-    '6da75e15b5707f4de5a153c48a5d839fb85074c38aeb6285977f03a13977597f976069fdb903f183474aaa5ed0cfe878ba8ef868c5e47ca3f96ccfb3a89b2a0672');
-
-  DoEd25519Test(8, TEd25519SignerAlgorithm.Ed25519Blake2B,
-    'c5aa8df43f9f837bedb7442f31dcb7b166d38535076f094b85ce3a2e0b4458f7',
-    '8d53ca70f0eab23b9178345785fcdb69ed6723f8148f7e339e88653700b718da', 'af82',
-    '7cc3c13852bd12abf3ce4ca8ca2836cbf86da96c4634c50df3fb80dc809e29db0e109c361353407c1236a904f636868aa33977a99d3f844598db1538b4295203af82');
-
-  DoEd25519Test(9, TEd25519SignerAlgorithm.Ed25519Blake2B,
-    '0d4a05b07352a5436e180356da0ae6efa0345ff7fb1572575772e8005ed978e9',
-    '0c6989f1abebe219db9d1e2cb8b0c602b191828ef7238f8e6dbff8a506802c09',
-    'cbc77b', '7fb2c11db736d16ebd07a653463dc8739d3315f89f61a66715e41528cb32b7689393f5af8a66c9c7336e209e6b187259fe266f7941a435fecb8cd7a7fc759400cbc77b');
-
-  DoEd25519Test(10, TEd25519SignerAlgorithm.Ed25519Blake2B,
-    '6df9340c138cc188b5fe4464ebaa3f7fc206a2d55c3434707e74c9fc04e20ebb',
-    'ce99a0d41b2c1bdf593cfe41b0bf38f40ab77a804a71138188cc879b59869d90',
-    '5f4c8989',
-    'e09625735d184975409020659f3c0b07f036a19a7e7aa2100964cef577806e26125d1437577d2d3286c29df871797cac3fc0cdecbbeca616030cfcc6711db6065f4c8989');
 end;
 
 initialization

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

@@ -161,7 +161,7 @@ begin
     // blind = r^e mod m
     blind := r.ModPow(e, m);
     // unblind = r^(-1) mod m
-    unblind := TBigIntegers.ModOddInverse(m, r);
+    unblind := TBigIntegers.ModOddInverseVar(m, r);
 
     // Blind the input: blindedInput = blind * input mod m
     blindedInput := blind.Multiply(input).&Mod(m);

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

@@ -150,7 +150,7 @@ var
   m, blindFactorInverse, res: TBigInteger;
 begin
   m := FKey.Modulus;
-  blindFactorInverse := TBigIntegers.ModOddInverse(m, FBlindingFactor);
+  blindFactorInverse := TBigIntegers.ModOddInverseVar(m, FBlindingFactor);
   res := blindedMsg.Multiply(blindFactorInverse);
   Result := res.&Mod(m);
 end;

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

@@ -249,7 +249,7 @@ begin
     // Calculate CRT parameters
     dP := d.Remainder(pSub1);
     dQ := d.Remainder(qSub1);
-    qInv := TBigIntegers.ModOddInverse(p, q);
+    qInv := TBigIntegers.ModOddInverseVar(p, q);
 
     // Create key pair
     pubKey := TRsaKeyParameters.Create(False, n, e) as IRsaKeyParameters;

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

@@ -45,8 +45,7 @@ type
 
   const
 
-    Falgorithms: array [0 .. 6] of String = ('EC', 'ECDSA', 'ECDH', 'ECDHC',
-      'ECGOST3410', 'ECMQV', 'ECSCHNORR');
+    Falgorithms: array [0 .. 5] of String = ('EC', 'ECDSA', 'ECDH', 'ECDHC', 'ECGOST3410', 'ECMQV');
 
   var
     Falgorithm: String;

+ 0 - 298
CryptoLib/src/Crypto/Signers/ClpECSchnorrSipaSigner.pas

@@ -1,298 +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 ClpECSchnorrSipaSigner;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  ClpIDigest,
-  ClpISchnorrExt,
-  ClpIECC,
-  ClpIECSchnorrSipaSigner,
-  ClpBigInteger,
-  ClpBigIntegers,
-  ClpISecureRandom,
-  ClpIECKeyParameters,
-  ClpICipherParameters,
-  ClpIECPrivateKeyParameters,
-  ClpIECPublicKeyParameters,
-  ClpSecureRandom,
-  ClpECAlgorithms,
-  ClpDigestUtilities,
-  ClpParameterUtilities,
-  ClpArrayUtilities,
-  ClpCryptoLibTypes;
-
-resourcestring
-  SECPublicKeyNotFound = 'EC Public Key Required for Verification';
-  SECPrivateKeyNotFound = 'EC Private Key Required for Signing';
-  SNotInitializedForSigning = 'Not Initialised For Signing';
-  SNotInitializedForVerifying = 'Not Initialised For Verifying';
-  SSignatureGenerationError = 'An Error Occurred During Signature Generation';
-  SOnlyFPCurvesAllowed =
-    'Only FP (Prime Field) Curves are Allowed for This Schnorr Implementation';
-
-type
-
-  /// <summary>
-  /// <para>
-  /// Schnorr Signature as described in <see href="https://github.com/sipa/bips/blob/bip-schnorr/bip-schnorr.mediawiki">
-  /// bip-schnorr</see>
-  /// </para>
-  /// <para>
-  /// This <c>Schnorr</c> implementation only allows <c>FP(Prime Field)</c>
-  /// Curves.
-  /// </para>
-  /// </summary>
-  TECSchnorrSipaSigner = class sealed(TInterfacedObject, ISchnorrExt,
-    IECSchnorrSipaSigner)
-
-  strict private
-  var
-    FForSigning: Boolean;
-    FKey: IECKeyParameters;
-    FRandom: ISecureRandom;
-    FDigest: IDigest;
-
-    function GetAlgorithmName: String; virtual;
-    function GetOrder: TBigInteger; virtual;
-
-    function GetPP: TBigInteger; inline;
-    function GetG: IECPoint; inline;
-    function GetCurve: IECCurve; inline;
-
-    property PP: TBigInteger read GetPP;
-    property G: IECPoint read GetG;
-    property Curve: IECCurve read GetCurve;
-
-    class procedure ValidateAllowedCurves(const ACurve: IECCurve);
-      static; inline;
-
-    procedure Reset();
-
-  public
-
-    property Order: TBigInteger read GetOrder;
-    property AlgorithmName: String read GetAlgorithmName;
-
-    procedure Init(AForSigning: Boolean; const AParameters: ICipherParameters;
-      const ADigest: IDigest); virtual;
-
-    function GenerateSignature(const AMessage: TCryptoLibByteArray)
-      : TCryptoLibGenericArray<TBigInteger>; virtual;
-
-    function VerifySignature(const AMessage: TCryptoLibByteArray;
-      const ARSig, ASSig: TBigInteger): Boolean; virtual;
-
-  end;
-
-implementation
-
-{ TECSchnorrSipaSigner }
-
-function TECSchnorrSipaSigner.GenerateSignature(const AMessage
-  : TCryptoLibByteArray): TCryptoLibGenericArray<TBigInteger>;
-var
-  LN, LK, LS, LXr, LYr, LE, LPrivateKey: TBigInteger;
-  LInput, LKeyPrefixedM: TCryptoLibByteArray;
-  LP, LR: IECPoint;
-  LNumBytes: Int32;
-begin
-  if (not FForSigning) then
-  begin
-    // not properly initialized... deal with it
-    raise EInvalidOperationCryptoLibException.CreateRes
-      (@SNotInitializedForSigning);
-  end;
-
-  LN := Order;
-  LNumBytes := TBigIntegers.GetUnsignedByteLength(LN);
-
-  LPrivateKey := (FKey as IECPrivateKeyParameters).D;
-
-  LInput := TArrayUtilities.Concatenate<Byte>(TBigIntegers.BigIntegerToBytes(LPrivateKey,
-    LNumBytes), AMessage);
-
-  LK := TBigInteger.Create(1, TDigestUtilities.DoFinal(FDigest, LInput)).&Mod(LN);
-
-  if LK.CompareTo(TBigInteger.Zero) = 0 then
-  begin
-    raise EInvalidOperationCryptoLibException.CreateRes
-      (@SSignatureGenerationError);
-  end;
-
-  LR := G.Multiply(LK).Normalize();
-  LXr := LR.XCoord.ToBigInteger();
-  LYr := LR.YCoord.ToBigInteger();
-  if (TBigInteger.Jacobi(LYr, PP) <> 1) then
-  begin
-    LK := LN.Subtract(LK);
-  end;
-
-  LP := G.Multiply(LPrivateKey);
-
-  LKeyPrefixedM := TArrayUtilities.Concatenate<Byte>
-  ([
-    TBigIntegers.BigIntegerToBytes(LXr, LNumBytes),
-    LP.GetEncoded(true),
-    AMessage
-  ]);
-
-  LE := TBigInteger.Create(1, TDigestUtilities.DoFinal(FDigest,
-    LKeyPrefixedM)).&Mod(LN);
-
-  LS := LK.Add(LE.Multiply(LPrivateKey)).&Mod(LN);
-
-  Result := TCryptoLibGenericArray<TBigInteger>.Create(LXr, LS);
-end;
-
-function TECSchnorrSipaSigner.GetAlgorithmName: String;
-begin
-  Result := 'ECSCHNORRSIPA';
-end;
-
-function TECSchnorrSipaSigner.GetCurve: IECCurve;
-begin
-  Result := FKey.Parameters.Curve;
-end;
-
-function TECSchnorrSipaSigner.GetG: IECPoint;
-begin
-  Result := FKey.Parameters.G;
-end;
-
-function TECSchnorrSipaSigner.GetOrder: TBigInteger;
-begin
-  Result := FKey.Parameters.N;
-end;
-
-function TECSchnorrSipaSigner.GetPP: TBigInteger;
-begin
-  Result := Curve.Field.Characteristic;
-end;
-
-class procedure TECSchnorrSipaSigner.ValidateAllowedCurves
-  (const ACurve: IECCurve);
-begin
-  if (not(TECAlgorithms.IsFpCurve(ACurve))) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SOnlyFPCurvesAllowed);
-  end;
-end;
-
-procedure TECSchnorrSipaSigner.Init(AForSigning: Boolean;
-  const AParameters: ICipherParameters; const ADigest: IDigest);
-var
-  LParameters: ICipherParameters;
-  LProvidedRandom: ISecureRandom;
-begin
-  FForSigning := AForSigning;
-  FDigest := ADigest;
-
-  if (AForSigning) then
-  begin
-    LParameters := TParameterUtilities.GetRandom(AParameters, LProvidedRandom);
-
-    if LProvidedRandom <> nil then
-      FRandom := LProvidedRandom
-    else
-      FRandom := TSecureRandom.Create();
-
-    if (not(Supports(LParameters, IECPrivateKeyParameters))) then
-    begin
-      raise EInvalidKeyCryptoLibException.CreateRes(@SECPrivateKeyNotFound);
-    end;
-
-    FKey := LParameters as IECPrivateKeyParameters;
-  end
-  else
-  begin
-    LParameters := TParameterUtilities.IgnoreRandom(AParameters);
-
-    if (not(Supports(LParameters, IECPublicKeyParameters))) then
-    begin
-      raise EInvalidKeyCryptoLibException.CreateRes(@SECPublicKeyNotFound);
-    end;
-
-    FKey := LParameters as IECPublicKeyParameters;
-  end;
-
-  ValidateAllowedCurves(Curve);
-  Reset();
-end;
-
-procedure TECSchnorrSipaSigner.Reset;
-begin
-  FDigest.Reset;
-end;
-
-function TECSchnorrSipaSigner.VerifySignature(const AMessage
-  : TCryptoLibByteArray; const ARSig, ASSig: TBigInteger): Boolean;
-var
-  LN, LE: TBigInteger;
-  LPublicKeyBytes, LInput: TCryptoLibByteArray;
-  LPublicKey: IECPublicKeyParameters;
-  LP, LQ, LR: IECPoint;
-  LNumBytes: Int32;
-begin
-  if (FForSigning) then
-  begin
-    // not properly initialized... deal with it
-    raise EInvalidOperationCryptoLibException.CreateRes
-      (@SNotInitializedForVerifying);
-  end;
-
-  LN := Order;
-  LNumBytes := TBigIntegers.GetUnsignedByteLength(LN);
-
-  if ((ARSig.CompareTo(PP) >= 0) or (ASSig.CompareTo(LN) >= 0)) then
-  begin
-    Result := false;
-    Exit;
-  end;
-
-  LPublicKey := (FKey as IECPublicKeyParameters);
-  LPublicKeyBytes := LPublicKey.Q.GetEncoded(true);
-
-  LInput := TArrayUtilities.Concatenate<Byte>
-  ([
-    TBigIntegers.BigIntegerToBytes(ARSig, LNumBytes),
-    LPublicKeyBytes,
-    AMessage
-  ]);
-
-  LE := TBigInteger.Create(1, TDigestUtilities.DoFinal(FDigest, LInput)).&Mod(LN);
-  LQ := LPublicKey.Q.Normalize();
-  LP := Curve.CreatePoint(LQ.XCoord.ToBigInteger(), LQ.YCoord.ToBigInteger());
-
-  LR := G.Multiply(ASSig).Add(LP.Multiply(LN.Subtract(LE))).Normalize();
-
-  if ((LR.IsInfinity) or (LR.XCoord.ToBigInteger().CompareTo(ARSig) <> 0) or
-    (TBigInteger.Jacobi(LR.YCoord.ToBigInteger(), PP) <> 1)) then
-  begin
-    Result := false;
-    Exit;
-  end;
-
-  Result := true;
-end;
-
-end.

+ 0 - 274
CryptoLib/src/Crypto/Signers/ClpSchnorrDigestSigner.pas

@@ -1,274 +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 ClpSchnorrDigestSigner;
-
-{$I ..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  SysUtils,
-  Classes,
-  ClpISchnorr,
-  ClpISchnorrExt,
-  ClpISignersEncodings,
-  ClpISchnorrDigestSigner,
-  ClpIDigest,
-  ClpBigInteger,
-  ClpBigIntegers,
-  ClpCryptoLibTypes,
-  ClpIAsymmetricKeyParameter,
-  ClpICipherParameters,
-  ClpISigner,
-  ClpParameterUtilities;
-
-resourcestring
-  SPrivateKey = 'Signing Requires Private Key.';
-  SPublicKey = 'Verification Requires Public Key.';
-  SSchnorrDigestSignerNotInitializedForSignatureGeneration =
-    'SchnorrDigestSigner not Initialized for Signature Generation.';
-  SSchnorrDigestSignerNotInitializedForVerification =
-    'SchnorrDigestSigner not Initialized for Verification';
-  SEncodingError = 'Unable to Encode Signature';
-
-type
-  TSchnorrDigestSigner = class(TInterfacedObject, ISigner, ISchnorrDigestSigner)
-
-  strict private
-  var
-    FDigest: IDigest;
-    FSchnorr: ISchnorr;
-    FForSigning: Boolean;
-    FEncoding: ISchnorrEncoding;
-    FBuffer: TMemoryStream;
-
-    function Aggregate: TCryptoLibByteArray; inline;
-
-  strict protected
-
-    function GetOrder(): TBigInteger; virtual;
-
-  public
-    // constructor Create(const Schnorr: ISchnorr; const digest: IDigest);
-    // overload;
-    constructor Create(const ASchnorr: ISchnorrExt; const ADigest: IDigest;
-      const AEncoding: ISchnorrEncoding);
-    destructor Destroy(); override;
-
-    function GetAlgorithmName: String; virtual;
-    property AlgorithmName: String read GetAlgorithmName;
-
-    procedure Init(AForSigning: Boolean;
-      const AParameters: ICipherParameters); virtual;
-
-    /// <summary>
-    /// update the internal digest with the byte b
-    /// </summary>
-    procedure Update(AInput: Byte); virtual;
-
-    /// <summary>
-    /// update the internal digest with the byte array in
-    /// </summary>
-    procedure BlockUpdate(const AInput: TCryptoLibByteArray;
-      AInOff, ALength: Int32); virtual;
-
-    /// <summary>
-    /// Return the maximum size for a signature produced by this signer.
-    /// </summary>
-    function GetMaxSignatureSize: Int32; virtual;
-
-    /// <summary>
-    /// Generate a signature for the message we've been loaded with using the
-    /// key we were initialised with.
-    /// </summary>
-    function GenerateSignature(): TCryptoLibByteArray; virtual;
-
-    /// <returns>
-    /// true if the internal state represents the signature described in the
-    /// passed in array.
-    /// </returns>
-    function VerifySignature(const ASignature: TCryptoLibByteArray)
-      : Boolean; virtual;
-
-    /// <summary>
-    /// Reset the internal state
-    /// </summary>
-    procedure Reset(); virtual;
-
-  end;
-
-implementation
-
-{ TSchnorrDigestSigner }
-
-function TSchnorrDigestSigner.Aggregate: TCryptoLibByteArray;
-begin
-  Result := nil;
-  if FBuffer.Size > 0 then
-  begin
-    FBuffer.Position := 0;
-    System.SetLength(Result, FBuffer.Size);
-    FBuffer.Read(Result[0], FBuffer.Size);
-  end;
-end;
-
-procedure TSchnorrDigestSigner.BlockUpdate(const AInput: TCryptoLibByteArray;
-  AInOff, ALength: Int32);
-begin
-  if AInput <> nil then
-  begin
-    FBuffer.Write(AInput[AInOff], ALength);
-  end;
-end;
-
-// constructor TSchnorrDigestSigner.Create(const Schnorr: ISchnorr;
-// const digest: IDigest);
-// begin
-// Inherited Create();
-// FSchnorr := Schnorr;
-// FDigest := digest;
-// FBuffer := TMemoryStream.Create();
-// end;
-
-constructor TSchnorrDigestSigner.Create(const ASchnorr: ISchnorrExt;
-  const ADigest: IDigest; const AEncoding: ISchnorrEncoding);
-begin
-  Inherited Create();
-  FSchnorr := ASchnorr;
-  FDigest := ADigest;
-  FEncoding := AEncoding;
-  FBuffer := TMemoryStream.Create();
-end;
-
-destructor TSchnorrDigestSigner.Destroy;
-begin
-  FBuffer.Free;
-  inherited Destroy;
-end;
-
-function TSchnorrDigestSigner.GenerateSignature: TCryptoLibByteArray;
-var
-  LSig: TCryptoLibGenericArray<TBigInteger>;
-begin
-  if ((not FForSigning)) then
-  begin
-    raise EInvalidOperationCryptoLibException.CreateRes
-      (@SSchnorrDigestSignerNotInitializedForSignatureGeneration);
-  end;
-
-  LSig := FSchnorr.GenerateSignature(Aggregate());
-
-  try
-    Result := FEncoding.Encode(GetOrder(), LSig[0], LSig[1]);
-  except
-    raise EInvalidOperationCryptoLibException.CreateRes(@SEncodingError);
-  end;
-end;
-
-function TSchnorrDigestSigner.GetAlgorithmName: String;
-begin
-  Result := FDigest.AlgorithmName + 'with' + FSchnorr.AlgorithmName;
-end;
-
-function TSchnorrDigestSigner.GetMaxSignatureSize: Int32;
-var
-  LOrder: TBigInteger;
-begin
-  LOrder := GetOrder();
-  if LOrder.IsInitialized then
-  begin
-    // Schnorr signature is two big integers (r, s), each the size of the order
-    // For standard encoding, add some overhead for ASN.1 structure
-    Result := (TBigIntegers.GetByteLength(LOrder) * 2) + 20; // 20 bytes overhead for ASN.1
-  end
-  else
-  begin
-    // Fallback: assume 256-bit order (32 bytes per component)
-    Result := 84; // 2 * 32 + 20 overhead
-  end;
-end;
-
-function TSchnorrDigestSigner.GetOrder: TBigInteger;
-begin
-  if Supports(FSchnorr, ISchnorrExt) then
-  begin
-    Result := (FSchnorr as ISchnorrExt).Order;
-  end
-  else
-  begin
-    Result := Default(TBigInteger);
-  end;
-end;
-
-procedure TSchnorrDigestSigner.Init(AForSigning: Boolean;
-  const AParameters: ICipherParameters);
-var
-  LKey: IAsymmetricKeyParameter;
-begin
-  FForSigning := AForSigning;
-
-  LKey := TParameterUtilities.IgnoreRandom(AParameters) as IAsymmetricKeyParameter;
-
-  if (AForSigning and (not LKey.IsPrivate)) then
-  begin
-    raise EInvalidKeyCryptoLibException.CreateRes(@SPrivateKey);
-  end;
-
-  if ((not AForSigning) and LKey.IsPrivate) then
-  begin
-    raise EInvalidKeyCryptoLibException.CreateRes(@SPublicKey);
-  end;
-
-  Reset();
-
-  FSchnorr.Init(AForSigning, AParameters, FDigest);
-end;
-
-procedure TSchnorrDigestSigner.Reset;
-begin
-  FDigest.Reset;
-  FBuffer.Clear;
-  FBuffer.SetSize(Int64(0));
-end;
-
-procedure TSchnorrDigestSigner.Update(AInput: Byte);
-begin
-  FBuffer.Write(TCryptoLibByteArray.Create(AInput)[0], 1);
-end;
-
-function TSchnorrDigestSigner.VerifySignature(const ASignature
-  : TCryptoLibByteArray): Boolean;
-var
-  LSig: TCryptoLibGenericArray<TBigInteger>;
-begin
-  if (FForSigning) then
-  begin
-    raise EInvalidOperationCryptoLibException.CreateRes
-      (@SSchnorrDigestSignerNotInitializedForVerification);
-  end;
-
-  try
-    LSig := FEncoding.Decode(GetOrder(), ASignature);
-    Result := FSchnorr.VerifySignature(Aggregate(), LSig[0], LSig[1]);
-  except
-    Result := false;
-  end;
-
-end;
-
-end.

+ 0 - 3
CryptoLib/src/Crypto/Signers/ClpSignerUtilities.pas

@@ -61,9 +61,6 @@ uses
   ClpISecureRandom,
   ClpIAsn1Objects,
   ClpSignersEncodings,
-  ClpSchnorrDigestSigner,
-  ClpECSchnorrSipaSigner,
-  ClpIECSchnorrSipaSigner,
   ClpRsaDigestSigner,
   ClpIRsaDigestSigner,
   ClpPssSigner,

+ 0 - 90
CryptoLib/src/Crypto/Signers/SignerEncodings/ClpSignersEncodings.pas

@@ -92,33 +92,6 @@ type
 
   end;
 
-type
-  TPlainSchnorrEncoding = class(TInterfacedObject, ISchnorrEncoding,
-    IPlainSchnorrEncoding)
-
-  strict private
-
-    class function GetInstance: IPlainSchnorrEncoding; static; inline;
-
-  strict protected
-
-    function CheckValue(const AN, AX: TBigInteger): TBigInteger; virtual;
-    function DecodeValue(const AN: TBigInteger; const ABuf: TCryptoLibByteArray;
-      AOff, ALength: Int32): TBigInteger; virtual;
-    procedure EncodeValue(const AN, AX: TBigInteger;
-      const ABuf: TCryptoLibByteArray; AOff, ALength: Int32); virtual;
-
-  public
-
-    function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
-      : TCryptoLibGenericArray<TBigInteger>; virtual;
-
-    function Encode(const AN, AR, &AS: TBigInteger): TCryptoLibByteArray; virtual;
-
-    class property Instance: IPlainSchnorrEncoding read GetInstance;
-
-  end;
-
 implementation
 
 { TStandardDsaEncoding }
@@ -254,67 +227,4 @@ begin
   Result := TPlainDsaEncoding.Create();
 end;
 
-{ TPlainSchnorrEncoding }
-
-function TPlainSchnorrEncoding.CheckValue(const AN, AX: TBigInteger): TBigInteger;
-begin
-  if ((AX.SignValue < 0) or ((AX.CompareTo(AN) >= 0))) then
-  begin
-    raise EArgumentCryptoLibException.CreateResFmt(@SValueOutOfRange, ['x']);
-  end;
-  Result := AX;
-end;
-
-function TPlainSchnorrEncoding.Decode(const AN: TBigInteger;
-  const AEncoding: TCryptoLibByteArray): TCryptoLibGenericArray<TBigInteger>;
-var
-  LValueLength: Int32;
-begin
-  LValueLength := TBigIntegers.GetUnsignedByteLength(AN);
-  if (System.Length(AEncoding) <> (LValueLength * 2)) then
-  begin
-    raise EArgumentCryptoLibException.CreateResFmt(@SInvalidEncodingLength,
-      ['encoding']);
-  end;
-  Result := TCryptoLibGenericArray<TBigInteger>.Create
-    (DecodeValue(AN, AEncoding, 0, LValueLength), DecodeValue(AN, AEncoding,
-    LValueLength, LValueLength));
-end;
-
-function TPlainSchnorrEncoding.DecodeValue(const AN: TBigInteger;
-  const ABuf: TCryptoLibByteArray; AOff, ALength: Int32): TBigInteger;
-begin
-  Result := CheckValue(AN, TBigInteger.Create(1, ABuf, AOff, ALength));
-end;
-
-function TPlainSchnorrEncoding.Encode(const AN, AR, &AS: TBigInteger)
-  : TCryptoLibByteArray;
-var
-  LValueLength: Int32;
-begin
-  LValueLength := TBigIntegers.GetUnsignedByteLength(AN);
-  System.SetLength(Result, LValueLength * 2);
-  EncodeValue(AN, AR, Result, 0, LValueLength);
-  EncodeValue(AN, &AS, Result, LValueLength, LValueLength);
-end;
-
-procedure TPlainSchnorrEncoding.EncodeValue(const AN, AX: TBigInteger;
-  const ABuf: TCryptoLibByteArray; AOff, ALength: Int32);
-var
-  LBs: TCryptoLibByteArray;
-  LBsOff, LBsLen, LPos: Int32;
-begin
-  LBs := CheckValue(AN, AX).ToByteArrayUnsigned();
-  LBsOff := Max(0, System.Length(LBs) - ALength);
-  LBsLen := System.Length(LBs) - LBsOff;
-  LPos := ALength - LBsLen;
-  TArrayUtilities.Fill<Byte>(ABuf, AOff, AOff + LPos, Byte(0));
-  System.Move(LBs[LBsOff], ABuf[AOff + LPos], LBsLen * System.SizeOf(Byte));
-end;
-
-class function TPlainSchnorrEncoding.GetInstance: IPlainSchnorrEncoding;
-begin
-  Result := TPlainSchnorrEncoding.Create();
-end;
-
 end.

+ 0 - 53
CryptoLib/src/Interfaces/ClpISchnorr.pas

@@ -1,53 +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 ClpISchnorr;
-
-{$I ..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpIDigest,
-  ClpBigInteger,
-  ClpICipherParameters,
-  ClpCryptoLibTypes;
-
-type
-  /// <summary>
-  /// interface for classes implementing the Schnorr Signature Algorithm
-  /// </summary>
-  ISchnorr = interface(IInterface)
-    ['{B8065C83-1164-4DD0-B983-8CF840F120EF}']
-
-    function GetAlgorithmName: String;
-    property AlgorithmName: String read GetAlgorithmName;
-
-    procedure Init(AForSigning: Boolean; const AParameters: ICipherParameters;
-      const ADigest: IDigest);
-
-    function GenerateSignature(const AMessage: TCryptoLibByteArray)
-      : TCryptoLibGenericArray<TBigInteger>;
-
-    function VerifySignature(const AMessage: TCryptoLibByteArray;
-      const AR, &AS: TBigInteger): Boolean;
-
-  end;
-
-implementation
-
-end.

+ 0 - 44
CryptoLib/src/Interfaces/ClpISchnorrExt.pas

@@ -1,44 +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 ClpISchnorrExt;
-
-{$I ..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpISchnorr,
-  ClpBigInteger;
-
-type
-  /// <summary>
-  /// An "extended" interface for classes implementing Schnorr-style algorithms, that provides access
-  /// to the group order.
-  /// </summary>
-  ISchnorrExt = interface(ISchnorr)
-    ['{0BCED764-F352-4C6C-B30C-9E0D7A2B042B}']
-
-    function GetOrder: TBigInteger;
-    /// <summary>The order of the group that the r, s values in signatures belong to.</summary>
-    property Order: TBigInteger read GetOrder;
-
-  end;
-
-implementation
-
-end.

+ 0 - 39
CryptoLib/src/Interfaces/Crypto/Signers/ClpISchnorrDigestSigner.pas

@@ -1,39 +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 ClpISchnorrDigestSigner;
-
-{$I ..\..\..\Include\CryptoLib.inc}
-
-interface
-
-uses
-  ClpISigner,
-  ClpBigInteger;
-
-type
-
-  ISchnorrDigestSigner = interface(ISigner)
-    ['{FD48778F-A071-459A-9008-423566240F09}']
-
-    function GetOrder(): TBigInteger;
-
-  end;
-
-implementation
-
-end.

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

@@ -53,28 +53,6 @@ type
 
   end;
 
-type
-  /// <summary>
-  /// An interface for different encoding formats for Schnorr signatures.
-  /// </summary>
-  ISchnorrEncoding = interface(IInterface)
-    ['{CC5ECEFB-D806-402F-9F86-8D17EC61BE00}']
-
-    /// <summary>Decode the (r, s) pair of a Schnorr signature.</summary>
-    /// <param name="n">The order of the group that r, s belong to.</param>
-    /// <param name="encoding">An encoding of the (r, s) pair of a Schnorr signature.</param>
-    /// <returns>The (r, s) of a Schnorr signature, stored in an array of exactly two elements, r followed by s.</returns>
-    function Decode(const AN: TBigInteger; const AEncoding: TCryptoLibByteArray)
-      : TCryptoLibGenericArray<TBigInteger>;
-    /// <summary>Encode the (r, s) pair of a Schnorr signature.</summary>
-    /// <param name="n">The order of the group that r, s belong to.</param>
-    /// <param name="r">The r value of a Schnorr signature.</param>
-    /// <param name="s">The s value of a Schnorr signature.</param>
-    /// <returns>An encoding of the Schnorr signature given by the provided (r, s) pair.</returns>
-    function Encode(const AN, AR, &AS: TBigInteger): TCryptoLibByteArray;
-
-  end;
-
 type
   IStandardDsaEncoding = interface(IDsaEncoding)
     ['{A8662374-922B-4D72-B956-FE0ED3505C68}']
@@ -98,18 +76,6 @@ type
 
   end;
 
-type
-  IPlainSchnorrEncoding = interface(ISchnorrEncoding)
-    ['{1C2D1D11-04C4-4438-B728-4BF3ED2F3E99}']
-
-    function CheckValue(const AN, AX: TBigInteger): TBigInteger;
-    function DecodeValue(const AN: TBigInteger; const ABuf: TCryptoLibByteArray;
-      AOff, ALength: Int32): TBigInteger;
-    procedure EncodeValue(const AN, AX: TBigInteger;
-      const ABuf: TCryptoLibByteArray; AOff, ALength: Int32);
-
-  end;
-
 implementation
 
 end.

+ 0 - 6
CryptoLib/src/Interfaces/Math/EC/Rfc8032/ClpIEd25519.pas

@@ -95,12 +95,6 @@ type
 
   end;
 
-type
-  IEd25519Blake2B = interface(IEd25519)
-    ['{4EF6C436-D49D-4442-A014-848E08D81BE6}']
-
-  end;
-
 implementation
 
 end.

+ 15 - 0
CryptoLib/src/Math/ClpBigInteger.pas

@@ -218,6 +218,8 @@ type
     function ToByteArray(): TCryptoLibByteArray;
     function ToByteArrayUnsigned(): TCryptoLibByteArray;
     function ToByteArrayInternal(const AUnsigned: Boolean): TCryptoLibByteArray;
+    function GetLengthofByteArray(): Int32;
+    function GetLengthofByteArrayUnsigned(): Int32;
     function ToString(): String; overload;
     function ToString(const ARadix: Int32): String; overload;
     procedure ToStringRecursive(var ASb: String; const ARadix: Int32; const AModuli: TCryptoLibGenericArray<TBigInteger>; const AScale: Int32; const APos: TBigInteger);
@@ -3214,6 +3216,19 @@ begin
   Result := ToByteArrayInternal(True);
 end;
 
+function TBigInteger.GetLengthofByteArray(): Int32;
+begin
+  Result := GetBytesLength(BitLength + 1);
+end;
+
+function TBigInteger.GetLengthofByteArrayUnsigned(): Int32;
+begin
+  if SignValue < 0 then
+    Result := GetBytesLength(BitLength + 1)
+  else
+    Result := GetBytesLength(BitLength);
+end;
+
 function TBigInteger.ToByteArrayInternal(const AUnsigned: Boolean): TCryptoLibByteArray;
 var
   LNBits, LNBytes, LMagIndex, LBytesIndex, J: Int32;

+ 216 - 180
CryptoLib/src/Math/ClpBigIntegers.pas

@@ -22,291 +22,327 @@ unit ClpBigIntegers;
 interface
 
 uses
-  Math,
+  SysUtils,
+  Classes,
   ClpBigInteger,
-  ClpCryptoLibTypes,
-  ClpISecureRandom;
+  ClpISecureRandom,
+  ClpCryptoLibTypes;
 
 resourcestring
-  SInvalidLength = 'Standard Length Exceeded, "n"';
-  SInvalidMinValue = '"min" may not be greater than "max""';
+  SStandardLengthExceeded = 'standard length exceeded';
+  SMinMayNotBeGreaterThanMax = '''min'' may not be greater than ''max''';
+  SMustBeOdd = 'must be odd';
+  SModulusNotPositive = 'BigInteger: modulus not positive';
 
 type
-
   /// <summary>
   /// BigInteger utilities.
   /// </summary>
-  TBigIntegers = class abstract(TObject)
-
+  TBigIntegers = class sealed(TObject)
   strict private
-  const
-    MaxIterations = Int32(1000);
+    const
+      MaxIterations = 1000;
+
+    class constructor Create;
 
   public
+    class var
+      Zero: TBigInteger;
+      One: TBigInteger;
 
     /// <summary>
     /// Return the passed in value as an unsigned byte array.
     /// </summary>
-    /// <param name="n">
-    /// value to be converted.
-    /// </param>
-    /// <returns>
-    /// a byte array without a leading zero byte if present in the signed
-    /// encoding.
-    /// </returns>
-    class function AsUnsignedByteArray(const n: TBigInteger)
-      : TCryptoLibByteArray; overload; static;
+    /// <param name="AN">the value to be converted.</param>
+    /// <returns>a byte array without a leading zero byte if present in the signed encoding.</returns>
+    class function AsUnsignedByteArray(const AN: TBigInteger): TCryptoLibByteArray; overload; static;
+
+    /// <summary>
+    /// Return the passed in value as an unsigned byte array of the specified length, padded with
+    /// leading zeros as necessary.
+    /// </summary>
+    /// <param name="ALength">the fixed length of the result.</param>
+    /// <param name="AN">the value to be converted.</param>
+    /// <returns>a byte array padded to a fixed length with leading zeros.</returns>
+    class function AsUnsignedByteArray(const ALength: Int32; const AN: TBigInteger): TCryptoLibByteArray; overload; static;
+
+    /// <summary>
+    /// Write the passed in value as unsigned bytes to the specified buffer range, padded with
+    /// leading zeros as necessary.
+    /// </summary>
+    /// <param name="AN">the value to be converted.</param>
+    /// <param name="ABuf">the buffer to which the value is written.</param>
+    /// <param name="AOff">the start offset in array ABuf at which the data is written.</param>
+    /// <param name="ALen">the fixed length of data written (possibly padded with leading zeros).</param>
+    class procedure AsUnsignedByteArray(const AN: TBigInteger; var ABuf: TCryptoLibByteArray; const AOff, ALen: Int32); overload; static;
+
+    /// <summary>
+    /// Creates a Random BigInteger from the secure random of a given bit length.
+    /// </summary>
+    /// <param name="ABitLength">the bit length.</param>
+    /// <param name="ASecureRandom">the source of randomness.</param>
+    /// <returns>a random BigInteger value.</returns>
+    class function CreateRandomBigInteger(const ABitLength: Int32; const ASecureRandom: ISecureRandom): TBigInteger; static;
+
+    /// <summary>
+    /// Return a random BigInteger not less than 'min' and not greater than 'max'
+    /// </summary>
+    /// <param name="AMin">the least value that may be generated.</param>
+    /// <param name="AMax">the greatest value that may be generated.</param>
+    /// <param name="ARandom">the source of randomness.</param>
+    /// <returns>a random BigInteger value in the range [min,max].</returns>
+    class function CreateRandomInRange(const AMin, AMax: TBigInteger; const ARandom: ISecureRandom): TBigInteger; static;
+
+    /// <summary>
+    /// Create a BigInteger from an unsigned byte array.
+    /// </summary>
+    /// <param name="ABuf">the byte array.</param>
+    /// <returns>a BigInteger value.</returns>
+    class function FromUnsignedByteArray(const ABuf: TCryptoLibByteArray): TBigInteger; overload; static;
 
     /// <summary>
-    /// the passed in value as an unsigned byte array of specified length,
-    /// zero-extended as necessary.
+    /// Create a BigInteger from an unsigned byte array.
     /// </summary>
-    /// <param name="length">
-    /// length desired length of result array.
-    /// </param>
-    /// <param name="n">
-    /// value to be converted.
-    /// </param>
-    /// <returns>
-    /// a byte array of specified length, with leading zeroes as necessary
-    /// given the size of n.
-    /// </returns>
-    class function AsUnsignedByteArray(length: Int32; const n: TBigInteger)
-      : TCryptoLibByteArray; overload; static;
+    /// <param name="ABuf">the byte array.</param>
+    /// <param name="AOff">the start offset in array ABuf.</param>
+    /// <param name="ALength">the length of data.</param>
+    /// <returns>a BigInteger value.</returns>
+    class function FromUnsignedByteArray(const ABuf: TCryptoLibByteArray; const AOff, ALength: Int32): TBigInteger; overload; static;
 
     /// <summary>
-    /// Return a random BigInteger not less than 'min' and not greater than
-    /// 'max'
+    /// Get the byte length of a BigInteger.
     /// </summary>
-    /// <param name="min">
-    /// the least value that may be generated
-    /// </param>
-    /// <param name="max">
-    /// the greatest value that may be generated
-    /// </param>
-    /// <param name="random">
-    /// the source of randomness
-    /// </param>
-    /// <returns>
-    /// a random BigInteger value in the range [min,max]
-    /// </returns>
-    class function CreateRandomInRange(const min, max: TBigInteger;
-      // TODO Should have been just Random class
-      const random: ISecureRandom): TBigInteger; static;
+    /// <param name="AN">the BigInteger.</param>
+    /// <returns>the byte length.</returns>
+    class function GetByteLength(const AN: TBigInteger): Int32; static;
 
     /// <summary>
-    /// <para>
-    /// The regular <b>BigInteger.toByteArray()</b> includes the sign bit
-    /// of the number and <br />might result in an extra byte addition.
-    /// This method removes this extra byte.
-    /// </para>
+    /// Get the unsigned byte length of a BigInteger.
     /// </summary>
-    /// <param name="b">
-    /// the integer to format into a byte array
-    /// </param>
-    /// <param name="numBytes">
-    /// the desired size of the resulting byte array
-    /// </param>
-    /// <returns>
-    /// numBytes byte long array.
-    /// </returns>
-    class function BigIntegerToBytes(const b: TBigInteger; numBytes: Int32)
-      : TCryptoLibByteArray; static; inline;
-
-    class function GetByteLength(const n: TBigInteger): Int32;
-
-    class function GetUnsignedByteLength(const n: TBigInteger): Int32;
-      static; inline;
+    /// <param name="AN">the BigInteger.</param>
+    /// <returns>the unsigned byte length.</returns>
+    class function GetUnsignedByteLength(const AN: TBigInteger): Int32; static;
 
     /// <summary>
-    /// Calculate the modular inverse of X mod M where M is odd.
+    /// Write the passed in value as unsigned bytes to the specified stream.
     /// </summary>
-    /// <param name="M">The odd modulus (must be positive and odd)</param>
-    /// <param name="X">The value to invert</param>
-    /// <returns>X^(-1) mod M</returns>
-    /// <exception cref="EArithmeticCryptoLibException">If M is not positive, not odd, or X is not invertible</exception>
-    class function ModOddInverse(const M, X: TBigInteger): TBigInteger; static;
+    /// <param name="AOutStr">the stream to which the value is written.</param>
+    /// <param name="AN">the value to be converted.</param>
+    class procedure WriteUnsignedByteArray(const AOutStr: TStream; const AN: TBigInteger); static;
 
     /// <summary>
-    /// Check if two BigIntegers are coprime (gcd = 1) for an odd modulus.
-    /// Uses GCD-based calculation - variable time but simpler than constant-time approach.
+    /// ModOddInverseVar.
     /// </summary>
-    /// <param name="M">The odd modulus (must be positive and odd)</param>
-    /// <param name="X">The value to check for coprimality</param>
-    /// <returns>True if gcd(M, X) = 1, False otherwise</returns>
-    class function ModOddIsCoprimeVar(const M, X: TBigInteger): Boolean; static;
+    /// <param name="AM">the modulus (must be odd).</param>
+    /// <param name="AX">the value to invert.</param>
+    /// <returns>inverse.</returns>
+    class function ModOddInverseVar(const AM, AX: TBigInteger): TBigInteger; static;
 
+    /// <summary>
+    /// ModOddIsCoprimeVar.
+    /// </summary>
+    /// <param name="AM">the modulus (must be odd).</param>
+    /// <param name="AX">the value to check.</param>
+    /// <returns>whether is coprime or not.</returns>
+    class function ModOddIsCoprimeVar(const AM, AX: TBigInteger): Boolean; static;
   end;
 
 implementation
 
+uses
+  ClpArrayUtilities;
+
 { TBigIntegers }
 
-class function TBigIntegers.AsUnsignedByteArray(const n: TBigInteger)
-  : TCryptoLibByteArray;
+class constructor TBigIntegers.Create;
+begin
+  Zero := TBigInteger.Zero;
+  One := TBigInteger.One;
+end;
+
+class function TBigIntegers.AsUnsignedByteArray(const AN: TBigInteger): TCryptoLibByteArray;
 begin
-  Result := n.ToByteArrayUnsigned();
+  Result := AN.ToByteArrayUnsigned();
 end;
 
-class function TBigIntegers.AsUnsignedByteArray(length: Int32;
-  const n: TBigInteger): TCryptoLibByteArray;
+class function TBigIntegers.AsUnsignedByteArray(const ALength: Int32; const AN: TBigInteger): TCryptoLibByteArray;
 var
-  bytes: TCryptoLibByteArray;
+  LBytes: TCryptoLibByteArray;
+  LBytesLength: Int32;
+  I: Int32;
 begin
-  Result := nil;
-  bytes := n.ToByteArrayUnsigned();
+  LBytes := AN.ToByteArrayUnsigned();
+  LBytesLength := System.Length(LBytes);
 
-  if (System.length(bytes) > length) then
-  begin
-    raise EArgumentCryptoLibException.CreateRes(@SInvalidLength);
-  end;
+  if LBytesLength > ALength then
+    raise EArgumentCryptoLibException.Create(SStandardLengthExceeded);
 
-  if (System.length(bytes) = length) then
+  if LBytesLength = ALength then
   begin
-    Result := bytes;
+    Result := LBytes;
     Exit;
   end;
 
-  System.SetLength(Result, length);
-  // Explicitly zero-initialize the array to ensure leading zeros
-  //System.FillChar(Result[0], System.length(Result) * System.SizeOf(Byte), 0);
-  System.Move(bytes[0], Result[System.length(Result) - System.length(bytes)],
-    System.length(bytes) * System.SizeOf(Byte));
-
+  System.SetLength(Result, ALength);
+  // Fill leading bytes with zeros
+  for I := 0 to System.Pred(ALength - LBytesLength) do
+  begin
+    Result[I] := 0;
+  end;
+  // Copy the actual bytes
+  System.Move(LBytes[0], Result[ALength - LBytesLength], LBytesLength * System.SizeOf(Byte));
 end;
 
-class function TBigIntegers.BigIntegerToBytes(const b: TBigInteger;
-  numBytes: Int32): TCryptoLibByteArray;
+class procedure TBigIntegers.AsUnsignedByteArray(const AN: TBigInteger; var ABuf: TCryptoLibByteArray; const AOff, ALen: Int32);
 var
-  biBytes: TCryptoLibByteArray;
-  start, length: Int32;
+  LBytes: TCryptoLibByteArray;
+  LBytesLength: Int32;
+  LPadLen: Int32;
+  I: Int32;
 begin
-  System.SetLength(Result, numBytes);
-  biBytes := b.ToByteArray();
-  if System.length(biBytes) = (numBytes + 1) then
-  begin
-    start := 1
-  end
-  else
+  LBytes := AN.ToByteArrayUnsigned();
+  LBytesLength := System.Length(LBytes);
+
+  if LBytesLength > ALen then
+    raise EArgumentCryptoLibException.Create(SStandardLengthExceeded);
+
+  LPadLen := ALen - LBytesLength;
+  // Fill padding bytes with zeros
+  for I := 0 to System.Pred(LPadLen) do
   begin
-    start := 0
+    ABuf[AOff + I] := 0;
   end;
+  // Copy the actual bytes
+  System.Move(LBytes[0], ABuf[AOff + LPadLen], LBytesLength * System.SizeOf(Byte));
+end;
 
-  length := min(System.length(biBytes), numBytes);
-  System.Move(biBytes[start], Result[numBytes - length],
-    length * System.SizeOf(Byte));
+class function TBigIntegers.CreateRandomBigInteger(const ABitLength: Int32; const ASecureRandom: ISecureRandom): TBigInteger;
+begin
+  Result := TBigInteger.Create(ABitLength, ASecureRandom);
 end;
 
-class function TBigIntegers.CreateRandomInRange(const min, max: TBigInteger;
-  // TODO Should have been just Random class
-  const random: ISecureRandom): TBigInteger;
+class function TBigIntegers.CreateRandomInRange(const AMin, AMax: TBigInteger; const ARandom: ISecureRandom): TBigInteger;
 var
-  cmp, I: Int32;
-  x: TBigInteger;
+  LCmp: Int32;
+  I: Int32;
+  LX: TBigInteger;
 begin
-  cmp := min.CompareTo(max);
-  if (cmp >= 0) then
+  LCmp := AMin.CompareTo(AMax);
+  if LCmp >= 0 then
   begin
-    if (cmp > 0) then
-    begin
-      raise EArgumentCryptoLibException.CreateRes(@SInvalidMinValue);
-    end;
+    if LCmp > 0 then
+      raise EArgumentCryptoLibException.Create(SMinMayNotBeGreaterThanMax);
 
-    Result := min;
+    Result := AMin;
     Exit;
   end;
 
-  if (min.BitLength > (max.BitLength shr 1)) then
+  if AMin.BitLength > (AMax.BitLength div 2) then
   begin
-    Result := CreateRandomInRange(TBigInteger.Zero, max.Subtract(min),
-      random).Add(min);
+    Result := CreateRandomInRange(TBigInteger.Zero, AMax.Subtract(AMin), ARandom).Add(AMin);
     Exit;
   end;
 
-  I := 0;
-  while I < MaxIterations do
+  for I := 0 to System.Pred(MaxIterations) do
   begin
-    x := TBigInteger.Create(max.BitLength, random);
-    if ((x.CompareTo(min) >= 0) and (x.CompareTo(max) <= 0)) then
+    LX := TBigInteger.Create(AMax.BitLength, ARandom);
+    if (LX.CompareTo(AMin) >= 0) and (LX.CompareTo(AMax) <= 0) then
     begin
-      Result := x;
+      Result := LX;
       Exit;
     end;
-    System.Inc(I);
   end;
 
   // fall back to a faster (restricted) method
-  Result := TBigInteger.Create(max.Subtract(min).BitLength - 1, random)
-    .Add(min);
+  Result := TBigInteger.Create(AMax.Subtract(AMin).BitLength - 1, ARandom).Add(AMin);
+end;
+
+class function TBigIntegers.FromUnsignedByteArray(const ABuf: TCryptoLibByteArray): TBigInteger;
+begin
+  Result := TBigInteger.Create(1, ABuf);
 end;
 
-class function TBigIntegers.GetByteLength(const n: TBigInteger): Int32;
+class function TBigIntegers.FromUnsignedByteArray(const ABuf: TCryptoLibByteArray; const AOff, ALength: Int32): TBigInteger;
 begin
-  Result := (n.BitLength + 8) shr 3;
+  Result := TBigInteger.Create(1, ABuf, AOff, ALength);
 end;
 
-class function TBigIntegers.GetUnsignedByteLength(const n: TBigInteger): Int32;
+class function TBigIntegers.GetByteLength(const AN: TBigInteger): Int32;
 begin
-  Result := (n.BitLength + 7) shr 3;
+  Result := AN.GetLengthofByteArray();
 end;
 
-class function TBigIntegers.ModOddIsCoprimeVar(const M, X: TBigInteger): Boolean;
+class function TBigIntegers.GetUnsignedByteLength(const AN: TBigInteger): Int32;
+begin
+  Result := AN.GetLengthofByteArrayUnsigned();
+end;
+
+class procedure TBigIntegers.WriteUnsignedByteArray(const AOutStr: TStream; const AN: TBigInteger);
+var
+  LBuffer: TCryptoLibByteArray;
+begin
+  LBuffer := AN.ToByteArrayUnsigned();
+  AOutStr.Write(LBuffer, 0, System.Length(LBuffer));
+end;
+
+class function TBigIntegers.ModOddInverseVar(const AM, AX: TBigInteger): TBigInteger;
 var
-  xMod, gcd: TBigInteger;
+  LX: TBigInteger;
 begin
-  // Validate M is odd and positive
-  if not M.TestBit(0) then
+  if not AM.TestBit(0) then
+    raise EArgumentCryptoLibException.Create(SMustBeOdd);
+
+  if AM.SignValue <> 1 then
+    raise EArithmeticCryptoLibException.Create(SModulusNotPositive);
+
+  if AM.Equals(One) then
   begin
-    raise EArgumentCryptoLibException.Create('Modulus must be odd');
+    Result := Zero;
+    Exit;
   end;
 
-  if M.SignValue <> 1 then
+  LX := AX;
+
+  if (LX.SignValue < 0) or (LX.BitLength > AM.BitLength) then
   begin
-    raise EArithmeticCryptoLibException.Create('Modulus must be positive');
+    LX := LX.&Mod(AM);
   end;
 
-  // If X is 1, it's always coprime
-  if X.Equals(TBigInteger.One) then
+  if LX.Equals(One) then
   begin
-    Result := True;
+    Result := One;
     Exit;
   end;
 
-  // Reduce X mod M if necessary
-  if (X.SignValue < 0) or (X.BitLength > M.BitLength) then
-    xMod := X.&Mod(M)
-  else
-    xMod := X;
-
-  // Check if GCD(M, X) = 1
-  gcd := M.Gcd(xMod);
-  Result := gcd.Equals(TBigInteger.One);
+  // Use BigInteger's built-in ModInverse
+  Result := LX.ModInverse(AM);
 end;
 
-class function TBigIntegers.ModOddInverse(const M, X: TBigInteger): TBigInteger;
+class function TBigIntegers.ModOddIsCoprimeVar(const AM, AX: TBigInteger): Boolean;
 var
-  xMod: TBigInteger;
+  LX: TBigInteger;
 begin
-  // Validate M is odd
-  if not M.TestBit(0) then
+  if not AM.TestBit(0) then
+    raise EArgumentCryptoLibException.Create(SMustBeOdd);
+
+  if AM.SignValue <> 1 then
+    raise EArithmeticCryptoLibException.Create(SModulusNotPositive);
+
+  LX := AX;
+
+  if (LX.SignValue < 0) or (LX.BitLength > AM.BitLength) then
   begin
-    raise EArgumentCryptoLibException.Create('Modulus must be odd');
+    LX := LX.&Mod(AM);
   end;
 
-  // Validate M is positive
-  if M.SignValue <> 1 then
+  if LX.Equals(One) then
   begin
-    raise EArithmeticCryptoLibException.Create('BigInteger: modulus not positive');
+    Result := True;
+    Exit;
   end;
 
-  // Reduce X mod M if necessary
-  if (X.SignValue < 0) or (X.BitLength > M.BitLength) then
-    xMod := X.&Mod(M)
-  else
-    xMod := X;
-
-  // Use BigInteger's built-in ModInverse
-  Result := xMod.ModInverse(M);
+  // Check if GCD(M, X) = 1
+  Result := AM.Gcd(LX).Equals(One);
 end;
 
 end.

+ 0 - 30
CryptoLib/src/Math/EC/Rfc8032/ClpEd25519.pas

@@ -410,19 +410,6 @@ type
 
   end;
 
-type
-  TEd25519Blake2B = class sealed(TEd25519, IEd25519Blake2B)
-
-  strict protected
-
-    function GetAlgorithmName: String; override;
-    function CreateDigest(): IDigest; override;
-
-  public
-    constructor Create();
-
-  end;
-
 implementation
 
 { TEd25519.TPointExt }
@@ -2285,21 +2272,4 @@ begin
   result.Fy := TX25519Field.Create();
 end;
 
-{ TEd25519Blake2B }
-
-constructor TEd25519Blake2B.Create;
-begin
-  Inherited Create();
-end;
-
-function TEd25519Blake2B.CreateDigest: IDigest;
-begin
-  result := TDigestUtilities.GetDigest('BLAKE2B-512');
-end;
-
-function TEd25519Blake2B.GetAlgorithmName: String;
-begin
-  result := 'Ed25519Blake2B';
-end;
-
 end.