Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

many fixes #1

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 17 additions & 15 deletions blind.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
package blinding

import (
"errors"
"encoding/base64"
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"encoding/base64"
"errors"
"github.com/cryptoballot/fdh"
"github.com/cryptoballot/rsablind"
)

var Keysize = 2048
var Hashize = 1536
var err error
const (
Keysize = 4096
Hashize = 3072
)

/*********************
Utilities
Expand All @@ -40,7 +41,7 @@ func SignPSS(message []byte, privkey *rsa.PrivateKey) ([]byte, error) {
// verify sig on blinded message
func VerifyPSS(message, sig []byte, pubkey *rsa.PublicKey) error {
hashed := sha256.Sum256(message)
err = rsa.VerifyPSS(pubkey, crypto.SHA256, hashed[:], sig, nil)
err := rsa.VerifyPSS(pubkey, crypto.SHA256, hashed[:], sig, nil)
return err
}

Expand All @@ -52,20 +53,20 @@ func FinalMessage(salary, sig []byte) string {
}

type BlindedMessage struct {
Blinded []byte
Sig []byte
PublicKey rsa.PublicKey
Blinded []byte
Sig []byte
PublicKey rsa.PublicKey
}

/*********************
Employee
**********************/
type Employee struct {
key *rsa.PrivateKey
signerskey *rsa.PublicKey
message []byte
unblinder []byte
PublicKey *rsa.PublicKey
key *rsa.PrivateKey
signerskey *rsa.PublicKey
message []byte
unblinder []byte
PublicKey *rsa.PublicKey
has_blinded bool
}

Expand Down Expand Up @@ -110,7 +111,7 @@ func (e *Employee) Unblind(blindSig []byte) ([]byte, error) {
unBlindedSig := rsablind.Unblind(e.signerskey, blindSig, e.unblinder)

// verify the sig
err = e.VerifySallary(e.message, unBlindedSig, e.signerskey)
err := e.VerifySallary(e.message, unBlindedSig, e.signerskey)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -155,6 +156,7 @@ func (s *Signer) SignSalary(message *BlindedMessage) (sig []byte, err error) {
if err != nil {
return nil, err
}
s.employees[message.PublicKey] = true
return sig, nil
}

Expand Down
18 changes: 10 additions & 8 deletions blind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package blinding
import (
"crypto/rsa"
"testing"
"fmt"
)

func TestIntegration(t *testing.T) {
Expand Down Expand Up @@ -45,7 +44,6 @@ func TestIntegration(t *testing.T) {
}
}


// Creates a signer, some employees, and registers them
func setup(nemployees int) (*Signer, []*Employee) {
signer, _ := NewSigner()
Expand All @@ -58,21 +56,25 @@ func setup(nemployees int) (*Signer, []*Employee) {
employees[i] = e
keys[i] = *e.PublicKey
}
signer.AddEmployees(keys)
return signer, employees
}


func TestOneSigPerEmployee(t *testing.T) {
// test employee can't get two sigs
signer, employees := setup(1)
employee := employees[0]
bmsg, _ := employee.BlindSalary([]byte("message one"))

// try to sign twice
signer.SignSalary(bmsg)
_, err := signer.SignSalary(bmsg)
if err != nil {
t.Fatal(err)
}

_, err = signer.SignSalary(bmsg)
if err == nil {
t.Fatal()
t.Fatal("Signer managed to sign the same employee twice")
}
}

Expand All @@ -85,16 +87,16 @@ func TestOnlyRegisteredEmployees(t *testing.T) {
// try to sign while not registered
_, err := signer.SignSalary(bmsg)
if err == nil {
t.Fatal()
t.Fatal("Signer managed to sign unregistered employee")
}
}

func TestEmployeeCanOnlyBlindOnce(t *testing.T) {
_, employees := setup(1)
employee := employees[0]
employee.BlindSalary([]byte("once"))
_, err = employee.BlindSalary([]byte("twice"))
_, err := employee.BlindSalary([]byte("twice"))
if err == nil {
t.Fatal()
t.Fatal("Employee managed to sign twice")
}
}