IAIK ECC
version 2.18

iaik.security.ecc.math.field
Class PrimeFieldFactory

java.lang.Object
  extended byiaik.security.ecc.math.field.PrimeFieldFactory
All Implemented Interfaces:
FieldFactory

public abstract class PrimeFieldFactory
extends java.lang.Object
implements FieldFactory

Abstract base class for all prime field factories. Subclasses provide factory methods to obtain concrete field implementations for specific prime moduli.

Use the static getInstance method to obtain an instance of the prime field factory. The used factory for a specific prime modulus can be set by the setDefaultFactory method. There will be one instance of a prime field factory for each modulus.

 BigInteger p192 = ECCParameters.PRIME_P[0];
 BigInteger prime = BigInteger.probablePrime(192, new Random());
 
 // set the default factory to be used for every modulus without
 // a specific implementation:
 Class cDefault = PrimeFieldFactory.class.getClassLoader().loadClass(
     "iaik.security.ecc.math.field.FastPrimeFieldFactory");
 PrimeFieldFactory.setDefaultFactory(cDefault, null);
 
 // set the factory used for the P-192 prime modulus
 Class cP192 = PrimeFieldFactory.class.getClassLoader().loadClass(
     "iaik.security.ecc.math.field.P192FieldFactory");
 PrimeFieldFactory.setDefaultFactory(cP192, p192);
 
 PrimeFieldFactory p192Factory = PrimeFieldFactory.getInstance(p192);
 PrimeField p192Field = p192Factory.getField();
 
 PrimeFieldFactory primeFactory = PrimeFieldFactory.getInstance(prime);
 PrimeField primeField = primeFactory.getField();
 
A default factory with field implementations for the NIST primes P-192, P-224, P-256, P-384 and P-521, and a fast default implementation for all other moduli is set by the static constructor.


Field Summary
protected  java.math.BigInteger modulus_
          This is the modulus for which this prime field factory creates prime fields.
protected static java.math.BigInteger p192_
          Define the modulus for the P-192 curve.
protected static java.math.BigInteger p224_
          Define the modulus for the P-224 curve.
protected static java.math.BigInteger p256_
          Define the modulus for the P-256 curve.
protected static java.math.BigInteger p384_
          Define the modulus for the P-384 curve.
protected static java.math.BigInteger p521_
          Define the modulus for the P-521 curve.
 
Constructor Summary
PrimeFieldFactory()
           
 
Method Summary
abstract  Field getField()
          Creates a new (factory specific) implementation of a prime field.
static FieldFactory getInstance(java.math.BigInteger modulus)
          Use this method to get a concrete instance of a PrimeFieldFactory for a specific modulus.
static void setDefaultFactory(java.lang.Class c, java.math.BigInteger modulus)
          Set the prime field factory to be used for a specific modulus.
protected  void setModulus(java.math.BigInteger modulus)
          This method is used to set the modulus after creating an instance of a PrimeFieldFactory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

p192_

protected static final java.math.BigInteger p192_
Define the modulus for the P-192 curve.


p224_

protected static final java.math.BigInteger p224_
Define the modulus for the P-224 curve.


p256_

protected static final java.math.BigInteger p256_
Define the modulus for the P-256 curve.


p384_

protected static final java.math.BigInteger p384_
Define the modulus for the P-384 curve.


p521_

protected static final java.math.BigInteger p521_
Define the modulus for the P-521 curve.


modulus_

protected java.math.BigInteger modulus_
This is the modulus for which this prime field factory creates prime fields.

Constructor Detail

PrimeFieldFactory

public PrimeFieldFactory()
Method Detail

getInstance

public static FieldFactory getInstance(java.math.BigInteger modulus)
                                throws FieldException
Use this method to get a concrete instance of a PrimeFieldFactory for a specific modulus. If there is already a factory instance for this modulus in the HashMap it will be returned. Otherwise a new instance of the default factory is created and stored in the HashMap, together with its modulus for later use.

Returns:
an implementation of a PrimeFieldFactory defined only for one modulus.
Throws:
FieldException - if the irreducible polynomial is null or the factory cannot be found.

setDefaultFactory

public static void setDefaultFactory(java.lang.Class c,
                                     java.math.BigInteger modulus)
                              throws FieldException
Set the prime field factory to be used for a specific modulus. To get an implementation of the factory use the getInstance method. This method should only be used if one wants to use a custom implementation of the prime field arithmetic.

Parameters:
c - the class of the field factory that should be used for a specific modulus. If factory is null the factory defined for modulus is removed.
modulus - the modulus that is used by the factory. If modulus is null the default factory will be set by factory .
Throws:
FieldException

getField

public abstract Field getField()
Creates a new (factory specific) implementation of a prime field. Use the newElement method to create a FieldElement for this field.

Specified by:
getField in interface FieldFactory
See Also:
FieldElement

setModulus

protected void setModulus(java.math.BigInteger modulus)
This method is used to set the modulus after creating an instance of a PrimeFieldFactory.

Parameters:
modulus - the modulus that the factory should use.

IAIK ECC
version 2.18

IAIK-ECC 2.18, (c) 2002 IAIK, (c) 2003 SIC