crypto: add support for AEAD and AES-GCM
[vpp.git] / src / plugins / unittest / crypto / aes_gcm.c
1 /*
2  * Copyright (c) 2019 Cisco and/or its affiliates.
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 /* Test vectors published in GCM Specification */
17
18 #include <vppinfra/clib.h>
19 #include <vnet/crypto/crypto.h>
20 #include <unittest/crypto/crypto.h>
21
22 static u8 tc6_iv[] = {
23   0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5,
24   0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa,
25   0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1,
26   0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28,
27   0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39,
28   0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54,
29   0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57,
30   0xa6, 0x37, 0xb3, 0x9b
31 };
32
33 static u8 tc6_plaintext[] = {
34   0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5,
35   0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a,
36   0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
37   0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72,
38   0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53,
39   0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
40   0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57,
41   0xba, 0x63, 0x7b, 0x39,
42 };
43
44 static u8 tc6_key[] = {
45   0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c,
46   0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08
47 };
48
49 static u8 tc6_aad[] = {
50   0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
51   0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
52   0xab, 0xad, 0xda, 0xd2
53 };
54
55 static u8 tc6_ciphertext[] = {
56   0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6,
57   0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94,
58   0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8,
59   0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7,
60   0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90,
61   0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f,
62   0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03,
63   0x4c, 0x34, 0xae, 0xe5
64 };
65
66 static u8 tc6_tag[] = {
67   0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa,
68   0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50,
69 };
70
71 /* *INDENT-OFF* */
72 UNITTEST_REGISTER_CRYPTO_TEST (aes_gcm_tc6) = {
73   .name = "GCM Spec. TC6",
74   .alg = VNET_CRYPTO_ALG_AES_128_GCM,
75   .iv = TEST_DATA (tc6_iv),
76   .key = TEST_DATA (tc6_key),
77   .plaintext = TEST_DATA (tc6_plaintext),
78   .ciphertext = TEST_DATA (tc6_ciphertext),
79   .tag = TEST_DATA (tc6_tag),
80   .aad = TEST_DATA (tc6_aad),
81 };
82
83 /* *INDENT-ON* */
84
85 /*
86  * fd.io coding-style-patch-verification: ON
87  *
88  * Local Variables:
89  * eval: (c-set-style "gnu")
90  * End:
91  */