Save This Page
Home » crypto-143 » org.bouncycastle.crypto.agreement » [javadoc | source]
    1   package org.bouncycastle.crypto.agreement;
    2   
    3   import java.math.BigInteger;
    4   
    5   import org.bouncycastle.math.ec.ECPoint;
    6   
    7   import org.bouncycastle.crypto.BasicAgreement;
    8   import org.bouncycastle.crypto.CipherParameters;
    9   import org.bouncycastle.crypto.params.ECPublicKeyParameters;
   10   import org.bouncycastle.crypto.params.ECPrivateKeyParameters;
   11   import org.bouncycastle.crypto.params.ECDomainParameters;
   12   
   13   /**
   14    * P1363 7.2.2 ECSVDP-DHC
   15    *
   16    * ECSVDP-DHC is Elliptic Curve Secret Value Derivation Primitive,
   17    * Diffie-Hellman version with cofactor multiplication. It is based on
   18    * the work of [DH76], [Mil86], [Kob87], [LMQ98] and [Kal98a]. This
   19    * primitive derives a shared secret value from one party's private key
   20    * and another party's public key, where both have the same set of EC
   21    * domain parameters. If two parties correctly execute this primitive,
   22    * they will produce the same output. This primitive can be invoked by a
   23    * scheme to derive a shared secret key; specifically, it may be used
   24    * with the schemes ECKAS-DH1 and DL/ECKAS-DH2. It does not assume the
   25    * validity of the input public key (see also Section 7.2.1).
   26    * <p>
   27    * Note: As stated P1363 compatability mode with ECDH can be preset, and
   28    * in this case the implementation doesn't have a ECDH compatability mode
   29    * (if you want that just use ECDHBasicAgreement and note they both implement
   30    * BasicAgreement!).
   31    */
   32   public class ECDHCBasicAgreement
   33       implements BasicAgreement
   34   {
   35       ECPrivateKeyParameters key;
   36   
   37       public void init(
   38           CipherParameters key)
   39       {
   40           this.key = (ECPrivateKeyParameters)key;
   41       }
   42   
   43       public BigInteger calculateAgreement(
   44           CipherParameters pubKey)
   45       {
   46           ECPublicKeyParameters   pub = (ECPublicKeyParameters)pubKey;
   47           ECDomainParameters      params = pub.getParameters();
   48           ECPoint P = pub.getQ().multiply(params.getH().multiply(key.getD()));
   49   
   50           // if (p.isInfinity()) throw new RuntimeException("Invalid public key");
   51   
   52           return P.getX().toBigInteger();
   53       }
   54   }

Save This Page
Home » crypto-143 » org.bouncycastle.crypto.agreement » [javadoc | source]