github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/singhdas/requestor_test.go (about)

     1  package singhdas
     2  
     3  import (
     4  	"crypto/elliptic"
     5  	"crypto/rand"
     6  	"github.com/ronperry/cryptoedge/eccutil"
     7  	"testing"
     8  )
     9  
    10  func TestNewInstance(t *testing.T) {
    11  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    12  	privKey, pubKey, err := c.GenerateKey() // Signer long-term key
    13  	if err != nil {
    14  		t.Fatalf("Long term key gen failed: %s", err)
    15  	}
    16  	sc := NewSignerClient(pubKey, c)
    17  	_, _ = privKey, sc
    18  }
    19  
    20  func TestBlind(t *testing.T) {
    21  	msg := []byte("Something to sign")
    22  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    23  	privKey, pubKey, err := c.GenerateKey() // Signer long-term key
    24  	if err != nil {
    25  		t.Fatalf("Long term key gen failed: %s", err)
    26  	}
    27  	sig := NewSigner(privKey, pubKey, c)
    28  	sp, err := sig.NewRequest()
    29  	if err != nil {
    30  		t.Errorf("Cannot create request parameters: %s", err)
    31  	}
    32  	sc := NewSignerClient(pubKey, c)
    33  	blindmsg, blindfac, err := sc.Blind(msg, sp.Q)
    34  	if err != nil {
    35  		t.Errorf("Cannot blind")
    36  	}
    37  	_, _ = blindmsg, blindfac
    38  }
    39  
    40  func TestUnblind(t *testing.T) {
    41  	msg := []byte("Something to sign")
    42  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    43  	privKey, pubKey, err := c.GenerateKey() // Signer long-term key
    44  	if err != nil {
    45  		t.Fatalf("Long term key gen failed: %s", err)
    46  	}
    47  	sig := NewSigner(privKey, pubKey, c)
    48  	sp, err := sig.NewRequest()
    49  	if err != nil {
    50  		t.Errorf("Cannot create request parameters: %s", err)
    51  	}
    52  	sc := NewSignerClient(pubKey, c)
    53  	blindmsg, blindfac, err := sc.Blind(msg, sp.Q)
    54  	if err != nil {
    55  		t.Errorf("Cannot blind: %s", err)
    56  	}
    57  	blindsig, err := sig.Sign(blindmsg, sp)
    58  	if err != nil {
    59  		t.Errorf("Cannot sign: %s", err)
    60  	}
    61  	unblindsig, err := sc.UnBlind(blindsig, blindfac)
    62  	if err != nil {
    63  		t.Errorf("Cannot unblind: %s", err)
    64  	}
    65  	_, _ = blindsig, unblindsig
    66  }