package cipher
-type ocfb struct {
+type ocfbEncrypter struct {
b Block
fre []byte
outUsed int
return nil, nil
}
- x := &ocfb{
+ x := &ocfbEncrypter{
b: block,
fre: make([]byte, blockSize),
outUsed: 0,
return x, prefix
}
+func (x *ocfbEncrypter) XORKeyStream(dst, src []byte) {
+ for i := 0; i < len(src); i++ {
+ if x.outUsed == len(x.fre) {
+ x.b.Encrypt(x.fre, x.fre)
+ x.outUsed = 0
+ }
+
+ x.fre[x.outUsed] ^= src[i]
+ dst[i] = x.fre[x.outUsed]
+ x.outUsed++
+ }
+}
+
+type ocfbDecrypter struct {
+ b Block
+ fre []byte
+ outUsed int
+}
+
// NewOCFBDecrypter returns a Stream which decrypts data with OpenPGP's cipher
// feedback mode using the given Block. Prefix must be the first blockSize + 2
// bytes of the ciphertext, where blockSize is the Block's block size. If an
return nil
}
- x := &ocfb{
+ x := &ocfbDecrypter{
b: block,
fre: make([]byte, blockSize),
outUsed: 0,
return x
}
-func (x *ocfb) XORKeyStream(dst, src []byte) {
+func (x *ocfbDecrypter) XORKeyStream(dst, src []byte) {
for i := 0; i < len(src); i++ {
if x.outUsed == len(x.fre) {
x.b.Encrypt(x.fre, x.fre)
x.outUsed = 0
}
+ c := src[i]
dst[i] = x.fre[x.outUsed] ^ src[i]
+ x.fre[x.outUsed] = c
x.outUsed++
}
}