mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-08-07 06:42:56 +03:00
- Support for DES weak keys and parity bits added
This commit is contained in:
@@ -232,5 +232,8 @@ des_encrypt_cbc:"0123456789abcdef":"fedcba9876543210":"37363534333231204E6F77206
|
||||
3DES-CBC 3Key Encrypt (Invalid input length)
|
||||
des3_encrypt_cbc:3:"0123456789abcdeff1e0d3c2b5a49786fedcba9876543210":"fedcba9876543210":"37363534333231204E6F77206973207468652074696D65":"":POLARSSL_ERR_DES_INVALID_INPUT_LENGTH
|
||||
|
||||
Run through parity bit tests
|
||||
des_key_parity_run:
|
||||
|
||||
DES Selftest
|
||||
des_selftest:
|
||||
|
@@ -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