Skip to content

Commit

Permalink
stable
Browse files Browse the repository at this point in the history
  • Loading branch information
Tatiana Bradley committed Aug 21, 2020
1 parent 07f8a7e commit 91cce92
Show file tree
Hide file tree
Showing 20 changed files with 2,282 additions and 1,934 deletions.
4 changes: 2 additions & 2 deletions go/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
TEST_FLAGS=./... -cover -count=1
TEST_FLAGS=./... -cover -count=1 -mod=vendor
BENCH_FLAGS=$(TEST_FLAGS) -bench=.
COMPILED=voprf-go
BUILD_FLAGS=-o $(COMPILED)
BUILD_FLAGS=-o $(COMPILED) -mod=vendor

# defaults
GROUP=P384
Expand Down
13 changes: 6 additions & 7 deletions go/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/alxdavids/voprf-poc/go/jsonrpc"
"github.com/alxdavids/voprf-poc/go/oprf"
gg "github.com/alxdavids/voprf-poc/go/oprf/groups"
"github.com/alxdavids/voprf-poc/go/oprf/groups/dleq"
)

const (
Expand Down Expand Up @@ -44,7 +43,7 @@ type Config struct {

// CreateConfig instantiates the client that will communicate with the HTTP
// server running the (V)OPRF
func CreateConfig(ciphersuite string, pogInit gg.PrimeOrderGroup, n int, outputPath string, testIndex int) (*Config, error) {
func CreateConfig(ciphersuite int, pogInit gg.PrimeOrderGroup, n int, outputPath string, testIndex int) (*Config, error) {
ptpnt, err := oprf.Client{}.Setup(ciphersuite, pogInit)
if err != nil {
return nil, err
Expand All @@ -64,7 +63,7 @@ func CreateConfig(ciphersuite string, pogInit gg.PrimeOrderGroup, n int, outputP
test: test,
}
if test {
raw, err := ioutil.ReadFile(fmt.Sprintf("../test-vectors/%s.json", ciphersuite))
raw, err := ioutil.ReadFile(fmt.Sprintf("../test-vectors/%s.json", gg.IDtoName(ciphersuite)))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -223,7 +222,7 @@ func (cfg *Config) processServerResponse(jsonrpcResp *jsonrpc.ResponseSuccess) (
}

// if the ciphersuite is verifiable then construct the proof object
if cfg.ocli.Ciphersuite().Verifiable() {
if cfg.ocli.Verifiable() {
cBytes, err := hex.DecodeString(result.Proof[0])
if err != nil {
return nil, nil, nil, oprf.BatchedEvaluation{}, err
Expand All @@ -233,7 +232,7 @@ func (cfg *Config) processServerResponse(jsonrpcResp *jsonrpc.ResponseSuccess) (
return nil, nil, nil, oprf.BatchedEvaluation{}, err
}
var proofBytes = [][]byte{cBytes, sBytes}
ev.Proof = dleq.Proof{}.Deserialize(pog, proofBytes)
ev.Proof = oprf.Proof{}.Deserialize(pog, proofBytes)
}

// run the unblinding steps
Expand Down Expand Up @@ -281,7 +280,7 @@ func (cfg *Config) createJSONRPCRequest(eles [][]byte, id int) *jsonrpc.Request
Method: "eval",
Params: jsonrpc.RequestParams{
Data: hexParams,
Ciphersuite: cfg.ocli.Ciphersuite().Name(),
Ciphersuite: cfg.ocli.Ciphersuite().ID(),
},
ID: id,
}
Expand Down Expand Up @@ -352,7 +351,7 @@ func (cfg *Config) PrintStorage() error {
outputStrings[j] = outString
}

evJSON, err := storedEvaluations.ToJSON(cfg.ocli.Ciphersuite().Verifiable())
evJSON, err := storedEvaluations.ToJSON(cfg.ocli.Verifiable())
if err != nil {
return err
}
Expand Down
84 changes: 39 additions & 45 deletions go/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,8 @@ import (
"github.com/stretchr/testify/assert"
)

var (
validOPRFP384Ciphersuite = "OPRF-P384-HKDF-SHA512-SSWU-RO"
validOPRFP521Ciphersuite = "OPRF-P521-HKDF-SHA512-SSWU-RO"
validOPRFC448Ciphersuite = "OPRF-curve448-HKDF-SHA512-ELL2-RO"
)

func TestCreateConfigP384(t *testing.T) {
cfg, err := CreateConfig(validOPRFP384Ciphersuite, ecgroup.GroupCurve{}, 1, "some_file", -1)
cfg, err := CreateConfig(gg.OPRF_P384_SHA512, ecgroup.GroupCurve{}, 1, "some_file", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -32,7 +26,7 @@ func TestCreateConfigP384(t *testing.T) {
}

func TestCreateConfigP521(t *testing.T) {
cfg, err := CreateConfig(validOPRFP521Ciphersuite, ecgroup.GroupCurve{}, 1, "some_file", -1)
cfg, err := CreateConfig(gg.OPRF_P521_SHA512, ecgroup.GroupCurve{}, 1, "some_file", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -43,7 +37,7 @@ func TestCreateConfigP521(t *testing.T) {
}

func TestCreateConfigC448(t *testing.T) {
cfg, err := CreateConfig(validOPRFC448Ciphersuite, ecgroup.GroupCurve{}, 1, "some_file", -1)
cfg, err := CreateConfig(gg.OPRF_CURVE448_SHA512, ecgroup.GroupCurve{}, 1, "some_file", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -54,26 +48,26 @@ func TestCreateConfigC448(t *testing.T) {
}

func TestInvalidCiphersuite(t *testing.T) {
_, err := CreateConfig("OPRF-P256-HKDF-SHA512-SSWU-RO", ecgroup.GroupCurve{}, 1, "", -1)
_, err := CreateConfig(gg.GROUP_P256, ecgroup.GroupCurve{}, 1, "", -1)
if !errors.Is(err, oerr.ErrUnsupportedGroup) {
t.Fatal("bad group should have triggered a bad ciphersuite error")
}
}

func TestCreateOPRFRequestP384(t *testing.T) {
CreateOPRFRequest(t, validOPRFP384Ciphersuite)
CreateOPRFRequest(t, gg.OPRF_P384_SHA512)
}

func TestCreateOPRFRequestP521(t *testing.T) {
CreateOPRFRequest(t, validOPRFP521Ciphersuite)
CreateOPRFRequest(t, gg.OPRF_P521_SHA512)
}

func TestCreateOPRFRequestC448(t *testing.T) {
CreateOPRFRequest(t, validOPRFC448Ciphersuite)
CreateOPRFRequest(t, gg.OPRF_CURVE448_SHA512)
}

func CreateOPRFRequest(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, 1, "", -1)
func CreateOPRFRequest(t *testing.T, ciph int) {
cfg, err := CreateConfig(ciph, ecgroup.GroupCurve{}, 1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -112,19 +106,19 @@ func CreateOPRFRequest(t *testing.T, config string) {
}

func TestCreateOPRFRequestBadNP384(t *testing.T) {
CreateOPRFRequestBadN(t, validOPRFP384Ciphersuite)
CreateOPRFRequestBadN(t, gg.OPRF_P384_SHA512)
}

func TestCreateOPRFRequestBadNP521(t *testing.T) {
CreateOPRFRequestBadN(t, validOPRFP521Ciphersuite)
CreateOPRFRequestBadN(t, gg.OPRF_P521_SHA512)
}

func TestCreateOPRFRequestBadNC448(t *testing.T) {
CreateOPRFRequestBadN(t, validOPRFC448Ciphersuite)
CreateOPRFRequestBadN(t, gg.OPRF_CURVE448_SHA512)
}

func CreateOPRFRequestBadN(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, -1, "", -1)
func CreateOPRFRequestBadN(t *testing.T, ciphID int) {
cfg, err := CreateConfig(ciphID, ecgroup.GroupCurve{}, -1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -135,19 +129,19 @@ func CreateOPRFRequestBadN(t *testing.T, config string) {
}

func TestCreateJSONRPCRequestP384(t *testing.T) {
CreateJSONRPCRequest(t, validOPRFP384Ciphersuite)
CreateJSONRPCRequest(t, gg.OPRF_P384_SHA512)
}

func TestCreateJSONRPCRequestP521(t *testing.T) {
CreateJSONRPCRequest(t, validOPRFP521Ciphersuite)
CreateJSONRPCRequest(t, gg.OPRF_P521_SHA512)
}

func TestCreateJSONRPCRequestC448(t *testing.T) {
CreateJSONRPCRequest(t, validOPRFC448Ciphersuite)
CreateJSONRPCRequest(t, gg.OPRF_CURVE448_SHA512)
}

func CreateJSONRPCRequest(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, 1, "", -1)
func CreateJSONRPCRequest(t *testing.T, ciph int) {
cfg, err := CreateConfig(ciph, ecgroup.GroupCurve{}, 1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -162,19 +156,19 @@ func CreateJSONRPCRequest(t *testing.T, config string) {
}

func TestParseJSONRPCResponseSuccessP384(t *testing.T) {
ParseJSONRPCResponseSuccess(t, validOPRFP384Ciphersuite)
ParseJSONRPCResponseSuccess(t, gg.OPRF_P384_SHA512)
}

func TestParseJSONRPCResponseSuccessP521(t *testing.T) {
ParseJSONRPCResponseSuccess(t, validOPRFP521Ciphersuite)
ParseJSONRPCResponseSuccess(t, gg.OPRF_P521_SHA512)
}

func TestParseJSONRPCResponseSuccessC448(t *testing.T) {
ParseJSONRPCResponseSuccess(t, validOPRFC448Ciphersuite)
ParseJSONRPCResponseSuccess(t, gg.OPRF_CURVE448_SHA512)
}

func ParseJSONRPCResponseSuccess(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, 1, "", -1)
func ParseJSONRPCResponseSuccess(t *testing.T, ciph int) {
cfg, err := CreateConfig(ciph, ecgroup.GroupCurve{}, 1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -199,19 +193,19 @@ func ParseJSONRPCResponseSuccess(t *testing.T, config string) {
}

func TestParseJSONRPCResponseErrorP384(t *testing.T) {
ParseJSONRPCResponseError(t, validOPRFP384Ciphersuite)
ParseJSONRPCResponseError(t, gg.OPRF_P384_SHA512)
}

func TestParseJSONRPCResponseErrorP521(t *testing.T) {
ParseJSONRPCResponseError(t, validOPRFP521Ciphersuite)
ParseJSONRPCResponseError(t, gg.OPRF_P521_SHA512)
}

func TestParseJSONRPCResponseErrorC448(t *testing.T) {
ParseJSONRPCResponseError(t, validOPRFC448Ciphersuite)
ParseJSONRPCResponseError(t, gg.OPRF_CURVE448_SHA512)
}

func ParseJSONRPCResponseError(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, 1, "", -1)
func ParseJSONRPCResponseError(t *testing.T, ciph int) {
cfg, err := CreateConfig(ciph, ecgroup.GroupCurve{}, 1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -238,19 +232,19 @@ func ParseJSONRPCResponseError(t *testing.T, config string) {
}

func TestParseJSONRPCResponseInvalidResultP384(t *testing.T) {
ParseJSONRPCResponseInvalidResult(t, validOPRFP384Ciphersuite)
ParseJSONRPCResponseInvalidResult(t, gg.OPRF_P384_SHA512)
}

func TestParseJSONRPCResponseInvalidResultP521(t *testing.T) {
ParseJSONRPCResponseInvalidResult(t, validOPRFP521Ciphersuite)
ParseJSONRPCResponseInvalidResult(t, gg.OPRF_P521_SHA512)
}

func TestParseJSONRPCResponseInvalidResultC448(t *testing.T) {
ParseJSONRPCResponseInvalidResult(t, validOPRFC448Ciphersuite)
ParseJSONRPCResponseInvalidResult(t, gg.OPRF_CURVE448_SHA512)
}

func ParseJSONRPCResponseInvalidResult(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, 1, "", -1)
func ParseJSONRPCResponseInvalidResult(t *testing.T, ciph int) {
cfg, err := CreateConfig(ciph, ecgroup.GroupCurve{}, 1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand All @@ -269,19 +263,19 @@ func ParseJSONRPCResponseInvalidResult(t *testing.T, config string) {
}

func TestParseJSONRPCResponseInvalidFieldP384(t *testing.T) {
ParseJSONRPCResponseInvalidField(t, validOPRFP384Ciphersuite)
ParseJSONRPCResponseInvalidField(t, gg.OPRF_P384_SHA512)
}

func TestParseJSONRPCResponseInvalidFieldP521(t *testing.T) {
ParseJSONRPCResponseInvalidField(t, validOPRFP521Ciphersuite)
ParseJSONRPCResponseInvalidField(t, gg.OPRF_P521_SHA512)
}

func TestParseJSONRPCResponseInvalidFieldC448(t *testing.T) {
ParseJSONRPCResponseInvalidField(t, validOPRFC448Ciphersuite)
ParseJSONRPCResponseInvalidField(t, gg.OPRF_CURVE448_SHA512)
}

func ParseJSONRPCResponseInvalidField(t *testing.T, config string) {
cfg, err := CreateConfig(config, ecgroup.GroupCurve{}, 1, "", -1)
func ParseJSONRPCResponseInvalidField(t *testing.T, ciph int) {
cfg, err := CreateConfig(ciph, ecgroup.GroupCurve{}, 1, "", -1)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion go/jsonrpc/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Request struct {
// RequestParams objects are sent as the main payload of the Request object
type RequestParams struct {
Data []string `json:"data"`
Ciphersuite string `json:"ciph"`
Ciphersuite int `json:"ciph"`
}

// ResponseSuccess constructs a successful JSONRPC response back to a
Expand Down
16 changes: 6 additions & 10 deletions go/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ import (
"os"

"github.com/alxdavids/voprf-poc/go/client"
gg "github.com/alxdavids/voprf-poc/go/oprf/groups"
"github.com/alxdavids/voprf-poc/go/oprf/groups/ecgroup"
"github.com/alxdavids/voprf-poc/go/server"
)

var (
validP384Ciphersuite = "OPRF-P384-HKDF-SHA512-SSWU-RO"
validP521Ciphersuite = "OPRF-P521-HKDF-SHA512-SSWU-RO"
)

func main() {
var mode, ciphersuite, clientOutFolder, pk string
var max, n, test int
var mode, clientOutFolder, pk string
var ciphersuite, max, n, test int
flag.StringVar(&mode, "mode", "", "Specifies which mode to run in, options: (client|server).")
flag.StringVar(&ciphersuite, "ciph", validP384Ciphersuite, "Specifies the VOPRF ciphersuite to use.")
flag.IntVar(&ciphersuite, "ciph", gg.OPRF_P384_SHA512, "Specifies the VOPRF ciphersuite to use.")
flag.StringVar(&clientOutFolder, "out_folder", "", "Specifies an output folder to write files containing the client's stored variables after invocation. If left empty, output is written to console.")
flag.IntVar(&max, "max_evals", 10, "Specifies the maximum number of OPRF evaluations that are permitted by the server")
flag.IntVar(&n, "n", 1, "Specifies the number of OPRF evaluations to be attempted by the client")
Expand Down Expand Up @@ -48,7 +44,7 @@ func main() {
}
}

func runServer(ciphersuite string, max, test int) error {
func runServer(ciphersuite, max, test int) error {
cfgServer, err := server.CreateConfig(ciphersuite, ecgroup.GroupCurve{}, max, false, test)
if err != nil {
return err
Expand All @@ -63,7 +59,7 @@ func runServer(ciphersuite string, max, test int) error {
return nil
}

func runClient(ciphersuite, clientOutFolder string, n int, pk string, test int) error {
func runClient(ciphersuite int, clientOutFolder string, n int, pk string, test int) error {
cfgClient, err := client.CreateConfig(ciphersuite, ecgroup.GroupCurve{}, n, clientOutFolder, test)
if err != nil {
return err
Expand Down
4 changes: 4 additions & 0 deletions go/oerr/oerr.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ var (
// ErrUnsupportedH2C indicates that the requested hash-to-curve function is
// not supported.
ErrUnsupportedH2C = errors.New("The chosen hash-to-curve function is not supported, currently supported functions: [SSWU-RO (for NIST curves)]")
// ErrUnsupportedCiphersuite indicates that the requested ciphersuite is
// not supported.
// TODO: fill in supported ciphersuites
ErrUnsupportedCiphersuite = errors.New("The chosen ciphersuite is not supported, currently supported ciphersuites: [TODO]")
// ErrIncompatibleGroupParams indicates that the requested group has a
// parameter setting that is incompatible with our implementation
ErrIncompatibleGroupParams = errors.New("The chosen group has an incompatible parameter setting")
Expand Down
Loading

0 comments on commit 91cce92

Please sign in to comment.