des.c
/*
 * Check whether the 8 byte key is weak.
 * Dose not check the parity bits of the key but simple ignore them.
 */
Check whether the 8 byte key is weak.
Dose not check the parity bits of the key but simple ignore them.
Check whether the 8 byte key is weak . Dose not check the parity bits of the key but simple ignore them .
int
is_weak_key ( const unsigned char *key )
{
  unsigned char work[8];
  int i, left, right, middle, cmp_result;
  for(i=0; i<8; ++i)
     work[i] = key[i] & 0xfe;
  left = 0;
  right = 63;
  while(left <= right)
    {
      middle = (left + right) / 2;
      if ( !(cmp_result=memcmp(work, weak_keys[middle], 8)) )
	  return -1;
      if ( cmp_result > 0 )
	  left = middle + 1;
      else
	  right = middle - 1;
    }
  return 0;
}
int is_weak_key ( const unsigned char * key ) { unsigned char work [ 8 ] ; int i , left , right , middle , cmp_result ; for ( i = 0 ; i < 8 ; ++ i ) work [ i ] = key [ i ] & 0xfe ; left = 0 ; right = 63 ; while ( left <= right ) { middle = ( left + right ) / 2 ; if ( ! ( cmp_result = memcmp ( work , weak_keys [ middle ] , 8 ) ) ) return -1 ; if ( cmp_result > 0 ) left = middle + 1 ; else right = middle - 1 ; } return 0 ; }
Check whether the 8 byte key is weak.
Check whether the 8 byte key is weak .
/* clear parity bits */ /* binary search in the weak key table */