类java.security.spec.ECFieldF2m源码实例Demo

下面列出了怎么用java.security.spec.ECFieldF2m的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Tests for constructor <code>ECFieldF2m(int)</code><br>
 *
 * Assertion: constructs new <code>ECFieldF2m</code> object
 * using valid parameter m.
 *
 * Assertion: IllegalArgumentException if m is not positive.
 */
public final void testECFieldF2mint() {
    for(int i=0; i<intCtorTestParameters.length; i++) {
        ECFieldF2mDomainParams tp = intCtorTestParameters[i];
        try {
            // perform test
            new ECFieldF2m(tp.m);

            if (tp.x != null) {
                // exception has been expected
                fail(getName() + ", set " + i +
                        " FAILED: expected exception has not been thrown");
            }
        } catch (Exception e){
            if (tp.x == null || !e.getClass().isInstance(tp.x)) {
                // exception: failure
                // if it has not been expected
                // or wrong one has been thrown
                fail(getName() + ", set " + i +
                        " FAILED: unexpected " + e);
            }
        }
    }
}
 
源代码2 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Tests for constructor <code>ECFieldF2m(int m, int[] ks)</code><br>
 *
 * Assertion: constructs new <code>ECFieldF2m</code> object
 * using valid parameters m and rp. ks represents trinomial basis.
 *
 * Assertion: constructs new <code>ECFieldF2m</code> object
 * using valid parameters m and ks. ks represents pentanomial basis.
 *
 * Assertion: IllegalArgumentException if m is not positive.
 *
 * Assertion: NullPointerException if ks is null.
 *
 * Assertion: IllegalArgumentException if ks is invalid.
 */
public final void testECFieldF2mintintArray() {
    for(int i=0; i<constructorTestParameters.length; i++) {
        ECFieldF2mDomainParams tp = constructorTestParameters[i];
        try {
            // perform test
            ECFieldF2m test = new ECFieldF2m(tp.m, tp.ks);

            if (tp.x != null) {
                // exception has been expected
                fail(getName() + ", set " + i +
                        " FAILED: expected exception has not been thrown");
            }
        } catch (Exception e){
            if (tp.x == null || !e.getClass().isInstance(tp.x)) {
                // exception: failure
                // if it has not been expected
                // or wrong one has been thrown
                fail(getName() + ", set " + i +
                        " FAILED: unexpected " + e);
            }
        }
    }
}
 
源代码3 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Tests for constructor <code>ECFieldF2m(int m, BigInteger rp)</code><br>
 *
 * Assertion: constructs new <code>ECFieldF2m</code> object
 * using valid parameters m and rp.
 *
 * Assertion: constructs new <code>ECFieldF2m</code> object
 * using valid parameters m and rp.
 *
 * Assertion: IllegalArgumentException if m is not positive.
 *
 * Assertion: NullPointerException if rp is null.
 *
 * Assertion: IllegalArgumentException if rp is invalid.
 */
public final void testECFieldF2mintBigInteger() {
    for(int i=0; i<constructorTestParameters.length; i++) {
        ECFieldF2mDomainParams tp = constructorTestParameters[i];
        try {
            // perform test
            new ECFieldF2m(tp.m, tp.rp);

            if (tp.x != null) {
                // exception has been expected
                fail(getName() + ", set " + i +
                        " FAILED: expected exception has not been thrown");
            }
        } catch (Exception e){
            if (tp.x == null || !e.getClass().isInstance(tp.x)) {
                // exception: failure
                // if it has not been expected
                // or wrong one has been thrown
                fail(getName() + ", set " + i +
                        " FAILED: unexpected " + e);
            }
        }
    }
}
 
源代码4 项目: RipplePower   文件: EC5Util.java
public static ECCurve convertCurve(
    EllipticCurve ec)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        ECCurve.Fp curve = new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);

        if (customCurves.containsKey(curve))
        {
            return (ECCurve)customCurves.get(curve);
        }

        return curve;
    }
    else
    {
        ECFieldF2m fieldF2m = (ECFieldF2m)field;
        int m = fieldF2m.getM();
        int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
        return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b); 
    }
}
 
源代码5 项目: ripple-lib-java   文件: EC5Util.java
public static ECCurve convertCurve(
    EllipticCurve ec)
{
    ECField field = ec.getField();
    BigInteger a = ec.getA();
    BigInteger b = ec.getB();

    if (field instanceof ECFieldFp)
    {
        ECCurve.Fp curve = new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);

        if (customCurves.containsKey(curve))
        {
            return (ECCurve)customCurves.get(curve);
        }

        return curve;
    }
    else
    {
        ECFieldF2m fieldF2m = (ECFieldF2m)field;
        int m = fieldF2m.getM();
        int ks[] = ECUtil.convertMidTerms(fieldF2m.getMidTermsOfReductionPolynomial());
        return new ECCurve.F2m(m, ks[0], ks[1], ks[2], a, b); 
    }
}
 
源代码6 项目: swim   文件: EcFieldDef.java
public static EcFieldDef from(ECField field) {
  if (field instanceof ECFieldFp) {
    return EcPrimeFieldDef.from((ECFieldFp) field);
  } else if (field instanceof ECFieldF2m) {
    return EcCharacteristic2FieldDef.from((ECFieldF2m) field);
  } else {
    throw new IllegalArgumentException(field.toString());
  }
}
 
源代码7 项目: swim   文件: EcCharacteristic2FieldDef.java
@Override
public ECFieldF2m toECField() {
  if (this.basis != null) {
    return new ECFieldF2m(this.size, this.basis);
  } else {
    return new ECFieldF2m(this.size);
  }
}
 
源代码8 项目: j2objc   文件: EllipticCurveTest.java
/**
 * Test #5 for <code>EllipticCurve(ECField, BigInteger, BigInteger, byte[])</code>
 * constructor<br>
 * Assertion: array <code>seed</code> is copied to prevent subsequent modification<br>
 * Test preconditions: pass <code>seed</code> to the ctor then modify it<br>
 * Expected: getSeed() must return unmodified array
 */
public final void testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05() {
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(0L);
    BigInteger b = BigInteger.valueOf(19L);
    byte[] seed = new byte[24];
    byte[] seedCopy = seed.clone();
    EllipticCurve c = new EllipticCurve(f, a, b, seedCopy);
    // modify array passed
    seedCopy[0] = (byte) 1;
    // check that above modification did not changed
    // internal state of test object
    assertTrue(Arrays.equals(seed, c.getSeed()));
}
 
源代码9 项目: j2objc   文件: ECPublicKeySpecTest.java
protected void setUp() throws Exception {
    super.setUp();
    ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger
            .valueOf(1));
    EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger
            .valueOf(1), BigInteger.valueOf(1));

    w = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1));
    params = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1);
    ecpks = new ECPublicKeySpec(w, params);
}
 
源代码10 项目: j2objc   文件: ECPrivateKeySpecTest.java
protected void setUp() throws Exception {
    super.setUp();

    ECPoint ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger
            .valueOf(1));
    EllipticCurve curve = new EllipticCurve(new ECFieldF2m(2), BigInteger
            .valueOf(1), BigInteger.valueOf(1));

    s = BigInteger.valueOf(1);
    ecparams = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1);
    ecpks = new ECPrivateKeySpec(s, ecparams);
}
 
源代码11 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #1 for <code>hashCode()</code> method.<br>
 *
 * Assertion: must return the same value if invoked
 * repeatedly on the same object.
 */
public final void testHashCode01() {
    ECFieldF2m f = new ECFieldF2m(2000);
    int hc = f.hashCode();
    assertTrue(hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode());
}
 
源代码12 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #2 for <code>hashCode()</code> method.<br>
 *
 * Assertion: must return the same value if invoked
 * repeatedly on the same object.
 */
public final void testHashCode02() {
    ECFieldF2m f = new ECFieldF2m(2000, new int[] {981, 2, 1});
    int hc = f.hashCode();
    assertTrue(hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode() &&
               hc == f.hashCode());
}
 
源代码13 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #5 for <code>hashCode()</code> method.<br>
 *
 * Assertion: must return the same value if invoked
 * on equal (according to the <code>equals(Object)</code> method) objects.
 */
public final void testHashCode05() {
    assertTrue(new ECFieldF2m(2000, new int[] {981, 2, 1}).hashCode() ==
               new ECFieldF2m(2000, BigInteger.valueOf(0L).
                                    setBit(0).setBit(1).setBit(2).
                                    setBit(981).setBit(2000)).hashCode());
}
 
源代码14 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #4 for <code>equals()</code> method.<br>
 *
 * Assertion: pentanomial basis - objects equal if their m, and rp
 * are mutually equal.
 */
public final void testEqualsObject04() {
    ECFieldF2m f1 = new ECFieldF2m(2000, new int[] {981, 2, 1});
    ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L).
            setBit(0).setBit(1).setBit(2).
            setBit(981).setBit(2000));
    assertTrue(f1.equals(f2) && f2.equals(f1));
}
 
源代码15 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #5 for <code>equals()</code> method.<br>
 *
 * Assertion: objects equal if their m, and rp are mutually equal.
 */
public final void testEqualsObject05() {
    ECFieldF2m f1 = new ECFieldF2m(2000);
    ECFieldF2m f2 = new ECFieldF2m(2000, BigInteger.valueOf(0L).
            setBit(0).setBit(1).setBit(2).
            setBit(981).setBit(2000));
    assertFalse(f1.equals(f2) || f2.equals(f1));
}
 
源代码16 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #1 for <code>getMidTermsOfReductionPolynomial()</code> method.<br>
 *
 * Assertion: returns mid terms of reduction polynomial
 */
public final void testGetMidTermsOfReductionPolynomial01() {
    int[] a = new int[] {981,2,1};
    int[] b = new ECFieldF2m(2000,
            BigInteger.valueOf(0L).setBit(0).setBit(1).
            setBit(2).setBit(981).setBit(2000)).
            getMidTermsOfReductionPolynomial();
    assertTrue(Arrays.equals(a, b));
}
 
源代码17 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Tests that object state is preserved against modifications
 * through array reference passed to the constructor.
 */
public final void testIsStatePreserved01() {
    // reference array
    int[] a = new int[] {367};
    // reference array copy
    int[] aCopy = a.clone();
    // create obj using copy
    ECFieldF2m f = new ECFieldF2m(1999, aCopy);
    // modify copy
    aCopy[0] = 5;
    // compare reference with returned array
    assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial()));
}
 
源代码18 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Tests that object state is preserved against
 * modifications through array reference returned by
 * <code>getMidTermsOfReductionPolynomial()</code> method.
 */
public final void testIsStatePreserved02() {
    // reference array
    int[] a = new int[] {981,2,1};
    // reference array copy
    int[] aCopy = a.clone();
    // create obj using copy
    ECFieldF2m f = new ECFieldF2m(2000, aCopy);
    // get array reference and modify returned array
    f.getMidTermsOfReductionPolynomial()[0] = 1532;
    // compare reference with returned for the second time array
    assertTrue(Arrays.equals(a, f.getMidTermsOfReductionPolynomial()));
}
 
源代码19 项目: j2objc   文件: ECParameterSpecTest.java
protected void setUp() throws Exception {
    super.setUp();
    curve = new EllipticCurve(new ECFieldF2m(2), BigInteger.valueOf(1),
            BigInteger.valueOf(1));
    ecpoint = new ECPoint(BigInteger.valueOf(1), BigInteger.valueOf(1));
    ecps = new ECParameterSpec(curve, ecpoint, BigInteger.valueOf(1), 1);
}
 
源代码20 项目: RipplePower   文件: ECPointUtil.java
/**
 * Decode a point on this curve which has been encoded using point
 * compression (X9.62 s 4.2.1 and 4.2.2) or regular encoding.
 * 
 * @param curve
 *            The elliptic curve.
 * @param encoded
 *            The encoded point.
 * @return the decoded point.
 */
public static ECPoint decodePoint(
   EllipticCurve curve, 
   byte[] encoded)
{
    ECCurve c = null;
    
    if (curve.getField() instanceof ECFieldFp)
    {
        c = new ECCurve.Fp(
                ((ECFieldFp)curve.getField()).getP(), curve.getA(), curve.getB());
    }
    else
    {
        int k[] = ((ECFieldF2m)curve.getField()).getMidTermsOfReductionPolynomial();
        
        if (k.length == 3)
        {
            c = new ECCurve.F2m(
                    ((ECFieldF2m)curve.getField()).getM(), k[2], k[1], k[0], curve.getA(), curve.getB());
        }
        else
        {
            c = new ECCurve.F2m(
                    ((ECFieldF2m)curve.getField()).getM(), k[0], curve.getA(), curve.getB());
        }
    }
    
    org.ripple.bouncycastle.math.ec.ECPoint p = c.decodePoint(encoded);

    return new ECPoint(p.getAffineXCoord().toBigInteger(), p.getAffineYCoord().toBigInteger());
}
 
源代码21 项目: RipplePower   文件: ECNamedCurveSpec.java
private static EllipticCurve convertCurve(
    ECCurve  curve,
    byte[]   seed)
{
    if (ECAlgorithms.isFpCurve(curve))
    {
        return new EllipticCurve(new ECFieldFp(curve.getField().getCharacteristic()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
    }
    else
    {
        ECCurve.F2m curveF2m = (ECCurve.F2m)curve;
        int ks[];
        
        if (curveF2m.isTrinomial())
        {
            ks = new int[] { curveF2m.getK1() };
            
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
        }
        else
        {
            ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };

            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
        } 
    }

}
 
源代码22 项目: RipplePower   文件: EC5Util.java
public static EllipticCurve convertCurve(
    ECCurve curve, 
    byte[]  seed)
{
    // TODO: the Sun EC implementation doesn't currently handle the seed properly
    // so at the moment it's set to null. Should probably look at making this configurable
    if (ECAlgorithms.isFpCurve(curve))
    {
        return new EllipticCurve(new ECFieldFp(curve.getField().getCharacteristic()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
    }
    else
    {
        ECCurve.F2m curveF2m = (ECCurve.F2m)curve;
        int ks[];
        
        if (curveF2m.isTrinomial())
        {
            ks = new int[] { curveF2m.getK1() };
            
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
        }
        else
        {
            ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };
            
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
        } 
    }
}
 
源代码23 项目: ripple-lib-java   文件: ECPointUtil.java
/**
 * Decode a point on this curve which has been encoded using point
 * compression (X9.62 s 4.2.1 and 4.2.2) or regular encoding.
 * 
 * @param curve
 *            The elliptic curve.
 * @param encoded
 *            The encoded point.
 * @return the decoded point.
 */
public static ECPoint decodePoint(
   EllipticCurve curve, 
   byte[] encoded)
{
    ECCurve c = null;
    
    if (curve.getField() instanceof ECFieldFp)
    {
        c = new ECCurve.Fp(
                ((ECFieldFp)curve.getField()).getP(), curve.getA(), curve.getB());
    }
    else
    {
        int k[] = ((ECFieldF2m)curve.getField()).getMidTermsOfReductionPolynomial();
        
        if (k.length == 3)
        {
            c = new ECCurve.F2m(
                    ((ECFieldF2m)curve.getField()).getM(), k[2], k[1], k[0], curve.getA(), curve.getB());
        }
        else
        {
            c = new ECCurve.F2m(
                    ((ECFieldF2m)curve.getField()).getM(), k[0], curve.getA(), curve.getB());
        }
    }
    
    org.ripple.bouncycastle.math.ec.ECPoint p = c.decodePoint(encoded);

    return new ECPoint(p.getAffineXCoord().toBigInteger(), p.getAffineYCoord().toBigInteger());
}
 
源代码24 项目: ripple-lib-java   文件: ECNamedCurveSpec.java
private static EllipticCurve convertCurve(
    ECCurve  curve,
    byte[]   seed)
{
    if (ECAlgorithms.isFpCurve(curve))
    {
        return new EllipticCurve(new ECFieldFp(curve.getField().getCharacteristic()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
    }
    else
    {
        ECCurve.F2m curveF2m = (ECCurve.F2m)curve;
        int ks[];
        
        if (curveF2m.isTrinomial())
        {
            ks = new int[] { curveF2m.getK1() };
            
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
        }
        else
        {
            ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };

            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), seed);
        } 
    }

}
 
源代码25 项目: ripple-lib-java   文件: EC5Util.java
public static EllipticCurve convertCurve(
    ECCurve curve, 
    byte[]  seed)
{
    // TODO: the Sun EC implementation doesn't currently handle the seed properly
    // so at the moment it's set to null. Should probably look at making this configurable
    if (ECAlgorithms.isFpCurve(curve))
    {
        return new EllipticCurve(new ECFieldFp(curve.getField().getCharacteristic()), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
    }
    else
    {
        ECCurve.F2m curveF2m = (ECCurve.F2m)curve;
        int ks[];
        
        if (curveF2m.isTrinomial())
        {
            ks = new int[] { curveF2m.getK1() };
            
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
        }
        else
        {
            ks = new int[] { curveF2m.getK3(), curveF2m.getK2(), curveF2m.getK1() };
            
            return new EllipticCurve(new ECFieldF2m(curveF2m.getM(), ks), curve.getA().toBigInteger(), curve.getB().toBigInteger(), null);
        } 
    }
}
 
源代码26 项目: swim   文件: EcCharacteristic2FieldDef.java
public static EcCharacteristic2FieldDef from(ECFieldF2m field) {
  return new EcCharacteristic2FieldDef(field.getM(), field.getReductionPolynomial());
}
 
源代码27 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #3 for <code>getMidTermsOfReductionPolynomial()</code> method.<br>
 *
 * Assertion: returns mid terms of reduction polynomial
 */
public final void testGetMidTermsOfReductionPolynomial03() {
    int[] a = new int[] {367};
    int[] b = new ECFieldF2m(1999, a).getMidTermsOfReductionPolynomial();
    assertTrue(Arrays.equals(a, b));
}
 
源代码28 项目: j2objc   文件: ECFieldF2mTest.java
/**
 * Test #1 for <code>getReductionPolynomial()</code> method.<br>
 *
 * Assertion: returns reduction polynomial
 */
public final void testGetReductionPolynomial01() {
    BigInteger rp = BigInteger.valueOf(0L).setBit(0).setBit(1).setBit(2).
    setBit(981).setBit(2000);
    assertTrue(new ECFieldF2m(2000, rp).getReductionPolynomial().equals(rp));
}
 
源代码29 项目: j2objc   文件: EllipticCurveTest.java
/**
 * Test for <code>getA()</code> method<br>
 * Assertion: returns coefficient <code>a</code><br>
 * Test preconditions: <code>ECFieldF2m</code> instance
 * created using valid parameters<br>
 * Expected: must return coefficient <code>a</code> which is equal
 * to the one passed to the constructor; (both must refer
 * the same object)
 */
public final void testGetA() {
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(5L);
    BigInteger b = BigInteger.valueOf(19L);
    EllipticCurve c = new EllipticCurve(f, a, b);
    assertEquals(a, c.getA());
    assertSame(a, c.getA());
}
 
源代码30 项目: j2objc   文件: EllipticCurveTest.java
/**
 * Test for <code>getB()</code> method<br>
 * Assertion: returns coefficient <code>b</code><br>
 * Test preconditions: <code>ECFieldF2m</code> instance
 * created using valid parameters<br>
 * Expected: must return coefficient <code>b</code> which is equal
 * to the one passed to the constructor; (both must refer
 * the same object)
 */
public final void testGetB() {
    ECFieldF2m f = new ECFieldF2m(5);
    BigInteger a = BigInteger.valueOf(5L);
    BigInteger b = BigInteger.valueOf(19L);
    EllipticCurve c = new EllipticCurve(f, a, b);
    assertEquals(b, c.getB());
    assertSame(b, c.getB());
}