當前位置: 首頁>>代碼示例>>Golang>>正文


Golang abstract.Secret類代碼示例

本文整理匯總了Golang中github.com/dedis/crypto/abstract.Secret的典型用法代碼示例。如果您正苦於以下問題:Golang Secret類的具體用法?Golang Secret怎麽用?Golang Secret使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Secret類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: SecretMarshalTo

// SecretEncodeTo provides a generic implementation of Secret.EncodeTo
// based on Secret.Encode.
func SecretMarshalTo(s abstract.Secret, w io.Writer) (int, error) {
	buf, err := s.MarshalBinary()
	if err != nil {
		return 0, err
	}
	return w.Write(buf)
}
開發者ID:Liamsi,項目名稱:crypto,代碼行數:9,代碼來源:encoding.go

示例2: 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

示例3: SecretUnmarshalFrom

// SecretDecodeFrom provides a generic implementation of Secret.DecodeFrom,
// based on Secret.Decode, or Secret.Pick if r is a Cipher or cipher.Stream.
// The returned byte-count is valid only when decoding from a normal Reader,
// not when picking from a pseudorandom source.
func SecretUnmarshalFrom(s abstract.Secret, r io.Reader) (int, error) {
	if strm, ok := r.(cipher.Stream); ok {
		s.Pick(strm)
		return -1, nil // no byte-count when picking randomly
	}
	buf := make([]byte, s.MarshalSize())
	n, err := io.ReadFull(r, buf)
	if err != nil {
		return n, err
	}
	return n, s.UnmarshalBinary(buf)
}
開發者ID:Liamsi,項目名稱:crypto,代碼行數:16,代碼來源:encoding.go

示例4: ConstructTree

// ConstructTree does a depth-first construction of the tree specified in the
// config file. ConstructTree must be called AFTER populating the HostConfig with
// ALL the possible hosts.
func ConstructTree(
	n *Node,
	hc *HostConfig,
	parent string,
	suite abstract.Suite,
	rand cipher.Stream,
	hosts map[string]coconet.Host,
	nameToAddr map[string]string,
	opts ConfigOptions) (int, error) {
	// passes up its X_hat, and/or an error

	// get the name associated with this address
	name, ok := nameToAddr[n.Name]
	if !ok {
		fmt.Println("unknown name in address book:", n.Name)
		return 0, errors.New("unknown name in address book")
	}

	// generate indicates whether we should generate the signing
	// node for this hostname
	generate := opts.Host == "" || opts.Host == name

	// check to make sure the this hostname is in the tree
	// it can be backed by a nil pointer
	h, ok := hosts[name]
	if !ok {
		fmt.Println("unknown host in tree:", name)
		return 0, errors.New("unknown host in tree")
	}

	var prikey abstract.Secret
	var pubkey abstract.Point
	var sn *sign.Node

	// if the JSON holds the fields field is set load from there
	if len(n.PubKey) != 0 {
		// log.Println("decoding point")
		encoded, err := hex.DecodeString(string(n.PubKey))
		if err != nil {
			log.Print("failed to decode hex from encoded")
			return 0, err
		}
		pubkey = suite.Point()
		err = pubkey.UnmarshalBinary(encoded)
		if err != nil {
			log.Print("failed to decode point from hex")
			return 0, err
		}
		// log.Println("decoding point")
		encoded, err = hex.DecodeString(string(n.PriKey))
		if err != nil {
			log.Print("failed to decode hex from encoded")
			return 0, err
		}
		prikey = suite.Secret()
		err = prikey.UnmarshalBinary(encoded)
		if err != nil {
			log.Print("failed to decode point from hex")
			return 0, err
		}
	}
	if generate {
		if prikey != nil {
			// if we have been given a private key load that
			aux := sign.NewKeyedNode(h, suite, prikey)
			aux.GenSetPool()
			hc.SNodes = append(hc.SNodes, aux)
			h.SetPubKey(pubkey)
		} else {
			// otherwise generate a random new one
			sn := sign.NewNode(h, suite, rand)
			sn.GenSetPool()
			hc.SNodes = append(hc.SNodes, sn)
			h.SetPubKey(sn.PubKey)
		}
		sn = hc.SNodes[len(hc.SNodes)-1]
		hc.Hosts[name] = sn
		if prikey == nil {
			prikey = sn.PrivKey
			pubkey = sn.PubKey
		}
		// log.Println("pubkey:", sn.PubKey)
		// log.Println("given: ", pubkey)
	}
	// if the parent of this call is empty then this must be the root node
	if parent != "" && generate {
		h.AddParent(0, parent)
	}
	// log.Println("name: ", n.Name)
	// log.Println("prikey: ", prikey)
	// log.Println("pubkey: ", pubkey)
	height := 0
	for _, c := range n.Children {
		// connect this node to its children
		cname, ok := nameToAddr[c.Name]
		if !ok {
			fmt.Println("unknown name in address book:", n.Name)
//.........這裏部分代碼省略.........
開發者ID:ineiti,項目名稱:prifi,代碼行數:101,代碼來源:config.go

示例5: SecretHex

// Encode a secret to hexadecimal
func SecretHex(suite abstract.Suite, secret abstract.Secret) (string, error) {
	sbuf, err := secret.MarshalBinary()
	return hex.EncodeToString(sbuf), err
}
開發者ID:mlncn,項目名稱:cothority,代碼行數:5,代碼來源:key.go


注:本文中的github.com/dedis/crypto/abstract.Secret類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。