Commit 49664704 authored by Anders Jensen Løvig's avatar Anders Jensen Løvig
Browse files

Benchmark primes

parent 60d26dc2
Pipeline #21991 passed with stages
in 1 minute and 40 seconds
......@@ -16,6 +16,9 @@ const (
// p = "113725176798010050451165288258759946268131239693032262275611886693367245547103"
// q = "56862588399005025225582644129379973134065619846516131137805943346683622773551"
// p = "C047"
// q = "6023"
// 2048 bits
p = "df0df2d4d4320d6f562ddf3ef2ba7b96463e8ba2b6d965a7b377521434dea91ffc299287efc0d495e58fc33cacfc02d2ed819c83bd66b4ebf5373a001adf1b18b0a80c4df6bb372708479c3afa081ae913b99c6b74906b6d497f7752a54869d9542097b98e7373d6643cc3533197ff8160a7d79791ce3e5f53c43a89cf8f4f9fd3afd5cdc6902784daa97715ef73ba8f5d69c2f8e0e901c35917b8d081f38ae07e59df580515fdcb38a718de4c512353658f4e622ed88b7379893907e7d59df22c427f4b04fd0bfbb40e650907c25d61f0cdc7dc2f677841ee06a60ed8206e7ec46684a8716a9470aa19cb221ea1bce00f59067ce4439fd04be0c370e9f3f487"
q = "6f86f96a6a1906b7ab16ef9f795d3dcb231f45d15b6cb2d3d9bba90a1a6f548ffe14c943f7e06a4af2c7e19e567e016976c0ce41deb35a75fa9b9d000d6f8d8c58540626fb5d9b938423ce1d7d040d7489dcce35ba4835b6a4bfbba952a434ecaa104bdcc739b9eb321e61a998cbffc0b053ebcbc8e71f2fa9e21d44e7c7a7cfe9d7eae6e34813c26d54bb8af7b9dd47aeb4e17c707480e1ac8bdc6840f9c5703f2cefac028afee59c538c6f262891a9b2c7a731176c45b9bcc49c83f3eacef916213fa5827e85fdda07328483e12eb0f866e3ee17b3bc20f70353076c10373f6233425438b54a38550ce5910f50de7007ac833e7221cfe825f061b874f9fa43"
......@@ -31,8 +34,8 @@ type Params struct {
H *big.Int // Generator for subgroup G of order q in Zp
}
func ParseNumber(number string) *big.Int {
n, success := new(big.Int).SetString(number, 16)
func ParseNumber(number string, base int) *big.Int {
n, success := new(big.Int).SetString(number, base)
if !success {
panic("Not a decimal number: " + number)
}
......@@ -41,19 +44,23 @@ func ParseNumber(number string) *big.Int {
// DefaultParams returns the default parameters
func DefaultParams() *Params {
p := ParseNumber(p)
return NewParams(p, q, g, h, 16)
}
func NewParams(pStr, qStr, gStr, hStr string, base int) *Params {
p := ParseNumber(pStr, base)
if !p.ProbablyPrime(20) {
panic("p is not prime")
}
q := ParseNumber(q)
q := ParseNumber(qStr, base)
if !q.ProbablyPrime(20) {
panic("p is not prime")
}
zp := zn.NewRing(p)
zq := zn.NewRing(q)
g := ParseNumber(g)
h := ParseNumber(h)
g := ParseNumber(gStr, base)
h := ParseNumber(hStr, base)
if zp.Exp(g, q).Cmp(big.NewInt(1)) != 0 {
panic("g is not a generator for Gq")
......
......@@ -174,7 +174,6 @@ func (box *BallotBox) Tally(filter []uuid.UUID) *Tally {
log.Printf("Election: processed %d ballots with %d/%d valid", valids, valids, size)
params := pedersen.NewParams(box.params)
return newTally(params.AddShares(shares), params.MulProofs(commits))
}
......
......@@ -35,35 +35,7 @@ func benchConfig() *common.Params {
}
func createConfig(p, q string) *common.Params {
P := common.ParseNumber(p)
if !P.ProbablyPrime(20) {
panic("p is not prime")
}
Q := common.ParseNumber(q)
if !Q.ProbablyPrime(20) {
panic("p is not prime")
}
zp := zn.NewRing(P)
zq := zn.NewRing(Q)
g := common.ParseNumber("2")
h := common.ParseNumber("3")
if zp.Exp(g, Q).Cmp(big.NewInt(1)) != 0 {
panic("g is not a generator for Gq")
}
if zp.Exp(h, Q).Cmp(big.NewInt(1)) != 0 {
panic("h is not a generator for Gq")
}
return &common.Params{
P: P,
Q: Q,
Zp: zp,
Zq: zq,
G: g,
H: h,
}
return common.NewParams(p, q, "2", "3", 16)
}
func setupVote(votecount int) []*big.Int {
......@@ -364,8 +336,8 @@ func BenchmarkClientConfig(b *testing.B) {
"6BA489FD79FCB277")
b.Run(" 64-bit", func(b *testing.B) { benchmarkBallots(config, 10, 17, 9, b) })
config = createConfig(
"EBDD3B1ADF5E595C977667F3CBDECD13",
"75EE9D8D6FAF2CAE4BBB33F9E5EF6689")
"F213D1D3FCB695A327DACA080380F5B7",
"7909E8E9FE5B4AD193ED650401C07ADB")
b.Run("128-bit", func(b *testing.B) { benchmarkBallots(config, 10, 17, 9, b) })
config = createConfig(
"FB6E2B44AC03CE014942C38631E31810C18B97B8C1110DB6DC698CB71AE9A65F",
......@@ -381,8 +353,8 @@ func BenchmarkTallyConfig(b *testing.B) {
log.SetOutput(ioutil.Discard)
//var config *common.Params
config := createConfig(
"E2D3",
"7169")
"C047",
"6023")
b.Run(" 16-bit", func(b *testing.B) { benchmarkTally(config, 10, 17, 9, b) })
config = createConfig(
"E0885DBF",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment