1 Star 0 Fork 0

闫熊猫/cypherock-internship-assingment-Feldman-vss-algortihm

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
main.go 2.23 KB
一键复制 编辑 原始数据 按行查看 历史
Janani R 提交于 2023-01-04 13:48 . Initial commit
package main
import (
crand "crypto/rand"
"fmt"
"os"
"strconv"
"strings"
"github.com/coinbase/kryptology/pkg/core/curves"
"github.com/coinbase/kryptology/pkg/sharing"
)
func getCurve(t string) *curves.Curve {
s := strings.ToLower(t)
if s == "ed25519" {
return (curves.ED25519())
} else if s == "k256" {
return (curves.K256())
} else if s == "p256" {
return (curves.P256())
} else if s == "pallas" {
return (curves.PALLAS())
}
return curves.ED25519()
}
func main() {
msg := "Hello"
var t uint32 = uint32(3)
var n uint32 = uint32(5)
testCurve := curves.ED25519()
argCount := len(os.Args[1:])
if argCount > 0 {
msg = os.Args[1]
}
if argCount > 1 {
val, err := strconv.Atoi(os.Args[2])
if err == nil {
t = uint32(val)
}
}
if argCount > 2 {
val, err := strconv.Atoi(os.Args[3])
if err == nil {
n = uint32(val)
}
}
if argCount > 3 {
curvetype := os.Args[4]
testCurve = getCurve(curvetype)
}
scheme, _ := sharing.NewFeldman(t, n, testCurve)
secret := testCurve.Scalar.Hash([]byte(msg))
fmt.Printf("=== Feldman Verifiable Secret Shares ===\n")
fmt.Printf("Curve: %s\n", testCurve.Name)
fmt.Printf("\nMessage: %s\nScheme: %d from %d\nOriginal secret: %x\n", msg, t, n, secret.Bytes())
fmt.Printf("\nSplitting shares:\n")
verifiers, shares, _ := scheme.Split(secret, crand.Reader)
for _, s := range shares {
rtn := verifiers.Verify(s)
if rtn == nil {
fmt.Printf(" Share %d: %x [Valid]\n", s.Id, s.Bytes())
}
}
fmt.Printf("\nNow combining with all the shares ...\n")
rSecret, err := scheme.Combine(shares...)
if err == nil {
fmt.Printf("Recovered secret: %x\n", rSecret.Bytes())
} else {
fmt.Printf("Cannot recover from all shares\n")
}
fmt.Printf("\nNow combining with two shares ...\n")
rSecret, err = scheme.Combine(shares[0], shares[1])
if err == nil {
fmt.Printf("Recovered secret: %x\n", rSecret.Bytes())
fmt.Printf("\nNow combining with two shares ...\n")
} else {
fmt.Printf("Cannot recover from two shares\n")
}
fmt.Printf("\nNow combining with three shares ...\n")
rSecret, err = scheme.Combine(shares[0], shares[1], shares[2])
if err == nil {
fmt.Printf("Recovered secret: %x\n", rSecret.Bytes())
} else {
fmt.Printf("Cannot recover from three shares\n")
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/panda-yan/cypherock-internship-assingment-Feldman-vss-algortihm.git
git@gitee.com:panda-yan/cypherock-internship-assingment-Feldman-vss-algortihm.git
panda-yan
cypherock-internship-assingment-Feldman-vss-algortihm
cypherock-internship-assingment-Feldman-vss-algortihm
main

搜索帮助