mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-08 17:42:09 +03:00
- Support for DES weak keys and parity bits added
This commit is contained in:
@@ -254,6 +254,49 @@ des3_decrypt_cbc:key_count:hex_key_string:hex_iv_string:hex_src_string:hex_dst_s
|
||||
}
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
des_key_parity_run:
|
||||
{
|
||||
int i, j, cnt;
|
||||
unsigned char key[DES_KEY_SIZE];
|
||||
unsigned int parity;
|
||||
|
||||
memset( key, 0, DES_KEY_SIZE );
|
||||
cnt = 0;
|
||||
|
||||
// Iterate through all possible byte values
|
||||
//
|
||||
for( i = 0; i < 32; i++ )
|
||||
{
|
||||
for( j = 0; j < 8; j++ )
|
||||
key[j] = cnt++;
|
||||
|
||||
// Set the key parity according to the table
|
||||
//
|
||||
des_key_set_parity( key );
|
||||
|
||||
// Check the parity with a function
|
||||
//
|
||||
for( j = 0; j < 8; j++ )
|
||||
{
|
||||
parity = key[j] ^ ( key[j] >> 4 );
|
||||
parity = parity ^
|
||||
( parity >> 1 ) ^
|
||||
( parity >> 2 ) ^
|
||||
( parity >> 3 );
|
||||
parity &= 1;
|
||||
|
||||
if( parity != 1 )
|
||||
TEST_ASSERT( 0 );
|
||||
}
|
||||
|
||||
// Check the parity with the table
|
||||
//
|
||||
TEST_ASSERT( des_key_check_key_parity( key ) == 0 );
|
||||
}
|
||||
}
|
||||
END_CASE
|
||||
|
||||
BEGIN_CASE
|
||||
des_selftest:
|
||||
{
|
||||
|
Reference in New Issue
Block a user