Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
aes_cmac_tests.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../aes_cmac.h"
Include dependency graph for aes_cmac_tests.c:

Go to the source code of this file.

Macros

#define asrt(c, e, m)
 

Functions

int main ()
 

Macro Definition Documentation

◆ asrt

#define asrt ( c,
e,
m )
Value:
_asrt(__LINE__, c, e, m);

Definition at line 23 of file aes_cmac_tests.c.

Function Documentation

◆ main()

int main ( void )

Definition at line 37 of file aes_cmac_tests.c.

37 {
39
41
42 uint8_t m[] = {0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96, 0xe9, 0x3d,
43 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a, 0xae, 0x2d, 0x8a, 0x57,
44 0x1e, 0x03, 0xac, 0x9c, 0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf,
45 0x8e, 0x51, 0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
46 0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef, 0xf6, 0x9f,
47 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17, 0xad, 0x2b, 0x41, 0x7b,
48 0xe6, 0x6c, 0x37, 0x10};
49
50 uint8_t k_128[] = {0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
51 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c};
52
53 uint8_t k_192[] = {0x8e, 0x73, 0xb0, 0xf7, 0xda, 0x0e, 0x64, 0x52,
54 0xc8, 0x10, 0xf3, 0x2b, 0x80, 0x90, 0x79, 0xe5,
55 0x62, 0xf8, 0xea, 0xd2, 0x52, 0x2c, 0x6b, 0x7b};
56
57 uint8_t k_256[] = {0x60, 0x3d, 0xeb, 0x10, 0x15, 0xca, 0x71, 0xbe,
58 0x2b, 0x73, 0xae, 0xf0, 0x85, 0x7d, 0x77, 0x81,
59 0x1f, 0x35, 0x2c, 0x07, 0x3b, 0x61, 0x08, 0xd7,
60 0x2d, 0x98, 0x10, 0xa3, 0x09, 0x14, 0xdf, 0xf4};
61
62 uint8_t mac1[] = {0xbb, 0x1d, 0x69, 0x29, 0xe9, 0x59, 0x37, 0x28,
63 0x7f, 0xa3, 0x7d, 0x12, 0x9b, 0x75, 0x67, 0x46};
64 uint8_t mac2[] = {0x07, 0x0a, 0x16, 0xb4, 0x6b, 0x4d, 0x41, 0x44,
65 0xf7, 0x9b, 0xdd, 0x9d, 0xd0, 0x4a, 0x28, 0x7c};
66 uint8_t mac3[] = {0xdf, 0xa6, 0x67, 0x47, 0xde, 0x9a, 0xe6, 0x30,
67 0x30, 0xca, 0x32, 0x61, 0x14, 0x97, 0xc8, 0x27};
68 uint8_t mac4[] = {0x51, 0xf0, 0xbe, 0xbf, 0x7e, 0x3b, 0x9d, 0x92,
69 0xfc, 0x49, 0x74, 0x17, 0x79, 0x36, 0x3c, 0xfe};
70 uint8_t mac5[] = {0xd1, 0x7d, 0xdf, 0x46, 0xad, 0xaa, 0xcd, 0xe5,
71 0x31, 0xca, 0xc4, 0x83, 0xde, 0x7a, 0x93, 0x67};
72 uint8_t mac6[] = {0x9e, 0x99, 0xa7, 0xbf, 0x31, 0xe7, 0x10, 0x90,
73 0x06, 0x62, 0xf6, 0x5e, 0x61, 0x7c, 0x51, 0x84};
74 uint8_t mac7[] = {0x8a, 0x1d, 0xe5, 0xbe, 0x2e, 0xb3, 0x1a, 0xad,
75 0x08, 0x9a, 0x82, 0xe6, 0xee, 0x90, 0x8b, 0x0e};
76 uint8_t mac8[] = {0xa1, 0xd5, 0xdf, 0x0e, 0xed, 0x79, 0x0f, 0x79,
77 0x4d, 0x77, 0x58, 0x96, 0x59, 0xf3, 0x9a, 0x11};
78 uint8_t mac9[] = {0x02, 0x89, 0x62, 0xf6, 0x1b, 0x7b, 0xf8, 0x9e,
79 0xfc, 0x6b, 0x55, 0x1f, 0x46, 0x67, 0xd9, 0x83};
80 uint8_t mac10[] = {0x28, 0xa7, 0x02, 0x3f, 0x45, 0x2e, 0x8f, 0x82,
81 0xbd, 0x4b, 0xf2, 0x8d, 0x8c, 0x37, 0xc3, 0x5c};
82 uint8_t mac11[] = {0xaa, 0xf3, 0xd8, 0xf1, 0xde, 0x56, 0x40, 0xc2,
83 0x32, 0xf5, 0xb1, 0x69, 0xb9, 0xc9, 0x11, 0xe6};
84 uint8_t mac12[] = {0xe1, 0x99, 0x21, 0x90, 0x54, 0x9f, 0x6e, 0xd5,
85 0x69, 0x6a, 0x2c, 0x05, 0x6c, 0x31, 0x54, 0x10};
86
87 aes_cmac_init(k_128, sizeof(k_128), &ctx);
88 aes_cmac_encrypt(&ctx, m, 0, mac);
89 asrt(memcmp(mac, mac1, 16), 0, (unsigned char *) "MAC1");
90 aes_cmac_encrypt(&ctx, m, 16, mac);
91 asrt(memcmp(mac, mac2, 16), 0, (unsigned char *) "MAC2");
92 aes_cmac_encrypt(&ctx, m, 40, mac);
93 asrt(memcmp(mac, mac3, 16), 0, (unsigned char *) "MAC3");
94 aes_cmac_encrypt(&ctx, m, 64, mac);
95 asrt(memcmp(mac, mac4, 16), 0, (unsigned char *) "MAC4");
96
97 aes_cmac_init(k_192, sizeof(k_192), &ctx);
98 aes_cmac_encrypt(&ctx, m, 0, mac);
99 asrt(memcmp(mac, mac5, 16), 0, (unsigned char *) "MAC5");
100 aes_cmac_encrypt(&ctx, m, 16, mac);
101 asrt(memcmp(mac, mac6, 16), 0, (unsigned char *) "MAC6");
102 aes_cmac_encrypt(&ctx, m, 40, mac);
103 asrt(memcmp(mac, mac7, 16), 0, (unsigned char *) "MAC7");
104 aes_cmac_encrypt(&ctx, m, 64, mac);
105 asrt(memcmp(mac, mac8, 16), 0, (unsigned char *) "MAC8");
106
107 aes_cmac_init(k_256, sizeof(k_256), &ctx);
108 aes_cmac_encrypt(&ctx, m, 0, mac);
109 asrt(memcmp(mac, mac9, 16), 0, (unsigned char *) "MAC9");
110 aes_cmac_encrypt(&ctx, m, 16, mac);
111 asrt(memcmp(mac, mac10, 16), 0, (unsigned char *) "MAC10");
112 aes_cmac_encrypt(&ctx, m, 40, mac);
113 asrt(memcmp(mac, mac11, 16), 0, (unsigned char *) "MAC11");
114 aes_cmac_encrypt(&ctx, m, 64, mac);
115 asrt(memcmp(mac, mac12, 16), 0, (unsigned char *) "MAC12");
116
117 // Padding tests
118
119 uint8_t a[48];
120 uint16_t l;
121
122 l = 3;
123 memset(a, 0xab, 48);
125 asrt(memcmp(a,
126 "\xab\xab\xab\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
127 "\x00",
128 16),
129 0, (unsigned char *) "PADDING 1a");
130 asrt(l, 16, (unsigned char *) "PADDING 1b");
132 asrt(memcmp(a, "\xab\xab\xab", 3), 0, (unsigned char *) "PADDING 1c");
133 asrt(l, 3, (unsigned char *) "PADDING 1d");
134 fprintf(stderr, "\n");
135
136 l = 15;
137 memset(a, 0xab, 48);
139 asrt(memcmp(a,
140 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
141 "\x80",
142 16),
143 0, (unsigned char *) "PADDING 2a");
144 asrt(l, 16, (unsigned char *) "PADDING 2b");
146 asrt(memcmp(a,
147 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
148 "\xab",
149 15),
150 0, (unsigned char *) "PADDING 2c");
151 asrt(l, 15, (unsigned char *) "PADDING 2d");
152 fprintf(stderr, "\n");
153
154 l = 16;
155 memset(a, 0xab, 48);
157 asrt(memcmp(a,
158 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
159 "\xab\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
160 "\x00\x00",
161 32),
162 0, (unsigned char *) "PADDING 3a");
163 asrt(l, 32, (unsigned char *) "PADDING 3b");
165 asrt(memcmp(a,
166 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
167 "\xab",
168 16),
169 0, (unsigned char *) "PADDING 3c");
170 asrt(l, 16, (unsigned char *) "PADDING 3d");
171 fprintf(stderr, "\n");
172
173 l = 19;
174 memset(a, 0xab, 48);
176 asrt(memcmp(a,
177 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
178 "\xab\xab\xab\xab\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
179 "\x00\x00",
180 32),
181 0, (unsigned char *) "PADDING 4a");
182 asrt(l, 32, (unsigned char *) "PADDING 4b");
184 asrt(memcmp(a,
185 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
186 "\xab\xab\xab\xab",
187 19),
188 0, (unsigned char *) "PADDING 4c");
189 asrt(l, 19, (unsigned char *) "PADDING 4d");
190 fprintf(stderr, "\n");
191
192 l = 32;
193 memset(a, 0xab, 48);
195 asrt(memcmp(a,
196 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
197 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
198 "\xab\xab\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
199 "\x00\x00\x00",
200 48),
201 0, (unsigned char *) "PADDING 5a");
202 asrt(l, 48, (unsigned char *) "PADDING 5b");
204 asrt(memcmp(a,
205 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
206 "\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab\xab"
207 "\xab\xab",
208 32),
209 0, (unsigned char *) "PADDING 5c");
210 asrt(l, 32, (unsigned char *) "PADDING 5d");
211 fprintf(stderr, "\n");
212
213 l = 0;
214 memset(a, 0xab, 48);
216 asrt(memcmp(a,
217 "\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
218 "\x00",
219 16),
220 0, (unsigned char *) "PADDING 6a");
221 asrt(l, 16, (unsigned char *) "PADDING 6b");
223 asrt(memcmp(a, "", 0), 0, (unsigned char *) "PADDING 6c");
224 asrt(l, 0, (unsigned char *) "PADDING 6d");
225 fprintf(stderr, "\n");
226
227 return EXIT_SUCCESS;
228}
void aes_remove_padding(uint8_t *in, uint16_t *len)
Definition aes.c:321
void aes_add_padding(uint8_t *in, uint16_t *len)
Definition aes.c:313
#define AES_BLOCK_SIZE
Definition aes.h:35
uint8_t aes_cmac_init(uint8_t *key, uint16_t key_len, aes_cmac_context_t *ctx)
Definition aes_cmac.c:130
void aes_cmac_encrypt(const aes_cmac_context_t *ctx, const uint8_t *message, const uint16_t message_len, uint8_t *mac)
Definition aes_cmac.c:85
#define asrt(c, e, m)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition pointer.h:1181
unsigned short uint16_t
Definition stdint.h:125
unsigned char uint8_t
Definition stdint.h:124
int l
memset(pInfo->slotDescription, ' ', 64)
Here is the call graph for this function: