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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libgo/] [go/] [crypto/] [rc4/] [rc4_test.go] - Blame information for rev 747

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 747 jeremybenn
// Copyright 2009 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 rc4
6
 
7
import (
8
        "testing"
9
)
10
 
11
type rc4Test struct {
12
        key, keystream []byte
13
}
14
 
15
var golden = []rc4Test{
16
        // Test vectors from the original cypherpunk posting of ARC4:
17
        //   http://groups.google.com/group/sci.crypt/msg/10a300c9d21afca0?pli=1
18
        {
19
                []byte{0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef},
20
                []byte{0x74, 0x94, 0xc2, 0xe7, 0x10, 0x4b, 0x08, 0x79},
21
        },
22
        {
23
                []byte{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
24
                []byte{0xde, 0x18, 0x89, 0x41, 0xa3, 0x37, 0x5d, 0x3a},
25
        },
26
        {
27
                []byte{0xef, 0x01, 0x23, 0x45},
28
                []byte{0xd6, 0xa1, 0x41, 0xa7, 0xec, 0x3c, 0x38, 0xdf, 0xbd, 0x61},
29
        },
30
 
31
        // Test vectors from the Wikipedia page: http://en.wikipedia.org/wiki/RC4
32
        {
33
                []byte{0x4b, 0x65, 0x79},
34
                []byte{0xeb, 0x9f, 0x77, 0x81, 0xb7, 0x34, 0xca, 0x72, 0xa7, 0x19},
35
        },
36
        {
37
                []byte{0x57, 0x69, 0x6b, 0x69},
38
                []byte{0x60, 0x44, 0xdb, 0x6d, 0x41, 0xb7},
39
        },
40
}
41
 
42
func TestGolden(t *testing.T) {
43
        for i := 0; i < len(golden); i++ {
44
                g := golden[i]
45
                c, err := NewCipher(g.key)
46
                if err != nil {
47
                        t.Errorf("Failed to create cipher at golden index %d", i)
48
                        return
49
                }
50
                keystream := make([]byte, len(g.keystream))
51
                c.XORKeyStream(keystream, keystream)
52
                for j, v := range keystream {
53
                        if g.keystream[j] != v {
54
                                t.Errorf("Failed at golden index %d", i)
55
                                break
56
                        }
57
                }
58
        }
59
}

powered by: WebSVN 2.1.0

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