IAIK ECC
version 2.18

iaik.security.ecc.ecdh
Class ECDH

java.lang.Object
  extended byjavax.crypto.KeyAgreementSpi
      extended byiaik.security.ecc.ecdh.ECDH
Direct Known Subclasses:
ECDHwithCofactor

public class ECDH
extends javax.crypto.KeyAgreementSpi

DLSVDP-DH is Discrete Logarithm Secret Value Derivation Primitive, Diffie-Hellman version, compliant with IEEE 1363 and DLSVDP-DHC is Discrete Logarithm Secret Value Derivation Primitive, Diffie-Hellman version with cofactor multiplication.

This implementation doesn't perform a parameter check. Both, the private and the public key have to use the same parameter set.


Field Summary
protected  ECDSAParams parameter_
          The used parameter set.
protected  ECDSAPrivateKey privateKey_
          The private key for this key agreement.
protected  byte[] secret_
          The generated shared secret.
protected  boolean withCoFactor_
          if true the algorithm uses cofactor multiplication.
 
Constructor Summary
  ECDH()
          Constructor used by provider.
protected ECDH(boolean withCoFactorMultiplication)
          Creates a new ECDH instance.
 
Method Summary
protected  java.security.Key engineDoPhase(java.security.Key publicKey, boolean lastPhase)
          Performs the shared secret calculation, which is the x coordinate of the point p = puplicKey * privateKey (*cofactor).
protected  byte[] engineGenerateSecret()
          The result of this key agreement scheme, which is the x coordinate of the new ec point.
protected  int engineGenerateSecret(byte[] sharedSecret, int offset)
          After the last phase, this method copies the result in the provided buffer.
protected  javax.crypto.SecretKey engineGenerateSecret(java.lang.String algorithm)
          Describe engineGenerateSecret method here.
protected  void engineInit(java.security.Key privateKey, java.security.spec.AlgorithmParameterSpec param, java.security.SecureRandom random)
          Initializes this key agreement with a private key and an parameter set.
protected  void engineInit(java.security.Key privateKey, java.security.SecureRandom secureRandom)
          Initializes this with a given private key.
protected  boolean equalParameters(ECDSAParams p1, ECDSAParams p2)
          Compares 2 domain parameter sets.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

parameter_

protected ECDSAParams parameter_
The used parameter set.


privateKey_

protected ECDSAPrivateKey privateKey_
The private key for this key agreement.


secret_

protected byte[] secret_
The generated shared secret.


withCoFactor_

protected boolean withCoFactor_
if true the algorithm uses cofactor multiplication.

Constructor Detail

ECDH

public ECDH()
Constructor used by provider. It simply calls this(flase). Don't try to get an instance of this class but use the provider.


ECDH

protected ECDH(boolean withCoFactorMultiplication)
Creates a new ECDH instance. Don't try to get an instance of this class but use the provider.

Parameters:
withCoFactorMultiplication - a boolean value, if true cofactor multiplication is used.
Method Detail

engineDoPhase

protected java.security.Key engineDoPhase(java.security.Key publicKey,
                                          boolean lastPhase)
                                   throws java.lang.IllegalStateException,
                                          java.security.InvalidKeyException
Performs the shared secret calculation, which is the x coordinate of the point p = puplicKey * privateKey (*cofactor).

Parameters:
publicKey - a Key value which is the peers public key and MUST use the same domain parameter as the used private key.
lastPhase - a boolean value indicates if this is the last phase in this scheme.
Returns:
a Key value, which is null if the lastPhase parameter is true.
Throws:
java.lang.IllegalStateException - if an error occurs
java.security.InvalidKeyException - if an error occurs

engineGenerateSecret

protected byte[] engineGenerateSecret()
                               throws java.lang.IllegalStateException
The result of this key agreement scheme, which is the x coordinate of the new ec point.

Returns:
a byte[] value which is the result of this key agreement.
Throws:
java.lang.IllegalStateException - never occurs.

engineGenerateSecret

protected int engineGenerateSecret(byte[] sharedSecret,
                                   int offset)
                            throws javax.crypto.ShortBufferException,
                                   java.lang.IllegalStateException
After the last phase, this method copies the result in the provided buffer.

Parameters:
sharedSecret - a byte[] value to hold the secret
offset - an int value specifies the buffer offset
Returns:
an int value, which is the length of the secret
Throws:
javax.crypto.ShortBufferException - if the provided buffer is too small
java.lang.IllegalStateException - never thrown.

engineGenerateSecret

protected javax.crypto.SecretKey engineGenerateSecret(java.lang.String algorithm)
                                               throws java.security.InvalidKeyException,
                                                      java.security.NoSuchAlgorithmException,
                                                      java.lang.IllegalStateException
Describe engineGenerateSecret method here.

Parameters:
algorithm - a String value value describing the secret key algorithm.
Returns:
a SecretKey value of the specified type.
Throws:
java.security.InvalidKeyException - if an error occurs
java.security.NoSuchAlgorithmException - if an error occurs
java.lang.IllegalStateException - if an error occurs

engineInit

protected void engineInit(java.security.Key privateKey,
                          java.security.spec.AlgorithmParameterSpec param,
                          java.security.SecureRandom random)
                   throws java.security.InvalidAlgorithmParameterException,
                          java.security.InvalidKeyException
Initializes this key agreement with a private key and an parameter set. ATTENTION the private key must be intended for this parameter set. This property will not be checked.

Throws:
java.security.InvalidAlgorithmParameterException
java.security.InvalidKeyException

engineInit

protected void engineInit(java.security.Key privateKey,
                          java.security.SecureRandom secureRandom)
                   throws java.security.InvalidKeyException
Initializes this with a given private key. The secure random parameter is ignored.

Parameters:
privateKey - a Key value, which must be a private ec key
secureRandom - a SecureRandom value
Throws:
java.security.InvalidKeyException - if the provided key is invalid.

equalParameters

protected boolean equalParameters(ECDSAParams p1,
                                  ECDSAParams p2)
Compares 2 domain parameter sets. The base points and the orders must be equal. If a cofactor is defined in both sets it must be equal as well.

Parameters:
p1 - parameters to be compared
p2 - parameters to be compared
Returns:
a boolean value if the parameters are equal.

IAIK ECC
version 2.18

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