1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 @file pelican_test.c
7 Pelican MAC, test, by Tom St Denis
8 */
9
10 #ifdef LTC_PELICAN
11
pelican_test(void)12 int pelican_test(void)
13 {
14 #ifndef LTC_TEST
15 return CRYPT_NOP;
16 #else
17 static const struct {
18 unsigned char K[32], MSG[64], T[16];
19 int keylen, ptlen;
20 } tests[] = {
21 /* K=16, M=0 */
22 {
23 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
24 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
25 { 0 },
26 { 0xeb, 0x58, 0x37, 0x15, 0xf8, 0x34, 0xde, 0xe5,
27 0xa4, 0xd1, 0x6e, 0xe4, 0xb9, 0xd7, 0x76, 0x0e, },
28 16, 0
29 },
30
31 /* K=16, M=3 */
32 {
33 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
34 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
35 { 0x00, 0x01, 0x02 },
36 { 0x1c, 0x97, 0x40, 0x60, 0x6c, 0x58, 0x17, 0x2d,
37 0x03, 0x94, 0x19, 0x70, 0x81, 0xc4, 0x38, 0x54, },
38 16, 3
39 },
40
41 /* K=16, M=16 */
42 {
43 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
44 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
45 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
46 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
47 { 0x03, 0xcc, 0x46, 0xb8, 0xac, 0xa7, 0x9c, 0x36,
48 0x1e, 0x8c, 0x6e, 0xa6, 0x7b, 0x89, 0x32, 0x49, },
49 16, 16
50 },
51
52 /* K=16, M=32 */
53 {
54 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
55 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
56 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
57 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
58 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
59 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F },
60 { 0x89, 0xcc, 0x36, 0x58, 0x1b, 0xdd, 0x4d, 0xb5,
61 0x78, 0xbb, 0xac, 0xf0, 0xff, 0x8b, 0x08, 0x15, },
62 16, 32
63 },
64
65 /* K=16, M=35 */
66 {
67 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
68 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F },
69 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
70 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
71 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
72 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
73 0x20, 0x21, 0x23 },
74 { 0x4a, 0x7d, 0x45, 0x4d, 0xcd, 0xb5, 0xda, 0x8d,
75 0x48, 0x78, 0x16, 0x48, 0x5d, 0x45, 0x95, 0x99, },
76 16, 35
77 },
78 };
79 int x, err;
80 unsigned char out[16];
81 pelican_state pel;
82
83 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
84 if ((err = pelican_init(&pel, tests[x].K, tests[x].keylen)) != CRYPT_OK) {
85 return err;
86 }
87 if ((err = pelican_process(&pel, tests[x].MSG, tests[x].ptlen)) != CRYPT_OK) {
88 return err;
89 }
90 if ((err = pelican_done(&pel, out)) != CRYPT_OK) {
91 return err;
92 }
93
94 if (compare_testvector(out, 16, tests[x].T, 16, "PELICAN", x)) {
95 return CRYPT_FAIL_TESTVECTOR;
96 }
97 }
98 return CRYPT_OK;
99 #endif
100 }
101
102
103 #endif
104