本文整理汇总了Java中java.security.spec.ECFieldF2m类的典型用法代码示例。如果您正苦于以下问题:Java ECFieldF2m类的具体用法?Java ECFieldF2m怎么用?Java ECFieldF2m使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ECFieldF2m类属于java.security.spec包,在下文中一共展示了ECFieldF2m类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: convertCurve
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
public static ECCurve convertCurve(
EllipticCurve ec)
{
ECField field = ec.getField();
BigInteger a = ec.getA();
BigInteger b = ec.getB();
if (field instanceof ECFieldFp)
{
return new ECCurve.Fp(((ECFieldFp)field).getP(), a, b);
}
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);
}
}
示例2: convertCurve
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
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);
}
}
示例3: testECFieldF2mint
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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);
}
}
}
}
示例4: testECFieldF2mintintArray
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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);
}
}
}
}
示例5: testECFieldF2mintBigInteger
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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);
}
}
}
}
示例6: testEllipticCurveECFieldBigIntegerBigIntegerbyteArray05
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "Verifies that byte array of EllipticCurve can't be modified",
method = "EllipticCurve",
args = {java.security.spec.ECField.class, java.math.BigInteger.class, java.math.BigInteger.class, byte[].class}
)
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()));
}
示例7: testHashCode01
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* Test #1 for <code>hashCode()</code> method.<br>
*
* Assertion: must return the same value if invoked
* repeatedly on the same object.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "hashCode",
args = {}
)
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());
}
示例8: testHashCode02
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* Test #2 for <code>hashCode()</code> method.<br>
*
* Assertion: must return the same value if invoked
* repeatedly on the same object.
*/
@TestTargetNew(
level = TestLevel.PARTIAL_COMPLETE,
notes = "",
method = "hashCode",
args = {}
)
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());
}
示例9: testIsStatePreserved01
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* Tests that object state is preserved against modifications
* through array reference passed to the constructor.
*/
@TestTargetNew(
level = TestLevel.PARTIAL,
notes = "Verifies that object state is preserved against modifications through array reference passed to the constructor.",
method = "ECFieldF2m",
args = {int.class, int[].class}
)
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()));
}
示例10: testECFieldF2mint
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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);
}
}
}
}
示例11: testECFieldF2mintintArray
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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<intIntArrayCtorTestParameters.length; i++) {
ECFieldF2mDomainParams tp = intIntArrayCtorTestParameters[i];
try {
// perform 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);
}
}
}
}
示例12: testECFieldF2mintBigInteger
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* Tests for constructor <code>ECFieldF2m(int, BigInteger)</code><br>
*
* Assertion: constructs new <code>ECFieldF2m</code> object
* using valid parameters m and rp. rp represents trinomial basis.
*
* Assertion: constructs new <code>ECFieldF2m</code> object
* using valid parameters m and rp. rp represents pentanomial basis.
*
* 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<intBigIntegerCtorTestParameters.length; i++) {
ECFieldF2mDomainParams tp = intBigIntegerCtorTestParameters[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);
}
}
}
}
示例13: initKey
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 初始化密钥
*
* @return
* @throws Exception
*/
public static Map<String, Object> initKey() throws Exception {
BigInteger x1 = new BigInteger(
"2fe13c0537bbc11acaa07d793de4e6d5e5c94eee8", 16);
BigInteger x2 = new BigInteger(
"289070fb05d38ff58321f2e800536d538ccdaa3d9", 16);
ECPoint g = new ECPoint(x1, x2);
// the order of generator
BigInteger n = new BigInteger(
"5846006549323611672814741753598448348329118574063", 10);
// the cofactor
int h = 2;
int m = 163;
int[] ks = { 7, 6, 3 };
ECFieldF2m ecField = new ECFieldF2m(m, ks);
// y^2+xy=x^3+x^2+1
BigInteger a = new BigInteger("1", 2);
BigInteger b = new BigInteger("1", 2);
EllipticCurve ellipticCurve = new EllipticCurve(ecField, a, b);
ECParameterSpec ecParameterSpec = new ECParameterSpec(ellipticCurve, g,
n, h);
// 公钥
ECPublicKey publicKey = new ECPublicKeyImpl(g, ecParameterSpec);
BigInteger s = new BigInteger(
"1234006549323611672814741753598448348329118574063", 10);
// 私钥
ECPrivateKey privateKey = new ECPrivateKeyImpl(s, ecParameterSpec);
Map<String, Object> keyMap = new HashMap<String, Object>(2);
keyMap.put(PUBLIC_KEY, publicKey);
keyMap.put(PRIVATE_KEY, privateKey);
return keyMap;
}
示例14: decodePoint
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
/**
* 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.bouncycastle.math.ec.ECPoint p = c.decodePoint(encoded);
return new ECPoint(p.getX().toBigInteger(), p.getY().toBigInteger());
}
示例15: convertCurve
import java.security.spec.ECFieldF2m; //导入依赖的package包/类
private static EllipticCurve convertCurve(
ECCurve curve,
byte[] seed)
{
if (curve instanceof ECCurve.Fp)
{
return new EllipticCurve(new ECFieldFp(((ECCurve.Fp)curve).getQ()), 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);
}
}
}