From 3da02d646fe35396f2a0efeef81e80a8707b4c4b Mon Sep 17 00:00:00 2001 From: Sanjit Bhat Date: Sun, 17 Nov 2024 22:40:24 -0500 Subject: [PATCH] make vrf pk start from bytes to make pk agree assumption possible --- cryptoffi/cryptoffi.go | 2 ++ kt/client.go | 5 +++-- kttest/testhelpers.go | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/cryptoffi/cryptoffi.go b/cryptoffi/cryptoffi.go index 126b040..74814f5 100644 --- a/cryptoffi/cryptoffi.go +++ b/cryptoffi/cryptoffi.go @@ -38,11 +38,13 @@ func SigGenerateKey() (SigPublicKey, *SigPrivateKey) { return SigPublicKey(pk), &SigPrivateKey{sk: sk} } +// Sign assumes a valid sk and returns a signature for msg. func (sk *SigPrivateKey) Sign(message []byte) []byte { return ed25519.Sign(ed25519.PrivateKey(sk.sk), message) } // Verify verifies the sig and rets any errs. +// it checks for pk, msg, and sig validity. func (pk SigPublicKey) Verify(message []byte, sig []byte) bool { return !ed25519.Verify(ed25519.PublicKey(pk), message, sig) } diff --git a/kt/client.go b/kt/client.go index 8edba0e..5173aaa 100644 --- a/kt/client.go +++ b/kt/client.go @@ -229,8 +229,9 @@ func (c *Client) Audit(adtrAddr uint64, adtrPk cryptoffi.SigPublicKey) *ClientEr return err0 } -func NewClient(uid, servAddr uint64, servSigPk cryptoffi.SigPublicKey, servVrfPk *cryptoffi.VrfPublicKey) *Client { +func NewClient(uid, servAddr uint64, servSigPk cryptoffi.SigPublicKey, servVrfPk []byte) *Client { c := advrpc.Dial(servAddr) + pk := cryptoffi.VrfPublicKeyDecode(servVrfPk) digs := make(map[uint64]*SigDig) - return &Client{uid: uid, servCli: c, servSigPk: servSigPk, servVrfPk: servVrfPk, seenDigs: digs} + return &Client{uid: uid, servCli: c, servSigPk: servSigPk, servVrfPk: pk, seenDigs: digs} } diff --git a/kttest/testhelpers.go b/kttest/testhelpers.go index 66da82e..7eeaedd 100644 --- a/kttest/testhelpers.go +++ b/kttest/testhelpers.go @@ -10,7 +10,7 @@ import ( type setupParams struct { servAddr uint64 servSigPk cryptoffi.SigPublicKey - servVrfPk *cryptoffi.VrfPublicKey + servVrfPk []byte adtrAddrs []uint64 adtrPks []cryptoffi.SigPublicKey } @@ -20,6 +20,7 @@ type setupParams struct { // different adversary configs. func setup(servAddr uint64, adtrAddrs []uint64) *setupParams { serv, servSigPk, servVrfPk := kt.NewServer() + servVrfPkEnc := cryptoffi.VrfPublicKeyEncode(servVrfPk) servRpc := kt.NewRpcServer(serv) servRpc.Serve(servAddr) var adtrPks []cryptoffi.SigPublicKey @@ -30,7 +31,7 @@ func setup(servAddr uint64, adtrAddrs []uint64) *setupParams { adtrPks = append(adtrPks, adtrPk) } primitive.Sleep(1_000_000) - return &setupParams{servAddr: servAddr, servSigPk: servSigPk, servVrfPk: servVrfPk, adtrAddrs: adtrAddrs, adtrPks: adtrPks} + return &setupParams{servAddr: servAddr, servSigPk: servSigPk, servVrfPk: servVrfPkEnc, adtrAddrs: adtrAddrs, adtrPks: adtrPks} } func mkRpcClients(addrs []uint64) []*advrpc.Client {