package cipher
import
type ofb struct {
b Block
cipher []byte
out []byte
outUsed int
}
func ( Block, []byte) Stream {
:= .BlockSize()
if len() != {
panic("cipher.NewOFB: IV length must equal block size")
}
:= streamBufferSize
if < {
=
}
:= &ofb{
b: ,
cipher: make([]byte, ),
out: make([]byte, 0, ),
outUsed: 0,
}
copy(.cipher, )
return
}
func ( *ofb) () {
:= .b.BlockSize()
:= len(.out) - .outUsed
if > .outUsed {
return
}
copy(.out, .out[.outUsed:])
.out = .out[:cap(.out)]
for < len(.out)- {
.b.Encrypt(.cipher, .cipher)
copy(.out[:], .cipher)
+=
}
.out = .out[:]
.outUsed = 0
}
func ( *ofb) (, []byte) {
if len() < len() {
panic("crypto/cipher: output smaller than input")
}
if subtle.InexactOverlap([:len()], ) {
panic("crypto/cipher: invalid buffer overlap")
}
for len() > 0 {
if .outUsed >= len(.out)-.b.BlockSize() {
.refill()
}
:= xorBytes(, , .out[.outUsed:])
= [:]
= [:]
.outUsed +=
}
}