Skip to content

Commit

Permalink
Merge branch 'development' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Humm committed Mar 13, 2021
2 parents 1f6ede2 + 9b3d742 commit 5bbda59
Show file tree
Hide file tree
Showing 19 changed files with 790 additions and 497 deletions.
8 changes: 4 additions & 4 deletions Demos/Cipher_FMX/MainForm.pas
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ procedure TFormMain.ComboBoxCipherAlgorithmChange(Sender: TObject);
StringGridContext.Cells[0, 5] := 'Cipher mode';
StringGridContext.Cells[0, 6] := 'Cipher key';

StringGridContext.Cells[1, 0] := (Context.KeySize*8).ToString;
StringGridContext.Cells[1, 1] := (Context.BlockSize*8).ToString;
StringGridContext.Cells[1, 2] := (Context.BufferSize*8).ToString;
StringGridContext.Cells[1, 3] := (Context.AdditionalBufferSize*8).ToString;
StringGridContext.Cells[1, 0] := IntToStr((Context.KeySize*8);
StringGridContext.Cells[1, 1] := IntToStr((Context.BlockSize*8);
StringGridContext.Cells[1, 2] := IntToStr((Context.BufferSize*8);
StringGridContext.Cells[1, 3] := IntToStr((Context.AdditionalBufferSize*8);
StringGridContext.Cells[1, 4] := BoolToStr(Context.NeedsAdditionalBufferBackup, true);

if ctBlock in Context.CipherType then
Expand Down
400 changes: 232 additions & 168 deletions Demos/Hash_FMX/Hash_FMX.dproj

Large diffs are not rendered by default.

17 changes: 14 additions & 3 deletions Source/DECBaseClass.pas
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,22 @@ class function TDECObject.Identity: Int64;
begin
{$IFDEF DEC52_IDENTITY}
Signature := StringOfChar(#$5A, 256 - Length(ClassName)) + UpperCase(ClassName);
Result := CRC32(IdentityBase, Signature[Low(Signature)],
Length(Signature) * SizeOf(Signature[Low(Signature)]));
{$IF CompilerVersion >= 17.0}
Result := CRC32(IdentityBase, Signature[Low(Signature)],
Length(Signature) * SizeOf(Signature[Low(Signature)]));
{$ELSE}
Result := CRC32(IdentityBase, Signature[Low(Signature)],
Length(Signature) * SizeOf(Signature[1]));
{$ENDIF}
{$ELSE !DEC52_IDENTITY}
Signature := RawByteString(StringOfChar(#$5A, 256 - Length(ClassName)) + UpperCase(ClassName));
Result := CRC32(IdentityBase, Signature[Low(Signature)], Length(Signature));
{$IF CompilerVersion >= 17.0}
Result := CRC32(IdentityBase, Signature[Low(Signature)],
Length(Signature) * SizeOf(Signature[Low(Signature)]));
{$ELSE}
Result := CRC32(IdentityBase, Signature[1],
Length(Signature) * SizeOf(Signature[1]));
{$ENDIF}
{$ENDIF !DEC52_IDENTITY}
end;

Expand Down
38 changes: 37 additions & 1 deletion Source/DECCipherBase.pas
Original file line number Diff line number Diff line change
Expand Up @@ -898,10 +898,19 @@ procedure TDECCipher.Init(const Key: RawByteString; const IVector: RawByteString
raise EDECCipherException.CreateRes(@sNoKeyMaterialGiven);

if Length(IVector) > 0 then
{$IF CompilerVersion >= 17.0}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
{$ELSE}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[1]),
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[1]), IFiller)
{$ENDIF}
else
{$IF CompilerVersion >= 17.0}
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);
{$ENDIF}
end;


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

if Length(IVector) > 0 then
{$IF CompilerVersion >= 17.0}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
IVector[Low(IVector)], Length(IVector) * SizeOf(Low(IVector)), IFiller)
{$ELSE}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
IVector[IVector[1]], Length(IVector) * SizeOf(IVector[1]), IFiller)
{$ENDIF}
else
{$IF CompilerVersion >= 17.0}
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);
{$ENDIF}
end;
{$ENDIF}

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

if Length(IVector) > 0 then
{$IF CompilerVersion >= 17.0}
Init(Key[Low(Key)], Length(Key) * SizeOf(Key[Low(Key)]),
IVector[Low(IVector)], Length(IVector) * SizeOf(IVector[Low(IVector)]), IFiller)
{$ELSE}
Init(Key[1], Length(Key) * SizeOf(Key[1]),
IVector[1], Length(IVector) * SizeOf(IVector[1]), IFiller)
{$ENDIF}
else
{$IF CompilerVersion >= 17.0}
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);
{$ENDIF}
end;
{$ENDIF}

Expand Down Expand Up @@ -959,8 +986,13 @@ function TDECCipher.EncodeRawByteString(const Source: RawByteString; Format: TDE
SetLength(b, 0);
if Length(Source) > 0 then
begin
{$IF CompilerVersion >= 17.0}
SetLength(b, Length(Source) * SizeOf(Source[Low(Source)]));
DoEncode(@Source[low(Source)], @b[0], Length(Source) * SizeOf(Source[low(Source)]));
{$ELSE}
SetLength(b, Length(Source) * SizeOf(Source[1]));
DoEncode(@Source[1], @b[0], Length(Source) * SizeOf(Source[1]));
{$ENDIF}
Result := BytesToRawString(ValidFormat(Format).Encode(b));
end;
end;
Expand Down Expand Up @@ -990,7 +1022,11 @@ 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 >= 17.0}
DoDecode(@b[0], @Result[Low(Result)], Length(Result) * SizeOf(Result[Low(Result)]));
{$ELSE}
DoDecode(@b[0], @Result[1], Length(Result) * SizeOf(Result[1]));
{$ENDIF}
end;
end;

Expand Down
44 changes: 41 additions & 3 deletions Source/DECCipherFormats.pas
Original file line number Diff line number Diff line change
Expand Up @@ -720,9 +720,15 @@ function TDECFormattedCipher.EncodeStringToBytes(const Source: string;
begin
if Length(Source) > 0 then
begin
{$IF CompilerVersion >= 17.0}
Len := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(Result, Len);
Encode(Source[low(Source)], Result[0], Len);
{$ELSE}
Len := Length(Source) * SizeOf(Source[1]);
SetLength(Result, Len);
Encode(Source[1], Result[0], Len);
{$ENDIF}

Result := ValidFormat(Format).Encode(Result);
end
Expand All @@ -736,9 +742,15 @@ function TDECFormattedCipher.EncodeStringToBytes(const Source: RawByteString; Fo
begin
if Length(Source) > 0 then
begin
{$IF CompilerVersion >= 17.0}
Len := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(Result, Len);
Encode(Source[low(Source)], Result[0], Len);
{$ELSE}
Len := Length(Source) * SizeOf(Source[1]);
SetLength(Result, Len);
Encode(Source[1], Result[0], Len);
{$ENDIF}

Result := ValidFormat(Format).Encode(Result);
end
Expand Down Expand Up @@ -872,9 +884,15 @@ function TDECFormattedCipher.EncodeStringToString(const Source: string;
begin
if Length(Source) > 0 then
begin
{$IF CompilerVersion >= 17.0}
SourceSize := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(EncryptedBuffer, SourceSize);
Encode(Source[low(Source)], EncryptedBuffer[0], SourceSize);
{$ELSE}
SourceSize := Length(Source) * SizeOf(Source[1]);
SetLength(EncryptedBuffer, SourceSize);
Encode(Source[1], EncryptedBuffer[0], SourceSize);
{$ENDIF}

Result := StringOf(ValidFormat(Format).Encode(EncryptedBuffer));
end
Expand All @@ -891,13 +909,23 @@ function TDECFormattedCipher.EncodeStringToString(const Source: RawByteString;
begin
if Length(Source) > 0 then
begin
{$IF CompilerVersion >= 17.0}
SourceSize := Length(Source) * SizeOf(Source[low(Source)]);
SetLength(EncryptedBuffer, SourceSize);
Encode(Source[low(Source)], EncryptedBuffer[0], SourceSize);
{$ELSE}
SourceSize := Length(Source) * SizeOf(Source[1]);
SetLength(EncryptedBuffer, SourceSize);
Encode(Source[1], EncryptedBuffer[0], SourceSize);
{$ENDIF}

Temp := ValidFormat(Format).Encode(EncryptedBuffer);
SetLength(Result, length(Temp));
Move(Temp[0], Result[low(Result)], length(Temp));
{$IF CompilerVersion >= 17.0}
Move(Temp[0], Result[low(Result)], length(Temp))
{$ELSE}
Move(Temp[0], Result[1], length(Temp))
{$ENDIF}
end
else
Result := '';
Expand Down Expand Up @@ -939,7 +967,12 @@ function TDECFormattedCipher.DecodeStringToString(const Source: AnsiString;
Decode(Src[0], Tmp[0], Len);

SetLength(Result, length(Tmp));
Move(Tmp[0], Result[low(Result)], length(Tmp));

{$IF CompilerVersion >= 17.0}
Move(Tmp[0], Result[low(Result)], length(Tmp))
{$ELSE}
Move(Tmp[0], Result[1], length(Tmp))
{$ENDIF}
end
else
SetLength(Result, 0);
Expand Down Expand Up @@ -970,7 +1003,12 @@ function TDECFormattedCipher.DecodeStringToString(const Source: RawByteString;
Decode(Src[0], Tmp[0], Len);

SetLength(Result, length(Tmp));
Move(Tmp[0], Result[low(Result)], length(Tmp));

{$IF CompilerVersion >= 17.0}
Move(Tmp[0], Result[low(Result)], length(Tmp))
{$ELSE}
Move(Tmp[0], Result[1], length(Tmp))
{$ENDIF}
end
else
SetLength(Result, 0);
Expand Down
Loading

0 comments on commit 5bbda59

Please sign in to comment.