本文整理匯總了Golang中github.com/dedis/crypto/abstract.Group類的典型用法代碼示例。如果您正苦於以下問題:Golang Group類的具體用法?Golang Group怎麽用?Golang Group使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Group類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: InitNull
// InitNull does the same thing as Init PLUS initialize every points / coef to the Null
// Identity Element so we can use it like a "temp" / "aggregate" variable to add with others poly
func (pub *PubPoly) InitNull(g abstract.Group, k int, b abstract.Point) *PubPoly {
pub.Init(g, k, b)
for i, _ := range pub.p {
pub.p[i] = g.Point().Null()
}
return pub
}
示例2: EncryptPoint
func EncryptPoint(g abstract.Group, msgPt abstract.Point, pk abstract.Point) (abstract.Point, abstract.Point) {
k := g.Scalar().Pick(random.Stream)
c1 := g.Point().Mul(nil, k)
c2 := g.Point().Mul(pk, k)
c2 = c2.Add(c2, msgPt)
return c1, c2
}
示例3: testHiding
func testHiding(g abstract.Group, k int) {
rand := random.Stream
// Test conversion from random strings to points and back
p := g.Point()
p2 := g.Point()
l := p.(abstract.Hiding).HideLen()
buf := make([]byte, l)
for i := 0; i < k; i++ {
rand.XORKeyStream(buf, buf)
//println("R "+hex.EncodeToString(buf))
p.(abstract.Hiding).HideDecode(buf)
//println("P "+p.String())
b2 := p.(abstract.Hiding).HideEncode(rand)
if b2 == nil {
panic("HideEncode failed")
}
//println("R'"+hex.EncodeToString(b2))
p2.(abstract.Hiding).HideDecode(b2)
//println("P'"+p2.String())
if !p.Equal(p2) {
panic("HideDecode produced wrong point")
}
//println("")
}
}
示例4: NewGroupBench
func NewGroupBench(g abstract.Group) *GroupBench {
var gb GroupBench
gb.g = g
gb.x = g.Secret().Pick(random.Stream)
gb.y = g.Secret().Pick(random.Stream)
gb.xe, _ = gb.x.MarshalBinary()
gb.X, _ = g.Point().Pick(nil, random.Stream)
gb.Y, _ = g.Point().Pick(nil, random.Stream)
gb.Xe, _ = gb.X.MarshalBinary()
return &gb
}
示例5: Pick
// Create a fresh sharing polynomial in the Secret space of a given group.
// Shares the provided Secret s, or picks a random one if s == nil.
func (p *PriPoly) Pick(g abstract.Group, k int, s0 abstract.Secret,
rand cipher.Stream) *PriPoly {
p.g = g
s := make([]abstract.Secret, k)
if s0 == nil { // Choose secret to share if none provided
s0 = g.Secret().Pick(rand)
}
s[0] = s0
for i := 1; i < k; i++ {
s[i] = g.Secret().Pick(rand)
}
p.s = s
return p
}
示例6: testScalarClone
func testScalarClone(g abstract.Group, rand cipher.Stream) {
N := 1000
one := g.Scalar().One()
for i := 0; i < N; i++ {
s1 := g.Scalar().Pick(rand)
s2 := s1.Clone()
if !s1.Equal(s2) {
panic("Clone didn't create a scalar s2 with same value as s1's.")
}
if !s1.Equal(one) {
s1.Mul(s1, s1)
if s1.Equal(s2) {
panic("Modifying s1 shouldn't modify s2")
}
}
}
}
示例7: testPointClone
func testPointClone(g abstract.Group, rand cipher.Stream) {
N := 1000
null := g.Point().Null()
for i := 0; i < N; i++ {
P1, _ := g.Point().Pick(nil, rand)
P2 := P1.Clone()
if !P1.Equal(P2) {
panic("Clone didn't create a point with same " +
"coordinates as the original point.")
}
if !P1.Equal(null) {
P1.Add(P1, P1)
if P1.Equal(P2) {
panic("Modifying P1 shouldn't modify P2")
}
}
}
}
示例8: testEmbed
func testEmbed(g abstract.Group, rand cipher.Stream, points *[]abstract.Point,
s string) {
//println("embedding: ",s)
b := []byte(s)
p, rem := g.Point().Pick(b, rand)
//println("embedded, remainder",len(rem),"/",len(b),":",string(rem))
x, err := p.Data()
if err != nil {
panic("Point extraction failed: " + err.Error())
}
//println("extracted data: ",string(x))
if !bytes.Equal(append(x, rem...), b) {
panic("Point embedding corrupted the data")
}
*points = append(*points, p)
}
示例9: thenc
// Simple helper to compute G^{ab-cd} for Theta vector computation.
func thenc(grp abstract.Group, G abstract.Point,
a, b, c, d abstract.Scalar) abstract.Point {
var ab, cd abstract.Scalar
if a != nil {
ab = grp.Scalar().Mul(a, b)
} else {
ab = grp.Scalar().Zero()
}
if c != nil {
if d != nil {
cd = grp.Scalar().Mul(c, d)
} else {
cd = c
}
} else {
cd = grp.Scalar().Zero()
}
return grp.Point().Mul(G, ab.Sub(ab, cd))
}
示例10: Shuffle
func Shuffle(pi []int, group abstract.Group, g, h abstract.Point, X, Y []abstract.Point,
rand cipher.Stream) (XX, YY []abstract.Point, P proof.Prover) {
k := len(X)
if k != len(Y) {
panic("X,Y vectors have inconsistent length")
}
ps := shuffle.PairShuffle{}
ps.Init(group, k)
// Pick a fresh ElGamal blinding factor for each pair
beta := make([]abstract.Scalar, k)
for i := 0; i < k; i++ {
beta[i] = group.Scalar().Pick(rand)
}
// Create the output pair vectors
Xbar := make([]abstract.Point, k)
Ybar := make([]abstract.Point, k)
for i := 0; i < k; i++ {
Xbar[i] = group.Point().Mul(g, beta[pi[i]])
Xbar[i].Add(Xbar[i], X[pi[i]])
Ybar[i] = group.Point().Mul(h, beta[pi[i]])
Ybar[i].Add(Ybar[i], Y[pi[i]])
}
prover := func(ctx proof.ProverContext) error {
return ps.Prove(pi, g, h, beta, X, Y, rand, ctx)
}
return Xbar, Ybar, prover
}
示例11: EncryptKey
func EncryptKey(g abstract.Group, msgPt abstract.Point, pks []abstract.Point) (abstract.Point, abstract.Point) {
k := g.Scalar().Pick(random.Stream)
c1 := g.Point().Mul(nil, k)
var c2 abstract.Point = nil
for _, pk := range pks {
if c2 == nil {
c2 = g.Point().Mul(pk, k)
} else {
c2 = c2.Add(c2, g.Point().Mul(pk, k))
}
}
c2 = c2.Add(c2, msgPt)
return c1, c2
}
示例12: Encrypt
func Encrypt(g abstract.Group, msg []byte, pks []abstract.Point) ([]abstract.Point, []abstract.Point) {
c1s := []abstract.Point{}
c2s := []abstract.Point{}
var msgPt abstract.Point
remainder := msg
for len(remainder) != 0 {
msgPt, remainder = g.Point().Pick(remainder, random.Stream)
k := g.Scalar().Pick(random.Stream)
c1 := g.Point().Mul(nil, k)
var c2 abstract.Point = nil
for _, pk := range pks {
if c2 == nil {
c2 = g.Point().Mul(pk, k)
} else {
c2 = c2.Add(c2, g.Point().Mul(pk, k))
}
}
c2 = c2.Add(c2, msgPt)
c1s = append(c1s, c1)
c2s = append(c2s, c2)
}
return c1s, c2s
}
示例13: testPointSet
func testPointSet(g abstract.Group, rand cipher.Stream) {
N := 1000
null := g.Point().Null()
for i := 0; i < N; i++ {
P1, _ := g.Point().Pick(nil, rand)
P2 := g.Point()
P2.Set(P1)
if !P1.Equal(P2) {
panic("Set() set to a different point.")
}
if !P1.Equal(null) {
P1.Add(P1, P1)
if P1.Equal(P2) {
panic("Modifying P1 shouldn't modify P2")
}
}
}
}
示例14: Decrypt
func Decrypt(g abstract.Group, c1 abstract.Point, c2 abstract.Point, sk abstract.Scalar) abstract.Point {
return g.Point().Sub(c2, g.Point().Mul(c1, sk))
}
示例15:
"github.com/dedis/crypto/abstract"
"github.com/dedis/crypto/edwards"
"github.com/dedis/crypto/random"
)
/* This file is a testing suite for sharing.go. It provides multiple test cases
* for ensuring that encryption schemes built upon this package such as Shamir
* secret sharing are safe and secure.
*
* The tests can also serve as references for how to work with this library.
*/
/* Global Variables */
var group abstract.Group = new(edwards.ExtendedCurve).Init(
edwards.Param25519(), false)
var altGroup abstract.Group = new(edwards.ProjectiveCurve).Init(
edwards.ParamE382(), false)
var k int = 10
var n int = 20
var secret = group.Scalar().Pick(random.Stream)
var point = group.Point().Mul(group.Point().Base(), secret)
var altSecret = altGroup.Scalar().Pick(random.Stream)
var altPoint = altGroup.Point().Mul(altGroup.Point().Base(), altSecret)
/* Setup Functions
*
* These functions provide greater modularity by consolidating commonly used
* setup tasks.
*
* Not every function uses these methods, since they may have unique set-up