1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
|
/*****************************************************************************
Copyright (c) 2009-2019, Intel Corporation
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Intel Corporation nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
/*-----------------------------------------------------------------------
* Zuc functional test
*-----------------------------------------------------------------------
*
* A simple functional test for ZUC
*
*-----------------------------------------------------------------------*/
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <intel-ipsec-mb.h>
#include "zuc_test_vectors.h"
#include "gcm_ctr_vectors_test.h"
#define MAXBUFS 9
#define PASS_STATUS 0
#define FAIL_STATUS -1
int zuc_test(const enum arch_type arch, struct MB_MGR *mb_mgr);
int validate_zuc_algorithm(struct MB_MGR *mb_mgr, uint8_t *pSrcData,
uint8_t *pDstData, uint8_t *pKeys, uint8_t *pIV);
int validate_zuc_EEA_1_block(struct MB_MGR *mb_mgr, uint8_t *pSrcData,
uint8_t *pDstData, uint8_t *pKeys, uint8_t *pIV);
int validate_zuc_EEA_4_block(struct MB_MGR *mb_mgr, uint8_t **pSrcData,
uint8_t **pDstData, uint8_t **pKeys,
uint8_t **pIV);
int validate_zuc_EEA_n_block(struct MB_MGR *mb_mgr, uint8_t **pSrcData,
uint8_t **pDstData, uint8_t **pKeys, uint8_t **pIV,
uint32_t numBuffs);
int validate_zuc_EIA_1_block(struct MB_MGR *mb_mgr, uint8_t *pSrcData,
uint8_t *pDstData, uint8_t *pKeys, uint8_t *pIV);
static void byte_hexdump(const char *message, const uint8_t *ptr, int len);
/******************************************************************************
* @ingroup zuc_functionalTest_app
*
* @description
* This function allocates memory for buffers and set random data in each buffer
*
* pSrcData = pointers to the new source buffers
* numOfBuffs = number of buffers
* ************************************************/
static uint32_t createData(uint8_t *pSrcData[MAXBUFS],
uint32_t numOfBuffs)
{
uint32_t i = 0, j = 0;
for (i = 0; i < numOfBuffs; i++) {
pSrcData[i] = (uint8_t *)malloc(MAX_BUFFER_LENGTH_IN_BYTES);
if (!pSrcData[i]) {
printf("malloc(pSrcData[i]): failed!\n");
for (j = 0; j < i; j++) {
free(pSrcData[j]);
pSrcData[j] = NULL;
}
return FAIL_STATUS;
}
}
return PASS_STATUS;
}
/******************************************************************************
* @ingroup zuc_functionalTest_app
*
* @description
* This function creates source data and vector buffers.
*
* keyLen = key length
* pKeys = array of pointers to the new key buffers
* ivLen = vector length
* pIV = array of pointers to the new vector buffers
* numOfBuffs = number of buffers
************************************************/
static uint32_t createKeyVecData(uint32_t keyLen, uint8_t *pKeys[MAXBUFS],
uint32_t ivLen, uint8_t *pIV[MAXBUFS],
uint32_t numOfBuffs)
{
uint32_t i = 0, j = 0;
for (i = 0; i < numOfBuffs; i++) {
pIV[i] = (uint8_t *)malloc(ivLen);
if (!pIV[i]) {
printf("malloc(pIV[i]): failed!\n");
for (j = 0; j < i; j++) {
free(pIV[j]);
free(pKeys[j]);
}
return FAIL_STATUS;
}
pKeys[i] = malloc(keyLen);
if (!pKeys[i]) {
printf("malloc(pKeys[i]): failed!\n");
for (j = 0; j <= i; j++) {
free(pIV[j]);
if (j < i)
free(pKeys[j]);
}
return FAIL_STATUS;
}
}
return PASS_STATUS;
}
/******************************************************************************
* @ingroup zuc_benchmark_app
*
* @description
* This function free memory pointed to by an array of pointers
*
* arr = array of memory pointers
* length = length of pointer array (or number of pointers whose buffers
* should be freed)
* ************************************************/
static void freePtrArray(uint8_t *pArr[MAXBUFS], uint32_t arrayLength)
{
uint32_t i = 0;
for (i = 0; i < arrayLength; i++)
free(pArr[i]);
}
static uint32_t bswap4(const uint32_t val)
{
return ((val >> 24) | /**< A*/
((val & 0xff0000) >> 8) | /**< B*/
((val & 0xff00) << 8) | /**< C*/
(val << 24)); /**< D*/
}
int zuc_test(const enum arch_type arch, struct MB_MGR *mb_mgr)
{
uint32_t numBuffs, a;
uint32_t status = PASS_STATUS;
uint8_t *pKeys[MAXBUFS];
uint8_t *pIV[MAXBUFS];
uint8_t *pSrcData[MAXBUFS];
uint8_t *pDstData[MAXBUFS];
/* Do not run the tests for aesni emulation */
if (arch == ARCH_NO_AESNI)
return 0;
printf("Running Functional Tests\n");
fflush(stdout);
/*Create test data buffers + populate with random data*/
if (createData(pSrcData, MAXBUFS)) {
printf("createData() error\n");
return FAIL_STATUS;
}
if (createData(pDstData, MAXBUFS)) {
printf("createData() error\n");
return FAIL_STATUS;
}
/*Create random keys and vectors*/
if (createKeyVecData(ZUC_KEY_LEN_IN_BYTES, pKeys, ZUC_IV_LEN_IN_BYTES,
pIV, MAXBUFS)) {
printf("createKeyVecData() error\n");
freePtrArray(pSrcData, MAXBUFS);
freePtrArray(pDstData, MAXBUFS);
return FAIL_STATUS;
}
if (validate_zuc_algorithm(mb_mgr, pSrcData[0], pSrcData[0], pKeys[0],
pIV[0]))
status = 1;
else
printf("validate ZUC algorithm: PASS\n");
if (validate_zuc_EEA_1_block(mb_mgr, pSrcData[0], pSrcData[0], pKeys[0],
pIV[0]))
status = 1;
else
printf("validate ZUC 1 block: PASS\n");
if (validate_zuc_EEA_4_block(mb_mgr, pSrcData, pSrcData, pKeys, pIV))
status = 1;
else
printf("validate ZUC 4 block: PASS\n");
for (a = 0; a < 3; a++) {
switch (a) {
case 0:
numBuffs = 4;
break;
case 1:
numBuffs = 8;
break;
default:
numBuffs = 9;
break;
}
if (validate_zuc_EEA_n_block(mb_mgr, pSrcData, pDstData, pKeys,
pIV, numBuffs))
status = 1;
else
printf("validate ZUC n block buffers %d: PASS\n", a);
}
if (validate_zuc_EIA_1_block(mb_mgr, pSrcData[0], pDstData[0], pKeys[0],
pIV[0]))
status = 1;
else
printf("validate ZUC Integrity 1 block: PASS\n");
freePtrArray(pKeys, MAXBUFS); /*Free the key buffers*/
freePtrArray(pIV, MAXBUFS); /*Free the vector buffers*/
freePtrArray(pSrcData, MAXBUFS); /*Free the source buffers*/
freePtrArray(pDstData, MAXBUFS); /*Free the destination buffers*/
if (status)
return status;
printf("The Functional Test application completed\n");
return 0;
}
int validate_zuc_EEA_1_block(struct MB_MGR *mb_mgr, uint8_t *pSrcData,
uint8_t *pDstData, uint8_t *pKeys, uint8_t *pIV)
{
uint32_t i, byteResidue;
int retTmp, ret = 0;
uint32_t byteLength;
uint32_t bitResidue;
for (i = 0; i < NUM_ZUC_EEA3_TESTS; i++) {
memcpy(pKeys, testEEA3_vectors[i].CK, ZUC_KEY_LEN_IN_BYTES);
zuc_eea3_iv_gen(testEEA3_vectors[i].count,
testEEA3_vectors[i].Bearer,
testEEA3_vectors[i].Direction,
pIV);
byteLength = (testEEA3_vectors[i].length_in_bits + 7) / 8;
memcpy(pSrcData, testEEA3_vectors[i].plaintext, byteLength);
IMB_ZUC_EEA3_1_BUFFER(mb_mgr, pKeys, pIV, pSrcData, pDstData,
byteLength);
retTmp = memcmp(pDstData, testEEA3_vectors[i].ciphertext,
byteLength - 1);
if (retTmp) {
printf("Validate ZUC 1 block test %d (Enc): FAIL\n",
i + 1);
byte_hexdump("Expected", testEEA3_vectors[i].ciphertext,
byteLength);
byte_hexdump("Found", pDstData, byteLength);
ret = retTmp;
} else {
bitResidue =
(0xFF00 >>
(testEEA3_vectors[i].length_in_bits % 8)) &
0x00FF;
byteResidue =
(testEEA3_vectors[i].ciphertext
[testEEA3_vectors[i].length_in_bits / 8] ^
pDstData[testEEA3_vectors[i].length_in_bits / 8]) &
bitResidue;
if (byteResidue) {
printf("Validate ZUC 1 block test %d (Enc): "
"FAIL\n",
i + 1);
printf("Expected: 0x%02X (last byte)\n",
0xFF &
testEEA3_vectors[i]
.ciphertext[testEEA3_vectors[i]
.length_in_bits /
8]);
printf("Found: 0x%02X (last byte)\n",
0xFF & pDstData[testEEA3_vectors[i]
.length_in_bits /
8]);
} else
printf("Validate ZUC 1 block test %d (Enc): "
"PASS\n",
i + 1);
}
fflush(stdout);
}
return ret;
};
int validate_zuc_EEA_4_block(struct MB_MGR *mb_mgr, uint8_t **pSrcData,
uint8_t **pDstData, uint8_t **pKeys, uint8_t **pIV)
{
uint32_t i, j, packetLen[4], bitResidue, byteResidue;
int retTmp, ret = 0;
for (i = 0; i < NUM_ZUC_EEA3_TESTS; i++) {
for (j = 0; j < 4; j++) {
packetLen[j] =
(testEEA3_vectors[i].length_in_bits + 7) / 8;
memcpy(pKeys[j], testEEA3_vectors[i].CK,
ZUC_KEY_LEN_IN_BYTES);
zuc_eea3_iv_gen(testEEA3_vectors[i].count,
testEEA3_vectors[i].Bearer,
testEEA3_vectors[i].Direction,
pIV[j]);
memcpy(pSrcData[j], testEEA3_vectors[i].plaintext,
packetLen[j]);
}
IMB_ZUC_EEA3_4_BUFFER(mb_mgr, (const void * const *)pKeys,
(const void * const *)pIV,
(const void * const *)pSrcData,
(void **)pDstData, packetLen);
uint8_t *pDst8 = (uint8_t *)pDstData[0];
retTmp = memcmp(pDst8, testEEA3_vectors[i].ciphertext,
(testEEA3_vectors[i].length_in_bits) / 8);
if (retTmp) {
printf("Validate ZUC 4 block (Enc) test %d: FAIL\n",
i + 1);
byte_hexdump("Expected", testEEA3_vectors[i].ciphertext,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
byte_hexdump("Found", pDst8,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
ret = retTmp;
} else {
bitResidue =
(0xFF00 >>
(testEEA3_vectors[i].length_in_bits % 8)) &
0x00FF;
byteResidue =
(testEEA3_vectors[i].ciphertext
[testEEA3_vectors[i].length_in_bits / 8] ^
pDst8[testEEA3_vectors[i].length_in_bits / 8]) &
bitResidue;
if (byteResidue) {
ret = 1;
printf("Validate ZUC 4 block test %d (Enc): "
"FAIL\n",
i + 1);
printf("Expected: 0x%02X (last byte)\n",
0xFF &
testEEA3_vectors[i]
.ciphertext[testEEA3_vectors[i]
.length_in_bits /
8]);
printf("Found: 0x%02X (last byte)\n",
0xFF & pDst8[testEEA3_vectors[i]
.length_in_bits /
8]);
} else
printf("Validate ZUC 4 block test %d (Enc): "
"PASS\n",
i + 1);
}
fflush(stdout);
for (j = 0; j < 4; j++) {
memcpy(pSrcData[j], testEEA3_vectors[i].ciphertext,
(testEEA3_vectors[i].length_in_bits + 7) / 8);
}
IMB_ZUC_EEA3_4_BUFFER(mb_mgr, (const void * const *)pKeys,
(const void * const *)pIV,
(const void * const *)pSrcData,
(void **)pDstData, packetLen);
pDst8 = (uint8_t *)pDstData[0];
retTmp = memcmp(pDst8, testEEA3_vectors[i].plaintext,
(testEEA3_vectors[i].length_in_bits) / 8);
if (retTmp) {
printf("Validate ZUC 4 block (Dec) test %d: FAIL\n",
i + 1);
byte_hexdump("Expected", testEEA3_vectors[i].plaintext,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
byte_hexdump("Found", pDst8,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
ret = retTmp;
} else {
bitResidue =
(0xFF00 >>
(testEEA3_vectors[i].length_in_bits % 8)) &
0x00FF;
byteResidue =
(testEEA3_vectors[i]
.plaintext[testEEA3_vectors[i].length_in_bits /
8] ^
pDst8[testEEA3_vectors[i].length_in_bits / 8]) &
bitResidue;
if (byteResidue) {
ret = 1;
printf("Validate ZUC 4 block test %d (Dec): "
"FAIL\n",
i + 1);
printf("Expected: 0x%02X (last byte)\n",
0xFF &
testEEA3_vectors[i]
.plaintext[testEEA3_vectors[i]
.length_in_bits /
8]);
printf("Found: 0x%02X (last byte)\n",
0xFF & pDst8[testEEA3_vectors[i]
.length_in_bits /
8]);
} else
printf("Validate ZUC 4 block test %d (Dec): "
"PASS\n",
i + 1);
}
fflush(stdout);
}
return ret;
};
int validate_zuc_EEA_n_block(struct MB_MGR *mb_mgr, uint8_t **pSrcData,
uint8_t **pDstData, uint8_t **pKeys, uint8_t **pIV,
uint32_t numBuffs)
{
uint32_t i, j, bitResidue, byteResidue;
int retTmp, ret = 0;
uint32_t packetLen[MAXBUFS];
assert(numBuffs > 0);
for (i = 0; i < NUM_ZUC_EEA3_TESTS; i++) {
for (j = 0; j <= (numBuffs - 1); j++) {
memcpy(pKeys[j], testEEA3_vectors[i].CK,
ZUC_KEY_LEN_IN_BYTES);
zuc_eea3_iv_gen(testEEA3_vectors[i].count,
testEEA3_vectors[i].Bearer,
testEEA3_vectors[i].Direction,
pIV[j]);
memcpy(pSrcData[j], testEEA3_vectors[i].plaintext,
(testEEA3_vectors[i].length_in_bits + 7) / 8);
packetLen[j] =
(testEEA3_vectors[i].length_in_bits + 7) / 8;
}
IMB_ZUC_EEA3_N_BUFFER(mb_mgr, (const void * const *)pKeys,
(const void * const *)pIV,
(const void * const *)pSrcData,
(void **)pDstData, packetLen, numBuffs);
uint8_t *pDst8 = (uint8_t *)pDstData[0];
retTmp = memcmp(pDstData[0], testEEA3_vectors[i].ciphertext,
(testEEA3_vectors[i].length_in_bits) / 8);
if (retTmp) {
printf("Validate ZUC n block (Enc) test %d, buffers: "
"%d: FAIL\n",
i + 1, numBuffs);
byte_hexdump("Expected", testEEA3_vectors[i].ciphertext,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
byte_hexdump("Found", pDst8,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
ret = retTmp;
} else {
bitResidue =
(0xFF00 >>
(testEEA3_vectors[i].length_in_bits % 8)) &
0x00FF;
byteResidue =
(testEEA3_vectors[i].ciphertext
[testEEA3_vectors[i].length_in_bits / 8] ^
pDst8[testEEA3_vectors[i].length_in_bits / 8]) &
bitResidue;
if (byteResidue) {
ret = 1;
printf("Validate ZUC n block (Enc) test %d, "
"buffers %d: FAIL\n",
i + 1, numBuffs);
printf("Expected: 0x%02X (last byte)\n",
0xFF &
testEEA3_vectors[i]
.ciphertext[testEEA3_vectors[i]
.length_in_bits /
8]);
printf("Found: 0x%02X (last byte)\n",
0xFF & pDst8[testEEA3_vectors[i]
.length_in_bits /
8]);
} else
printf("Validate ZUC n block (Enc) test %d, "
"buffers %d: PASS\n",
i + 1, numBuffs);
}
fflush(stdout);
for (j = 0; j <= (numBuffs - 1); j++) {
memcpy(pSrcData[j], testEEA3_vectors[i].ciphertext,
(testEEA3_vectors[i].length_in_bits + 7) / 8);
}
IMB_ZUC_EEA3_N_BUFFER(mb_mgr, (const void * const *)pKeys,
(const void * const *)pIV,
(const void * const *)pSrcData,
(void **)pDstData, packetLen, numBuffs);
retTmp = memcmp(pDstData[0], testEEA3_vectors[i].plaintext,
(testEEA3_vectors[i].length_in_bits) / 8);
if (retTmp) {
printf("Validate ZUC n block (Dec) test %d, buffers "
"%d: FAIL\n",
i + 1, numBuffs);
byte_hexdump("Expected", testEEA3_vectors[i].plaintext,
(testEEA3_vectors[i].length_in_bits + 7) /
8);
byte_hexdump("Found", pDstData[0],
(testEEA3_vectors[i].length_in_bits + 7) /
8);
ret = retTmp;
} else {
bitResidue =
(0xFF00 >>
(testEEA3_vectors[i].length_in_bits % 8)) &
0x00FF;
byteResidue =
(testEEA3_vectors[i]
.plaintext[testEEA3_vectors[i].length_in_bits /
8] ^
pDst8[testEEA3_vectors[i].length_in_bits / 8]) &
bitResidue;
if (byteResidue) {
ret = 1;
printf("Validate ZUC n block (Dec) test %d, "
"buffers %d : FAIL\n",
i + 1, numBuffs);
printf("Expected: 0x%02X (last byte)\n",
0xFF &
testEEA3_vectors[i]
.plaintext[testEEA3_vectors[i]
.length_in_bits /
8]);
printf("Found: 0x%02X (last byte)\n",
0xFF & pDst8[testEEA3_vectors[i]
.length_in_bits /
8]);
} else
printf("Validate ZUC n block (Dec) test %d, "
"buffers %d: PASS\n",
i + 1, numBuffs);
}
fflush(stdout);
}
return ret;
};
int validate_zuc_EIA_1_block(struct MB_MGR *mb_mgr, uint8_t *pSrcData,
uint8_t *pDstData, uint8_t *pKeys, uint8_t *pIV)
{
uint32_t i;
int retTmp, ret = 0;
uint32_t byteLength;
for (i = 0; i < NUM_ZUC_EIA3_TESTS; i++) {
memcpy(pKeys, testEIA3_vectors[i].CK, ZUC_KEY_LEN_IN_BYTES);
zuc_eia3_iv_gen(testEIA3_vectors[i].count,
testEIA3_vectors[i].Bearer,
testEIA3_vectors[i].Direction,
pIV);
byteLength = (testEIA3_vectors[i].length_in_bits + 7) / 8;
memcpy(pSrcData, testEIA3_vectors[i].message, byteLength);
IMB_ZUC_EIA3_1_BUFFER(mb_mgr, pKeys, pIV, pSrcData,
testEIA3_vectors[i].length_in_bits,
(uint32_t *)pDstData);
retTmp =
memcmp(pDstData, &testEIA3_vectors[i].mac,
sizeof(((struct test128EIA3_vectors_t *)0)->mac));
if (retTmp) {
printf("Validate ZUC 1 block test %d (Int): FAIL\n",
i + 1);
byte_hexdump("Expected",
(const uint8_t *)&testEIA3_vectors[i].mac,
ZUC_DIGEST_LEN);
byte_hexdump("Found", pDstData, ZUC_DIGEST_LEN);
ret = retTmp;
} else
printf("Validate ZUC 1 block test %d (Int): PASS\n",
i + 1);
fflush(stdout);
}
return ret;
};
int validate_zuc_algorithm(struct MB_MGR *mb_mgr, uint8_t *pSrcData,
uint8_t *pDstData, uint8_t *pKeys, uint8_t *pIV)
{
uint32_t i;
int ret = 0;
union SwapBytes {
uint8_t sbb[8];
uint32_t sbw[2];
} swapBytes;
for (i = 0; i < NUM_ZUC_ALG_TESTS; i++) {
memcpy(pKeys, testZUC_vectors[i].CK, ZUC_KEY_LEN_IN_BYTES);
memcpy(pIV, testZUC_vectors[i].IV, ZUC_IV_LEN_IN_BYTES);
memset(pSrcData, 0, 8);
IMB_ZUC_EEA3_1_BUFFER(mb_mgr, pKeys, pIV, pSrcData, pDstData,
8);
swapBytes.sbw[0] = bswap4(testZUC_vectors[i].Z[0]);
swapBytes.sbw[1] = bswap4(testZUC_vectors[i].Z[1]);
ret = memcmp(pDstData, swapBytes.sbb, 8);
if (ret)
printf("ZUC 1 algorithm test %d: FAIL\n", i);
else
printf("ZUC 1 algorithm test %d: PASS\n", i);
}
return ret;
};
/*****************************************************************************
** @description - utility function to dump test buffers$
** $
** @param message [IN] - debug message to print$
** @param ptr [IN] - pointer to beginning of buffer.$
** @param len [IN] - length of buffer.$
*****************************************************************************/
static void byte_hexdump(const char *message, const uint8_t *ptr, int len)
{
int ctr;
printf("%s:\n", message);
for (ctr = 0; ctr < len; ctr++) {
printf("0x%02X ", ptr[ctr] & 0xff);
if (!((ctr + 1) % 16))
printf("\n");
}
printf("\n");
printf("\n");
};
|