当前位置: 首页>>代码示例>>Golang>>正文


Golang Suite.Secret方法代码示例

本文整理汇总了Golang中github.com/dedis/crypto/abstract.Suite.Secret方法的典型用法代码示例。如果您正苦于以下问题:Golang Suite.Secret方法的具体用法?Golang Suite.Secret怎么用?Golang Suite.Secret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/dedis/crypto/abstract.Suite的用法示例。


在下文中一共展示了Suite.Secret方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: NewNode

func NewNode(hn coconet.Host, suite abstract.Suite, random cipher.Stream) *Node {
	sn := &Node{Host: hn, suite: suite}
	sn.PrivKey = suite.Secret().Pick(random)
	sn.PubKey = suite.Point().Mul(nil, sn.PrivKey)

	sn.peerKeys = make(map[string]abstract.Point)

	sn.closed = make(chan error, 20)
	sn.done = make(chan int, 10)
	sn.commitsDone = make(chan int, 10)
	sn.viewChangeCh = make(chan string, 0)

	sn.RoundCommits = make(map[int][]*SigningMessage)
	sn.RoundResponses = make(map[int][]*SigningMessage)
	sn.FailureRate = 0
	h := fnv.New32a()
	h.Write([]byte(hn.Name()))
	seed := h.Sum32()
	sn.Rand = rand.New(rand.NewSource(int64(seed)))
	sn.Host.SetSuite(suite)
	sn.VoteLog = NewVoteLog()
	sn.Actions = make(map[int][]*Vote)
	sn.RoundsPerView = 0
	sn.Rounds = make(map[int]Round)
	sn.MaxWait = 50 * time.Second
	return sn
}
开发者ID:mlncn,项目名称:cothority,代码行数:27,代码来源:nodehelper.go

示例2: GenerateZ

/* GenerateZ takes some random agreed information and creates
   Z the "public-only" key that is witness-independent as per
   the paper. We've probably broken that slightly in this implementation
   because I could not pick a point without generating it
   via a Secret, instead of directly via a Point - that is, even as a
   32-byte string, we cannot decode on C25519 (and this wouldn't work
   for abstract suites anyway).

   However, it demonstrates the idea.
*/
func GenerateZ(suite abstract.Suite, info []byte) (abstract.Point, error) {

	hasher := sha3.New256()
	hasher.Write(info)
	zraw := hasher.Sum(nil)

	//I think this might be cheating
	zrawCt := suite.Cipher(zraw)

	zfactor := suite.Secret().Pick(zrawCt)
	Z := suite.Point()
	Z.Mul(nil, zfactor)

	// every 32-bit integer exists on Curve25519 only if we have the fullgroup
	// this should work, but doesn't.

	/*var Z abstract.Point
	  zrawBuf := bytes.NewBuffer(zraw)
	  err := abstract.Read(zrawBuf, &Z, suite);
	  if err != nil {
	      return nil, err
	  }*/

	return Z, nil
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:35,代码来源:partialBlind.go

示例3: Biffle

// Binary shuffle ("biffle") for 2 ciphertexts based on general ZKPs.
func Biffle(suite abstract.Suite, G, H abstract.Point,
	X, Y [2]abstract.Point, rand abstract.Cipher) (
	Xbar, Ybar [2]abstract.Point, prover proof.Prover) {

	// Pick the single-bit permutation.
	bit := int(random.Byte(rand) & 1)

	// Pick a fresh ElGamal blinding factor for each pair
	var beta [2]abstract.Secret
	for i := 0; i < 2; i++ {
		beta[i] = suite.Secret().Pick(rand)
	}

	// Create the output pair vectors
	for i := 0; i < 2; i++ {
		pi_i := i ^ bit
		Xbar[i] = suite.Point().Mul(G, beta[pi_i])
		Xbar[i].Add(Xbar[i], X[pi_i])
		Ybar[i] = suite.Point().Mul(H, beta[pi_i])
		Ybar[i].Add(Ybar[i], Y[pi_i])
	}

	or := bifflePred()
	secrets := map[string]abstract.Secret{
		"beta0": beta[0],
		"beta1": beta[1]}
	points := bifflePoints(suite, G, H, X, Y, Xbar, Ybar)
	choice := map[proof.Predicate]int{or: bit}
	prover = or.Prover(suite, secrets, points, choice)
	return
}
开发者ID:Liamsi,项目名称:crypto,代码行数:32,代码来源:biffle.go

示例4: SchnorrVerify

// Checks the signature against
// the message
func SchnorrVerify(suite abstract.Suite,
	kp SchnorrPublicKey,
	msg []byte, sig []byte) (bool, error) {

	buf := bytes.NewBuffer(sig)
	signature := SchnorrSignature{}
	err := abstract.Read(buf, &signature, suite)
	if err != nil {
		return false, err
	}

	s := signature.S
	e := signature.E

	var gs, ye, r abstract.Point
	gs = suite.Point().Mul(nil, s)  // g^s
	ye = suite.Point().Mul(kp.Y, e) // y^e
	r = suite.Point().Add(gs, ye)   // g^xy^e

	r_bin, _ := r.MarshalBinary()
	msg_and_r := append(msg, r_bin...)
	hasher := sha3.New256()
	hasher.Write(msg_and_r)
	h := hasher.Sum(nil)

	// again I'm hoping this just reads the state out
	// and doesn't  actually perform any ops
	lct := suite.Cipher(h)

	ev := suite.Secret().Pick(lct)
	return ev.Equal(e), nil
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:34,代码来源:schnorr.go

示例5: ServerGenerateResponse

/* The servergenerateresponse function is fairly self explanatory - this function provides an answer
   to the challenge message provided by the user. */
func ServerGenerateResponse(suite abstract.Suite, challenge WISchnorrChallengeMessage, privateParameters WISchnorrBlindPrivateParams, privKey SchnorrKeyset) WISchnorrResponseMessage {

	c := suite.Secret()
	c.Sub(challenge.E, privateParameters.D)
	r := suite.Secret()
	r.Mul(c, privKey.X).Sub(privateParameters.U, r)

	return WISchnorrResponseMessage{r, c, privateParameters.S, privateParameters.D}
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:11,代码来源:partialBlind.go

示例6: ReadSecretHex

// Read a secret in hexadceimal from string
func ReadSecretHex(suite abstract.Suite, str string) (abstract.Secret, error) {
	enc, err := hex.DecodeString(str)
	if err != nil {
		return nil, err
	}
	sec := suite.Secret()
	err = sec.UnmarshalBinary(enc)
	return sec, err
}
开发者ID:mlncn,项目名称:cothority,代码行数:10,代码来源:key.go

示例7: GenerateKeyPair

// GenerateKeyPair generates a new random private/public keypair in the specified group
func GenerateKeyPair(suite abstract.Suite) (*PriKey, *PubKey) {
	secret := suite.Secret().Pick(suite.Cipher(nil))
	base := suite.Point().Base()

	pk := PubKey{suite, base, suite.Point().Mul(base, secret)}
	sk := PriKey{pk, secret}

	return &sk, &pk
}
开发者ID:confiks,项目名称:ipfs-dc,代码行数:10,代码来源:elgamal.go

示例8: GenKeys

// generate keys for the tree
func (t *Tree) GenKeys(suite abstract.Suite, rand abstract.Cipher) {
	t.TraverseTree(func(t *Tree) {
		PrivKey := suite.Secret().Pick(rand)
		PubKey := suite.Point().Mul(nil, PrivKey)
		prk, _ := PrivKey.MarshalBinary()
		pbk, _ := PubKey.MarshalBinary()
		t.PriKey = string(hex.EncodeToString(prk))
		t.PubKey = string(hex.EncodeToString(pbk))
	})
}
开发者ID:Liamsi,项目名称:cothority,代码行数:11,代码来源:tree.go

示例9: SchnorrMUnmarshallCCComputeResponse

// (Server side) This function reads the collective challenge
// from the wire, generates and serializes a response
// to that as a raw "secret"
func SchnorrMUnmarshallCCComputeResponse(suite abstract.Suite,
	kv SchnorrKeyset,
	privatecommit SchnorrMPrivateCommitment,
	cc []byte) SchnorrMResponse {
	hct := suite.Cipher(cc)
	c := suite.Secret().Pick(hct)
	r := suite.Secret()
	r.Mul(c, kv.X).Sub(privatecommit.V, r)

	return SchnorrMResponse{r}
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:14,代码来源:multisignatures.go

示例10: signH1

func signH1(suite abstract.Suite, H1pre abstract.Cipher, PG, PH abstract.Point) abstract.Secret {
	H1 := H1pre.Clone()
	PGb, _ := PG.MarshalBinary()
	H1.Write(PGb)
	if PH != nil {
		PHb, _ := PH.MarshalBinary()
		H1.Write(PHb)
	}
	H1.Message(nil, nil, nil) // finish message absorption
	return suite.Secret().Pick(H1)
}
开发者ID:eftychis,项目名称:crypto-1,代码行数:11,代码来源:sig.go

示例11: ClientSignBlindly

/* This is the function that given the client's challenge and response from the server is able to
   compute the final blind signature. This is done on the user side (blindly to the signer). */
func ClientSignBlindly(suite abstract.Suite, clientParameters WISchnorrClientParamersList, responseMsg WISchnorrResponseMessage, pubKey SchnorrPublicKey, msg []byte) (WIBlindSignature, bool) {

	rho := suite.Secret()
	omega := suite.Secret()
	sigma := suite.Secret()
	delta := suite.Secret()

	rho.Add(responseMsg.R, clientParameters.T1)
	omega.Add(responseMsg.C, clientParameters.T2)
	sigma.Add(responseMsg.S, clientParameters.T3)
	delta.Add(responseMsg.D, clientParameters.T4)

	gp := suite.Point()
	gp.Mul(nil, rho)

	yw := suite.Point()
	yw.Mul(pubKey.Y, omega)
	gpyw := suite.Point()

	gpyw.Add(gp, yw)
	bGpyw, _ := gpyw.MarshalBinary()

	gs := suite.Point()
	gs.Mul(nil, sigma)
	zd := suite.Point()
	zd.Mul(clientParameters.Z, delta)
	gszd := suite.Point()
	gszd.Add(gs, zd)
	bGszd, _ := gszd.MarshalBinary()

	bZ, _ := clientParameters.Z.MarshalBinary()

	var combinedmsg []byte

	combinedmsg = append(combinedmsg, bGpyw...)
	combinedmsg = append(combinedmsg, bGszd...)
	combinedmsg = append(combinedmsg, bZ...)
	combinedmsg = append(combinedmsg, msg...)

	hasher := sha3.New256()
	hasher.Write(combinedmsg)
	bSig := hasher.Sum(nil)
	bSigCt := suite.Cipher(bSig)

	sig := suite.Secret().Pick(bSigCt)

	vsig := suite.Secret()
	vsig.Add(omega, delta)

	//fmt.Println(sig)
	//fmt.Println(vsig)

	return WIBlindSignature{rho, omega, sigma, delta}, sig.Equal(vsig)
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:56,代码来源:partialBlind.go

示例12: ElGamalEncrypt

func ElGamalEncrypt(suite abstract.Suite, pubkey abstract.Point, M abstract.Point) (
	K, C abstract.Point, remainder []byte) {

	// Embed the message (or as much of it as will fit) into a curve point.
	//M, remainder := suite.Point().Pick(message, random.Stream)

	// ElGamal-encrypt the point to produce ciphertext (K,C).
	k := suite.Secret().Pick(random.Stream) // ephemeral private key
	K = suite.Point().Mul(nil, k)           // ephemeral DH public key
	S := suite.Point().Mul(pubkey, k)       // ephemeral DH shared secret
	C = S.Add(S, M)                         // message blinded with secret
	return
}
开发者ID:anonyreputation,项目名称:anonCred,代码行数:13,代码来源:Util.go

示例13: SchnorrGenerateKeypair

// The schnorrGenerateKeypair does exactly that -
// it generates a valid keypair for later use
// in producing signatures.
// I wanted to add a little bit of proper key
// management to the process but I couldn't work out
// how to pass a simple random stream to suite.Secret().Pick().
// I looked into Go streams very briefly  but decided
// I was spending too much time on that
// instead I passed /dev/urandom through the cipher
// interface.
func SchnorrGenerateKeypair(suite abstract.Suite) (SchnorrKeyset, error) {
	rsource := make([]byte, 16)
	_, err := rand.Read(rsource)
	if err != nil {
		return SchnorrKeyset{}, err
	}

	rct := suite.Cipher(rsource)

	x := suite.Secret().Pick(rct)  // some x
	y := suite.Point().Mul(nil, x) // y = g^x \in G, DLP.

	return SchnorrKeyset{x, y}, nil
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:24,代码来源:schnorr.go

示例14: SchnorrMComputeSignatureFromResponses

// this function produces a signature given a response from the server.
func SchnorrMComputeSignatureFromResponses(suite abstract.Suite,
	cc []byte,
	responses []SchnorrMResponse) SchnorrSignature {
	hct := suite.Cipher(cc)
	c := suite.Secret().Pick(hct) // H(m||r)

	var r abstract.Secret = responses[0].R

	for _, response := range responses[1:] {
		r.Add(r, response.R)
	}

	return SchnorrSignature{S: r, E: c}
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:15,代码来源:multisignatures.go

示例15: SchnorrMGenerateCommitment

func SchnorrMGenerateCommitment(suite abstract.Suite) (SchnorrMPrivateCommitment, error) {
	rsource := make([]byte, 16)
	_, err := rand.Read(rsource)
	if err != nil {
		return SchnorrMPrivateCommitment{}, err
	}
	// I have no idea if I just encrypted randomness or not
	// I'm hoping this just reads the state out.
	rct := suite.Cipher(rsource)

	v := suite.Secret().Pick(rct)  // some v
	t := suite.Point().Mul(nil, v) // g^v = t
	return SchnorrMPrivateCommitment{T: t, V: v}, nil
}
开发者ID:diagprov,项目名称:interview-go-multisigs,代码行数:14,代码来源:multisignatures.go


注:本文中的github.com/dedis/crypto/abstract.Suite.Secret方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。