blob: c1086d1d29ef8c5f4997479b3aa3c1645941c856 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
// +build !without_openssl
// We compare against Go's built-in GCM implementation. Since stupidgcm only
// supports 128-bit IVs and Go only supports that from 1.5 onward, we cannot
// run these tests on older Go versions.
package stupidgcm
import (
"testing"
"golang.org/x/crypto/chacha20poly1305"
)
// TestEncryptDecrypt encrypts and decrypts using both stupidgcm and Go's built-in
// GCM implementation and verifies that the results are identical.
func TestEncryptDecryptChacha(t *testing.T) {
key := randBytes(32)
c := newChacha20poly1305(key)
ref, err := chacha20poly1305.New(key)
if err != nil {
t.Fatal(err)
}
testEncryptDecrypt(t, c, ref)
}
// Seal re-uses the "dst" buffer it is large enough.
// Check that this works correctly by testing different "dst" capacities from
// 5000 to 16 and "in" lengths from 1 to 5000.
func TestInplaceSealChacha(t *testing.T) {
key := randBytes(32)
c := newChacha20poly1305(key)
ref, err := chacha20poly1305.New(key)
if err != nil {
t.Fatal(err)
}
testInplaceSeal(t, c, ref)
}
// Open re-uses the "dst" buffer it is large enough.
// Check that this works correctly by testing different "dst" capacities from
// 5000 to 16 and "in" lengths from 1 to 5000.
func TestInplaceOpenChacha(t *testing.T) {
key := randBytes(32)
c := newChacha20poly1305(key)
ref, err := chacha20poly1305.New(key)
if err != nil {
t.Fatal(err)
}
testInplaceOpen(t, c, ref)
}
// TestCorruption verifies that changes in the ciphertext result in a decryption
// error
func TestCorruptionChacha(t *testing.T) {
key := randBytes(32)
c := newChacha20poly1305(key)
testCorruption(t, c)
}
|