OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / golang.org / x / crypto / chacha20poly1305 / internal / chacha20 / chacha_test.go
1 // Copyright 2016 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 chacha20
6
7 import (
8         "encoding/hex"
9         "testing"
10 )
11
12 func TestCore(t *testing.T) {
13         // This is just a smoke test that checks the example from
14         // https://tools.ietf.org/html/rfc7539#section-2.3.2. The
15         // chacha20poly1305 package contains much more extensive tests of this
16         // code.
17         var key [32]byte
18         for i := range key {
19                 key[i] = byte(i)
20         }
21
22         var input [16]byte
23         input[0] = 1
24         input[7] = 9
25         input[11] = 0x4a
26
27         var out [64]byte
28         XORKeyStream(out[:], out[:], &input, &key)
29         const expected = "10f1e7e4d13b5915500fdd1fa32071c4c7d1f4c733c068030422aa9ac3d46c4ed2826446079faa0914c2d705d98b02a2b5129cd1de164eb9cbd083e8a2503c4e"
30         if result := hex.EncodeToString(out[:]); result != expected {
31                 t.Errorf("wanted %x but got %x", expected, result)
32         }
33 }