Advertisement
Guest User

Untitled

a guest
Sep 29th, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.14 KB | Software | 0 0
  1. var
  2.   key, iv, aad, ocipher, cipher, uncipher, cleartext: RawByteString;
  3.   aes: TAesGcmAbstract;
  4.   tag: THash128;
  5.   dummy: THash256;
  6.   same: boolean;
  7. begin
  8.   key := hextobin('11111111111111111111111111111111');
  9.   iv := hextobin('4D4554000000000100000000');
  10.   aad := hextobin('3033333333333333333333333333333333');
  11.   cleartext := hextobin('0fc00000010c07e6091a0103272e5aff8880020209060001190900ff01010206090c07e6091a0103230000ff8880115a1749cb251d1749cb251d1749cb251d1749cb251d');
  12.  
  13.   var tmp := hextobin('e9ceff7675f00b0e217b7620');
  14.  
  15.     FillZero(tag);
  16.   aes := TAesGcm.Create(pointer(key)^, 128);
  17.   try
  18.     aes.IV := PHash128(iv)^;
  19.     aes.MacSetNonce(false, dummy, aad);
  20.     cipher := aes.EncryptPkcs7(cleartext);
  21.     aes.AesGcmFinal(tag);
  22.     // here (tag = tmp) -> FALSE in both Win64 and Win32
  23.   finally
  24.     aes.Free;
  25.   end;
  26.  
  27.  
  28.   FillZero(tag);
  29.   aes := TAesGcm.Create(pointer(key)^, 128);
  30.   try
  31.     aes.IV := PHash128(iv)^;
  32.     aes.MacSetNonce(true, dummy, aad);
  33.     aes.Encrypt(pointer(cleartext), pointer(cipher), 68);
  34.     aes.AesGcmFinal(tag);
  35.     // here (tag = tmp) -> FALSE in Win32
  36.   finally
  37.     aes.Free;
  38.   end;
  39.  
  40. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement