Skip to content

Commit 5bbda59

Browse files
author
Markus Humm
committed
Merge branch 'development' into master
2 parents 1f6ede2 + 9b3d742 commit 5bbda59

19 files changed

+790
-497
lines changed

Demos/Cipher_FMX/MainForm.pas

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,10 @@ procedure TFormMain.ComboBoxCipherAlgorithmChange(Sender: TObject);
265265
StringGridContext.Cells[0, 5] := 'Cipher mode';
266266
StringGridContext.Cells[0, 6] := 'Cipher key';
267267

268-
StringGridContext.Cells[1, 0] := (Context.KeySize*8).ToString;
269-
StringGridContext.Cells[1, 1] := (Context.BlockSize*8).ToString;
270-
StringGridContext.Cells[1, 2] := (Context.BufferSize*8).ToString;
271-
StringGridContext.Cells[1, 3] := (Context.AdditionalBufferSize*8).ToString;
268+
StringGridContext.Cells[1, 0] := IntToStr((Context.KeySize*8);
269+
StringGridContext.Cells[1, 1] := IntToStr((Context.BlockSize*8);
270+
StringGridContext.Cells[1, 2] := IntToStr((Context.BufferSize*8);
271+
StringGridContext.Cells[1, 3] := IntToStr((Context.AdditionalBufferSize*8);
272272
StringGridContext.Cells[1, 4] := BoolToStr(Context.NeedsAdditionalBufferBackup, true);
273273

274274
if ctBlock in Context.CipherType then

Demos/Hash_FMX/Hash_FMX.dproj

Lines changed: 232 additions & 168 deletions
Large diffs are not rendered by default.

Source/DECBaseClass.pas

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,22 @@ class function TDECObject.Identity: Int64;
226226
begin
227227
{$IFDEF DEC52_IDENTITY}
228228
Signature := StringOfChar(#$5A, 256 - Length(ClassName)) + UpperCase(ClassName);
229-
Result := CRC32(IdentityBase, Signature[Low(Signature)],
230-
Length(Signature) * SizeOf(Signature[Low(Signature)]));
229+
{$IF CompilerVersion >= 17.0}
230+
Result := CRC32(IdentityBase, Signature[Low(Signature)],
231+
Length(Signature) * SizeOf(Signature[Low(Signature)]));
232+
{$ELSE}
233+
Result := CRC32(IdentityBase, Signature[Low(Signature)],
234+
Length(Signature) * SizeOf(Signature[1]));
235+
{$ENDIF}
231236
{$ELSE !DEC52_IDENTITY}
232237
Signature := RawByteString(StringOfChar(#$5A, 256 - Length(ClassName)) + UpperCase(ClassName));
233-
Result := CRC32(IdentityBase, Signature[Low(Signature)], Length(Signature));
238+
{$IF CompilerVersion >= 17.0}
239+
Result := CRC32(IdentityBase, Signature[Low(Signature)],
240+
Length(Signature) * SizeOf(Signature[Low(Signature)]));
241+
{$ELSE}
242+
Result := CRC32(IdentityBase, Signature[1],
243+
Length(Signature) * SizeOf(Signature[1]));
244+
{$ENDIF}
234245
{$ENDIF !DEC52_IDENTITY}
235246
end;
236247

Source/DECCipherBase.pas

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,10 +898,19 @@ procedure TDECCipher.Init(const Key: RawByteString; const IVector: RawByteString
898898
raise EDECCipherException.CreateRes(@sNoKeyMaterialGiven);
899899

900900
if Length(IVector) > 0 then
901+
{$IF CompilerVersion >= 17.0}
901902
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
902903
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
904+
{$ELSE}
905+
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[1]),
906+
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[1]), IFiller)
907+
{$ENDIF}
903908
else
909+
{$IF CompilerVersion >= 17.0}
904910
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]), NullStr, 0, IFiller);
911+
{$ELSE}
912+
Init(Key[1], Length(Key) * SizeOf(Key[1]), NullStr, 0, IFiller);
913+
{$ENDIF}
905914
end;
906915

907916

@@ -912,10 +921,19 @@ procedure TDECCipher.Init(const Key, IVector: AnsiString; IFiller: Byte);
912921
raise EDECCipherException.Create(sNoKeyMaterialGiven);
913922

914923
if Length(IVector) > 0 then
924+
{$IF CompilerVersion >= 17.0}
915925
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
916-
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
926+
IVector[Low(IVector)], Length(IVector) * SizeOf(Low(IVector)), IFiller)
927+
{$ELSE}
928+
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
929+
IVector[IVector[1]], Length(IVector) * SizeOf(IVector[1]), IFiller)
930+
{$ENDIF}
917931
else
932+
{$IF CompilerVersion >= 17.0}
918933
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]), NullStr, 0, IFiller);
934+
{$ELSE}
935+
Init(Key[1], Length(Key) * SizeOf(Key[1]), NullStr, 0, IFiller);
936+
{$ENDIF}
919937
end;
920938
{$ENDIF}
921939

@@ -927,10 +945,19 @@ procedure TDECCipher.Init(const Key, IVector: WideString; IFiller: Byte);
927945
raise EDECCipherException.CreateRes(@sNoKeyMaterialGiven);
928946

929947
if Length(IVector) > 0 then
948+
{$IF CompilerVersion >= 17.0}
930949
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
931950
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
951+
{$ELSE}
952+
Init(Key[1], Length(Key) * SizeOf(Key[1]),
953+
IVector[1], Length(IVector) * SizeOf(IVector[1]), IFiller)
954+
{$ENDIF}
932955
else
956+
{$IF CompilerVersion >= 17.0}
933957
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]), NullStr, 0, IFiller);
958+
{$ELSE}
959+
Init(Key[1], Length(Key) * SizeOf(Key[1]), NullStr, 0, IFiller);
960+
{$ENDIF}
934961
end;
935962
{$ENDIF}
936963

@@ -959,8 +986,13 @@ function TDECCipher.EncodeRawByteString(const Source: RawByteString; Format: TDE
959986
SetLength(b, 0);
960987
if Length(Source) > 0 then
961988
begin
989+
{$IF CompilerVersion >= 17.0}
962990
SetLength(b, Length(Source) * SizeOf(Source[Low(Source)]));
963991
DoEncode(@Source[low(Source)], @b[0], Length(Source) * SizeOf(Source[low(Source)]));
992+
{$ELSE}
993+
SetLength(b, Length(Source) * SizeOf(Source[1]));
994+
DoEncode(@Source[1], @b[0], Length(Source) * SizeOf(Source[1]));
995+
{$ENDIF}
964996
Result := BytesToRawString(ValidFormat(Format).Encode(b));
965997
end;
966998
end;
@@ -990,7 +1022,11 @@ function TDECCipher.DecodeRawByteString(const Source: RawByteString; Format: TDE
9901022
// This has been fixed in 10.3.0 Rio
9911023
b := ValidFormat(Format).Decode(BytesOf(Source));
9921024

1025+
{$IF CompilerVersion >= 17.0}
9931026
DoDecode(@b[0], @Result[Low(Result)], Length(Result) * SizeOf(Result[Low(Result)]));
1027+
{$ELSE}
1028+
DoDecode(@b[0], @Result[1], Length(Result) * SizeOf(Result[1]));
1029+
{$ENDIF}
9941030
end;
9951031
end;
9961032

Source/DECCipherFormats.pas

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -720,9 +720,15 @@ function TDECFormattedCipher.EncodeStringToBytes(const Source: string;
720720
begin
721721
if Length(Source) > 0 then
722722
begin
723+
{$IF CompilerVersion >= 17.0}
723724
Len := Length(Source) * SizeOf(Source[low(Source)]);
724725
SetLength(Result, Len);
725726
Encode(Source[low(Source)], Result[0], Len);
727+
{$ELSE}
728+
Len := Length(Source) * SizeOf(Source[1]);
729+
SetLength(Result, Len);
730+
Encode(Source[1], Result[0], Len);
731+
{$ENDIF}
726732

727733
Result := ValidFormat(Format).Encode(Result);
728734
end
@@ -736,9 +742,15 @@ function TDECFormattedCipher.EncodeStringToBytes(const Source: RawByteString; Fo
736742
begin
737743
if Length(Source) > 0 then
738744
begin
745+
{$IF CompilerVersion >= 17.0}
739746
Len := Length(Source) * SizeOf(Source[low(Source)]);
740747
SetLength(Result, Len);
741748
Encode(Source[low(Source)], Result[0], Len);
749+
{$ELSE}
750+
Len := Length(Source) * SizeOf(Source[1]);
751+
SetLength(Result, Len);
752+
Encode(Source[1], Result[0], Len);
753+
{$ENDIF}
742754

743755
Result := ValidFormat(Format).Encode(Result);
744756
end
@@ -872,9 +884,15 @@ function TDECFormattedCipher.EncodeStringToString(const Source: string;
872884
begin
873885
if Length(Source) > 0 then
874886
begin
887+
{$IF CompilerVersion >= 17.0}
875888
SourceSize := Length(Source) * SizeOf(Source[low(Source)]);
876889
SetLength(EncryptedBuffer, SourceSize);
877890
Encode(Source[low(Source)], EncryptedBuffer[0], SourceSize);
891+
{$ELSE}
892+
SourceSize := Length(Source) * SizeOf(Source[1]);
893+
SetLength(EncryptedBuffer, SourceSize);
894+
Encode(Source[1], EncryptedBuffer[0], SourceSize);
895+
{$ENDIF}
878896

879897
Result := StringOf(ValidFormat(Format).Encode(EncryptedBuffer));
880898
end
@@ -891,13 +909,23 @@ function TDECFormattedCipher.EncodeStringToString(const Source: RawByteString;
891909
begin
892910
if Length(Source) > 0 then
893911
begin
912+
{$IF CompilerVersion >= 17.0}
894913
SourceSize := Length(Source) * SizeOf(Source[low(Source)]);
895914
SetLength(EncryptedBuffer, SourceSize);
896915
Encode(Source[low(Source)], EncryptedBuffer[0], SourceSize);
916+
{$ELSE}
917+
SourceSize := Length(Source) * SizeOf(Source[1]);
918+
SetLength(EncryptedBuffer, SourceSize);
919+
Encode(Source[1], EncryptedBuffer[0], SourceSize);
920+
{$ENDIF}
897921

898922
Temp := ValidFormat(Format).Encode(EncryptedBuffer);
899923
SetLength(Result, length(Temp));
900-
Move(Temp[0], Result[low(Result)], length(Temp));
924+
{$IF CompilerVersion >= 17.0}
925+
Move(Temp[0], Result[low(Result)], length(Temp))
926+
{$ELSE}
927+
Move(Temp[0], Result[1], length(Temp))
928+
{$ENDIF}
901929
end
902930
else
903931
Result := '';
@@ -939,7 +967,12 @@ function TDECFormattedCipher.DecodeStringToString(const Source: AnsiString;
939967
Decode(Src[0], Tmp[0], Len);
940968

941969
SetLength(Result, length(Tmp));
942-
Move(Tmp[0], Result[low(Result)], length(Tmp));
970+
971+
{$IF CompilerVersion >= 17.0}
972+
Move(Tmp[0], Result[low(Result)], length(Tmp))
973+
{$ELSE}
974+
Move(Tmp[0], Result[1], length(Tmp))
975+
{$ENDIF}
943976
end
944977
else
945978
SetLength(Result, 0);
@@ -970,7 +1003,12 @@ function TDECFormattedCipher.DecodeStringToString(const Source: RawByteString;
9701003
Decode(Src[0], Tmp[0], Len);
9711004

9721005
SetLength(Result, length(Tmp));
973-
Move(Tmp[0], Result[low(Result)], length(Tmp));
1006+
1007+
{$IF CompilerVersion >= 17.0}
1008+
Move(Tmp[0], Result[low(Result)], length(Tmp))
1009+
{$ELSE}
1010+
Move(Tmp[0], Result[1], length(Tmp))
1011+
{$ENDIF}
9741012
end
9751013
else
9761014
SetLength(Result, 0);

0 commit comments

Comments
 (0)