Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- procedure TForm371.Button1Click(Sender: TObject);
- var
- KeyArray: TBytes;
- iv: TBytes;
- mmIV: TAESBlock;
- clearText: TBytes;
- aad: TBytes;
- ciphertext: TBytes;
- checktag : TAESBlock;
- checktag2 : TAESBlock;
- checktag4 : TAESBlock;
- checktag3 : TAESBlock;
- rawClear : RawByteString;
- rawciphertext : RawByteString;
- aad2 : TAESKey;
- begin
- KeyArray := [$11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11, $11];
- iv := [$4D, $45, $54, $00, $00, $00, $00, $01, $00, $00, $00, $00];
- FillChar(mmIv, 16, 0);
- System.Move(iv[0], mmIv, System.Length(iv) );
- cleartext := [$0f, $c0, $00, $00, $01, $0c, $07, $e6, $09, $1a, $01, $03, $27, $2e, $5a, $ff, $88, $80, $02, $02, $09, $06, $00, $01, $19, $09, $00, $ff, $01, $01, $02, $06, $09, $0c, $07, $e6, $09, $1a, $01, $03, $23, $00, $00, $ff, $88, $80, $11, $5a, $17, $49, $cb, $25, $1d, $17, $49, $cb, $25, $1d, $17, $49, $cb, $25, $1d, $17, $49, $cb, $25, $1d];
- aad := [$30, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33, $33];
- setlength(ciphertext, length(cleartext));
- var mAES := TAESGCM.Create(KeyArray); try
- mAES.IV := mmIv;
- mAES.Encrypt(nil, nil, 0);
- mAES.AesGcmAad(Pointer(aad), System.Length(aad));
- rawciphertext := mAES.EncryptPkcs7(Convert(cleartext));
- Move(rawciphertext[1], ciphertext[0], length(rawciphertext));
- FillChar(checktag, 16, 255);
- mAES.AesGcmFinal(checktag);
- finally
- mAES.Free;
- end;
- var mAES2 := TAESGCM.Create(KeyArray);
- try
- mAES2.IV := mmIv;
- mAES2.Encrypt(nil, nil, 0);
- rawciphertext := mAES.EncryptPkcs7(Convert(cleartext));
- FillChar(checktag2, 16, 255);
- mAES2.AesGcmFinal(checktag2);
- finally
- mAES2.Free;
- end;
- var mAES3 := TAESGCM.Create(KeyArray);
- try
- mAES3.IV := mmIv;
- mAES3.Encrypt(nil, nil, 0);
- System.Move(aad[0], aad2[0], 12);
- // Use MacSetNonce instead of AesGcmAAD
- mAES3.MacSetNonce(False, aad2);
- rawciphertext := mAES3.EncryptPkcs7(Convert(cleartext));
- FillChar(checktag3, 16, 255);
- mAES3.AesGcmFinal(checktag3);
- finally
- mAES3.Free;
- end;
- var mAES4 := TAESGCM.Create(KeyArray);
- try
- mAES4.IV := mmIv;
- mAES4.Encrypt(nil, nil, 0);
- rawClear := Convert(iv) + Convert([$00, $00, $00, $00]) + Convert(cleartext);
- rawciphertext := mAES4.MacAndCrypt(rawClear, True, True, '3033333333333333333333333333333333');
- FillChar(checktag4, 16, 255);
- mAES4.AesGcmFinal(checktag4);
- finally
- mAES4.Free;
- end;
- end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement