Two common curves used in ECC (Elliptic Curve Cryptography) are secp256k1 (as used in Bitcoin and Ethereum) and P256 (secp256r1). The "k1" refers to the Kolbitz curve 1 (named after the creator of ECC). With these we have a base point which are can operate on. This is typically defined as \(G\). We can then operate on this with add and multiply operation. For example, \(2G=G+G\) and \(P=n.G\). In this following we will show the base point for a number of common curves, such as secp256r1, P256, Pallas, Curve 25519, BLS12381G1, BLS12381G2, BLS12377G1 and BLS12377G2.
Elliptic Curve Points (Base Point and Others) |
Method
Two common curves used in ECC (Elliptic Curve Cryptography) are secp256k1 (as used in Bitcoin and Ethereum) and P256 (secp256r1). The "k1" refers to the Kolbitz curve 1 (named after the creator of ECC). With these we have a base point which are can operate on. This is typically defined as \(G\). We can then operate on this with add and multiply operation. For example, \(2G=G+G\) and \(P=n.G\). In this following we will show the base point for a number of common curves, such as secp256r1, P256, Pallas, Curve 25519, BLS12381G1, BLS12381G2, BLS12377G1 and BLS12377G2.
Coding
The outline code is:
package main import ( "math/big" "crypto/rand" "fmt" "os" "github.com/coinbase/kryptology/pkg/core/curves" ) func main() { ctype:="0" curve := curves.K256() argCount := len(os.Args[1:]) if (argCount>0) {ctype = string(os.Args[1])} if (ctype=="1") { curve = curves.P256() } if (ctype=="2") { curve = curves.ED25519() } if (ctype=="3") { curve = curves.PALLAS() } if (ctype=="4") { curve = curves.BLS12381G1() } if (ctype=="5") { curve = curves.BLS12381G2() } if (ctype=="6") { curve = curves.BLS12377G1() } if (ctype=="7") { curve = curves.BLS12377G2() } G := curve.Point.Generator() fmt.Printf("Curve= %s\n", G.CurveName()) fmt.Printf("\nUncompressed Base Point (G)= %x\n", G.ToAffineUncompressed()) fmt.Printf("Compressed Base Point (G)= %x\n", G.ToAffineCompressed()) lenb := len(G.ToAffineUncompressed()) Gx := G.ToAffineUncompressed()[1 : lenb/2+1] Gy := G.ToAffineUncompressed()[lenb/2+1 : lenb] fmt.Printf("\n--- Basic point operation ---\n") fmt.Printf("G(x,y)=%x, %x\n", Gx, Gy) fmt.Printf("G(x,y)=%d, %d\n", new(big.Int).SetBytes(Gx), new(big.Int).SetBytes(Gy)) n:=curve.Scalar.New(1) P1:=G.Mul(n) fmt.Printf("\nP1=1.G= %x\n", P1.ToAffineUncompressed()) n=curve.Scalar.New(-1) P2:=G.Mul(n) fmt.Printf("\nP2=-1.G= %x\n", P2.ToAffineUncompressed()) n=curve.Scalar.New(2) P3:=G.Mul(n) fmt.Printf("\nP3=2.G= %x\n", P3.ToAffineUncompressed()) P4:=P1.Add(P2) fmt.Printf("\nP4=P1+P2= %x\n", P4.ToAffineUncompressed()) P5:=P1.Add(P3) fmt.Printf("\nP5=P1+P3= %x\n", P5.ToAffineUncompressed()) n = curve.Scalar.Random(rand.Reader) P6:=G.Mul(n) fmt.Printf("n (random)= %x\n", n.Bytes()) fmt.Printf("\nP6=n.G= %x\n", P6.ToAffineUncompressed()) }
A sample run for secp256k1 gives:
Curve= secp256k1 Uncompressed Base Point (G)= 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 Compressed Base Point (G)= 0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798 --- Basic point operation --- G(x,y)=79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798, 483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 G(x,y)=55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424 P1=1.G= 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8 P2=-1.G= 0479be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798b7c52588d95c3b9aa25b0403f1eef75702e84bb7597aabe663b82f6f04ef2777 P3=2.G= 04c6047f9441ed7d6d3045406e95c07cd85c778e4b8cef3ca7abac09b95c709ee51ae168fea63dc339a3c58419466ceaeef7f632653266d0e1236431a950cfe52a P4=P1+P2= 0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 P5=P1+P3= 04f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672 n (random)= c60a9c68a89f9fd7ce26e26cbdc1445d61e69eebef808ab0840db180cdd76157 P6=n.G= 04da4b3340fb70983feddffc577eee6be9ef456a20ace4aa0bfc4b852459138ffde251d7d2c7cc6067ae97d225d7eee7d9c89046032aa52ce09c4cb02f20417592
With this we can see that the generator point for sepc256k1 is (55066263022277343669578718895168534326250603453777594175500187360389116729240, 32670510020758816978083085130507043184471273380659243275938904335757337482424)
For P256 we get:
Curve= P-256 Uncompressed Base Point (G)= 046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c2964fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5 Compressed Base Point (G)= 036b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296 --- Basic point operation --- G(x,y)=6b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296, 4fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5 G(x,y)=48439561293906451759052585252797914202762949526041747995844080717082404635286, 36134250956749795798585127919587881956611106672985015071877198253568414405109 P1=1.G= 046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c2964fe342e2fe1a7f9b8ee7eb4a7c0f9e162bce33576b315ececbb6406837bf51f5 P2=-1.G= 046b17d1f2e12c4247f8bce6e563a440f277037d812deb33a0f4a13945d898c296b01cbd1c01e58065711814b583f061e9d431cca994cea1313449bf97c840ae0a P3=2.G= 047cf27b188d034f7e8a52380304b51ac3c08969e277f21b35a60b48fc4766997807775510db8ed040293d9ac69f7430dbba7dade63ce982299e04b79d227873d1 P4=P1+P2= 0400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 P5=P1+P3= 045ecbe4d1a6330a44c8f7ef951d4bf165e6c6b721efada985fb41661bc6e7fd6c8734640c4998ff7e374b06ce1a64a2ecd82ab036384fb83d9a79b127a27d5032 n (random)= be6d9828312aa30d8b8a9d98c7c9bb311b2f94f914b4f35ae652de659aef8a65 P6=n.G= 047d682731d045e7c795fc7282ed95a6cfe09a7711597e491f9d5e4c72eaed90be7d530c1ad40dddaa53494cae1497a8525bdfaaa8f0166c6bd3ed01673eb88aca
If we try P256, we get a generator point of (48439561293906451759052585252797914202762949526041747995844080717082404635286, 36134250956749795798585127919587881956611106672985015071877198253568414405109)