Skip to content

Investigate AES-GCM divergence, tag #39

@Archprogrammer

Description

@Archprogrammer

Following up on issue #11

The following code:

    List<int> key128bit=[
      122,140,235,87,
      10,140,37,178,
      172,182,154,240,
      211,126,138,11
    ];
    List<int> encodeIV=[
      0,0,0,0,
      1,1,1,1,
      2,2,2,2
    ];
    String plaintext='a sample plaintext';   // utf-8 encoded in AesCrypt.encrypt()

    AesCrypt encrypter=AesCrypt(
      mode: ModeAES.gcm,
      padding: PaddingAES.pkcs7,   // Setting this to "none" results in an exception
      key: base64.encode(key128bit)
    );

    String result=encrypter.encrypt(plaintext, iv: base64.encode(encodeIV));

    dev.log("plain.length=${plaintext.length}");
    dev.log("result.length=${base64.decode(result).length}");
    dev.log(base64.decode(result).toString());

Results in the output :

[log] plain.length=18
[log] result.length=32
[log] [57, 126, 210, 236, 146, 205, 233, 139, 16, 45, 193, 146, 164, 250, 98, 165, 147, 120, 153, 51, 116, 146, 11, 111, 218, 175, 8, 183, 211, 164, 245, 44]

Encrypting the same string (in utf-8) with the same key and the same IV in Firefox using subtle.crypto (but setting tag-length to 96 bits) results in the following byte sequence:

[ 57 126 210 236 146 205 233 139 16 45 193 146 164 250 98 165 147 120  73 255 75 137 95 252 156 90 215 157 98 122 ]

The sequences match for the first 18 bytes after which they diverge - if I understand it correctly, they should be identical (to the shortest length).

Furthermore, as referenced in #11 , an input string of 88 bytes resulted in a 64-bit tag (8 bytes) but this sample code results in a 112-bit tag (14 bytes).

To sum it up - there appears to be two major and one minor problem:

  1. The AES-GCM tag appears garbled.
  2. There is no way (currently) to set the tag length.
  3. (minor) PaddingAES.none results in an exception.

If I can provide any more information or help in any other way, just ask.

Metadata

Metadata

Assignees

Labels

bugfixSomething isn't workingcross-languageThis issue pertains to both Dart and another language.in progressEnhancement is being worked on for next release

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions