github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/singhdas/signer_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 TestNewSigner(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 sig := NewSigner(privKey, pubKey, c) 17 _ = sig 18 } 19 20 func TestNewRequest(t *testing.T) { 21 c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash) 22 privKey, pubKey, err := c.GenerateKey() // Signer long-term key 23 if err != nil { 24 t.Fatalf("Long term key gen failed: %s", err) 25 } 26 sig := NewSigner(privKey, pubKey, c) 27 sp, err := sig.NewRequest() 28 if err != nil { 29 t.Errorf("Cannot create request parameters: %s", err) 30 } 31 _ = sp 32 } 33 34 func TestSign(t *testing.T) { 35 msg := []byte("Something to sign") 36 c := eccutil.SetCurve(elliptic.P256, rand.Reader, eccutil.Sha1Hash) 37 privKey, pubKey, err := c.GenerateKey() // Signer long-term key 38 if err != nil { 39 t.Fatalf("Long term key gen failed: %s", err) 40 } 41 sig := NewSigner(privKey, pubKey, c) 42 sp, err := sig.NewRequest() 43 if err != nil { 44 t.Errorf("Cannot create request parameters: %s", err) 45 } 46 sc := NewSignerClient(pubKey, c) 47 blindmsg, blindfac, err := sc.Blind(msg, sp.Q) 48 if err != nil { 49 t.Errorf("Cannot blind: %s", err) 50 } 51 blindsig, err := sig.Sign(blindmsg, sp) 52 if err != nil { 53 t.Errorf("Cannot sign: %s", err) 54 } 55 _, _ = blindsig, blindfac 56 }