Which one of these functions are preferred for authenticating AES-CTR?
function encrypt(msg, key) {
encryptionKey, encryptionSalt = newPBKDF2(key)
hmacKey, hmacSalt = newPBKDF2(key)
ciphertext = aesCTR(msg, encryptionKey)
hmac = generateHMAC(ciphertext, hmacKey)
salt = encryptionSalt + hmacSalt
return hmac + salt + ciphertext
}
VS
function encrypt(msg, key) {
encryptionKey, encryptionSalt = newPBKDF2(key)
hmacKey, hmacSalt = newPBKDF2(key)
ciphertext = aesCTR(msg, encryptionKey)
salt = encryptionSalt + hmacSalt
hmac = generateHMAC(salt + ciphertext, hmacKey)
return hmac + salt + ciphertext
}