FileDocCategorySizeDatePackage
DESParameters.javaAPI DocAzureus 3.0.3.43940Tue Jun 08 05:13:00 BST 2004org.bouncycastle.crypto.params

DESParameters

public class DESParameters extends KeyParameter

Fields Summary
public static final int
DES_KEY_LENGTH
private static final int
N_DES_WEAK_KEYS
private static byte[]
DES_weak_keys
Constructors Summary
public DESParameters(byte[] key)

        super(key);

        if (isWeakKey(key, 0))
        {
            throw new IllegalArgumentException("attempt to create weak DES key");
        }
    
Methods Summary
public static booleanisWeakKey(byte[] key, int offset)
DES has 16 weak keys. This method will check if the given DES key material is weak or semi-weak. Key material that is too short is regarded as weak.

See "Applied Cryptography" by Bruce Schneier for more information.

return
true if the given DES key material is weak or semi-weak, false otherwise.


                                                                    
       
         
         
    
        if (key.length - offset < DES_KEY_LENGTH)
        {
            throw new IllegalArgumentException("key material too short.");
        }

        nextkey: for (int i = 0; i < N_DES_WEAK_KEYS; i++)
        {
            for (int j = 0; j < DES_KEY_LENGTH; j++)
            {
                if (key[j + offset] != DES_weak_keys[i * DES_KEY_LENGTH + j])
                {
                    continue nextkey;
                }
            }

            return true;
        }
        return false;
    
public static voidsetOddParity(byte[] bytes)
DES Keys use the LSB as the odd parity bit. This can be used to check for corrupt keys.

param
bytes the byte array to set the parity on.

        for (int i = 0; i < bytes.length; i++)
        {
            int b = bytes[i];
            bytes[i] = (byte)((b & 0xfe) |
                            ((((b >> 1) ^
                            (b >> 2) ^
                            (b >> 3) ^
                            (b >> 4) ^
                            (b >> 5) ^
                            (b >> 6) ^
                            (b >> 7)) ^ 0x01) & 0x01));
        }