Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Cryptix V3.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## cryptix.provider.elgamal
Class BaseElGamalKeyPairGenerator

    java.lang.Object
      |
      +--java.security.KeyPairGeneratorSpi
            |
            +--java.security.KeyPairGenerator
                  |
                  +--cryptix.provider.elgamal.BaseElGamalKeyPairGenerator

public class BaseElGamalKeyPairGenerator
extends java.security.KeyPairGenerator
implements ElGamalKeyPairGenerator

A class capable of generating ElGamal key pairs. The generator is first initialized, then used to generate one or more key pairs.

Users wishing to indicate the prime or base, and to generate a key pair suitable for use with the ElGamal signature or encryption algorithms typically

1. Get a key pair generator for the ElGamal algorithms by calling the KeyPairGenerator `getInstance` method with "ElGamal" as its argument.

2. Initialize the generator by casting the result to an ElGamalKeyPairGenerator and calling one of the `initialize` methods.

3. Generate one or more key pairs by calling the `generateKeyPair` method, as often as desired.

The algorithm used to generate ElGamal keys is as follows:

1. Generate a random probable-prime, p, of the desired length (using java.math.BigInteger.generatePrime).
2. Find the small prime factors of p-1 by trial division.
3. Divide p-1 by all its small prime factors, and check that the result is probably-prime.
4. Pick a random g, with one less bit than p.
5. Repeat step 3 until g is a generator mod p (using the test given in Schneier section 11.3, and noting that we know the factors of p-1 from steps 2 and 3).
6. Pick a random x, also with one less bit than p.
7. Calculate y = g^x mod p.

If p and g are specified in advance then only the last two steps are needed.

References:

1. Bruce Schneier, "Section 19.6 ElGamal," and "Section 11.3 Number Theory" (heading "Generators," pages 253-254), Applied Cryptography, 2nd edition, John Wiley & Sons, 1996

2. S.C. Pohlig and M.E. Hellman, "An Improved Algorithm for Computing Logarithms in GF(p) and Its Cryptographic Significance," IEEE Transactions on Information Theory, v. 24 n. 1, Jan 1978, pages 106-111.

3. IEEE P1363 draft standard, http://stdsbbs.ieee.org/groups/1363/index.html

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

$Revision: 1.6 $

Since:
  Cryptix 2.2.2
Author:
  David Hopwood
See Also:
  `KeyPairGenerator`

Field Summary
`protected java.math.BigInteger` | `g`
`protected java.math.BigInteger` | `p`
`protected java.security.SecureRandom` | `source`

Constructor Summary
`BaseElGamalKeyPairGenerator()`

Method Summary
`java.security.KeyPair` | `generateKeyPair()` Generates a key pair.
`ElGamalParams` | `generateParams(int primeLen, java.security.SecureRandom random)` Generates new parameters, p and g.
`void` | `initialize(java.math.BigInteger prime, java.math.BigInteger base, java.security.SecureRandom random)` Initialises the key pair generator using the specified prime (p) and base (g).
`void` | `initialize(ElGamalParams params, java.security.SecureRandom random)` Initialises the key pair generator using the prime and base from the specified ElGamalParams object.
`void` | `initialize(int primeLen, boolean genParams, java.security.SecureRandom random)` Initialises the key pair generator for a given prime length, without parameters.
`void` | `initialize(int primeLen, java.security.SecureRandom random)` Initialises the key pair generator for a given prime length, without parameters.

Methods inherited from class java.security.KeyPairGenerator
`genKeyPair, getAlgorithm, getInstance, getInstance, getProvider, initialize, initialize, initialize`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### p

    protected java.math.BigInteger p

### g

    protected java.math.BigInteger g

### source

    protected java.security.SecureRandom source

Constructor Detail

### BaseElGamalKeyPairGenerator

    public BaseElGamalKeyPairGenerator()

Method Detail

### initialize

    public void initialize(ElGamalParams params,
                           java.security.SecureRandom random)
                    throws java.security.InvalidParameterException

  Initialises the key pair generator using the prime and base from the specified ElGamalParams object.
  Specified by:
    initialize in interface ElGamalKeyPairGenerator
  Parameters:
    `params` - the parameters to use to generate the keys.
    `random` - the random bit source to use to generate key bits.
  Throws:
    NullPointerException - if params == null || random == null
    java.security.InvalidParameterException - if the parameters passed are invalid.

### initialize

    public void initialize(java.math.BigInteger prime,
                           java.math.BigInteger base,
                           java.security.SecureRandom random)
                    throws java.security.InvalidParameterException

  Initialises the key pair generator using the specified prime (p) and base (g). The difficulty of cracking ElGamal by solving the discrete logarithm problem is dependent on the length of the prime.

  An InvalidParameterException will be thrown if `base >= prime`.

  Specified by:
    initialize in interface ElGamalKeyPairGenerator
  Parameters:
    `prime` - the prime to be used, as a java.math.BigInteger
    `base` - the base to be used, as a java.math.BigInteger
    `random` - the random bit source to use to generate key bits.
  Throws:
    NullPointerException - if prime == null || base == null || random == null
    java.security.InvalidParameterException - if the parameters passed are invalid.

### initialize

    public void initialize(int primeLen,
                           java.security.SecureRandom random)

  Initialises the key pair generator for a given prime length, without parameters.
  Overrides:
    initialize in class java.security.KeyPairGenerator
  Parameters:
    `primeLen` - the prime length, in bits. Valid lengths are any integer >= 256.
    `random` - the random bit source to use to generate key bits.
  Throws:
    java.security.InvalidParameterException - if the prime length is less than 256.

### initialize

    public void initialize(int primeLen,
                           boolean genParams,
                           java.security.SecureRandom random)
                    throws java.security.InvalidParameterException

  Initialises the key pair generator for a given prime length, without parameters.

  If genParams is true, this method will generate new p and g parameters. If it is false, the method will use precomputed parameters for the prime length requested. If there are no precomputed parameters for that prime length, an exception will be thrown. It is guaranteed that there will always be default parameters for a prime length of 512 bits.

  [Future versions will probably also support 1024, 1536, 2048, 3072, and 4096 bits.]

  Specified by:
    initialize in interface ElGamalKeyPairGenerator
  Parameters:
    `primeLen` - the prime length, in bits. Valid lengths are any integer >= 256.
    `random` - the random bit source to use to generate key bits.
    `genParams` - whether to generate new parameters for the prime length requested.
  Throws:
    java.security.InvalidParameterException - if the prime length is less than 256, or if genParams is false and there are not precomputed parameters for the prime length requested.

### generateKeyPair

    public java.security.KeyPair generateKeyPair()

  Generates a key pair.
  Overrides:
    generateKeyPair in class java.security.KeyPairGeneratorSpi

### generateParams

    public ElGamalParams generateParams(int primeLen,
                                        java.security.SecureRandom random)
                                 throws java.security.InvalidParameterException

  Generates new parameters, p and g. This method does not change the parameters currently being used by `generateKeyPair`.
  Specified by:
    generateParams in interface ElGamalKeyPairGenerator
  Parameters:
    `primeLen` - the prime length, in bits. Valid lengths are any integer >= 256.
    `random` - the random bit source to use to generate the parameters.
  Throws:
    java.security.InvalidParameterException - if the prime length is less than 256.

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
| Cryptix V3.2
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

Copyright (C) 1995-2000 The Cryptix Foundation Ltd. All rights reserved.