package aes
import (
)
type CBCEncrypter struct {
b Block
iv [BlockSize]byte
}
func ( *Block, [BlockSize]byte) *CBCEncrypter {
return &CBCEncrypter{b: *, iv: }
}
func ( *CBCEncrypter) () int { return BlockSize }
func ( *CBCEncrypter) (, []byte) {
if len()%BlockSize != 0 {
panic("crypto/cipher: input not full blocks")
}
if len() < len() {
panic("crypto/cipher: output smaller than input")
}
if alias.InexactOverlap([:len()], ) {
panic("crypto/cipher: invalid buffer overlap")
}
fips140.RecordApproved()
if len() == 0 {
return
}
cryptBlocksEnc(&.b, &.iv, , )
}
func ( *CBCEncrypter) ( []byte) {
if len() != len(.iv) {
panic("cipher: incorrect length IV")
}
copy(.iv[:], )
}
func ( *Block, *[BlockSize]byte, , []byte) {
:= [:]
for len() > 0 {
subtle.XORBytes([:BlockSize], [:BlockSize], )
encryptBlock(, [:BlockSize], [:BlockSize])
= [:BlockSize]
= [BlockSize:]
= [BlockSize:]
}
copy([:], )
}
type CBCDecrypter struct {
b Block
iv [BlockSize]byte
}
func ( *Block, [BlockSize]byte) *CBCDecrypter {
return &CBCDecrypter{b: *, iv: }
}
func ( *CBCDecrypter) () int { return BlockSize }
func ( *CBCDecrypter) (, []byte) {
if len()%BlockSize != 0 {
panic("crypto/cipher: input not full blocks")
}
if len() < len() {
panic("crypto/cipher: output smaller than input")
}
if alias.InexactOverlap([:len()], ) {
panic("crypto/cipher: invalid buffer overlap")
}
fips140.RecordApproved()
if len() == 0 {
return
}
cryptBlocksDec(&.b, &.iv, , )
}
func ( *CBCDecrypter) ( []byte) {
if len() != len(.iv) {
panic("cipher: incorrect length IV")
}
copy(.iv[:], )
}
func ( *Block, *[BlockSize]byte, , []byte) {
:= len()
:= - BlockSize
:= - BlockSize
:= *
copy([:], [:])
for >= 0 {
decryptBlock(, [:], [:])
if > 0 {
subtle.XORBytes([:], [:], [:])
} else {
subtle.XORBytes([:], [:], [:])
}
-= BlockSize
-= BlockSize
-= BlockSize
}
}