iaik.security.cipher
Class DESKeyGenerator

java.lang.Object
  |
  +--javax.crypto.KeyGeneratorSpi
        |
        +--iaik.security.cipher.VarLengthKeyGenerator
              |
              +--iaik.security.cipher.DESKeyGenerator

public class DESKeyGenerator
extends iaik.security.cipher.VarLengthKeyGenerator

This class provides the functionality of a DES key generator. A key generator is used for creating secret keys for symmetric algorithms.

An application uses

KeyGenerator des_key_gen =
 KeyGenerator.getInstance("DES");
for creating a KeyGenerator object for the DES algorithm. For actually generating the requested secret DES key from the KeyGenerator object just created, an application calls the generateKey method after having initialized the generator with some random seed or relied on the default system-provided source of randomness:

 SecretKey des_key = des_key_gen.generateKey();
 

Due to the way, the DES algorithm generates sub-keys for the several DES rounds, some initial keys may be classified as weak or semi-weak keys reducing the security of the DES cipher (see "Applied Cryptography", Bruce Schneier, ISBN 0-471-59756-2). This KeyGenerator class ensures to generate a strong DES key by repeating the key generation process as long as comparison with all the known weak and semi-weak DES keys will show that the just created key is not a strong one.

Version:
File Revision 16
See Also:
KeyGenerator, KeyGeneratorSpi, SecretKey, SecretKey, DES

Constructor Summary
DESKeyGenerator()
           
 
Method Summary
static void adjustParity(byte[] key, int offset)
          Adjusts the parity-bits of a DES key, supplied in a byte array beginning at the given offset.
static boolean checkParity(byte[] key, int offset, boolean odd)
          Checks if the given DES key, supplied in a byte array beginning at the given offset, is parity adjusted.
protected  SecretKey engineGenerateKey()
          Generates a DES key.
protected  void engineInit(AlgorithmParameterSpec params, SecureRandom random)
          Initializes this key generator.
protected  void engineInit(int strength, SecureRandom random)
          Initializes this key generator for the given strength with the given random seed.
protected  void engineInit(SecureRandom random)
          Initializes this key generator with the given random seed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DESKeyGenerator

public DESKeyGenerator()
Method Detail

engineGenerateKey

protected SecretKey engineGenerateKey()
Generates a DES key.

For ensuring to create a strong DES key, the key generation process is repeated as long as comparison with all the known weak and semi-weak DES keys will show that the just created key is not a strong DES key.

Overrides:
engineGenerateKey in class iaik.security.cipher.VarLengthKeyGenerator
Returns:
the new created parity adjusted DES key
See Also:
SecretKey

adjustParity

public static void adjustParity(byte[] key,
                                int offset)
Adjusts the parity-bits of a DES key, supplied in a byte array beginning at the given offset.
Parameters:
key - the byte array holding the DES key
offset - the offset indicating where the key starts within the given byte array

checkParity

public static boolean checkParity(byte[] key,
                                  int offset,
                                  boolean odd)
Checks if the given DES key, supplied in a byte array beginning at the given offset, is parity adjusted.
Parameters:
key - the byte array holding the DES key
offset - the offset indicating where the key starts within the given byte array
odd - whether to check for odd or even parity
Returns:
true if checking for odd parity and the key is odd parity adjusted; true if checking for even parity and the key is even parity adjusted; false in any other case (note that if this method returns false when checking for odd (even) parity, this does not nessesarily mean that the key is even (odd) parity adjusted

engineInit

protected void engineInit(AlgorithmParameterSpec params,
                          SecureRandom random)
                   throws InvalidAlgorithmParameterException
Initializes this key generator. If params is not null, otherwise this call is identical to engineInit(random).
Overrides:
engineInit in class KeyGeneratorSpi
Throws:
InvalidAlgorithmParameterException - if parameters are passed

engineInit

protected void engineInit(int strength,
                          SecureRandom random)
Initializes this key generator for the given strength with the given random seed. Lengths outside the range of minimum to maximum length default to the default length.
Overrides:
engineInit in class KeyGeneratorSpi
Parameters:
strength - the strength of the key to be created
random - the random seed

engineInit

protected void engineInit(SecureRandom random)
Initializes this key generator with the given random seed. The strength defaults to the default length.
Overrides:
engineInit in class KeyGeneratorSpi
Parameters:
random - the random seed for this generator

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK