Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 1 | /* BEGIN_HEADER */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 2 | #include <polarssl/des.h> |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 3 | /* END_HEADER */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 4 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 5 | /* BEGIN_DEPENDENCIES |
| 6 | * depends_on:POLARSSL_DES_C |
| 7 | * END_DEPENDENCIES |
| 8 | */ |
Paul Bakker | 5690efc | 2011-05-26 13:16:06 +0000 | [diff] [blame] | 9 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 10 | /* BEGIN_CASE */ |
| 11 | void des_encrypt_ecb( char *hex_key_string, char *hex_src_string, |
| 12 | char *hex_dst_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 13 | { |
| 14 | unsigned char key_str[100]; |
| 15 | unsigned char src_str[100]; |
| 16 | unsigned char dst_str[100]; |
| 17 | unsigned char output[100]; |
| 18 | des_context ctx; |
| 19 | |
| 20 | memset(key_str, 0x00, 100); |
| 21 | memset(src_str, 0x00, 100); |
| 22 | memset(dst_str, 0x00, 100); |
| 23 | memset(output, 0x00, 100); |
| 24 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 25 | unhexify( key_str, hex_key_string ); |
| 26 | unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 27 | |
| 28 | des_setkey_enc( &ctx, key_str ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 29 | TEST_ASSERT( des_crypt_ecb( &ctx, src_str, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 30 | hexify( dst_str, output, 8 ); |
| 31 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 32 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 33 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 34 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 35 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 36 | /* BEGIN_CASE */ |
| 37 | void des_decrypt_ecb( char *hex_key_string, char *hex_src_string, |
| 38 | char *hex_dst_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 39 | { |
| 40 | unsigned char key_str[100]; |
| 41 | unsigned char src_str[100]; |
| 42 | unsigned char dst_str[100]; |
| 43 | unsigned char output[100]; |
| 44 | des_context ctx; |
| 45 | |
| 46 | memset(key_str, 0x00, 100); |
| 47 | memset(src_str, 0x00, 100); |
| 48 | memset(dst_str, 0x00, 100); |
| 49 | memset(output, 0x00, 100); |
| 50 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 51 | unhexify( key_str, hex_key_string ); |
| 52 | unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 53 | |
| 54 | des_setkey_dec( &ctx, key_str ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 55 | TEST_ASSERT( des_crypt_ecb( &ctx, src_str, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 56 | hexify( dst_str, output, 8 ); |
| 57 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 58 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 59 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 60 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 61 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 62 | /* BEGIN_CASE */ |
| 63 | void des_encrypt_cbc( char *hex_key_string, char *hex_iv_string, |
| 64 | char *hex_src_string, char *hex_dst_string, int cbc_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 65 | { |
| 66 | unsigned char key_str[100]; |
| 67 | unsigned char iv_str[100]; |
| 68 | unsigned char src_str[100]; |
| 69 | unsigned char dst_str[100]; |
| 70 | unsigned char output[100]; |
| 71 | des_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 72 | int src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 73 | |
| 74 | memset(key_str, 0x00, 100); |
| 75 | memset(iv_str, 0x00, 100); |
| 76 | memset(src_str, 0x00, 100); |
| 77 | memset(dst_str, 0x00, 100); |
| 78 | memset(output, 0x00, 100); |
| 79 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 80 | unhexify( key_str, hex_key_string ); |
| 81 | unhexify( iv_str, hex_iv_string ); |
| 82 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 83 | |
| 84 | des_setkey_enc( &ctx, key_str ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 85 | TEST_ASSERT( des_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result ); |
| 86 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 87 | { |
| 88 | hexify( dst_str, output, src_len ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 89 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 90 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 91 | } |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 92 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 93 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 94 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 95 | /* BEGIN_CASE */ |
| 96 | void des_decrypt_cbc( char *hex_key_string, char *hex_iv_string, |
| 97 | char *hex_src_string, char *hex_dst_string, int cbc_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 98 | { |
| 99 | unsigned char key_str[100]; |
| 100 | unsigned char iv_str[100]; |
| 101 | unsigned char src_str[100]; |
| 102 | unsigned char dst_str[100]; |
| 103 | unsigned char output[100]; |
| 104 | des_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 105 | int src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 106 | |
| 107 | memset(key_str, 0x00, 100); |
| 108 | memset(iv_str, 0x00, 100); |
| 109 | memset(src_str, 0x00, 100); |
| 110 | memset(dst_str, 0x00, 100); |
| 111 | memset(output, 0x00, 100); |
| 112 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 113 | unhexify( key_str, hex_key_string ); |
| 114 | unhexify( iv_str, hex_iv_string ); |
| 115 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 116 | |
| 117 | des_setkey_dec( &ctx, key_str ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 118 | TEST_ASSERT( des_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result ); |
| 119 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 120 | { |
| 121 | hexify( dst_str, output, src_len ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 122 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 123 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 124 | } |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 125 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 126 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 127 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 128 | /* BEGIN_CASE */ |
| 129 | void des3_encrypt_ecb( int key_count, char *hex_key_string, |
| 130 | char *hex_src_string, char *hex_dst_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 131 | { |
| 132 | unsigned char key_str[100]; |
| 133 | unsigned char src_str[100]; |
| 134 | unsigned char dst_str[100]; |
| 135 | unsigned char output[100]; |
| 136 | des3_context ctx; |
| 137 | |
| 138 | memset(key_str, 0x00, 100); |
| 139 | memset(src_str, 0x00, 100); |
| 140 | memset(dst_str, 0x00, 100); |
| 141 | memset(output, 0x00, 100); |
| 142 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 143 | unhexify( key_str, hex_key_string ); |
| 144 | unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 145 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 146 | if( key_count == 2 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 147 | des3_set2key_enc( &ctx, key_str ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 148 | else if( key_count == 3 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 149 | des3_set3key_enc( &ctx, key_str ); |
| 150 | else |
| 151 | TEST_ASSERT( 0 ); |
| 152 | |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 153 | TEST_ASSERT( des3_crypt_ecb( &ctx, src_str, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 154 | hexify( dst_str, output, 8 ); |
| 155 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 156 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 157 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 158 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 159 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 160 | /* BEGIN_CASE */ |
| 161 | void des3_decrypt_ecb( int key_count, char *hex_key_string, |
| 162 | char *hex_src_string, char *hex_dst_string ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 163 | { |
| 164 | unsigned char key_str[100]; |
| 165 | unsigned char src_str[100]; |
| 166 | unsigned char dst_str[100]; |
| 167 | unsigned char output[100]; |
| 168 | des3_context ctx; |
| 169 | |
| 170 | memset(key_str, 0x00, 100); |
| 171 | memset(src_str, 0x00, 100); |
| 172 | memset(dst_str, 0x00, 100); |
| 173 | memset(output, 0x00, 100); |
| 174 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 175 | unhexify( key_str, hex_key_string ); |
| 176 | unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 177 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 178 | if( key_count == 2 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 179 | des3_set2key_dec( &ctx, key_str ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 180 | else if( key_count == 3 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 181 | des3_set3key_dec( &ctx, key_str ); |
| 182 | else |
| 183 | TEST_ASSERT( 0 ); |
| 184 | |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 185 | TEST_ASSERT( des3_crypt_ecb( &ctx, src_str, output ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 186 | hexify( dst_str, output, 8 ); |
| 187 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 188 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 189 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 190 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 191 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 192 | /* BEGIN_CASE */ |
| 193 | void des3_encrypt_cbc( int key_count, char *hex_key_string, |
| 194 | char *hex_iv_string, char *hex_src_string, |
| 195 | char *hex_dst_string, int cbc_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 196 | { |
| 197 | unsigned char key_str[100]; |
| 198 | unsigned char iv_str[100]; |
| 199 | unsigned char src_str[100]; |
| 200 | unsigned char dst_str[100]; |
| 201 | unsigned char output[100]; |
| 202 | des3_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 203 | int src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 204 | |
| 205 | memset(key_str, 0x00, 100); |
| 206 | memset(iv_str, 0x00, 100); |
| 207 | memset(src_str, 0x00, 100); |
| 208 | memset(dst_str, 0x00, 100); |
| 209 | memset(output, 0x00, 100); |
| 210 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 211 | unhexify( key_str, hex_key_string ); |
| 212 | unhexify( iv_str, hex_iv_string ); |
| 213 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 214 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 215 | if( key_count == 2 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 216 | des3_set2key_enc( &ctx, key_str ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 217 | else if( key_count == 3 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 218 | des3_set3key_enc( &ctx, key_str ); |
| 219 | else |
| 220 | TEST_ASSERT( 0 ); |
| 221 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 222 | TEST_ASSERT( des3_crypt_cbc( &ctx, DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result ); |
Paul Bakker | 02722ea | 2011-05-25 11:34:44 +0000 | [diff] [blame] | 223 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 224 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 225 | { |
| 226 | hexify( dst_str, output, src_len ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 227 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 228 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 229 | } |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 230 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 231 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 232 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 233 | /* BEGIN_CASE */ |
| 234 | void des3_decrypt_cbc( int key_count, char *hex_key_string, |
| 235 | char *hex_iv_string, char *hex_src_string, |
| 236 | char *hex_dst_string, int cbc_result ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 237 | { |
| 238 | unsigned char key_str[100]; |
| 239 | unsigned char iv_str[100]; |
| 240 | unsigned char src_str[100]; |
| 241 | unsigned char dst_str[100]; |
| 242 | unsigned char output[100]; |
| 243 | des3_context ctx; |
Paul Bakker | 69998dd | 2009-07-11 19:15:20 +0000 | [diff] [blame] | 244 | int src_len; |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 245 | |
| 246 | memset(key_str, 0x00, 100); |
| 247 | memset(iv_str, 0x00, 100); |
| 248 | memset(src_str, 0x00, 100); |
| 249 | memset(dst_str, 0x00, 100); |
| 250 | memset(output, 0x00, 100); |
| 251 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 252 | unhexify( key_str, hex_key_string ); |
| 253 | unhexify( iv_str, hex_iv_string ); |
| 254 | src_len = unhexify( src_str, hex_src_string ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 255 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 256 | if( key_count == 2 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 257 | des3_set2key_dec( &ctx, key_str ); |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 258 | else if( key_count == 3 ) |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 259 | des3_set3key_dec( &ctx, key_str ); |
| 260 | else |
| 261 | TEST_ASSERT( 0 ); |
| 262 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 263 | TEST_ASSERT( des3_crypt_cbc( &ctx, DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result ); |
Paul Bakker | 02722ea | 2011-05-25 11:34:44 +0000 | [diff] [blame] | 264 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 265 | if( cbc_result == 0 ) |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 266 | { |
| 267 | hexify( dst_str, output, src_len ); |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 268 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 269 | TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 ); |
Paul Bakker | f3ccc68 | 2010-03-18 21:21:02 +0000 | [diff] [blame] | 270 | } |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 271 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 272 | /* END_CASE */ |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 273 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 274 | /* BEGIN_CASE */ |
| 275 | void des_key_parity_run() |
Paul Bakker | 1f87fb6 | 2011-01-15 17:32:24 +0000 | [diff] [blame] | 276 | { |
| 277 | int i, j, cnt; |
| 278 | unsigned char key[DES_KEY_SIZE]; |
| 279 | unsigned int parity; |
| 280 | |
| 281 | memset( key, 0, DES_KEY_SIZE ); |
| 282 | cnt = 0; |
| 283 | |
| 284 | // Iterate through all possible byte values |
| 285 | // |
| 286 | for( i = 0; i < 32; i++ ) |
| 287 | { |
| 288 | for( j = 0; j < 8; j++ ) |
| 289 | key[j] = cnt++; |
| 290 | |
| 291 | // Set the key parity according to the table |
| 292 | // |
| 293 | des_key_set_parity( key ); |
| 294 | |
| 295 | // Check the parity with a function |
| 296 | // |
| 297 | for( j = 0; j < 8; j++ ) |
| 298 | { |
| 299 | parity = key[j] ^ ( key[j] >> 4 ); |
| 300 | parity = parity ^ |
| 301 | ( parity >> 1 ) ^ |
| 302 | ( parity >> 2 ) ^ |
| 303 | ( parity >> 3 ); |
| 304 | parity &= 1; |
| 305 | |
| 306 | if( parity != 1 ) |
| 307 | TEST_ASSERT( 0 ); |
| 308 | } |
| 309 | |
| 310 | // Check the parity with the table |
| 311 | // |
| 312 | TEST_ASSERT( des_key_check_key_parity( key ) == 0 ); |
| 313 | } |
| 314 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 315 | /* END_CASE */ |
Paul Bakker | 1f87fb6 | 2011-01-15 17:32:24 +0000 | [diff] [blame] | 316 | |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 317 | /* BEGIN_CASE */ |
| 318 | void des_selftest() |
Paul Bakker | e896fea | 2009-07-06 06:40:23 +0000 | [diff] [blame] | 319 | { |
| 320 | TEST_ASSERT( des_self_test( 0 ) == 0 ); |
| 321 | } |
Paul Bakker | 33b43f1 | 2013-08-20 11:48:36 +0200 | [diff] [blame] | 322 | /* END_CASE */ |