当前位置: 首页>>代码示例>>Java>>正文


Java ECPoint.multiply方法代码示例

本文整理汇总了Java中org.bouncycastle.math.ec.ECPoint.multiply方法的典型用法代码示例。如果您正苦于以下问题:Java ECPoint.multiply方法的具体用法?Java ECPoint.multiply怎么用?Java ECPoint.multiply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.bouncycastle.math.ec.ECPoint的用法示例。


在下文中一共展示了ECPoint.multiply方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transform

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * Transform an existing cipher test pair using the ElGamal algorithm. Note: the input cipherText will
 * need to be preserved in order to complete the transformation to the new public key.
 *
 * @param cipherText the EC point to process.
 * @return returns a new ECPair representing the result of the process.
 */
public ECPair transform(ECPair cipherText)
{
    if (key == null)
    {
        throw new IllegalStateException("ECNewPublicKeyTransform not initialised");
    }

    BigInteger             n = key.getParameters().getN();
    BigInteger             k = ECUtil.generateK(n, random);

    ECPoint  g = key.getParameters().getG();
    ECPoint  gamma = g.multiply(k);
    ECPoint  phi = key.getQ().multiply(k).add(cipherText.getY());

    return new ECPair(gamma, phi);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:24,代码来源:ECNewPublicKeyTransform.java

示例2: transform

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * Transform an existing cipher test pair using the ElGamal algorithm. Note: it is assumed this
 * transform has been initialised with the same public key that was used to create the original
 * cipher text.
 *
 * @param cipherText the EC point to process.
 * @return returns a new ECPair representing the result of the process.
 */
public ECPair transform(ECPair cipherText)
{
    if (key == null)
    {
        throw new IllegalStateException("ECNewRandomnessTransform not initialised");
    }

    BigInteger             n = key.getParameters().getN();
    BigInteger             k = ECUtil.generateK(n, random);

    ECPoint  g = key.getParameters().getG();
    ECPoint  gamma = g.multiply(k);
    ECPoint  phi = key.getQ().multiply(k).add(cipherText.getY());

    return new ECPair(cipherText.getX().add(gamma), phi);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:25,代码来源:ECNewRandomnessTransform.java

示例3: encrypt

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * Process a single EC point using the basic ElGamal algorithm.
 *
 * @param point the EC point to process.
 * @return the result of the Elgamal process.
 */
public ECPair encrypt(ECPoint point)
{
    if (key == null)
    {
        throw new IllegalStateException("ECElGamalEncryptor not initialised");
    }

    BigInteger             n = key.getParameters().getN();
    BigInteger             k = ECUtil.generateK(n, random);

    ECPoint  g = key.getParameters().getG();
    ECPoint  gamma = g.multiply(k);
    ECPoint  phi = key.getQ().multiply(k).add(point);

    return new ECPair(gamma, phi);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:23,代码来源:ECElGamalEncryptor.java

示例4: initEnc

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
public ECPoint initEnc(SM2 sm2, ECPoint userKey) {
    AsymmetricCipherKeyPair key = sm2.ecc_key_pair_generator.generateKeyPair();
    ECPrivateKeyParameters ecpriv = (ECPrivateKeyParameters) key.getPrivate();
    ECPublicKeyParameters ecpub = (ECPublicKeyParameters) key.getPublic();
    BigInteger k = ecpriv.getD();
    ECPoint c1 = ecpub.getQ();
    this.p2 = userKey.multiply(k);
    reset();
    return c1;
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:11,代码来源:Cipher.java

示例5: expon

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
public ECPoint expon(ECPoint base, BigInteger exp) {
    return base.multiply(exp);
}
 
开发者ID:cheahjs,项目名称:JLoopix,代码行数:4,代码来源:GroupECC.java

示例6: main

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
	
	SecureRandom sr = new SecureRandom(); // SecureRandom is thread-safe

	Security.addProvider(new BouncyCastleProvider());

	ECParameterSpec ecSpec = ECNamedCurveTable.getParameterSpec("P-256");
	BigInteger n = ecSpec.getN();

	KeyPairGenerator kpg = KeyPairGenerator.getInstance("ECDSA", "BC");

	kpg.initialize(ecSpec, new SecureRandom());
	KeyPair pair = kpg.generateKeyPair();

	ECPoint pki = ((ECPublicKey) pair.getPublic()).getQ();
	BigInteger xi = ((ECPrivateKey) pair.getPrivate()).getD();

	// BigInteger xi = getRandom(n);
	System.out.println("xi = " + xi);
	BigInteger xj = getRandom(sr, n);
	System.out.println("xj = " + xj);

	ECPoint g = ecSpec.getG();
	encoded(g);

	// ECPoint pki = g.multiply(xi);
	System.out.println("pki = " + pki);
	encoded(pki);
	ECPoint pkj = g.multiply(xj);
	System.out.println("pkj = " + pkj);
	encoded(pkj);

	ECPoint m = g.multiply(getRandom(sr, n));
	System.out.println("m = " + m);
	encoded(m);

	ECPoint[] c = encrypt(ecSpec, pki, m, sr);

	ECPoint m2 = decrypt(ecSpec, xi, c);
	System.out.println("m2 = " + m2);
	encoded(m2);

	if (!m2.equals(m)) {
		System.out.println("Error 1!");
	} else {
		System.out.println("m == m2? " + m2.equals(m));
	}

	// RKG & REENC

	BigInteger invxi = xi.modInverse(n);
	BigInteger rk = xj.multiply(invxi).mod(n);

	ECPoint[] c_j = reencrypt(ecSpec, rk, c);

	ECPoint m3 = decrypt(ecSpec, xj, c_j);
	System.out.println("m3 = " + m3);
	if (!m3.equals(m))
		System.out.println("Error 2!");

}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:62,代码来源:BBS98BouncyCastle.java

示例7: decrypt

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
/**
 * Decrypt an encapsulated session key.
 *
 * @param in     the input buffer for the encapsulated key.
 * @param inOff  the offset for the input buffer.
 * @param inLen  the length of the encapsulated key.
 * @param keyLen the length of the session key.
 * @return the session key.
 */
public CipherParameters decrypt(byte[] in, int inOff, int inLen, int keyLen)
    throws IllegalArgumentException
{
    if (!(key instanceof ECPrivateKeyParameters))
    {
        throw new IllegalArgumentException("Private key required for encryption");
    }

    BigInteger n = key.getParameters().getN();
    BigInteger h = key.getParameters().getH();

    // Decode the ephemeral public key
    byte[] C = new byte[inLen];
    System.arraycopy(in, inOff, C, 0, inLen);
    ECPoint gTilde = key.getParameters().getCurve().decodePoint(C);

    // Compute the static-ephemeral key agreement
    ECPoint gHat;
    if ((CofactorMode) || (OldCofactorMode))
    {
        gHat = gTilde.multiply(h);
    }
    else
    {
        gHat = gTilde;
    }

    BigInteger xHat;
    if (CofactorMode)
    {
        xHat = ((ECPrivateKeyParameters)key).getD().multiply(h.modInverse(n)).mod(n);
    }
    else
    {
        xHat = ((ECPrivateKeyParameters)key).getD();
    }

    ECPoint hTilde = gHat.multiply(xHat);

    // Encode the shared secret value
    int PEHlen = (key.getParameters().getCurve().getFieldSize() + 7) / 8;
    byte[] PEH = BigIntegers.asUnsignedByteArray(PEHlen, hTilde.getX().toBigInteger());

    // Initialise the KDF
    byte[] kdfInput;
    if (SingleHashMode)
    {
        kdfInput = new byte[C.length + PEH.length];
        System.arraycopy(C, 0, kdfInput, 0, C.length);
        System.arraycopy(PEH, 0, kdfInput, C.length, PEH.length);
    }
    else
    {
        kdfInput = PEH;
    }
    kdf.init(new KDFParameters(kdfInput, null));

    // Generate the secret key
    byte[] K = new byte[keyLen];
    kdf.generateBytes(K, 0, K.length);

    return new KeyParameter(K);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:73,代码来源:ECIESKeyEncapsulation.java

示例8: initDec

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
public void initDec(BigInteger userD, ECPoint c1) {
    this.p2 = c1.multiply(userD);
    reset();
}
 
开发者ID:nuls-io,项目名称:nuls,代码行数:5,代码来源:Cipher.java

示例9: Decrypt

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
@Override
public byte[] Decrypt(short quorumIndex, byte[] ciphertext) throws Exception {
    ECPoint c1 = Util.ECPointDeSerialization(curve, ciphertext, 0);
    ECPoint xc1_share = c1.multiply(priv_key_BI);
    return xc1_share.getEncoded(false);
}
 
开发者ID:OpenCryptoProject,项目名称:Myst,代码行数:7,代码来源:SimulatedMPCPlayer.java

示例10: encrypt

import org.bouncycastle.math.ec.ECPoint; //导入方法依赖的package包/类
public static ECPoint[] encrypt(ECParameterSpec ecSpec, ECPoint pk, ECPoint m, SecureRandom sr) {
	ECPoint g = ecSpec.getG();
	BigInteger n = ecSpec.getN();

	BigInteger r = getRandom(sr, n);

	ECPoint g_r = g.multiply(r);

	ECPoint m_g_r = g_r.add(m);
	ECPoint pk_r = pk.multiply(r);

	return new ECPoint[] { pk_r, m_g_r };
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:14,代码来源:BBS98BouncyCastle.java


注:本文中的org.bouncycastle.math.ec.ECPoint.multiply方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。