admin管理员组文章数量:1565351
golang 实现的EC pederson-commitment
EC 曲线使用的是 Edwards25519,由 go-ristretto 包提供,文档参考 https://pkg.go.dev/github/bwesterb/go-ristretto?tab=doc ,GitHub库 https://github/bwesterb/go-ristretto
另外参考了 https://github/threehook/go-pedersen-commitment 的实现,这里的封装是为了实现我自己的一些需求,同时也分享出来给需要的朋友
pederson-commitment 原论文可见 https://link.springer/content/pdf/10.1007%2F3-540-46766-1_9.pdf
下面直接上代码了,里面涉及到转字符串的都是是由标准库hex来转,要参考的话需要先导包 “github/bwesterb/go-ristretto” ,直接去github下来放到GOPATH下即可
package go_ec_pederson_commitment
import (
"encoding/hex"
"github/bwesterb/go-ristretto"
"math/big"
)
/**
基于EC的 pederson commitment
原论文:Non-Interactive and Information-Theoretic Secure Verifiable Secret Sharing
在原论文里是基于循环群的实现,说的是g,h是群里的元素,没有人知道log_g(h)
对应到椭圆曲线的话,就是对G、H的要求是G和H是椭圆曲线上的点,没有人知道 H=aG 中a的值,那么G和H都采用随机选取的方式,应该是满足要求的?! 或者更简单的方式就是G使用基点,H随机选,这里采用都随机生成的方式
秘密x,随机数r, G和H是椭圆曲线上的随机的点, --> c = xG + rH
G,H 由被承诺方选定,r由承诺方选定
*/
//生成两个曲线上的点,用于计算承诺
func ParamsGen() (G, H ristretto.Point) {
G.Rand()
H.Rand()
return G, H
}
func ParamsGenToString() (GString, HString string) {
var G, H ristretto.Point
G.Rand()
H.Rand()
GBytes, _ := G.MarshalText()
HBytes, _ := H.MarshalText()
GString = hex.EncodeToString(GBytes)
HString = hex.EncodeToString(HBytes)
return
}
//生成一个随机阶数
func RandomGen() (r ristretto.Scalar) {
r.Rand()
return r
}
func RandomGenToNumberString() string {
var r ristretto.Scalar
r.Rand()
return r.BigInt().String()
}
//计算 秘密 的 Pederson 承诺, 返回曲线上的点
func Commit(G,
本文标签: 椭圆曲线Golangpedersoncommitment
版权声明:本文标题:golang pederson commitment 实现,基于椭圆曲线 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1726703631a1081410.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论