Mercurial > dropbear
comparison src/mac/pmac/pmac_test.c @ 191:1c15b283127b libtomcrypt-orig
Import of libtomcrypt 1.02 with manual path rename rearrangement etc
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 06 May 2005 13:23:02 +0000 |
parents | |
children | 39d5d58461d6 |
comparison
equal
deleted
inserted
replaced
143:5d99163f7e32 | 191:1c15b283127b |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 * | |
9 * Tom St Denis, [email protected], http://libtomcrypt.org | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file pmac_test.c | |
15 PMAC implementation, self-test, by Tom St Denis | |
16 */ | |
17 | |
18 | |
19 #ifdef PMAC | |
20 | |
21 /** | |
22 Test the OMAC implementation | |
23 @return CRYPT_OK if successful, CRYPT_NOP if testing has been disabled | |
24 */ | |
25 int pmac_test(void) | |
26 { | |
27 #if !defined(LTC_TEST) | |
28 return CRYPT_NOP; | |
29 #else | |
30 static const struct { | |
31 int msglen; | |
32 unsigned char key[16], msg[34], tag[16]; | |
33 } tests[] = { | |
34 | |
35 /* PMAC-AES-128-0B */ | |
36 { | |
37 0, | |
38 /* key */ | |
39 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
40 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
41 /* msg */ | |
42 { 0x00 }, | |
43 /* tag */ | |
44 { 0x43, 0x99, 0x57, 0x2c, 0xd6, 0xea, 0x53, 0x41, | |
45 0xb8, 0xd3, 0x58, 0x76, 0xa7, 0x09, 0x8a, 0xf7 } | |
46 }, | |
47 | |
48 /* PMAC-AES-128-3B */ | |
49 { | |
50 3, | |
51 /* key */ | |
52 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
53 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
54 /* msg */ | |
55 { 0x00, 0x01, 0x02 }, | |
56 /* tag */ | |
57 { 0x25, 0x6b, 0xa5, 0x19, 0x3c, 0x1b, 0x99, 0x1b, | |
58 0x4d, 0xf0, 0xc5, 0x1f, 0x38, 0x8a, 0x9e, 0x27 } | |
59 }, | |
60 | |
61 /* PMAC-AES-128-16B */ | |
62 { | |
63 16, | |
64 /* key */ | |
65 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
66 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
67 /* msg */ | |
68 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
69 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
70 /* tag */ | |
71 { 0xeb, 0xbd, 0x82, 0x2f, 0xa4, 0x58, 0xda, 0xf6, | |
72 0xdf, 0xda, 0xd7, 0xc2, 0x7d, 0xa7, 0x63, 0x38 } | |
73 }, | |
74 | |
75 /* PMAC-AES-128-20B */ | |
76 { | |
77 20, | |
78 /* key */ | |
79 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
80 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
81 /* msg */ | |
82 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
83 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
84 0x10, 0x11, 0x12, 0x13 }, | |
85 /* tag */ | |
86 { 0x04, 0x12, 0xca, 0x15, 0x0b, 0xbf, 0x79, 0x05, | |
87 0x8d, 0x8c, 0x75, 0xa5, 0x8c, 0x99, 0x3f, 0x55 } | |
88 }, | |
89 | |
90 /* PMAC-AES-128-32B */ | |
91 { | |
92 32, | |
93 /* key */ | |
94 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
95 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
96 /* msg */ | |
97 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
98 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
99 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | |
100 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f }, | |
101 /* tag */ | |
102 { 0xe9, 0x7a, 0xc0, 0x4e, 0x9e, 0x5e, 0x33, 0x99, | |
103 0xce, 0x53, 0x55, 0xcd, 0x74, 0x07, 0xbc, 0x75 } | |
104 }, | |
105 | |
106 /* PMAC-AES-128-34B */ | |
107 { | |
108 34, | |
109 /* key */ | |
110 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
111 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f }, | |
112 /* msg */ | |
113 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
114 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, | |
115 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | |
116 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, | |
117 0x20, 0x21 }, | |
118 /* tag */ | |
119 { 0x5c, 0xba, 0x7d, 0x5e, 0xb2, 0x4f, 0x7c, 0x86, | |
120 0xcc, 0xc5, 0x46, 0x04, 0xe5, 0x3d, 0x55, 0x12 } | |
121 } | |
122 | |
123 }; | |
124 int err, x, idx; | |
125 unsigned long len; | |
126 unsigned char outtag[MAXBLOCKSIZE]; | |
127 | |
128 /* AES can be under rijndael or aes... try to find it */ | |
129 if ((idx = find_cipher("aes")) == -1) { | |
130 if ((idx = find_cipher("rijndael")) == -1) { | |
131 return CRYPT_NOP; | |
132 } | |
133 } | |
134 | |
135 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { | |
136 len = sizeof(outtag); | |
137 if ((err = pmac_memory(idx, tests[x].key, 16, tests[x].msg, tests[x].msglen, outtag, &len)) != CRYPT_OK) { | |
138 return err; | |
139 } | |
140 | |
141 if (memcmp(outtag, tests[x].tag, len)) { | |
142 #if 0 | |
143 unsigned long y; | |
144 printf("\nTAG:\n"); | |
145 for (y = 0; y < len; ) { | |
146 printf("0x%02x", outtag[y]); | |
147 if (y < len-1) printf(", "); | |
148 if (!(++y % 8)) printf("\n"); | |
149 } | |
150 #endif | |
151 return CRYPT_FAIL_TESTVECTOR; | |
152 } | |
153 } | |
154 return CRYPT_OK; | |
155 #endif /* LTC_TEST */ | |
156 } | |
157 | |
158 #endif /* PMAC_MODE */ | |
159 | |
160 | |
161 |