~juju-qa/ubuntu/xenial/juju/2.0-rc2

« back to all changes in this revision

Viewing changes to src/golang.org/x/crypto/pkcs12/internal/rc2/rc2_test.go

  • Committer: Nicholas Skaggs
  • Date: 2016-09-30 14:39:30 UTC
  • mfrom: (1.8.1)
  • Revision ID: nicholas.skaggs@canonical.com-20160930143930-vwwhrefh6ftckccy
import upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright 2015 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 rc2
 
6
 
 
7
import (
 
8
        "bytes"
 
9
        "encoding/hex"
 
10
        "testing"
 
11
)
 
12
 
 
13
func TestEncryptDecrypt(t *testing.T) {
 
14
 
 
15
        // TODO(dgryski): add the rest of the test vectors from the RFC
 
16
        var tests = []struct {
 
17
                key    string
 
18
                plain  string
 
19
                cipher string
 
20
                t1     int
 
21
        }{
 
22
                {
 
23
                        "0000000000000000",
 
24
                        "0000000000000000",
 
25
                        "ebb773f993278eff",
 
26
                        63,
 
27
                },
 
28
                {
 
29
                        "ffffffffffffffff",
 
30
                        "ffffffffffffffff",
 
31
                        "278b27e42e2f0d49",
 
32
                        64,
 
33
                },
 
34
                {
 
35
                        "3000000000000000",
 
36
                        "1000000000000001",
 
37
                        "30649edf9be7d2c2",
 
38
                        64,
 
39
                },
 
40
                {
 
41
                        "88",
 
42
                        "0000000000000000",
 
43
                        "61a8a244adacccf0",
 
44
                        64,
 
45
                },
 
46
                {
 
47
                        "88bca90e90875a",
 
48
                        "0000000000000000",
 
49
                        "6ccf4308974c267f",
 
50
                        64,
 
51
                },
 
52
                {
 
53
                        "88bca90e90875a7f0f79c384627bafb2",
 
54
                        "0000000000000000",
 
55
                        "1a807d272bbe5db1",
 
56
                        64,
 
57
                },
 
58
                {
 
59
                        "88bca90e90875a7f0f79c384627bafb2",
 
60
                        "0000000000000000",
 
61
                        "2269552ab0f85ca6",
 
62
                        128,
 
63
                },
 
64
                {
 
65
                        "88bca90e90875a7f0f79c384627bafb216f80a6f85920584c42fceb0be255daf1e",
 
66
                        "0000000000000000",
 
67
                        "5b78d3a43dfff1f1",
 
68
                        129,
 
69
                },
 
70
        }
 
71
 
 
72
        for _, tt := range tests {
 
73
                k, _ := hex.DecodeString(tt.key)
 
74
                p, _ := hex.DecodeString(tt.plain)
 
75
                c, _ := hex.DecodeString(tt.cipher)
 
76
 
 
77
                b, _ := New(k, tt.t1)
 
78
 
 
79
                var dst [8]byte
 
80
 
 
81
                b.Encrypt(dst[:], p)
 
82
 
 
83
                if !bytes.Equal(dst[:], c) {
 
84
                        t.Errorf("encrypt failed: got % 2x wanted % 2x\n", dst, c)
 
85
                }
 
86
 
 
87
                b.Decrypt(dst[:], c)
 
88
 
 
89
                if !bytes.Equal(dst[:], p) {
 
90
                        t.Errorf("decrypt failed: got % 2x wanted % 2x\n", dst, p)
 
91
                }
 
92
        }
 
93
}