OLD | NEW |
(Empty) | |
| 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. |
| 4 |
| 5 package cipher |
| 6 |
| 7 import ( |
| 8 "bytes" |
| 9 "crypto/aes" |
| 10 "crypto/rand" |
| 11 "testing" |
| 12 ) |
| 13 |
| 14 func TestOCFB(t *testing.T) { |
| 15 block, err := aes.NewCipher(commonKey128) |
| 16 if err != nil { |
| 17 t.Error(err) |
| 18 return |
| 19 } |
| 20 |
| 21 plaintext := []byte("this is the plaintext") |
| 22 randData := make([]byte, block.BlockSize()) |
| 23 rand.Reader.Read(randData) |
| 24 ocfb, prefix := NewOCFBEncrypter(block, randData) |
| 25 ciphertext := make([]byte, len(plaintext)) |
| 26 ocfb.XORKeyStream(ciphertext, plaintext) |
| 27 |
| 28 ocfbdec := NewOCFBDecrypter(block, prefix) |
| 29 if ocfbdec == nil { |
| 30 t.Error("NewOCFBDecrypter failed") |
| 31 return |
| 32 } |
| 33 plaintextCopy := make([]byte, len(plaintext)) |
| 34 ocfbdec.XORKeyStream(plaintextCopy, ciphertext) |
| 35 |
| 36 if !bytes.Equal(plaintextCopy, plaintext) { |
| 37 t.Errorf("got: %x, want: %x", plaintextCopy, plaintext) |
| 38 } |
| 39 } |
OLD | NEW |