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


Java ECDomainParameters.getCurve方法代码示例

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


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

示例1: DSTU4145ECBinary

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
public DSTU4145ECBinary(ECDomainParameters params)
{
    if (!(params.getCurve() instanceof ECCurve.F2m))
    {
        throw new IllegalArgumentException("only binary domain is possible");
    }

    // We always use big-endian in parameter encoding
    ECCurve.F2m curve = (ECCurve.F2m)params.getCurve();
    f = new DSTU4145BinaryField(curve.getM(), curve.getK1(), curve.getK2(), curve.getK3());
    a = new ASN1Integer(curve.getA().toBigInteger());
    X9IntegerConverter converter = new X9IntegerConverter();
    b = new DEROctetString(converter.integerToBytes(curve.getB().toBigInteger(), converter.getByteLength(curve)));
    n = new ASN1Integer(params.getN());
    bp = new DEROctetString(DSTU4145PointEncoder.encodePoint(params.getG()));
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:17,代码来源:DSTU4145ECBinary.java

示例2: JCEECPrivateKey

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
JCEECPrivateKey(
    String                  algorithm,
    ECPrivateKeyParameters  params,
    ECParameterSpec         spec)
{
    ECDomainParameters      dp = params.getParameters();

    this.algorithm = algorithm;
    this.d = params.getD();

    if (spec == null)
    {
        this.ecSpec = new ECParameterSpec(
                        dp.getCurve(),
                        dp.getG(),
                        dp.getN(),
                        dp.getH(),
                        dp.getSeed());
    }
    else
    {
        this.ecSpec = spec;
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:25,代码来源:JCEECPrivateKey.java

示例3: JCEECPublicKey

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
JCEECPublicKey(
    String                  algorithm,
    ECPublicKeyParameters   params,
    ECParameterSpec         spec)
{
    ECDomainParameters      dp = params.getParameters();

    this.algorithm = algorithm;
    this.q = params.getQ();

    if (spec == null)
    {
        this.ecSpec = new ECParameterSpec(
                        dp.getCurve(),
                        dp.getG(),
                        dp.getN(),
                        dp.getH(),
                        dp.getSeed());
    }
    else
    {
        this.ecSpec = spec;
    }
}
 
开发者ID:thangbn,项目名称:Direct-File-Downloader,代码行数:25,代码来源:JCEECPublicKey.java

示例4: getParameterSpec

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
/**
 * return a parameter spec representing the passed in named
 * curve. The routine returns null if the curve is not present.
 * 
 * @param name the name of the curve requested
 * @return a parameter spec for the curve, null if it is not available.
 */
public static ECNamedCurveParameterSpec getParameterSpec(
    String  name)
{
    ECDomainParameters  ecP = ECGOST3410NamedCurves.getByName(name);
    if (ecP == null)
    {
        try
        {
            ecP = ECGOST3410NamedCurves.getByOID(new ASN1ObjectIdentifier(name));
        }
        catch (IllegalArgumentException e)
        {
            return null; // not an oid.
        }
    }
    
    if (ecP == null)
    {
        return null;
    }

    return new ECNamedCurveParameterSpec(
                                    name,
                                    ecP.getCurve(),
                                    ecP.getG(),
                                    ecP.getN(),
                                    ecP.getH(),
                                    ecP.getSeed());
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:37,代码来源:ECGOST3410NamedCurveTable.java

示例5: calculateMqvAgreement

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
private ECPoint calculateMqvAgreement(
    ECDomainParameters      parameters,
    ECPrivateKeyParameters  d1U,
    ECPrivateKeyParameters  d2U,
    ECPublicKeyParameters   Q2U,
    ECPublicKeyParameters   Q1V,
    ECPublicKeyParameters   Q2V)
{
    BigInteger n = parameters.getN();
    int e = (n.bitLength() + 1) / 2;
    BigInteger powE = ECConstants.ONE.shiftLeft(e);

    ECCurve curve = parameters.getCurve();

    ECPoint[] points = new ECPoint[]{
        // The Q2U public key is optional
        ECAlgorithms.importPoint(curve, Q2U == null ? parameters.getG().multiply(d2U.getD()) : Q2U.getQ()),
        ECAlgorithms.importPoint(curve, Q1V.getQ()),
        ECAlgorithms.importPoint(curve, Q2V.getQ())
    };

    curve.normalizeAll(points);

    ECPoint q2u = points[0], q1v = points[1], q2v = points[2];

    BigInteger x = q2u.getAffineXCoord().toBigInteger();
    BigInteger xBar = x.mod(powE);
    BigInteger Q2UBar = xBar.setBit(e);
    BigInteger s = d1U.getD().multiply(Q2UBar).add(d2U.getD()).mod(n);

    BigInteger xPrime = q2v.getAffineXCoord().toBigInteger();
    BigInteger xPrimeBar = xPrime.mod(powE);
    BigInteger Q2VBar = xPrimeBar.setBit(e);

    BigInteger hs = parameters.getH().multiply(s).mod(n);

    return ECAlgorithms.sumOfTwoMultiplies(
        q1v, Q2VBar.multiply(hs).mod(n), q2v, hs);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:40,代码来源:ECMQVBasicAgreement.java

示例6: verifySignature

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
public boolean verifySignature(byte[] message, BigInteger r, BigInteger s)
{
    if (r.signum() <= 0 || s.signum() <= 0)
    {
        return false;
    }

    ECDomainParameters parameters = key.getParameters();

    BigInteger n = parameters.getN();
    if (r.compareTo(n) >= 0 || s.compareTo(n) >= 0)
    {
        return false;
    }

    ECCurve curve = parameters.getCurve();

    ECFieldElement h = hash2FieldElement(curve, message);
    if (h.isZero())
    {
        h = curve.fromBigInteger(ONE);
    }

    ECPoint R = ECAlgorithms.sumOfTwoMultiplies(parameters.getG(), s, ((ECPublicKeyParameters)key).getQ(), r).normalize();

    // components must be bogus.
    if (R.isInfinity())
    {
        return false;
    }

    ECFieldElement y = h.multiply(R.getAffineXCoord());
    return fieldElement2Integer(n, y).compareTo(r) == 0;
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:35,代码来源:DSTU4145Signer.java

示例7: DSTU4145ECBinary

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
public DSTU4145ECBinary(ECDomainParameters params)
{
    ECCurve curve = params.getCurve();
    if (!ECAlgorithms.isF2mCurve(curve))
    {
        throw new IllegalArgumentException("only binary domain is possible");
    }

    // We always use big-endian in parameter encoding

    PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
    int[] exponents = field.getMinimalPolynomial().getExponentsPresent();
    if (exponents.length == 3)
    {
        f = new DSTU4145BinaryField(exponents[2], exponents[1]);
    }
    else if (exponents.length == 5)
    {
        f = new DSTU4145BinaryField(exponents[4], exponents[1], exponents[2], exponents[3]);
    }
    else
    {
        throw new IllegalArgumentException("curve must have a trinomial or pentanomial basis");
    }

    a = new ASN1Integer(curve.getA().toBigInteger());
    b = new DEROctetString(curve.getB().getEncoded());
    n = new ASN1Integer(params.getN());
    bp = new DEROctetString(DSTU4145PointEncoder.encodePoint(params.getG()));
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:31,代码来源:DSTU4145ECBinary.java

示例8: writeExplicitECParameters

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
public static void writeExplicitECParameters(short[] ecPointFormats, ECDomainParameters ecParameters,
                                             OutputStream output)
    throws IOException
{

    ECCurve curve = ecParameters.getCurve();
    if (curve instanceof ECCurve.Fp)
    {

        TlsUtils.writeUint8(ECCurveType.explicit_prime, output);

        ECCurve.Fp fp = (ECCurve.Fp)curve;
        writeECParameter(fp.getQ(), output);

    }
    else if (curve instanceof ECCurve.F2m)
    {

        TlsUtils.writeUint8(ECCurveType.explicit_char2, output);

        ECCurve.F2m f2m = (ECCurve.F2m)curve;
        TlsUtils.writeUint16(f2m.getM(), output);

        if (f2m.isTrinomial())
        {
            TlsUtils.writeUint8(ECBasisType.ec_basis_trinomial, output);
            writeECExponent(f2m.getK1(), output);
        }
        else
        {
            TlsUtils.writeUint8(ECBasisType.ec_basis_pentanomial, output);
            writeECExponent(f2m.getK1(), output);
            writeECExponent(f2m.getK2(), output);
            writeECExponent(f2m.getK3(), output);
        }

    }
    else
    {
        throw new IllegalArgumentException("'ecParameters' not a known curve type");
    }

    writeECFieldElement(curve.getFieldSize(), curve.getA().toBigInteger(), output);
    writeECFieldElement(curve.getFieldSize(), curve.getB().toBigInteger(), output);
    TlsUtils.writeOpaque8(serializeECPoint(ecPointFormats, ecParameters.getG()), output);
    writeECParameter(ecParameters.getN(), output);
    writeECParameter(ecParameters.getH(), output);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:49,代码来源:TlsECCUtils.java

示例9: writeExplicitECParameters

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
public static void writeExplicitECParameters(short[] ecPointFormats, ECDomainParameters ecParameters,
    OutputStream output) throws IOException
{
    ECCurve curve = ecParameters.getCurve();

    if (ECAlgorithms.isFpCurve(curve))
    {
        TlsUtils.writeUint8(ECCurveType.explicit_prime, output);

        writeECParameter(curve.getField().getCharacteristic(), output);
    }
    else if (ECAlgorithms.isF2mCurve(curve))
    {
        PolynomialExtensionField field = (PolynomialExtensionField)curve.getField();
        int[] exponents = field.getMinimalPolynomial().getExponentsPresent();

        TlsUtils.writeUint8(ECCurveType.explicit_char2, output);

        int m = exponents[exponents.length - 1];
        TlsUtils.checkUint16(m);
        TlsUtils.writeUint16(m, output);

        if (exponents.length == 3)
        {
            TlsUtils.writeUint8(ECBasisType.ec_basis_trinomial, output);
            writeECExponent(exponents[1], output);
        }
        else if (exponents.length == 5)
        {
            TlsUtils.writeUint8(ECBasisType.ec_basis_pentanomial, output);
            writeECExponent(exponents[1], output);
            writeECExponent(exponents[2], output);
            writeECExponent(exponents[3], output);
        }
        else
        {
            throw new IllegalArgumentException("Only trinomial and pentomial curves are supported");
        }
    }
    else
    {
        throw new IllegalArgumentException("'ecParameters' not a known curve type");
    }

    writeECFieldElement(curve.getA(), output);
    writeECFieldElement(curve.getB(), output);
    TlsUtils.writeOpaque8(serializeECPoint(ecPointFormats, ecParameters.getG()), output);
    writeECParameter(ecParameters.getN(), output);
    writeECParameter(ecParameters.getH(), output);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:51,代码来源:TlsECCUtils.java

示例10: generateSignature

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
public BigInteger[] generateSignature(byte[] message)
{
    ECDomainParameters ec = key.getParameters();

    ECCurve curve = ec.getCurve();

    ECFieldElement h = hash2FieldElement(curve, message);
    if (h.isZero())
    {
        h = curve.fromBigInteger(ONE);
    }

    BigInteger n = ec.getN();
    BigInteger e, r, s;
    ECFieldElement Fe, y;

    BigInteger d = ((ECPrivateKeyParameters)key).getD();

    ECMultiplier basePointMultiplier = createBasePointMultiplier();

    do
    {
        do
        {
            do
            {
                e = generateRandomInteger(n, random);
                Fe = basePointMultiplier.multiply(ec.getG(), e).normalize().getAffineXCoord();
            }
            while (Fe.isZero());

            y = h.multiply(Fe);
            r = fieldElement2Integer(n, y);
        }
        while (r.signum() == 0);

        s = r.multiply(d).add(e).mod(n);
    }
    while (s.signum() == 0);

    return new BigInteger[]{r, s};
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:43,代码来源:DSTU4145Signer.java

示例11: encrypt

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
/**
 * Generate and encapsulate a random session key.
 *
 * @param out    the output buffer for the encapsulated key.
 * @param outOff the offset for the output buffer.
 * @param keyLen the length of the session key.
 * @return the random session key.
 */
public CipherParameters encrypt(byte[] out, int outOff, int keyLen)
    throws IllegalArgumentException
{
    if (!(key instanceof ECPublicKeyParameters))
    {
        throw new IllegalArgumentException("Public key required for encryption");
    }

    ECPublicKeyParameters ecPubKey = (ECPublicKeyParameters)key;
    ECDomainParameters ecParams = ecPubKey.getParameters();
    ECCurve curve = ecParams.getCurve();
    BigInteger n = ecParams.getN();
    BigInteger h = ecParams.getH();

    // Generate the ephemeral key pair    
    BigInteger r = BigIntegers.createRandomInRange(ONE, n, rnd);

    // Compute the static-ephemeral key agreement
    BigInteger rPrime = CofactorMode ? r.multiply(h).mod(n) : r;

    ECMultiplier basePointMultiplier = createBasePointMultiplier();

    ECPoint[] ghTilde = new ECPoint[]{ 
        basePointMultiplier.multiply(ecParams.getG(), r),
        ecPubKey.getQ().multiply(rPrime)
    };

    // NOTE: More efficient than normalizing each individually
    curve.normalizeAll(ghTilde);

    ECPoint gTilde = ghTilde[0], hTilde = ghTilde[1];

    // Encode the ephemeral public key
    byte[] C = gTilde.getEncoded(false);
    System.arraycopy(C, 0, out, outOff, C.length);

    // Encode the shared secret value
    byte[] PEH = hTilde.getAffineXCoord().getEncoded();

    return deriveKey(keyLen, C, PEH);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:50,代码来源:ECIESKeyEncapsulation.java

示例12: decrypt

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的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");
    }

    ECPrivateKeyParameters ecPrivKey = (ECPrivateKeyParameters)key;
    ECDomainParameters ecParams = ecPrivKey.getParameters();
    ECCurve curve = ecParams.getCurve();
    BigInteger n = ecParams.getN();
    BigInteger h = ecParams.getH();

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

    // NOTE: Decoded points are already normalized (i.e in affine form)
    ECPoint gTilde = curve.decodePoint(C);

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

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

    ECPoint hTilde = gHat.multiply(xHat).normalize();

    // Encode the shared secret value
    byte[] PEH = hTilde.getAffineXCoord().getEncoded();

    return deriveKey(keyLen, C, PEH);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:51,代码来源:ECIESKeyEncapsulation.java

示例13: getSendAddress

import org.bouncycastle.crypto.params.ECDomainParameters; //导入方法依赖的package包/类
/**
 * Calculates the sent address of an EthereumTransaction. Note this can be a costly operation to calculate. . This requires that you have Bouncy castle as a dependency in your project
 *
 *
 * @param eTrans transaction
 * @return sent address as byte array
 */
public static byte[] getSendAddress(EthereumTransaction eTrans) {
	// init, maybe we move this out to save time
	X9ECParameters params = SECNamedCurves.getByName("secp256k1");
	ECDomainParameters CURVE=new ECDomainParameters(params.getCurve(), params.getG(), params.getN(), params.getH());	 // needed for getSentAddress

  // transaction hash without signature data
	byte[] transactionHash = EthereumUtil.getTransactionHashWithoutSignature(eTrans);
  // signature to address
	BigInteger bR = new BigInteger(1,eTrans.getSig_r());
	BigInteger bS = new BigInteger(1,eTrans.getSig_s());
  // calculate v for signature
	byte v =(byte) (eTrans.getSig_v()[0]);
	if (!((v == EthereumUtil.LOWER_REAL_V) || (v== (LOWER_REAL_V+1)))) {
		v = EthereumUtil.LOWER_REAL_V;
		if (((int)v%2 == 0)) {
			v = (byte) (v+0x01);
		}
	}
	
	boolean compressedKey= false;
	// the following lines are inspired from ECKey.java of EthereumJ, but adapted to the hadoopcryptoledger context
	if (v < 27 || v > 34) {
		throw new RuntimeException("Header out of range");
	}
	if (v>=31) {
		compressedKey = true;
		v -=4;
	}
	int receiverId = v - 27;
	BigInteger n = CURVE.getN();
    BigInteger i = BigInteger.valueOf((long) receiverId / 2);
    BigInteger x = bR.add(i.multiply(n));
    ECCurve.Fp curve = (ECCurve.Fp) CURVE.getCurve();
    BigInteger prime = curve.getQ();
    if (x.compareTo(prime) >= 0) {
        return null;
     }
    // decompress Key
    X9IntegerConverter x9 = new X9IntegerConverter();
    byte[] compEnc = x9.integerToBytes(x, 1 + x9.getByteLength(CURVE.getCurve()));
    boolean yBit=(receiverId & 1) == 1;
    compEnc[0] = (byte)(yBit ? 0x03 : 0x02);
    ECPoint R =  CURVE.getCurve().decodePoint(compEnc);
    if (!R.multiply(n).isInfinity()) {
    		return null;
    }
    BigInteger e = new BigInteger(1,transactionHash);
    BigInteger eInv = BigInteger.ZERO.subtract(e).mod(n);
    BigInteger rInv = bR.modInverse(n);
    BigInteger srInv = rInv.multiply(bS).mod(n);
    BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
    ECPoint.Fp q = (ECPoint.Fp) ECAlgorithms.sumOfTwoMultiplies(CURVE.getG(), eInvrInv, R, srInv);
    byte[] pubKey=q.getEncoded(false);
    // now we need to convert the public key into an ethereum sent address which is the last 20 bytes of 32 byte KECCAK-256 Hash of the key.
	Keccak.Digest256 digest256 = new Keccak.Digest256();
	digest256.update(pubKey,1,pubKey.length-1);
	byte[] kcck = digest256.digest();
    return Arrays.copyOfRange(kcck,12,kcck.length);
}
 
开发者ID:ZuInnoTe,项目名称:hadoopcryptoledger,代码行数:67,代码来源:EthereumUtil.java


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