![JAR search and dependency download from the Maven repository](/logo.png)
com.jingtum.core.crypto.ecdsa.SECP256K1 Maven / Gradle / Ivy
The newest version!
/*
* Copyright www.jingtum.com Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.jingtum.core.crypto.ecdsa;
import org.bouncycastle.crypto.params.ECDomainParameters;
import org.bouncycastle.math.ec.ECConstants;
import org.bouncycastle.math.ec.ECCurve;
import org.bouncycastle.math.ec.ECPoint;
import org.bouncycastle.util.encoders.Hex;
import java.math.BigInteger;
public class SECP256K1 {
private static final ECDomainParameters params;
static {
params = createParameters();
}
private static BigInteger fromHex(
String hex)
{
return new BigInteger(1, Hex.decode(hex));
}
public static BigInteger order() {
return params.getN();
}
public static ECPoint basePoint() {
return params.getG();
}
static byte[] basePointMultipliedBy(BigInteger secret) {
return basePoint().multiply(secret).getEncoded(true);
}
private static ECDomainParameters createParameters()
{
// p = 2^256 - 2^32 - 2^9 - 2^8 - 2^7 - 2^6 - 2^4 - 1
BigInteger p = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F");
BigInteger a = ECConstants.ZERO;
BigInteger b = BigInteger.valueOf(7);
byte[] S = null;
BigInteger n = fromHex("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141");
BigInteger h = BigInteger.valueOf(1);
ECCurve curve = new ECCurve.Fp(p, a, b);
ECPoint G = curve.decodePoint(Hex.decode("04"
+ "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798"
+ "483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8"));
return new ECDomainParameters(curve, G, n, h, S);
}
public static ECDomainParameters params() {
return params;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy