63 Star 181 Fork 3

Gitee 极速下载 / hyperledger-fabric

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/hyperledger/fabric
克隆/下载
revocation.go 1.92 KB
一键复制 编辑 原始数据 按行查看 历史
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package bridge
import (
"crypto/ecdsa"
"github.com/golang/protobuf/proto"
"github.com/hyperledger/fabric-amcl/amcl/FP256BN"
"github.com/hyperledger/fabric/bccsp"
cryptolib "github.com/hyperledger/fabric/idemix"
"github.com/pkg/errors"
)
// Revocation encapsulates the idemix algorithms for revocation
type Revocation struct {
}
// NewKey generate a new revocation key-pair.
func (*Revocation) NewKey() (*ecdsa.PrivateKey, error) {
return cryptolib.GenerateLongTermRevocationKey()
}
// Sign generates a new CRI with the respect to the passed unrevoked handles, epoch, and revocation algorithm.
func (*Revocation) Sign(key *ecdsa.PrivateKey, unrevokedHandles [][]byte, epoch int, alg bccsp.RevocationAlgorithm) (res []byte, err error) {
defer func() {
if r := recover(); r != nil {
res = nil
err = errors.Errorf("failure [%s]", r)
}
}()
handles := make([]*FP256BN.BIG, len(unrevokedHandles))
for i := 0; i < len(unrevokedHandles); i++ {
handles[i] = FP256BN.FromBytes(unrevokedHandles[i])
}
cri, err := cryptolib.CreateCRI(key, handles, epoch, cryptolib.RevocationAlgorithm(alg), NewRandOrPanic())
if err != nil {
return nil, errors.WithMessage(err, "failed creating CRI")
}
return proto.Marshal(cri)
}
// Verify checks that the passed serialised CRI (criRaw) is valid with the respect to the passed revocation public key,
// epoch, and revocation algorithm.
func (*Revocation) Verify(pk *ecdsa.PublicKey, criRaw []byte, epoch int, alg bccsp.RevocationAlgorithm) (err error) {
defer func() {
if r := recover(); r != nil {
err = errors.Errorf("failure [%s]", r)
}
}()
cri := &cryptolib.CredentialRevocationInformation{}
err = proto.Unmarshal(criRaw, cri)
if err != nil {
return err
}
return cryptolib.VerifyEpochPK(
pk,
cri.EpochPk,
cri.EpochPkSig,
int(cri.Epoch),
cryptolib.RevocationAlgorithm(cri.RevocationAlg),
)
}
Go
1
https://gitee.com/mirrors/hyperledger-fabric.git
git@gitee.com:mirrors/hyperledger-fabric.git
mirrors
hyperledger-fabric
hyperledger-fabric
v2.1.1

搜索帮助