xref: /aosp_15_r20/external/tink/go/internal/aead/aead_test.go (revision e7b1675dde1b92d52ec075b0a92829627f2c52a5)
1// Copyright 2022 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14//
15////////////////////////////////////////////////////////////////////////////////
16
17package aead_test
18
19import (
20	"testing"
21
22	"github.com/google/tink/go/internal/aead"
23	"github.com/google/tink/go/testutil"
24)
25
26type AEADSuite struct {
27	testutil.WycheproofSuite
28	TestGroups []*AEADGroup `json:"testGroups"`
29}
30
31type AEADGroup struct {
32	testutil.WycheproofGroup
33	IVSize  uint32      `json:"ivSize"`
34	KeySize uint32      `json:"keySize"`
35	TagSize uint32      `json:"tagSize"`
36	Type    string      `json:"type"`
37	Tests   []*AEADCase `json:"tests"`
38}
39
40type AEADCase struct {
41	testutil.WycheproofCase
42	AD      testutil.HexBytes `json:"aad"`
43	CT      testutil.HexBytes `json:"ct"`
44	IV      testutil.HexBytes `json:"iv"`
45	Key     testutil.HexBytes `json:"key"`
46	Message testutil.HexBytes `json:"msg"`
47	Tag     testutil.HexBytes `json:"tag"`
48}
49
50func TestValidateAESKeySize(t *testing.T) {
51	for _, keySize := range []uint32{8, 16, 24, 32, 40} {
52		err := aead.ValidateAESKeySize(keySize)
53		if keySize == 16 || keySize == 32 {
54			if err != nil {
55				t.Errorf("ValidateAESKeySize(%d): got err %q, want success", keySize, err)
56			}
57		} else if err == nil {
58			t.Errorf("ValidateAESKeySize(%d): got success, want error", keySize)
59		}
60	}
61}
62