OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [crypto/] [cipher/] [cfb_test.go] - Blame information for rev 858

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// 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 TestCFB(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
        iv := make([]byte, block.BlockSize())
23
        rand.Reader.Read(iv)
24
        cfb := NewCFBEncrypter(block, iv)
25
        ciphertext := make([]byte, len(plaintext))
26
        cfb.XORKeyStream(ciphertext, plaintext)
27
 
28
        cfbdec := NewCFBDecrypter(block, iv)
29
        plaintextCopy := make([]byte, len(plaintext))
30
        cfbdec.XORKeyStream(plaintextCopy, ciphertext)
31
 
32
        if !bytes.Equal(plaintextCopy, plaintext) {
33
                t.Errorf("got: %x, want: %x", plaintextCopy, plaintext)
34
        }
35
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.