1package org.bouncycastle.math.ec.custom.sec; 2 3import java.math.BigInteger; 4 5import org.bouncycastle.math.ec.ECConstants; 6import org.bouncycastle.math.ec.ECCurve; 7import org.bouncycastle.math.ec.ECFieldElement; 8import org.bouncycastle.math.ec.ECPoint; 9import org.bouncycastle.util.encoders.Hex; 10 11public class SecP256K1Curve extends ECCurve.AbstractFp 12{ 13 public static final BigInteger q = new BigInteger(1, 14 Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F")); 15 16 private static final int SECP256K1_DEFAULT_COORDS = COORD_JACOBIAN; 17 18 protected SecP256K1Point infinity; 19 20 public SecP256K1Curve() 21 { 22 super(q); 23 24 this.infinity = new SecP256K1Point(this, null, null); 25 26 this.a = fromBigInteger(ECConstants.ZERO); 27 this.b = fromBigInteger(BigInteger.valueOf(7)); 28 this.order = new BigInteger(1, Hex.decode("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141")); 29 this.cofactor = BigInteger.valueOf(1); 30 this.coord = SECP256K1_DEFAULT_COORDS; 31 } 32 33 protected ECCurve cloneCurve() 34 { 35 return new SecP256K1Curve(); 36 } 37 38 public boolean supportsCoordinateSystem(int coord) 39 { 40 switch (coord) 41 { 42 case COORD_JACOBIAN: 43 return true; 44 default: 45 return false; 46 } 47 } 48 49 public BigInteger getQ() 50 { 51 return q; 52 } 53 54 public int getFieldSize() 55 { 56 return q.bitLength(); 57 } 58 59 public ECFieldElement fromBigInteger(BigInteger x) 60 { 61 return new SecP256K1FieldElement(x); 62 } 63 64 protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y, boolean withCompression) 65 { 66 return new SecP256K1Point(this, x, y, withCompression); 67 } 68 69 protected ECPoint createRawPoint(ECFieldElement x, ECFieldElement y, ECFieldElement[] zs, boolean withCompression) 70 { 71 return new SecP256K1Point(this, x, y, zs, withCompression); 72 } 73 74 public ECPoint getInfinity() 75 { 76 return infinity; 77 } 78} 79