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


Java ECFieldElement类代码示例

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


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

示例1: getYCoord

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECFieldElement getYCoord()
{
    ECFieldElement X = x, L = y;

    if (this.isInfinity() || X.isZero())
    {
        return L;
    }

    // Y is actually Lambda (X + Y/X) here; convert to affine value on the fly
    ECFieldElement Y = L.add(X).multiply(X);

    ECFieldElement Z = zs[0];
    if (!Z.isOne())
    {
        Y = Y.divide(Z);
    }

    return Y;
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:21,代码来源:SecT113R1Point.java

示例2: twice

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECPoint twice()
{
    if (this.isInfinity())
    {
        return this;
    }

    ECCurve curve = this.getCurve();

    ECFieldElement Y1 = this.y;
    if (Y1.isZero()) 
    {
        return curve.getInfinity();
    }

    return twiceJacobianModified(true);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:18,代码来源:Curve25519Point.java

示例3: negate

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECPoint negate()
{
    if (this.isInfinity())
    {
        return this;
    }

    ECFieldElement X = this.x;
    if (X.isZero())
    {
        return this;
    }

    // L is actually Lambda (X + Y/X) here
    ECFieldElement L = this.y, Z = this.zs[0];
    return new SecT193R1Point(curve, X, L.add(Z), new ECFieldElement[]{ Z }, this.withCompression);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:18,代码来源:SecT193R1Point.java

示例4: negate

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECPoint negate()
{
    if (this.isInfinity())
    {
        return this;
    }

    ECFieldElement X = this.x;
    if (X.isZero())
    {
        return this;
    }

    // L is actually Lambda (X + Y/X) here
    ECFieldElement L = this.y, Z = this.zs[0];
    return new SecT131R1Point(curve, X, L.add(Z), new ECFieldElement[]{ Z }, this.withCompression);
}
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:18,代码来源:SecT131R1Point.java

示例5: encodeToECPoint

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
private static ECPoint encodeToECPoint(ECParameterSpec ps, byte[] message, SecureRandom sr) {
		// Method based on Section 2.4 of https://eprint.iacr.org/2013/373.pdf

//		System.out.println("Encoding: " + BBS98BouncyCastle.bytesToHex(message));
		int lBits = ps.getN().bitLength() / 2;
//		System.out.println("N = " + ps.getN());
//		System.out.println("lbits: " + lBits);

		if (message.length * 8 > lBits) {
			throw new IllegalArgumentException("Message too large to be encoded");
		}

		BigInteger mask = BigInteger.ZERO.flipBit(lBits).subtract(BigInteger.ONE);
		BigInteger m = new BigInteger(1, message);

		ECFieldElement a = ps.getCurve().getA();
		ECFieldElement b = ps.getCurve().getB();

		BigInteger r;
		ECFieldElement x = null, y = null;
		do {
			r = BBS98BouncyCastle.getRandom(sr, ps.getN());
			r = r.andNot(mask).or(m);

			if (!ps.getCurve().isValidFieldElement(r)) {
				continue;
			}

			x = ps.getCurve().fromBigInteger(r);

			// y^2 = x^3 + ax + b = (x^2+a)x +b
			ECFieldElement y2 = x.square().add(a).multiply(x).add(b);
			y = y2.sqrt();

		} while (y == null);
		return ps.getCurve().createPoint(x.toBigInteger(), y.toBigInteger());

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

示例6: generateSignature

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public BigInteger[] generateSignature(byte[] message)
{
    ECFieldElement h = hash2FieldElement(key.getParameters().getCurve(), message);
    if (h.toBigInteger().signum() == 0)
    {
        h = key.getParameters().getCurve().fromBigInteger(ONE);
    }

    BigInteger e, r, s;
    ECFieldElement Fe, y;

    do
    {
        do
        {
            do
            {
                e = generateRandomInteger(key.getParameters().getN(), random);
                Fe = key.getParameters().getG().multiply(e).getX();
            }
            while (Fe.toBigInteger().signum() == 0);

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

        s = r.multiply(((ECPrivateKeyParameters)key).getD()).add(e).mod(key.getParameters().getN());
    }
    while (s.signum() == 0);

    return new BigInteger[]{r, s};
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:34,代码来源:DSTU4145Signer.java

示例7: verifySignature

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public boolean verifySignature(byte[] message, BigInteger r, BigInteger s)
{
    if (r.signum() == 0 || s.signum() == 0)
    {
        return false;
    }
    if (r.compareTo(key.getParameters().getN()) >= 0 || s.compareTo(key.getParameters().getN()) >= 0)
    {
        return false;
    }

    ECFieldElement h = hash2FieldElement(key.getParameters().getCurve(), message);
    if (h.toBigInteger().signum() == 0)
    {
        h = key.getParameters().getCurve().fromBigInteger(ONE);
    }

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

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

    ECFieldElement y = h.multiply(R.getX());
    return fieldElement2Integer(key.getParameters().getN(), y).compareTo(r) == 0;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:29,代码来源:DSTU4145Signer.java

示例8: hash2FieldElement

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
private static ECFieldElement hash2FieldElement(ECCurve curve, byte[] hash)
{
    byte[] data = Arrays.clone(hash);
    reverseBytes(data);
    BigInteger num = new BigInteger(1, data);
    while (num.bitLength() >= curve.getFieldSize())
    {
        num = num.clearBit(num.bitLength() - 1);
    }

    return curve.fromBigInteger(num);
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:13,代码来源:DSTU4145Signer.java

示例9: fieldElement2Integer

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
private static BigInteger fieldElement2Integer(BigInteger n, ECFieldElement fieldElement)
{
    BigInteger num = fieldElement.toBigInteger();
    while (num.bitLength() >= n.bitLength())
    {
        num = num.clearBit(num.bitLength() - 1);
    }

    return num;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:11,代码来源:DSTU4145Signer.java

示例10: trace

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
private static BigInteger trace(ECFieldElement fe)
{
    ECFieldElement t = fe;
    for (int i = 0; i < fe.getFieldSize() - 1; i++)
    {
        t = t.square().add(fe);
    }
    return t.toBigInteger();
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:10,代码来源:DSTU4145PointEncoder.java

示例11: solveQuadradicEquation

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
/**
 * Solves a quadratic equation <code>z<sup>2</sup> + z = beta</code>(X9.62
 * D.1.6) The other solution is <code>z + 1</code>.
 *
 * @param beta The value to solve the qradratic equation for.
 * @return the solution for <code>z<sup>2</sup> + z = beta</code> or
 *         <code>null</code> if no solution exists.
 */
private static ECFieldElement solveQuadradicEquation(ECFieldElement beta)
{
    ECFieldElement.F2m b = (ECFieldElement.F2m)beta;
    ECFieldElement zeroElement = new ECFieldElement.F2m(
        b.getM(), b.getK1(), b.getK2(), b.getK3(), ECConstants.ZERO);

    if (beta.toBigInteger().equals(ECConstants.ZERO))
    {
        return zeroElement;
    }

    ECFieldElement z = null;
    ECFieldElement gamma = zeroElement;

    Random rand = new Random();
    int m = b.getM();
    do
    {
        ECFieldElement t = new ECFieldElement.F2m(b.getM(), b.getK1(),
            b.getK2(), b.getK3(), new BigInteger(m, rand));
        z = zeroElement;
        ECFieldElement w = beta;
        for (int i = 1; i <= m - 1; i++)
        {
            ECFieldElement w2 = w.square();
            z = z.square().add(w2.multiply(t));
            w = w2.add(beta);
        }
        if (!w.toBigInteger().equals(ECConstants.ZERO))
        {
            return null;
        }
        gamma = z.square().add(z);
    }
    while (gamma.toBigInteger().equals(ECConstants.ZERO));

    return z;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:47,代码来源:DSTU4145PointEncoder.java

示例12: encodePoint

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public static byte[] encodePoint(ECPoint Q)
{
    /*if (!Q.isCompressed())
          Q=new ECPoint.F2m(Q.getCurve(),Q.getX(),Q.getY(),true);

      byte[] bytes=Q.getEncoded();

      if (bytes[0]==0x02)
          bytes[bytes.length-1]&=0xFE;
      else if (bytes[0]==0x02)
          bytes[bytes.length-1]|=0x01;

      return Arrays.copyOfRange(bytes, 1, bytes.length);*/

    int byteCount = converter.getByteLength(Q.getX());
    byte[] bytes = converter.integerToBytes(Q.getX().toBigInteger(), byteCount);

    if (!(Q.getX().toBigInteger().equals(ECConstants.ZERO)))
    {
        ECFieldElement y = Q.getY().multiply(Q.getX().invert());
        if (trace(y).equals(ECConstants.ONE))
        {
            bytes[bytes.length - 1] |= 0x01;
        }
        else
        {
            bytes[bytes.length - 1] &= 0xFE;
        }
    }

    return bytes;
}
 
开发者ID:Appdome,项目名称:ipack,代码行数:33,代码来源:DSTU4145PointEncoder.java

示例13: twice

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECPoint twice()
    {
        if (this.isInfinity())
        {
            return this;
        }

        ECCurve curve = this.getCurve();

        ECFieldElement X1 = this.x;
        if (X1.isZero())
        {
            // A point with X == 0 is it's own additive inverse
            return curve.getInfinity();
        }

        ECFieldElement L1 = this.y, Z1 = this.zs[0];

        boolean Z1IsOne = Z1.isOne();
        ECFieldElement L1Z1 = Z1IsOne ? L1 : L1.multiply(Z1);
        ECFieldElement Z1Sq = Z1IsOne ? Z1 : Z1.square();
        ECFieldElement T = L1.square().add(L1Z1).add(Z1Sq);
        if (T.isZero())
        {
//            return new SecT571R1Point(curve, T, curve.getB().sqrt(), withCompression);
            return new SecT571R1Point(curve, T, SecT571R1Curve.SecT571R1_B_SQRT, withCompression);
        }

        ECFieldElement X3 = T.square();
        ECFieldElement Z3 = Z1IsOne ? T : T.multiply(Z1Sq);

        ECFieldElement X1Z1 = Z1IsOne ? X1 : X1.multiply(Z1);
        ECFieldElement L3 = X1Z1.squarePlusProduct(T, L1Z1).add(X3).add(Z3);

        return new SecT571R1Point(curve, X3, L3, new ECFieldElement[]{ Z3 }, this.withCompression);
    }
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:37,代码来源:SecT571R1Point.java

示例14: invert

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECFieldElement invert()
    {
//        return new SecP224K1FieldElement(toBigInteger().modInverse(Q));
        int[] z = Nat224.create();
        Mod.invert(SecP224K1Field.P, x, z);
        return new SecP224K1FieldElement(z);
    }
 
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:8,代码来源:SecP224K1FieldElement.java

示例15: twice

import org.bouncycastle.math.ec.ECFieldElement; //导入依赖的package包/类
public ECPoint twice()
{
    if (this.isInfinity())
    {
        return this;
    }

    ECCurve curve = this.getCurve();

    ECFieldElement X1 = this.x;
    if (X1.isZero())
    {
        // A point with X == 0 is it's own additive inverse
        return curve.getInfinity();
    }

    ECFieldElement L1 = this.y, Z1 = this.zs[0];

    boolean Z1IsOne = Z1.isOne();
    ECFieldElement L1Z1 = Z1IsOne ? L1 : L1.multiply(Z1);
    ECFieldElement Z1Sq = Z1IsOne ? Z1 : Z1.square();
    ECFieldElement a = curve.getA();
    ECFieldElement aZ1Sq = Z1IsOne ? a : a.multiply(Z1Sq);
    ECFieldElement T = L1.square().add(L1Z1).add(aZ1Sq);
    if (T.isZero())
    {
        return new SecT193R2Point(curve, T, curve.getB().sqrt(), withCompression);
    }

    ECFieldElement X3 = T.square();
    ECFieldElement Z3 = Z1IsOne ? T : T.multiply(Z1Sq);

    ECFieldElement X1Z1 = Z1IsOne ? X1 : X1.multiply(Z1);
    ECFieldElement L3 = X1Z1.squarePlusProduct(T, L1Z1).add(X3).add(Z3);

    return new SecT193R2Point(curve, X3, L3, new ECFieldElement[]{ Z3 }, this.withCompression);
}
 
开发者ID:thedrummeraki,项目名称:Aki-SSL,代码行数:38,代码来源:SecT193R2Point.java


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