-
Notifications
You must be signed in to change notification settings - Fork 230
Expand file tree
/
Copy pathecc_field.go
More file actions
137 lines (129 loc) · 4.85 KB
/
Copy pathecc_field.go
File metadata and controls
137 lines (129 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// Copyright 2020-2026 Consensys Software Inc.
// Licensed under the Apache License, Version 2.0. See the LICENSE file for details.
// Code generated by consensys/gnark-crypto DO NOT EDIT
package ecc
import (
"errors"
"math/big"
"strings"
)
var mID = map[string]ID{
"bls12_377": BLS12_377,
"bls12_381": BLS12_381,
"bls24_315": BLS24_315,
"bls24_317": BLS24_317,
"bn254": BN254,
"bw6_633": BW6_633,
"bw6_761": BW6_761,
"grumpkin": GRUMPKIN,
"kb8": KB8,
"secp256k1": SECP256K1,
"secp256r1": SECP256R1,
"stark_curve": STARK_CURVE,
}
// ScalarField returns the scalar field of the curve
func (id ID) ScalarField() *big.Int {
f := new(big.Int)
switch id {
case BLS12_377:
f.SetString("8444461749428370424248824938781546531375899335154063827935233455917409239041", 10)
case BLS12_381:
f.SetString("52435875175126190479447740508185965837690552500527637822603658699938581184513", 10)
case BLS24_315:
f.SetString("11502027791375260645628074404575422495959608200132055716665986169834464870401", 10)
case BLS24_317:
f.SetString("30869589236456844204538189757527902584594726589286811523515204428962673459201", 10)
case BN254:
f.SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
case BW6_633:
f.SetString("39705142709513438335025689890408969744933502416914749335064285505637884093126342347073617133569", 10)
case BW6_761:
f.SetString("258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177", 10)
case GRUMPKIN:
f.SetString("21888242871839275222246405745257275088696311157297823662689037894645226208583", 10)
case KB8:
f.SetString("424804331891979973455971894938199991839487883914575852667663156896715214921", 10)
case SECP256K1:
f.SetString("115792089237316195423570985008687907852837564279074904382605163141518161494337", 10)
case SECP256R1:
f.SetString("115792089210356248762697446949407573529996955224135760342422259061068512044369", 10)
case STARK_CURVE:
f.SetString("3618502788666131213697322783095070105526743751716087489154079457884512865583", 10)
default:
panic("unimplemented ecc ID")
}
return f
}
// BaseField returns the base field of the curve
func (id ID) BaseField() *big.Int {
f := new(big.Int)
switch id {
case BLS12_377:
f.SetString("258664426012969094010652733694893533536393512754914660539884262666720468348340822774968888139573360124440321458177", 10)
case BLS12_381:
f.SetString("4002409555221667393417789825735904156556882819939007885332058136124031650490837864442687629129015664037894272559787", 10)
case BLS24_315:
f.SetString("39705142709513438335025689890408969744933502416914749335064285505637884093126342347073617133569", 10)
case BLS24_317:
f.SetString("136393071104295911515099765908274057061945112121419593977210139303905973197232025618026156731051", 10)
case BN254:
f.SetString("21888242871839275222246405745257275088696311157297823662689037894645226208583", 10)
case BW6_633:
f.SetString("20494478644167774678813387386538961497669590920908778075528754551012016751717791778743535050360001387419576570244406805463255765034468441182772056330021723098661967429339971741066259394985997", 10)
case BW6_761:
f.SetString("6891450384315732539396789682275657542479668912536150109513790160209623422243491736087683183289411687640864567753786613451161759120554247759349511699125301598951605099378508850372543631423596795951899700429969112842764913119068299", 10)
case GRUMPKIN:
f.SetString("21888242871839275222246405745257275088548364400416034343698204186575808495617", 10)
case KB8:
f.SetString("2130706433", 10)
case SECP256K1:
f.SetString("115792089237316195423570985008687907853269984665640564039457584007908834671663", 10)
case SECP256R1:
f.SetString("115792089210356248762697446949407573530086143415290314195533631308867097853951", 10)
case STARK_CURVE:
f.SetString("3618502788666131213697322783095070105623107215331596699973092056135872020481", 10)
default:
panic("unimplemented ecc ID")
}
return f
}
// String returns the string representation of the ID
func (id ID) String() string {
switch id {
case BLS12_377:
return "bls12_377"
case BLS12_381:
return "bls12_381"
case BLS24_315:
return "bls24_315"
case BLS24_317:
return "bls24_317"
case BN254:
return "bn254"
case BW6_633:
return "bw6_633"
case BW6_761:
return "bw6_761"
case GRUMPKIN:
return "grumpkin"
case KB8:
return "kb8"
case SECP256K1:
return "secp256k1"
case SECP256R1:
return "secp256r1"
case STARK_CURVE:
return "stark_curve"
default:
panic("unimplemented ecc ID")
}
}
// IDFromString returns the ID corresponding to the string representation of the curve ID.
// It returns UNKNOWN if the string does not match any known curve ID.
func IDFromString(s string) (ID, error) {
s = strings.ToLower(s)
if id, ok := mID[s]; ok {
return id, nil
}
return UNKNOWN, errors.New("unknown curve ID")
}