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.
14 var commonKey128 = []byte{0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c}
16 func testOCFB(t *testing.T, resync OCFBResyncOption) {
17 block, err := aes.NewCipher(commonKey128)
23 plaintext := []byte("this is the plaintext, which is long enough to span several blocks.")
24 randData := make([]byte, block.BlockSize())
25 rand.Reader.Read(randData)
26 ocfb, prefix := NewOCFBEncrypter(block, randData, resync)
27 ciphertext := make([]byte, len(plaintext))
28 ocfb.XORKeyStream(ciphertext, plaintext)
30 ocfbdec := NewOCFBDecrypter(block, prefix, resync)
32 t.Errorf("NewOCFBDecrypter failed (resync: %t)", resync)
35 plaintextCopy := make([]byte, len(plaintext))
36 ocfbdec.XORKeyStream(plaintextCopy, ciphertext)
38 if !bytes.Equal(plaintextCopy, plaintext) {
39 t.Errorf("got: %x, want: %x (resync: %t)", plaintextCopy, plaintext, resync)
43 func TestOCFB(t *testing.T) {
44 testOCFB(t, OCFBNoResync)
45 testOCFB(t, OCFBResync)