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

2048 prime

parent 2ed3f9b3
Pipeline #21754 failed with stages
in 1 minute and 17 seconds
......@@ -6,35 +6,46 @@ import (
"math/big"
"os"
"strconv"
"github.com/jessevdk/go-flags"
)
var one = big.NewInt(1)
var two = big.NewInt(2)
var opts struct {
Bits int `short:"b" long:"bit" description:"Bit length of prime p" default:"2048"`
}
func main() {
findSafePrimes(16)
findSafePrimes(32)
findSafePrimes(64)
findSafePrimes(128)
findSafePrimes(256)
findSafePrimes(512)
findSafePrimes(1024)
// findGroup()
_, err := flags.Parse(&opts)
if err != nil {
os.Exit(0)
}
findSafePrimes(opts.Bits)
}
func findSafePrimes(bits int) {
one := big.NewInt(1)
two := big.NewInt(2)
i := 1
// Find 4 safe primes
for i := 0; i < 4; i++ {
fmt.Printf("==== %d bits ====\n", bits)
kbits := bits - 1
for n := 0; n < 4; n++ {
q := new(big.Int)
p := new(big.Int)
for !p.ProbablyPrime(20) {
q, _ = rand.Prime(rand.Reader, bits-1)
fmt.Print("\rTry: ", i)
i++
q, _ = rand.Prime(rand.Reader, kbits)
p = p.Mul(q, two).Add(p, one)
}
fmt.Printf("p: %d\nq: %d\n", p, q)
fmt.Printf("\n==== %d bits ====\n", bits)
fmt.Printf("p: %d bits: %x\n", p.BitLen(), p)
fmt.Printf("q: %d bits: %x\n", q.BitLen(), q)
}
}
......
......@@ -7,10 +7,14 @@ import (
// String constants for default primes
const (
p = "3767033279"
q = "1883516639"
// p = "3767033279"
// q = "1883516639"
g = "2"
h = "3"
// 2048 bits
p = "df0df2d4d4320d6f562ddf3ef2ba7b96463e8ba2b6d965a7b377521434dea91ffc299287efc0d495e58fc33cacfc02d2ed819c83bd66b4ebf5373a001adf1b18b0a80c4df6bb372708479c3afa081ae913b99c6b74906b6d497f7752a54869d9542097b98e7373d6643cc3533197ff8160a7d79791ce3e5f53c43a89cf8f4f9fd3afd5cdc6902784daa97715ef73ba8f5d69c2f8e0e901c35917b8d081f38ae07e59df580515fdcb38a718de4c512353658f4e622ed88b7379893907e7d59df22c427f4b04fd0bfbb40e650907c25d61f0cdc7dc2f677841ee06a60ed8206e7ec46684a8716a9470aa19cb221ea1bce00f59067ce4439fd04be0c370e9f3f487"
q = "6f86f96a6a1906b7ab16ef9f795d3dcb231f45d15b6cb2d3d9bba90a1a6f548ffe14c943f7e06a4af2c7e19e567e016976c0ce41deb35a75fa9b9d000d6f8d8c58540626fb5d9b938423ce1d7d040d7489dcce35ba4835b6a4bfbba952a434ecaa104bdcc739b9eb321e61a998cbffc0b053ebcbc8e71f2fa9e21d44e7c7a7cfe9d7eae6e34813c26d54bb8af7b9dd47aeb4e17c707480e1ac8bdc6840f9c5703f2cefac028afee59c538c6f262891a9b2c7a731176c45b9bcc49c83f3eacef916213fa5827e85fdda07328483e12eb0f866e3ee17b3bc20f70353076c10373f6233425438b54a38550ce5910f50de7007ac833e7221cfe825f061b874f9fa43"
)
// Params represents common parameters used by all schemes
......@@ -24,7 +28,7 @@ type Params struct {
}
func parseNumber(number string) *big.Int {
n, success := new(big.Int).SetString(number, 10)
n, success := new(big.Int).SetString(number, 16)
if !success {
panic("Not a decimal number: " + number)
}
......
......@@ -7,8 +7,23 @@ import (
"testing"
)
func parseNumber(number string) *big.Int {
n, success := new(big.Int).SetString(number, 10)
if !success {
panic("Not a decimal number: " + number)
}
return n
}
func TestCommit(t *testing.T) {
commonParams := common.DefaultParams()
commonParams := &common.Params{
P: parseNumber("3767033279"),
Q: parseNumber("1883516639"),
Zp: zn.NewRing(parseNumber("3767033279")),
Zq: zn.NewRing(parseNumber("1883516639")),
G: parseNumber("2"),
H: parseNumber("3"),
}
params := NewParams(commonParams)
commit1 := params.Commit(big.NewInt(4), big.NewInt(5))
......@@ -42,8 +57,8 @@ func TestThresholds(test *testing.T) {
secret := big.NewInt(4567) // Does not matter
binder := params.Zq.GetRandomElement()
fails := 0
for t := 1; t <= 40; t++ {
for n := t; n <= 40; n++ {
for t := 1; t <= 10; t++ {
for n := t; n <= 10; n++ {
shares, proof := params.Create(3, createXS(5), secret, binder)
for i := 0; i < len(shares); i++ {
if !params.Verify(shares[i], proof) {
......
......@@ -81,4 +81,9 @@ p: 16953948252198101681708549705423805342111513706073775900927614214691629937865
q: 84769741260990508408542748527119026710557568530368879504638071073458149689326436480748039491688137093280496350676196825533759814356907538714835582098099395200778305554729347960218770153190064000171702716649426733768953603271894020988626450204540301250475835029972654048957110147558684519802720786355191899873
==== 1024 bits ====
p: 173779796349494458942827608731077624808460138849162074693973749114992328579810372861747290629516444256897767725610719513368076327692911973134845883327439735497007961294351427758873942609833987916072116739363492929851423657394735387676122852234271989650850589395003709409175693859839923221759133518749413372819
q: 86889898174747229471413804365538812404230069424581037346986874557496164289905186430873645314758222128448883862805359756684038163846455986567422941663719867748503980647175713879436971304916993958036058369681746464925711828697367693838061426117135994825425294697501854704587846929919961610879566759374706686409
\ No newline at end of file
q: 868898981747472294714138043655388124042300694245810373469868745574961642899051864308736453147582221284488838628053597566840381638464559865674229416637198677485039806471757138794369713
Try: 503
==== 2048 bits ====
p: 2048 bits: df0df2d4d4320d6f562ddf3ef2ba7b96463e8ba2b6d965a7b377521434dea91ffc299287efc0d495e58fc33cacfc02d2ed819c83bd66b4ebf5373a001adf1b18b0a80c4df6bb372708479c3afa081ae913b99c6b74906b6d497f7752a54869d9542097b98e7373d6643cc3533197ff8160a7d79791ce3e5f53c43a89cf8f4f9fd3afd5cdc6902784daa97715ef73ba8f5d69c2f8e0e901c35917b8d081f38ae07e59df580515fdcb38a718de4c512353658f4e622ed88b7379893907e7d59df22c427f4b04fd0bfbb40e650907c25d61f0cdc7dc2f677841ee06a60ed8206e7ec46684a8716a9470aa19cb221ea1bce00f59067ce4439fd04be0c370e9f3f487
q: 2047 bits: 6f86f96a6a1906b7ab16ef9f795d3dcb231f45d15b6cb2d3d9bba90a1a6f548ffe14c943f7e06a4af2c7e19e567e016976c0ce41deb35a75fa9b9d000d6f8d8c58540626fb5d9b938423ce1d7d040d7489dcce35ba4835b6a4bfbba952a434ecaa104bdcc739b9eb321e61a998cbffc0b053ebcbc8e71f2fa9e21d44e7c7a7cfe9d7eae6e34813c26d54bb8af7b9dd47aeb4e17c707480e1ac8bdc6840f9c5703f2cefac028afee59c538c6f262891a9b2c7a731176c45b9bcc49c83f3eacef916213fa5827e85fdda07328483e12eb0f866e3ee17b3bc20f70353076c10373f6233425438b54a38550ce5910f50de7007ac833e7221cfe825f061b874f9fa43
\ No newline at end of file
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