Update to 5.0.9.5 from 4.3.3.0 (or something like that)

I have some problems after update From Delphi 12 CP 4.3.3.0 (??) to Delphi13 CP 5.0.9.5
I haven't found any release notes. It seems there are new units, such as CryptoConst.

I'm still having these compile-time issues:

var
  Speck: TSPECKEncryption;
begin
    Speck.WordSizeBits := wsb64;           // WordSizeBits 64
    Speck.KeySizeWords := ksw4;            // KeySizeWords 4

WordSizeBits and KeySizeWords no longer exist.

var
  sha3: TSHA3Hash;
begin
    sha3.HashSizeBits := 256 * 8;          // 224, 256, 384 or 512 bits in classical SHA-3, any value in extended SHA-3

HashSizeBits no longer exist.

What do I have to do here?

Hi,
I have simplified Speck and there is a warning in the .pas file:
{ FOR SECURITY REASONS, THIS IMPLEMENTATION IS NOW LIMITED TO }
{ VERSIONS USING 128 bit blocks and 128, 192 and 256 bit KEYS }
You just need to set the key and the parameters will be computed from there.

For SHA3, there is a new property, HashSize: THSize3
with THSize3 = (shs224, shs256, shs384, shs512, shs1024);

SHA3.HashSize := shs256; should work.

And, yes, there are several new units, including CryptoConst. The latter to share constants and reduce their number across files.

Hope this clarifies the issues.

Ok, it works.
Thank you.

OK, good.

Sorry, now I have a problem with the new config.
I cannot read the data written by my old release.

I have a string (which is read from a configuration file) and need to decode it.

Here's my source code. You can see the commented lines (WordSizeBits and KeySizeWords). Do I need to set anything special to be able to read the old data again?

function DecodeName_intern( EncodedName, Key32: String) : String;
var
  Speck: TSPECKEncryption;
begin
  result := '';
  Speck := TSPECKEncryption.Create(nil);   // Speck Chiffrierung (ähnlich wie AES, optimiert für Performance in Software)
                                           // https://en.wikipedia.org/wiki/Speck_(cipher)
  try
    Speck.AType := stCBC;                  // Cipher Block Chaining (besser als ECB)
//    Speck.WordSizeBits := wsb64;           // WordSizeBits 64
//    Speck.KeySizeWords := ksw4;            // KeySizeWords 4
    Speck.OutputFormat := base64url;       // Output base64url ist wie base64 nur Filename konform (also ohne + (plus) usw.
    Speck.Key := Key32;
    Speck.Unicode := yesUni;
    Speck.PaddingMode := TSPECKPaddingMode.PKCS7;   // Anpassung der Länge  | aus Doku: TSPECKPaddingMode = (PKCS7, nopadding);
    Speck.IVMode := TSPECKIVMode.rand;              // aus Doku: TSPECKIVMode = (rand, userdefined);
    result := Speck.Decrypt( EncodedName); // entschlüsseln
  finally
    Speck.Free;
  end;
end;

I suppose you encrypted with:

    Speck.OutputFormat := base64url;

If yes, then you need to convert either the key or the cryptogram when you decrypt as they have to have the same format. Let's take the cryptogram:

var
Conv: TConvert;
...
Conv := TConvert.Create(base64url);
EncodedName := Conv.FormatToChar(EncodedName); // convert to 'raw', key is already 'raw'
...
Speck.OutputFormat := rawl;       // to recover the original string
result := Speck.Decrypt( EncodedName);
Conv.Free;

Unfortunately, that doesn't work.
I'll reinstall version 4.x first. I've installed too many versions at the customer's site, so I need to come up with a plan for how to solve this in the future.

Here is my test code, with several keys:

procedure TMainForm.SpeckBtnClick(Sender: TObject);
var
  MySpeck: TSPECKEncryption;
  s: string;
  conv: TConvert;

begin
  MySpeck := TSPECKEncryption.Create;
  MySpeck.Key := #0#1#2#3#4#5#6#7#8#9#$a#$b#$c#$d#$e#$f#$10#$11#$12#$13#$14#$15#$16#$17#$18#$19#$1a#$1b#$1c#$1d#$1e#$1f;
//  MySpeck.Key := #0#1#2#3#4#5#6#7#8#9#$a#$b#$c#$d#$e#$f#$10#$11#$12#$13#$14#$15#$16#$17;
//  MySpeck.Key := #0#1#2#3#4#5#6#7#8#9#$a#$b#$c#$d#$e#$f;

  // default values - already set
  // MySpeck.FInputFormat  := raw;
  // MySpeck.FOutputFormat := hexa;

  MySpeck.IV          := #8#7#6#5#4#3#2#1#8#7#6#5#4#3#2#1;
  MySpeck.IVMode      := rand; // can switch to userdefined if need be
  MySpeck.AType       := stCBC;
  MySpeck.PaddingMode := PKCS7;
  s := MySpeck.Encrypt('pooner. In those days life was more challenging and really nice.');
  MainMemo.Lines.Add(s);

  conv := TConvert.Create(hexa);
  s := conv.FormatToChar(s);
  s := MySpeck.Decrypt(s);
  MainMemo.Lines.Add(s);

  conv.Free;
  MySpeck.Free;
end;

Could you send me you encrypt sequence at bernard@tmssoftware.com?

I have send an email.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.