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