From 8d97cdae896fdb730f0164683d661433764f7b0b Mon Sep 17 00:00:00 2001 From: bryanqiu Date: Tue, 15 Nov 2022 15:18:16 +0800 Subject: [PATCH] debug --- zkp.go | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/zkp.go b/zkp.go index a3df908..a967709 100644 --- a/zkp.go +++ b/zkp.go @@ -15,9 +15,21 @@ import ( ) type DLogProof struct { - ChallengeResponse *big_Int `json:"cr"` - ChallengeResponseXXXX *big.Int `json:"cr___TODO______debug"` - RandomPoint string `json:"pkr"` + ChallengeResponse *big_Int `json:"cr"` + RandomPoint string `json:"pkr"` +} + +func (dlogproof *DLogProof) ToString() string { + var b, _ = json.Marshal(dlogproof) + return string(b) +} + +func DLogProofFromString(jsonstr string) (*DLogProof, error) { + var proof = DLogProof{} + if err := json.Unmarshal([]byte(jsonstr), &proof); err != nil { + return nil, err + } + return &proof, nil } /* @@ -48,7 +60,8 @@ func DLogProve(sk *big.Int) (proof *DLogProof, err error) { // Step 2. caculate challenge: c = SHA256(pkr || G || pk) challenge := fmt.Sprintf( - "%x,%x@%x,%x@%x,%x", pkr.X, pkr.Y, Gx, Gy, pk.X, pk.Y) + "%064x,%064x@%064x,%064x@%064x,%064x", + pkr.X, pkr.Y, Gx, Gy, pk.X, pk.Y) chash256 := sha256.Sum256([]byte(challenge)) var c = new(big.Int).SetBytes(chash256[:]) log.Debugf("challenge='%s',c='%x'", challenge, c) @@ -61,9 +74,8 @@ func DLogProve(sk *big.Int) (proof *DLogProof, err error) { // return proof = &DLogProof{ - RandomPoint: fmt.Sprintf("%x,%x", pkr.X, pkr.Y), - ChallengeResponse: (*big_Int)(cr), - ChallengeResponseXXXX: cr, + RandomPoint: fmt.Sprintf("%x,%x", pkr.X, pkr.Y), + ChallengeResponse: (*big_Int)(cr), } return proof, nil } @@ -93,7 +105,8 @@ func DLogVerify(pkstr string, proof *DLogProof) bool { Gx := cv.Params().Gx Gy := cv.Params().Gy challenge := fmt.Sprintf( - "%x,%x@%x,%x@%x,%x", pkr.X, pkr.Y, Gx, Gy, pk.X, pk.Y) + "%064x,%064x@%064x,%064x@%064x,%064x", + pkr.X, pkr.Y, Gx, Gy, pk.X, pk.Y) chash256 := sha256.Sum256([]byte(challenge)) var c = new(big.Int).SetBytes(chash256[:]) var cr = (*big.Int)(proof.ChallengeResponse) @@ -129,16 +142,3 @@ func HexStringToS256Point(pstr string) (*ecdsa.PublicKey, error) { } return &pk, nil } - -func (dlogproof *DLogProof) ToString() string { - var b, _ = json.Marshal(dlogproof) - return string(b) -} - -func DLogProofFromString(jsonstr string) (*DLogProof, error) { - var proof = DLogProof{} - if err := json.Unmarshal([]byte(jsonstr), &proof); err != nil { - return nil, err - } - return &proof, nil -}