Comments (4)
Sorry for only finding time to follow up on this now.
Do you have any sample code demoing this? That would really help investigating and fixing this.
from delphiencryptioncompendium.
I did a test now (will publish the code used later). 10.000 iterations each for 2DES encrypting/decrypting the same string and comparing the result. Works flawlessly for 2DES and 3DES but seems to have a general failure for Shark, as there it produced 10.000 failures as the decrypted string never matched the plain text fed into the encryption method.
Mode used was CFB each time and cipher key etc. were all the same each time.
For me this suggests, that 2DES and 3DES do work but Shark has a general problem, despite having a unit test for it with data derived from the old 5.2/5.3 test program which does not report any error.
from delphiencryptioncompendium.
As promised here the code of the test application used. Does anybody spot any flaws in my test?
program Shark_3DES_2DES_Bugtest;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
DECCipherModes in '..\Source\DECCipherModes.pas',
DECCiphers in '..\Source\DECCiphers.pas',
DECBaseClass in '..\Source\DECBaseClass.pas',
DECCipherBase in '..\Source\DECCipherBase.pas',
DECCipherFormats in '..\Source\DECCipherFormats.pas',
DECCRC in '..\Source\DECCRC.pas',
DECFormat in '..\Source\DECFormat.pas',
DECFormatBase in '..\Source\DECFormatBase.pas',
DECUtil in '..\Source\DECUtil.pas',
DECTypes in '..\Source\DECTypes.pas',
DECUtilRawByteStringHelper in '..\Source\DECUtilRawByteStringHelper.pas',
DECData in '..\Source\DECData.pas',
DECCipherInterface in '..\Source\DECCipherInterface.pas';
var
Cipher : TCipher_Shark;
// We use raw byte string here since Unicode handling of Windows console
// is not given
SourceText : RawByteString;
CipherText : string;
// Key for the initialization of our encryption run
CipherKey : RawByteString;
IV : RawByteString;
Input,
Output : TBytes;
i, n, ErrC : Integer;
const
cPlainText = 'Beispielklartext';
begin
Cipher := TCipher_Shark.Create;
// number of decryption failures
ErrC := 0;
try
try
for n := 1 to 10000 do
begin
// Init our encryption
CipherKey := 'Passwort';
IV := #0#0#0#0#0#0#0#0;
Cipher.Init(CipherKey, IV, 0);
Cipher.Mode := cmCBCx;
SourceText := cPlainText; //'Beispielklartext';
WriteLn(n:5, ' Source text: ' + SourceText);
Input := System.SysUtils.BytesOf(SourceText);
Write(n:5, ' Source text in hex: ');
for i := 0 to high(Input) do
Write(IntToHex(Input[i], 2), ' ');
WriteLn;
// Encrypt
Output := Cipher.EncodeBytes(Input);
Write(n:5, ' Encrypted data in hex: ');
for i := 0 to high(Output) do
Write(IntToHex(Output[i], 2), ' ');
WriteLn;
// Decrypt
Cipher.Init(CipherKey, IV, 0);
Output := Cipher.DecodeBytes(Output);
SourceText := System.SysUtils.StringOf(Output);
WriteLn(n:5, ' Decrypted data: ' + SourceText);
if SourceText <> cPlainText then
begin
inc(ErrC);
WriteLn('Decryption error!');
end;
// Show that using a different key results in a different output
WriteLn;
CipherKey := 'Password';
Cipher.Init(CipherKey, IV, 0);
Output := Cipher.DecodeBytes(Output);
SourceText := System.SysUtils.StringOf(Output);
WriteLn('Decrypted with different key: ' + SourceText);
end;
WriteLn;
WriteLn('Number of decription errors ', ErrC);
ReadLn;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
finally
Cipher.Free;
end;
end.
from delphiencryptioncompendium.
Did another test with Shark cipher now. When changing the cipher key from 'Passwort' to 'TCipher_Shark', which is longer, it properly encrypts and decrypts the encrypted text. This has been run 10.000 times in a loop as well so I cannot find any failure. At least not with the simplistic description of @piker00. So I close this one now.
from delphiencryptioncompendium.
Related Issues (20)
- Can't execute PBKDF2 key derivation function. Please help HOT 1
- Urgent: Migration from DEC 5.2 library (Part2 - decrypt).
- Are there plans to support bcrypt ? HOT 2
- DECCipherInterface error HOT 12
- THash_SHA1.PBKDF2 create wrong Results HOT 13
- Range Check Error in TDECCipherModes.EncodeCBCx() HOT 5
- no compile on Linux HOT 18
- Incorrect auth tag generated for GCM mode when feeding data using small chunks HOT 8
- Missing padding for ECB mode HOT 12
- 3DES DoEncode()/DoDecode() Source overwriting Dest problem HOT 10
- Integer Overflow when hashing a large TFilestream HOT 5
- Installing in Delphi 2010 HOT 1
- Implement HMACStream and HMACFile HOT 7
- Question about processing of last block of data using Done HOT 17
- Testcases failure HOT 9
- "VCL" vs "VLC" typo in samples HOT 1
- Random padding / Confusion about "IV" padding vs "Last block" padding? HOT 4
- Access violation if GCM mode is set after cipher is initialized
- Change IV HOT 2
- Range Check Exception when using KDF with empty password HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delphiencryptioncompendium.