Advertisement
Guest User

Untitled

a guest
Sep 29th, 2022
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.56 KB | Software | 0 0
  1. var
  2.   key, iv, aad, cipher, uncipher: RawByteString;
  3.   expected_tag: RawByteString;
  4.   aes: TAesGcmAbstract;
  5.   tag: THash128;
  6.   dummy: THash256;
  7. begin
  8.   key := hextobin('11111111111111111111111111111111');
  9.   iv := hextobin('4D4554000000000100000000');
  10.   aad := hextobin('3033333333333333333333333333333333');
  11.   //cleartext := hextobin('0fc00000010c07e6091a0103272e5aff8880020209060001190900ff01010206090c07e6091a0103230000ff8880115a1749cb251d1749cb251d1749cb251d1749cb251d');
  12.   cipher := hextobin('b662a493a5dfdbccc1dc832271bae416945f2e0474d102d2c7941fcd50c678534083e5d1520ae04c3038a281d176b6b2a1ce6e15fe861f4689b7fe7909f309908a40f843');
  13.   expected_tag := hextobin('e9ceff7675f00b0e217b7620');
  14.   uncipher := hextobin('00');  // so that it has a valid address
  15.  
  16.   FillZero(tag);
  17.   System.Move(expected_tag[1], tag[0], 12);
  18.  
  19.   DisabledAsm := DisabledAsm + [ daAesGcmAvx ];
  20.   aes := TAesGcm.Create(pointer(key)^, 128);
  21.   try
  22.     aes.IV := PHash128(iv)^;
  23.     aes.MacSetNonce(true, dummy, aad);
  24.     aes.Decrypt(pointer(cipher), pointer(uncipher), 68);
  25.     var a := aes.AesGcmFinal(tag, 12);
  26.     if not a then
  27.       raise Exception.Create('Tag does not match');
  28.   finally
  29.     aes.Free;
  30.   end;
  31.  
  32.   DisabledAsm := DisabledAsm - [ daAesGcmAvx ];
  33.   aes := TAesGcm.Create(pointer(key)^, 128);
  34.   try
  35.     aes.IV := PHash128(iv)^;
  36.     aes.MacSetNonce(true, dummy, aad);
  37.     aes.Decrypt(pointer(cipher), pointer(uncipher), 68);
  38.     var a := aes.AesGcmFinal(tag, 12);
  39.     if not a then
  40.       raise Exception.Create('Tag does not match');
  41.   finally
  42.     aes.Free;
  43.   end;
  44.  
  45. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement