1 // Copyright 2010 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // CFB (Cipher Feedback) Mode.
18 func (x
*cfb
) XORKeyStream(dst
, src
[]byte) {
20 if x
.outUsed
== len(x
.out
) {
21 x
.b
.Encrypt(x
.out
, x
.next
)
26 // We can precompute a larger segment of the
27 // keystream on decryption. This will allow
28 // larger batches for xor, and we should be
29 // able to match CTR/OFB performance.
30 copy(x
.next
[x
.outUsed
:], src
)
32 n
:= xorBytes(dst
, src
, x
.out
[x
.outUsed
:])
34 copy(x
.next
[x
.outUsed
:], dst
)
42 // NewCFBEncrypter returns a Stream which encrypts with cipher feedback mode,
43 // using the given Block. The iv must be the same length as the Block's block
45 func NewCFBEncrypter(block Block
, iv
[]byte) Stream
{
46 return newCFB(block
, iv
, false)
49 // NewCFBDecrypter returns a Stream which decrypts with cipher feedback mode,
50 // using the given Block. The iv must be the same length as the Block's block
52 func NewCFBDecrypter(block Block
, iv
[]byte) Stream
{
53 return newCFB(block
, iv
, true)
56 func newCFB(block Block
, iv
[]byte, decrypt
bool) Stream
{
57 blockSize
:= block
.BlockSize()
58 if len(iv
) != blockSize
{
59 // stack trace will indicate whether it was de or encryption
60 panic("cipher.newCFB: IV length must equal block size")
64 out
: make([]byte, blockSize
),
65 next
: make([]byte, blockSize
),