Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- key, iv, aad, cipher, uncipher: RawByteString;
- expected_tag: RawByteString;
- aes: TAesGcmAbstract;
- tag: THash128;
- dummy: THash256;
- begin
- key := hextobin('11111111111111111111111111111111');
- iv := hextobin('4D4554000000000100000000');
- aad := hextobin('3033333333333333333333333333333333');
- //cleartext := hextobin('0fc00000010c07e6091a0103272e5aff8880020209060001190900ff01010206090c07e6091a0103230000ff8880115a1749cb251d1749cb251d1749cb251d1749cb251d');
- cipher := hextobin('b662a493a5dfdbccc1dc832271bae416945f2e0474d102d2c7941fcd50c678534083e5d1520ae04c3038a281d176b6b2a1ce6e15fe861f4689b7fe7909f309908a40f843');
- expected_tag := hextobin('e9ceff7675f00b0e217b7620');
- uncipher := hextobin('00'); // so that it has a valid address
- FillZero(tag);
- System.Move(expected_tag[1], tag[0], 12);
- DisabledAsm := DisabledAsm + [ daAesGcmAvx ];
- aes := TAesGcm.Create(pointer(key)^, 128);
- try
- aes.IV := PHash128(iv)^;
- aes.MacSetNonce(true, dummy, aad);
- aes.Decrypt(pointer(cipher), pointer(uncipher), 68);
- var a := aes.AesGcmFinal(tag, 12);
- if not a then
- raise Exception.Create('Tag does not match');
- finally
- aes.Free;
- end;
- DisabledAsm := DisabledAsm - [ daAesGcmAvx ];
- aes := TAesGcm.Create(pointer(key)^, 128);
- try
- aes.IV := PHash128(iv)^;
- aes.MacSetNonce(true, dummy, aad);
- aes.Decrypt(pointer(cipher), pointer(uncipher), 68);
- var a := aes.AesGcmFinal(tag, 12);
- if not a then
- raise Exception.Create('Tag does not match');
- finally
- aes.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement