de.flexiprovider.ec
Class ECSVDPDHC

java.lang.Object
  |
  +--javax.crypto.KeyAgreementSpi
        |
        +--de.flexiprovider.api.KeyAgreement
              |
              +--de.flexiprovider.ec.ECSVDPDHC
Direct Known Subclasses:
ECSVDPDH

public class ECSVDPDHC
extends KeyAgreement

ECSVDPDHC provides the implementation for key exchange with the Diffie Hellman algorithm on elliptic curves GP(p), where p is an odd prime number.

This class implements the ECSVDP-DHC primitive from IEEE 1363, i.e. the Diffie Hellman algorithm with co-factor multiplication.

Usage:

kagA and kagB represent the parties trying to establish a shared secret key, each with a private and public key. The following steps have to be performed:

 KeyAgreement kagA = KeyAgreement.getInstance("ECDH", "FlexiEC");
 kagA.init(ecprivA, params, random);
 KeyAgreement kagB = KeyAgreement.getInstance("ECDH", "FlexiEC");
 kagB.init(ecprivB, random);
 ECSecretKey secrA = (ECSecretKey) kagA.doPhase(ecpubB, true);
 ECSecretKey secrB = (ECSecretKey) kagB.doPhase(ecpubA, true);
 

Author:
Jochen Hechler, Marcus Stögbauer, Martin Döring
See Also:
ECPrivateKey, ECPublicKey, ECSecretKey

Field Summary
protected  boolean withCoFactor
          flag indicating whether cofactor multiplication shall be used
 
Constructor Summary
ECSVDPDHC()
           
 
Method Summary
 Key doPhase(PublicKey key, boolean lastPhase)
          Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.
 byte[] generateSecret()
          Generates the shared Secret and returns it as an byte-array.
 int generateSecret(byte[] sharedSecret, int offset)
          Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset inclusive.
 SecretKey generateSecret(java.lang.String algorithm)
          Generate the shared secret via the algorithm specified in algorithm.
 void init(PrivateKey key, AlgorithmParameterSpec params, SecureRandom random)
          Initializes this ECSVDPDHC with a key, the curve parameters and some random information which is not being used here.
 void init(PrivateKey key, SecureRandom random)
          Initializes this ECSVDPDHC with a key and some random information which is not being used here.
 
Methods inherited from class de.flexiprovider.api.KeyAgreement
engineDoPhase, engineGenerateSecret, engineGenerateSecret, engineGenerateSecret, engineInit, engineInit
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

withCoFactor

protected boolean withCoFactor
flag indicating whether cofactor multiplication shall be used
Constructor Detail

ECSVDPDHC

public ECSVDPDHC()
Method Detail

init

public void init(PrivateKey key,
                 AlgorithmParameterSpec params,
                 SecureRandom random)
          throws InvalidKeyException
Initializes this ECSVDPDHC with a key, the curve parameters and some random information which is not being used here.
Overrides:
init in class KeyAgreement
Parameters:
key - is the private key of the party initializing ECSVDPDHC
params - are the curve parameters
random - contains some random information that are randomly ignored
Throws:
InvalidKeyException - if key is no instance of ECPrivateKey.

init

public void init(PrivateKey key,
                 SecureRandom random)
          throws InvalidKeyException
Initializes this ECSVDPDHC with a key and some random information which is not being used here.
Parameters:
key - is the secret key of the party initializing ECSVDPDHC
random - contains some random information that are randomly ignored
Throws:
InvalidKeyException - if key is no instance of ECPrivateKey

generateSecret

public SecretKey generateSecret(java.lang.String algorithm)
                         throws NoSuchAlgorithmException
Generate the shared secret via the algorithm specified in algorithm. Only ECDH is valid for algorithm. This is only a wrapper function, the whole work is done in secretGenerator.
Overrides:
generateSecret in class KeyAgreement
Parameters:
algorithm - is the desired algorithm for the generation of the secret
Returns:
the shared secret as an SecretKey
Throws:
NoSuchAlgorithmException - if algorithm isn't ECDH

generateSecret

public int generateSecret(byte[] sharedSecret,
                          int offset)
                   throws ShortBufferException
Generates the shared secret, and places it into the buffer sharedSecret, beginning at offset inclusive. This is only a wrapper function, the whole work is done in secretGenerator.
Overrides:
generateSecret in class KeyAgreement
Parameters:
sharedSecret - is the buffer for the shared secret
offset - is the offset in sharedSecret where the shared secret will be stored
Returns:
the number of bytes written in sharedSecret
Throws:
ShortBufferException - if sharedSecret is too small to to hold the shared secret

generateSecret

public byte[] generateSecret()
Generates the shared Secret and returns it as an byte-array. This is only a wrapper function, the whole work is done in secretGenerator.
Overrides:
generateSecret in class KeyAgreement
Returns:
the shared SecretValue as an byte-array, and null if the object is not in DoPhase

doPhase

public Key doPhase(PublicKey key,
                   boolean lastPhase)
            throws InvalidKeyException
Executes the next phase of this key agreement with the given key that was received from one of the other parties involved in this key agreement.
Overrides:
doPhase in class KeyAgreement
Parameters:
key - the public key of the other party
lastPhase - true, if this is the last phase of the key agreement. After the last phase only generateSecret should be called.
Returns:
the shared secret as a java.security.Key
Throws:
InvalidKeyException - if key is no interface of an ECPublicKey or if key is an invalid ECPublicKey