package gcm
import (
)
func ( []byte, *GCM, , , []byte) {
var , , [gcmBlockSize]byte
aes.EncryptBlockInternal(&.cipher, [:], [:])
deriveCounterGeneric(&, &, )
gcmCounterCryptGeneric(&.cipher, [:], [:], &)
gcmCounterCryptGeneric(&.cipher, , , &)
var [gcmTagSize]byte
gcmAuthGeneric([:], &, &, [:len()], )
copy([len():], [:])
}
func ( []byte, *GCM, , , []byte) error {
var , , [gcmBlockSize]byte
aes.EncryptBlockInternal(&.cipher, [:], [:])
deriveCounterGeneric(&, &, )
gcmCounterCryptGeneric(&.cipher, [:], [:], &)
:= [len()-.tagSize:]
= [:len()-.tagSize]
var [gcmTagSize]byte
gcmAuthGeneric([:], &, &, , )
if subtle.ConstantTimeCompare([:.tagSize], ) != 1 {
return errOpen
}
gcmCounterCryptGeneric(&.cipher, , , &)
return nil
}
func (, *[gcmBlockSize]byte, []byte) {
if len() == gcmStandardNonceSize {
copy([:], )
[gcmBlockSize-1] = 1
} else {
:= make([]byte, 16)
byteorder.BEPutUint64([8:], uint64(len())*8)
ghash(, , , )
}
}
func ( *aes.Block, , []byte, *[gcmBlockSize]byte) {
var [gcmBlockSize]byte
for len() >= gcmBlockSize {
aes.EncryptBlockInternal(, [:], [:])
gcmInc32()
subtle.XORBytes(, , [:])
= [gcmBlockSize:]
= [gcmBlockSize:]
}
if len() > 0 {
aes.EncryptBlockInternal(, [:], [:])
gcmInc32()
subtle.XORBytes(, , [:])
}
}
func ( *[gcmBlockSize]byte) {
:= [len()-4:]
byteorder.BEPutUint32(, byteorder.BEUint32()+1)
}
func ( []byte, , *[gcmBlockSize]byte, , []byte) {
checkGenericIsExpected()
:= make([]byte, 16)
byteorder.BEPutUint64([:8], uint64(len())*8)
byteorder.BEPutUint64([8:], uint64(len())*8)
var [gcmBlockSize]byte
ghash(&, , , , )
subtle.XORBytes(, [:], [:])
}