Since you are trying to implement AES-GCM encryption, I'm assuming you already know that the two major parts of AES-GCM encryption are:
- The confidentiality of input data using a variant of counter-mode of operation. In your case AES is used as the underlying block cipher.
- The authenticity of the confidential data using GHASH algorithm.
That's mean the plaintext (toEncrypt) needs to be enciphered using the variant of counter-mode and calculate the authentication tag from the resulting ciphertext (cipherText).
additional authenticated data (AAD) protects the confidentiality of plaintext without enciphering it, usually AAD implies small amount of data like version numbers, address, and port..
So you only need to apply the GHASH algorithm on AAD (associatedData) and assign the output tag value of the encrypting operation to the input tag of GHASH algorithm. Note this assumes the scheme that function uses is encrypting input data then hashing AAD, if it's the opposite order you have to assign the output tag of GHASH function for AAD to the input tag of GHASH function for data to encrypt.