This commit is contained in:
bryanqiu 2022-12-03 19:54:11 +08:00
parent 8d97cdae89
commit cecc2cfffe

12
zkp.go
View File

@ -74,7 +74,7 @@ func DLogProve(sk *big.Int) (proof *DLogProof, err error) {
// return // return
proof = &DLogProof{ proof = &DLogProof{
RandomPoint: fmt.Sprintf("%x,%x", pkr.X, pkr.Y), RandomPoint: fmt.Sprintf("%064x,%064x", pkr.X, pkr.Y),
ChallengeResponse: (*big_Int)(cr), ChallengeResponse: (*big_Int)(cr),
} }
return proof, nil return proof, nil
@ -91,12 +91,12 @@ func DLogVerify(pkstr string, proof *DLogProof) bool {
// Step 0. get pk & pkr // Step 0. get pk & pkr
var pk, err1 = HexStringToS256Point(pkstr) var pk, err1 = HexStringToS256Point(pkstr)
if err1 != nil { if err1 != nil {
//errors.New("input pk is invalid") log.Infof("input pk is invalid: %s, pk=[%s]", err1, pkstr)
return false return false
} }
var pkr, err2 = HexStringToS256Point(proof.RandomPoint) var pkr, err2 = HexStringToS256Point(proof.RandomPoint)
if err2 != nil { if err2 != nil {
//errors.New("input pkr is invalid") log.Infof("input pkr is invalid: %s, pkr=[%s]", err2, proof.RandomPoint)
return false return false
} }
@ -131,11 +131,11 @@ func DLogVerify(pkstr string, proof *DLogProof) bool {
func HexStringToS256Point(pstr string) (*ecdsa.PublicKey, error) { func HexStringToS256Point(pstr string) (*ecdsa.PublicKey, error) {
var pk = ecdsa.PublicKey{Curve: crypto.S256()} var pk = ecdsa.PublicKey{Curve: crypto.S256()}
if x2y2 := strings.Split(pstr, ","); len(x2y2) != 2 { if x2y2 := strings.Split(pstr, ","); len(x2y2) != 2 {
return nil, errors.New("input pk is invalid") return nil, errors.New("input point is invalid")
} else if x, err := hex.DecodeString(x2y2[0]); err != nil { } else if x, err := hex.DecodeString(x2y2[0]); err != nil {
return nil, errors.New("input pk.x is invalid") return nil, fmt.Errorf("input point.x is invalid: [%s]", err)
} else if y, err := hex.DecodeString(x2y2[1]); err != nil { } else if y, err := hex.DecodeString(x2y2[1]); err != nil {
return nil, errors.New("input pk.y is invalid") return nil, fmt.Errorf("input point.y is invalid: [%s]", err)
} else { } else {
pk.X = new(big.Int).SetBytes(x) pk.X = new(big.Int).SetBytes(x)
pk.Y = new(big.Int).SetBytes(y) pk.Y = new(big.Int).SetBytes(y)