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.
15 func TestCFB(t
*testing
.T
) {
16 block
, err
:= aes
.NewCipher(commonKey128
)
22 plaintext
:= []byte("this is the plaintext. this is the plaintext.")
23 iv
:= make([]byte, block
.BlockSize())
25 cfb
:= cipher
.NewCFBEncrypter(block
, iv
)
26 ciphertext
:= make([]byte, len(plaintext
))
27 copy(ciphertext
, plaintext
)
28 cfb
.XORKeyStream(ciphertext
, ciphertext
)
30 cfbdec
:= cipher
.NewCFBDecrypter(block
, iv
)
31 plaintextCopy
:= make([]byte, len(plaintext
))
32 copy(plaintextCopy
, ciphertext
)
33 cfbdec
.XORKeyStream(plaintextCopy
, plaintextCopy
)
35 if !bytes
.Equal(plaintextCopy
, plaintext
) {
36 t
.Errorf("got: %x, want: %x", plaintextCopy
, plaintext
)