github.com/ronperry/cryptoedge@v0.0.0-20150815114006-cc363e290743/genericblinding/blindingclient.go (about) 1 // Package genericblinding provides interface definitions for blind signature schemes 2 package genericblinding 3 4 import ( 5 "github.com/ronperry/cryptoedge/eccutil" 6 "errors" 7 ) 8 9 const ( 10 // TypeBlindingParamClient data identification 11 TypeBlindingParamClient = iota + 1 12 // TypeClearMessage data identification 13 TypeClearMessage 14 // TypeBlindingFactors data identification 15 TypeBlindingFactors 16 // TypeBlindMessage data identification 17 TypeBlindMessage 18 // TypeBlindSignature data identification 19 TypeBlindSignature 20 // TypeClearSignature data identification 21 TypeClearSignature 22 // TypeBlindingParamServer data identification 23 TypeBlindingParamServer 24 ) 25 26 var ( 27 // ErrBadScheme is returned if unmarshalling the data for the wrong scheme 28 ErrBadScheme = errors.New("blinding: Data does not match scheme") 29 // ErrBadType is returned if unmarshalling the data for the wrong scheme 30 ErrBadType = errors.New("blinding: Data does not match type") 31 // ErrBadSigner is returned if unmarshalling data for a foreign signer 32 ErrBadSigner = errors.New("blinding: Foreign signer") 33 ) 34 35 // DataType is the type of data encoded in a BlindingData 36 type DataType int 37 38 // BlindingData encapsulates data needed for blinding operations 39 type BlindingData interface { 40 // Marshall returns ASN.1 DER encoded data 41 Marshal() ([]byte, error) 42 // Unmarshall loads data that was produced by Marshall 43 Unmarshal([]byte) (BlindingData, error) 44 // UniqueID returns a (globally) unique, 32byte ID for this data structure that can be used for duplicate/reuse testing 45 UniqueID() []byte 46 // Return . 47 SchemeData() (string, DataType, *eccutil.Point) 48 //Return() BlindingData 49 } 50 51 // BlindingParamClient is an encoded set of blinding parameters 52 type BlindingParamClient BlindingData 53 54 // ClearMessage is a cleartext message before blinding 55 type ClearMessage BlindingData 56 57 // BlindingFactors are blinding factors generated by a BlindingClient 58 type BlindingFactors BlindingData 59 60 // BlindMessage is a blind message to be signed 61 type BlindMessage BlindingData 62 63 // BlindSignature is a blinded signature 64 type BlindSignature BlindingData 65 66 // ClearSignature is an unblinded Signature 67 type ClearSignature BlindingData 68 69 // BlindingParamServer is an encoded set of blinding parameters 70 type BlindingParamServer BlindingData 71 72 // BlindingClient implements a blind signature client 73 type BlindingClient interface { 74 // Blind a ClearMessage with server-supplied BlindingParamClient 75 Blind(BlindingParamClient, ClearMessage) (BlindingFactors, BlindMessage, error) 76 // Unblind a BlindSignature of ClearMessage using BlindingFactors 77 Unblind(BlindingFactors, ClearMessage, BlindSignature) (ClearSignature, ClearMessage, error) 78 // Verify that ClearSignature is a signature of ClearMessage 79 Verify(ClearSignature, ClearMessage) (bool, error) 80 } 81 82 // BlindingServer implements a BlindingServer 83 type BlindingServer interface { 84 // Generate one-time BlindingParam 85 GetParams() (BlindingParamClient, BlindingParamServer, error) 86 // Sign a BlindMessage usign BlindingParam 87 Sign(BlindingParamServer, BlindMessage) (BlindSignature, error) 88 } 89 90 // MatchMessage tests parameters of a BlindingData 91 func MatchMessage(bd BlindingData, testScheme string, testDataType DataType, testPoint *eccutil.Point) (bool, error) { 92 scheme, datatype, pubkey := bd.SchemeData() 93 if scheme != testScheme { 94 return false, ErrBadScheme 95 } 96 if datatype != testDataType { 97 return false, ErrBadType 98 } 99 if pubkey != nil { 100 if !eccutil.PointEqual(pubkey, testPoint) { 101 return false, ErrBadSigner 102 } 103 } 104 return true, nil 105 }