Как реализовать aes-256-gcm в delphi?
Не могу написать функцию для расшифровки строки, используя алгоритм aes-256-gcm. Использую SynCrypto Вот перечень функций из модуля SynCrypto.pas :
type
/// low-level AES-GCM processing
// - implements standard AEAD (authenticated-encryption with associated-data)
// algorithm, as defined by NIST and
TAESGCMEngine = object
private
/// standard AES encryption context
// - will use AES-NI if available
actx: TAES;
/// ghash value of the Authentication Data
aad_ghv: TAESBlock;
/// ghash value of the Ciphertext
txt_ghv: TAESBlock;
/// ghash H current value
ghash_h: TAESBlock;
/// number of Authentication Data bytes processed
aad_cnt: TQWordRec;
/// number of bytes of the Ciphertext
atx_cnt: TQWordRec;
/// initial 32-bit ctr val - to be reused in Final()
y0_val: integer;
/// current 0..15 position in encryption block
blen: byte;
/// the state of this context
flags: set of (flagInitialized, flagFinalComputed, flagFlushed);
/// lookup table for fast Galois Finite Field multiplication
// - is defined as last field of the object for better code generation
gf_t4k: array[byte] of TAESBlock;
/// build the gf_t4k[] internal table - assuming set to zero by caller
procedure Make4K_Table;
/// compute a * ghash_h in Galois Finite Field 2^128
procedure gf_mul_h(var a: TAESBlock); {$ifdef FPC} inline; {$endif}
/// low-level AES-CTR encryption
procedure internal_crypt(ptp, ctp: PByte; ILen: PtrUInt);
/// low-level GCM authentication
procedure internal_auth(ctp: PByte; ILen: PtrUInt;
var ghv: TAESBlock; var gcnt: TQWordRec);
public
/// initialize the AES-GCM structure for the supplied Key
function Init(const Key; KeyBits: PtrInt): boolean;
/// start AES-GCM encryption with a given Initialization Vector
// - IV_len is in bytes use 12 for exact IV setting, otherwise the
// supplied buffer will be hashed using gf_mul_h()
function Reset(pIV: pointer; IV_len: PtrInt): boolean;
/// encrypt a buffer with AES-GCM, updating the associated authentication data
function Encrypt(ptp, ctp: Pointer; ILen: PtrInt): boolean;
/// decrypt a buffer with AES-GCM, updating the associated authentication data
// - also validate the GMAC with the supplied ptag/tlen if ptag<>nil,
// and skip the AES-CTR phase if the authentication doesn't match
function Decrypt(ctp, ptp: Pointer; ILen: PtrInt;
ptag: pointer=nil; tlen: PtrInt=0): boolean;
/// append some data to be authenticated, but not encrypted
function Add_AAD(pAAD: pointer; aLen: PtrInt): boolean;
/// finalize the AES-GCM encryption, returning the authentication tag
// - will also flush the AES context to avoid forensic issues, unless
// andDone is forced to false
function Final(out tag: TAESBlock; andDone: boolean=true): boolean;
/// flush the AES context to avoid forensic issues
// - do nothing if Final() has been already called
procedure Done;
/// single call AES-GCM encryption and authentication process
function FullEncryptAndAuthenticate(const Key; KeyBits: PtrInt;
pIV: pointer; IV_len: PtrInt; pAAD: pointer; aLen: PtrInt;
ptp, ctp: Pointer; pLen: PtrInt; out tag: TAESBlock): boolean;
/// single call AES-GCM decryption and verification process
function FullDecryptAndVerify(const Key; KeyBits: PtrInt;
pIV: pointer; IV_len: PtrInt; pAAD: pointer; aLen: PtrInt;
ctp, ptp: Pointer; pLen: PtrInt; ptag: pointer; tLen: PtrInt): boolean;
end;
Только в виду своей малообразованности в программировании и отсутствии примеров, не пойму как их заюзать. Помогите составить каркас действий.