debug
This commit is contained in:
parent
a1ade9e06f
commit
8d97cdae89
34
zkp.go
34
zkp.go
@ -16,10 +16,22 @@ import (
|
||||
|
||||
type DLogProof struct {
|
||||
ChallengeResponse *big_Int `json:"cr"`
|
||||
ChallengeResponseXXXX *big.Int `json:"cr___TODO______debug"`
|
||||
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
|
||||
}
|
||||
|
||||
/*
|
||||
* Prove:
|
||||
* step 1. generate random bignumber: skr, let pkr = skr * G
|
||||
@ -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)
|
||||
@ -63,7 +76,6 @@ func DLogProve(sk *big.Int) (proof *DLogProof, err error) {
|
||||
proof = &DLogProof{
|
||||
RandomPoint: fmt.Sprintf("%x,%x", pkr.X, pkr.Y),
|
||||
ChallengeResponse: (*big_Int)(cr),
|
||||
ChallengeResponseXXXX: 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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user