Mercurial > dropbear
comparison libtomcrypt/src/modes/lrw/lrw_test.c @ 398:59c7938af2bd
merge of '1250b8af44b62d8f4fe0f8d9fc7e7a1cc34e7e1c'
and '7f8670ac3bb975f40967f3979d09d2199b7e90c8'
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 03 Feb 2007 08:20:30 +0000 |
parents | 0cbe8f6dbf9e |
children | f849a5ca2efc |
comparison
equal
deleted
inserted
replaced
396:e7c1a77d2921 | 398:59c7938af2bd |
---|---|
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.com | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file lrw_test.c | |
15 LRW_MODE implementation, test LRW, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef LTC_LRW_MODE | |
19 | |
20 /** | |
21 Test LRW against specs | |
22 @return CRYPT_OK if goodly | |
23 */ | |
24 int lrw_test(void) | |
25 { | |
26 #ifndef LTC_TEST | |
27 return CRYPT_NOP; | |
28 #else | |
29 static const struct { | |
30 unsigned char key[16], tweak[16], IV[16], P[16], expected_tweak[16], C[16]; | |
31 } tests[] = { | |
32 | |
33 { | |
34 { 0x45, 0x62, 0xac, 0x25, 0xf8, 0x28, 0x17, 0x6d, 0x4c, 0x26, 0x84, 0x14, 0xb5, 0x68, 0x01, 0x85 }, | |
35 { 0x25, 0x8e, 0x2a, 0x05, 0xe7, 0x3e, 0x9d, 0x03, 0xee, 0x5a, 0x83, 0x0c, 0xcc, 0x09, 0x4c, 0x87 }, | |
36 { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
37 { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, | |
38 { 0x25, 0x8e, 0x2a, 0x05, 0xe7, 0x3e, 0x9d, 0x03, 0xee, 0x5a, 0x83, 0x0c, 0xcc, 0x09, 0x4c, 0x87 }, | |
39 { 0xf1, 0xb2, 0x73, 0xcd, 0x65, 0xa3, 0xdf, 0x5f, 0xe9, 0x5d, 0x48, 0x92, 0x54, 0x63, 0x4e, 0xb8 } | |
40 }, | |
41 | |
42 { | |
43 { 0x59, 0x70, 0x47, 0x14, 0xf5, 0x57, 0x47, 0x8c, 0xd7, 0x79, 0xe8, 0x0f, 0x54, 0x88, 0x79, 0x44 }, | |
44 { 0x35, 0x23, 0xc2, 0xde, 0xc5, 0x69, 0x4f, 0xa8, 0x72, 0xa9, 0xac, 0xa7, 0x0b, 0x2b, 0xee, 0xbc }, | |
45 { 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | |
46 { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, | |
47 { 0x1a, 0x91, 0xe1, 0x6f, 0x62, 0xb4, 0xa7, 0xd4, 0x39, 0x54, 0xd6, 0x53, 0x85, 0x95, 0xf7, 0x5e }, | |
48 { 0x00, 0xc8, 0x2b, 0xae, 0x95, 0xbb, 0xcd, 0xe5, 0x27, 0x4f, 0x07, 0x69, 0xb2, 0x60, 0xe1, 0x36 }, | |
49 }, | |
50 | |
51 { | |
52 { 0x59, 0x70, 0x47, 0x14, 0xf5, 0x57, 0x47, 0x8c, 0xd7, 0x79, 0xe8, 0x0f, 0x54, 0x88, 0x79, 0x44 }, | |
53 { 0x67, 0x53, 0xc9, 0x0c, 0xb7, 0xd8, 0xcd, 0xe5, 0x06, 0xa0, 0x47, 0x78, 0x1a, 0xad, 0x85, 0x11 }, | |
54 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 }, | |
55 { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, | |
56 { 0x1a, 0x91, 0xe1, 0x6f, 0x62, 0xb4, 0xa7, 0xd4, 0x39, 0x54, 0xd6, 0x53, 0x85, 0x95, 0xf7, 0x5e }, | |
57 { 0x00, 0xc8, 0x2b, 0xae, 0x95, 0xbb, 0xcd, 0xe5, 0x27, 0x4f, 0x07, 0x69, 0xb2, 0x60, 0xe1, 0x36 }, | |
58 }, | |
59 | |
60 { | |
61 | |
62 { 0xd8, 0x2a, 0x91, 0x34, 0xb2, 0x6a, 0x56, 0x50, 0x30, 0xfe, 0x69, 0xe2, 0x37, 0x7f, 0x98, 0x47 }, | |
63 { 0x4e, 0xb5, 0x5d, 0x31, 0x05, 0x97, 0x3a, 0x3f, 0x5e, 0x23, 0xda, 0xfb, 0x5a, 0x45, 0xd6, 0xc0 }, | |
64 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 }, | |
65 { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 }, | |
66 { 0x18, 0xc9, 0x1f, 0x6d, 0x60, 0x1a, 0x1a, 0x37, 0x5d, 0x0b, 0x0e, 0xf7, 0x3a, 0xd5, 0x74, 0xc4 }, | |
67 { 0x76, 0x32, 0x21, 0x83, 0xed, 0x8f, 0xf1, 0x82, 0xf9, 0x59, 0x62, 0x03, 0x69, 0x0e, 0x5e, 0x01 }, | |
68 | |
69 } | |
70 }; | |
71 | |
72 int idx, err, x; | |
73 symmetric_LRW lrw; | |
74 unsigned char buf[2][16]; | |
75 | |
76 idx = find_cipher("aes"); | |
77 if (idx == -1) { | |
78 idx = find_cipher("rijndael"); | |
79 if (idx == -1) { | |
80 return CRYPT_NOP; | |
81 } | |
82 } | |
83 | |
84 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { | |
85 /* schedule it */ | |
86 if ((err = lrw_start(idx, tests[x].IV, tests[x].key, 16, tests[x].tweak, 0, &lrw)) != CRYPT_OK) { | |
87 return err; | |
88 } | |
89 | |
90 /* check pad against expected tweak */ | |
91 if (XMEMCMP(tests[x].expected_tweak, lrw.pad, 16)) { | |
92 lrw_done(&lrw); | |
93 return CRYPT_FAIL_TESTVECTOR; | |
94 } | |
95 | |
96 /* process block */ | |
97 if ((err = lrw_encrypt(tests[x].P, buf[0], 16, &lrw)) != CRYPT_OK) { | |
98 lrw_done(&lrw); | |
99 return err; | |
100 } | |
101 | |
102 if (XMEMCMP(buf[0], tests[x].C, 16)) { | |
103 lrw_done(&lrw); | |
104 return CRYPT_FAIL_TESTVECTOR; | |
105 } | |
106 | |
107 /* process block */ | |
108 if ((err = lrw_setiv(tests[x].IV, 16, &lrw)) != CRYPT_OK) { | |
109 lrw_done(&lrw); | |
110 return err; | |
111 } | |
112 | |
113 if ((err = lrw_decrypt(buf[0], buf[1], 16, &lrw)) != CRYPT_OK) { | |
114 lrw_done(&lrw); | |
115 return err; | |
116 } | |
117 | |
118 if (XMEMCMP(buf[1], tests[x].P, 16)) { | |
119 lrw_done(&lrw); | |
120 return CRYPT_FAIL_TESTVECTOR; | |
121 } | |
122 if ((err = lrw_done(&lrw)) != CRYPT_OK) { | |
123 return err; | |
124 } | |
125 } | |
126 return CRYPT_OK; | |
127 #endif | |
128 } | |
129 | |
130 #endif | |
131 | |
132 | |
133 | |
134 /* $Source: /cvs/libtom/libtomcrypt/src/modes/lrw/lrw_test.c,v $ */ | |
135 /* $Revision: 1.11 $ */ | |
136 /* $Date: 2006/06/29 01:53:13 $ */ |