This repository has been archived by the owner on Oct 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from ldsec/dev
MedCo v0.3.0
- Loading branch information
Showing
22 changed files
with
1,304 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"github.com/urfave/cli" | ||
"go.dedis.ch/kyber/v3" | ||
"go.dedis.ch/kyber/v3/suites" | ||
"go.dedis.ch/onet/v3/log" | ||
"os" | ||
"strconv" | ||
) | ||
|
||
func mappingTableGenFromApp(c *cli.Context) error { | ||
|
||
var PointToInt = make(map[string]int64, 0) | ||
var suite = suites.MustFind("Ed25519") | ||
|
||
// cli arguments | ||
outputFile := c.String("outputFile") // mandatory | ||
outputFormat := c.String("outputFormat") // typescript | ||
nbMappings := c.Int64("nbMappings") // optional default to 1000 | ||
checkNeg := c.Bool("checkNeg") // optional default to false | ||
|
||
var Bi kyber.Point | ||
B := suite.Point().Base() | ||
var m int64 | ||
|
||
// generate mapping in memory | ||
for Bi, m = suite.Point().Null(), 0; m < nbMappings; Bi, m = Bi.Add(Bi, B), m+1 { | ||
PointToInt[Bi.String()] = m | ||
|
||
if checkNeg { | ||
neg := suite.Point().Mul(suite.Scalar().SetInt64(int64(-m)), B) | ||
PointToInt[neg.String()] = -m | ||
} | ||
} | ||
|
||
// open file | ||
file, err := os.Create(outputFile) | ||
if err != nil { | ||
return cli.NewExitError(err, 1) | ||
} | ||
defer file.Close() | ||
|
||
// write mapping to disk | ||
switch outputFormat { | ||
case "typescript": | ||
err = writeMapToTSFile(file, PointToInt) | ||
case "go": | ||
err = writeMapToGoFile(file, PointToInt) | ||
default: | ||
err = errors.New("format selected is incorrect: " + outputFormat) | ||
} | ||
|
||
if err != nil { | ||
return cli.NewExitError(err, 2) | ||
} | ||
|
||
log.Info("Successfully generated mapping file with ", nbMappings, " mappings to ", outputFile) | ||
return nil | ||
} | ||
|
||
func writeMapToTSFile(file *os.File, pointToInt map[string]int64) (err error) { | ||
//export let PointToInt: Record<string, number> = { | ||
// "edc876d6831fd2105d0b4389ca2e283166469289146e2ce06faefe98b22548df": 5, | ||
// "f47e49f9d07ad2c1606b4d94067c41f9777d4ffda709b71da1d88628fce34d85": 6, | ||
//} | ||
|
||
_, err = file.WriteString("export let PointToInt: Record<string, number> = {\n") | ||
if err != nil { | ||
return | ||
} | ||
for k, v := range pointToInt { | ||
_, err = file.WriteString("\t" + `"` + k + `": ` + strconv.FormatInt(v, 10) + ",\n") | ||
if err != nil { | ||
return | ||
} | ||
} | ||
_, err = file.WriteString("};") | ||
if err != nil { | ||
return | ||
} | ||
return | ||
} | ||
|
||
func writeMapToGoFile(file *os.File, pointToInt map[string]int64) (err error) { | ||
//package main | ||
//var PointToInt = map[string]int64{ | ||
// "00022ddff3737fda59ef096dae2ea2876a5893510442fde25cb37486ed8b97c3": 7414, | ||
//} | ||
|
||
_, err = file.WriteString("package main \nvar PointToInt = map[string]int64{\n") | ||
if err != nil { | ||
return | ||
} | ||
|
||
for k, v := range pointToInt { | ||
_, err = file.WriteString("\t" + `"` + k + `": ` + strconv.FormatInt(v, 10) + ",\n") | ||
if err != nil { | ||
return | ||
} | ||
} | ||
|
||
_, err = file.WriteString("}") | ||
if err != nil { | ||
return | ||
} | ||
return | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"gopkg.in/urfave/cli.v1" | ||
servicesmedco "github.com/ldsec/medco-unlynx/services" | ||
"time" | ||
|
||
// Empty imports to have the init-functions called which should | ||
// register the protocol | ||
_ "github.com/lca1/medco-unlynx/services" | ||
_ "github.com/lca1/unlynx/protocols" | ||
_ "github.com/ldsec/medco-unlynx/services" | ||
_ "github.com/ldsec/unlynx/protocols" | ||
"github.com/urfave/cli" | ||
"go.dedis.ch/onet/v3/app" | ||
) | ||
|
||
func runServer(ctx *cli.Context) error { | ||
// first check the options | ||
config := ctx.String("config") | ||
timeout := ctx.Int64("timeout") | ||
|
||
app.RunServer(config) | ||
|
||
servicesmedco.TimeoutService = time.Duration(timeout) * time.Minute | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
module github.com/lca1/medco-unlynx | ||
module github.com/ldsec/medco-unlynx | ||
|
||
go 1.13 | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 | ||
github.com/btcsuite/goleveldb v1.0.0 | ||
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect | ||
github.com/fanliao/go-concurrentMap v0.0.0-20141114143905-7d2d7a5ea67b | ||
github.com/gopherjs/gopherjs v0.0.0-20190430165422-3e4dfb77656c // indirect | ||
github.com/lca1/unlynx v1.3.1 | ||
github.com/satori/go.uuid v1.2.0 | ||
github.com/smartystreets/assertions v0.0.0-20190401211740-f487f9de1cd3 // indirect | ||
github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect | ||
github.com/stretchr/testify v1.3.0 | ||
go.dedis.ch/kyber/v3 v3.0.3 | ||
go.dedis.ch/onet/v3 v3.0.14 | ||
golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f // indirect | ||
golang.org/x/net v0.0.0-20190522155817-f3200d17e092 // indirect | ||
golang.org/x/sys v0.0.0-20190528183647-3626398d7749 // indirect | ||
golang.org/x/text v0.3.2 // indirect | ||
gopkg.in/urfave/cli.v1 v1.20.0 | ||
github.com/gorilla/websocket v1.4.1 // indirect | ||
github.com/ldsec/unlynx v1.4.0 | ||
github.com/smartystreets/goconvey v1.6.4 // indirect | ||
github.com/stretchr/testify v1.4.0 | ||
github.com/urfave/cli v1.22.2 | ||
go.dedis.ch/kyber/v3 v3.0.12 | ||
go.dedis.ch/onet/v3 v3.1.0 | ||
golang.org/x/crypto v0.0.0-20200210222208-86ce3cb69678 // indirect | ||
golang.org/x/net v0.0.0-20191126235420-ef20fe5d7933 // indirect | ||
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect | ||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 | ||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect | ||
gopkg.in/yaml.v2 v2.2.7 // indirect | ||
) |
Oops, something went wrong.