1*cd964fceSMatt Barden /*
2*cd964fceSMatt Barden  * This file and its contents are supplied under the terms of the
3*cd964fceSMatt Barden  * Common Development and Distribution License ("CDDL"), version 1.0.
4*cd964fceSMatt Barden  * You may only use this file in accordance with the terms of version
5*cd964fceSMatt Barden  * 1.0 of the CDDL.
6*cd964fceSMatt Barden  *
7*cd964fceSMatt Barden  * A full copy of the text of the CDDL should have accompanied this
8*cd964fceSMatt Barden  * source.  A copy of the CDDL is also available via the Internet at
9*cd964fceSMatt Barden  * http://www.illumos.org/license/CDDL.
10*cd964fceSMatt Barden  */
11*cd964fceSMatt Barden 
12*cd964fceSMatt Barden /*
13*cd964fceSMatt Barden  * Copyright 2015 Nexenta Systems, Inc.  All rights reserved.
14*cd964fceSMatt Barden  */
15*cd964fceSMatt Barden 
16*cd964fceSMatt Barden #ifndef _AES_CBC_H
17*cd964fceSMatt Barden #define	_AES_CBC_H
18*cd964fceSMatt Barden 
19*cd964fceSMatt Barden #ifdef __cplusplus
20*cd964fceSMatt Barden extern "C" {
21*cd964fceSMatt Barden #endif
22*cd964fceSMatt Barden 
23*cd964fceSMatt Barden /*
24*cd964fceSMatt Barden  * Test vectors
25*cd964fceSMatt Barden  * RFC3602 section 4
26*cd964fceSMatt Barden  */
27*cd964fceSMatt Barden 
28*cd964fceSMatt Barden static uint8_t CBC1_KEY[16] = {
29*cd964fceSMatt Barden 	0x06, 0xa9, 0x21, 0x40, 0x36, 0xb8, 0xa1, 0x5b,
30*cd964fceSMatt Barden 	0x51, 0x2e, 0x03, 0xd5, 0x34, 0x12, 0x00, 0x06,
31*cd964fceSMatt Barden };
32*cd964fceSMatt Barden static uint8_t CBC1_IV[16] = {
33*cd964fceSMatt Barden 	0x3d, 0xaf, 0xba, 0x42, 0x9d, 0x9e, 0xb4, 0x30,
34*cd964fceSMatt Barden 	0xb4, 0x22, 0xda, 0x80, 0x2c, 0x9f, 0xac, 0x41,
35*cd964fceSMatt Barden };
36*cd964fceSMatt Barden static uint8_t CBC1_DATA[] = {
37*cd964fceSMatt Barden 	'S', 'i', 'n', 'g', 'l', 'e', ' ', 'b',
38*cd964fceSMatt Barden 	'l', 'o', 'c', 'k', ' ', 'm', 's', 'g',
39*cd964fceSMatt Barden };
40*cd964fceSMatt Barden static uint8_t CBC1_RES[] = {
41*cd964fceSMatt Barden 	0xe3, 0x53, 0x77, 0x9c, 0x10, 0x79, 0xae, 0xb8,
42*cd964fceSMatt Barden 	0x27, 0x08, 0x94, 0x2d, 0xbe, 0x77, 0x18, 0x1a,
43*cd964fceSMatt Barden };
44*cd964fceSMatt Barden 
45*cd964fceSMatt Barden static uint8_t CBC2_KEY[] = {
46*cd964fceSMatt Barden 	0xc2, 0x86, 0x69, 0x6d, 0x88, 0x7c, 0x9a, 0xa0,
47*cd964fceSMatt Barden 	0x61, 0x1b, 0xbb, 0x3e, 0x20, 0x25, 0xa4, 0x5a,
48*cd964fceSMatt Barden };
49*cd964fceSMatt Barden static uint8_t CBC2_IV[] = {
50*cd964fceSMatt Barden 	0x56, 0x2e, 0x17, 0x99, 0x6d, 0x09, 0x3d, 0x28,
51*cd964fceSMatt Barden 	0xdd, 0xb3, 0xba, 0x69, 0x5a, 0x2e, 0x6f, 0x58,
52*cd964fceSMatt Barden };
53*cd964fceSMatt Barden static uint8_t CBC2_DATA[] = {
54*cd964fceSMatt Barden 	0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
55*cd964fceSMatt Barden 	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
56*cd964fceSMatt Barden 
57*cd964fceSMatt Barden 	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
58*cd964fceSMatt Barden 	0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f
59*cd964fceSMatt Barden };
60*cd964fceSMatt Barden static uint8_t CBC2_RES[] = {
61*cd964fceSMatt Barden 	0xd2, 0x96, 0xcd, 0x94, 0xc2, 0xcc, 0xcf, 0x8a,
62*cd964fceSMatt Barden 	0x3a, 0x86, 0x30, 0x28, 0xb5, 0xe1, 0xdc, 0x0a,
63*cd964fceSMatt Barden 
64*cd964fceSMatt Barden 	0x75, 0x86, 0x60, 0x2d, 0x25, 0x3c, 0xff, 0xf9,
65*cd964fceSMatt Barden 	0x1b, 0x82, 0x66, 0xbe, 0xa6, 0xd6, 0x1a, 0xb1,
66*cd964fceSMatt Barden };
67*cd964fceSMatt Barden 
68*cd964fceSMatt Barden static uint8_t CBC3_KEY[] = {
69*cd964fceSMatt Barden 	0x6c, 0x3e, 0xa0, 0x47, 0x76, 0x30, 0xce, 0x21,
70*cd964fceSMatt Barden 	0xa2, 0xce, 0x33, 0x4a, 0xa7, 0x46, 0xc2, 0xcd,
71*cd964fceSMatt Barden };
72*cd964fceSMatt Barden static uint8_t CBC3_IV[] = {
73*cd964fceSMatt Barden 	0xc7, 0x82, 0xdc, 0x4c, 0x09, 0x8c, 0x66, 0xcb,
74*cd964fceSMatt Barden 	0xd9, 0xcd, 0x27, 0xd8, 0x25, 0x68, 0x2c, 0x81,
75*cd964fceSMatt Barden };
76*cd964fceSMatt Barden static uint8_t CBC3_DATA[] = {
77*cd964fceSMatt Barden 	'T', 'h', 'i', 's', ' ', 'i', 's', ' ',
78*cd964fceSMatt Barden 	'a', ' ', '4', '8', '-', 'b', 'y', 't',
79*cd964fceSMatt Barden 
80*cd964fceSMatt Barden 	'e', ' ', 'm', 'e', 's', 's', 'a', 'g',
81*cd964fceSMatt Barden 	'e', ' ', '(', 'e', 'x', 'a', 'c', 't',
82*cd964fceSMatt Barden 
83*cd964fceSMatt Barden 	'l', 'y', ' ', '3', ' ', 'A', 'E', 'S',
84*cd964fceSMatt Barden 	' ', 'b', 'l', 'o', 'c', 'k', 's', ')',
85*cd964fceSMatt Barden };
86*cd964fceSMatt Barden 
87*cd964fceSMatt Barden static uint8_t CBC3_RES[] = {
88*cd964fceSMatt Barden 	0xd0, 0xa0, 0x2b, 0x38, 0x36, 0x45, 0x17, 0x53,
89*cd964fceSMatt Barden 	0xd4, 0x93, 0x66, 0x5d, 0x33, 0xf0, 0xe8, 0x86,
90*cd964fceSMatt Barden 
91*cd964fceSMatt Barden 	0x2d, 0xea, 0x54, 0xcd, 0xb2, 0x93, 0xab, 0xc7,
92*cd964fceSMatt Barden 	0x50, 0x69, 0x39, 0x27, 0x67, 0x72, 0xf8, 0xd5,
93*cd964fceSMatt Barden 
94*cd964fceSMatt Barden 	0x02, 0x1c, 0x19, 0x21, 0x6b, 0xad, 0x52, 0x5c,
95*cd964fceSMatt Barden 	0x85, 0x79, 0x69, 0x5d, 0x83, 0xba, 0x26, 0x84,
96*cd964fceSMatt Barden };
97*cd964fceSMatt Barden 
98*cd964fceSMatt Barden static uint8_t CBC4_KEY[] = {
99*cd964fceSMatt Barden 	0x56, 0xe4, 0x7a, 0x38, 0xc5, 0x59, 0x89, 0x74,
100*cd964fceSMatt Barden 	0xbc, 0x46, 0x90, 0x3d, 0xba, 0x29, 0x03, 0x49,
101*cd964fceSMatt Barden };
102*cd964fceSMatt Barden static uint8_t CBC4_IV[] = {
103*cd964fceSMatt Barden 	0x8c, 0xe8, 0x2e, 0xef, 0xbe, 0xa0, 0xda, 0x3c,
104*cd964fceSMatt Barden 	0x44, 0x69, 0x9e, 0xd7, 0xdb, 0x51, 0xb7, 0xd9,
105*cd964fceSMatt Barden };
106*cd964fceSMatt Barden static uint8_t CBC4_DATA[] = {
107*cd964fceSMatt Barden 	0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
108*cd964fceSMatt Barden 	0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
109*cd964fceSMatt Barden 
110*cd964fceSMatt Barden 	0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
111*cd964fceSMatt Barden 	0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
112*cd964fceSMatt Barden 
113*cd964fceSMatt Barden 	0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
114*cd964fceSMatt Barden 	0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
115*cd964fceSMatt Barden 
116*cd964fceSMatt Barden 	0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
117*cd964fceSMatt Barden 	0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
118*cd964fceSMatt Barden };
119*cd964fceSMatt Barden static uint8_t CBC4_RES[] = {
120*cd964fceSMatt Barden 	0xc3, 0x0e, 0x32, 0xff, 0xed, 0xc0, 0x77, 0x4e,
121*cd964fceSMatt Barden 	0x6a, 0xff, 0x6a, 0xf0, 0x86, 0x9f, 0x71, 0xaa,
122*cd964fceSMatt Barden 
123*cd964fceSMatt Barden 	0x0f, 0x3a, 0xf0, 0x7a, 0x9a, 0x31, 0xa9, 0xc6,
124*cd964fceSMatt Barden 	0x84, 0xdb, 0x20, 0x7e, 0xb0, 0xef, 0x8e, 0x4e,
125*cd964fceSMatt Barden 
126*cd964fceSMatt Barden 	0x35, 0x90, 0x7a, 0xa6, 0x32, 0xc3, 0xff, 0xdf,
127*cd964fceSMatt Barden 	0x86, 0x8b, 0xb7, 0xb2, 0x9d, 0x3d, 0x46, 0xad,
128*cd964fceSMatt Barden 
129*cd964fceSMatt Barden 	0x83, 0xce, 0x9f, 0x9a, 0x10, 0x2e, 0xe9, 0x9d,
130*cd964fceSMatt Barden 	0x49, 0xa5, 0x3e, 0x87, 0xf4, 0xc3, 0xda, 0x55,
131*cd964fceSMatt Barden };
132*cd964fceSMatt Barden 
133*cd964fceSMatt Barden uint8_t *DATA[] = {
134*cd964fceSMatt Barden 	CBC1_DATA, CBC2_DATA, CBC3_DATA, CBC4_DATA
135*cd964fceSMatt Barden };
136*cd964fceSMatt Barden 
137*cd964fceSMatt Barden size_t DATALEN[] = {
138*cd964fceSMatt Barden 	sizeof (CBC1_DATA), sizeof (CBC2_DATA),
139*cd964fceSMatt Barden 	sizeof (CBC3_DATA), sizeof (CBC4_DATA),
140*cd964fceSMatt Barden };
141*cd964fceSMatt Barden 
142*cd964fceSMatt Barden uint8_t *KEY[] = {
143*cd964fceSMatt Barden 	CBC1_KEY, CBC2_KEY, CBC3_KEY, CBC4_KEY
144*cd964fceSMatt Barden };
145*cd964fceSMatt Barden 
146*cd964fceSMatt Barden size_t KEYLEN[] = {
147*cd964fceSMatt Barden 	sizeof (CBC1_KEY), sizeof (CBC2_KEY),
148*cd964fceSMatt Barden 	sizeof (CBC3_KEY), sizeof (CBC4_KEY),
149*cd964fceSMatt Barden };
150*cd964fceSMatt Barden 
151*cd964fceSMatt Barden uint8_t *IV[] = {
152*cd964fceSMatt Barden 	CBC1_IV, CBC2_IV, CBC3_IV, CBC4_IV
153*cd964fceSMatt Barden };
154*cd964fceSMatt Barden 
155*cd964fceSMatt Barden size_t IVLEN[] = {
156*cd964fceSMatt Barden 	sizeof (CBC1_IV), sizeof (CBC2_IV),
157*cd964fceSMatt Barden 	sizeof (CBC3_IV), sizeof (CBC4_IV),
158*cd964fceSMatt Barden };
159*cd964fceSMatt Barden 
160*cd964fceSMatt Barden uint8_t *RES[] = {
161*cd964fceSMatt Barden 	CBC1_RES, CBC2_RES, CBC3_RES, CBC4_RES
162*cd964fceSMatt Barden };
163*cd964fceSMatt Barden 
164*cd964fceSMatt Barden size_t RESLEN[] = {
165*cd964fceSMatt Barden 	sizeof (CBC1_RES), sizeof (CBC2_RES),
166*cd964fceSMatt Barden 	sizeof (CBC3_RES), sizeof (CBC4_RES),
167*cd964fceSMatt Barden };
168*cd964fceSMatt Barden 
169*cd964fceSMatt Barden #ifdef __cplusplus
170*cd964fceSMatt Barden }
171*cd964fceSMatt Barden #endif
172*cd964fceSMatt Barden 
173*cd964fceSMatt Barden #endif /* _AES_CBC_H */
174