Ugochukwu Mmaduekwe пре 1 недеља
родитељ
комит
bde1a6a04d
63 измењених фајлова са 847 додато и 875 уклоњено
  1. 1 1
      CryptoLib.Tests/Delphi.Tests/CryptoLib.Tests.dpr
  2. 2 2
      CryptoLib.Tests/src/Asn1/TagTests.pas
  3. 2 2
      CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP256R1FieldTests.pas
  4. 2 2
      CryptoLib.Tests/src/Math/EC/Custom/Sec/SecP384R1FieldTests.pas
  5. 2 2
      CryptoLib.Tests/src/Math/ECPointTests.pas
  6. 5 5
      CryptoLib.Tests/src/Utils/ClpFixedSecureRandom.pas
  7. 3 3
      CryptoLib/src/Asn1/ClpAsn1Core.pas
  8. 6 8
      CryptoLib/src/Asn1/ClpAsn1Generators.pas
  9. 24 24
      CryptoLib/src/Asn1/ClpAsn1Objects.pas
  10. 7 7
      CryptoLib/src/Asn1/ClpAsn1Streams.pas
  11. 2 2
      CryptoLib/src/Asn1/X509/ClpRfc5280Asn1Utilities.pas
  12. 3 3
      CryptoLib/src/Asn1/X509/ClpX509Asn1Objects.pas
  13. 5 5
      CryptoLib/src/Crypto/Encodings/ClpOaepEncoding.pas
  14. 7 7
      CryptoLib/src/Crypto/Encodings/ClpPkcs1Encoding.pas
  15. 29 29
      CryptoLib/src/Crypto/Engines/ClpAesEngine.pas
  16. 29 29
      CryptoLib/src/Crypto/Engines/ClpAesLightEngine.pas
  17. 9 9
      CryptoLib/src/Crypto/Engines/ClpBlowfishEngine.pas
  18. 5 10
      CryptoLib/src/Crypto/Engines/ClpChaChaEngine.pas
  19. 2 2
      CryptoLib/src/Crypto/Engines/ClpIesEngine.pas
  20. 7 12
      CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas
  21. 3 7
      CryptoLib/src/Crypto/Engines/ClpXSalsa20Engine.pas
  22. 3 3
      CryptoLib/src/Crypto/Generators/ClpBaseKdfBytesGenerator.pas
  23. 3 3
      CryptoLib/src/Crypto/Generators/ClpDHKeyGeneratorHelper.pas
  24. 3 3
      CryptoLib/src/Crypto/Generators/ClpDHParametersHelper.pas
  25. 2 2
      CryptoLib/src/Crypto/Generators/ClpDsaKeyPairGenerator.pas
  26. 2 2
      CryptoLib/src/Crypto/Generators/ClpECKeyPairGenerator.pas
  27. 2 2
      CryptoLib/src/Crypto/Randoms/ClpSecureRandom.pas
  28. 2 2
      CryptoLib/src/Crypto/Signers/ClpDsaSigner.pas
  29. 28 37
      CryptoLib/src/GeneralUtilities/ClpStringUtilities.pas
  30. 12 12
      CryptoLib/src/Math/ClpBigInteger.pas
  31. 3 5
      CryptoLib/src/Math/ClpPrimes.pas
  32. 8 8
      CryptoLib/src/Math/EC/ClpECAlgorithms.pas
  33. 11 11
      CryptoLib/src/Math/EC/ClpECC.pas
  34. 6 6
      CryptoLib/src/Math/EC/ClpECCompUtilities.pas
  35. 6 6
      CryptoLib/src/Math/EC/ClpLongArray.pas
  36. 2 2
      CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256K1Custom.pas
  37. 32 32
      CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256R1Custom.pas
  38. 29 29
      CryptoLib/src/Math/EC/Custom/Sec/ClpSecP384R1Custom.pas
  39. 2 2
      CryptoLib/src/Math/EC/Custom/Sec/ClpSecP521R1Custom.pas
  40. 4 4
      CryptoLib/src/Math/EC/Custom/Sec/ClpSecT283Custom.pas
  41. 10 10
      CryptoLib/src/Math/EC/Multiplier/ClpMultipliers.pas
  42. 2 2
      CryptoLib/src/Math/EC/Rfc7748/ClpX25519.pas
  43. 66 66
      CryptoLib/src/Math/EC/Rfc7748/ClpX25519Field.pas
  44. 10 10
      CryptoLib/src/Math/EC/Rfc8032/ClpEd25519.pas
  45. 53 53
      CryptoLib/src/Math/EC/Rfc8032/ClpScalar25519.pas
  46. 36 36
      CryptoLib/src/Math/EC/Rfc8032/ClpScalarUtilities.pas
  47. 5 5
      CryptoLib/src/Math/EC/Rfc8032/ClpWnaf.pas
  48. 2 2
      CryptoLib/src/Math/Field/ClpGenericPolynomialExtensionField.pas
  49. 41 41
      CryptoLib/src/Math/Raw/ClpMod.pas
  50. 96 96
      CryptoLib/src/Math/Raw/ClpNat.pas
  51. 22 22
      CryptoLib/src/Math/Raw/ClpNat128.pas
  52. 27 27
      CryptoLib/src/Math/Raw/ClpNat160.pas
  53. 32 32
      CryptoLib/src/Math/Raw/ClpNat192.pas
  54. 37 37
      CryptoLib/src/Math/Raw/ClpNat224.pas
  55. 42 42
      CryptoLib/src/Math/Raw/ClpNat256.pas
  56. 1 1
      CryptoLib/src/Math/Raw/ClpNat320.pas
  57. 1 1
      CryptoLib/src/Math/Raw/ClpNat384.pas
  58. 1 1
      CryptoLib/src/Math/Raw/ClpNat448.pas
  59. 28 28
      CryptoLib/src/Misc/ClpBitOperations.pas
  60. 7 7
      CryptoLib/src/Misc/ClpConverters.pas
  61. 2 3
      CryptoLib/src/Rngs/ClpDigestRandomGenerator.pas
  62. 9 9
      CryptoLib/src/X509/ClpX509Generators.pas
  63. 2 2
      CryptoLib/src/X509/ClpX509Utilities.pas

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

@@ -515,7 +515,7 @@ uses
   ClpX509DsaAsn1Objects in '..\..\CryptoLib\src\Asn1\X509\ClpX509DsaAsn1Objects.pas',
   ClpX509RsaAsn1Objects in '..\..\CryptoLib\src\Asn1\X509\ClpX509RsaAsn1Objects.pas',
   ClpBinaryPrimitives in '..\..\CryptoLib\src\Misc\ClpBinaryPrimitives.pas',
-  ClpBitUtilities in '..\..\CryptoLib\src\Misc\ClpBitUtilities.pas',
+  ClpBitOperations in '..\..\CryptoLib\src\Misc\ClpBitOperations.pas',
   ClpPack in '..\..\CryptoLib\src\Misc\ClpPack.pas',
   ClpBits in '..\..\CryptoLib\src\Math\Raw\ClpBits.pas',
   ClpMod in '..\..\CryptoLib\src\Math\Raw\ClpMod.pas',

+ 2 - 2
CryptoLib.Tests/src/Asn1/TagTests.pas

@@ -37,7 +37,7 @@ uses
   ClpAsn1Tags,
   ClpSecureRandom,
   ClpISecureRandom,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpEncoders,
   ClpCryptoLibTypes,
   CryptoLibTestBase;
@@ -158,7 +158,7 @@ begin
   LSR := TSecureRandom.Create();
   for I := 0 to 99 do
   begin
-    LTestTag := TBitUtilities.Asr32(LSR.NextInt32() and System.High(Int32), LSR.Next(26));
+    LTestTag := TBitOperations.Asr32(LSR.NextInt32() and System.High(Int32), LSR.Next(26));
     LApp := TDerTaggedObject.Create(False, TAsn1Tags.Application, LTestTag, TDerOctetString.Create(TCryptoLibByteArray.Create(1)) as IDerOctetString);
     LApp := TAsn1TaggedObject.GetInstance(TAsn1Object.FromByteArray(LApp.GetEncoded())) as IAsn1TaggedObject;
 

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

@@ -35,7 +35,7 @@ uses
   ClpISecureRandom,
   ClpIX9ECAsn1Objects,
   ClpSecObjectIdentifiers,
-  ClpConverters,
+  ClpPack,
   ClpCustomNamedCurves,
   ClpIECC,
   ClpBigInteger,
@@ -173,7 +173,7 @@ begin
     x_i := x[i];
     if (x_i <> 0) then
     begin
-      temp := TConverters.ReadUInt32AsBytesBE(x_i);
+      temp := TPack.UInt32_To_BE(x_i);
       System.Move(temp[0], bs[(7 - i) shl 2], System.Length(temp) *
         SizeOf(Byte));
 

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

@@ -35,7 +35,7 @@ uses
   ClpISecureRandom,
   ClpIX9ECAsn1Objects,
   ClpSecObjectIdentifiers,
-  ClpConverters,
+  ClpPack,
   ClpCustomNamedCurves,
   ClpIECC,
   ClpBigInteger,
@@ -129,7 +129,7 @@ begin
     x_i := x[i];
     if (x_i <> 0) then
     begin
-      temp := TConverters.ReadUInt32AsBytesBE(x_i);
+      temp := TPack.UInt32_To_BE(x_i);
       System.Move(temp[0], bs[(len - 1 - i) shl 2], System.Length(temp) *
         SizeOf(Byte));
 

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

@@ -33,7 +33,7 @@ uses
   TestFramework,
 {$ENDIF FPC}
   Generics.Collections,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCustomNamedCurves,
   ClpECNamedCurveTable,
   ClpCryptoLibTypes,
@@ -336,7 +336,7 @@ begin
   ImplTestMultiply(q, n.BitLength);
   ImplTestMultiply(infinity, n.BitLength);
 
-  logSize := 32 - TBitUtilities.NumberOfLeadingZeros32(curve.FieldSize - 1);
+  logSize := 32 - TBitOperations.NumberOfLeadingZeros32(curve.FieldSize - 1);
   rounds := Max(2, Min(10, 32 - 3 * logSize));
 
   p := q;

+ 5 - 5
CryptoLib.Tests/src/Utils/ClpFixedSecureRandom.pas

@@ -28,7 +28,7 @@ uses
   SysUtils,
   ClpEncoders,
   ClpCryptoLibTypes,
-  ClpConverters,
+  ClpPack,
   ClpBigInteger,
   ClpIFixedSecureRandom,
   ClpISecureRandom,
@@ -329,8 +329,8 @@ begin
     begin
       if (bitLength mod 8 <> 0) then
       begin
-        i := TConverters.ReadBytesAsUInt32BE(PByte(tmp), 0);
-        tmp := TConverters.ReadUInt32AsBytesBE(i shl (8 - (bitLength mod 8)));
+        i := TPack.BE_To_UInt32(tmp, 0);
+        TPack.UInt32_To_BE(i shl (8 - (bitLength mod 8)), tmp, 0);
 
       end;
     end;
@@ -344,8 +344,8 @@ begin
     begin
       if (bitLength mod 8 <> 0) then
       begin
-        i := TConverters.ReadBytesAsUInt32BE(PByte(lv), 0);
-        lv := TConverters.ReadUInt32AsBytesBE(i shl (8 - (bitLength mod 8)));
+        i := TPack.BE_To_UInt32(lv, 0);
+        lv := TPack.UInt32_To_BE(i shl (8 - (bitLength mod 8)));
 
       end;
     end;

+ 3 - 3
CryptoLib/src/Asn1/ClpAsn1Core.pas

@@ -30,6 +30,8 @@ uses
   ClpIAsn1Core,
   ClpIAsn1Objects,
   ClpIAsn1Encodings,
+  ClpBitOperations,
+  ClpAsn1Tags,
   ClpAsn1Streams;
 
 type
@@ -287,8 +289,6 @@ type
 implementation
 
 uses
-  ClpBitUtilities,
-  ClpAsn1Tags,
   ClpAsn1Objects; // For TDerTaggedObject in AddOptionalTagged
 
 { TAsn1Encodable }
@@ -580,7 +580,7 @@ var
   LCopy: TCryptoLibGenericArray<IAsn1Encodable>;
 begin
   LOldCapacity := System.Length(FElements);
-  LNewCapacity := Math.Max(LOldCapacity, AMinCapacity + (TBitUtilities.Asr32(AMinCapacity, 1)));
+  LNewCapacity := Math.Max(LOldCapacity, AMinCapacity + (TBitOperations.Asr32(AMinCapacity, 1)));
 
   System.SetLength(LCopy, LNewCapacity);
   for I := 0 to FElementCount - 1 do

+ 6 - 8
CryptoLib/src/Asn1/ClpAsn1Generators.pas

@@ -28,7 +28,9 @@ uses
   ClpIAsn1Core,
   ClpAsn1Tags,
   ClpAsn1Core,
-  ClpAsn1Streams;
+  ClpAsn1Streams,
+  ClpBitOperations,
+  ClpStreamUtilities;
 
 type
   /// <summary>
@@ -136,10 +138,6 @@ type
 
 implementation
 
-uses
-  ClpBitUtilities,
-  ClpStreamUtilities;
-
 { TAsn1Generator }
 
 constructor TAsn1Generator.Create(AOutStream: TStream);
@@ -369,17 +367,17 @@ begin
   begin
     LSize := 1;
     LVal := ALength;
-    LVal := TBitUtilities.Asr32(LVal, 8);
+    LVal := TBitOperations.Asr32(LVal, 8);
     while LVal <> 0 do
     begin
       System.Inc(LSize);
-      LVal := TBitUtilities.Asr32(LVal, 8);
+      LVal := TBitOperations.Asr32(LVal, 8);
     end;
     AOutStr.WriteByte(Byte(LSize or $80));
     I := (LSize - 1) * 8;
     while I >= 0 do
     begin
-      AOutStr.WriteByte(Byte(TBitUtilities.Asr32(ALength, I)));
+      AOutStr.WriteByte(Byte(TBitOperations.Asr32(ALength, I)));
       System.Dec(I, 8);
     end;
   end

+ 24 - 24
CryptoLib/src/Asn1/ClpAsn1Objects.pas

@@ -26,7 +26,7 @@ uses
   SysUtils,
   Math,
   DateUtils,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes,
   ClpBigInteger,
   ClpBigIntegers,
@@ -1998,7 +1998,7 @@ type
     constructor Create(const AContents: TCryptoLibByteArray); overload;
     constructor Create(const ATimeString: String); overload;
     constructor Create(const ADateTime: TDateTime); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime); overload;
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime); overload;
     class function GetInstance(const AObj: TObject): IAsn1GeneralizedTime; overload; static;
     class function GetInstance(const AObj: IAsn1Object): IAsn1GeneralizedTime; overload; static;
     class function GetInstance(const AObj: IAsn1Convertible): IAsn1GeneralizedTime; overload; static;
@@ -2054,8 +2054,8 @@ type
     constructor Create(const ATimeString: String); overload;
     constructor Create(const ADateTime: TDateTime); overload; deprecated 'Use Create(DateTime, Int32) instead';
     constructor Create(const ADateTime: TDateTime; ATwoDigitYearMax: Int32); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32); overload;
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime); overload;
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32); overload;
     class function GetInstance(const AObj: TObject): IAsn1UtcTime; overload; static;
     class function GetInstance(const AObj: IAsn1Object): IAsn1UtcTime; overload; static;
     /// <summary>
@@ -2090,8 +2090,8 @@ type
     constructor Create(const ADateTime: TDateTime); overload; deprecated 'Use Create(DateTime, Int32) instead';
     constructor Create(const ADateTime: TDateTime; ATwoDigitYearMax: Int32); overload;
     constructor Create(const AContents: TCryptoLibByteArray); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32); overload;
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime); overload;
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32); overload;
 
     function GetEncoding(AEncoding: Int32): IAsn1Encoding; override;
     function GetEncodingImplicit(AEncoding, ATagClass, ATagNo: Int32): IAsn1Encoding; override;
@@ -2105,7 +2105,7 @@ type
     constructor Create(const ATimeString: String); overload;
     constructor Create(const ADateTime: TDateTime); overload;
     constructor Create(const AContents: TCryptoLibByteArray); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime); overload;
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime); overload;
 
     function GetEncoding(AEncoding: Int32): IAsn1Encoding; override;
     function GetEncodingImplicit(AEncoding, ATagClass, ATagNo: Int32): IAsn1Encoding; override;
@@ -6594,13 +6594,13 @@ begin
     FContents[0] := 0;
     Exit;
   end;
-  LBits := 32 - TBitUtilities.NumberOfLeadingZeros32(UInt32(ANamedBits));
+  LBits := 32 - TBitOperations.NumberOfLeadingZeros32(UInt32(ANamedBits));
   LBytes := (LBits + 7) div 8;
   System.SetLength(LData, 1 + LBytes);
   for I := 1 to LBytes - 1 do
   begin
     LData[I] := Byte(ANamedBits);
-    ANamedBits := TBitUtilities.Asr32(ANamedBits, 8);
+    ANamedBits := TBitOperations.Asr32(ANamedBits, 8);
   end;
   LData[LBytes] := Byte(ANamedBits);
   LPadBits := 0;
@@ -7328,7 +7328,7 @@ begin
   LByteLen := System.Length(AStr);
   if (LByteLen and 1) <> 0 then
     raise EArgumentCryptoLibException.Create('malformed BMPString encoding encountered');
-  LCharLen := TBitUtilities.Asr32(LByteLen, 1);
+  LCharLen := TBitOperations.Asr32(LByteLen, 1);
   System.SetLength(LCs, LCharLen);
   for I := 0 to LCharLen - 1 do
     LCs[I] := Char((AStr[2 * I] shl 8) or (AStr[2 * I + 1] and $FF));
@@ -9260,10 +9260,10 @@ end;
 
 constructor TAsn1GeneralizedTime.Create(const ADateTime: TDateTime);
 begin
-  CreateUtc(TTimeZone.Local.ToUniversalTime(ADateTime));
+  CreateFromUtc(TTimeZone.Local.ToUniversalTime(ADateTime));
 end;
 
-constructor TAsn1GeneralizedTime.CreateUtc(const AUtcDateTime: TDateTime);
+constructor TAsn1GeneralizedTime.CreateFromUtc(const AUtcDateTime: TDateTime);
 begin
   inherited Create();
   FDateTime := TDateTimeUtilities.WithPrecisionSecond(AUtcDateTime);
@@ -9608,15 +9608,15 @@ end;
 
 constructor TAsn1UtcTime.Create(const ADateTime: TDateTime);
 begin
-  CreateUtc(TTimeZone.Local.ToUniversalTime(ADateTime));
+  CreateFromUtc(TTimeZone.Local.ToUniversalTime(ADateTime));
 end;
 
 constructor TAsn1UtcTime.Create(const ADateTime: TDateTime; ATwoDigitYearMax: Int32);
 begin
-  CreateUtc(TTimeZone.Local.ToUniversalTime(ADateTime), ATwoDigitYearMax);
+  CreateFromUtc(TTimeZone.Local.ToUniversalTime(ADateTime), ATwoDigitYearMax);
 end;
 
-constructor TAsn1UtcTime.CreateUtc(const AUtcDateTime: TDateTime);
+constructor TAsn1UtcTime.CreateFromUtc(const AUtcDateTime: TDateTime);
 const
   DefaultTwoDigitYearMax = 2049;
 var
@@ -9632,7 +9632,7 @@ begin
   FTwoDigitYearMax := DefaultTwoDigitYearMax;
 end;
 
-constructor TAsn1UtcTime.CreateUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32);
+constructor TAsn1UtcTime.CreateFromUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32);
 var
   LUtc: TDateTime;
 begin
@@ -9849,14 +9849,14 @@ begin
   inherited Create(AContents);
 end;
 
-constructor TDerUtcTime.CreateUtc(const AUtcDateTime: TDateTime);
+constructor TDerUtcTime.CreateFromUtc(const AUtcDateTime: TDateTime);
 begin
-  inherited CreateUtc(AUtcDateTime);
+  inherited CreateFromUtc(AUtcDateTime);
 end;
 
-constructor TDerUtcTime.CreateUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32);
+constructor TDerUtcTime.CreateFromUtc(const AUtcDateTime: TDateTime; ATwoDigitYearMax: Int32);
 begin
-  inherited CreateUtc(AUtcDateTime, ATwoDigitYearMax);
+  inherited CreateFromUtc(AUtcDateTime, ATwoDigitYearMax);
 end;
 
 function TDerUtcTime.GetEncoding(AEncoding: Int32): IAsn1Encoding;
@@ -9887,9 +9887,9 @@ begin
   inherited Create(AContents);
 end;
 
-constructor TDerGeneralizedTime.CreateUtc(const AUtcDateTime: TDateTime);
+constructor TDerGeneralizedTime.CreateFromUtc(const AUtcDateTime: TDateTime);
 begin
-  inherited CreateUtc(AUtcDateTime);
+  inherited CreateFromUtc(AUtcDateTime);
 end;
 
 function TDerGeneralizedTime.GetEncoding(AEncoding: Int32): IAsn1Encoding;
@@ -12135,7 +12135,7 @@ begin
     1:
       Result := False;
   else
-    Result := (ShortInt(ABytes[0]) = TBitUtilities.Asr32(ShortInt(ABytes[1]), 7)) and (not AllowUnsafe());
+    Result := (ShortInt(ABytes[0]) = TBitOperations.Asr32(ShortInt(ABytes[1]), 7)) and (not AllowUnsafe());
   end;
 end;
 
@@ -12145,7 +12145,7 @@ var
 begin
   LPos := 0;
   LLast := System.Length(ABytes) - 1;
-  while (LPos < LLast) and (ShortInt(ABytes[LPos]) = TBitUtilities.Asr32(ShortInt(ABytes[LPos + 1]), 7)) do
+  while (LPos < LLast) and (ShortInt(ABytes[LPos]) = TBitOperations.Asr32(ShortInt(ABytes[LPos + 1]), 7)) do
   begin
     System.Inc(LPos);
   end;

+ 7 - 7
CryptoLib/src/Asn1/ClpAsn1Streams.pas

@@ -31,7 +31,7 @@ uses
   ClpIAsn1Parsers,
   ClpAsn1Encodings,
   ClpAsn1Tags,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpPlatformUtilities,
   ClpCryptoLibTypes,
   ClpStreams,
@@ -846,7 +846,7 @@ begin
   repeat
     System.Dec(LPos);
     LStack[LPos] := Byte(ADl);
-    ADl := TBitUtilities.Asr32(ADl, 8);
+    ADl := TBitOperations.Asr32(ADl, 8);
   until ADl = 0;
 
   LCount := System.Length(LStack) - LPos;
@@ -874,7 +874,7 @@ begin
   LStack[LPos] := Byte(ATagNo and $7F);
   while ATagNo > 127 do
   begin
-    ATagNo := TBitUtilities.Asr32(ATagNo, 7);
+    ATagNo := TBitOperations.Asr32(ATagNo, 7);
     System.Dec(LPos);
     LStack[LPos] := Byte((ATagNo and $7F) or $80);
   end;
@@ -904,9 +904,9 @@ begin
   end;
 
   Result := 2;
-  while TBitUtilities.Asr32(ADl, 8) > 0 do
+  while TBitOperations.Asr32(ADl, 8) > 0 do
   begin
-    ADl := TBitUtilities.Asr32(ADl, 8);
+    ADl := TBitOperations.Asr32(ADl, 8);
     System.Inc(Result);
   end;
 end;
@@ -920,9 +920,9 @@ begin
   end;
 
   Result := 2;
-  while TBitUtilities.Asr32(ATagNo, 7) > 0 do
+  while TBitOperations.Asr32(ATagNo, 7) > 0 do
   begin
-    ATagNo := TBitUtilities.Asr32(ATagNo, 7);
+    ATagNo := TBitOperations.Asr32(ATagNo, 7);
     System.Inc(Result);
   end;
 end;

+ 2 - 2
CryptoLib/src/Asn1/X509/ClpRfc5280Asn1Utilities.pas

@@ -61,7 +61,7 @@ end;
 
 class function TRfc5280Asn1Utilities.CreateGeneralizedTimeFromUtc(const AUtcDateTime: TDateTime): IAsn1GeneralizedTime;
 begin
-  Result := TDerGeneralizedTime.CreateUtc(TDateTimeUtilities.WithPrecisionSecond(AUtcDateTime));
+  Result := TDerGeneralizedTime.CreateFromUtc(TDateTimeUtilities.WithPrecisionSecond(AUtcDateTime));
 end;
 
 class function TRfc5280Asn1Utilities.CreateUtcTime(const ADateTime: TDateTime): IAsn1UtcTime;
@@ -71,7 +71,7 @@ end;
 
 class function TRfc5280Asn1Utilities.CreateUtcTimeFromUtc(const AUtcDateTime: TDateTime): IAsn1UtcTime;
 begin
-  Result := TDerUtcTime.CreateUtc(AUtcDateTime, 2049);
+  Result := TDerUtcTime.CreateFromUtc(AUtcDateTime, 2049);
 end;
 
 end.

+ 3 - 3
CryptoLib/src/Asn1/X509/ClpX509Asn1Objects.pas

@@ -949,7 +949,7 @@ type
     constructor Create(const AGeneralizedTime: IAsn1GeneralizedTime); overload;
     constructor Create(const AUtcTime: IAsn1UtcTime); overload;
     constructor Create(const ADateTime: TDateTime); overload;
-    constructor CreateUtc(const AUtcDateTime: TDateTime);
+    constructor CreateFromUtc(const AUtcDateTime: TDateTime);
 
     function ToDateTime: TDateTime;
     function ToAsn1Object: IAsn1Object; override;
@@ -2730,10 +2730,10 @@ end;
 
 constructor TTime.Create(const ADateTime: TDateTime);
 begin
-  CreateUtc(TTimeZone.Local.ToUniversalTime(ADateTime));
+  CreateFromUtc(TTimeZone.Local.ToUniversalTime(ADateTime));
 end;
 
-constructor TTime.CreateUtc(const AUtcDateTime: TDateTime);
+constructor TTime.CreateFromUtc(const AUtcDateTime: TDateTime);
 var
   LYear, LMonth, LDay, LHour, LMinute, LSecond, LMillisecond: Word;
 begin

+ 5 - 5
CryptoLib/src/Crypto/Encodings/ClpOaepEncoding.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   SysUtils,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpICipherParameters,
   ClpIParametersWithRandom,
   ClpIDigest,
@@ -235,12 +235,12 @@ begin
   defHashLen := System.Length(FDefHash);
 
   // Check reduced block size is valid
-  wrongMask := TBitUtilities.Asr32(GetReducedBlockSize(outBlockSize), 31);
+  wrongMask := TBitOperations.Asr32(GetReducedBlockSize(outBlockSize), 31);
 
   SetLength(block, outBlockSize);
   data := FEngine.ProcessBlock(inBytes, inOff, inLen);
 
-  wrongMask := wrongMask or TBitUtilities.Asr32((System.Length(block) - System.Length(data)), 31);
+  wrongMask := wrongMask or TBitOperations.Asr32((System.Length(block) - System.Length(data)), 31);
 
   copyLen := System.Length(data);
   if copyLen > System.Length(block) then
@@ -271,11 +271,11 @@ begin
   begin
     octet := block[index];
     // Mask will be 0xFFFFFFFF if octet is non-zero and start is (still) negative
-    shouldSetMask := TBitUtilities.Asr32((-octet) and start, 31);
+    shouldSetMask := TBitOperations.Asr32((-octet) and start, 31);
     start := start + (index and shouldSetMask);
   end;
 
-  wrongMask := wrongMask or TBitUtilities.Asr32(start, 31);
+  wrongMask := wrongMask or TBitOperations.Asr32(start, 31);
   Inc(start);
   wrongMask := wrongMask or (block[start] xor 1);
 

+ 7 - 7
CryptoLib/src/Crypto/Encodings/ClpPkcs1Encoding.pas

@@ -24,7 +24,7 @@ interface
 uses
   SysUtils,
   Math,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpICipherParameters,
   ClpIAsymmetricKeyParameter,
   ClpIAsymmetricBlockCipher,
@@ -277,8 +277,8 @@ begin
   for i := 1 to System.Length(buf) - 1 do
   begin
     padByte := buf[i];
-    is0x00Mask := TBitUtilities.Asr32((padByte xor $00) - 1, 31);
-    is0xFFMask := TBitUtilities.Asr32((padByte xor $FF) - 1, 31);
+    is0x00Mask := TBitOperations.Asr32((padByte xor $00) - 1, 31);
+    is0xFFMask := TBitOperations.Asr32((padByte xor $FF) - 1, 31);
     lastPadPos := lastPadPos xor (i and (not foundZeroMask) and is0x00Mask);
     foundZeroMask := foundZeroMask or is0x00Mask;
     badPadSign := badPadSign or (not (foundZeroMask or is0xFFMask));
@@ -288,7 +288,7 @@ begin
   badPadSign := badPadSign or (lastPadPos - 9);
 
   plaintextLength := System.Length(buf) - 1 - lastPadPos;
-  Result := plaintextLength or TBitUtilities.Asr32(badPadSign, 31);
+  Result := plaintextLength or TBitOperations.Asr32(badPadSign, 31);
 end;
 
 class function TPkcs1Encoding.CheckPkcs1Encoding2(
@@ -308,7 +308,7 @@ begin
   for i := 1 to System.Length(buf) - 1 do
   begin
     padByte := buf[i];
-    is0x00Mask := TBitUtilities.Asr32((padByte xor $00) - 1, 31);
+    is0x00Mask := TBitOperations.Asr32((padByte xor $00) - 1, 31);
     lastPadPos := lastPadPos xor (i and (not foundZeroMask) and is0x00Mask);
     foundZeroMask := foundZeroMask or is0x00Mask;
   end;
@@ -317,7 +317,7 @@ begin
   badPadSign := badPadSign or (lastPadPos - 9);
 
   plaintextLength := System.Length(buf) - 1 - lastPadPos;
-  Result := plaintextLength or TBitUtilities.Asr32(badPadSign, 31);
+  Result := plaintextLength or TBitOperations.Asr32(badPadSign, 31);
 end;
 
 class function TPkcs1Encoding.CheckPkcs1Encoding2(
@@ -341,7 +341,7 @@ begin
   // Last pad byte should be zero
   badPadSign := badPadSign or (-buf[lastPadPos]);
 
-  Result := TBitUtilities.Asr32(badPadSign, 31);
+  Result := TBitOperations.Asr32(badPadSign, 31);
 end;
 
 function TPkcs1Encoding.DecodeBlockOrRandom(const input: TCryptoLibByteArray;

+ 29 - 29
CryptoLib/src/Crypto/Engines/ClpAesEngine.pas

@@ -28,8 +28,8 @@ uses
   ClpICipherParameters,
   ClpIKeyParameter,
   ClpCheck,
-  ClpBitUtilities,
-  ClpConverters,
+  ClpBitOperations,
+  ClpPack,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -296,7 +296,7 @@ implementation
 
 class function TAesEngine.Shift(r: UInt32; Shift: Int32): UInt32;
 begin
-  result := TBitUtilities.RotateRight32(r, Shift);
+  result := TBitOperations.RotateRight32(r, Shift);
 end;
 
 class function TAesEngine.SubWord(x: UInt32): UInt32;
@@ -517,13 +517,13 @@ begin
   case KC of
     4:
       begin
-        lt0 := TConverters.ReadBytesAsUInt32LE(PByte(key), 0);
+        lt0 := TPack.LE_To_UInt32(key, 0);
         bigW[0][0] := lt0;
-        t1 := TConverters.ReadBytesAsUInt32LE(PByte(key), 4);
+        t1 := TPack.LE_To_UInt32(key, 4);
         bigW[0][1] := t1;
-        t2 := TConverters.ReadBytesAsUInt32LE(PByte(key), 8);
+        t2 := TPack.LE_To_UInt32(key, 8);
         bigW[0][2] := t2;
-        t3 := TConverters.ReadBytesAsUInt32LE(PByte(key), 12);
+        t3 := TPack.LE_To_UInt32(key, 12);
         bigW[0][3] := t3;
 
         for i := 1 to 10 do
@@ -542,17 +542,17 @@ begin
 
     6:
       begin
-        lt0 := TConverters.ReadBytesAsUInt32LE(PByte(key), 0);
+        lt0 := TPack.LE_To_UInt32(key, 0);
         bigW[0][0] := lt0;
-        t1 := TConverters.ReadBytesAsUInt32LE(PByte(key), 4);
+        t1 := TPack.LE_To_UInt32(key, 4);
         bigW[0][1] := t1;
-        t2 := TConverters.ReadBytesAsUInt32LE(PByte(key), 8);
+        t2 := TPack.LE_To_UInt32(key, 8);
         bigW[0][2] := t2;
-        t3 := TConverters.ReadBytesAsUInt32LE(PByte(key), 12);
+        t3 := TPack.LE_To_UInt32(key, 12);
         bigW[0][3] := t3;
-        t4 := TConverters.ReadBytesAsUInt32LE(PByte(key), 16);
+        t4 := TPack.LE_To_UInt32(key, 16);
         bigW[1][0] := t4;
-        t5 := TConverters.ReadBytesAsUInt32LE(PByte(key), 20);
+        t5 := TPack.LE_To_UInt32(key, 20);
         bigW[1][1] := t5;
 
         lrcon := 1;
@@ -620,21 +620,21 @@ begin
 
     8:
       begin
-        lt0 := TConverters.ReadBytesAsUInt32LE(PByte(key), 0);
+        lt0 := TPack.LE_To_UInt32(key, 0);
         bigW[0][0] := lt0;
-        t1 := TConverters.ReadBytesAsUInt32LE(PByte(key), 4);
+        t1 := TPack.LE_To_UInt32(key, 4);
         bigW[0][1] := t1;
-        t2 := TConverters.ReadBytesAsUInt32LE(PByte(key), 8);
+        t2 := TPack.LE_To_UInt32(key, 8);
         bigW[0][2] := t2;
-        t3 := TConverters.ReadBytesAsUInt32LE(PByte(key), 12);
+        t3 := TPack.LE_To_UInt32(key, 12);
         bigW[0][3] := t3;
-        t4 := TConverters.ReadBytesAsUInt32LE(PByte(key), 16);
+        t4 := TPack.LE_To_UInt32(key, 16);
         bigW[1][0] := t4;
-        t5 := TConverters.ReadBytesAsUInt32LE(PByte(key), 20);
+        t5 := TPack.LE_To_UInt32(key, 20);
         bigW[1][1] := t5;
-        t6 := TConverters.ReadBytesAsUInt32LE(PByte(key), 24);
+        t6 := TPack.LE_To_UInt32(key, 24);
         bigW[1][2] := t6;
-        t7 := TConverters.ReadBytesAsUInt32LE(PByte(key), 28);
+        t7 := TPack.LE_To_UInt32(key, 28);
         bigW[1][3] := t7;
 
         lrcon := 1;
@@ -747,18 +747,18 @@ end;
 
 procedure TAesEngine.PackBlock(const bytes: TCryptoLibByteArray; off: Int32);
 begin
-  TConverters.ReadUInt32AsBytesLE(FC0, bytes, off);
-  TConverters.ReadUInt32AsBytesLE(FC1, bytes, off + 4);
-  TConverters.ReadUInt32AsBytesLE(FC2, bytes, off + 8);
-  TConverters.ReadUInt32AsBytesLE(FC3, bytes, off + 12);
+  TPack.UInt32_To_LE(FC0, bytes, off);
+  TPack.UInt32_To_LE(FC1, bytes, off + 4);
+  TPack.UInt32_To_LE(FC2, bytes, off + 8);
+  TPack.UInt32_To_LE(FC3, bytes, off + 12);
 end;
 
 procedure TAesEngine.UnPackBlock(const bytes: TCryptoLibByteArray; off: Int32);
 begin
-  FC0 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off);
-  FC1 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off + 4);
-  FC2 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off + 8);
-  FC3 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off + 12);
+  FC0 := TPack.LE_To_UInt32(bytes, off);
+  FC1 := TPack.LE_To_UInt32(bytes, off + 4);
+  FC2 := TPack.LE_To_UInt32(bytes, off + 8);
+  FC3 := TPack.LE_To_UInt32(bytes, off + 12);
 end;
 
 function TAesEngine.ProcessBlock(const input: TCryptoLibByteArray; inOff: Int32;

+ 29 - 29
CryptoLib/src/Crypto/Engines/ClpAesLightEngine.pas

@@ -28,8 +28,8 @@ uses
   ClpICipherParameters,
   ClpIKeyParameter,
   ClpCheck,
-  ClpBitUtilities,
-  ClpConverters,
+  ClpBitOperations,
+  ClpPack,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -205,7 +205,7 @@ implementation
 
 class function TAesLightEngine.Shift(r: UInt32; Shift: Int32): UInt32;
 begin
-  result := TBitUtilities.RotateRight32(r, Shift);
+  result := TBitOperations.RotateRight32(r, Shift);
 end;
 
 class function TAesLightEngine.SubWord(x: UInt32): UInt32;
@@ -443,13 +443,13 @@ begin
   case KC of
     4:
       begin
-        t0 := TConverters.ReadBytesAsUInt32LE(PByte(key), 0);
+        t0 := TPack.LE_To_UInt32(key, 0);
         bigW[0][0] := t0;
-        t1 := TConverters.ReadBytesAsUInt32LE(PByte(key), 4);
+        t1 := TPack.LE_To_UInt32(key, 4);
         bigW[0][1] := t1;
-        t2 := TConverters.ReadBytesAsUInt32LE(PByte(key), 8);
+        t2 := TPack.LE_To_UInt32(key, 8);
         bigW[0][2] := t2;
-        t3 := TConverters.ReadBytesAsUInt32LE(PByte(key), 12);
+        t3 := TPack.LE_To_UInt32(key, 12);
         bigW[0][3] := t3;
 
         for i := 1 to 10 do
@@ -468,17 +468,17 @@ begin
 
     6:
       begin
-        t0 := TConverters.ReadBytesAsUInt32LE(PByte(key), 0);
+        t0 := TPack.LE_To_UInt32(key, 0);
         bigW[0][0] := t0;
-        t1 := TConverters.ReadBytesAsUInt32LE(PByte(key), 4);
+        t1 := TPack.LE_To_UInt32(key, 4);
         bigW[0][1] := t1;
-        t2 := TConverters.ReadBytesAsUInt32LE(PByte(key), 8);
+        t2 := TPack.LE_To_UInt32(key, 8);
         bigW[0][2] := t2;
-        t3 := TConverters.ReadBytesAsUInt32LE(PByte(key), 12);
+        t3 := TPack.LE_To_UInt32(key, 12);
         bigW[0][3] := t3;
-        t4 := TConverters.ReadBytesAsUInt32LE(PByte(key), 16);
+        t4 := TPack.LE_To_UInt32(key, 16);
         bigW[1][0] := t4;
-        t5 := TConverters.ReadBytesAsUInt32LE(PByte(key), 20);
+        t5 := TPack.LE_To_UInt32(key, 20);
         bigW[1][1] := t5;
 
         lrcon := 1;
@@ -546,21 +546,21 @@ begin
 
     8:
       begin
-        t0 := TConverters.ReadBytesAsUInt32LE(PByte(key), 0);
+        t0 := TPack.LE_To_UInt32(key, 0);
         bigW[0][0] := t0;
-        t1 := TConverters.ReadBytesAsUInt32LE(PByte(key), 4);
+        t1 := TPack.LE_To_UInt32(key, 4);
         bigW[0][1] := t1;
-        t2 := TConverters.ReadBytesAsUInt32LE(PByte(key), 8);
+        t2 := TPack.LE_To_UInt32(key, 8);
         bigW[0][2] := t2;
-        t3 := TConverters.ReadBytesAsUInt32LE(PByte(key), 12);
+        t3 := TPack.LE_To_UInt32(key, 12);
         bigW[0][3] := t3;
-        t4 := TConverters.ReadBytesAsUInt32LE(PByte(key), 16);
+        t4 := TPack.LE_To_UInt32(key, 16);
         bigW[1][0] := t4;
-        t5 := TConverters.ReadBytesAsUInt32LE(PByte(key), 20);
+        t5 := TPack.LE_To_UInt32(key, 20);
         bigW[1][1] := t5;
-        t6 := TConverters.ReadBytesAsUInt32LE(PByte(key), 24);
+        t6 := TPack.LE_To_UInt32(key, 24);
         bigW[1][2] := t6;
-        t7 := TConverters.ReadBytesAsUInt32LE(PByte(key), 28);
+        t7 := TPack.LE_To_UInt32(key, 28);
         bigW[1][3] := t7;
 
         lrcon := 1;
@@ -663,19 +663,19 @@ end;
 procedure TAesLightEngine.PackBlock(const bytes: TCryptoLibByteArray;
   off: Int32);
 begin
-  TConverters.ReadUInt32AsBytesLE(FC0, bytes, off);
-  TConverters.ReadUInt32AsBytesLE(FC1, bytes, off + 4);
-  TConverters.ReadUInt32AsBytesLE(FC2, bytes, off + 8);
-  TConverters.ReadUInt32AsBytesLE(FC3, bytes, off + 12);
+  TPack.UInt32_To_LE(FC0, bytes, off);
+  TPack.UInt32_To_LE(FC1, bytes, off + 4);
+  TPack.UInt32_To_LE(FC2, bytes, off + 8);
+  TPack.UInt32_To_LE(FC3, bytes, off + 12);
 end;
 
 procedure TAesLightEngine.UnPackBlock(const bytes: TCryptoLibByteArray;
   off: Int32);
 begin
-  FC0 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off);
-  FC1 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off + 4);
-  FC2 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off + 8);
-  FC3 := TConverters.ReadBytesAsUInt32LE(PByte(bytes), off + 12);
+  FC0 := TPack.LE_To_UInt32(bytes, off);
+  FC1 := TPack.LE_To_UInt32(bytes, off + 4);
+  FC2 := TPack.LE_To_UInt32(bytes, off + 8);
+  FC3 := TPack.LE_To_UInt32(bytes, off + 12);
 end;
 
 function TAesLightEngine.ProcessBlock(const input: TCryptoLibByteArray;

+ 9 - 9
CryptoLib/src/Crypto/Engines/ClpBlowfishEngine.pas

@@ -28,7 +28,7 @@ uses
   ClpICipherParameters,
   ClpIBlowfishEngine,
   ClpCheck,
-  ClpConverters,
+  ClpPack,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -422,8 +422,8 @@ var
   xl, xr: UInt32;
   i: Int32;
 begin
-  xl := TConverters.ReadBytesAsUInt32BE(PByte(src), srcIndex);
-  xr := TConverters.ReadBytesAsUInt32BE(PByte(src), srcIndex + 4);
+  xl := TPack.BE_To_UInt32(src, srcIndex);
+  xr := TPack.BE_To_UInt32(src, srcIndex + 4);
 
   xl := xl xor FP[0];
 
@@ -438,8 +438,8 @@ begin
 
   xr := xr xor FP[ROUNDS + 1];
 
-  TConverters.ReadUInt32AsBytesBE(xr, dst, dstIndex);
-  TConverters.ReadUInt32AsBytesBE(xl, dst, dstIndex + 4);
+  TPack.UInt32_To_BE(xr, dst, dstIndex);
+  TPack.UInt32_To_BE(xl, dst, dstIndex + 4);
 end;
 
 procedure TBlowfishEngine.DecryptBlock(const src: TCryptoLibByteArray;
@@ -448,8 +448,8 @@ var
   xl, xr: UInt32;
   i: Int32;
 begin
-  xl := TConverters.ReadBytesAsUInt32BE(PByte(src), srcIndex);
-  xr := TConverters.ReadBytesAsUInt32BE(PByte(src), srcIndex + 4);
+  xl := TPack.BE_To_UInt32(src, srcIndex);
+  xr := TPack.BE_To_UInt32(src, srcIndex + 4);
 
   xl := xl xor FP[ROUNDS + 1];
 
@@ -464,8 +464,8 @@ begin
 
   xr := xr xor FP[0];
 
-  TConverters.ReadUInt32AsBytesBE(xr, dst, dstIndex);
-  TConverters.ReadUInt32AsBytesBE(xl, dst, dstIndex + 4);
+  TPack.UInt32_To_BE(xr, dst, dstIndex);
+  TPack.UInt32_To_BE(xl, dst, dstIndex + 4);
 end;
 
 function TBlowfishEngine.GetAlgorithmName: String;

+ 5 - 10
CryptoLib/src/Crypto/Engines/ClpChaChaEngine.pas

@@ -26,7 +26,7 @@ uses
   ClpIStreamCipher,
   ClpIChaChaEngine,
   ClpSalsa20Engine,
-  ClpConverters,
+  ClpPack,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -222,8 +222,7 @@ end;
 procedure TChaChaEngine.GenerateKeyStream(const output: TCryptoLibByteArray);
 begin
   ChaChaCore(FRounds, FEngineState, Fx);
-  TConverters.le32_copy(PCardinal(Fx), 0, PByte(output), 0,
-    System.Length(Fx) * System.SizeOf(UInt32));
+  TPack.UInt32_To_LE(Fx, 0, System.Length(Fx), output, 0);
 end;
 
 function TChaChaEngine.GetAlgorithmName: String;
@@ -252,16 +251,12 @@ begin
     PackTauOrSigma(System.Length(keyBytes), FEngineState, 0);
 
     // Key
-    TConverters.le32_copy(PByte(keyBytes), 0, PCardinal(FEngineState),
-      4 * System.SizeOf(UInt32), 4 * System.SizeOf(UInt32));
-    TConverters.le32_copy(PByte(keyBytes), (System.Length(keyBytes) - 16) *
-      System.SizeOf(Byte), PCardinal(FEngineState), 8 * System.SizeOf(UInt32),
-      4 * System.SizeOf(UInt32));
+    TPack.LE_To_UInt32(keyBytes, 0, FEngineState, 4, 4);
+    TPack.LE_To_UInt32(keyBytes, System.Length(keyBytes) - 16, FEngineState, 8, 4);
   end;
 
   // IV
-  TConverters.le32_copy(PByte(ivBytes), 0, PCardinal(FEngineState),
-    14 * System.SizeOf(UInt32), 2 * System.SizeOf(UInt32));
+  TPack.LE_To_UInt32(ivBytes, 0, FEngineState, 14, 2);
 
   TArrayUtilities.Fill<Byte>(keyBytes, 0, System.Length(keyBytes), Byte(0));
   TArrayUtilities.Fill<Byte>(ivBytes, 0, System.Length(ivBytes), Byte(0));

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

@@ -42,7 +42,7 @@ uses
   ClpKdfParameters,
   ClpIKdfParameters,
   ClpIIesWithCipherParameters,
-  ClpConverters,
+  ClpPack,
   ClpArrayUtilities,
   ClpBigInteger,
   ClpBigIntegers,
@@ -211,7 +211,7 @@ begin
   System.SetLength(Result, 8);
   if (AP2 <> nil) then
   begin
-    TConverters.ReadUInt64AsBytesBE(System.Length(AP2) * 8, Result, 0);
+    TPack.UInt64_To_BE(UInt64(System.Length(AP2) * 8), Result, 0);
   end;
 end;
 

+ 7 - 12
CryptoLib/src/Crypto/Engines/ClpSalsa20Engine.pas

@@ -23,14 +23,14 @@ interface
 
 uses
   SysUtils,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCheck,
   ClpIStreamCipher,
   ClpISalsa20Engine,
   ClpIKeyParameter,
   ClpICipherParameters,
   ClpIParametersWithIV,
-  ClpConverters,
+  ClpPack,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -174,8 +174,7 @@ end;
 procedure TSalsa20Engine.GenerateKeyStream(const output: TCryptoLibByteArray);
 begin
   SalsaCore(FRounds, FEngineState, Fx);
-  TConverters.le32_copy(PCardinal(Fx), 0, PByte(output), 0,
-    System.Length(Fx) * System.SizeOf(UInt32));
+  TPack.UInt32_To_LE(Fx, 0, System.Length(Fx), output, 0);
 end;
 
 function TSalsa20Engine.GetAlgorithmName: String;
@@ -329,7 +328,7 @@ end;
 
 class function TSalsa20Engine.R(x: UInt32; y: Int32): UInt32;
 begin
-  result := TBitUtilities.RotateLeft32(x, y);
+  result := TBitOperations.RotateLeft32(x, y);
 end;
 
 procedure TSalsa20Engine.ResetCounter;
@@ -491,16 +490,12 @@ begin
     FEngineState[15] := TAU_SIGMA[tsOff + 3];
 
     // Key
-    TConverters.le32_copy(PByte(keyBytes), 0, PCardinal(FEngineState),
-      1 * System.SizeOf(UInt32), 4 * System.SizeOf(UInt32));
-    TConverters.le32_copy(PByte(keyBytes), (System.Length(keyBytes) - 16) *
-      System.SizeOf(Byte), PCardinal(FEngineState), 11 * System.SizeOf(UInt32),
-      4 * System.SizeOf(UInt32));
+    TPack.LE_To_UInt32(keyBytes, 0, FEngineState, 1, 4);
+    TPack.LE_To_UInt32(keyBytes, System.Length(keyBytes) - 16, FEngineState, 11, 4);
   end;
 
   // IV
-  TConverters.le32_copy(PByte(ivBytes), 0, PCardinal(FEngineState),
-    6 * System.SizeOf(UInt32), 2 * System.SizeOf(UInt32));
+  TPack.LE_To_UInt32(ivBytes, 0, FEngineState, 6, 2);
 
   if (Self.ClassType = TSalsa20Engine) then
   begin

+ 3 - 7
CryptoLib/src/Crypto/Engines/ClpXSalsa20Engine.pas

@@ -25,7 +25,7 @@ uses
   ClpIStreamCipher,
   ClpSalsa20Engine,
   ClpIXSalsa20Engine,
-  ClpConverters,
+  ClpPack,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -90,9 +90,7 @@ begin
   Inherited SetKey(keyBytes, ivBytes);
 
   // Pack next 64 bits of IV into engine state instead of counter
-  TConverters.le32_copy(PByte(ivBytes), 8 * System.SizeOf(Byte),
-    PCardinal(FEngineState), 8 * System.SizeOf(UInt32),
-    2 * System.SizeOf(UInt32));
+  TPack.LE_To_UInt32(ivBytes, 8, FEngineState, 8, 2);
 
   // Process engine state to generate Salsa20 key
   System.SetLength(hsalsa20Out, System.Length(FEngineState));
@@ -110,9 +108,7 @@ begin
   FEngineState[14] := hsalsa20Out[9] - FEngineState[9];
 
   // Last 64 bits of input IV
-  TConverters.le32_copy(PByte(ivBytes), 16 * System.SizeOf(Byte),
-    PCardinal(FEngineState), 6 * System.SizeOf(UInt32),
-    2 * System.SizeOf(UInt32));
+  TPack.LE_To_UInt32(ivBytes, 16, FEngineState, 6, 2);
 
   TArrayUtilities.Fill<Byte>(keyBytes, 0, System.Length(keyBytes), Byte(0));
   TArrayUtilities.Fill<Byte>(ivBytes, 0, System.Length(ivBytes), Byte(0));

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

@@ -29,7 +29,7 @@ uses
   ClpIDerivationFunction,
   ClpIDerivationParameters,
   ClpIBaseKdfBytesGenerator,
-  ClpConverters,
+  ClpPack,
   ClpCryptoLibTypes;
 
 resourcestring
@@ -141,7 +141,7 @@ begin
 
   System.SetLength(C, 4);
 
-  TConverters.ReadUInt32AsBytesBE(UInt32(FcounterStart), C, 0);
+  TPack.UInt32_To_BE(UInt32(FcounterStart), C, 0);
 
   counterBase := UInt32(FcounterStart and (not $FF));
 
@@ -174,7 +174,7 @@ begin
 
     begin
       counterBase := counterBase + $100;
-      TConverters.ReadUInt32AsBytesBE(counterBase, C, 0);
+      TPack.UInt32_To_BE(counterBase, C, 0);
     end;
 
     System.Inc(i);

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

@@ -24,7 +24,7 @@ interface
 uses
 
   ClpISecureRandom,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpBigIntegers,
   ClpECCompUtilities,
@@ -81,7 +81,7 @@ begin
 
   if (limit <> 0) then
   begin
-    minWeight := TBitUtilities.Asr32(limit, 2);
+    minWeight := TBitOperations.Asr32(limit, 2);
 
     while True do
     begin
@@ -108,7 +108,7 @@ begin
   end;
   max := q.Subtract(TBigInteger.Two);
 
-  minWeight := TBitUtilities.Asr32(max.BitLength, 2);
+  minWeight := TBitOperations.Asr32(max.BitLength, 2);
 
   while True do
   begin

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

@@ -26,7 +26,7 @@ uses
   ClpBigInteger,
   ClpBigIntegers,
   ClpECCompUtilities,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -125,7 +125,7 @@ var
 begin
   retryFlag := False;
   qLength := size - 1;
-  minWeight := TBitUtilities.Asr32(size, 2);
+  minWeight := TBitOperations.Asr32(size, 2);
 
   if (size <= 32) then
   begin
@@ -176,7 +176,7 @@ begin
         begin
           prime := LPrimeList[j];
           qRem := test mod prime;
-          if ((qRem = 0) or (qRem = TBitUtilities.Asr32(prime, 1))) then
+          if ((qRem = 0) or (qRem = TBitOperations.Asr32(prime, 1))) then
           begin
             q := q.Add(FSix);
             retryFlag := True;

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

@@ -34,7 +34,7 @@ uses
   ClpIKeyGenerationParameters,
   ClpIDsaKeyGenerationParameters,
   ClpIAsymmetricCipherKeyPairGenerator,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpBigIntegers,
   ClpECCompUtilities,
@@ -110,7 +110,7 @@ begin
   One := TBigInteger.One;
   result := TBigInteger.GetDefault;
   // B.1.2 Key Pair Generation by Testing Candidates
-  minWeight := TBitUtilities.Asr32(q.BitLength, 2);
+  minWeight := TBitOperations.Asr32(q.BitLength, 2);
   while (True) do
   begin
     // TODO Prefer this method? (change test cases that used fixed random)

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

@@ -24,7 +24,7 @@ interface
 uses
   SysUtils,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes,
   ClpECKeyParameters,
   ClpECCompUtilities,
@@ -134,7 +134,7 @@ var
   q: IECPoint;
 begin
   n := Fparameters.n;
-  minWeight := TBitUtilities.Asr32(n.BitLength, 2);
+  minWeight := TBitOperations.Asr32(n.BitLength, 2);
 
   while (true) do
   begin

+ 2 - 2
CryptoLib/src/Crypto/Randoms/ClpSecureRandom.pas

@@ -26,7 +26,7 @@ uses
   SyncObjs,
   SysUtils,
   DateUtils,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes,
   ClpDateTimeUtilities,
   ClpIDigest,
@@ -160,7 +160,7 @@ begin
   if ((AMaxValue and (AMaxValue - 1)) = 0) then
   begin
     LBits := NextInt32() and System.High(Int32);
-    Result := Int32(TBitUtilities.Asr64((Int64(LBits) * AMaxValue), 31));
+    Result := Int32(TBitOperations.Asr64((Int64(LBits) * AMaxValue), 31));
     Exit;
   end;
 

+ 2 - 2
CryptoLib/src/Crypto/Signers/ClpDsaSigner.pas

@@ -36,7 +36,7 @@ uses
   ClpParameterUtilities,
   ClpSecureRandom,
   ClpRandomDsaKCalculator,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpCryptoLibTypes;
 
@@ -124,7 +124,7 @@ function TDsaSigner.CalculateE(const AN: TBigInteger;
 var
   LLength: Int32;
 begin
-  LLength := Math.Min(System.length(AMessage), TBitUtilities.Asr32(AN.BitLength, 3));
+  LLength := Math.Min(System.length(AMessage), TBitOperations.Asr32(AN.BitLength, 3));
   Result := TBigInteger.Create(1, AMessage, 0, LLength);
 end;
 

+ 28 - 37
CryptoLib/src/GeneralUtilities/ClpStringUtilities.pas

@@ -24,7 +24,7 @@ interface
 uses
   SysUtils,
   StrUtils,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -134,7 +134,7 @@ begin
 
   while LStart <= LEnd do
   begin
-    LResult := TBitUtilities.RotateLeft32(LResult, 5);
+    LResult := TBitOperations.RotateLeft32(LResult, 5);
     LResult := LResult xor UInt32(AInput[LStart]);
     System.Inc(LStart);
   end;
@@ -143,51 +143,42 @@ end;
 
 class function TStringUtilities.SplitString(const AInput: string; ADelimiter: Char)
   : TCryptoLibStringArray;
-var
-  LPosStart, LPosDel, LSplitPoints, I, LLowPoint, LHighPoint, LLen: Int32;
 begin
-  Result := nil;
-  if AInput <> '' then
-  begin
-    { Determine the length of the resulting array }
-    LLowPoint := 1;
-    LHighPoint := System.Length(AInput);
-
-    LSplitPoints := 0;
-    for I := LLowPoint to LHighPoint do
-    begin
-      if (ADelimiter = AInput[I]) then
-        System.Inc(LSplitPoints);
-    end;
-
-    System.SetLength(Result, LSplitPoints + 1);
-
-    { Split the string and fill the resulting array }
-
-    I := 0;
-    LLen := 1;
-    LPosStart := 1;
-    LPosDel := System.Pos(ADelimiter, AInput);
-    while LPosDel > 0 do
-    begin
-      Result[I] := System.Copy(AInput, LPosStart, LPosDel - LPosStart);
-      LPosStart := LPosDel + LLen;
-      LPosDel := PosEx(ADelimiter, AInput, LPosStart);
-      System.Inc(I);
-    end;
-    Result[I] := System.Copy(AInput, LPosStart, System.Length(AInput));
-  end;
+  Result := SplitString(AInput, ADelimiter, 0);
 end;
 
 class function TStringUtilities.SplitString(const AInput: string; ADelimiter: Char;
   AMaxCount: Int32): TCryptoLibStringArray;
 var
-  LPosStart, LPosDel, J, K: Int32;
+  LPosStart, LPosDel, LSplitPoints, I, J, K, LLowPoint, LHighPoint: Int32;
 begin
   Result := nil;
   if AMaxCount <= 0 then
   begin
-    Result := SplitString(AInput, ADelimiter);
+    { Unlimited split: count delimiters then split }
+    if AInput <> '' then
+    begin
+      LLowPoint := 1;
+      LHighPoint := System.Length(AInput);
+      LSplitPoints := 0;
+      for I := LLowPoint to LHighPoint do
+      begin
+        if (ADelimiter = AInput[I]) then
+          System.Inc(LSplitPoints);
+      end;
+      System.SetLength(Result, LSplitPoints + 1);
+      I := 0;
+      LPosStart := 1;
+      LPosDel := System.Pos(ADelimiter, AInput);
+      while LPosDel > 0 do
+      begin
+        Result[I] := System.Copy(AInput, LPosStart, LPosDel - LPosStart);
+        LPosStart := LPosDel + 1;
+        LPosDel := PosEx(ADelimiter, AInput, LPosStart);
+        System.Inc(I);
+      end;
+      Result[I] := System.Copy(AInput, LPosStart, System.Length(AInput));
+    end;
     Exit;
   end;
   if AInput = '' then

+ 12 - 12
CryptoLib/src/Math/ClpBigInteger.pas

@@ -26,7 +26,7 @@ uses
   Math,
   ClpCryptoLibTypes,
   ClpPack,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpArrayUtilities,
   ClpISecureRandom,
   ClpIRandom;
@@ -445,13 +445,13 @@ end;
 
 class function TBigInteger.PopCount(const AValue: UInt32): Int32;
 begin
-  Result := TBitUtilities.PopCount32(AValue);
+  Result := TBitOperations.PopCount32(AValue);
 end;
 
 class function TBigInteger.BitLen(const AValue: Byte): Int32;
 begin
   //Result := BitLengthTable[AValue];
-  Result := 32 - TBitUtilities.NumberOfLeadingZeros32(AValue);
+  Result := 32 - TBitOperations.NumberOfLeadingZeros32(AValue);
 end;
 
 class function TBigInteger.BitLen(const AValue: UInt32): Int32;
@@ -477,7 +477,7 @@ begin
     Exit;
   end;
   Result := BitLengthTable[AValue]; *)
-  Result := 32 - TBitUtilities.NumberOfLeadingZeros32(AValue);
+  Result := 32 - TBitOperations.NumberOfLeadingZeros32(AValue);
 end;
 
 class function TBigInteger.CreateUValueOf(const AValue: UInt32): TBigInteger;
@@ -828,7 +828,7 @@ begin
     System.Dec(LIV);
     LM := Int64(AX[LIT] and UIMASK) - Int64(AY[LIV] and UIMASK) + LBorrow;
     AX[LIT] := UInt32(LM);
-    LBorrow := Int32(TBitUtilities.Asr64(LM, 63));
+    LBorrow := Int32(TBitOperations.Asr64(LM, 63));
   until LIV <= AYStart;
   if LBorrow <> 0 then
   begin
@@ -1079,7 +1079,7 @@ begin
 
     if LShift > 0 then
     begin
-      System.SetLength(LICount, (TBitUtilities.Asr32(LShift, 5)) + 1);
+      System.SetLength(LICount, (TBitOperations.Asr32(LShift, 5)) + 1);
       LICount[0] := UInt32(1) shl (LShift mod 32);
       LC := ShiftLeft(AY, LShift);
       LCBitLength := LCBitLength + LShift;
@@ -2194,7 +2194,7 @@ begin
     begin
       LY := LY.Multiply(LZ);
     end;
-    LExp := TBitUtilities.Asr32(LExp, 1);
+    LExp := TBitOperations.Asr32(LExp, 1);
     if LExp = 0 then
       Break;
     LZ := LZ.Multiply(LZ);
@@ -2343,9 +2343,9 @@ begin
       Result := FZero;
     Exit;
   end;
-  LResultLength := TBitUtilities.Asr32((BitLength - AN + 31), 5);
+  LResultLength := TBitOperations.Asr32((BitLength - AN + 31), 5);
   System.SetLength(LRes, LResultLength);
-  LNInts := TBitUtilities.Asr32(AN, 5);
+  LNInts := TBitOperations.Asr32(AN, 5);
   LNBits := AN and 31;
   if LNBits = 0 then
   begin
@@ -2633,7 +2633,7 @@ var
 begin
   // Clone magnitude
   LMag := System.Copy(FMagnitude);
-  LMag[System.Length(LMag) - 1 - (TBitUtilities.Asr32(AN, 5))] := LMag[System.Length(LMag) - 1 - (TBitUtilities.Asr32(AN, 5))] xor (UInt32(1) shl (AN and 31));
+  LMag[System.Length(LMag) - 1 - (TBitOperations.Asr32(AN, 5))] := LMag[System.Length(LMag) - 1 - (TBitOperations.Asr32(AN, 5))] xor (UInt32(1) shl (AN and 31));
   Result := TBigInteger.Create(FSign, LMag, False);
 end;
 
@@ -2667,7 +2667,7 @@ begin
     LOffset := LOffset + 32;
   end;
 
-  LOffset := LOffset + TBitUtilities.NumberOfTrailingZeros32(LWord);
+  LOffset := LOffset + TBitOperations.NumberOfTrailingZeros32(LWord);
  (*
   while (LWord and $FF) = 0 do
   begin
@@ -2808,7 +2808,7 @@ begin
     LMult := LMult shr 1;
     System.Inc(LZeros);
   end; *)
-  LTZ := TBitUtilities.NumberOfTrailingZeros32(LMult);
+  LTZ := TBitOperations.NumberOfTrailingZeros32(LMult);
   LMult := LMult shr LTZ;
   LZeros := LZeros + UInt32(LTZ);
   // Combine multiplier and zeros: mult | (zeros << 8)

+ 3 - 5
CryptoLib/src/Math/ClpPrimes.pas

@@ -29,6 +29,8 @@ uses
   ClpPack,
   ClpIDigest,
   ClpISecureRandom,
+  ClpArrayUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 resourcestring
@@ -150,10 +152,6 @@ type
 
 implementation
 
-uses
-  ClpArrayUtilities,
-  ClpBitUtilities;
-
 { TPrimes.TMROutput }
 
 constructor TPrimes.TMROutput.Create(AProvablyComposite: Boolean;
@@ -630,7 +628,7 @@ begin
       Break;
     AC := AC + ASeed[LPos];
     ASeed[LPos] := Byte(AC);
-    AC := TBitUtilities.Asr32(AC, 8);
+    AC := TBitOperations.Asr32(AC, 8);
   end;
 end;
 

+ 8 - 8
CryptoLib/src/Math/EC/ClpECAlgorithms.pas

@@ -26,7 +26,7 @@ uses
   Math,
   ClpCryptoLibTypes,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat,
   ClpIECC,
   ClpECCompUtilities,
@@ -260,12 +260,12 @@ begin
     while j >= 0 do
     begin
 
-      secretBitK := BigK[TBitUtilities.Asr32(j, 5)] shr (j and $1F);
+      secretBitK := BigK[TBitOperations.Asr32(j, 5)] shr (j and $1F);
       secretIndexK := secretIndexK xor (secretBitK shr 1);
       secretIndexK := secretIndexK shl 1;
       secretIndexK := secretIndexK xor secretBitK;
 
-      secretBitL := BigL[TBitUtilities.Asr32(j, 5)] shr (j and $1F);
+      secretBitL := BigL[TBitOperations.Asr32(j, 5)] shr (j and $1F);
       secretIndexL := secretIndexL xor (secretBitL shr 1);
       secretIndexL := secretIndexL shl 1;
       secretIndexL := secretIndexL xor secretBitL;
@@ -319,8 +319,8 @@ begin
     jsfi := jsf[i];
 
     // NOTE: The shifting ensures the sign is extended correctly
-    kDigit := (TBitUtilities.Asr32((jsfi shl 24), 28));
-    lDigit := (TBitUtilities.Asr32((jsfi shl 28), 28));
+    kDigit := (TBitOperations.Asr32((jsfi shl 24), 28));
+    lDigit := (TBitOperations.Asr32((jsfi shl 28), 28));
 
     index := 4 + (kDigit * 3) + lDigit;
     R := R.TwicePlus(table[index]);
@@ -540,7 +540,7 @@ begin
         tableP := preCompP;
       end;
 
-      point := point.Add(tableP[TBitUtilities.Asr32(nP, 1)]);
+      point := point.Add(tableP[TBitOperations.Asr32(nP, 1)]);
     end;
     if (wiQ <> 0) then
     begin
@@ -555,7 +555,7 @@ begin
         tableQ := preCompQ;
       end;
 
-      point := point.Add(tableQ[TBitUtilities.Asr32(nQ, 1)]);
+      point := point.Add(tableQ[TBitOperations.Asr32(nQ, 1)]);
 
     end;
 
@@ -723,7 +723,7 @@ begin
           table := info.PreCompNeg;
         end;
 
-        point := point.Add(table[TBitUtilities.Asr32(n, 1)]);
+        point := point.Add(table[TBitOperations.Asr32(n, 1)]);
       end;
     end;
 

+ 11 - 11
CryptoLib/src/Math/EC/ClpECC.pas

@@ -33,7 +33,7 @@ uses
   ClpCryptoLibTypes,
   ClpBigInteger,
   ClpBigIntegers,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpIGlvEndomorphism,
   ClpECAlgorithms,
   ClpLongArray,
@@ -2501,8 +2501,8 @@ begin
     raise EArgumentCryptoLibException.CreateRes(@SHalfTraceUndefinedForM);
   end;
 
-  n := TBitUtilities.Asr32((m + 1), 1);
-  K := 31 - TBitUtilities.NumberOfLeadingZeros32(n);
+  n := TBitOperations.Asr32((m + 1), 1);
+  K := 31 - TBitOperations.NumberOfLeadingZeros32(n);
   nk := 1;
 
   ht := Self as IECFieldElement;
@@ -2510,7 +2510,7 @@ begin
   begin
     ht := ht.SquarePow(nk shl 1).Add(ht);
     System.Dec(K);
-    nk := TBitUtilities.Asr32(n, K);
+    nk := TBitOperations.Asr32(n, K);
 
     if ((nk and 1) <> 0) then
     begin
@@ -2533,7 +2533,7 @@ var
 begin
   m := FieldSize;
 
-  K := 31 - TBitUtilities.NumberOfLeadingZeros32(m);
+  K := 31 - TBitOperations.NumberOfLeadingZeros32(m);
   mk := 1;
 
   tr := Self as IECFieldElement;
@@ -2542,7 +2542,7 @@ begin
     tr := tr.SquarePow(mk).Add(tr);
 
     System.Dec(K);
-    mk := TBitUtilities.Asr32(m, K);
+    mk := TBitOperations.Asr32(m, K);
 
     if ((mk and 1) <> 0) then
     begin
@@ -2857,8 +2857,8 @@ function TECCurve.GetHashCode: {$IFDEF DELPHI}Int32; {$ELSE}PtrInt;
 {$ENDIF DELPHI}
 begin
   result := (field as TObject).GetHashCode()
-    xor Int32(TBitUtilities.RotateLeft32(a.ToBigInteger().GetHashCode(), 8))
-    xor Int32(TBitUtilities.RotateLeft32(b.ToBigInteger().GetHashCode(), 16));
+    xor Int32(TBitOperations.RotateLeft32(a.ToBigInteger().GetHashCode(), 8))
+    xor Int32(TBitOperations.RotateLeft32(b.ToBigInteger().GetHashCode(), 16));
 end;
 
 function TECCurve.GetMultiplier: IECMultiplier;
@@ -3776,7 +3776,7 @@ begin
   for i := 0 to System.Pred(Fm_size) do
   begin
 
-    MASK := Byte(TBitUtilities.Asr32((i xor index) - 1, 31));
+    MASK := Byte(TBitOperations.Asr32((i xor index) - 1, 31));
 
     for j := 0 to System.Pred(FE_BYTES) do
     begin
@@ -3873,7 +3873,7 @@ begin
   for i := 0 to System.Pred(Fm_size) do
   begin
 
-    MASK := UInt64(TBitUtilities.Asr32((i xor index) - 1, 31));
+    MASK := UInt64(TBitOperations.Asr32((i xor index) - 1, 31));
 
     for j := 0 to System.Pred(FE_LONGS) do
     begin
@@ -5043,7 +5043,7 @@ begin
 
         b := ecCurve.b;
 
-        if (b.BitLength < (TBitUtilities.Asr32(ecCurve.FieldSize, 1))) then
+        if (b.BitLength < (TBitOperations.Asr32(ecCurve.FieldSize, 1))) then
         begin
           t1 := L1.Add(x1).Square();
 

+ 6 - 6
CryptoLib/src/Math/EC/ClpECCompUtilities.pas

@@ -24,7 +24,7 @@ interface
 uses
   SysUtils,
   Math,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpIECC,
   ClpIPreCompInfo,
   ClpIWNafPreCompInfo,
@@ -493,7 +493,7 @@ var
   bits, highBit, &length, zeroes, i, digit: Int32;
   naf: TCryptoLibInt32Array;
 begin
-  if ((TBitUtilities.Asr32(k.BitLength, 16)) <> 0) then
+  if ((TBitOperations.Asr32(k.BitLength, 16)) <> 0) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SInvalidBitLength);
   end;
@@ -506,7 +506,7 @@ begin
   _3k := k.ShiftLeft(1).Add(k);
 
   bits := _3k.BitLength;
-  System.SetLength(naf, TBitUtilities.Asr32(bits, 1));
+  System.SetLength(naf, TBitOperations.Asr32(bits, 1));
 
   diff := _3k.&Xor(k);
 
@@ -572,7 +572,7 @@ begin
   begin
     raise EArgumentCryptoLibException.CreateRes(@SInvalidRange);
   end;
-  if ((TBitUtilities.Asr32(LK.BitLength, 16)) <> 0) then
+  if ((TBitOperations.Asr32(LK.BitLength, 16)) <> 0) then
   begin
     raise EArgumentCryptoLibException.CreateRes(@SInvalidBitLength);
   end;
@@ -587,7 +587,7 @@ begin
   // 2^width and a mask and sign bit set accordingly
   pow2 := 1 shl width;
   mask := pow2 - 1;
-  sign := TBitUtilities.Asr32(pow2, 1);
+  sign := TBitOperations.Asr32(pow2, 1);
 
   carry := false;
   length := 0;
@@ -788,7 +788,7 @@ begin
   // 2^width and a mask and sign bit set accordingly
   pow2 := 1 shl width;
   mask := pow2 - 1;
-  sign := TBitUtilities.Asr32(pow2, 1);
+  sign := TBitOperations.Asr32(pow2, 1);
 
   carry := false;
   length := 0;

+ 6 - 6
CryptoLib/src/Math/EC/ClpLongArray.pas

@@ -25,7 +25,7 @@ uses
   SysUtils,
   Math,
   ClpCryptoLibTypes,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat,
   ClpInterleave,
   ClpArrayUtilities,
@@ -255,7 +255,7 @@ end;
 
 class function TLongArray.BitLength(AW: UInt64): Int32;
 begin
-  Result := 64 - TBitUtilities.NumberOfLeadingZeros64(AW);
+  Result := 64 - TBitOperations.NumberOfLeadingZeros64(AW);
 end;
 
 function TLongArray.Degree(): Int32;
@@ -658,7 +658,7 @@ var
   LVectorableWords: Int32;
   LVectorWiseWords: Int32;
 begin
-  LMLen := TBitUtilities.Asr32(AM + 63, 6);
+  LMLen := TBitOperations.Asr32(AM + 63, 6);
   if ALen < LMLen then
     Exit(ALen);
 
@@ -677,7 +677,7 @@ begin
   else
     LKNext := 0;
   LWordWiseLimit := Max(AM, LKMax + 64);
-  LVectorableWords := TBitUtilities.Asr32(LExcessBits + Min(LNumBits - LWordWiseLimit, AM - LKNext), 6);
+  LVectorableWords := TBitOperations.Asr32(LExcessBits + Min(LNumBits - LWordWiseLimit, AM - LKNext), 6);
   if LVectorableWords > 1 then
   begin
     LVectorWiseWords := ALen - LVectorableWords;
@@ -1082,7 +1082,7 @@ begin
   LLen := GetUsedLength();
   if LLen = 0 then
     Exit(Self);
-  LMLen := TBitUtilities.Asr32(AM + 63, 6);
+  LMLen := TBitOperations.Asr32(AM + 63, 6);
   System.SetLength(LR, LMLen shl 1);
   if LLen > 0 then
     System.Move(FData[0], LR[0], LLen * SizeOf(UInt64));
@@ -1128,7 +1128,7 @@ begin
     Exit(Self);
 
   LUz := Copy();
-  LT := TBitUtilities.Asr32(AM + 63, 6);
+  LT := TBitOperations.Asr32(AM + 63, 6);
 
   LVz := TLongArray.Create(LT);
   ReduceBit(LVz.FData, 0, AM, AM, AKs);

+ 2 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256K1Custom.pas

@@ -25,7 +25,7 @@ uses
   ClpMod,
   ClpEncoders,
   ClpNat,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat256,
   ClpECC,
   ClpBigInteger,
@@ -1161,7 +1161,7 @@ begin
 
   for i := 0 to System.Pred(Fm_size) do
   begin
-    MASK := UInt32(TBitUtilities.Asr32((i xor index) - 1, 31));
+    MASK := UInt32(TBitOperations.Asr32((i xor index) - 1, 31));
 
     for J := 0 to System.Pred(SECP256K1_FE_INTS) do
     begin

+ 32 - 32
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP256R1Custom.pas

@@ -25,7 +25,7 @@ uses
   ClpMod,
   ClpEncoders,
   ClpNat,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat256,
   ClpECC,
   ClpBigInteger,
@@ -330,31 +330,31 @@ var
 begin
   c := Int64(z[0]) + 1;
   z[0] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     c := c + Int64(z[1]);
     z[1] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
     c := c + Int64(z[2]);
     z[2] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
   end;
   c := c + (Int64(z[3]) - 1);
   z[3] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     c := c + Int64(z[4]);
     z[4] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
     c := c + Int64(z[5]);
     z[5] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
   end;
   c := c + (Int64(z[6]) - 1);
   z[6] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   c := c + (Int64(z[7]) + 1);
   z[7] := UInt32(c);
   // c := TBitUtilities.Asr64(c, 32);
@@ -429,28 +429,28 @@ begin
 
   cc := cc + (Int64(xx[0]) - t3 - t7);
   z[0] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[1]) + t1 - t4 - t6);
   z[1] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[2]) + t2 - t5);
   z[2] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[3]) + (t3 shl 1) + t7 - t6);
   z[3] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[4]) + (t4 shl 1) + xx14 - t1);
   z[4] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[5]) + (t5 shl 1) - t2);
   z[5] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[6]) + (t6 shl 1) + t7);
   z[6] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[7]) + (xx15 shl 1) + xx08 - t2 - t4);
   z[7] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + n;
 
 {$IFDEF DEBUG}
@@ -505,34 +505,34 @@ begin
 
     cc := cc + (Int64(z[0]) + xx08);
     z[0] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
     if (cc <> 0) then
     begin
       cc := cc + Int64(z[1]);
       z[1] := UInt32(cc);
-      cc := TBitUtilities.Asr64(cc, 32);
+      cc := TBitOperations.Asr64(cc, 32);
       cc := cc + Int64(z[2]);
       z[2] := UInt32(cc);
-      cc := TBitUtilities.Asr64(cc, 32);
+      cc := TBitOperations.Asr64(cc, 32);
     end;
     cc := cc + (Int64(z[3]) - xx08);
     z[3] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
     if (cc <> 0) then
     begin
       cc := cc + Int64(z[4]);
       z[4] := UInt32(cc);
-      cc := TBitUtilities.Asr64(cc, 32);
+      cc := TBitOperations.Asr64(cc, 32);
       cc := cc + Int64(z[5]);
       z[5] := UInt32(cc);
-      cc := TBitUtilities.Asr64(cc, 32);
+      cc := TBitOperations.Asr64(cc, 32);
     end;
     cc := cc + (Int64(z[6]) - xx08);
     z[6] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
     cc := cc + (Int64(z[7]) + xx08);
     z[7] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
 
 {$IFDEF DEBUG}
     System.Assert((cc = 0) or (cc = 1));
@@ -581,31 +581,31 @@ var
 begin
   c := Int64(z[0]) - 1;
   z[0] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     c := c + Int64(z[1]);
     z[1] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
     c := c + Int64(z[2]);
     z[2] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
   end;
   c := c + (Int64(z[3]) + 1);
   z[3] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     c := c + Int64(z[4]);
     z[4] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
     c := c + Int64(z[5]);
     z[5] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
   end;
   c := c + (Int64(z[6]) + 1);
   z[6] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   c := c + (Int64(z[7]) - 1);
   z[7] := UInt32(c);
   // c := TBitUtilities.Asr64(c, 32);
@@ -1304,7 +1304,7 @@ begin
 
   for i := 0 to System.Pred(Fm_size) do
   begin
-    MASK := UInt32(TBitUtilities.Asr32((i xor index) - 1, 31));
+    MASK := UInt32(TBitOperations.Asr32((i xor index) - 1, 31));
 
     for J := 0 to System.Pred(SECP256R1_FE_INTS) do
     begin

+ 29 - 29
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP384R1Custom.pas

@@ -25,7 +25,7 @@ uses
   ClpMod,
   ClpEncoders,
   ClpNat,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat384,
   ClpECC,
   ClpBigInteger,
@@ -295,22 +295,22 @@ var
 begin
   c := Int64(z[0]) + 1;
   z[0] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   c := c + (Int64(z[1]) - 1);
   z[1] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     c := c + Int64(z[2]);
     z[2] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
   end;
   c := c + (Int64(z[3]) + 1);
   z[3] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   c := c + (Int64(z[4]) + 1);
   z[4] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     TNat.IncAt(12, z, 5);
@@ -339,22 +339,22 @@ var
 begin
   c := Int64(z[0]) - 1;
   z[0] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   c := c + (Int64(z[1]) + 1);
   z[1] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     c := c + Int64(z[2]);
     z[2] := UInt32(c);
-    c := TBitUtilities.Asr64(c, 32);
+    c := TBitOperations.Asr64(c, 32);
   end;
   c := c + (Int64(z[3]) - 1);
   z[3] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   c := c + (Int64(z[4]) - 1);
   z[4] := UInt32(c);
-  c := TBitUtilities.Asr64(c, 32);
+  c := TBitOperations.Asr64(c, 32);
   if (c <> 0) then
   begin
     TNat.DecAt(12, z, 5);
@@ -438,22 +438,22 @@ begin
 
     cc := cc + (Int64(z[0]) + xx12);
     z[0] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
     cc := cc + (Int64(z[1]) - xx12);
     z[1] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
     if (cc <> 0) then
     begin
       cc := cc + Int64(z[2]);
       z[2] := UInt32(cc);
-      cc := TBitUtilities.Asr64(cc, 32);
+      cc := TBitOperations.Asr64(cc, 32);
     end;
     cc := cc + (Int64(z[3]) + xx12);
     z[3] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
     cc := cc + (Int64(z[4]) + xx12);
     z[4] := UInt32(cc);
-    cc := TBitUtilities.Asr64(cc, 32);
+    cc := TBitOperations.Asr64(cc, 32);
 
 {$IFDEF DEBUG}
     System.Assert((cc = 0) or (cc = 1));
@@ -496,40 +496,40 @@ begin
   cc := 0;
   cc := cc + (Int64(xx[0]) + t7);
   z[0] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[1]) + xx23 - t0 + t1);
   z[1] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[2]) - xx21 - t1 + t2);
   z[2] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[3]) - t2 + t3 + t7);
   z[3] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[4]) + xx16 + xx21 + t1 - t3 + t7);
   z[4] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[5]) - xx16 + t1 + t2 + t4);
   z[5] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[6]) + xx18 - xx17 + t2 + t3);
   z[6] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[7]) + xx16 + xx19 - xx18 + t3);
   z[7] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[8]) + xx16 + xx17 + xx20 - xx19);
   z[8] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[9]) + xx18 - xx20 + t4);
   z[9] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[10]) + xx18 + xx19 - t5 + t6);
   z[10] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (Int64(xx[11]) + xx19 + xx20 - t6);
   z[11] := UInt32(cc);
-  cc := TBitUtilities.Asr64(cc, 32);
+  cc := TBitOperations.Asr64(cc, 32);
   cc := cc + (n);
 
 {$IFDEF DEBUG}
@@ -1312,7 +1312,7 @@ begin
 
   for i := 0 to System.Pred(Fm_size) do
   begin
-    MASK := UInt32(TBitUtilities.Asr32((i xor index) - 1, 31));
+    MASK := UInt32(TBitOperations.Asr32((i xor index) - 1, 31));
 
     for J := 0 to System.Pred(SECP384R1_FE_INTS) do
     begin

+ 2 - 2
CryptoLib/src/Math/EC/Custom/Sec/ClpSecP521R1Custom.pas

@@ -25,7 +25,7 @@ uses
   ClpNat,
   ClpMod,
   ClpEncoders,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat512,
   ClpECC,
   ClpBigInteger,
@@ -1105,7 +1105,7 @@ begin
 
   for i := 0 to System.Pred(Fm_size) do
   begin
-    MASK := UInt32(TBitUtilities.Asr32((i xor index) - 1, 31));
+    MASK := UInt32(TBitOperations.Asr32((i xor index) - 1, 31));
 
     for J := 0 to System.Pred(SECP521R1_FE_INTS) do
     begin

+ 4 - 4
CryptoLib/src/Math/EC/Custom/Sec/ClpSecT283Custom.pas

@@ -22,7 +22,7 @@ unit ClpSecT283Custom;
 interface
 
 uses
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpEncoders,
   ClpNat,
   ClpNat320,
@@ -716,13 +716,13 @@ begin
     j := UInt32(x shr k);
     g := u[j and 7] xor u[(j shr 3) and 7] shl 3 xor u[(j shr 6) and 7] shl 6;
     l := l xor ((g shl k));
-    h := h xor TBitUtilities.NegativeRightShift64(g, -k);
+    h := h xor TBitOperations.NegativeRightShift64(g, -k);
 
     System.Dec(k, 9);
   until not(k > 0);
 
   h := h xor (((x and Int64($0100804020100800)) and
-    UInt64(TBitUtilities.Asr64(Int64(y) shl 7, 63))) shr 8);
+    UInt64(TBitOperations.Asr64(Int64(y) shl 7, 63))) shr 8);
 
 {$IFDEF DEBUG}
   System.Assert((h shr 49) = 0);
@@ -1616,7 +1616,7 @@ begin
 
   for i := 0 to System.Pred(Fm_size) do
   begin
-    MASK := UInt64(Int64(TBitUtilities.Asr32((i xor index) - 1, 31)));
+    MASK := UInt64(Int64(TBitOperations.Asr32((i xor index) - 1, 31)));
 
     for j := 0 to System.Pred(SECT283K1_FE_LONGS) do
     begin

+ 10 - 10
CryptoLib/src/Math/EC/Multiplier/ClpMultipliers.pas

@@ -24,7 +24,7 @@ interface
 uses
   SysUtils,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpNat,
   ClpTnaf,
   ClpIECC,
@@ -301,7 +301,7 @@ begin
     while j >= 0 do
     begin
 
-      secretBit := LK[TBitUtilities.Asr32(j, 5)] shr (j and $1F);
+      secretBit := LK[TBitOperations.Asr32(j, 5)] shr (j and $1F);
       secretIndex := secretIndex xor (secretBit shr 1);
       secretIndex := secretIndex shl 1;
       secretIndex := secretIndex xor secretBit;
@@ -407,7 +407,7 @@ begin
   begin
     System.Dec(i);
     wi := wnaf[i];
-    digit := TBitUtilities.Asr32(wi, 16);
+    digit := TBitOperations.Asr32(wi, 16);
     zeroes := wi and $FFFF;
 
     n := System.Abs(digit);
@@ -423,7 +423,7 @@ begin
     // Optimization can only be used for values in the lower half of the table
     if ((n shl 2) < (1 shl width)) then
     begin
-      highest := 32 - TBitUtilities.NumberOfLeadingZeros32(n);
+      highest := 32 - TBitOperations.NumberOfLeadingZeros32(n);
 
       // TODO Get addition/doubling cost ratio from curve and compare to 'scale' to see if worth substituting?
       scale := width - highest;
@@ -431,13 +431,13 @@ begin
 
       i1 := ((1 shl (width - 1)) - 1);
       i2 := (lowBits shl scale) + 1;
-      R := table[TBitUtilities.Asr32(i1, 1)].add(table[TBitUtilities.Asr32(i2, 1)]);
+      R := table[TBitOperations.Asr32(i1, 1)].add(table[TBitOperations.Asr32(i2, 1)]);
 
       zeroes := zeroes - scale;
     end
     else
     begin
-      R := table[TBitUtilities.Asr32(n, 1)];
+      R := table[TBitOperations.Asr32(n, 1)];
     end;
 
     R := R.TimesPow2(zeroes);
@@ -447,7 +447,7 @@ begin
   begin
     System.Dec(i);
     wi := wnaf[i];
-    digit := TBitUtilities.Asr32(wi, 16);
+    digit := TBitOperations.Asr32(wi, 16);
     zeroes := wi and $FFFF;
 
     n := System.Abs(digit);
@@ -460,7 +460,7 @@ begin
       table := preComp;
     end;
 
-    lr := table[TBitUtilities.Asr32(n, 1)];
+    lr := table[TBitOperations.Asr32(n, 1)];
 
     R := R.TwicePlus(lr);
     R := R.TimesPow2(zeroes);
@@ -516,11 +516,11 @@ begin
 
       if ui > 0 then
       begin
-        x := pu[TBitUtilities.Asr32(ui, 1)];
+        x := pu[TBitOperations.Asr32(ui, 1)];
       end
       else
       begin
-        x := puNeg[TBitUtilities.Asr32(-ui, 1)];
+        x := puNeg[TBitOperations.Asr32(-ui, 1)];
       end;
 
       q := q.add(x) as IAbstractF2mPoint;

+ 2 - 2
CryptoLib/src/Math/EC/Rfc7748/ClpX25519.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   ClpArrayUtilities,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes,
   ClpEd25519,
   ClpISecureRandom,
@@ -190,7 +190,7 @@ begin
     TX25519Field.Sqr(LZ3, LZ3);
     TX25519Field.Mul(LZ3, LX1, LZ3);
     System.Dec(LBit);
-    LWord := TBitUtilities.Asr32(LBit, 5);
+    LWord := TBitOperations.Asr32(LBit, 5);
     LShift := LBit and $1F;
     LKt := Int32(LN[LWord] shr LShift) and 1;
     LSwap := LSwap xor LKt;

+ 66 - 66
CryptoLib/src/Math/EC/Rfc7748/ClpX25519Field.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   ClpMod,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpArrayUtilities,
   ClpCryptoLibTypes;
 
@@ -169,9 +169,9 @@ begin
     Ld := Ld or (AX[LI] xor AY[LI]);
     System.Inc(LI);
   end;
-  Ld := Ld or TBitUtilities.Asr32(Ld, 16);
+  Ld := Ld or TBitOperations.Asr32(Ld, 16);
   Ld := Ld and $FFFF;
-  Result := TBitUtilities.Asr32(Ld - 1, 31);
+  Result := TBitOperations.Asr32(Ld - 1, 31);
 end;
 
 class function TX25519Field.AreEqualVar(const AX, AY: TCryptoLibInt32Array): Boolean;
@@ -193,33 +193,33 @@ begin
   Lz7 := AZ[7];
   Lz8 := AZ[8];
   Lz9 := AZ[9];
-  Lz2 := Lz2 + TBitUtilities.Asr32(Lz1, 26);
+  Lz2 := Lz2 + TBitOperations.Asr32(Lz1, 26);
   Lz1 := Lz1 and M26;
-  Lz4 := Lz4 + TBitUtilities.Asr32(Lz3, 26);
+  Lz4 := Lz4 + TBitOperations.Asr32(Lz3, 26);
   Lz3 := Lz3 and M26;
-  Lz7 := Lz7 + TBitUtilities.Asr32(Lz6, 26);
+  Lz7 := Lz7 + TBitOperations.Asr32(Lz6, 26);
   Lz6 := Lz6 and M26;
-  Lz9 := Lz9 + TBitUtilities.Asr32(Lz8, 26);
+  Lz9 := Lz9 + TBitOperations.Asr32(Lz8, 26);
   Lz8 := Lz8 and M26;
-  Lz3 := Lz3 + TBitUtilities.Asr32(Lz2, 25);
+  Lz3 := Lz3 + TBitOperations.Asr32(Lz2, 25);
   Lz2 := Lz2 and M25;
-  Lz5 := Lz5 + TBitUtilities.Asr32(Lz4, 25);
+  Lz5 := Lz5 + TBitOperations.Asr32(Lz4, 25);
   Lz4 := Lz4 and M25;
-  Lz8 := Lz8 + TBitUtilities.Asr32(Lz7, 25);
+  Lz8 := Lz8 + TBitOperations.Asr32(Lz7, 25);
   Lz7 := Lz7 and M25;
-  Lz0 := Lz0 + TBitUtilities.Asr32(Lz9, 25) * 38;
+  Lz0 := Lz0 + TBitOperations.Asr32(Lz9, 25) * 38;
   Lz9 := Lz9 and M25;
-  Lz1 := Lz1 + TBitUtilities.Asr32(Lz0, 26);
+  Lz1 := Lz1 + TBitOperations.Asr32(Lz0, 26);
   Lz0 := Lz0 and M26;
-  Lz6 := Lz6 + TBitUtilities.Asr32(Lz5, 26);
+  Lz6 := Lz6 + TBitOperations.Asr32(Lz5, 26);
   Lz5 := Lz5 and M26;
-  Lz2 := Lz2 + TBitUtilities.Asr32(Lz1, 26);
+  Lz2 := Lz2 + TBitOperations.Asr32(Lz1, 26);
   Lz1 := Lz1 and M26;
-  Lz4 := Lz4 + TBitUtilities.Asr32(Lz3, 26);
+  Lz4 := Lz4 + TBitOperations.Asr32(Lz3, 26);
   Lz3 := Lz3 and M26;
-  Lz7 := Lz7 + TBitUtilities.Asr32(Lz6, 26);
+  Lz7 := Lz7 + TBitOperations.Asr32(Lz6, 26);
   Lz6 := Lz6 and M26;
-  Lz9 := Lz9 + TBitUtilities.Asr32(Lz8, 26);
+  Lz9 := Lz9 + TBitOperations.Asr32(Lz8, 26);
   Lz8 := Lz8 and M26;
   AZ[0] := Lz0;
   AZ[1] := Lz1;
@@ -256,7 +256,7 @@ var
   LI: Int32;
 begin
   {$IFDEF DEBUG}
-  System.Assert(TBitUtilities.Asr32(ANegate, 1) = 0);
+  System.Assert(TBitOperations.Asr32(ANegate, 1) = 0);
   {$ENDIF}
   LMask := 0 - ANegate;
   LI := 0;
@@ -495,9 +495,9 @@ begin
     Ld := Ld or AX[LI];
     System.Inc(LI);
   end;
-  Ld := Ld or TBitUtilities.Asr32(Ld, 16);
+  Ld := Ld or TBitOperations.Asr32(Ld, 16);
   Ld := Ld and $FFFF;
-  Result := TBitUtilities.Asr32(Ld - 1, 31);
+  Result := TBitOperations.Asr32(Ld - 1, 31);
 end;
 
 class function TX25519Field.IsOneVar(const AX: TCryptoLibInt32Array): Boolean;
@@ -517,9 +517,9 @@ begin
     Ld := Ld or AX[LI];
     System.Inc(LI);
   end;
-  Ld := Ld or TBitUtilities.Asr32(Ld, 16);
+  Ld := Ld or TBitOperations.Asr32(Ld, 16);
   Ld := Ld and $FFFF;
-  Result := TBitUtilities.Asr32(Ld - 1, 31);
+  Result := TBitOperations.Asr32(Ld - 1, 31);
 end;
 
 class function TX25519Field.IsZeroVar(const AX: TCryptoLibInt32Array): Boolean;
@@ -544,35 +544,35 @@ begin
   Lx9 := AX[9];
   Lc0 := Int64(Lx2) * AY;
   Lx2 := Int32(Lc0) and M25;
-  Lc0 := TBitUtilities.Asr64(Lc0, 25);
+  Lc0 := TBitOperations.Asr64(Lc0, 25);
   Lc1 := Int64(Lx4) * AY;
   Lx4 := Int32(Lc1) and M25;
-  Lc1 := TBitUtilities.Asr64(Lc1, 25);
+  Lc1 := TBitOperations.Asr64(Lc1, 25);
   Lc2 := Int64(Lx7) * AY;
   Lx7 := Int32(Lc2) and M25;
-  Lc2 := TBitUtilities.Asr64(Lc2, 25);
+  Lc2 := TBitOperations.Asr64(Lc2, 25);
   Lc3 := Int64(Lx9) * AY;
   Lx9 := Int32(Lc3) and M25;
-  Lc3 := TBitUtilities.Asr64(Lc3, 25);
+  Lc3 := TBitOperations.Asr64(Lc3, 25);
   Lc3 := Lc3 * 38;
   Lc3 := Lc3 + Int64(Lx0) * AY;
   AZ[0] := Int32(Lc3) and M26;
-  Lc3 := TBitUtilities.Asr64(Lc3, 26);
+  Lc3 := TBitOperations.Asr64(Lc3, 26);
   Lc1 := Lc1 + Int64(Lx5) * AY;
   AZ[5] := Int32(Lc1) and M26;
-  Lc1 := TBitUtilities.Asr64(Lc1, 26);
+  Lc1 := TBitOperations.Asr64(Lc1, 26);
   Lc3 := Lc3 + Int64(Lx1) * AY;
   AZ[1] := Int32(Lc3) and M26;
-  Lc3 := TBitUtilities.Asr64(Lc3, 26);
+  Lc3 := TBitOperations.Asr64(Lc3, 26);
   Lc0 := Lc0 + Int64(Lx3) * AY;
   AZ[3] := Int32(Lc0) and M26;
-  Lc0 := TBitUtilities.Asr64(Lc0, 26);
+  Lc0 := TBitOperations.Asr64(Lc0, 26);
   Lc1 := Lc1 + Int64(Lx6) * AY;
   AZ[6] := Int32(Lc1) and M26;
-  Lc1 := TBitUtilities.Asr64(Lc1, 26);
+  Lc1 := TBitOperations.Asr64(Lc1, 26);
   Lc2 := Lc2 + Int64(Lx8) * AY;
   AZ[8] := Int32(Lc2) and M26;
-  Lc2 := TBitUtilities.Asr64(Lc2, 26);
+  Lc2 := TBitOperations.Asr64(Lc2, 26);
   AZ[2] := Lx2 + Int32(Lc3);
   AZ[4] := Lx4 + Int32(Lc0);
   AZ[7] := Lx7 + Int32(Lc1);
@@ -662,37 +662,37 @@ begin
   Lc8 := (Int64(Lx4) * Ly4) shl 1;
   Lt := La8 + (Lc3 - La3);
   Lz8 := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + (Lc4 - La4) - Lb4;
   Lz9 := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := La0 + (Lt + Lc5 - La5) * 38;
   AZ[0] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La1 + (Lc6 - La6) * 38;
   AZ[1] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La2 + (Lc7 - La7) * 38;
   AZ[2] := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := Lt + La3 + (Lc8 - La8) * 38;
   AZ[3] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La4 + Lb4 * 38;
   AZ[4] := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := Lt + La5 + (Lc0 - La0);
   AZ[5] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La6 + (Lc1 - La1);
   AZ[6] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La7 + (Lc2 - La2);
   AZ[7] := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := Lt + Lz8;
   AZ[8] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   AZ[9] := Lz9 + Int32(Lt);
 end;
 
@@ -715,35 +715,35 @@ var
 begin
   Lt := AZ[9];
   Lz9 := Lt and M24;
-  Lt := TBitUtilities.Asr32(Lt, 24) + AX;
+  Lt := TBitOperations.Asr32(Lt, 24) + AX;
   Lcc := Int64(Lt) * 19;
   Lcc := Lcc + AZ[0];
   AZ[0] := Int32(Lcc) and M26;
-  Lcc := TBitUtilities.Asr64(Lcc, 26);
+  Lcc := TBitOperations.Asr64(Lcc, 26);
   Lcc := Lcc + AZ[1];
   AZ[1] := Int32(Lcc) and M26;
-  Lcc := TBitUtilities.Asr64(Lcc, 26);
+  Lcc := TBitOperations.Asr64(Lcc, 26);
   Lcc := Lcc + AZ[2];
   AZ[2] := Int32(Lcc) and M25;
-  Lcc := TBitUtilities.Asr64(Lcc, 25);
+  Lcc := TBitOperations.Asr64(Lcc, 25);
   Lcc := Lcc + AZ[3];
   AZ[3] := Int32(Lcc) and M26;
-  Lcc := TBitUtilities.Asr64(Lcc, 26);
+  Lcc := TBitOperations.Asr64(Lcc, 26);
   Lcc := Lcc + AZ[4];
   AZ[4] := Int32(Lcc) and M25;
-  Lcc := TBitUtilities.Asr64(Lcc, 25);
+  Lcc := TBitOperations.Asr64(Lcc, 25);
   Lcc := Lcc + AZ[5];
   AZ[5] := Int32(Lcc) and M26;
-  Lcc := TBitUtilities.Asr64(Lcc, 26);
+  Lcc := TBitOperations.Asr64(Lcc, 26);
   Lcc := Lcc + AZ[6];
   AZ[6] := Int32(Lcc) and M26;
-  Lcc := TBitUtilities.Asr64(Lcc, 26);
+  Lcc := TBitOperations.Asr64(Lcc, 26);
   Lcc := Lcc + AZ[7];
   AZ[7] := Int32(Lcc) and M25;
-  Lcc := TBitUtilities.Asr64(Lcc, 25);
+  Lcc := TBitOperations.Asr64(Lcc, 25);
   Lcc := Lcc + AZ[8];
   AZ[8] := Int32(Lcc) and M26;
-  Lcc := TBitUtilities.Asr64(Lcc, 26);
+  Lcc := TBitOperations.Asr64(Lcc, 26);
   AZ[9] := Lz9 + Int32(Lcc);
 end;
 
@@ -751,11 +751,11 @@ class procedure TX25519Field.Normalize(AZ: TCryptoLibInt32Array);
 var
   Lx: Int32;
 begin
-  Lx := TBitUtilities.Asr32(AZ[9], 23) and 1;
+  Lx := TBitOperations.Asr32(AZ[9], 23) and 1;
   Reduce(AZ, Lx);
   Reduce(AZ, -Lx);
   {$IFDEF DEBUG}
-  System.Assert(TBitUtilities.Asr32(AZ[9], 24) = 0);
+  System.Assert(TBitOperations.Asr32(AZ[9], 24) = 0);
   {$ENDIF}
 end;
 
@@ -879,37 +879,37 @@ begin
   Lc8 := Int64(Lx4) * Lx4_2;
   Lt := La8 + (Lc3 - La3);
   Lz8 := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + (Lc4 - La4) - Lb4;
   Lz9 := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := La0 + (Lt + Lc5 - La5) * 38;
   AZ[0] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La1 + (Lc6 - La6) * 38;
   AZ[1] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La2 + (Lc7 - La7) * 38;
   AZ[2] := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := Lt + La3 + (Lc8 - La8) * 38;
   AZ[3] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La4 + Lb4 * 38;
   AZ[4] := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := Lt + La5 + (Lc0 - La0);
   AZ[5] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La6 + (Lc1 - La1);
   AZ[6] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   Lt := Lt + La7 + (Lc2 - La2);
   AZ[7] := Int32(Lt) and M25;
-  Lt := TBitUtilities.Asr64(Lt, 25);
+  Lt := TBitOperations.Asr64(Lt, 25);
   Lt := Lt + Lz8;
   AZ[8] := Int32(Lt) and M26;
-  Lt := TBitUtilities.Asr64(Lt, 26);
+  Lt := TBitOperations.Asr64(Lt, 26);
   AZ[9] := Lz9 + Int32(Lt);
 end;
 

+ 10 - 10
CryptoLib/src/Math/EC/Rfc8032/ClpEd25519.pas

@@ -25,7 +25,7 @@ uses
   SyncObjs,
   ClpCodec,
   ClpDigestUtilities,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpIDigest,
   ClpISecureRandom,
   ClpNat256,
@@ -464,7 +464,7 @@ var
   LX0: Int32;
   LU, LV: TCryptoLibInt32Array;
 begin
-  LX0 := TBitUtilities.Asr32(Int32(AP[PointBytes - 1] and $80), 7);
+  LX0 := TBitOperations.Asr32(Int32(AP[PointBytes - 1] and $80), 7);
   TX25519Field.Decode(AP, AR.Y);
   LU := TX25519Field.Create;
   LV := TX25519Field.Create;
@@ -851,7 +851,7 @@ begin
   LI := 0;
   while LI < PrecompPoints do
   begin
-    LCond := TBitUtilities.Asr32((LI xor AIndex) - 1, 31);
+    LCond := TBitOperations.Asr32((LI xor AIndex) - 1, 31);
     TX25519Field.CMov(LCond, FPrecompBaseComb, LOff, AP.YmxH, 0);
     LOff := LOff + TX25519Field.Size;
     TX25519Field.CMov(LCond, FPrecompBaseComb, LOff, AP.YpxH, 0);
@@ -881,7 +881,7 @@ begin
   LI := 0;
   while LI < 8 do
   begin
-    LCond := TBitUtilities.Asr32((LI xor LAbs) - 1, 31);
+    LCond := TBitOperations.Asr32((LI xor LAbs) - 1, 31);
     TX25519Field.CMov(LCond, ATable, LOff, AR.YmxH, 0);
     LOff := LOff + TX25519Field.Size;
     TX25519Field.CMov(LCond, ATable, LOff, AR.YpxH, 0);
@@ -1042,7 +1042,7 @@ begin
     while LBlock < PrecompBlocks do
     begin
       LW := LN[LBlock] shr LCOff;
-      LSign := TBitUtilities.Asr32(Int32(LW), PrecompTeeth - 1) and 1;
+      LSign := TBitOperations.Asr32(Int32(LW), PrecompTeeth - 1) and 1;
       LAbs := (Int32(LW) xor -LSign) and PrecompMask;
       {$IFDEF DEBUG}
       System.Assert((LSign = 0) or (LSign = 1));
@@ -1109,7 +1109,7 @@ begin
     LWP := LWsP[LBit];
     if LWP <> 0 then
     begin
-      LIndex := TBitUtilities.Asr32(LWP, 1) xor TBitUtilities.Asr32(LWP, 31);
+      LIndex := TBitOperations.Asr32(LWP, 1) xor TBitOperations.Asr32(LWP, 31);
       PointAddVar(LWP < 0, LTp[LIndex], AR, LT);
     end;
     System.Dec(LBit);
@@ -1273,25 +1273,25 @@ begin
     LWB := LWsB[LBit];
     if LWB <> 0 then
     begin
-      LIndex := TBitUtilities.Asr32(LWB, 1) xor TBitUtilities.Asr32(LWB, 31);
+      LIndex := TBitOperations.Asr32(LWB, 1) xor TBitOperations.Asr32(LWB, 31);
       PointAddVar(LWB < 0, FPrecompBaseWnaf[LIndex], AR, LT);
     end;
     LWB128 := LWsB[128 + LBit];
     if LWB128 <> 0 then
     begin
-      LIndex := TBitUtilities.Asr32(LWB128, 1) xor TBitUtilities.Asr32(LWB128, 31);
+      LIndex := TBitOperations.Asr32(LWB128, 1) xor TBitOperations.Asr32(LWB128, 31);
       PointAddVar(LWB128 < 0, FPrecompBase128Wnaf[LIndex], AR, LT);
     end;
     LWP := LWsP[LBit];
     if LWP <> 0 then
     begin
-      LIndex := TBitUtilities.Asr32(LWP, 1) xor TBitUtilities.Asr32(LWP, 31);
+      LIndex := TBitOperations.Asr32(LWP, 1) xor TBitOperations.Asr32(LWP, 31);
       PointAddVar(LWP < 0, LTp[LIndex], AR, LT);
     end;
     LWQ := LWsQ[LBit];
     if LWQ <> 0 then
     begin
-      LIndex := TBitUtilities.Asr32(LWQ, 1) xor TBitUtilities.Asr32(LWQ, 31);
+      LIndex := TBitOperations.Asr32(LWQ, 1) xor TBitOperations.Asr32(LWQ, 31);
       PointAddVar(LWQ < 0, LTq[LIndex], AR, LT);
     end;
     PointDouble(AR);

+ 53 - 53
CryptoLib/src/Math/EC/Rfc8032/ClpScalar25519.pas

@@ -22,7 +22,7 @@ unit ClpScalar25519;
 interface
 
 uses
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCodec,
   ClpWnaf,
   ClpNat256,
@@ -138,62 +138,62 @@ begin
   Lx11 := Int64(TCodec.Decode24(AN, 39)) shl 4;
   Lx12 := Int64(TCodec.Decode32(AN, 42));
   Lx13 := Int64(TCodec.Decode16(AN, 46)) shl 4;
-  Lx13 := Lx13 + TBitUtilities.Asr64(Lx12, 28);
+  Lx13 := Lx13 + TBitOperations.Asr64(Lx12, 28);
   Lx12 := Lx12 and M28L;
   Lx04 := Lx04 - Lx13 * L0;
   Lx05 := Lx05 - Lx13 * L1;
   Lx06 := Lx06 - Lx13 * L2;
   Lx07 := Lx07 - Lx13 * L3;
   Lx08 := Lx08 - Lx13 * L4;
-  Lx12 := Lx12 + TBitUtilities.Asr64(Lx11, 28);
+  Lx12 := Lx12 + TBitOperations.Asr64(Lx11, 28);
   Lx11 := Lx11 and M28L;
   Lx03 := Lx03 - Lx12 * L0;
   Lx04 := Lx04 - Lx12 * L1;
   Lx05 := Lx05 - Lx12 * L2;
   Lx06 := Lx06 - Lx12 * L3;
   Lx07 := Lx07 - Lx12 * L4;
-  Lx11 := Lx11 + TBitUtilities.Asr64(Lx10, 28);
+  Lx11 := Lx11 + TBitOperations.Asr64(Lx10, 28);
   Lx10 := Lx10 and M28L;
   Lx02 := Lx02 - Lx11 * L0;
   Lx03 := Lx03 - Lx11 * L1;
   Lx04 := Lx04 - Lx11 * L2;
   Lx05 := Lx05 - Lx11 * L3;
   Lx06 := Lx06 - Lx11 * L4;
-  Lx10 := Lx10 + TBitUtilities.Asr64(Lx09, 28);
+  Lx10 := Lx10 + TBitOperations.Asr64(Lx09, 28);
   Lx09 := Lx09 and M28L;
   Lx01 := Lx01 - Lx10 * L0;
   Lx02 := Lx02 - Lx10 * L1;
   Lx03 := Lx03 - Lx10 * L2;
   Lx04 := Lx04 - Lx10 * L3;
   Lx05 := Lx05 - Lx10 * L4;
-  Lx08 := Lx08 + TBitUtilities.Asr64(Lx07, 28);
+  Lx08 := Lx08 + TBitOperations.Asr64(Lx07, 28);
   Lx07 := Lx07 and M28L;
-  Lx09 := Lx09 + TBitUtilities.Asr64(Lx08, 28);
+  Lx09 := Lx09 + TBitOperations.Asr64(Lx08, 28);
   Lx08 := Lx08 and M28L;
-  Lt := TBitUtilities.Asr64(Lx08, 27) and 1;
+  Lt := TBitOperations.Asr64(Lx08, 27) and 1;
   Lx09 := Lx09 + Lt;
   Lx00 := Lx00 - Lx09 * L0;
   Lx01 := Lx01 - Lx09 * L1;
   Lx02 := Lx02 - Lx09 * L2;
   Lx03 := Lx03 - Lx09 * L3;
   Lx04 := Lx04 - Lx09 * L4;
-  Lx01 := Lx01 + TBitUtilities.Asr64(Lx00, 28);
+  Lx01 := Lx01 + TBitOperations.Asr64(Lx00, 28);
   Lx00 := Lx00 and M28L;
-  Lx02 := Lx02 + TBitUtilities.Asr64(Lx01, 28);
+  Lx02 := Lx02 + TBitOperations.Asr64(Lx01, 28);
   Lx01 := Lx01 and M28L;
-  Lx03 := Lx03 + TBitUtilities.Asr64(Lx02, 28);
+  Lx03 := Lx03 + TBitOperations.Asr64(Lx02, 28);
   Lx02 := Lx02 and M28L;
-  Lx04 := Lx04 + TBitUtilities.Asr64(Lx03, 28);
+  Lx04 := Lx04 + TBitOperations.Asr64(Lx03, 28);
   Lx03 := Lx03 and M28L;
-  Lx05 := Lx05 + TBitUtilities.Asr64(Lx04, 28);
+  Lx05 := Lx05 + TBitOperations.Asr64(Lx04, 28);
   Lx04 := Lx04 and M28L;
-  Lx06 := Lx06 + TBitUtilities.Asr64(Lx05, 28);
+  Lx06 := Lx06 + TBitOperations.Asr64(Lx05, 28);
   Lx05 := Lx05 and M28L;
-  Lx07 := Lx07 + TBitUtilities.Asr64(Lx06, 28);
+  Lx07 := Lx07 + TBitOperations.Asr64(Lx06, 28);
   Lx06 := Lx06 and M28L;
-  Lx08 := Lx08 + TBitUtilities.Asr64(Lx07, 28);
+  Lx08 := Lx08 + TBitOperations.Asr64(Lx07, 28);
   Lx07 := Lx07 and M28L;
-  Lx09 := TBitUtilities.Asr64(Lx08, 28);
+  Lx09 := TBitOperations.Asr64(Lx08, 28);
   Lx08 := Lx08 and M28L;
   Lx09 := Lx09 - Lt;
   {$IFDEF DEBUG}
@@ -204,21 +204,21 @@ begin
   Lx02 := Lx02 + (Lx09 and Int64(L2));
   Lx03 := Lx03 + (Lx09 and Int64(L3));
   Lx04 := Lx04 + (Lx09 and Int64(L4));
-  Lx01 := Lx01 + TBitUtilities.Asr64(Lx00, 28);
+  Lx01 := Lx01 + TBitOperations.Asr64(Lx00, 28);
   Lx00 := Lx00 and M28L;
-  Lx02 := Lx02 + TBitUtilities.Asr64(Lx01, 28);
+  Lx02 := Lx02 + TBitOperations.Asr64(Lx01, 28);
   Lx01 := Lx01 and M28L;
-  Lx03 := Lx03 + TBitUtilities.Asr64(Lx02, 28);
+  Lx03 := Lx03 + TBitOperations.Asr64(Lx02, 28);
   Lx02 := Lx02 and M28L;
-  Lx04 := Lx04 + TBitUtilities.Asr64(Lx03, 28);
+  Lx04 := Lx04 + TBitOperations.Asr64(Lx03, 28);
   Lx03 := Lx03 and M28L;
-  Lx05 := Lx05 + TBitUtilities.Asr64(Lx04, 28);
+  Lx05 := Lx05 + TBitOperations.Asr64(Lx04, 28);
   Lx04 := Lx04 and M28L;
-  Lx06 := Lx06 + TBitUtilities.Asr64(Lx05, 28);
+  Lx06 := Lx06 + TBitOperations.Asr64(Lx05, 28);
   Lx05 := Lx05 and M28L;
-  Lx07 := Lx07 + TBitUtilities.Asr64(Lx06, 28);
+  Lx07 := Lx07 + TBitOperations.Asr64(Lx06, 28);
   Lx06 := Lx06 and M28L;
-  Lx08 := Lx08 + TBitUtilities.Asr64(Lx07, 28);
+  Lx08 := Lx08 + TBitOperations.Asr64(Lx07, 28);
   Lx07 := Lx07 and M28L;
   TCodec.Encode56(UInt64(Lx00 or (Lx01 shl 28)), AR, 0);
   TCodec.Encode56(UInt64(Lx02 or (Lx03 shl 28)), AR, 7);
@@ -261,7 +261,7 @@ begin
   Lx11 := Lx11 - Lx18 * L2;
   Lx12 := Lx12 - Lx18 * L3;
   Lx13 := Lx13 - Lx18 * L4;
-  Lx17 := Lx17 + TBitUtilities.Asr64(Lx16, 28);
+  Lx17 := Lx17 + TBitOperations.Asr64(Lx16, 28);
   Lx16 := Lx16 and M28L;
   Lx08 := Lx08 - Lx17 * L0;
   Lx09 := Lx09 - Lx17 * L1;
@@ -273,7 +273,7 @@ begin
   Lx09 := Lx09 - Lx16 * L2;
   Lx10 := Lx10 - Lx16 * L3;
   Lx11 := Lx11 - Lx16 * L4;
-  Lx15 := Lx15 + TBitUtilities.Asr64(Lx14, 28);
+  Lx15 := Lx15 + TBitOperations.Asr64(Lx14, 28);
   Lx14 := Lx14 and M28L;
   Lx06 := Lx06 - Lx15 * L0;
   Lx07 := Lx07 - Lx15 * L1;
@@ -285,62 +285,62 @@ begin
   Lx07 := Lx07 - Lx14 * L2;
   Lx08 := Lx08 - Lx14 * L3;
   Lx09 := Lx09 - Lx14 * L4;
-  Lx13 := Lx13 + TBitUtilities.Asr64(Lx12, 28);
+  Lx13 := Lx13 + TBitOperations.Asr64(Lx12, 28);
   Lx12 := Lx12 and M28L;
   Lx04 := Lx04 - Lx13 * L0;
   Lx05 := Lx05 - Lx13 * L1;
   Lx06 := Lx06 - Lx13 * L2;
   Lx07 := Lx07 - Lx13 * L3;
   Lx08 := Lx08 - Lx13 * L4;
-  Lx12 := Lx12 + TBitUtilities.Asr64(Lx11, 28);
+  Lx12 := Lx12 + TBitOperations.Asr64(Lx11, 28);
   Lx11 := Lx11 and M28L;
   Lx03 := Lx03 - Lx12 * L0;
   Lx04 := Lx04 - Lx12 * L1;
   Lx05 := Lx05 - Lx12 * L2;
   Lx06 := Lx06 - Lx12 * L3;
   Lx07 := Lx07 - Lx12 * L4;
-  Lx11 := Lx11 + TBitUtilities.Asr64(Lx10, 28);
+  Lx11 := Lx11 + TBitOperations.Asr64(Lx10, 28);
   Lx10 := Lx10 and M28L;
   Lx02 := Lx02 - Lx11 * L0;
   Lx03 := Lx03 - Lx11 * L1;
   Lx04 := Lx04 - Lx11 * L2;
   Lx05 := Lx05 - Lx11 * L3;
   Lx06 := Lx06 - Lx11 * L4;
-  Lx10 := Lx10 + TBitUtilities.Asr64(Lx09, 28);
+  Lx10 := Lx10 + TBitOperations.Asr64(Lx09, 28);
   Lx09 := Lx09 and M28L;
   Lx01 := Lx01 - Lx10 * L0;
   Lx02 := Lx02 - Lx10 * L1;
   Lx03 := Lx03 - Lx10 * L2;
   Lx04 := Lx04 - Lx10 * L3;
   Lx05 := Lx05 - Lx10 * L4;
-  Lx08 := Lx08 + TBitUtilities.Asr64(Lx07, 28);
+  Lx08 := Lx08 + TBitOperations.Asr64(Lx07, 28);
   Lx07 := Lx07 and M28L;
-  Lx09 := Lx09 + TBitUtilities.Asr64(Lx08, 28);
+  Lx09 := Lx09 + TBitOperations.Asr64(Lx08, 28);
   Lx08 := Lx08 and M28L;
-  Lt := TBitUtilities.Asr64(Lx08, 27) and 1;
+  Lt := TBitOperations.Asr64(Lx08, 27) and 1;
   Lx09 := Lx09 + Lt;
   Lx00 := Lx00 - Lx09 * L0;
   Lx01 := Lx01 - Lx09 * L1;
   Lx02 := Lx02 - Lx09 * L2;
   Lx03 := Lx03 - Lx09 * L3;
   Lx04 := Lx04 - Lx09 * L4;
-  Lx01 := Lx01 + TBitUtilities.Asr64(Lx00, 28);
+  Lx01 := Lx01 + TBitOperations.Asr64(Lx00, 28);
   Lx00 := Lx00 and M28L;
-  Lx02 := Lx02 + TBitUtilities.Asr64(Lx01, 28);
+  Lx02 := Lx02 + TBitOperations.Asr64(Lx01, 28);
   Lx01 := Lx01 and M28L;
-  Lx03 := Lx03 + TBitUtilities.Asr64(Lx02, 28);
+  Lx03 := Lx03 + TBitOperations.Asr64(Lx02, 28);
   Lx02 := Lx02 and M28L;
-  Lx04 := Lx04 + TBitUtilities.Asr64(Lx03, 28);
+  Lx04 := Lx04 + TBitOperations.Asr64(Lx03, 28);
   Lx03 := Lx03 and M28L;
-  Lx05 := Lx05 + TBitUtilities.Asr64(Lx04, 28);
+  Lx05 := Lx05 + TBitOperations.Asr64(Lx04, 28);
   Lx04 := Lx04 and M28L;
-  Lx06 := Lx06 + TBitUtilities.Asr64(Lx05, 28);
+  Lx06 := Lx06 + TBitOperations.Asr64(Lx05, 28);
   Lx05 := Lx05 and M28L;
-  Lx07 := Lx07 + TBitUtilities.Asr64(Lx06, 28);
+  Lx07 := Lx07 + TBitOperations.Asr64(Lx06, 28);
   Lx06 := Lx06 and M28L;
-  Lx08 := Lx08 + TBitUtilities.Asr64(Lx07, 28);
+  Lx08 := Lx08 + TBitOperations.Asr64(Lx07, 28);
   Lx07 := Lx07 and M28L;
-  Lx09 := TBitUtilities.Asr64(Lx08, 28);
+  Lx09 := TBitOperations.Asr64(Lx08, 28);
   Lx08 := Lx08 and M28L;
   Lx09 := Lx09 - Lt;
   {$IFDEF DEBUG}
@@ -351,21 +351,21 @@ begin
   Lx02 := Lx02 + (Lx09 and Int64(L2));
   Lx03 := Lx03 + (Lx09 and Int64(L3));
   Lx04 := Lx04 + (Lx09 and Int64(L4));
-  Lx01 := Lx01 + TBitUtilities.Asr64(Lx00, 28);
+  Lx01 := Lx01 + TBitOperations.Asr64(Lx00, 28);
   Lx00 := Lx00 and M28L;
-  Lx02 := Lx02 + TBitUtilities.Asr64(Lx01, 28);
+  Lx02 := Lx02 + TBitOperations.Asr64(Lx01, 28);
   Lx01 := Lx01 and M28L;
-  Lx03 := Lx03 + TBitUtilities.Asr64(Lx02, 28);
+  Lx03 := Lx03 + TBitOperations.Asr64(Lx02, 28);
   Lx02 := Lx02 and M28L;
-  Lx04 := Lx04 + TBitUtilities.Asr64(Lx03, 28);
+  Lx04 := Lx04 + TBitOperations.Asr64(Lx03, 28);
   Lx03 := Lx03 and M28L;
-  Lx05 := Lx05 + TBitUtilities.Asr64(Lx04, 28);
+  Lx05 := Lx05 + TBitOperations.Asr64(Lx04, 28);
   Lx04 := Lx04 and M28L;
-  Lx06 := Lx06 + TBitUtilities.Asr64(Lx05, 28);
+  Lx06 := Lx06 + TBitOperations.Asr64(Lx05, 28);
   Lx05 := Lx05 and M28L;
-  Lx07 := Lx07 + TBitUtilities.Asr64(Lx06, 28);
+  Lx07 := Lx07 + TBitOperations.Asr64(Lx06, 28);
   Lx06 := Lx06 and M28L;
-  Lx08 := Lx08 + TBitUtilities.Asr64(Lx07, 28);
+  Lx08 := Lx08 + TBitOperations.Asr64(Lx07, 28);
   Lx07 := Lx07 and M28L;
   TCodec.Encode56(UInt64(Lx00 or (Lx01 shl 28)), AR, 0);
   TCodec.Encode56(UInt64(Lx02 or (Lx03 shl 28)), AR, 7);
@@ -409,7 +409,7 @@ begin
       Exit(False);
     LLenP := TScalarUtilities.GetBitLength(LLast, Lp);
     LS := LLenP - LLenNv;
-    LS := LS and (not TBitUtilities.Asr32(LS, 31));
+    LS := LS and (not TBitOperations.Asr32(LS, 31));
     if Int32(Lp[LLast]) < 0 then
     begin
       TScalarUtilities.AddShifted_NP(LLast, LS, LNu, LNv, Lp, Lt);
@@ -425,7 +425,7 @@ begin
       TScalarUtilities.Swap(Lu0, Lv0);
       TScalarUtilities.Swap(Lu1, Lv1);
       TScalarUtilities.Swap(LNu, LNv);
-      LLast := TBitUtilities.Asr32(LLenNv, 5);
+      LLast := TBitOperations.Asr32(LLenNv, 5);
       LLenNv := TScalarUtilities.GetBitLengthPositive(LLast, LNv);
     end;
   end;

+ 36 - 36
CryptoLib/src/Math/EC/Rfc8032/ClpScalarUtilities.pas

@@ -22,7 +22,7 @@ unit ClpScalarUtilities;
 interface
 
 uses
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -82,19 +82,19 @@ begin
     while LI <= ALast do
     begin
       Lp_i := AP[LI];
-      Lp_s := (Lp_i shl AShift) or TBitUtilities.NegativeRightShift32(Lprev_p, -AShift);
+      Lp_s := (Lp_i shl AShift) or TBitOperations.NegativeRightShift32(Lprev_p, -AShift);
       Lprev_p := Lp_i;
       Lcc_Nu := Lcc_Nu + ANu[LI];
       Lcc_Nu := Lcc_Nu + Lp_s;
       Lnext_v := ANv[LI];
-      Lv_s := (Lnext_v shl AShift) or TBitUtilities.NegativeRightShift32(Lprev_v, -AShift);
+      Lv_s := (Lnext_v shl AShift) or TBitOperations.NegativeRightShift32(Lprev_v, -AShift);
       Lprev_v := Lnext_v;
       Lcc_p := Lcc_p + Lp_i;
       Lcc_p := Lcc_p + Lv_s;
       Lp_i := UInt32(Lcc_p);
       Lcc_p := Lcc_p shr 32;
       AP[LI] := Lp_i;
-      Lq_s := (Lp_i shl AShift) or TBitUtilities.NegativeRightShift32(Lprev_q, -AShift);
+      Lq_s := (Lp_i shl AShift) or TBitOperations.NegativeRightShift32(Lprev_q, -AShift);
       Lprev_q := Lp_i;
       Lcc_Nu := Lcc_Nu + Lq_s;
       ANu[LI] := UInt32(Lcc_Nu);
@@ -107,7 +107,7 @@ begin
   // Copy the low limbs of the original p
   System.Move(AP[0], AT[0], ALast * System.SizeOf(UInt32));
 
-  LsWords := TBitUtilities.Asr32(AShift, 5);
+  LsWords := TBitOperations.Asr32(AShift, 5);
   LsBits := AShift and 31;
 
   if LsBits = 0 then
@@ -136,19 +136,19 @@ begin
   while LI <= ALast do
   begin
     Lnext_t := AT[LI - LsWords];
-    Lt_s := (Lnext_t shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_t, -LsBits);
+    Lt_s := (Lnext_t shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_t, -LsBits);
     Lprev_t := Lnext_t;
     Lcc_Nu := Lcc_Nu + ANu[LI];
     Lcc_Nu := Lcc_Nu + Lt_s;
     Lnext_v := ANv[LI - LsWords];
-    Lv_s := (Lnext_v shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_v, -LsBits);
+    Lv_s := (Lnext_v shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_v, -LsBits);
     Lprev_v := Lnext_v;
     Lcc_p := Lcc_p + AP[LI];
     Lcc_p := Lcc_p + Lv_s;
     AP[LI] := UInt32(Lcc_p);
     Lcc_p := Lcc_p shr 32;
     Lnext_q := AP[LI - LsWords];
-    Lq_s := (Lnext_q shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_q, -LsBits);
+    Lq_s := (Lnext_q shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_q, -LsBits);
     Lprev_q := Lnext_q;
     Lcc_Nu := Lcc_Nu + Lq_s;
     ANu[LI] := UInt32(Lcc_Nu);
@@ -164,7 +164,7 @@ var
   Lnext_v0, Lnext_v1, Lv0_s, Lv1_s: UInt32;
   Lprev_v0, Lprev_v1: UInt32;
 begin
-  LsWords := TBitUtilities.Asr32(AShift, 5);
+  LsWords := TBitOperations.Asr32(AShift, 5);
   LsBits := AShift and 31;
   Lcc_u0 := 0;
   Lcc_u1 := 0;
@@ -194,8 +194,8 @@ begin
   begin
     Lnext_v0 := AV0[LI - LsWords];
     Lnext_v1 := AV1[LI - LsWords];
-    Lv0_s := (Lnext_v0 shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_v0, -LsBits);
-    Lv1_s := (Lnext_v1 shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_v1, -LsBits);
+    Lv0_s := (Lnext_v0 shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_v0, -LsBits);
+    Lv1_s := (Lnext_v1 shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_v1, -LsBits);
     Lprev_v0 := Lnext_v0;
     Lprev_v1 := Lnext_v1;
     Lcc_u0 := Lcc_u0 + AU0[LI];
@@ -216,10 +216,10 @@ var
   LSign: UInt32;
 begin
   LI := ALast;
-  LSign := UInt32(TBitUtilities.Asr32(Int32(AX[LI]), 31));
+  LSign := UInt32(TBitOperations.Asr32(Int32(AX[LI]), 31));
   while (LI > 0) and (AX[LI] = LSign) do
     System.Dec(LI);
-  Result := LI * 32 + 32 - TBitUtilities.NumberOfLeadingZeros32(UInt32(Int32(AX[LI]) xor Int32(LSign)));
+  Result := LI * 32 + 32 - TBitOperations.NumberOfLeadingZeros32(UInt32(Int32(AX[LI]) xor Int32(LSign)));
 end;
 
 class function TScalarUtilities.GetBitLengthPositive(ALast: Int32; const AX: TCryptoLibUInt32Array): Int32;
@@ -229,7 +229,7 @@ begin
   LI := ALast;
   while (LI > 0) and (AX[LI] = 0) do
     System.Dec(LI);
-  Result := LI * 32 + 32 - TBitUtilities.NumberOfLeadingZeros32(UInt32(AX[LI]));
+  Result := LI * 32 + 32 - TBitOperations.NumberOfLeadingZeros32(UInt32(AX[LI]));
 end;
 
 class function TScalarUtilities.LessThan(ALast: Int32; const AX: TCryptoLibUInt32Array;
@@ -269,11 +269,11 @@ begin
       Lcc_p := Lcc_p + Lp_i;
       Lcc_p := Lcc_p - Int64(ANv[LI]);
       Lp_i := UInt32(Lcc_p);
-      Lcc_p := TBitUtilities.Asr64(Lcc_p, 32);
+      Lcc_p := TBitOperations.Asr64(Lcc_p, 32);
       AP[LI] := Lp_i;
       Lcc_Nu := Lcc_Nu - Int64(Lp_i);
       ANu[LI] := UInt32(Lcc_Nu);
-      Lcc_Nu := TBitUtilities.Asr64(Lcc_Nu, 32);
+      Lcc_Nu := TBitOperations.Asr64(Lcc_Nu, 32);
       System.Inc(LI);
     end;
     Exit;
@@ -288,30 +288,30 @@ begin
     while LI <= ALast do
     begin
       Lp_i := AP[LI];
-      Lp_s := (Lp_i shl AShift) or TBitUtilities.NegativeRightShift32(Lprev_p, -AShift);
+      Lp_s := (Lp_i shl AShift) or TBitOperations.NegativeRightShift32(Lprev_p, -AShift);
       Lprev_p := Lp_i;
       Lcc_Nu := Lcc_Nu + Int64(ANu[LI]);
       Lcc_Nu := Lcc_Nu - Int64(Lp_s);
       Lnext_v := ANv[LI];
-      Lv_s := (Lnext_v shl AShift) or TBitUtilities.NegativeRightShift32(Lprev_v, -AShift);
+      Lv_s := (Lnext_v shl AShift) or TBitOperations.NegativeRightShift32(Lprev_v, -AShift);
       Lprev_v := Lnext_v;
       Lcc_p := Lcc_p + Lp_i;
       Lcc_p := Lcc_p - Int64(Lv_s);
       Lp_i := UInt32(Lcc_p);
-      Lcc_p := TBitUtilities.Asr64(Lcc_p, 32);
+      Lcc_p := TBitOperations.Asr64(Lcc_p, 32);
       AP[LI] := Lp_i;
-      Lq_s := (Lp_i shl AShift) or TBitUtilities.NegativeRightShift32(Lprev_q, -AShift);
+      Lq_s := (Lp_i shl AShift) or TBitOperations.NegativeRightShift32(Lprev_q, -AShift);
       Lprev_q := Lp_i;
       Lcc_Nu := Lcc_Nu - Int64(Lq_s);
       ANu[LI] := UInt32(Lcc_Nu);
-      Lcc_Nu := TBitUtilities.Asr64(Lcc_Nu, 32);
+      Lcc_Nu := TBitOperations.Asr64(Lcc_Nu, 32);
       System.Inc(LI);
     end;
     Exit;
   end;
 
   System.Move(AP[0], AT[0], ALast * System.SizeOf(UInt32));
-  LsWords := TBitUtilities.Asr32(AShift, 5);
+  LsWords := TBitOperations.Asr32(AShift, 5);
   LsBits := AShift and 31;
 
   if LsBits = 0 then
@@ -324,10 +324,10 @@ begin
       Lcc_p := Lcc_p + Int64(AP[LI]);
       Lcc_p := Lcc_p - Int64(ANv[LI - LsWords]);
       AP[LI] := UInt32(Lcc_p);
-      Lcc_p := TBitUtilities.Asr64(Lcc_p, 32);
+      Lcc_p := TBitOperations.Asr64(Lcc_p, 32);
       Lcc_Nu := Lcc_Nu - Int64(AP[LI - LsWords]);
       ANu[LI] := UInt32(Lcc_Nu);
-      Lcc_Nu := TBitUtilities.Asr64(Lcc_Nu, 32);
+      Lcc_Nu := TBitOperations.Asr64(Lcc_Nu, 32);
       System.Inc(LI);
     end;
     Exit;
@@ -340,23 +340,23 @@ begin
   while LI <= ALast do
   begin
     Lnext_t := AT[LI - LsWords];
-    Lt_s := (Lnext_t shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_t, -LsBits);
+    Lt_s := (Lnext_t shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_t, -LsBits);
     Lprev_t := Lnext_t;
     Lcc_Nu := Lcc_Nu + Int64(ANu[LI]);
     Lcc_Nu := Lcc_Nu - Int64(Lt_s);
     Lnext_v := ANv[LI - LsWords];
-    Lv_s := (Lnext_v shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_v, -LsBits);
+    Lv_s := (Lnext_v shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_v, -LsBits);
     Lprev_v := Lnext_v;
     Lcc_p := Lcc_p + Int64(AP[LI]);
     Lcc_p := Lcc_p - Int64(Lv_s);
     AP[LI] := UInt32(Lcc_p);
-    Lcc_p := TBitUtilities.Asr64(Lcc_p, 32);
+    Lcc_p := TBitOperations.Asr64(Lcc_p, 32);
     Lnext_q := AP[LI - LsWords];
-    Lq_s := (Lnext_q shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_q, -LsBits);
+    Lq_s := (Lnext_q shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_q, -LsBits);
     Lprev_q := Lnext_q;
     Lcc_Nu := Lcc_Nu - Int64(Lq_s);
     ANu[LI] := UInt32(Lcc_Nu);
-    Lcc_Nu := TBitUtilities.Asr64(Lcc_Nu, 32);
+    Lcc_Nu := TBitOperations.Asr64(Lcc_Nu, 32);
     System.Inc(LI);
   end;
 end;
@@ -368,7 +368,7 @@ var
   Lnext_v0, Lnext_v1, Lv0_s, Lv1_s: UInt32;
   Lprev_v0, Lprev_v1: UInt32;
 begin
-  LsWords := TBitUtilities.Asr32(AShift, 5);
+  LsWords := TBitOperations.Asr32(AShift, 5);
   LsBits := AShift and 31;
   Lcc_u0 := 0;
   Lcc_u1 := 0;
@@ -383,9 +383,9 @@ begin
       Lcc_u0 := Lcc_u0 - AV0[LI - LsWords];
       Lcc_u1 := Lcc_u1 - AV1[LI - LsWords];
       AU0[LI] := UInt32(Lcc_u0);
-      Lcc_u0 := TBitUtilities.Asr64(Lcc_u0, 32);
+      Lcc_u0 := TBitOperations.Asr64(Lcc_u0, 32);
       AU1[LI] := UInt32(Lcc_u1);
-      Lcc_u1 := TBitUtilities.Asr64(Lcc_u1, 32);
+      Lcc_u1 := TBitOperations.Asr64(Lcc_u1, 32);
       System.Inc(LI);
     end;
     Exit;
@@ -398,8 +398,8 @@ begin
   begin
     Lnext_v0 := AV0[LI - LsWords];
     Lnext_v1 := AV1[LI - LsWords];
-    Lv0_s := (Lnext_v0 shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_v0, -LsBits);
-    Lv1_s := (Lnext_v1 shl LsBits) or TBitUtilities.NegativeRightShift32(Lprev_v1, -LsBits);
+    Lv0_s := (Lnext_v0 shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_v0, -LsBits);
+    Lv1_s := (Lnext_v1 shl LsBits) or TBitOperations.NegativeRightShift32(Lprev_v1, -LsBits);
     Lprev_v0 := Lnext_v0;
     Lprev_v1 := Lnext_v1;
     Lcc_u0 := Lcc_u0 + AU0[LI];
@@ -407,9 +407,9 @@ begin
     Lcc_u0 := Lcc_u0 - Int64(Lv0_s);
     Lcc_u1 := Lcc_u1 - Int64(Lv1_s);
     AU0[LI] := UInt32(Lcc_u0);
-    Lcc_u0 := TBitUtilities.Asr64(Lcc_u0, 32);
+    Lcc_u0 := TBitOperations.Asr64(Lcc_u0, 32);
     AU1[LI] := UInt32(Lcc_u1);
-    Lcc_u1 := TBitUtilities.Asr64(Lcc_u1, 32);
+    Lcc_u1 := TBitOperations.Asr64(Lcc_u1, 32);
     System.Inc(LI);
   end;
 end;

+ 5 - 5
CryptoLib/src/Math/EC/Rfc8032/ClpWnaf.pas

@@ -22,7 +22,7 @@ unit ClpWnaf;
 interface
 
 uses
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -77,22 +77,22 @@ begin
     while LJ < 16 do
     begin
       LWord16 := Int32(UInt32(LWord) shr (UInt32(LJ) and 31));
-      LSkip := TBitUtilities.NumberOfTrailingZeros32(UInt32((LSign xor LWord16) or (1 shl 16)));
+      LSkip := TBitOperations.NumberOfTrailingZeros32(UInt32((LSign xor LWord16) or (1 shl 16)));
       if LSkip > 0 then
       begin
         LJ := LJ + LSkip;
         continue;
       end;
       LDigit := (LWord16 or 1) shl LLead;
-      LSign := TBitUtilities.Asr32(LDigit, 31);
-      AWs[(LI shl 4) + LJ] := ShortInt(TBitUtilities.Asr32(LDigit, LLead));
+      LSign := TBitOperations.Asr32(LDigit, 31);
+      AWs[(LI shl 4) + LJ] := ShortInt(TBitOperations.Asr32(LDigit, LLead));
       LJ := LJ + AWidth;
     end;
     LJ := LJ - 16;
     System.Inc(LI);
   end;
   {$IFDEF DEBUG}
-  System.Assert(LSign = TBitUtilities.Asr32(Int32(AN[System.High(AN)]), 31));
+  System.Assert(LSign = TBitOperations.Asr32(Int32(AN[System.High(AN)]), 31));
   {$ENDIF}
 end;
 

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

@@ -22,7 +22,7 @@ unit ClpGenericPolynomialExtensionField;
 interface
 
 uses
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpIFiniteField,
   ClpIPolynomial,
@@ -116,7 +116,7 @@ function TGenericPolynomialExtensionField.GetHashCode: {$IFDEF DELPHI}Int32;
 {$ELSE}PtrInt; {$ENDIF DELPHI}
 begin
   Result := (subfield as TObject).GetHashCode()
-    xor Int32(TBitUtilities.RotateLeft32((MinimalPolynomial as TObject)
+    xor Int32(TBitOperations.RotateLeft32((MinimalPolynomial as TObject)
     .GetHashCode(), 16));
 end;
 

+ 41 - 41
CryptoLib/src/Math/Raw/ClpMod.pas

@@ -27,7 +27,7 @@ uses
   ClpISecureRandom,
   ClpPack,
   ClpNat,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -164,7 +164,7 @@ begin
   System.Assert(AM[LLen32 - 1] <> 0);
   {$ENDIF}
 
-  LBits := (LLen32 shl 5) - TBitUtilities.NumberOfLeadingZeros32(AM[LLen32 - 1]);
+  LBits := (LLen32 shl 5) - TBitOperations.NumberOfLeadingZeros32(AM[LLen32 - 1]);
   LLen30 := (LBits + 29) div 30;
 
   SetLength(LT, 4);
@@ -193,7 +193,7 @@ begin
     Inc(LDivSteps, 30);
   end;
 
-  LSignF := TBitUtilities.Asr32(LF[LLen30 - 1], 31);
+  LSignF := TBitOperations.Asr32(LF[LLen30 - 1], 31);
   CNegate30(LLen30, LSignF, LF);
 
   CNormalize30(LLen30, LSignF, LD, LM);
@@ -223,7 +223,7 @@ begin
   System.Assert(AM[LLen32 - 1] <> 0);
   {$ENDIF}
 
-  LBits := (LLen32 shl 5) - TBitUtilities.NumberOfLeadingZeros32(AM[LLen32 - 1]);
+  LBits := (LLen32 shl 5) - TBitOperations.NumberOfLeadingZeros32(AM[LLen32 - 1]);
   LLen30 := (LBits + 29) div 30;
 
   LClz := LBits - TNat.GetBitLength(LLen32, AX);
@@ -265,10 +265,10 @@ begin
     LLenFG := TrimFG30Var(LLenFG, LF, LG);
   end;
 
-  LSignF := TBitUtilities.Asr32(LF[LLenFG - 1], 31);
+  LSignF := TBitOperations.Asr32(LF[LLenFG - 1], 31);
 
   // D is in the range (-2.M, M) ...
-  LSignD := TBitUtilities.Asr32(LD[LLenDE - 1], 31);
+  LSignD := TBitOperations.Asr32(LD[LLenDE - 1], 31);
   if LSignD < 0 then
     LSignD := Add30(LLenDE, LD, LM);
 
@@ -314,7 +314,7 @@ begin
   System.Assert(AM[LLen32 - 1] <> 0);
   {$ENDIF}
 
-  LBits := (LLen32 shl 5) - TBitUtilities.NumberOfLeadingZeros32(AM[LLen32 - 1]);
+  LBits := (LLen32 shl 5) - TBitOperations.NumberOfLeadingZeros32(AM[LLen32 - 1]);
   LLen30 := (LBits + 29) div 30;
 
   SetLength(LT, 4);
@@ -337,7 +337,7 @@ begin
     Inc(LDivSteps, 30);
   end;
 
-  LSignF := TBitUtilities.Asr32(LF[LLen30 - 1], 31);
+  LSignF := TBitOperations.Asr32(LF[LLen30 - 1], 31);
   CNegate30(LLen30, LSignF, LF);
 
   Result := UInt32(EqualTo(LLen30, LF, 1) and EqualTo(LLen30, LG, 0));
@@ -356,7 +356,7 @@ begin
   System.Assert(AM[LLen32 - 1] <> 0);
   {$ENDIF}
 
-  LBits := (LLen32 shl 5) - TBitUtilities.NumberOfLeadingZeros32(AM[LLen32 - 1]);
+  LBits := (LLen32 shl 5) - TBitOperations.NumberOfLeadingZeros32(AM[LLen32 - 1]);
   LLen30 := (LBits + 29) div 30;
 
   LClz := LBits - TNat.GetBitLength(LLen32, AX);
@@ -392,7 +392,7 @@ begin
     LLenFG := TrimFG30Var(LLenFG, LF, LG);
   end;
 
-  LSignF := TBitUtilities.Asr32(LF[LLenFG - 1], 31);
+  LSignF := TBitOperations.Asr32(LF[LLenFG - 1], 31);
   if LSignF < 0 then
   begin
     LSignF := Negate30(LLenFG, LF);
@@ -452,12 +452,12 @@ begin
   begin
     LC := LC + AD[LI] + AM[LI];
     AD[LI] := LC and M30;
-    LC := TBitUtilities.Asr32(LC, 30);
+    LC := TBitOperations.Asr32(LC, 30);
   end;
 
   LC := LC + AD[LLast] + AM[LLast];
   AD[LLast] := LC;
-  LC := TBitUtilities.Asr32(LC, 30);
+  LC := TBitOperations.Asr32(LC, 30);
   Result := LC;
 end;
 
@@ -477,7 +477,7 @@ begin
   begin
     LC := LC + ((AD[LI] xor ACond) - ACond);
     AD[LI] := LC and M30;
-    LC := TBitUtilities.Asr32(LC, 30);
+    LC := TBitOperations.Asr32(LC, 30);
   end;
 
   LC := LC + ((AD[LLast] xor ACond) - ACond);
@@ -500,14 +500,14 @@ begin
 
   begin
     LC := 0;
-    LCondAdd := TBitUtilities.Asr32(AD[LLast], 31);
+    LCondAdd := TBitOperations.Asr32(AD[LLast], 31);
     for LI := 0 to LLast - 1 do
     begin
       LDi := AD[LI] + (AM[LI] and LCondAdd);
       LDi := (LDi xor ACondNegate) - ACondNegate;
       LC := LC + LDi;
       AD[LI] := LC and M30;
-      LC := TBitUtilities.Asr32(LC, 30);
+      LC := TBitOperations.Asr32(LC, 30);
     end;
 
     LDi := AD[LLast] + (AM[LLast] and LCondAdd);
@@ -518,13 +518,13 @@ begin
 
   begin
     LC := 0;
-    LCondAdd := TBitUtilities.Asr32(AD[LLast], 31);
+    LCondAdd := TBitOperations.Asr32(AD[LLast], 31);
     for LI := 0 to LLast - 1 do
     begin
       LDi := AD[LI] + (AM[LI] and LCondAdd);
       LC := LC + LDi;
       AD[LI] := LC and M30;
-      LC := TBitUtilities.Asr32(LC, 30);
+      LC := TBitOperations.Asr32(LC, 30);
     end;
 
     LDi := AD[LLast] + (AM[LLast] and LCondAdd);
@@ -532,7 +532,7 @@ begin
     AD[LLast] := LC;
 
     {$IFDEF DEBUG}
-    System.Assert((TBitUtilities.Asr32(LC, 30)) = 0);
+    System.Assert((TBitOperations.Asr32(LC, 30)) = 0);
     {$ENDIF}
   end;
 end;
@@ -584,9 +584,9 @@ begin
   begin
     // sentinel bit to count zeros only up to i.
     //LZeros := TBitUtilities.NumberOfTrailingZeros(UInt32(LG) or (-1 shl LI));
-    LZeros := TBitUtilities.NumberOfTrailingZeros32(UInt32(LG) or (UInt32($FFFFFFFF) shl LI));
+    LZeros := TBitOperations.NumberOfTrailingZeros32(UInt32(LG) or (UInt32($FFFFFFFF) shl LI));
 
-    LG := TBitUtilities.Asr32(LG, LZeros);
+    LG := TBitOperations.Asr32(LG, LZeros);
     LU := LU shl LZeros;
     LV := LV shl LZeros;
     AEta := AEta - LZeros;
@@ -682,7 +682,7 @@ begin
   end;
 
   LD := Int32(UInt32(LD) shr 1) or (LD and 1);
-  Result := TBitUtilities.Asr32(LD - 1, 31);
+  Result := TBitOperations.Asr32(LD - 1, 31);
 end;
 
 class function TMod.EqualToVar(ALen: Int32; const AX: TCryptoLibInt32Array; AY: Int32): Boolean;
@@ -706,7 +706,7 @@ end;
 
 class function TMod.GetMaximumHDDivsteps(ABits: Int32): Int32;
 begin
-  Result := Int32(TBitUtilities.Asr64((Int64(150964) * ABits + 99243), 16));
+  Result := Int32(TBitOperations.Asr64((Int64(150964) * ABits + 99243), 16));
 end;
 
 class function TMod.HDDivsteps30(ATheta: Int32; AF0: Int32; AG0: Int32; const AT: TCryptoLibInt32Array): Int32;
@@ -722,7 +722,7 @@ begin
 
   for LI := 0 to 29 do
   begin
-    LC1 := TBitUtilities.Asr32(ATheta, 31);
+    LC1 := TBitOperations.Asr32(ATheta, 31);
     LC2 := -(LG and 1);
 
     LX := LF xor LC1;
@@ -740,9 +740,9 @@ begin
     LU := LU + (LQ and LC3);
     LV := LV + (LR and LC3);
 
-    LG := TBitUtilities.Asr32(LG, 1);
-    LQ := TBitUtilities.Asr32(LQ, 1);
-    LR := TBitUtilities.Asr32(LR, 1);
+    LG := TBitOperations.Asr32(LG, 1);
+    LQ := TBitOperations.Asr32(LQ, 1);
+    LR := TBitOperations.Asr32(LR, 1);
   end;
 
   AT[0] := LU;
@@ -769,12 +769,12 @@ begin
   begin
     LC := LC - AD[LI];
     AD[LI] := LC and M30;
-    LC := TBitUtilities.Asr32(LC, 30);
+    LC := TBitOperations.Asr32(LC, 30);
   end;
 
   LC := LC - AD[LLast];
   AD[LLast] := LC;
-  LC := TBitUtilities.Asr32(LC, 30);
+  LC := TBitOperations.Asr32(LC, 30);
   Result := LC;
 end;
 
@@ -791,9 +791,9 @@ begin
   LFn := AF[ALen30 - 1];
   LGn := AG[ALen30 - 1];
 
-  LCond := TBitUtilities.Asr32(ALen30 - 2, 31);
-  LCond := LCond or (LFn xor (TBitUtilities.Asr32(LFn, 31)));
-  LCond := LCond or (LGn xor (TBitUtilities.Asr32(LGn, 31)));
+  LCond := TBitOperations.Asr32(ALen30 - 2, 31);
+  LCond := LCond or (LFn xor (TBitOperations.Asr32(LFn, 31)));
+  LCond := LCond or (LGn xor (TBitOperations.Asr32(LGn, 31)));
 
   if LCond = 0 then
   begin
@@ -822,8 +822,8 @@ begin
 
   LU := AT[0]; LV := AT[1]; LQ := AT[2]; LR := AT[3];
 
-  LSd := TBitUtilities.Asr32(AD[ALen30 - 1], 31);
-  LSe := TBitUtilities.Asr32(AE[ALen30 - 1], 31);
+  LSd := TBitOperations.Asr32(AD[ALen30 - 1], 31);
+  LSe := TBitOperations.Asr32(AE[ALen30 - 1], 31);
 
   LMd := (LU and LSd) + (LV and LSe);
   LMe := (LQ and LSd) + (LR and LSe);
@@ -846,8 +846,8 @@ begin
   System.Assert((Int32(LCe) and M30) = 0);
   {$ENDIF}
 
-  LCd := TBitUtilities.Asr64(LCd, 30);
-  LCe := TBitUtilities.Asr64(LCe, 30);
+  LCd := TBitOperations.Asr64(LCd, 30);
+  LCe := TBitOperations.Asr64(LCe, 30);
 
   for LI := 1 to ALen30 - 1 do
   begin
@@ -859,10 +859,10 @@ begin
     LCe := LCe + Int64(LQ) * LDi + Int64(LR) * LEi + Int64(LMi) * LMe;
 
     AD[LI - 1] := Int32(LCd) and M30;
-    LCd := TBitUtilities.Asr64(LCd, 30);
+    LCd := TBitOperations.Asr64(LCd, 30);
 
     AE[LI - 1] := Int32(LCe) and M30;
-    LCe := TBitUtilities.Asr64(LCe, 30);
+    LCe := TBitOperations.Asr64(LCe, 30);
   end;
 
   AD[ALen30 - 1] := Int32(LCd);
@@ -895,8 +895,8 @@ begin
   System.Assert((Int32(LCg) and M30) = 0);
   {$ENDIF}
 
-  LCf := TBitUtilities.Asr64(LCf, 30);
-  LCg := TBitUtilities.Asr64(LCg, 30);
+  LCf := TBitOperations.Asr64(LCf, 30);
+  LCg := TBitOperations.Asr64(LCg, 30);
 
   for LI := 1 to ALen30 - 1 do
   begin
@@ -907,10 +907,10 @@ begin
     LCg := LCg + Int64(LQ) * LFi + Int64(LR) * LGi;
 
     AF[LI - 1] := Int32(LCf) and M30;
-    LCf := TBitUtilities.Asr64(LCf, 30);
+    LCf := TBitOperations.Asr64(LCf, 30);
 
     AG[LI - 1] := Int32(LCg) and M30;
-    LCg := TBitUtilities.Asr64(LCg, 30);
+    LCg := TBitOperations.Asr64(LCg, 30);
   end;
 
   AF[ALen30 - 1] := Int32(LCf);

+ 96 - 96
CryptoLib/src/Math/Raw/ClpNat.pas

@@ -25,7 +25,7 @@ uses
   SysUtils,
   ClpArrayUtilities,
   ClpPack,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpCryptoLibTypes;
 
@@ -683,7 +683,7 @@ begin
   begin
     LC := LC + (AX[LI] - (AY[LI] and LMASK));
     AZ[LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -700,7 +700,7 @@ begin
   begin
     LC := LC + (AX[AXOff + LI] - (AY[AYOff + LI] and LMASK));
     AZ[AZOff + LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -806,7 +806,7 @@ begin
     LD := LD or (AX[AXOff + LI]);
   end;
   LD := ((LD shr 1)) or (LD and 1);
-  Result := UInt32(TBitUtilities.Asr32(Int32(LD - 1), 31));
+  Result := UInt32(TBitOperations.Asr32(Int32(LD - 1), 31));
 end;
 
 class function TNat.EqualTo(ALen: Int32; const AX: TCryptoLibUInt32Array; AXOff: Int32; const AY: TCryptoLibUInt32Array; AYOff: Int32): UInt32;
@@ -820,7 +820,7 @@ begin
     LD := LD or (AX[AXOff + LI] xor AY[AYOff + LI]);
   end;
   LD := ((LD shr 1)) or (LD and 1);
-  Result := UInt32(TBitUtilities.Asr32(Int32(LD - 1), 31));
+  Result := UInt32(TBitOperations.Asr32(Int32(LD - 1), 31));
 end;
 
 class function TNat.EqualToZero(ALen: Int32; const AX: TCryptoLibUInt32Array; AXOff: Int32): UInt32;
@@ -834,7 +834,7 @@ begin
     LD := LD or (AX[AXOff + LI]);
   end;
   LD := ((LD shr 1)) or (LD and 1);
-  Result := UInt32(TBitUtilities.Asr32(Int32(LD - 1), 31));
+  Result := UInt32(TBitOperations.Asr32(Int32(LD - 1), 31));
 end;
 
 class function TNat.FromBigInteger(ABits: Int32; AX: TBigInteger): TCryptoLibUInt32Array;
@@ -885,7 +885,7 @@ begin
     Result := AX[0] and 1;
     Exit;
   end;
-  LW := TBitUtilities.Asr32(ABit, 5);
+  LW := TBitOperations.Asr32(ABit, 5);
   LB := ABit and 31;
   if (LW < 0) or (LW >= System.Length(AX)) then
   begin
@@ -905,7 +905,7 @@ begin
     LXI := AX[LI];
     if LXI <> 0 then
     begin
-      Result := LI * 32 + 32 - TBitUtilities.NumberOfLeadingZeros32(LXI);
+      Result := LI * 32 + 32 - TBitOperations.NumberOfLeadingZeros32(LXI);
       Exit;
     end;
   end;
@@ -922,7 +922,7 @@ begin
     LXI := AX[AXOff + LI];
     if LXI <> 0 then
     begin
-      Result := LI * 32 + 32 - TBitUtilities.NumberOfLeadingZeros32(LXI);
+      Result := LI * 32 + 32 - TBitOperations.NumberOfLeadingZeros32(LXI);
       Exit;
     end;
   end;
@@ -1091,7 +1091,7 @@ begin
   for LI := 0 to ALen - 1 do
   begin
     LC := LC + (Int64(AX[LI]) - AY[LI]);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   System.Assert((LC = Int64(0)) or (LC = -Int64(1)));
   Result := Int32(LC);
@@ -1106,7 +1106,7 @@ begin
   for LI := 0 to ALen - 1 do
   begin
     LC := LC + (Int64(AX[AXOff + LI]) - Int64(AY[AYOff + LI]));
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   {$IFDEF DEBUG}
   System.Assert((LC = Int64(0)) or (LC = -Int64(1)));
@@ -1291,7 +1291,7 @@ begin
   begin
     LC := LC - (AX[LI]);
     AZ[LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -1373,10 +1373,10 @@ begin
   begin
     System.Dec(LI);
     LNext := AZ[LI];
-    AZ[LI] := ((LNext shr ABits)) or (TBitUtilities.NegativeLeftShift32(AC, -ABits));
+    AZ[LI] := ((LNext shr ABits)) or (TBitOperations.NegativeLeftShift32(AC, -ABits));
     AC := LNext;
   end;
-  Result := TBitUtilities.NegativeLeftShift32(AC, -ABits);
+  Result := TBitOperations.NegativeLeftShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftDownBits(ALen: Int32; AZ: TCryptoLibUInt32Array; AZOff: Int32; ABits: Int32; AC: UInt32): UInt32;
@@ -1392,10 +1392,10 @@ begin
   begin
     System.Dec(LI);
     LNext := AZ[AZOff + LI];
-    AZ[AZOff + LI] := ((LNext shr ABits)) or (TBitUtilities.NegativeLeftShift32(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shr ABits)) or (TBitOperations.NegativeLeftShift32(AC, -ABits));
     AC := LNext;
   end;
-  Result := TBitUtilities.NegativeLeftShift32(AC, -ABits);
+  Result := TBitOperations.NegativeLeftShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftDownBits(ALen: Int32; const AX: TCryptoLibUInt32Array; ABits: Int32; AC: UInt32; AZ: TCryptoLibUInt32Array): UInt32;
@@ -1411,10 +1411,10 @@ begin
   begin
     System.Dec(LI);
     LNext := AX[LI];
-    AZ[LI] := ((LNext shr ABits)) or (TBitUtilities.NegativeLeftShift32(AC, -ABits));
+    AZ[LI] := ((LNext shr ABits)) or (TBitOperations.NegativeLeftShift32(AC, -ABits));
     AC := LNext;
   end;
-  Result := TBitUtilities.NegativeLeftShift32(AC, -ABits);
+  Result := TBitOperations.NegativeLeftShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftDownBits(ALen: Int32; const AX: TCryptoLibUInt32Array; AXOff: Int32; ABits: Int32; AC: UInt32; AZ: TCryptoLibUInt32Array; AZOff: Int32): UInt32;
@@ -1430,10 +1430,10 @@ begin
   begin
     System.Dec(LI);
     LNext := AX[AXOff + LI];
-    AZ[AZOff + LI] := ((LNext shr ABits)) or (TBitUtilities.NegativeLeftShift32(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shr ABits)) or (TBitOperations.NegativeLeftShift32(AC, -ABits));
     AC := LNext;
   end;
-  Result := TBitUtilities.NegativeLeftShift32(AC, -ABits);
+  Result := TBitOperations.NegativeLeftShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftDownBits64(ALen: Int32; AZ: TCryptoLibUInt64Array; AZOff: Int32; ABits: Int32; AC: UInt64): UInt64;
@@ -1449,10 +1449,10 @@ begin
   begin
     System.Dec(LI);
     LNext := AZ[AZOff + LI];
-    AZ[AZOff + LI] := ((LNext shr ABits)) or (TBitUtilities.NegativeLeftShift64(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shr ABits)) or (TBitOperations.NegativeLeftShift64(AC, -ABits));
     AC := LNext;
   end;
-  Result := TBitUtilities.NegativeLeftShift64(AC, -ABits);
+  Result := TBitOperations.NegativeLeftShift64(AC, -ABits);
 end;
 
 class function TNat.ShiftDownWord(ALen: Int32; AZ: TCryptoLibUInt32Array; AC: UInt32): UInt32;
@@ -1702,21 +1702,21 @@ begin
     LNext1 := AZ[LI + 1];
     LNext2 := AZ[LI + 2];
     LNext3 := AZ[LI + 3];
-    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
-    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext0, -ABits));
-    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext1, -ABits));
-    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext2, -ABits));
+    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
+    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext0, -ABits));
+    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext1, -ABits));
+    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AZ[LI];
-    AZ[LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
+    AZ[LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift32(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits(ALen: Int32; AZ: TCryptoLibUInt32Array; AZOff: Int32; ABits: Int32; AC: UInt32): UInt32;
@@ -1740,21 +1740,21 @@ begin
     LNext1 := AZ[AZOff + LI + 1];
     LNext2 := AZ[AZOff + LI + 2];
     LNext3 := AZ[AZOff + LI + 3];
-    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
-    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext0, -ABits));
-    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext1, -ABits));
-    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext2, -ABits));
+    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
+    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext0, -ABits));
+    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext1, -ABits));
+    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AZ[AZOff + LI];
-    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift32(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits(ALen: Int32; const AX: TCryptoLibUInt32Array; ABits: Int32; AC: UInt32; AZ: TCryptoLibUInt32Array): UInt32;
@@ -1778,21 +1778,21 @@ begin
     LNext1 := AX[LI + 1];
     LNext2 := AX[LI + 2];
     LNext3 := AX[LI + 3];
-    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
-    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext0, -ABits));
-    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext1, -ABits));
-    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext2, -ABits));
+    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
+    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext0, -ABits));
+    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext1, -ABits));
+    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AX[LI];
-    AZ[LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
+    AZ[LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift32(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits(ALen: Int32; const AX: TCryptoLibUInt32Array; AXOff: Int32; ABits: Int32; AC: UInt32; AZ: TCryptoLibUInt32Array; AZOff: Int32): UInt32;
@@ -1816,21 +1816,21 @@ begin
     LNext1 := AX[AXOff + LI + 1];
     LNext2 := AX[AXOff + LI + 2];
     LNext3 := AX[AXOff + LI + 3];
-    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
-    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext0, -ABits));
-    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext1, -ABits));
-    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift32(LNext2, -ABits));
+    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
+    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext0, -ABits));
+    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext1, -ABits));
+    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift32(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AX[AXOff + LI];
-    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift32(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift32(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift32(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift32(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits64(ALen: Int32; AZ: TCryptoLibUInt64Array; ABits: Int32; AC: UInt64): UInt64;
@@ -1854,21 +1854,21 @@ begin
     LNext1 := AZ[LI + 1];
     LNext2 := AZ[LI + 2];
     LNext3 := AZ[LI + 3];
-    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
-    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext0, -ABits));
-    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext1, -ABits));
-    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext2, -ABits));
+    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
+    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext0, -ABits));
+    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext1, -ABits));
+    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AZ[LI];
-    AZ[LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
+    AZ[LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift64(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift64(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits64(ALen: Int32; AZ: TCryptoLibUInt64Array; AZOff: Int32; ABits: Int32; AC: UInt64): UInt64;
@@ -1892,21 +1892,21 @@ begin
     LNext1 := AZ[AZOff + LI + 1];
     LNext2 := AZ[AZOff + LI + 2];
     LNext3 := AZ[AZOff + LI + 3];
-    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
-    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext0, -ABits));
-    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext1, -ABits));
-    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext2, -ABits));
+    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
+    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext0, -ABits));
+    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext1, -ABits));
+    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AZ[AZOff + LI];
-    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift64(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift64(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits64(ALen: Int32; const AX: TCryptoLibUInt64Array; ABits: Int32; AC: UInt64; AZ: TCryptoLibUInt64Array): UInt64;
@@ -1930,21 +1930,21 @@ begin
     LNext1 := AX[LI + 1];
     LNext2 := AX[LI + 2];
     LNext3 := AX[LI + 3];
-    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
-    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext0, -ABits));
-    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext1, -ABits));
-    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext2, -ABits));
+    AZ[LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
+    AZ[LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext0, -ABits));
+    AZ[LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext1, -ABits));
+    AZ[LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AX[LI];
-    AZ[LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
+    AZ[LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift64(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift64(AC, -ABits);
 end;
 
 class function TNat.ShiftUpBits64(ALen: Int32; const AX: TCryptoLibUInt64Array; AXOff: Int32; ABits: Int32; AC: UInt64; AZ: TCryptoLibUInt64Array; AZOff: Int32): UInt64;
@@ -1968,21 +1968,21 @@ begin
     LNext1 := AX[AXOff + LI + 1];
     LNext2 := AX[AXOff + LI + 2];
     LNext3 := AX[AXOff + LI + 3];
-    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
-    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext0, -ABits));
-    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext1, -ABits));
-    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitUtilities.NegativeRightShift64(LNext2, -ABits));
+    AZ[AZOff + LI + 0] := ((LNext0 shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
+    AZ[AZOff + LI + 1] := ((LNext1 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext0, -ABits));
+    AZ[AZOff + LI + 2] := ((LNext2 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext1, -ABits));
+    AZ[AZOff + LI + 3] := ((LNext3 shl ABits)) or (TBitOperations.NegativeRightShift64(LNext2, -ABits));
     AC := LNext3;
     LI := LI + 4;
   end;
   while LI < ALen do
   begin
     LNext := AX[AXOff + LI];
-    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitUtilities.NegativeRightShift64(AC, -ABits));
+    AZ[AZOff + LI] := ((LNext shl ABits)) or (TBitOperations.NegativeRightShift64(AC, -ABits));
     AC := LNext;
     System.Inc(LI);
   end;
-  Result := TBitUtilities.NegativeRightShift64(AC, -ABits);
+  Result := TBitOperations.NegativeRightShift64(AC, -ABits);
 end;
 
 class procedure TNat.Square(ALen: Int32; const AX: TCryptoLibUInt32Array; AZz: TCryptoLibUInt32Array);
@@ -2148,7 +2148,7 @@ begin
   begin
     LC := LC + (Int64(AX[LI]) - Int64(AY[LI]));
     AZ[LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -2163,7 +2163,7 @@ begin
   begin
     LC := LC + (Int64(AX[AXOff + LI]) - Int64(AY[AYOff + LI]));
     AZ[AZOff + LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -2177,10 +2177,10 @@ begin
   System.Assert(AZPos <= (ALen - 2));
   {$ENDIF}
   AZ[AZPos + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZPos + 1] - 1));
   AZ[AZPos + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2200,10 +2200,10 @@ begin
   System.Assert(AZPos <= (ALen - 2));
   {$ENDIF}
   AZ[AZOff + AZPos] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + AZPos + 1] - 1));
   AZ[AZOff + AZPos + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2220,10 +2220,10 @@ var
 begin
   LC := Int64(AZ[0] - AX);
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1] - 1));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2240,10 +2240,10 @@ var
 begin
   LC := Int64(AZ[AZOff + 0] - AX);
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 1] - 1));
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2264,7 +2264,7 @@ begin
   begin
     LC := LC + (Int64(AZ[LI]) - Int64(AX[LI]) - Int64(AY[LI]));
     AZ[LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -2279,7 +2279,7 @@ begin
   begin
     LC := LC + (Int64(AZ[AZOff + LI]) - Int64(AX[AXOff + LI]) - Int64(AY[AYOff + LI]));
     AZ[AZOff + LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -2293,10 +2293,10 @@ begin
   System.Assert(AZPos <= (ALen - 2));
   {$ENDIF}
   AZ[AZPos + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (AZ[AZPos + 1] - Int64(AX shr 32));
   AZ[AZPos + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2316,10 +2316,10 @@ begin
   System.Assert(AZPos <= (ALen - 2));
   {$ENDIF}
   AZ[AZOff + AZPos] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (AZ[AZOff + AZPos + 1] - Int64(AX shr 32));
   AZ[AZOff + AZPos + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2336,10 +2336,10 @@ var
 begin
   LC := AZ[0] - Int64(AX and M);
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (AZ[1] - Int64(AX shr 32));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2356,10 +2356,10 @@ var
 begin
   LC := AZ[AZOff + 0] - Int64(AX and M);
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (AZ[AZOff + 1] - Int64(AX shr 32));
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2380,7 +2380,7 @@ begin
   begin
     LC := LC + (Int64(AZ[LI]) - Int64(AX[LI]));
     AZ[LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -2395,7 +2395,7 @@ begin
   begin
     LC := LC + (Int64(AZ[AZOff + LI]) - Int64(AX[AXOff + LI]));
     AZ[AZOff + LI] := UInt32(LC);
-    LC := TBitUtilities.Asr64(LC, 32);
+    LC := TBitOperations.Asr64(LC, 32);
   end;
   Result := Int32(LC);
 end;
@@ -2409,7 +2409,7 @@ begin
   System.Assert(AZPos <= (ALen - 1));
   {$ENDIF}
   AZ[AZPos] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2429,7 +2429,7 @@ begin
   System.Assert(AZPos <= (ALen - 1));
   {$ENDIF}
   AZ[AZOff + AZPos] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2446,7 +2446,7 @@ var
 begin
   LC := Int64(AZ[0] - AX);
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;
@@ -2463,7 +2463,7 @@ var
 begin
   LC := Int64(AZ[AZOff + 0] - AX);
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   if (LC = 0) then
   begin
     Result := 0;

+ 22 - 22
CryptoLib/src/Math/Raw/ClpNat128.pas

@@ -23,7 +23,7 @@ interface
 
 uses
   SysUtils,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpArrayUtilities,
   ClpBigInteger,
   ClpPack,
@@ -325,7 +325,7 @@ begin
     Exit;
   end;
 
-  LW := TBitUtilities.Asr32(ABit, 5);
+  LW := TBitOperations.Asr32(ABit, 5);
 
   LB := ABit and 31;
   Result := (AX[LW] shr LB) and 1;
@@ -977,16 +977,16 @@ begin
   LC := 0;
   LC := LC + Int64(AX[0]) - AY[0];
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[1]) - AY[1];
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[2]) - AY[2];
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[3]) - AY[3];
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -998,16 +998,16 @@ begin
   LC := 0;
   LC := LC + Int64(AX[AXOff + 0]) - AY[AYOff + 0];
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 1]) - AY[AYOff + 1];
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 2]) - AY[AYOff + 2];
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 3]) - AY[AYOff + 3];
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1018,16 +1018,16 @@ begin
   LC := 0;
   LC := LC + Int64(AZ[0]) - AX[0] - AY[0];
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[1]) - AX[1] - AY[1];
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[2]) - AX[2] - AY[2];
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[3]) - AX[3] - AY[3];
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1038,16 +1038,16 @@ begin
   LC := 0;
   LC := LC + Int64(AZ[0]) - AX[0];
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[1]) - AX[1];
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[2]) - AX[2];
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[3]) - AX[3];
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1058,16 +1058,16 @@ begin
   LC := 0;
   LC := LC + Int64(AZ[AZOff + 0]) - AX[AXOff + 0];
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 1]) - AX[AXOff + 1];
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 2]) - AX[AXOff + 2];
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 3]) - AX[AXOff + 3];
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 

+ 27 - 27
CryptoLib/src/Math/Raw/ClpNat160.pas

@@ -24,7 +24,7 @@ interface
 uses
   SysUtils,
   ClpArrayUtilities,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBigInteger,
   ClpPack,
   ClpNat,
@@ -290,7 +290,7 @@ begin
     Exit;
   end;
 
-  LW := TBitUtilities.Asr32(ABit, 5);
+  LW := TBitOperations.Asr32(ABit, 5);
   if (LW < 0) or (LW >= 5) then
   begin
     Result := 0;
@@ -1007,19 +1007,19 @@ begin
   LC := 0;
   LC := LC + Int64(AX[0]) - AY[0];
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[1]) - AY[1];
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[2]) - AY[2];
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[3]) - AY[3];
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[4]) - AY[4];
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1031,19 +1031,19 @@ begin
   LC := 0;
   LC := LC + Int64(AX[AXOff + 0]) - AY[AYOff + 0];
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 1]) - AY[AYOff + 1];
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 2]) - AY[AYOff + 2];
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 3]) - AY[AYOff + 3];
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AX[AXOff + 4]) - AY[AYOff + 4];
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1054,19 +1054,19 @@ begin
   LC := 0;
   LC := LC + Int64(AZ[0]) - AX[0] - AY[0];
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[1]) - AX[1] - AY[1];
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[2]) - AX[2] - AY[2];
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[3]) - AX[3] - AY[3];
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[4]) - AX[4] - AY[4];
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1077,19 +1077,19 @@ begin
   LC := 0;
   LC := LC + Int64(AZ[0]) - AX[0];
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[1]) - AX[1];
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[2]) - AX[2];
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[3]) - AX[3];
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[4]) - AX[4];
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1100,19 +1100,19 @@ begin
   LC := 0;
   LC := LC + Int64(AZ[AZOff + 0]) - AX[AXOff + 0];
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 1]) - AX[AXOff + 1];
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 2]) - AX[AXOff + 2];
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 3]) - AX[AXOff + 3];
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + Int64(AZ[AZOff + 4]) - AX[AXOff + 4];
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 

+ 32 - 32
CryptoLib/src/Math/Raw/ClpNat192.pas

@@ -27,7 +27,7 @@ uses
   ClpNat,
   ClpPack,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -313,7 +313,7 @@ begin
     Result := AX[0] and 1;
     Exit;
   end;
-  LW := TBitUtilities.Asr32(ABit, 5);
+  LW := TBitOperations.Asr32(ABit, 5);
   if (LW < 0) or (LW >= 6) then
   begin
     Result := 0;
@@ -1089,22 +1089,22 @@ begin
   LC := 0;
   LC := LC + (Int64(AX[0]) - Int64(AY[0]));
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[1]) - Int64(AY[1]));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[2]) - Int64(AY[2]));
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[3]) - Int64(AY[3]));
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[4]) - Int64(AY[4]));
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[5]) - Int64(AY[5]));
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1115,22 +1115,22 @@ begin
   LC := 0;
   LC := LC + (Int64(AX[AXOff + 0]) - Int64(AY[AYOff + 0]));
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 1]) - Int64(AY[AYOff + 1]));
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 2]) - Int64(AY[AYOff + 2]));
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 3]) - Int64(AY[AYOff + 3]));
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 4]) - Int64(AY[AYOff + 4]));
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 5]) - Int64(AY[AYOff + 5]));
   AZ[AZOff + 5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1141,22 +1141,22 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[0]) - Int64(AX[0]) - Int64(AY[0]));
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1]) - Int64(AX[1]) - Int64(AY[1]));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[2]) - Int64(AX[2]) - Int64(AY[2]));
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[3]) - Int64(AX[3]) - Int64(AY[3]));
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[4]) - Int64(AX[4]) - Int64(AY[4]));
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[5]) - Int64(AX[5]) - Int64(AY[5]));
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1167,22 +1167,22 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[0]) - Int64(AX[0]));
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1]) - Int64(AX[1]));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[2]) - Int64(AX[2]));
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[3]) - Int64(AX[3]));
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[4]) - Int64(AX[4]));
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[5]) - Int64(AX[5]));
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1193,22 +1193,22 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[AZOff + 0]) - Int64(AX[AXOff + 0]));
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 1]) - Int64(AX[AXOff + 1]));
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 2]) - Int64(AX[AXOff + 2]));
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 3]) - Int64(AX[AXOff + 3]));
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 4]) - Int64(AX[AXOff + 4]));
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 5]) - Int64(AX[AXOff + 5]));
   AZ[AZOff + 5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 

+ 37 - 37
CryptoLib/src/Math/Raw/ClpNat224.pas

@@ -27,7 +27,7 @@ uses
   ClpPack,
   ClpBigInteger,
   ClpArrayUtilities,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -347,7 +347,7 @@ begin
     Result := AX[0] and 1;
     Exit;
   end;
-  LW := TBitUtilities.Asr32(ABit, 5);
+  LW := TBitOperations.Asr32(ABit, 5);
   if (LW < 0) or (LW >= 7) then
   begin
     Result := 0;
@@ -1245,25 +1245,25 @@ begin
   LC := 0;
   LC := LC + (Int64(AX[0]) - Int64(AY[0]));
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[1]) - Int64(AY[1]));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[2]) - Int64(AY[2]));
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[3]) - Int64(AY[3]));
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[4]) - Int64(AY[4]));
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[5]) - Int64(AY[5]));
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[6]) - Int64(AY[6]));
   AZ[6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1274,25 +1274,25 @@ begin
   LC := 0;
   LC := LC + (Int64(AX[AXOff + 0]) - Int64(AY[AYOff + 0]));
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 1]) - Int64(AY[AYOff + 1]));
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 2]) - Int64(AY[AYOff + 2]));
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 3]) - Int64(AY[AYOff + 3]));
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 4]) - Int64(AY[AYOff + 4]));
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 5]) - Int64(AY[AYOff + 5]));
   AZ[AZOff + 5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 6]) - Int64(AY[AYOff + 6]));
   AZ[AZOff + 6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1303,25 +1303,25 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[0]) - Int64(AX[0]) - Int64(AY[0]));
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1]) - Int64(AX[1]) - Int64(AY[1]));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[2]) - Int64(AX[2]) - Int64(AY[2]));
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[3]) - Int64(AX[3]) - Int64(AY[3]));
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[4]) - Int64(AX[4]) - Int64(AY[4]));
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[5]) - Int64(AX[5]) - Int64(AY[5]));
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[6]) - Int64(AX[6]) - Int64(AY[6]));
   AZ[6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1332,25 +1332,25 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[0]) - Int64(AX[0]));
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1]) - Int64(AX[1]));
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[2]) - Int64(AX[2]));
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[3]) - Int64(AX[3]));
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[4]) - Int64(AX[4]));
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[5]) - Int64(AX[5]));
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[6]) - Int64(AX[6]));
   AZ[6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1361,25 +1361,25 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[AZOff + 0]) - Int64(AX[AXOff + 0]));
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 1]) - Int64(AX[AXOff + 1]));
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 2]) - Int64(AX[AXOff + 2]));
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 3]) - Int64(AX[AXOff + 3]));
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 4]) - Int64(AX[AXOff + 4]));
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 5]) - Int64(AX[AXOff + 5]));
   AZ[AZOff + 5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 6]) - Int64(AX[AXOff + 6]));
   AZ[AZOff + 6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 

+ 42 - 42
CryptoLib/src/Math/Raw/ClpNat256.pas

@@ -27,7 +27,7 @@ uses
   ClpNat,
   ClpPack,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type
@@ -425,7 +425,7 @@ begin
     Result := 0;
     Exit;
   end;
-  LW := TBitUtilities.Asr32(ABit, 5);
+  LW := TBitOperations.Asr32(ABit, 5);
   LB := ABit and 31;
   Result := (AX[LW] shr LB) and 1;
 end;
@@ -1542,28 +1542,28 @@ begin
   LC := 0;
   LC := LC + (Int64(AX[0]) - AY[0]);
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[1]) - AY[1]);
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[2]) - AY[2]);
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[3]) - AY[3]);
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[4]) - AY[4]);
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[5]) - AY[5]);
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[6]) - AY[6]);
   AZ[6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[7]) - AY[7]);
   AZ[7] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1574,28 +1574,28 @@ begin
   LC := 0;
   LC := LC + (Int64(AX[AXOff + 0]) - AY[AYOff + 0]);
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 1]) - AY[AYOff + 1]);
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 2]) - AY[AYOff + 2]);
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 3]) - AY[AYOff + 3]);
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 4]) - AY[AYOff + 4]);
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 5]) - AY[AYOff + 5]);
   AZ[AZOff + 5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 6]) - AY[AYOff + 6]);
   AZ[AZOff + 6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AX[AXOff + 7]) - AY[AYOff + 7]);
   AZ[AZOff + 7] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1606,28 +1606,28 @@ begin
   LC := 0;
   LC := LC + (Int64(AZ[0]) - AX[0] - AY[0]);
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1]) - AX[1] - AY[1]);
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[2]) - AX[2] - AY[2]);
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[3]) - AX[3] - AY[3]);
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[4]) - AX[4] - AY[4]);
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[5]) - AX[5] - AY[5]);
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[6]) - AX[6] - AY[6]);
   AZ[6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[7]) - AX[7] - AY[7]);
   AZ[7] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1638,28 +1638,28 @@ begin
   LC := ACIn;
   LC := LC + (Int64(AZ[0]) - AX[0]);
   AZ[0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[1]) - AX[1]);
   AZ[1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[2]) - AX[2]);
   AZ[2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[3]) - AX[3]);
   AZ[3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[4]) - AX[4]);
   AZ[4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[5]) - AX[5]);
   AZ[5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[6]) - AX[6]);
   AZ[6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[7]) - AX[7]);
   AZ[7] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 
@@ -1670,28 +1670,28 @@ begin
   LC := ACIn;
   LC := LC + (Int64(AZ[AZOff + 0]) - AX[AXOff + 0]);
   AZ[AZOff + 0] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 1]) - AX[AXOff + 1]);
   AZ[AZOff + 1] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 2]) - AX[AXOff + 2]);
   AZ[AZOff + 2] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 3]) - AX[AXOff + 3]);
   AZ[AZOff + 3] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 4]) - AX[AXOff + 4]);
   AZ[AZOff + 4] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 5]) - AX[AXOff + 5]);
   AZ[AZOff + 5] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 6]) - AX[AXOff + 6]);
   AZ[AZOff + 6] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   LC := LC + (Int64(AZ[AZOff + 7]) - AX[AXOff + 7]);
   AZ[AZOff + 7] := UInt32(LC);
-  LC := TBitUtilities.Asr64(LC, 32);
+  LC := TBitOperations.Asr64(LC, 32);
   Result := Int32(LC);
 end;
 

+ 1 - 1
CryptoLib/src/Math/Raw/ClpNat320.pas

@@ -26,7 +26,7 @@ uses
   ClpNat,
   ClpPack,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type

+ 1 - 1
CryptoLib/src/Math/Raw/ClpNat384.pas

@@ -27,7 +27,7 @@ uses
   ClpNat192,
   ClpPack,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type

+ 1 - 1
CryptoLib/src/Math/Raw/ClpNat448.pas

@@ -27,7 +27,7 @@ uses
   ClpNat224,
   ClpPack,
   ClpBigInteger,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpCryptoLibTypes;
 
 type

+ 28 - 28
CryptoLib/src/Misc/ClpBitUtilities.pas → CryptoLib/src/Misc/ClpBitOperations.pas

@@ -15,14 +15,14 @@
 
 (* &&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& *)
 
-unit ClpBitUtilities;
+unit ClpBitOperations;
 
 {$I ..\Include\CryptoLib.inc}
 
 interface
 
 type
-  TBitUtilities = class sealed(TObject)
+  TBitOperations = class sealed(TObject)
 
   public
 
@@ -138,7 +138,7 @@ implementation
 
 { TBitUtilities }
 
-class function TBitUtilities.ReverseBytesInt32(AValue: Int32): Int32;
+class function TBitOperations.ReverseBytesInt32(AValue: Int32): Int32;
 {$IFNDEF FPC}
 var
   LI1, LI2, LI3, LI4: Int32;
@@ -148,15 +148,15 @@ begin
   Result := SwapEndian(AValue);
 {$ELSE}
   LI1 := AValue and $FF;
-  LI2 := TBitUtilities.Asr32(AValue, 8) and $FF;
-  LI3 := TBitUtilities.Asr32(AValue, 16) and $FF;
-  LI4 := TBitUtilities.Asr32(AValue, 24) and $FF;
+  LI2 := TBitOperations.Asr32(AValue, 8) and $FF;
+  LI3 := TBitOperations.Asr32(AValue, 16) and $FF;
+  LI4 := TBitOperations.Asr32(AValue, 24) and $FF;
 
   Result := (LI1 shl 24) or (LI2 shl 16) or (LI3 shl 8) or (LI4 shl 0);
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.ReverseBitsUInt8(AValue: UInt8): UInt8;
+class function TBitOperations.ReverseBitsUInt8(AValue: UInt8): UInt8;
 begin
   AValue := ((AValue shr 1) and $55) or ((AValue shl 1) and $AA);
   AValue := ((AValue shr 2) and $33) or ((AValue shl 2) and $CC);
@@ -164,7 +164,7 @@ begin
   Result := AValue;
 end;
 
-class function TBitUtilities.ReverseBytesUInt16(AValue: UInt16): UInt16;
+class function TBitOperations.ReverseBytesUInt16(AValue: UInt16): UInt16;
 begin
 {$IFDEF FPC}
   Result := SwapEndian(AValue);
@@ -174,7 +174,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.ReverseBytesUInt32(AValue: UInt32): UInt32;
+class function TBitOperations.ReverseBytesUInt32(AValue: UInt32): UInt32;
 begin
 {$IFDEF FPC}
   Result := SwapEndian(AValue);
@@ -185,7 +185,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.ReverseBytesUInt64(AValue: UInt64): UInt64;
+class function TBitOperations.ReverseBytesUInt64(AValue: UInt64): UInt64;
 begin
 {$IFDEF FPC}
   Result := SwapEndian(AValue);
@@ -201,7 +201,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.Asr32(AValue: Int32; AShiftBits: Byte): Int32;
+class function TBitOperations.Asr32(AValue: Int32; AShiftBits: Byte): Int32;
 begin
 {$IFDEF FPC}
   Result := SarLongInt(AValue, AShiftBits);
@@ -213,7 +213,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.Asr64(AValue: Int64; AShiftBits: Byte): Int64;
+class function TBitOperations.Asr64(AValue: Int64; AShiftBits: Byte): Int64;
 begin
 {$IFDEF FPC}
   Result := SarInt64(AValue, AShiftBits);
@@ -225,7 +225,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.NegativeLeftShift32(AValue: UInt32; AShiftBits: Int32): UInt32;
+class function TBitOperations.NegativeLeftShift32(AValue: UInt32; AShiftBits: Int32): UInt32;
 begin
 {$IFDEF DEBUG}
   System.Assert(AShiftBits < 0);
@@ -233,7 +233,7 @@ begin
   Result := AValue shl (32 + AShiftBits);
 end;
 
-class function TBitUtilities.NegativeRightShift32(AValue: UInt32; AShiftBits: Int32): UInt32;
+class function TBitOperations.NegativeRightShift32(AValue: UInt32; AShiftBits: Int32): UInt32;
 begin
 {$IFDEF DEBUG}
   System.Assert(AShiftBits < 0);
@@ -241,7 +241,7 @@ begin
   Result := AValue shr (32 + AShiftBits);
 end;
 
-class function TBitUtilities.NegativeLeftShift64(AValue: UInt64; AShiftBits: Int32): UInt64;
+class function TBitOperations.NegativeLeftShift64(AValue: UInt64; AShiftBits: Int32): UInt64;
 begin
 {$IFDEF DEBUG}
   System.Assert(AShiftBits < 0);
@@ -249,7 +249,7 @@ begin
   Result := AValue shl (64 + AShiftBits);
 end;
 
-class function TBitUtilities.NegativeRightShift64(AValue: UInt64; AShiftBits: Int32): UInt64;
+class function TBitOperations.NegativeRightShift64(AValue: UInt64; AShiftBits: Int32): UInt64;
 begin
 {$IFDEF DEBUG}
   System.Assert(AShiftBits < 0);
@@ -257,7 +257,7 @@ begin
   Result := AValue shr (64 + AShiftBits);
 end;
 
-class function TBitUtilities.RotateLeft8(AValue: Byte; AN: Int32): Byte;
+class function TBitOperations.RotateLeft8(AValue: Byte; AN: Int32): Byte;
 begin
 {$IFDEF DEBUG}
   System.Assert(AN >= 0);
@@ -272,7 +272,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.RotateLeft32(AValue: UInt32; AN: Int32): UInt32;
+class function TBitOperations.RotateLeft32(AValue: UInt32; AN: Int32): UInt32;
 begin
 {$IFDEF DEBUG}
   System.Assert(AN >= 0);
@@ -287,7 +287,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.RotateLeft64(AValue: UInt64; AN: Int32): UInt64;
+class function TBitOperations.RotateLeft64(AValue: UInt64; AN: Int32): UInt64;
 begin
 {$IFDEF DEBUG}
   System.Assert(AN >= 0);
@@ -302,7 +302,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.RotateRight8(AValue: Byte; AN: Int32): Byte;
+class function TBitOperations.RotateRight8(AValue: Byte; AN: Int32): Byte;
 begin
 {$IFDEF DEBUG}
   System.Assert(AN >= 0);
@@ -317,7 +317,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.RotateRight32(AValue: UInt32; AN: Int32): UInt32;
+class function TBitOperations.RotateRight32(AValue: UInt32; AN: Int32): UInt32;
 begin
 {$IFDEF DEBUG}
   System.Assert(AN >= 0);
@@ -332,7 +332,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.RotateRight64(AValue: UInt64; AN: Int32): UInt64;
+class function TBitOperations.RotateRight64(AValue: UInt64; AN: Int32): UInt64;
 begin
 {$IFDEF DEBUG}
   System.Assert(AN >= 0);
@@ -347,7 +347,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.NumberOfLeadingZeros32(AValue: UInt32): Int32;
+class function TBitOperations.NumberOfLeadingZeros32(AValue: UInt32): Int32;
 {$IFNDEF FPC}
 var
   LN: UInt32;
@@ -394,7 +394,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.NumberOfLeadingZeros64(AValue: UInt64): Int32;
+class function TBitOperations.NumberOfLeadingZeros64(AValue: UInt64): Int32;
 {$IFNDEF FPC}
 var
   LX: UInt32;
@@ -423,7 +423,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.NumberOfTrailingZeros32(AValue: UInt32): Int32;
+class function TBitOperations.NumberOfTrailingZeros32(AValue: UInt32): Int32;
 {$IFNDEF FPC}
 var
   LN: UInt32;
@@ -467,7 +467,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.NumberOfTrailingZeros64(AValue: UInt64): Int32;
+class function TBitOperations.NumberOfTrailingZeros64(AValue: UInt64): Int32;
 {$IFNDEF FPC}
 var
   LN: UInt32;
@@ -518,7 +518,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.PopCount32(AValue: UInt32): Int32;
+class function TBitOperations.PopCount32(AValue: UInt32): Int32;
 begin
 {$IFDEF FPC}
   Result := PopCnt(AValue);
@@ -533,7 +533,7 @@ begin
 {$ENDIF FPC}
 end;
 
-class function TBitUtilities.PopCount64(AValue: UInt64): Int32;
+class function TBitOperations.PopCount64(AValue: UInt64): Int32;
 begin
 {$IFDEF FPC}
   Result := PopCnt(AValue);

+ 7 - 7
CryptoLib/src/Misc/ClpConverters.pas

@@ -26,7 +26,7 @@ uses
   StrUtils,
   SysUtils,
   ClpCryptoLibTypes,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpBitConverter;
 
 resourcestring
@@ -156,7 +156,7 @@ begin
     ldest := PCardinal(PByte(dest) + dest_index);
     while lsrc < lend do
     begin
-      ldest^ := TBitUtilities.ReverseBytesUInt32(lsrc^);
+      ldest^ := TBitOperations.ReverseBytesUInt32(lsrc^);
       System.Inc(ldest);
       System.Inc(lsrc);
     end;
@@ -195,7 +195,7 @@ begin
     ldest := PUInt64(PByte(dest) + dest_index);
     while lsrc < lend do
     begin
-      ldest^ := TBitUtilities.ReverseBytesUInt64(lsrc^);
+      ldest^ := TBitOperations.ReverseBytesUInt64(lsrc^);
       System.Inc(ldest);
       System.Inc(lsrc);
     end;
@@ -220,7 +220,7 @@ end;
 class function TConverters.be2me_32(x: UInt32): UInt32;
 begin
   if TBitConverter.IsLittleEndian then
-    result := TBitUtilities.ReverseBytesUInt32(x)
+    result := TBitOperations.ReverseBytesUInt32(x)
   else
     result := x;
 end;
@@ -228,7 +228,7 @@ end;
 class function TConverters.be2me_64(x: UInt64): UInt64;
 begin
   if TBitConverter.IsLittleEndian then
-    result := TBitUtilities.ReverseBytesUInt64(x)
+    result := TBitOperations.ReverseBytesUInt64(x)
   else
     result := x;
 end;
@@ -256,7 +256,7 @@ end;
 class function TConverters.le2me_32(x: UInt32): UInt32;
 begin
   if not TBitConverter.IsLittleEndian then
-    result := TBitUtilities.ReverseBytesUInt32(x)
+    result := TBitOperations.ReverseBytesUInt32(x)
   else
     result := x;
 end;
@@ -264,7 +264,7 @@ end;
 class function TConverters.le2me_64(x: UInt64): UInt64;
 begin
   if not TBitConverter.IsLittleEndian then
-    result := TBitUtilities.ReverseBytesUInt64(x)
+    result := TBitOperations.ReverseBytesUInt64(x)
   else
     result := x;
 end;

+ 2 - 3
CryptoLib/src/Rngs/ClpDigestRandomGenerator.pas

@@ -24,7 +24,7 @@ interface
 uses
   SyncObjs,
   ClpIDigest,
-  ClpConverters,
+  ClpPack,
   ClpCryptoLibTypes,
   ClpIDigestRandomGenerator,
   ClpIRandomGenerator;
@@ -76,8 +76,7 @@ procedure TDigestRandomGenerator.DigestAddCounter(ASeedVal: Int64);
 var
   LBytes: TCryptoLibByteArray;
 begin
-  System.SetLength(LBytes, 8);
-  LBytes := TConverters.ReadUInt64AsBytesLE(UInt64(ASeedVal));
+  LBytes := TPack.UInt64_To_LE(UInt64(ASeedVal));
   FDigest.BlockUpdate(LBytes, 0, System.Length(LBytes));
 end;
 

+ 9 - 9
CryptoLib/src/X509/ClpX509Generators.pas

@@ -233,12 +233,12 @@ end;
 
 procedure TX509V1CertificateGenerator.SetNotBeforeUtc(const AUtcDate: TDateTime);
 begin
-  FTbsGen.SetStartDate(TTime.CreateUtc(AUtcDate) as ITime);
+  FTbsGen.SetStartDate(TTime.CreateFromUtc(AUtcDate) as ITime);
 end;
 
 procedure TX509V1CertificateGenerator.SetNotAfterUtc(const AUtcDate: TDateTime);
 begin
-  FTbsGen.SetEndDate(TTime.CreateUtc(AUtcDate) as ITime);
+  FTbsGen.SetEndDate(TTime.CreateFromUtc(AUtcDate) as ITime);
 end;
 
 procedure TX509V1CertificateGenerator.SetSubjectDN(const ASubject: IX509Name);
@@ -358,12 +358,12 @@ end;
 
 procedure TX509V3CertificateGenerator.SetNotBeforeUtc(const AUtcDate: TDateTime);
 begin
-  FTbsGen.SetStartDate(TTime.CreateUtc(AUtcDate) as ITime);
+  FTbsGen.SetStartDate(TTime.CreateFromUtc(AUtcDate) as ITime);
 end;
 
 procedure TX509V3CertificateGenerator.SetNotAfterUtc(const AUtcDate: TDateTime);
 begin
-  FTbsGen.SetEndDate(TTime.CreateUtc(AUtcDate) as ITime);
+  FTbsGen.SetEndDate(TTime.CreateFromUtc(AUtcDate) as ITime);
 end;
 
 procedure TX509V3CertificateGenerator.SetSubjectDN(const ASubject: IX509Name);
@@ -661,12 +661,12 @@ end;
 
 procedure TX509V2CrlGenerator.SetThisUpdateUtc(const AUtcDate: TDateTime);
 begin
-  FTbsGen.SetThisUpdate(TTime.CreateUtc(AUtcDate) as ITime);
+  FTbsGen.SetThisUpdate(TTime.CreateFromUtc(AUtcDate) as ITime);
 end;
 
 procedure TX509V2CrlGenerator.SetNextUpdateUtc(const AUtcDate: TDateTime);
 begin
-  FTbsGen.SetNextUpdate(TTime.CreateUtc(AUtcDate) as ITime);
+  FTbsGen.SetNextUpdate(TTime.CreateFromUtc(AUtcDate) as ITime);
 end;
 
 procedure TX509V2CrlGenerator.AddCrlEntry(const AUserCertificate: TBigInteger;
@@ -691,20 +691,20 @@ end;
 procedure TX509V2CrlGenerator.AddCrlEntryUtc(const AUserCertificate: TBigInteger;
   const ARevocationDateUtc: TDateTime; AReason: Int32);
 begin
-  FTbsGen.AddCrlEntry(TDerInteger.Create(AUserCertificate), TTime.CreateUtc(ARevocationDateUtc) as ITime, AReason);
+  FTbsGen.AddCrlEntry(TDerInteger.Create(AUserCertificate), TTime.CreateFromUtc(ARevocationDateUtc) as ITime, AReason);
 end;
 
 procedure TX509V2CrlGenerator.AddCrlEntryUtc(const AUserCertificate: TBigInteger;
   const ARevocationDateUtc: TDateTime; AReason: Int32; const AInvalidityDateUtc: TDateTime);
 begin
-  FTbsGen.AddCrlEntry(TDerInteger.Create(AUserCertificate), TTime.CreateUtc(ARevocationDateUtc) as ITime, AReason,
+  FTbsGen.AddCrlEntry(TDerInteger.Create(AUserCertificate), TTime.CreateFromUtc(ARevocationDateUtc) as ITime, AReason,
     TRfc5280Asn1Utilities.CreateGeneralizedTime(AInvalidityDateUtc));
 end;
 
 procedure TX509V2CrlGenerator.AddCrlEntryUtc(const AUserCertificate: TBigInteger;
   const ARevocationDateUtc: TDateTime; const AExtensions: IX509Extensions);
 begin
-  FTbsGen.AddCrlEntry(TDerInteger.Create(AUserCertificate), TTime.CreateUtc(ARevocationDateUtc) as ITime, AExtensions);
+  FTbsGen.AddCrlEntry(TDerInteger.Create(AUserCertificate), TTime.CreateFromUtc(ARevocationDateUtc) as ITime, AExtensions);
 end;
 
 procedure TX509V2CrlGenerator.AddCrl(const AOther: IX509Crl);

+ 2 - 2
CryptoLib/src/X509/ClpX509Utilities.pas

@@ -25,7 +25,7 @@ uses
   SysUtils,
   Classes,
   Generics.Collections,
-  ClpBitUtilities,
+  ClpBitOperations,
   ClpAsn1Objects,
   ClpIAsn1Objects,
   ClpAsn1Core,
@@ -300,7 +300,7 @@ begin
   SetLength(LBytes, LByteLen);
   for I := 0 to System.High(AId) do
     if AId[I] then
-      LBytes[TBitUtilities.Asr32(I, 3)] := LBytes[TBitUtilities.Asr32(I, 3)] or Byte(TBitUtilities.Asr32($80, (I and 7)));
+      LBytes[TBitOperations.Asr32(I, 3)] := LBytes[TBitOperations.Asr32(I, 3)] or Byte(TBitOperations.Asr32($80, (I and 7)));
   LPad := (8 - System.Length(AId)) and 7;
   Result := TDerBitString.Create(LBytes, LPad);
 end;