Java Code Examples for org.spongycastle.math.ec.ECPoint#isInfinity()
The following examples show how to use
org.spongycastle.math.ec.ECPoint#isInfinity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HdPublicKey.java From ontology-java-sdk with GNU Lesser General Public License v3.0 | 5 votes |
@Override public HdPublicKey cKDpub(final int index) { if (isHardened(index)) { return null; } final HdKey parent = this.hdKey; final byte[] kPar = parent.getKey(); final byte[] data = new byte[37]; final ByteArrayWriter writer = new ByteArrayWriter(data); writer.concat(kPar, 33); writer.concatSer32(index); final byte[] I = Digest.hmacSha512(parent.getChainCode(), data); final byte[] Il = head32(I); final byte[] Ir = tail32(I); final BigInteger parse256_Il = parse256(Il); final ECPoint ki = gMultiplyAndAddPoint(parse256_Il, kPar); if (parse256_Il.compareTo(n()) >= 0 || ki.isInfinity()) { return cKDpub(index + 1); } final byte[] key = pointSerP(ki); return new HdPublicKey(new HdKey.Builder() .network(parent.getNetwork()) .neutered(true) .depth(parent.depth() + 1) .parentFingerprint(parent.calculateFingerPrint()) .key(key) .chainCode(Ir) .childNumber(index) .build()); }
Example 2
Source File: EOSECDSASigner.java From token-core-android with Apache License 2.0 | 5 votes |
/** * return true if the value r and s represent a DSA signature for * the passed in message (for standard DSA the message should be * a SHA-1 hash of the real message to be verified). */ public boolean verifySignature( byte[] message, BigInteger r, BigInteger s) { ECDomainParameters ec = key.getParameters(); BigInteger n = ec.getN(); BigInteger e = calculateE(n, message); // r in the range [1,n-1] if (r.compareTo(ONE) < 0 || r.compareTo(n) >= 0) { return false; } // s in the range [1,n-1] if (s.compareTo(ONE) < 0 || s.compareTo(n) >= 0) { return false; } BigInteger c = s.modInverse(n); BigInteger u1 = e.multiply(c).mod(n); BigInteger u2 = r.multiply(c).mod(n); ECPoint G = ec.getG(); ECPoint Q = ((ECPublicKeyParameters) key).getQ(); ECPoint point = ECAlgorithms.sumOfTwoMultiplies(G, u1, Q, u2).normalize(); // components must be bogus. if (point.isInfinity()) { return false; } BigInteger v = point.getAffineXCoord().toBigInteger().mod(n); return v.equals(r); }
Example 3
Source File: ExtendedPublicKey.java From dapp-wallet-demo with Apache License 2.0 | 5 votes |
@Override public ExtendedPublicKey cKDpub(final int index) { if (isHardened(index)) throw new IllegalCKDCall("Cannot derive a hardened key from a public key"); final HdKey parent = this.hdKey; final byte[] kPar = parent.getKey(); final byte[] data = new byte[37]; final ByteArrayWriter writer = new ByteArrayWriter(data); writer.concat(kPar, 33); writer.concatSer32(index); final byte[] I = hmacSha512(parent.getChainCode(), data); final byte[] Il = head32(I); final byte[] Ir = tail32(I); final BigInteger parse256_Il = parse256(Il); final ECPoint ki = gMultiplyAndAddPoint(parse256_Il, kPar); if (parse256_Il.compareTo(n()) >= 0 || ki.isInfinity()) { return cKDpub(index + 1); } final byte[] key = pointSerP(ki); return new ExtendedPublicKey(new HdKey.Builder() .network(parent.getNetwork()) .neutered(true) .depth(parent.depth() + 1) .parentFingerprint(parent.calculateFingerPrint()) .key(key) .chainCode(Ir) .childNumber(index) .build()); }