blob: 3d1bb9235c260546607b52327543040b99ef6063 [file] [log] [blame]
Paul Bakker33b43f12013-08-20 11:48:36 +02001/* BEGIN_HEADER */
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +00002#include "mbedtls/des.h"
Paul Bakker33b43f12013-08-20 11:48:36 +02003/* END_HEADER */
Paul Bakkere896fea2009-07-06 06:40:23 +00004
Paul Bakker33b43f12013-08-20 11:48:36 +02005/* BEGIN_DEPENDENCIES
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02006 * depends_on:MBEDTLS_DES_C
Paul Bakker33b43f12013-08-20 11:48:36 +02007 * END_DEPENDENCIES
8 */
Paul Bakker5690efc2011-05-26 13:16:06 +00009
Paul Bakker33b43f12013-08-20 11:48:36 +020010/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +010011void des_check_weak( uint8_t * key, uint32_t key_len, int ret )
Manuel Pégourié-Gonnard9ce7e842014-03-29 17:06:43 +010012{
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020013 TEST_ASSERT( mbedtls_des_key_check_weak( key ) == ret );
Manuel Pégourié-Gonnard9ce7e842014-03-29 17:06:43 +010014}
15/* END_CASE */
16
17/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +010018void des_encrypt_ecb( uint8_t * key_str, uint32_t key_str_len,
19 uint8_t * src_str, uint32_t src_str_len,
20 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Paul Bakkere896fea2009-07-06 06:40:23 +000021{
Paul Bakkere896fea2009-07-06 06:40:23 +000022 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020023 mbedtls_des_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000024
Paul Bakkere896fea2009-07-06 06:40:23 +000025 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020026 mbedtls_des_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000027
Paul Bakkere896fea2009-07-06 06:40:23 +000028
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020029 mbedtls_des_setkey_enc( &ctx, key_str );
30 TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +000031
Azim Khanf1aaec92017-05-30 14:23:15 +010032 TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +020033
Paul Bakkerbd51b262014-07-10 15:26:12 +020034exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020035 mbedtls_des_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000036}
Paul Bakker33b43f12013-08-20 11:48:36 +020037/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000038
Paul Bakker33b43f12013-08-20 11:48:36 +020039/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +010040void des_decrypt_ecb( uint8_t * key_str, uint32_t key_str_len,
41 uint8_t * src_str, uint32_t src_str_len,
42 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Paul Bakkere896fea2009-07-06 06:40:23 +000043{
Paul Bakkere896fea2009-07-06 06:40:23 +000044 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020045 mbedtls_des_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000046
Paul Bakkere896fea2009-07-06 06:40:23 +000047 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020048 mbedtls_des_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000049
Paul Bakkere896fea2009-07-06 06:40:23 +000050
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020051 mbedtls_des_setkey_dec( &ctx, key_str );
52 TEST_ASSERT( mbedtls_des_crypt_ecb( &ctx, src_str, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +000053
Azim Khanf1aaec92017-05-30 14:23:15 +010054 TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +020055
Paul Bakkerbd51b262014-07-10 15:26:12 +020056exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020057 mbedtls_des_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000058}
Paul Bakker33b43f12013-08-20 11:48:36 +020059/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000060
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020061/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khanf1aaec92017-05-30 14:23:15 +010062void des_encrypt_cbc( uint8_t * key_str, uint32_t key_str_len,
63 uint8_t * iv_str, uint32_t iv_str_len,
64 uint8_t * src_str, uint32_t src_len,
65 uint8_t * hex_dst_string, uint32_t hex_dst_string_len,
66 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +000067{
Paul Bakkere896fea2009-07-06 06:40:23 +000068 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020069 mbedtls_des_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000070
Paul Bakkere896fea2009-07-06 06:40:23 +000071 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020072 mbedtls_des_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000073
Paul Bakkere896fea2009-07-06 06:40:23 +000074
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020075 mbedtls_des_setkey_enc( &ctx, key_str );
76 TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result );
Paul Bakker33b43f12013-08-20 11:48:36 +020077 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +000078 {
Paul Bakkere896fea2009-07-06 06:40:23 +000079
Azim Khanf1aaec92017-05-30 14:23:15 +010080 TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +000081 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +020082
Paul Bakkerbd51b262014-07-10 15:26:12 +020083exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020084 mbedtls_des_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +000085}
Paul Bakker33b43f12013-08-20 11:48:36 +020086/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +000087
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020088/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khanf1aaec92017-05-30 14:23:15 +010089void des_decrypt_cbc( uint8_t * key_str, uint32_t key_str_len,
90 uint8_t * iv_str, uint32_t iv_str_len,
91 uint8_t * src_str, uint32_t src_len,
92 uint8_t * hex_dst_string, uint32_t hex_dst_string_len,
93 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +000094{
Paul Bakkere896fea2009-07-06 06:40:23 +000095 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020096 mbedtls_des_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +000097
Paul Bakkere896fea2009-07-06 06:40:23 +000098 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020099 mbedtls_des_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000100
Paul Bakkere896fea2009-07-06 06:40:23 +0000101
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200102 mbedtls_des_setkey_dec( &ctx, key_str );
103 TEST_ASSERT( mbedtls_des_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result );
Paul Bakker33b43f12013-08-20 11:48:36 +0200104 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000105 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000106
Azim Khanf1aaec92017-05-30 14:23:15 +0100107 TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000108 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200109
Paul Bakkerbd51b262014-07-10 15:26:12 +0200110exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200111 mbedtls_des_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000112}
Paul Bakker33b43f12013-08-20 11:48:36 +0200113/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000114
Paul Bakker33b43f12013-08-20 11:48:36 +0200115/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +0100116void des3_encrypt_ecb( int key_count, uint8_t * key_str, uint32_t key_str_len,
117 uint8_t * src_str, uint32_t src_str_len,
118 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Paul Bakkere896fea2009-07-06 06:40:23 +0000119{
Paul Bakkere896fea2009-07-06 06:40:23 +0000120 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200121 mbedtls_des3_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000122
Paul Bakkere896fea2009-07-06 06:40:23 +0000123 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200124 mbedtls_des3_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000125
Paul Bakkere896fea2009-07-06 06:40:23 +0000126
Paul Bakker33b43f12013-08-20 11:48:36 +0200127 if( key_count == 2 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200128 mbedtls_des3_set2key_enc( &ctx, key_str );
Paul Bakker33b43f12013-08-20 11:48:36 +0200129 else if( key_count == 3 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200130 mbedtls_des3_set3key_enc( &ctx, key_str );
Paul Bakkere896fea2009-07-06 06:40:23 +0000131 else
132 TEST_ASSERT( 0 );
133
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200134 TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000135
Azim Khanf1aaec92017-05-30 14:23:15 +0100136 TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200137
Paul Bakkerbd51b262014-07-10 15:26:12 +0200138exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200139 mbedtls_des3_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000140}
Paul Bakker33b43f12013-08-20 11:48:36 +0200141/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000142
Paul Bakker33b43f12013-08-20 11:48:36 +0200143/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +0100144void des3_decrypt_ecb( int key_count, uint8_t * key_str, uint32_t key_str_len,
145 uint8_t * src_str, uint32_t src_str_len,
146 uint8_t * hex_dst_string, uint32_t hex_dst_string_len )
Paul Bakkere896fea2009-07-06 06:40:23 +0000147{
Paul Bakkere896fea2009-07-06 06:40:23 +0000148 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200149 mbedtls_des3_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000150
Paul Bakkere896fea2009-07-06 06:40:23 +0000151 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200152 mbedtls_des3_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000153
Paul Bakkere896fea2009-07-06 06:40:23 +0000154
Paul Bakker33b43f12013-08-20 11:48:36 +0200155 if( key_count == 2 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200156 mbedtls_des3_set2key_dec( &ctx, key_str );
Paul Bakker33b43f12013-08-20 11:48:36 +0200157 else if( key_count == 3 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200158 mbedtls_des3_set3key_dec( &ctx, key_str );
Paul Bakkere896fea2009-07-06 06:40:23 +0000159 else
160 TEST_ASSERT( 0 );
161
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200162 TEST_ASSERT( mbedtls_des3_crypt_ecb( &ctx, src_str, output ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000163
Azim Khanf1aaec92017-05-30 14:23:15 +0100164 TEST_ASSERT( hexcmp( output, hex_dst_string, 8, hex_dst_string_len ) == 0 );
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200165
Paul Bakkerbd51b262014-07-10 15:26:12 +0200166exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200167 mbedtls_des3_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000168}
Paul Bakker33b43f12013-08-20 11:48:36 +0200169/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000170
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200171/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khanf1aaec92017-05-30 14:23:15 +0100172void des3_encrypt_cbc( int key_count, uint8_t * key_str, uint32_t key_str_len,
173 uint8_t * iv_str, uint32_t iv_str_len,
174 uint8_t * src_str, uint32_t src_len,
175 uint8_t * hex_dst_string, uint32_t hex_dst_string_len,
176 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000177{
Paul Bakkere896fea2009-07-06 06:40:23 +0000178 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200179 mbedtls_des3_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000180
Paul Bakkere896fea2009-07-06 06:40:23 +0000181 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200182 mbedtls_des3_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000183
Paul Bakkere896fea2009-07-06 06:40:23 +0000184
Paul Bakker33b43f12013-08-20 11:48:36 +0200185 if( key_count == 2 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200186 mbedtls_des3_set2key_enc( &ctx, key_str );
Paul Bakker33b43f12013-08-20 11:48:36 +0200187 else if( key_count == 3 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200188 mbedtls_des3_set3key_enc( &ctx, key_str );
Paul Bakkere896fea2009-07-06 06:40:23 +0000189 else
190 TEST_ASSERT( 0 );
191
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200192 TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_ENCRYPT, src_len, iv_str, src_str, output ) == cbc_result );
Paul Bakker02722ea2011-05-25 11:34:44 +0000193
Paul Bakker33b43f12013-08-20 11:48:36 +0200194 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000195 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000196
Azim Khanf1aaec92017-05-30 14:23:15 +0100197 TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000198 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200199
Paul Bakkerbd51b262014-07-10 15:26:12 +0200200exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200201 mbedtls_des3_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000202}
Paul Bakker33b43f12013-08-20 11:48:36 +0200203/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000204
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200205/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CBC */
Azim Khanf1aaec92017-05-30 14:23:15 +0100206void des3_decrypt_cbc( int key_count, uint8_t * key_str, uint32_t key_str_len,
207 uint8_t * iv_str, uint32_t iv_str_len,
208 uint8_t * src_str, uint32_t src_len,
209 uint8_t * hex_dst_string, uint32_t hex_dst_string_len,
210 int cbc_result )
Paul Bakkere896fea2009-07-06 06:40:23 +0000211{
Paul Bakkere896fea2009-07-06 06:40:23 +0000212 unsigned char output[100];
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200213 mbedtls_des3_context ctx;
Paul Bakkere896fea2009-07-06 06:40:23 +0000214
Paul Bakkere896fea2009-07-06 06:40:23 +0000215 memset(output, 0x00, 100);
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200216 mbedtls_des3_init( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000217
Paul Bakkere896fea2009-07-06 06:40:23 +0000218
Paul Bakker33b43f12013-08-20 11:48:36 +0200219 if( key_count == 2 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200220 mbedtls_des3_set2key_dec( &ctx, key_str );
Paul Bakker33b43f12013-08-20 11:48:36 +0200221 else if( key_count == 3 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200222 mbedtls_des3_set3key_dec( &ctx, key_str );
Paul Bakkere896fea2009-07-06 06:40:23 +0000223 else
224 TEST_ASSERT( 0 );
225
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200226 TEST_ASSERT( mbedtls_des3_crypt_cbc( &ctx, MBEDTLS_DES_DECRYPT, src_len, iv_str, src_str, output ) == cbc_result );
Paul Bakker02722ea2011-05-25 11:34:44 +0000227
Paul Bakker33b43f12013-08-20 11:48:36 +0200228 if( cbc_result == 0 )
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000229 {
Paul Bakkere896fea2009-07-06 06:40:23 +0000230
Azim Khanf1aaec92017-05-30 14:23:15 +0100231 TEST_ASSERT( hexcmp( output, hex_dst_string, src_len, hex_dst_string_len ) == 0 );
Paul Bakkerf3ccc682010-03-18 21:21:02 +0000232 }
Paul Bakker8cfd9d82014-06-18 11:16:11 +0200233
Paul Bakkerbd51b262014-07-10 15:26:12 +0200234exit:
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200235 mbedtls_des3_free( &ctx );
Paul Bakkere896fea2009-07-06 06:40:23 +0000236}
Paul Bakker33b43f12013-08-20 11:48:36 +0200237/* END_CASE */
Paul Bakkere896fea2009-07-06 06:40:23 +0000238
Paul Bakker33b43f12013-08-20 11:48:36 +0200239/* BEGIN_CASE */
Azim Khanf1aaec92017-05-30 14:23:15 +0100240void des_key_parity_run( )
Paul Bakker1f87fb62011-01-15 17:32:24 +0000241{
242 int i, j, cnt;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200243 unsigned char key[MBEDTLS_DES_KEY_SIZE];
Paul Bakker1f87fb62011-01-15 17:32:24 +0000244 unsigned int parity;
245
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200246 memset( key, 0, MBEDTLS_DES_KEY_SIZE );
Paul Bakker1f87fb62011-01-15 17:32:24 +0000247 cnt = 0;
248
249 // Iterate through all possible byte values
250 //
251 for( i = 0; i < 32; i++ )
252 {
253 for( j = 0; j < 8; j++ )
254 key[j] = cnt++;
255
256 // Set the key parity according to the table
257 //
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200258 mbedtls_des_key_set_parity( key );
Paul Bakker1f87fb62011-01-15 17:32:24 +0000259
260 // Check the parity with a function
261 //
262 for( j = 0; j < 8; j++ )
263 {
264 parity = key[j] ^ ( key[j] >> 4 );
265 parity = parity ^
266 ( parity >> 1 ) ^
267 ( parity >> 2 ) ^
268 ( parity >> 3 );
269 parity &= 1;
270
271 if( parity != 1 )
272 TEST_ASSERT( 0 );
273 }
274
275 // Check the parity with the table
276 //
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200277 TEST_ASSERT( mbedtls_des_key_check_key_parity( key ) == 0 );
Paul Bakker1f87fb62011-01-15 17:32:24 +0000278 }
279}
Paul Bakker33b43f12013-08-20 11:48:36 +0200280/* END_CASE */
Paul Bakker1f87fb62011-01-15 17:32:24 +0000281
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200282/* BEGIN_CASE depends_on:MBEDTLS_SELF_TEST */
Azim Khanf1aaec92017-05-30 14:23:15 +0100283void des_selftest( )
Paul Bakkere896fea2009-07-06 06:40:23 +0000284{
Andres AG93012e82016-09-09 09:10:28 +0100285 TEST_ASSERT( mbedtls_des_self_test( 1 ) == 0 );
Paul Bakkere896fea2009-07-06 06:40:23 +0000286}
Paul Bakker33b43f12013-08-20 11:48:36 +0200287/* END_CASE */