debug
This commit is contained in:
parent
a1ade9e06f
commit
8d97cdae89
42
zkp.go
42
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user