When creating a SealedBox, one of the parameters which needs to be passed is an authentication tag:
https://developer.apple.com/documentation/cryptokit/aes/gcm/sealedbox/init(nonce:ciphertext:tag:)
I have 2 questions about this:
- What should this authentication tag be? I have seen quite a few examples online where they simply pass an empty data buffer:
Data(). For example here:
they say: "You should not provide a pre determined tag while encrypting."
Is passing an empty data buffer okay from a security point of view?
- If I pass something else - lets say some random data - as the authentication tag, how would the person decrypting it know about this tag? Can it be safely sent publicly? How should both parties come up with the same
authentication tag?
EDIT:
Here's my encryptedData function which has an authenticating parameter.
func encryptedData(decryptedData : Data, key : SymmetricKey) throws -> Data {
let sealedMessage = try AES.GCM.seal(decryptedData, using: key, nonce: AES.GCM.Nonce(), authenticating: Data())
guard let encryptedData = sealedMessage.combined else {
throw "Error in sealedMessage"
}
return encryptedData
}
encryptedData. I am using thesealfunction yes. Apple describes it here. ThesealedMessage.combinedcombines the nonce, authentication tag and the cipher in one. However, I still don't know if passing an empty data buffer to theauthenticatingis okay? – sudoExclamationExclamation Feb 01 '24 at 22:55authenticatedDatais the AD part of Authenticated Encrypted with Associated Data (AEAD). Again a stupid naming by Apple people. Look at this picture and search forAuth Data 1. This data is not encrypted however authenticated. Can be used in protocols to clarify the data without decryption. – kelalaka Feb 01 '24 at 23:25authenticationDatais actually some additional data which can be authenticated? Can I use it to pass additional information such as "chunk number" and "total number of chunks" when encrypting large files by breaking into smaller chunks? That way, can I use it to ensure order and size of the large file? – sudoExclamationExclamation Feb 02 '24 at 00:00authenticationDataof the last chunk maybe? Or is there a better way? – sudoExclamationExclamation Feb 02 '24 at 14:27