FD.io VPP  v21.01.1
Vector Packet Processing
aes_ctr.c
Go to the documentation of this file.
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 for AES-CTR published here:
17  * https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-38a.pdf
18  */
19 
20 #include <vppinfra/clib.h>
21 #include <vnet/crypto/crypto.h>
22 #include <unittest/crypto/crypto.h>
23 
24 static u8 tc1_key[] = {
25  0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
26  0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c,
27 };
28 
29 static u8 tc1_iv[] = {
30  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
31  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
32 };
33 
34 static u8 tc1_plaintext[] = {
35  0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
36  0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
37 };
38 
39 static u8 tc1_ciphertext[] = {
40  0x87, 0x4d, 0x61, 0x91, 0xb6, 0x20, 0xe3, 0x26,
41  0x1b, 0xef, 0x68, 0x64, 0x99, 0x0d, 0xb6, 0xce,
42 };
43 
44 /* *INDENT-OFF* */
45 UNITTEST_REGISTER_CRYPTO_TEST (nist_aes128_ctr_tc1) = {
46  .name = "CTR-AES128 TC1",
47  .alg = VNET_CRYPTO_ALG_AES_128_CTR,
48  .key = TEST_DATA (tc1_key),
49  .iv = TEST_DATA (tc1_iv),
50  .plaintext = TEST_DATA (tc1_plaintext),
51  .ciphertext = TEST_DATA (tc1_ciphertext),
52 };
53 /* *INDENT-ON* */
54 
55 static u8 tc1_192_key[] = {
56  0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
57  0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
58  0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b,
59 };
60 
61 static u8 tc1_192_iv[] = {
62  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
63  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
64 };
65 
66 static u8 tc1_192_ciphertext[] = {
67  0x1a, 0xbc, 0x93, 0x24, 0x17, 0x52, 0x1c, 0xa2,
68  0x4f, 0x2b, 0x04, 0x59, 0xfe, 0x7e, 0x6e, 0x0b,
69 };
70 
71 /* *INDENT-OFF* */
72 UNITTEST_REGISTER_CRYPTO_TEST (nist_aes192_ctr_tc1) = {
73  .name = "CTR-AES192 TC1",
74  .alg = VNET_CRYPTO_ALG_AES_192_CTR,
75  .key = TEST_DATA (tc1_192_key),
76  .iv = TEST_DATA (tc1_192_iv),
77  .plaintext = TEST_DATA (tc1_plaintext),
78  .ciphertext = TEST_DATA (tc1_192_ciphertext),
79 };
80 /* *INDENT-ON* */
81 
82 static u8 tc1_256_key[] = {
83  0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
84  0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
85  0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
86  0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4,
87 };
88 
89 static u8 tc1_256_iv[] = {
90  0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
91  0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
92 };
93 
94 static u8 tc1_256_ciphertext[] = {
95  0x60, 0x1e, 0xc3, 0x13, 0x77, 0x57, 0x89, 0xa5,
96  0xb7, 0xa7, 0xf5, 0x04, 0xbb, 0xf3, 0xd2, 0x28,
97 };
98 
99 /* *INDENT-OFF* */
100 UNITTEST_REGISTER_CRYPTO_TEST (nist_aes256_ctr_tc1) = {
101  .name = "CTR-AES256 TC1",
102  .alg = VNET_CRYPTO_ALG_AES_256_CTR,
103  .key = TEST_DATA (tc1_256_key),
104  .iv = TEST_DATA (tc1_256_iv),
105  .plaintext = TEST_DATA (tc1_plaintext),
106  .ciphertext = TEST_DATA (tc1_256_ciphertext),
107 };
108 /* *INDENT-ON* */
109 
110 /*
111  * fd.io coding-style-patch-verification: ON
112  *
113  * Local Variables:
114  * eval: (c-set-style "gnu")
115  * End:
116  */
static u8 tc1_256_key[]
Definition: aes_ctr.c:82
unsigned char u8
Definition: types.h:56
static u8 tc1_plaintext[]
Definition: aes_ctr.c:34
static u8 tc1_key[]
Definition: aes_ctr.c:24
UNITTEST_REGISTER_CRYPTO_TEST(nist_aes128_ctr_tc1)
static u8 tc1_192_ciphertext[]
Definition: aes_ctr.c:66
#define TEST_DATA(n)
Definition: crypto.h:63
static u8 tc1_192_iv[]
Definition: aes_ctr.c:61
static u8 tc1_ciphertext[]
Definition: aes_ctr.c:39
static u8 tc1_256_ciphertext[]
Definition: aes_ctr.c:94
static u8 tc1_192_key[]
Definition: aes_ctr.c:55
static u8 tc1_iv[]
Definition: aes_ctr.c:29
static u8 tc1_256_iv[]
Definition: aes_ctr.c:89