github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/jjm/requestor_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 TestCalculateBlindingParams(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  	publicSigParams, privateSigParams, err := signer.NewSignRequest()
    18  	if err != nil {
    19  		t.Errorf("Error occured throughout parameter creation: %s", err)
    20  	}
    21  	bc := NewBlindingClient(c, pubkey)
    22  
    23  	privateBlindingParams, err := bc.CalculateBlindingParams(publicSigParams)
    24  	if err != nil {
    25  		t.Errorf("CalculateBlindingParams failed: %s", err)
    26  	}
    27  	_, _ = privateBlindingParams, privateSigParams
    28  }
    29  
    30  func TestBlind(t *testing.T) {
    31  	msg := []byte("Message to be blind-signed")
    32  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    33  	privkey, pubkey, err := c.GenerateKey()
    34  	if err != nil {
    35  		t.Fatalf("Error creating keys: %s", err)
    36  	}
    37  	signer := NewSigner(privkey, pubkey, c)
    38  	publicSigParams, privateSigParams, err := signer.NewSignRequest()
    39  	if err != nil {
    40  		t.Errorf("Error occured throughout parameter creation: %s", err)
    41  	}
    42  	bc := NewBlindingClient(c, pubkey)
    43  
    44  	privateBlindingParams, err := bc.CalculateBlindingParams(publicSigParams)
    45  	if err != nil {
    46  		t.Errorf("CalculateBlindingParams failed: %s", err)
    47  	}
    48  
    49  	blindmessage, err := bc.Blind(msg, publicSigParams, privateBlindingParams)
    50  	if err != nil {
    51  		t.Errorf("Blind failed: %s", err)
    52  	}
    53  	_, _ = blindmessage, privateSigParams
    54  }
    55  
    56  func TestUnBlind(t *testing.T) {
    57  	msg := []byte("Message to be blind-signed")
    58  	c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash)
    59  	privkey, pubkey, err := c.GenerateKey()
    60  	if err != nil {
    61  		t.Fatalf("Error creating keys: %s", err)
    62  	}
    63  	signer := NewSigner(privkey, pubkey, c)
    64  	publicSigParams, privateSigParams, err := signer.NewSignRequest()
    65  	if err != nil {
    66  		t.Errorf("Error occured throughout parameter creation: %s", err)
    67  	}
    68  	bc := NewBlindingClient(c, pubkey)
    69  
    70  	privateBlindingParams, err := bc.CalculateBlindingParams(publicSigParams)
    71  	if err != nil {
    72  		t.Errorf("CalculateBlindingParams failed: %s", err)
    73  	}
    74  
    75  	blindmessage, err := bc.Blind(msg, publicSigParams, privateBlindingParams)
    76  	if err != nil {
    77  		t.Errorf("Blind failed: %s", err)
    78  	}
    79  
    80  	blindsig, err := signer.Sign(blindmessage, privateSigParams)
    81  	if err != nil {
    82  		t.Errorf("Sign failed: %s", err)
    83  	}
    84  	signature, err := bc.Unblind(blindsig, privateBlindingParams)
    85  	if err != nil {
    86  		t.Errorf("Unblind failed: %s", err)
    87  	}
    88  	_ = signature
    89  }