Skip to content

Commit

Permalink
[FAB-14399] move idemix.proto out into idemix
Browse files Browse the repository at this point in the history
Change-Id: I9b89b20641352dac94759c96c005dcddb917862f
Signed-off-by: Matthew Sykes <sykesmat@us.ibm.com>
  • Loading branch information
sykesm committed Mar 1, 2019
1 parent e0f4d4b commit c6d0d48
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 11 deletions.
2 changes: 1 addition & 1 deletion idemix/idemix.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
37 changes: 37 additions & 0 deletions idemix/logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package idemix

import "log"

// logger is used to log debug information.
var logger Logger = LogFunc(log.Printf)

// SetLogger sets the logger instance used for debug and error reporting. The
// logger reference is not mutex-protected so this must be set before calling
// any other library functions.
//
// If a custom logger is not defined, the global logger from the standard
// library's log package is used.
func SetLogger(l Logger) {
logger = l
}

// Logger defines the contract for logging. This interface is explicitly
// defined to be compatible with the logger in the standard library log
// package.
type Logger interface {
Printf(format string, a ...interface{})
}

// LogFunc is a function adapter for logging.
type LogFunc func(format string, a ...interface{})

// Printf is used to create a formatted string log record.
func (l LogFunc) Printf(format string, a ...interface{}) {
l(format, a...)
}
11 changes: 6 additions & 5 deletions idemix/revocation_authority.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
"crypto/elliptic"
"crypto/rand"
"crypto/sha256"
"encoding/asn1"
"math/big"

"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-amcl/amcl"
"github.com/hyperledger/fabric-amcl/amcl/FP256BN"
"github.com/hyperledger/fabric/bccsp/utils"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -94,12 +95,12 @@ func VerifyEpochPK(pk *ecdsa.PublicKey, epochPK *ECP2, epochPkSig []byte, epoch
}
digest := sha256.Sum256(bytesToSign)

r, s, err := utils.UnmarshalECDSASignature(epochPkSig)
if err != nil {
return errors.Wrap(err, "failed to unmarshal ECDSA signature")
var sig struct{ R, S *big.Int }
if _, err := asn1.Unmarshal(epochPkSig, &sig); err != nil {
return errors.Wrap(err, "failed unmashalling signature")
}

if !ecdsa.Verify(pk, digest[:], r, s) {
if !ecdsa.Verify(pk, digest[:], sig.R, sig.S) {
return errors.Errorf("EpochPKSig invalid")
}

Expand Down
8 changes: 3 additions & 5 deletions idemix/signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,9 @@ import (

"github.com/hyperledger/fabric-amcl/amcl"
"github.com/hyperledger/fabric-amcl/amcl/FP256BN"
"github.com/hyperledger/fabric/common/flogging"
"github.com/pkg/errors"
)

var idemixLogger = flogging.MustGetLogger("idemix")

// signLabel is the label used in zero-knowledge proof (ZKP) to identify that this ZKP is a signature of knowledge
const signLabel = "sign"

Expand Down Expand Up @@ -376,7 +373,7 @@ func (sig *Signature) Ver(Disclosure []byte, ipk *IssuerPublicKey, msg []byte, a

if *ProofC != *HashModOrder(proofData) {
// This debug line helps identify where the mismatch happened
idemixLogger.Debugf("Signature Verification : \n"+
logger.Printf("Signature Verification : \n"+
" [t1:%v]\n,"+
" [t2:%v]\n,"+
" [t3:%v]\n,"+
Expand All @@ -398,7 +395,8 @@ func (sig *Signature) Ver(Disclosure []byte, ipk *IssuerPublicKey, msg []byte, a
nonRevokedProofBytes,
ipk.Hash,
Disclosure,
msg)
msg,
)
return errors.Errorf("signature invalid: zero-knowledge proof is invalid")
}

Expand Down

0 comments on commit c6d0d48

Please sign in to comment.