crypto/client/schnorr/verify/xuper_sig_verify.go

(开头部分) 3KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

package verify

import (
	//	"bytes"
	"crypto/ecdsa"
	"encoding/asn1"
	"encoding/json"
	"errors"
	"fmt"

	schnorr_ring_sign "github.com/xuperchain/xuperunion/crypto/client/schnorr/ringsign"
	schnorr_sign "github.com/xuperchain/xuperunion/crypto/client/schnorr/sign"
	"github.com/xuperchain/xuperunion/crypto/common"
	"github.com/xuperchain/xuperunion/crypto/config"
	"github.com/xuperchain/xuperunion/crypto/multisign"
	"github.com/xuperchain/xuperunion/crypto/sign"
)

// define errors
var (
	ErrInvalidInputParams        = errors.New("Invalid input params")
	ErrNotExactTheSameCurveInput = errors.New("The private keys of all the keys are not using the the same curve")
	ErrTooSmallNumOfkeys         = errors.New("The total num of keys should be greater than one")
	ErrEmptyMessage              = errors.New("Message to be sign should not be nil")
	ErrInvalidSignature          = errors.New("XuperSignature is invalid")
)

// XuperSigVerify support to verify multiple kinds of signatures
func XuperSigVerify(keys []*ecdsa.PublicKey, signature, message []byte) (bool, error) {
	if len(keys) < 1 {
		return false, fmt.Errorf("no public key found")
	}
	curveName := keys[0].Params().Name
	xuperSig := new(common.XuperSignature)
	err := json.Unmarshal(signature, xuperSig)
	if err != nil {
		return false, err
	}

	// 说明不是统一超级签名的格式
	if err != nil {
		switch curveName {
		case config.CurveNist: // NIST
			verifyResult, err := sign.VerifyECDSA(keys[0], signature, message)
			return verifyResult, err
		case config.CurveNistSN: // NIST + Schnorr
			verifyResult, err := schnorr_sign.Verify(keys[0], signature, message)
			return verifyResult, err
		default: // 不支持的密码学类型
			return false, fmt.Errorf("This cryptography[%v] has not been supported yet", curveName)
		}
	}

	switch xuperSig.SigType {
	// ECDSA签名
	case common.ECDSA:
		if curveName == config.CurveNist {
			verifyResult, err := sign.VerifyECDSA(keys[0], xuperSig.SigContent, message)
			return verifyResult, err
		}
后面还有 47 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。