aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.md8
-rw-r--r--avnet/avnet.go123
-rw-r--r--avnet/avnet_test.go16
-rw-r--r--go.mod4
-rw-r--r--go.sum2
-rw-r--r--go.work3
-rw-r--r--main.go35
7 files changed, 189 insertions, 2 deletions
diff --git a/README.md b/README.md
index d51732b..17887de 100644
--- a/README.md
+++ b/README.md
@@ -4,10 +4,16 @@ This package implements the seal protocol as defined in Bag et al. - 2020 - SEAL
## Design
+### AV-Net (Veto protocol)
+
## TODOs
- [ ] API-Design
- [ ] DB-Schema
- [ ] Tests
-- [ ] Implementation \ No newline at end of file
+- [ ] Implementation
+ - [ ] Veto-Protokoll
+ - [ ] Commitments
+ - [ ] Rounds
+ - [ ] Variants of Rounds \ No newline at end of file
diff --git a/avnet/avnet.go b/avnet/avnet.go
new file mode 100644
index 0000000..e40759f
--- /dev/null
+++ b/avnet/avnet.go
@@ -0,0 +1,123 @@
+package avnet
+
+import (
+ "crypto/rand"
+ "crypto/sha256"
+ "encoding/base32"
+ "encoding/binary"
+ "fmt"
+ "io"
+
+ curve "filippo.io/edwards25519"
+)
+
+var b32 = base32.StdEncoding.WithPadding(base32.NoPadding)
+
+// A Schnorr signature to prove knowledge of x for given g^x and i.
+
+type Proof struct {
+ PointV curve.Point
+ ScalarR curve.Scalar
+ I uint64
+}
+
+type Commitment struct {
+ PubX curve.Point
+ PubR curve.Point
+ ProofX Proof
+ ProofR Proof
+}
+
+type Vote struct {
+ bit bool
+
+ privX curve.Scalar
+ privR curve.Scalar
+
+ Commitment
+}
+
+func newPriv(s *curve.Scalar, random io.Reader) error {
+ var buf [64]byte
+ if random == nil {
+ random = rand.Reader
+ }
+ random.Read(buf[:])
+ _, e := s.SetUniformBytes(buf[:])
+ return e
+}
+
+func setPub(p *curve.Scalar, P *curve.Point) *curve.Point {
+ return P.ScalarBaseMult(p)
+}
+
+// Generates the proof, aka Schnorr signature, for given priv and i.
+// Choosing a scalar v randomly, the signature consists of (V, r) with
+//
+// V := g^v, with randomly chosen v
+// r := (v - x*h), with h := H(g, g^v, g^x, i), where i is given by the context.
+//
+// Verification of the signature is by comparing V =?= g^r * g^(x*h)
+func proof(pr *Proof, x *curve.Scalar, i uint64) error {
+ pr.I = i
+ var v curve.Scalar
+ e := newPriv(&v, nil)
+ if e != nil {
+ return e
+ }
+ setPub(&v, &pr.PointV)
+ gx := curve.Point{}
+ setPub(x, &gx)
+
+ // Calculate h := H(g, g^v, g^x, i)
+ h256 := sha256.New()
+ h256.Write(curve.NewGeneratorPoint().Bytes())
+ h256.Write(pr.PointV.Bytes())
+ h256.Write(gx.Bytes())
+ e = binary.Write(h256, binary.BigEndian, i)
+ if e != nil {
+ return e
+ }
+ // h := h256.Bytes()
+
+ // TODO: calculate r
+ return fmt.Errorf("proof not implemented")
+
+}
+
+func newVoteWithRand(bit bool, rand io.Reader) (vote *Vote, e error) {
+ vote = &Vote{
+ bit: bit,
+ }
+
+ e = newPriv(&vote.privX, rand)
+ if e != nil {
+ return nil, e
+ }
+ e = newPriv(&vote.privR, rand)
+ if e != nil {
+ return nil, e
+ }
+
+ setPub(&vote.privX, &vote.Commitment.PubX)
+ setPub(&vote.privR, &vote.Commitment.PubR)
+
+ return vote, nil
+}
+
+func NewVote(bit bool) (vote *Vote, e error) {
+ return newVoteWithRand(bit, nil)
+}
+
+func pubStr(p *curve.Point) string {
+ return b32.EncodeToString(p.Bytes())
+}
+
+func (c *Commitment) String() string {
+ return fmt.Sprintf(`{"PubX": "%s", "PubR": "%s"}`, pubStr(&c.PubX), pubStr(&c.PubR))
+}
+
+func (c *Commitment) MarshalJSON() ([]byte, error) {
+ s := c.String()
+ return []byte(s), nil
+} \ No newline at end of file
diff --git a/avnet/avnet_test.go b/avnet/avnet_test.go
new file mode 100644
index 0000000..8800b8b
--- /dev/null
+++ b/avnet/avnet_test.go
@@ -0,0 +1,16 @@
+package avnet
+
+import (
+ "testing"
+)
+
+func TestRound(t *testing.T) {
+ v, e := newVoteWithRand(false, nil)
+
+ if e != nil {
+ t.Fatalf("unexpected error: %v", e)
+ }
+ if v.bit {
+ t.Fatal("expected vote false, but got true")
+ }
+} \ No newline at end of file
diff --git a/go.mod b/go.mod
index ed03d2e..d779a7e 100644
--- a/go.mod
+++ b/go.mod
@@ -1,3 +1,5 @@
-module kesim.org/goseal
+module kesim.org/seal
go 1.22.0
+
+require filippo.io/edwards25519 v1.1.0 // indirect
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..359ca94
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,2 @@
+filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
+filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
diff --git a/go.work b/go.work
new file mode 100644
index 0000000..96b89a3
--- /dev/null
+++ b/go.work
@@ -0,0 +1,3 @@
+go 1.22.0
+
+use .
diff --git a/main.go b/main.go
new file mode 100644
index 0000000..4d497a8
--- /dev/null
+++ b/main.go
@@ -0,0 +1,35 @@
+package seal
+
+import (
+ "crypto"
+ "time"
+)
+
+// Auction describes the asset of an auction and other
+// relevant meta-data
+type Auction struct {
+ // Start date
+ Start time.Time
+ // End date
+ End time.Time
+ // Timeout per round by which all responses must have arrived
+ RoundTimeout time.Duration
+
+ // Sha512 Hash of the Asset
+ AssetHash string
+
+ // Public key of the Seller
+ SellerPublicKey crypto.PublicKey
+}
+
+// The SignedAuction contains an Auction and the signature,
+// signed by the seller's public key off the SHA512 hash of
+// the normalized JSON-object. TODO(oec): normalized?
+type SignedAuction struct {
+ Auction
+ SellerSignature string
+}
+
+// The published commiment of a participant
+type Commitment struct {
+}