/trunk/Decoder5/Coder.dpr |
---|
16,7 → 16,8 |
DECUtilRawByteStringHelper in '..\..\Source\DECUtilRawByteStringHelper.pas', |
DECFormatBase in '..\..\Source\DECFormatBase.pas', |
DECData in '..\..\Source\DECData.pas', |
DecoderEncDec in 'DecoderEncDec.pas'; |
DecoderEncDec in 'DecoderEncDec.pas', |
DecoderOldCiphers in 'DecoderOldCiphers.pas'; |
{$R *.res} |
/trunk/Decoder5/Coder.dproj |
---|
110,8 → 110,8 |
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo> |
<VerInfo_Locale>1033</VerInfo_Locale> |
<VerInfo_AutoIncVersion>true</VerInfo_AutoIncVersion> |
<VerInfo_Build>126</VerInfo_Build> |
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.126;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys> |
<VerInfo_Build>137</VerInfo_Build> |
<VerInfo_Keys>CompanyName=;FileDescription=$(MSBuildProjectName);FileVersion=1.0.0.137;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProgramID=com.embarcadero.$(MSBuildProjectName);ProductName=$(MSBuildProjectName);ProductVersion=1.0.0.0;Comments=</VerInfo_Keys> |
</PropertyGroup> |
<PropertyGroup Condition="'$(Cfg_1_Win64)'!=''"> |
<AppEnableRuntimeThemes>true</AppEnableRuntimeThemes> |
157,6 → 157,7 |
<DCCReference Include="..\..\Source\DECFormatBase.pas"/> |
<DCCReference Include="..\..\Source\DECData.pas"/> |
<DCCReference Include="DecoderEncDec.pas"/> |
<DCCReference Include="DecoderOldCiphers.pas"/> |
<BuildConfiguration Include="Base"> |
<Key>Base</Key> |
</BuildConfiguration> |
/trunk/Decoder5/DecoderEncDec.pas |
---|
189,6 → 189,7 |
if cn = 'THash_SHA0'{DEC6.0} then cn := 'THash_SHA'{DEC5.1}; |
if cn = 'THash_Whirlpool0'{DEC6.0} then cn := 'THash_Whirlpool'{DEC5.1}; |
if cn = 'TCipher_AES'{DEC6.0} then cn := 'TCipher_Rijndael'{DEC5.1}; |
if cn = 'TCipher_Magma' then cn := 'TCipher_Gost'; // TCipher_Magma is an alias for TCipher_Gost |
Signature := AnsiString(StringOfChar(#$5A, 256 - Length(cn)) + AnsiUpperCase(cn)); |
Result := CRC32(IdentityBase, Signature[1], Length(Signature)); |
end; |
679,7 → 680,7 |
if Length(OrigNameEncrypted) mod 2 <> 0 then OrigNameEncrypted := OrigNameEncrypted + #0; // should not happen, otherwise it is no valid UTF-16! |
OrigName := WideString(PWideString(Pointer(OrigNameEncrypted))); |
finally |
Cipher.Done; // TODO: I don't understand, if Done() processes the last byte/block, it won't affect our string since we already got the result from DecodeRawByteString(). Asked here https://github.com/MHumm/DelphiEncryptionCompendium/issues/63 |
Cipher.Done; |
end; |
end; |
{$ENDREGION} |
/trunk/Decoder5/DecoderMain.dfm |
---|
48,4 → 48,22 |
ParentFont = False |
TabOrder = 2 |
end |
object Button2: TButton |
Left = 248 |
Top = 104 |
Width = 153 |
Height = 49 |
Caption = 'Button2' |
TabOrder = 3 |
OnClick = Button2Click |
end |
object Button3: TButton |
Left = 432 |
Top = 96 |
Width = 145 |
Height = 65 |
Caption = 'Button3' |
TabOrder = 4 |
OnClick = Button3Click |
end |
end |
/trunk/Decoder5/DecoderMain.pas |
---|
11,7 → 11,11 |
Button1: TButton; |
ProgressBar1: TProgressBar; |
Memo1: TMemo; |
Button2: TButton; |
Button3: TButton; |
procedure Button1Click(Sender: TObject); |
procedure Button2Click(Sender: TObject); |
procedure Button3Click(Sender: TObject); |
end; |
var |
20,7 → 24,8 |
implementation |
uses |
DecoderEncDec, DECTypes; |
DecoderEncDec, DECTypes, DecoderOldCiphers, DECCipherBase, DECCiphers, |
DECCipherFormats; |
{$R *.dfm} |
110,4 → 115,58 |
end; |
*) |
procedure TFormMain.Button2Click(Sender: TObject); |
var |
Cipher: TDECCipher; |
s: RawByteString; |
begin |
Cipher := TCipher_Dc30.Create; |
Cipher.Init('', '', $FF); |
Cipher.Mode := cmECBx; |
s := Cipher.EncodeRawByteString('Hello'); |
memo1.Lines.Add(s); |
Cipher.Done; |
Cipher.Init('', '', $FF); |
Cipher.Mode := cmECBx; |
memo1.Lines.Add(Cipher.DecodeRawByteString(s)); |
Cipher.Done; |
end; |
function Convert(const Bytes: TBytes): RawByteString; |
begin |
SetLength(Result, Length(Bytes)); |
Move(Bytes[0], Result[1], Length(Bytes)) |
end; |
procedure TFormMain.Button3Click(Sender: TObject); |
var |
ssIn: TFileStream; |
ssOut: TFileStream; |
Cipher: TDECCipher; |
begin |
ssIn := TFileStream.Create('c:\SVN\Decoder\trunk\History\Decoder30\test_in.txt', fmOpenRead); |
ssOut := TFileStream.Create('c:\SVN\Decoder\trunk\History\Decoder30\test_out_foobar_2.txt', fmCreate); |
Cipher := TCipher_Dc30.Create; |
Cipher.Init(AnsiString('foobar'), AnsiString(''), $FF); |
Cipher.Mode := cmECBx; |
TDECFormattedCipher(Cipher).EncodeStream(ssIn, ssOut, ssIn.Size); |
Cipher.Done; |
ssIn.Free; |
ssOut.Free; |
ssIn := TFileStream.Create('c:\SVN\Decoder\trunk\History\Decoder30\256zero_in.txt', fmOpenRead); |
ssOut := TFileStream.Create('c:\SVN\Decoder\trunk\History\Decoder30\256zero_out_foobar_2.txt', fmCreate); |
// Cipher := TCipher_Dc30.Create; |
// Cipher.Init(AnsiString('foobar'), AnsiString(''), $FF); |
Cipher.Mode := cmECBx; |
TDECFormattedCipher(Cipher).EncodeStream(ssIn, ssOut, ssIn.Size); |
Cipher.Done; |
ssIn.Free; |
ssOut.Free; |
Cipher.Free; |
end; |
end. |
/trunk/Decoder5/DecoderOldCiphers.pas |
---|
0,0 → 1,75 |
unit DecoderOldCiphers; |
interface |
uses |
SysUtils, DECCipherBase, DECCipherFormats; |
type |
TCipher_Dc30 = class(TDECFormattedCipher) |
private |
FKey: TBytes; |
FKeyPos: Integer; |
protected |
procedure DoInit(const Key; Size: Integer); override; |
procedure DoEncode(Source, Dest: Pointer; Size: Integer); override; |
procedure DoDecode(Source, Dest: Pointer; Size: Integer); override; |
procedure SecureErase; override; |
public |
class function Context: TCipherContext; override; |
end; |
implementation |
uses |
DECTypes, DECUtil; |
{ TCipher_Dc30 } |
class function TCipher_Dc30.Context: TCipherContext; |
begin |
Result.KeySize := High(Integer); |
Result.BlockSize := 1; |
Result.BufferSize := 1; |
Result.AdditionalBufferSize := 0; |
Result.NeedsAdditionalBufferBackup := False; |
Result.MinRounds := 1; |
Result.MaxRounds := 1; |
Result.CipherType := [ctBlock, ctSymmetric]; |
end; |
procedure TCipher_Dc30.DoInit(const Key; Size: Integer); |
begin |
inherited; |
SetLength(FKey, Size); |
Move(Key, FKey[0], Size); |
FKeyPos := -1; // first byte is garbage, because there is one DoEncode round for IV in TDECCipher.Init, even if IV is empty |
end; |
procedure TCipher_Dc30.DoEncode(Source, Dest: Pointer; Size: Integer); |
var |
i: integer; |
begin |
if State = csDone then FKeyPos := 0; |
for i := 0 to Size-1 do |
begin |
PByte(Dest)[i] := PByte(Source)[i] xor FKey[FKeyPos]; |
FKeyPos := (FKeyPos+1) mod Length(FKey); |
end; |
end; |
procedure TCipher_Dc30.SecureErase; |
begin |
ProtectBuffer(FKey, Length(FKey)); |
SetLength(FKey, 0); |
inherited; |
end; |
procedure TCipher_Dc30.DoDecode(Source, Dest: Pointer; Size: Integer); |
begin |
DoEncode(Source, Dest, Size); |
end; |
initialization |
TCipher_Dc30.RegisterClass(TDECCipher.ClassList); |
end. |
/trunk/Decoder5/VCL_DEC/DECCipherBase.pas |
---|
694,7 → 694,7 |
/// Exception raised if the length of the data passed as <c>Source</c> |
/// is not a multiple of the algorithm's block size. |
/// </exception> |
function DecodeBytes(const Source: TBytes; Format: TDECFormatClass): TBytes; |
function DecodeBytes(const Source: TBytes; Format: TDECFormatClass = nil): TBytes; |
// CalcMACBytes deferred since the current implementation would neither be |
// performant (that would require another TFormatBase.Encode variant from |
1047,7 → 1047,9 |
begin |
// GCM allows empty key as the authentication still works |
if (Length(Key) = 0) and (not (ctNull in Context.CipherType)) and |
(not (FMode = cmGCM)) then |
(not (FMode = cmGCM)) and |
(Context.KeySize > 0) // added Daniel Marschall 06.05.2024, PR https://github.com/MHumm/DelphiEncryptionCompendium/pull/68 |
then |
raise EDECCipherException.CreateRes(@sNoKeyMaterialGiven); |
if Length(IVector) > 0 then |
1138,6 → 1140,8 |
// This has been fixed in 10.3.0 Rio |
b := ValidFormat(Format).Decode(BytesOf(Source)); |
SetLength(Result, Length(b)); // PR https://github.com/MHumm/DelphiEncryptionCompendium/pull/69 |
{$IFDEF HAVE_STR_LIKE_ARRAY} |
DoDecode(@b[0], @Result[Low(Result)], Length(Result) * SizeOf(Result[Low(Result)])); |
{$ELSE} |