6 Star 44 Fork 25

Hyperledger / fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
nymsignaturescheme.go 2.46 KB
一键复制 编辑 原始数据 按行查看 历史
Angelo De Caro 提交于 2018-11-05 13:45 . [FAB-9527] Use Idemix-Based BCCSP
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package bridge
import (
"github.com/hyperledger/fabric-amcl/amcl"
"github.com/hyperledger/fabric/bccsp/idemix/handlers"
"github.com/golang/protobuf/proto"
cryptolib "github.com/hyperledger/fabric/idemix"
"github.com/pkg/errors"
)
// NymSignatureScheme encapsulates the idemix algorithms to sign and verify using an idemix
// pseudonym.
type NymSignatureScheme struct {
NewRand func() *amcl.RAND
}
// Sign produces a signature over the passed digest. It takes in input, the user secret key (sk),
// the pseudonym public key (Nym) and secret key (RNym), and the issuer public key (ipk).
func (n *NymSignatureScheme) Sign(sk handlers.Big, Nym handlers.Ecp, RNym handlers.Big, ipk handlers.IssuerPublicKey, digest []byte) (res []byte, err error) {
defer func() {
if r := recover(); r != nil {
res = nil
err = errors.Errorf("failure [%s]", r)
}
}()
isk, ok := sk.(*Big)
if !ok {
return nil, errors.Errorf("invalid user secret key, expected *Big, got [%T]", sk)
}
inym, ok := Nym.(*Ecp)
if !ok {
return nil, errors.Errorf("invalid nym public key, expected *Ecp, got [%T]", Nym)
}
irnym, ok := RNym.(*Big)
if !ok {
return nil, errors.Errorf("invalid nym secret key, expected *Big, got [%T]", RNym)
}
iipk, ok := ipk.(*IssuerPublicKey)
if !ok {
return nil, errors.Errorf("invalid issuer public key, expected *IssuerPublicKey, got [%T]", ipk)
}
sig, err := cryptolib.NewNymSignature(
isk.E,
inym.E,
irnym.E,
iipk.PK,
digest,
n.NewRand())
if err != nil {
return nil, errors.WithMessage(err, "failed creating new nym signature")
}
return proto.Marshal(sig)
}
// Verify checks that the passed signatures is valid with the respect to the passed digest, issuer public key,
// and pseudonym public key.
func (*NymSignatureScheme) Verify(ipk handlers.IssuerPublicKey, Nym handlers.Ecp, signature, digest []byte) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.Errorf("failure [%s]", r)
}
}()
iipk, ok := ipk.(*IssuerPublicKey)
if !ok {
return errors.Errorf("invalid issuer public key, expected *IssuerPublicKey, got [%T]", ipk)
}
inym, ok := Nym.(*Ecp)
if !ok {
return errors.Errorf("invalid nym public key, expected *Ecp, got [%T]", Nym)
}
sig := &cryptolib.NymSignature{}
err = proto.Unmarshal(signature, sig)
if err != nil {
return errors.Wrap(err, "error unmarshalling signature")
}
return sig.Ver(inym.E, iipk.PK, digest)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/hyperledger/fabric.git
git@gitee.com:hyperledger/fabric.git
hyperledger
fabric
fabric
v1.4.4

搜索帮助

344bd9b3 5694891 D2dac590 5694891