Mercurial > dropbear
comparison libtomcrypt/src/mac/pmac/pmac_test.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 #include "tomcrypt.h" | 9 #include "tomcrypt.h" |
12 | 10 |
13 /** | 11 /** |
14 @file pmac_test.c | 12 @file pmac_test.c |
15 PMAC implementation, self-test, by Tom St Denis | 13 PMAC implementation, self-test, by Tom St Denis |
16 */ | 14 */ |
17 | 15 |
18 | 16 |
19 #ifdef LTC_PMAC | 17 #ifdef LTC_PMAC |
20 | 18 |
21 /** | 19 /** |
22 Test the LTC_OMAC implementation | 20 Test the LTC_OMAC implementation |
23 @return CRYPT_OK if successful, CRYPT_NOP if testing has been disabled | 21 @return CRYPT_OK if successful, CRYPT_NOP if testing has been disabled |
24 */ | 22 */ |
25 int pmac_test(void) | 23 int pmac_test(void) |
26 { | 24 { |
27 #if !defined(LTC_TEST) | 25 #if !defined(LTC_TEST) |
28 return CRYPT_NOP; | 26 return CRYPT_NOP; |
29 #else | 27 #else |
30 static const struct { | 28 static const struct { |
31 int msglen; | 29 int msglen; |
32 unsigned char key[16], msg[34], tag[16]; | 30 unsigned char key[16], msg[34], tag[16]; |
33 } tests[] = { | 31 } tests[] = { |
34 | 32 |
35 /* PMAC-AES-128-0B */ | 33 /* PMAC-AES-128-0B */ |
123 }; | 121 }; |
124 int err, x, idx; | 122 int err, x, idx; |
125 unsigned long len; | 123 unsigned long len; |
126 unsigned char outtag[MAXBLOCKSIZE]; | 124 unsigned char outtag[MAXBLOCKSIZE]; |
127 | 125 |
128 /* AES can be under rijndael or aes... try to find it */ | 126 /* AES can be under rijndael or aes... try to find it */ |
129 if ((idx = find_cipher("aes")) == -1) { | 127 if ((idx = find_cipher("aes")) == -1) { |
130 if ((idx = find_cipher("rijndael")) == -1) { | 128 if ((idx = find_cipher("rijndael")) == -1) { |
131 return CRYPT_NOP; | 129 return CRYPT_NOP; |
132 } | 130 } |
133 } | 131 } |
135 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { | 133 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { |
136 len = sizeof(outtag); | 134 len = sizeof(outtag); |
137 if ((err = pmac_memory(idx, tests[x].key, 16, tests[x].msg, tests[x].msglen, outtag, &len)) != CRYPT_OK) { | 135 if ((err = pmac_memory(idx, tests[x].key, 16, tests[x].msg, tests[x].msglen, outtag, &len)) != CRYPT_OK) { |
138 return err; | 136 return err; |
139 } | 137 } |
140 | 138 |
141 if (XMEMCMP(outtag, tests[x].tag, len)) { | 139 if (compare_testvector(outtag, len, tests[x].tag, sizeof(tests[x].tag), "PMAC", x)) { |
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; | 140 return CRYPT_FAIL_TESTVECTOR; |
152 } | 141 } |
153 } | 142 } |
154 return CRYPT_OK; | 143 return CRYPT_OK; |
155 #endif /* LTC_TEST */ | 144 #endif /* LTC_TEST */ |
156 } | 145 } |
157 | 146 |
158 #endif /* PMAC_MODE */ | 147 #endif /* PMAC_MODE */ |
159 | 148 |
160 | 149 |
161 | |
162 | 150 |
163 /* $Source$ */ | 151 |
164 /* $Revision$ */ | 152 /* ref: $Format:%D$ */ |
165 /* $Date$ */ | 153 /* git commit: $Format:%H$ */ |
154 /* commit time: $Format:%ai$ */ |