cryptix.provider.key

Class DESKeyGenerator

Implemented Interfaces:
Cloneable, ExtendedKeyGenerator, Parameterized
Known Direct Subclasses:
DES2XKeyGenerator, DESXKeyGenerator, DES_EDE3KeyGenerator

public class DESKeyGenerator
extends RawKeyGenerator

A key generator for (single) DES.

DES keys have a fixed length of 8 bytes, with a parity bit as the LSB of each byte (i.e. there are 2^56 possible keys).

Copyright © 1997 Systemics Ltd on behalf of the Cryptix Development Team.
All rights reserved.

$Revision: 1.2 $

Authors:
David Hopwood
Raif Naffah
Since:
Cryptix 2.2.0a, 2.2.2

Constructor Summary

DESKeyGenerator()
DESKeyGenerator(String algorithm, int seedlength)
Constructor for use by subclasses that need to specify a different seed length (e.g.

Method Summary

protected byte[]
engineGenerateKey(byte[] seed)
protected boolean
isWeak(byte[] key)
Returns true iff the first 8 bytes of key represent a weak or semi-weak single DES key.
protected boolean
isWeak(byte[] key, int offset)
Returns true iff the bytes at key[offset..offset+7] represent a weak or semi-weak single DES key.
protected void
setParity(byte[] array)
Sets parity bits for the given input array.

Methods inherited from class cryptix.provider.key.RawKeyGenerator

engineGenerateKey, generateKey, generateKey, getDefaultKeyLength, getMaximumKeyLength, getMinimumKeyLength, initialize, initialize, isValidKeyLength, isWeak, isWeakAllowed, setWeakAllowed

Methods inherited from class xjava.security.KeyGenerator

clone, engineGetParameter, engineSetParameter, generateKey, getAlgorithm, getAlgorithms, getAlgorithms, getInstance, getInstance, getParameter, initialize, setParameter, toString

Constructor Details

DESKeyGenerator

public DESKeyGenerator()

DESKeyGenerator

protected DESKeyGenerator(String algorithm,
                          int seedlength)
Constructor for use by subclasses that need to specify a different seed length (e.g. for Triple DES).

Method Details

engineGenerateKey

protected byte[] engineGenerateKey(byte[] seed)
            throws WeakKeyException,
                   InvalidKeyException
Overrides:
engineGenerateKey in interface RawKeyGenerator

isWeak

protected boolean isWeak(byte[] key)
Returns true iff the first 8 bytes of key represent a weak or semi-weak single DES key.
Overrides:
isWeak in interface RawKeyGenerator

isWeak

protected boolean isWeak(byte[] key,
                         int offset)
Returns true iff the bytes at key[offset..offset+7] represent a weak or semi-weak single DES key. It can be called either before or after setting parity bits.

(This checks for the 16 weak and semi-weak keys as given by Schneier, Applied Cryptography 2nd ed., tables 12.11 and 12.12. It does not check for the possibly-weak keys in table 12.13.)


setParity

protected void setParity(byte[] array)
Sets parity bits for the given input array. The least significant bit of each byte is changed to ensure that the byte has odd parity.