本文整理汇总了Java中org.bouncycastle.math.ec.custom.sec.SecP256K1Curve类的典型用法代码示例。如果您正苦于以下问题:Java SecP256K1Curve类的具体用法?Java SecP256K1Curve怎么用?Java SecP256K1Curve使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecP256K1Curve类属于org.bouncycastle.math.ec.custom.sec包,在下文中一共展示了SecP256K1Curve类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: createParameters
import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve; //导入依赖的package包/类
protected X9ECParameters createParameters()
{
byte[] S = null;
GLVTypeBParameters glv = new GLVTypeBParameters(
new BigInteger("7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee", 16),
new BigInteger("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72", 16),
new BigInteger[]{
new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16),
new BigInteger("-e4437ed6010e88286f547fa90abfe4c3", 16) },
new BigInteger[]{
new BigInteger("114ca50f7a8e2f3f657c1108d9d44cfd8", 16),
new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16) },
new BigInteger("3086d221a7d46bcde86c90e49284eb153dab", 16),
new BigInteger("e4437ed6010e88286f547fa90abfe4c42212", 16),
272);
ECCurve curve = configureCurveGLV(new SecP256K1Curve(), glv);
X9ECPoint G = new X9ECPoint(curve, Hex.decode("04"
+ "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
+ "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));
return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S);
}
开发者ID:ttt43ttt,项目名称:gwt-crypto,代码行数:22,代码来源:CustomNamedCurves.java
示例2: createParameters
import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve; //导入依赖的package包/类
protected X9ECParameters createParameters()
{
byte[] S = null;
GLVTypeBParameters glv = new GLVTypeBParameters(
new BigInteger("7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee", 16),
new BigInteger("5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72", 16),
new BigInteger[]{
new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16),
new BigInteger("-e4437ed6010e88286f547fa90abfe4c3", 16) },
new BigInteger[]{
new BigInteger("114ca50f7a8e2f3f657c1108d9d44cfd8", 16),
new BigInteger("3086d221a7d46bcde86c90e49284eb15", 16) },
new BigInteger("3086d221a7d46bcde86c90e49284eb153dab", 16),
new BigInteger("e4437ed6010e88286f547fa90abfe4c42212", 16),
272);
ECCurve curve = configureCurveGLV(new SecP256K1Curve(), glv);
ECPoint G = curve.decodePoint(Hex.decode("04"
+ "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
+ "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));
return new X9ECParameters(curve, G, curve.getOrder(), curve.getCofactor(), S);
}
开发者ID:redfish64,项目名称:TinyTravelTracker,代码行数:22,代码来源:CustomNamedCurves.java
示例3: decompressKey
import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve; //导入依赖的package包/类
/**
* Decompress a compressed public key (x coordinate and low-bit of y-coordinate).
*
* @param xBN X-coordinate
* @param yBit Sign of Y-coordinate
* @return Uncompressed public key
*/
private static ECPoint decompressKey(BigInteger xBN, boolean yBit) {
SecP256K1Curve curve = (SecP256K1Curve)ecParams.getCurve();
ECFieldElement x = curve.fromBigInteger(xBN);
ECFieldElement alpha = x.multiply(x.square().add(curve.getA())).add(curve.getB());
ECFieldElement beta = alpha.sqrt();
if (beta == null)
throw new IllegalArgumentException("Invalid point compression");
ECPoint ecPoint;
BigInteger nBeta = beta.toBigInteger();
if (nBeta.testBit(0) == yBit) {
ecPoint = curve.createPoint(x.toBigInteger(), nBeta);
} else {
ECFieldElement y = curve.fromBigInteger(curve.getQ().subtract(nBeta));
ecPoint = curve.createPoint(x.toBigInteger(), y.toBigInteger());
}
return ecPoint;
}
开发者ID:ScripterRon,项目名称:BitcoinCore,代码行数:25,代码来源:ECKey.java
示例4: recoverFromSignature
import org.bouncycastle.math.ec.custom.sec.SecP256K1Curve; //导入依赖的package包/类
/**
* <p>Given the components of a signature and a selector value, recover and return the public key
* that generated the signature according to the algorithm in SEC1v2 section 4.1.6.</p>
*
* <p>The recID is an index from 0 to 3 which indicates which of the 4 possible keys is the correct one.
* Because the key recovery operation yields multiple potential keys, the correct key must either be
* stored alongside the signature, or you must be willing to try each recId in turn until you find one
* that outputs the key you are expecting.</p>
*
* <p>If this method returns null, it means recovery was not possible and recID should be iterated.</p>
*
* <p>Given the above two points, a correct usage of this method is inside a for loop from 0 to 3, and if the
* output is null OR a key that is not the one you expect, you try again with the next recID.</p>
*
* @param recID Which possible key to recover.
* @param sig R and S components of the signature
* @param e The double SHA-256 hash of the original message
* @param compressed Whether or not the original public key was compressed
* @return An ECKey containing only the public part, or null if recovery wasn't possible
*/
private static ECKey recoverFromSignature(int recID, ECDSASignature sig, BigInteger e, boolean compressed) {
BigInteger n = ecParams.getN();
BigInteger i = BigInteger.valueOf((long)recID / 2);
BigInteger x = sig.getR().add(i.multiply(n));
//
// Convert the integer x to an octet string X of length mlen using the conversion routine
// specified in Section 2.3.7, where mlen = ⌈(log2 p)/8⌉ or mlen = ⌈m/8⌉.
// Convert the octet string (16 set binary digits)||X to an elliptic curve point R using the
// conversion routine specified in Section 2.3.4. If this conversion routine outputs 'invalid', then
// do another iteration.
//
// More concisely, what these points mean is to use X as a compressed public key.
//
SecP256K1Curve curve = (SecP256K1Curve)ecParams.getCurve();
BigInteger prime = curve.getQ();
if (x.compareTo(prime) >= 0) {
return null;
}
//
// Compressed keys require you to know an extra bit of data about the y-coordinate as
// there are two possibilities. So it's encoded in the recID.
//
ECPoint R = decompressKey(x, (recID & 1) == 1);
if (!R.multiply(n).isInfinity())
return null;
//
// For k from 1 to 2 do the following. (loop is outside this function via iterating recId)
// Compute a candidate public key as:
// Q = mi(r) * (sR - eG)
//
// Where mi(x) is the modular multiplicative inverse. We transform this into the following:
// Q = (mi(r) * s ** R) + (mi(r) * -e ** G)
// Where -e is the modular additive inverse of e, that is z such that z + e = 0 (mod n).
// In the above equation, ** is point multiplication and + is point addition (the EC group operator).
//
// We can find the additive inverse by subtracting e from zero then taking the mod. For example the additive
// inverse of 3 modulo 11 is 8 because 3 + 8 mod 11 = 0, and -3 mod 11 = 8.
//
BigInteger eInv = BigInteger.ZERO.subtract(e).mod(n);
BigInteger rInv = sig.getR().modInverse(n);
BigInteger srInv = rInv.multiply(sig.getS()).mod(n);
BigInteger eInvrInv = rInv.multiply(eInv).mod(n);
ECPoint q = ECAlgorithms.sumOfTwoMultiplies(ecParams.getG(), eInvrInv, R, srInv);
return new ECKey(q.getEncoded(compressed));
}
开发者ID:ScripterRon,项目名称:BitcoinCore,代码行数:66,代码来源:ECKey.java
注:本文中的org.bouncycastle.math.ec.custom.sec.SecP256K1Curve类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论