FD.io VPP  v20.01-48-g3e0dafb74
Vector Packet Processing
aes_cbc.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 published by NIST as SP 800-38A
17  https://csrc.nist.gov/CSRC/media/Projects/Cryptographic-Standards-and-Guidelines/documents/examples/AES_CFB.pdf
18  */
19 
20 #include <vppinfra/clib.h>
21 #include <vnet/crypto/crypto.h>
22 #include <unittest/crypto/crypto.h>
23 
24 static u8 iv[] = {
25  0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
26  0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
27 };
28 
29 static u8 plaintext[] = {
30  0x6B, 0xC1, 0xBE, 0xE2, 0x2E, 0x40, 0x9F, 0x96,
31  0xE9, 0x3D, 0x7E, 0x11, 0x73, 0x93, 0x17, 0x2A,
32  0xAE, 0x2D, 0x8A, 0x57, 0x1E, 0x03, 0xAC, 0x9C,
33  0x9E, 0xB7, 0x6F, 0xAC, 0x45, 0xAF, 0x8E, 0x51,
34  0x30, 0xC8, 0x1C, 0x46, 0xA3, 0x5C, 0xE4, 0x11,
35  0xE5, 0xFB, 0xC1, 0x19, 0x1A, 0x0A, 0x52, 0xEF,
36  0xF6, 0x9F, 0x24, 0x45, 0xDF, 0x4F, 0x9B, 0x17,
37  0xAD, 0x2B, 0x41, 0x7B, 0xE6, 0x6C, 0x37, 0x10,
38 };
39 
40 static u8 key128[] = {
41  0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6,
42  0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C
43 };
44 
45 static u8 ciphertext128[] = {
46  0x76, 0x49, 0xAB, 0xAC, 0x81, 0x19, 0xB2, 0x46,
47  0xCE, 0xE9, 0x8E, 0x9B, 0x12, 0xE9, 0x19, 0x7D,
48  0x50, 0x86, 0xCB, 0x9B, 0x50, 0x72, 0x19, 0xEE,
49  0x95, 0xDB, 0x11, 0x3A, 0x91, 0x76, 0x78, 0xB2,
50  0x73, 0xBE, 0xD6, 0xB8, 0xE3, 0xC1, 0x74, 0x3B,
51  0x71, 0x16, 0xE6, 0x9E, 0x22, 0x22, 0x95, 0x16,
52  0x3F, 0xF1, 0xCA, 0xA1, 0x68, 0x1F, 0xAC, 0x09,
53  0x12, 0x0E, 0xCA, 0x30, 0x75, 0x86, 0xE1, 0xA7,
54 };
55 
56 /* *INDENT-OFF* */
57 UNITTEST_REGISTER_CRYPTO_TEST (nist_aes128_cbc) = {
58  .name = "NIST SP 800-38A",
59  .alg = VNET_CRYPTO_ALG_AES_128_CBC,
60  .iv = TEST_DATA (iv),
61  .key = TEST_DATA (key128),
62  .plaintext = TEST_DATA (plaintext),
63  .ciphertext = TEST_DATA (ciphertext128),
64 };
65 
66 /* *INDENT-ON* */
67 
68 static u8 key192[24] = {
69  0x8E, 0x73, 0xB0, 0xF7, 0xDA, 0x0E, 0x64, 0x52,
70  0xC8, 0x10, 0xF3, 0x2B, 0x80, 0x90, 0x79, 0xE5,
71  0x62, 0xF8, 0xEA, 0xD2, 0x52, 0x2C, 0x6B, 0x7B,
72 };
73 
74 static u8 ciphertext192[64] = {
75  0x4F, 0x02, 0x1D, 0xB2, 0x43, 0xBC, 0x63, 0x3D,
76  0x71, 0x78, 0x18, 0x3A, 0x9F, 0xA0, 0x71, 0xE8,
77  0xB4, 0xD9, 0xAD, 0xA9, 0xAD, 0x7D, 0xED, 0xF4,
78  0xE5, 0xE7, 0x38, 0x76, 0x3F, 0x69, 0x14, 0x5A,
79  0x57, 0x1B, 0x24, 0x20, 0x12, 0xFB, 0x7A, 0xE0,
80  0x7F, 0xA9, 0xBA, 0xAC, 0x3D, 0xF1, 0x02, 0xE0,
81  0x08, 0xB0, 0xE2, 0x79, 0x88, 0x59, 0x88, 0x81,
82  0xD9, 0x20, 0xA9, 0xE6, 0x4F, 0x56, 0x15, 0xCD,
83 };
84 
85 /* *INDENT-OFF* */
86 UNITTEST_REGISTER_CRYPTO_TEST (nist_aes192_cbc) = {
87  .name = "NIST SP 800-38A",
88  .alg = VNET_CRYPTO_ALG_AES_192_CBC,
89  .iv = TEST_DATA (iv),
90  .key = TEST_DATA (key192),
91  .plaintext = TEST_DATA (plaintext),
92  .ciphertext = TEST_DATA (ciphertext192),
93 };
94 
95 /* *INDENT-ON* */
96 
97 static u8 key256[32] = {
98  0x60, 0x3D, 0xEB, 0x10, 0x15, 0xCA, 0x71, 0xBE,
99  0x2B, 0x73, 0xAE, 0xF0, 0x85, 0x7D, 0x77, 0x81,
100  0x1F, 0x35, 0x2C, 0x07, 0x3B, 0x61, 0x08, 0xD7,
101  0x2D, 0x98, 0x10, 0xA3, 0x09, 0x14, 0xDF, 0xF4,
102 };
103 
104 static u8 ciphertext256[64] = {
105  0xF5, 0x8C, 0x4C, 0x04, 0xD6, 0xE5, 0xF1, 0xBA,
106  0x77, 0x9E, 0xAB, 0xFB, 0x5F, 0x7B, 0xFB, 0xD6,
107  0x9C, 0xFC, 0x4E, 0x96, 0x7E, 0xDB, 0x80, 0x8D,
108  0x67, 0x9F, 0x77, 0x7B, 0xC6, 0x70, 0x2C, 0x7D,
109  0x39, 0xF2, 0x33, 0x69, 0xA9, 0xD9, 0xBA, 0xCF,
110  0xA5, 0x30, 0xE2, 0x63, 0x04, 0x23, 0x14, 0x61,
111  0xB2, 0xEB, 0x05, 0xE2, 0xC3, 0x9B, 0xE9, 0xFC,
112  0xDA, 0x6C, 0x19, 0x07, 0x8C, 0x6A, 0x9D, 0x1B,
113 };
114 
115 /* *INDENT-OFF* */
116 UNITTEST_REGISTER_CRYPTO_TEST (nist_aes256_cbc) = {
117  .name = "NIST SP 800-38A",
118  .alg = VNET_CRYPTO_ALG_AES_256_CBC,
119  .iv = TEST_DATA (iv),
120  .key = TEST_DATA (key256),
121  .plaintext = TEST_DATA (plaintext),
122  .ciphertext = TEST_DATA (ciphertext256),
123 };
124 
125 /* *INDENT-ON* */
126 
127 /*
128  * fd.io coding-style-patch-verification: ON
129  *
130  * Local Variables:
131  * eval: (c-set-style "gnu")
132  * End:
133  */
static u8 key128[]
Definition: aes_cbc.c:40
unsigned char u8
Definition: types.h:56
static u8 ciphertext128[]
Definition: aes_cbc.c:45
static u8 ciphertext256[64]
Definition: aes_cbc.c:104
static u8 iv[]
Definition: aes_cbc.c:24
static u8 key256[32]
Definition: aes_cbc.c:97
static u8 key192[24]
Definition: aes_cbc.c:68
static u8 plaintext[]
Definition: aes_cbc.c:29
static u8 ciphertext192[64]
Definition: aes_cbc.c:74
#define TEST_DATA(n)
Definition: crypto.h:54
UNITTEST_REGISTER_CRYPTO_TEST(nist_aes128_cbc)