diff --git a/Source/DECBaseClass.pas b/Source/DECBaseClass.pas
index ea280710..5d9a79a0 100644
--- a/Source/DECBaseClass.pas
+++ b/Source/DECBaseClass.pas
@@ -16,10 +16,10 @@
*****************************************************************************}
unit DECBaseClass;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -237,7 +237,7 @@ class function TDECObject.Identity: Int64;
begin
{$IFDEF DEC52_IDENTITY}
Signature := StringOfChar(#$5A, 256 - Length(ClassName)) + UpperCase(ClassName);
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Result := CRC32(IdentityBase, Signature[Low(Signature)],
Length(Signature) * SizeOf(Signature[Low(Signature)]));
{$ELSE}
@@ -246,7 +246,7 @@ class function TDECObject.Identity: Int64;
{$IFEND}
{$ELSE !DEC52_IDENTITY}
Signature := RawByteString(StringOfChar(#$5A, 256 - Length(ClassName)) + UpperCase(ClassName));
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
Result := CRC32(IdentityBase, Signature[Low(Signature)],
Length(Signature) * SizeOf(Signature[Low(Signature)]));
{$ELSE}
diff --git a/Source/DECCRC.pas b/Source/DECCRC.pas
index 16c4a863..d2f09eeb 100644
--- a/Source/DECCRC.pas
+++ b/Source/DECCRC.pas
@@ -47,10 +47,10 @@
}
unit DECCRC;
+{$INCLUDE DECOptions.inc}
-interface
-{$INCLUDE DECOptions.inc}
+interface
type
///
diff --git a/Source/DECCipherBase.pas b/Source/DECCipherBase.pas
index 12793698..6e02f25b 100644
--- a/Source/DECCipherBase.pas
+++ b/Source/DECCipherBase.pas
@@ -15,10 +15,10 @@
under the License.
*****************************************************************************}
unit DECCipherBase;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -1003,7 +1003,7 @@ procedure TDECCipher.Init(const Key : RawByteString;
raise EDECCipherException.CreateRes(@sNoKeyMaterialGiven);
if Length(IVector) > 0 then
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
{$ELSE}
@@ -1011,7 +1011,7 @@ procedure TDECCipher.Init(const Key : RawByteString;
IVector[1], Length(IVector) * SizeOf(IVector[1]), IFiller)
{$IFEND}
else
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]), NullStr, 0, IFiller);
{$ELSE}
Init(Key[1], Length(Key) * SizeOf(Key[1]), NullStr, 0, IFiller);
@@ -1052,7 +1052,7 @@ procedure TDECCipher.Init(const Key, IVector: WideString; IFiller: Byte);
raise EDECCipherException.CreateRes(@sNoKeyMaterialGiven);
if Length(IVector) > 0 then
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
{$ELSE}
@@ -1060,7 +1060,7 @@ procedure TDECCipher.Init(const Key, IVector: WideString; IFiller: Byte);
IVector[1], Length(IVector) * SizeOf(IVector[1]), IFiller)
{$IFEND}
else
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]), NullStr, 0, IFiller);
{$ELSE}
Init(Key[1], Length(Key) * SizeOf(Key[1]), NullStr, 0, IFiller);
@@ -1098,7 +1098,7 @@ function TDECCipher.EncodeRawByteString(const Source: RawByteString; Format: TDE
SetLength(b, 0);
if Length(Source) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
SetLength(b, Length(Source) * SizeOf(Source[Low(Source)]));
DoEncode(@Source[low(Source)], @b[0], Length(Source) * SizeOf(Source[low(Source)]));
{$ELSE}
@@ -1139,7 +1139,7 @@ function TDECCipher.DecodeRawByteString(const Source: RawByteString; Format: TDE
// This has been fixed in 10.3.0 Rio
b := ValidFormat(Format).Decode(BytesOf(Source));
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
DoDecode(@b[0], @Result[Low(Result)], Length(Result) * SizeOf(Result[Low(Result)]));
{$ELSE}
DoDecode(@b[0], @Result[1], Length(Result) * SizeOf(Result[1]));
diff --git a/Source/DECCipherFormats.pas b/Source/DECCipherFormats.pas
index e4799441..de69acbb 100644
--- a/Source/DECCipherFormats.pas
+++ b/Source/DECCipherFormats.pas
@@ -15,10 +15,10 @@
under the License.
*****************************************************************************}
unit DECCipherFormats;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -845,7 +845,7 @@ function TDECFormattedCipher.EncodeStringToBytes(const Source: string;
begin
if Length(Source) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Len := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(Result, Len);
Encode(Source[low(Source)], Result[0], Len);
@@ -867,7 +867,7 @@ function TDECFormattedCipher.EncodeStringToBytes(const Source: RawByteString; Fo
begin
if Length(Source) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Len := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(Result, Len);
Encode(Source[low(Source)], Result[0], Len);
@@ -1009,7 +1009,7 @@ function TDECFormattedCipher.EncodeStringToString(const Source: string;
begin
if Length(Source) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
SourceSize := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(EncryptedBuffer, SourceSize);
Encode(Source[low(Source)], EncryptedBuffer[0], SourceSize);
@@ -1034,7 +1034,7 @@ function TDECFormattedCipher.EncodeStringToString(const Source: RawByteString;
begin
if Length(Source) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
SourceSize := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(EncryptedBuffer, SourceSize);
Encode(Source[low(Source)], EncryptedBuffer[0], SourceSize);
@@ -1046,7 +1046,7 @@ function TDECFormattedCipher.EncodeStringToString(const Source: RawByteString;
Temp := ValidFormat(Format).Encode(EncryptedBuffer);
SetLength(Result, length(Temp));
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Move(Temp[0], Result[low(Result)], length(Temp))
{$ELSE}
Move(Temp[0], Result[1], length(Temp))
@@ -1093,7 +1093,7 @@ function TDECFormattedCipher.DecodeStringToString(const Source: AnsiString;
SetLength(Result, length(Tmp));
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Move(Tmp[0], Result[low(Result)], length(Tmp))
{$ELSE}
Move(Tmp[0], Result[1], length(Tmp))
@@ -1129,7 +1129,7 @@ function TDECFormattedCipher.DecodeStringToString(const Source: RawByteString;
SetLength(Result, length(Tmp));
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Move(Tmp[0], Result[low(Result)], length(Tmp))
{$ELSE}
Move(Tmp[0], Result[1], length(Tmp))
diff --git a/Source/DECCipherModes.pas b/Source/DECCipherModes.pas
index 02d70e66..094606d1 100644
--- a/Source/DECCipherModes.pas
+++ b/Source/DECCipherModes.pas
@@ -15,10 +15,10 @@
under the License.
*****************************************************************************}
unit DECCipherModes;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -470,7 +470,7 @@ implementation
procedure TDECCipherModes.ReportInvalidMessageLength(Cipher: TDECCipher);
begin
raise EDECCipherException.CreateResFmt(@sInvalidMessageLength,
- [System.TypInfo.GetEnumName(TypeInfo(TCipherMode),
+ [GetEnumName(TypeInfo(TCipherMode),
Integer(Cipher.Mode)),
Cipher.Context.BlockSize]);
end;
@@ -740,7 +740,7 @@ procedure TDECCipherModes.InitMode;
else
// GCM requires a cipher with 128 bit block size
raise EDECCipherException.CreateResFmt(@sInvalidBlockSize,
- [128, System.TypInfo.GetEnumName(TypeInfo(TCipherMode),
+ [128, GetEnumName(TypeInfo(TCipherMode),
Integer(FMode))]);
end
else
diff --git a/Source/DECFormat.pas b/Source/DECFormat.pas
index db296fd8..5b518384 100644
--- a/Source/DECFormat.pas
+++ b/Source/DECFormat.pas
@@ -20,10 +20,10 @@
/// to data
///
unit DECFormat;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -431,7 +431,7 @@ class function TFormat_HEX.CharTableBinary: TBytes;
// special and skipped chars
// '0123456789ABCDEFX$ abcdefhHx()[]{},;:-_/\*+"'''+CHR(9)+CHR(10)+CHR(13);
- {$IF CompilerVersion >= 28.0}
+ {$IFdef HAVE_ASSIGN_ARRAY}
result := [$30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $41, $42, $43,
$44, $45, $46, $58, $24, $20, $61, $62, $63, $64, $65, $66, $68,
$48, $78, $28, $29, $5B, $5D, $7B, $7D, $2C, $3B, $3A, $2D, $5F,
@@ -597,7 +597,7 @@ class function TFormat_HEXL.CharTableBinary: TBytes;
// special and skipped chars
// '0123456789abcdefX$ ABCDEFhHx()[]{},;:-_/\*+"'''+CHR(9)+CHR(10)+CHR(13);
- {$IF CompilerVersion >= 28.0}
+ {$IFdef HAVE_ASSIGN_ARRAY}
result := [$30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $61, $62, $63,
$64, $65, $66, $68, $58, $24, $20, $41, $42, $43, $44, $45, $46,
$48, $78, $28, $29, $5B, $5D, $7B, $7D, $2C, $3B, $3A, $2D, $5F,
@@ -1113,7 +1113,7 @@ class function TFormat_UU.CharTableBinary: TBytes;
// ' '+CHR(9)+CHR(10)+CHR(13);
SetLength(result, 68);
- {$IF CompilerVersion >= 28.0}
+ {$IFdef HAVE_ASSIGN_ARRAY}
result := [$60, $21, $22, $23, $24, $25, $26, $27, $28, $29, $2A, $2B, $2C,
$2D, $2E, $2F, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39,
$3A, $3B, $3C, $3D, $3E, $3F, $40, $41, $42, $43, $44, $45, $46,
@@ -1350,7 +1350,7 @@ class function TFormat_XX.CharTableBinary: TBytes;
// '+-0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz' +
// ' "()[]'''+CHR(9)+CHR(10)+CHR(13);
SetLength(result, 74);
- {$IF CompilerVersion >= 28.0}
+ {$IFdef HAVE_ASSIGN_ARRAY}
result := [$2B, $2D, $30, $31, $32, $33, $34, $35, $36, $37, $38, $39, $41,
$42, $43, $44, $45, $46, $47, $48, $49, $4A, $4B, $4C, $4D, $4E,
$4F, $50, $51, $52, $53, $54, $55, $56, $57, $58, $59, $5A, $61,
diff --git a/Source/DECFormatBase.pas b/Source/DECFormatBase.pas
index 235f1aeb..aeb46eed 100644
--- a/Source/DECFormatBase.pas
+++ b/Source/DECFormatBase.pas
@@ -19,11 +19,10 @@
/// Contains the base class for all the formatting classes
///
unit DECFormatBase;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
-
uses
{$IFDEF FPC}
SysUtils, Classes,
@@ -451,7 +450,7 @@ class function TDECFormat.Encode(const Data: RawByteString): RawByteString;
begin
if Length(Data) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
DoEncode(Data[Low(Data)], b, Length(Data) * SizeOf(Data[Low(Data)]));
{$ELSE}
DoEncode(Data[1], b, Length(Data) * SizeOf(Data[1]));
@@ -504,7 +503,7 @@ class function TDECFormat.Decode(const Data: RawByteString): RawByteString;
begin
if Length(Data) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
DoDecode(Data[Low(Data)], b, Length(Data) * SizeOf(Data[Low(Data)]));
{$ELSE}
DoDecode(Data[1], b, Length(Data) * SizeOf(Data[1]));
@@ -553,7 +552,7 @@ class function TDECFormat.IsValid(const Data: TBytes): Boolean;
class function TDECFormat.IsValid(const Text: RawByteString): Boolean;
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Result := (Length(Text) = 0) or
(DoIsValid(Text[Low(Text)], Length(Text) * SizeOf(Text[Low(Text)])));
{$ELSE}
diff --git a/Source/DECHashAuthentication.pas b/Source/DECHashAuthentication.pas
index 91e3c2fe..4fe0ae11 100644
--- a/Source/DECHashAuthentication.pas
+++ b/Source/DECHashAuthentication.pas
@@ -19,6 +19,7 @@
/// Unit containing all the KDF, MGF, HMAC and PBKDF2 algorithms
///
unit DECHashAuthentication;
+{$INCLUDE DECOptions.inc}
interface
@@ -30,7 +31,6 @@ interface
{$ENDIF}
DECBaseClass, DECHashBase, DECHashInterface, DECTypes , DECFormatBase;
-{$INCLUDE DECOptions.inc}
type
///
@@ -912,7 +912,7 @@ TDECPasswordHash = class(TDECHashAuthentication, IDECHashPassword)
write SetSalt;
end;
- {$IF CompilerVersion < 28.0}
+ {$IFndef HAVE_ASSIGN_ARRAY}
///
/// Class helper for implementing array concatenation which is not available
/// in Delphi XE6 or lower.
@@ -1508,7 +1508,7 @@ function TDECHashExtended.CalcFile(const FileName: string; Format: TDECFormatCla
{ TArrHelper }
-{$IF CompilerVersion < 28.0}
+{$IFNDEF HAVE_ASSIGN_ARRAY}
class procedure TArrHelper.AppendArrays(var A: TArray; const B: TArray);
var
i, L: Integer;
diff --git a/Source/DECHashBase.pas b/Source/DECHashBase.pas
index c6535b11..268d43c1 100644
--- a/Source/DECHashBase.pas
+++ b/Source/DECHashBase.pas
@@ -22,10 +22,10 @@
/// to inherit from TDECHashBit
///
unit DECHashBase;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -45,14 +45,12 @@ TDECHashClass = class of TDECHash;
///
/// Base class for all hash algorithm implementation classes
///
- {$IFDEF FPC}
- TDECHash = class(TDECObject) // does not find methods of the interface as it
- // searches for AnsiString instead of RawByteString
- // and thus does not find that
- {$ELSE}
TDECHash = class(TDECObject, IDECHash)
- {$ENDIF}
+{$IFDEF FPC}
+ protected
+{$ELSE}
strict private
+{$ENDIF}
///
/// Raises an EDECHashException hash algorithm not initialized exception
///
@@ -704,7 +702,7 @@ function TDECHash.CalcString(const Value: string; Format: TDECFormatClass): stri
Result := '';
if Length(Value) > 0 then
begin
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
Size := Length(Value) * SizeOf(Value[low(Value)]);
Data := CalcBuffer(Value[low(Value)], Size);
{$ELSE}
@@ -726,7 +724,7 @@ function TDECHash.CalcString(const Value: RawByteString; Format: TDECFormatClass
begin
Result := '';
if Length(Value) > 0 then
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
result := BytesToRawString(
ValidFormat(Format).Encode(
CalcBuffer(Value[low(Value)],
diff --git a/Source/DECHashInterface.pas b/Source/DECHashInterface.pas
index 2f65ff19..ca4591e9 100644
--- a/Source/DECHashInterface.pas
+++ b/Source/DECHashInterface.pas
@@ -15,6 +15,7 @@
under the License.
*****************************************************************************}
unit DECHashInterface;
+{$INCLUDE DECOptions.inc}
interface
diff --git a/Source/DECOptions.inc b/Source/DECOptions.inc
index ebcbf002..40dd4afb 100644
--- a/Source/DECOptions.inc
+++ b/Source/DECOptions.inc
@@ -76,19 +76,29 @@
// if the compiler does not support assembler turn usage off and even if restrict
// it to Windows, as those non Windows platforms which actually do support ASM
// in Delphi do not use Intel x86 ASM
-{$IFNDEF FPC}
- {$IFNDEF ASSEMBLER}
- {$DEFINE NO_ASM} (* default ON *)
+{$IFDEF FPC }
+ {$IF defined(CPUX86_64) or defined(CPUAMD64) or defined(CPUIA64) }
+ {$ifndef CPUX64}
+ {$define CPUX64}
+ {$endif}
+ {$else}{$if defined(CPU386) or defined(CPUI386) }
+ {$ifndef CPUX32}
+ {$define CPUX32}
+ {$endif}
{$ELSE}
- {$IFDEF WINDOWS}
- {.$DEFINE NO_ASM} (* default OFF *)
- {$ELSE}
- {$DEFINE NO_ASM} (* default ON *)
- {$ENDIF}
- {$ENDIF}
+ {$IFNDEF ASSEMBLER }
+ {$DEFINE NO_ASM} (* default ON *)
+ {$ELSE}
+ {$IFDEF WINDOWS}
+ {.$DEFINE NO_ASM} (* default OFF *)
+ {$ELSE}
+ {$DEFINE NO_ASM} (* default ON *)
+ {$ENDIF}
+ {$ENDIF}
+ {$ENDIF}{$endif}
{$ELSE}
// Turn ASM off for FPC as we do not know enough about ASM support on FPC
- {$DEFINE NO_ASM} (* default ON *)
+ {$DEFINE NO_ASM}
{$ENDIF}
// Enable the following option to restore the *wrong* Identity behavior of
@@ -129,18 +139,41 @@
{$IFDEF FPC}
{$UNDEF DELPHIORBCB}
- {$DEFINE PUREPASCAL}
+ // fpc supports assembler
+ //{$DEFINE PUREPASCAL}
{$DEFINE NATIVEINT_UNDEFINED}
+ {$if FPC_FULLVERSION >=30300}
+ {$define HAVE_LAMBDAS}
+ {$endif}
// use compatibility mode
{$MODE DELPHI}
+ {$ifdef HAVE_LAMBDAS}
+ {$modeswitch functionreferences}
+ {$modeswitch anonymousfunctions}
+ {$endif}
+
+ {$define HAVE_ASSIGN_ARRAY}
// defines for Mac OS X
{$IFDEF DARWIN}
{$DEFINE MACOS}
{$DEFINE ALIGN_STACK}
{$ENDIF}
+
+ // define delphi-style CPU-width
+ {$ifdef CPU64}
+ {$define CPU64BITS}
+ {$else} {$if defined(CPU32) }
+ {$define CPU32BITS}
+ {$endif}{$endif}
+
+ {$ASMMODE intel}
+
+{$ELSE}
+ // assume delphi have "reference to" feature
+ {$define HAVE_LAMBDAS}
{$ENDIF FPC}
//------------------------------------------------------------------------------
@@ -169,13 +202,6 @@
{$ENDIF}
{$ENDIF !PUREPASCAL}
-{$IF SizeOf(Pointer) = 4}
- {$DEFINE CPU32BITS}
-{$IFEND}
-{$IF SizeOf(Pointer) = 8}
- {$DEFINE CPU64BITS}
-{$IFEND}
-
//------------------------------------------------------------------------------
// Delphi and C++ Builder
//------------------------------------------------------------------------------
@@ -190,6 +216,12 @@
{$ELSE}
Sorry, but Delphi 2007 and lower are no longer supported!
{$IFEND}
+ {$IF CompilerVersion >= 24.0}
+ {$define HAVE_STR_LIKE_ARRAY} // Deplhi provides Low(str), Hight(Str) features
+ {$endif}
+ {$IF CompilerVersion >= 28.0}
+ {$define HAVE_ASSIGN_ARRAY} // XE7+ supports result := []
+ {$endif}
{$ENDIF}
//------------------------------------------------------------------------------
diff --git a/Source/DECRandom.pas b/Source/DECRandom.pas
index 0e14ca1f..35834a03 100644
--- a/Source/DECRandom.pas
+++ b/Source/DECRandom.pas
@@ -21,10 +21,10 @@
/// initialized always using the same start value.
///
unit DECRandom;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -311,7 +311,7 @@ function RandomBytes(Size: Integer): TBytes;
function RandomRawByteString(Size: Integer): RawByteString;
begin
SetLength(Result, Size);
- {$IF CompilerVersion >= 24.0}
+ {$IFdef HAVE_STR_LIKE_ARRAY}
RandomBuffer(Result[Low(Result)], Size);
{$ELSE}
RandomBuffer(Result[1], Size);
diff --git a/Source/DECTypes.pas b/Source/DECTypes.pas
index 9786992e..b5f4e506 100644
--- a/Source/DECTypes.pas
+++ b/Source/DECTypes.pas
@@ -87,7 +87,11 @@ interface
/// Position within size in byte. For streams this may be a position
/// relative to the starting position for processing.
///
+ {$ifdef HAVE_LAMBDAS}
TDECProgressEvent = reference to procedure(Size, Pos: Int64; State: TDECProgressState);
+ {$else}
+ TDECProgressEvent = procedure(Size, Pos: Int64; State: TDECProgressState);
+ {$endif}
// Exception Classes
diff --git a/Source/DECUtil.pas b/Source/DECUtil.pas
index dc05f094..6263f663 100644
--- a/Source/DECUtil.pas
+++ b/Source/DECUtil.pas
@@ -19,10 +19,10 @@
/// Utility functions
///
unit DECUtil;
+{$INCLUDE DECOptions.inc}
interface
-{$INCLUDE DECOptions.inc}
uses
{$IFDEF FPC}
@@ -266,6 +266,16 @@ implementation
$27, $A7, $67, $E7, $17, $97, $57, $D7, $37, $B7, $77, $F7, $0F, $8F,
$4F, $CF, $2F, $AF, $6F, $EF, $1F, $9F, $5F, $DF, $3F, $BF, $7F, $FF);
+{$ifdef FPC}
+{$include fpc\DECUtil.inc}
+{$endif}
+
+{$ifdef X64ASM}
+ {$include x86_64\DECUtil.inc}
+{$else}{$ifdef X86ASM}
+ {$include x86\DECUtil.inc}
+{$endif}{$endif}
+
function ReverseBits(Source: UInt32): UInt32;
begin
Result := (ReverseBitLookupTable256[Source and $FF] shl 24) or
@@ -320,15 +330,8 @@ procedure SwapBytes(var Buffer; Size: Integer);
end;
{$ENDIF !X86ASM}
+{$ifndef SwapUInt32_asm}
function SwapUInt32(Source: UInt32): UInt32;
-{$IF defined(X86ASM) or defined(X64ASM)}
- asm
- {$IFDEF X64ASM}
- MOV EAX, ECX
- {$ENDIF X64ASM}
- BSWAP EAX
- end;
-{$ELSE PUREPASCAL}
begin
Result := Source shl 24 or
Source shr 24 or
@@ -367,15 +370,9 @@ procedure SwapUInt32Buffer(const Source; var Dest; Count: Integer);
end;
{$ENDIF !X86ASM}
+
+{$IFNDEF SwapInt64_asm}
function SwapInt64(Source: Int64): Int64;
-{$IFDEF X86ASM}
-asm
- MOV EDX,Source.DWord[0]
- MOV EAX,Source.DWord[4]
- BSWAP EDX
- BSWAP EAX
-end;
-{$ELSE !X86ASM}
var
L, H: Cardinal;
begin
@@ -516,7 +513,7 @@ procedure ProtectStream(Stream: TStream; SizeToProtect: Int64 = 0);
begin
Stream.Position := Position;
Size := SizeToProtect;
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
FillChar(Buffer[Low(Buffer)], BufferSize, WipeBytes[Count]);
{$ELSE}
FillChar(Buffer[1], BufferSize, WipeBytes[Count]);
@@ -526,7 +523,7 @@ procedure ProtectStream(Stream: TStream; SizeToProtect: Int64 = 0);
Bytes := Size;
if Bytes > BufferSize then
Bytes := BufferSize;
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
Stream.Write(Buffer[Low(Buffer)], Bytes);
{$ELSE}
Stream.Write(Buffer[1], Bytes);
@@ -550,7 +547,7 @@ procedure ProtectString(var Source: string);
if Length(Source) > 0 then
begin
System.UniqueString(Source);
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
{$ELSE}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
@@ -566,7 +563,7 @@ procedure ProtectString(var Source: RawByteString);
// UniqueString(Source); cannot be called with a RawByteString as there is
// no overload for it, so we need to call our own one.
DECUtilRawByteStringHelper.UniqueString(Source);
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
{$ELSE}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
@@ -576,12 +573,13 @@ procedure ProtectString(var Source: RawByteString);
end;
{$IFNDEF NEXTGEN}
+{$IFDEF ANSISTRINGSUPPORTED} //{$ifndef FPC} // FPC use RawByteString == AnsiString
procedure ProtectString(var Source: AnsiString); overload;
begin
if Length(Source) > 0 then
begin
System.UniqueString(Source);
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
{$ELSE}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
@@ -589,13 +587,14 @@ procedure ProtectString(var Source: AnsiString); overload;
Source := '';
end;
end;
+{$endif FPC}
procedure ProtectString(var Source: WideString); overload;
begin
if Length(Source) > 0 then
begin
System.UniqueString(Source); // for OS <> Win, WideString is not RefCounted on Win
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[Low(Source)]));
{$ELSE}
ProtectBuffer(Pointer(Source)^, Length(Source) * SizeOf(Source[1]));
@@ -611,7 +610,7 @@ function BytesToRawString(const Source: TBytes): RawByteString;
if Length(Source) > 0 then
begin
// determine lowest string index for handling of ZeroBasedStrings
- {$IF CompilerVersion >= 24.0}
+ {$IFDEF HAVE_STR_LIKE_ARRAY}
Move(Source[0], Result[Low(result)], Length(Source));
{$ELSE}
Move(Source[0], Result[1], Length(Source));
diff --git a/Source/fpc/DECUtil.inc b/Source/fpc/DECUtil.inc
new file mode 100644
index 00000000..5618b629
--- /dev/null
+++ b/Source/fpc/DECUtil.inc
@@ -0,0 +1,14 @@
+
+{$define SwapUInt32_asm}
+function SwapUInt32(Source: UInt32): UInt32;
+begin
+ result := SwapEndian(Source);
+end;
+
+{$define SwapInt64_asm}
+function SwapInt64(Source: Int64): Int64;
+begin
+ result := SwapEndian(Source);
+end;
+
+
diff --git a/Source/fpc/dec.lpk b/Source/fpc/dec.lpk
new file mode 100644
index 00000000..1b7f2a31
--- /dev/null
+++ b/Source/fpc/dec.lpk
@@ -0,0 +1,151 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+ -
+
+
+
+
+
+ -
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Source/fpc/dec.pas b/Source/fpc/dec.pas
new file mode 100644
index 00000000..b957e05d
--- /dev/null
+++ b/Source/fpc/dec.pas
@@ -0,0 +1,19 @@
+{ This file was automatically created by Lazarus. Do not edit!
+ This source is only used to compile and install the package.
+ }
+
+unit DEC;
+
+{$warn 5023 off : no warning about unused units}
+interface
+
+uses
+ DECCRC, DECData, DECHash, DECRandom, DECUtil, DECBaseClass, DECCipherBase,
+ DECCipherFormats, DECCipherInterface, DECCipherModes, DECCipherModesGCM,
+ DECCiphers, DECDataCipher, DECDataHash, DECFormat, DECFormatBase,
+ DECHashAuthentication, DECHashBase, DECHashBitBase, DECHashInterface,
+ DECTypes, DECUtilRawByteStringHelper;
+
+implementation
+
+end.
diff --git a/Source/x86/DECUtil.inc b/Source/x86/DECUtil.inc
new file mode 100644
index 00000000..5de64346
--- /dev/null
+++ b/Source/x86/DECUtil.inc
@@ -0,0 +1,23 @@
+{$ifdef FPC}
+{$ASMMODE intel}
+{$endif}
+
+{$ifndef SwapUInt32_asm}
+{$define SwapUInt32_asm}
+function SwapUInt32(Source: UInt32): UInt32;
+asm
+ BSWAP EAX
+end;
+{$endif}
+
+{$ifndef SwapInt64_asm}
+{$define SwapInt64_asm}
+function SwapInt64(Source: Int64): Int64;
+asm
+ MOV EDX,Source.DWord[0]
+ MOV EAX,Source.DWord[4]
+ BSWAP EDX
+ BSWAP EAX
+end;
+{$endif}
+
diff --git a/Source/x86_64/DECUtil.inc b/Source/x86_64/DECUtil.inc
new file mode 100644
index 00000000..d12c7f9a
--- /dev/null
+++ b/Source/x86_64/DECUtil.inc
@@ -0,0 +1,24 @@
+{$ifdef FPC}
+{$ASMMODE intel}
+{$endif}
+
+{$ifndef SwapUInt32_asm}
+{$define SwapUInt32_asm}
+function SwapUInt32(Source: UInt32): UInt32;
+asm
+ MOV RAX, Source
+ BSWAP RAX
+ SHR RAX, 32
+end;
+{$endif}
+
+{$ifndef SwapInt64_asm}
+{$define SwapInt64_asm}
+function SwapInt64(Source: Int64): Int64;
+asm
+ MOV RAX, Source
+ BSWAP RAX
+end;
+{$endif}
+
+