Cryptography Reference
In-Depth Information
ror( pc1key );
if ( !( round >= 14 || round == 7 || round == 0 ) )
{
// Rotate twice except in rounds 1, 2, 9 & 16
ror( pc1key );
}
}
xor( expansion_block, subkey, 6 );
...
}
That's it. The substitution boxes and all the permutations are identical; the
only difference is the rotation of the key. The ror function, in Listing 2-15, is
the inverse of the rol function.
Listing 2-15: “des.c” rotate right
static void ror(unsigned char *target )
{
int carry_left, carry_right;
carry_right = ( target[ 6 ] & 0x01 ) << 3;
target[ 6 ] = ( target[ 6 ] >> 1 ) | ( ( target[ 5 ] & 0x01 ) << 7 );
target[ 5 ] = ( target[ 5 ] >> 1 ) | ( ( target[ 4 ] & 0x01 ) << 7 );
target[ 4 ] = ( target[ 4 ] >> 1 ) | ( ( target[ 3 ] & 0x01 ) << 7 );
carry_left = ( target[ 3 ] & 0x10 ) << 3;
target[ 3 ] = ( ( ( target[ 3 ] >> 1 ) |
( ( target[ 2 ] & 0x01 ) << 7 ) ) & ~0x08 ) | carry_right;
target[ 2 ] = ( target[ 2 ] >> 1 ) | ( ( target[ 1 ] & 0x01 ) << 7 );
target[ 1 ] = ( target[ 1 ] >> 1 ) | ( ( target[ 0 ] & 0x01 ) << 7 );
target[ 0 ] = ( target[ 0 ] >> 1 ) | carry_left;
}
Padding and Chaining in Block Cipher Algorithms
As shown earlier, DES operates on eight-byte input blocks. If the input is longer
than eight bytes, the des_block_operate function must be called repeatedly. If the
input isn't aligned on an eight-byte boundary, it has to be padded. Of course,
the padding must follow a specifi c scheme so that the decryption routine knows
what to discard after decryption. If you adopt a convention of padding with 0
bytes, the decryptor needs to have some way of determining whether the input
actually ended with 0 bytes or whether these were padding bytes. National
Institute for Standards and Technology (NIST) publication 800-38A ( http://csrc
.nist.gov/publications/nistpubs/800-38a/sp800-38a.pdf ) recommends that
a “1” bit be added to the input followed by enough zero-bits to make up eight
 
Search WWH ::




Custom Search