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

     1  package jjm
     2  
     3  import (
     4  	"crypto/elliptic"
     5  	"crypto/rand"
     6  	"github.com/ronperry/cryptoedge/eccutil"
     7  	"testing"
     8  )
     9  
    10  func TestNewSigner(t *testing.T) {
    11  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    12  	privkey, pubkey, err := c.GenerateKey()
    13  	if err != nil {
    14  		t.Fatalf("Error creating keys: %s", err)
    15  	}
    16  	signer := NewSigner(privkey, pubkey, c)
    17  	_ = signer
    18  }
    19  
    20  func TestNewSignRequest(t *testing.T) {
    21  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    22  	privkey, pubkey, err := c.GenerateKey()
    23  	if err != nil {
    24  		t.Fatalf("Error creating keys: %s", err)
    25  	}
    26  	signer := NewSigner(privkey, pubkey, c)
    27  	public, private, err := signer.NewSignRequest()
    28  	if err != nil {
    29  		t.Errorf("Error occured throughout parameter creation: %s", err)
    30  	}
    31  	_, _ = public, private
    32  }
    33  
    34  func TestSign(t *testing.T) {
    35  	msg := []byte("Message to be blind-signed")
    36  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    37  	privkey, pubkey, err := c.GenerateKey()
    38  	if err != nil {
    39  		t.Fatalf("Error creating keys: %s", err)
    40  	}
    41  	signer := NewSigner(privkey, pubkey, c)
    42  	publicSigParams, privateSigParams, err := signer.NewSignRequest()
    43  	if err != nil {
    44  		t.Errorf("Error occured throughout parameter creation: %s", err)
    45  	}
    46  	bc := NewBlindingClient(c, pubkey)
    47  
    48  	privateBlindingParams, err := bc.CalculateBlindingParams(publicSigParams)
    49  	if err != nil {
    50  		t.Errorf("CalculateBlindingParams failed: %s", err)
    51  	}
    52  
    53  	blindmessage, err := bc.Blind(msg, publicSigParams, privateBlindingParams)
    54  	if err != nil {
    55  		t.Errorf("Blind failed: %s", err)
    56  	}
    57  
    58  	blindsig, err := signer.Sign(blindmessage, privateSigParams)
    59  	if err != nil {
    60  		t.Errorf("Sign failed: %s", err)
    61  	}
    62  	_ = blindsig
    63  }