Skip to content

Encryption fail or setup fail? #5

@mmattice

Description

@mmattice

The following code fails. The encryption outputs two blocks when it should only output one. The first 16 bytes of 'outs' does match 'refs' though.

The KAT I'm using is the first on page 20 of http://csrc.nist.gov/groups/STM/cavp/documents/aes/AESAVS.pdf

procedure Check_tplockboxAES.SetUp;
begin
  inherited;
  Codec := TCodec.Create(nil);
  CryptoLib := TCryptographicLibrary.Create(nil);
  Codec.CryptoLibrary := CryptoLib;
  Codec.StreamCipherId := TPLB3.Constants.BlockCipher_ProgId;
  Codec.BlockCipherId := format(TPLB3.Constants.AES_ProgId, [128]);
  Codec.ChainModeId := TPLB3.Constants.ECB_ProgId;
  ks   := TBytesStream.Create();
  ins  := TBytesStream.Create();
  outs := TBytesStream.Create();
  refs := TBytesStream.Create();
end;

procedure Check_tplockboxAES.TearDown;
begin
  inherited;
  ks.free;
  ins.free;
  outs.free;
  refs.free;
end;

procedure Check_tplockboxAES.VerifyEncryptDecryptCycle;
begin
  HexToStream('00000000000000000000000000000000', ks);
  hextostream('80000000000000000000000000000000', ins);
  hextostream('3ad78e726c1ec02b7ebfe92b23d9ec34', refs);
  Codec.InitFromStream(ks);
  Codec.EncryptStream(ins, outs);
  check(comparememorystreams(outs, refs), format('refs: %s  outs: %s', [streamtohex(refs), streamtohex(outs)]));
end;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions