Last active
September 28, 2022 07:02
-
-
Save synopse/b7051b501122211f6eb7bff4a930af9a to your computer and use it in GitHub Desktop.
AES-GCM tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
key := hextobin('11111111111111111111111111111111'); | |
iv := hextobin('4D4554000000000100000000'); | |
aad := hextobin('3033333333333333333333333333333333'); | |
cleartext := hextobin('0fc00000010c07e6091a0103272e5aff8880020209060001190900ff01010206090c07e6091a0103230000ff8880115a1749cb251d1749cb251d1749cb251d1749cb251d'); | |
while length(cleartext) and 15 <> 0 do | |
cleartext := cleartext + #0; | |
writeln; | |
FillZero(tag); | |
aes := TAesGcm.Create(pointer(key)^, 128); | |
try | |
aes.IV := PHash128(iv)^; | |
aes.Encrypt(nil, nil, 0); | |
aes.AesGcmAad(pointer(aad), length(aad)); | |
SetLength(cipher, length(cleartext)); | |
aes.Encrypt(pointer(cleartext), pointer(cipher), length(cleartext)); | |
aes.AesGcmFinal(tag, 12); | |
writeln('cipher = ', bintohex(cipher)); | |
writeln('tag = ', bintohex(PAnsiChar(@tag), SizeOf(tag))); | |
finally | |
aes.Free; | |
end; | |
writeln; | |
aes := TAesGcm.Create(pointer(key)^, 128); | |
try | |
aes.IV := PHash128(iv)^; | |
aes.MacSetNonce(false, dummy, aad); | |
SetLength(uncipher, length(cipher)); | |
aes.Decrypt(pointer(cipher), pointer(uncipher), length(cipher)); | |
writeln('uncipher = ', bintohex(uncipher)); | |
writeln('tag = ', aes.AesGcmFinal(tag, 12)); | |
finally | |
aes.Free; | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment