// Key computes a new private key from the given subseed using the given security level.
// Optionally takes the SpongeFunction to use. Default is Kerl.
329926
func Key(subseed Trits, securityLevel SecurityLevel, spongeFunc ...SpongeFunction) (Trits, error) {
	h := GetSpongeFunc(spongeFunc, kerl.NewKerl)
	defer h.Reset()

	keyLength := KeyFragmentLength * int(securityLevel)
	key := make(Trits, keyLength)

	err := h.Absorb(subseed)
	if err != nil {
		return nil, err
	}

	key, err = h.Squeeze(keyLength)
	if err != nil {
		return nil, err
	}

	h.Reset()

	for i := 0; i < KeyFragmentLength*int(securityLevel); i += HashTrinarySize {
		if err := h.Absorb(key[i : i+HashTrinarySize]); err != nil {
			return nil, err
		}

		buf, err := h.Squeeze(HashTrinarySize)
		if err != nil {
			return nil, err
		}
		copy(key[i:], buf)

		h.Reset()
	}

	return key, nil
}
1050890
func (k *KeySet) Key(pairs ...string) (*Key, error) {
	switch {
	case len(pairs) == 0:
		return nil, fmt.Errorf("empty key path")
	case len(pairs)%2 != 0:
		return nil, fmt.Errorf("key path %q has odd number of components", pairs)
	}

	for _, s := range pairs {
		if strings.IndexByte(s, 0) != -1 {
			return nil, fmt.Errorf("bad key path element %q, has zero byte inside", s)
		}
	}

	keyID := strings.Join(pairs, "\x00")
	if key := k.keys[keyID]; key != nil {
		return key, nil
	}

	if k.keys == nil {
		k.keys = make(map[string]*Key, 1)
	}

	key := &Key{set: k, pairs: pairs, idx: len(k.keys), cmp: keyID}
	k.keys[keyID] = key
	return key, nil
}
29820
func NewKey(pub crypto.PublicKey, priv crypto.PrivateKey) *Key {
	return &Key{Public: pub, Private: priv}
}
412502
func (key *Key) PublicKey() *Key {
	keyBytes := key.Key

	if key.IsPrivate {
		keyBytes = publicKeyForPrivateKey(keyBytes)
	}

	return &Key{
		Version:     PublicWalletVersion,
		Key:         keyBytes,
		Depth:       key.Depth,
		ChildNumber: key.ChildNumber,
		FingerPrint: key.FingerPrint,
		ChainCode:   key.ChainCode,
		IsPrivate:   false,
	}
}
862576
func (v Map) Key(k string) Value {
	var result, ok = v[k]
	if !ok {
		return Undefined{}
	}
	return result
}
475246
func (privKey PrivKeySecp256k1) PubKey() crypto.PubKey {
	_, pubkeyObject := secp256k1.PrivKeyFromBytes(secp256k1.S256(), privKey[:])
	var pubkeyBytes PubKeySecp256k1
	copy(pubkeyBytes[:], pubkeyObject.SerializeCompressed())
	return pubkeyBytes
}
1245656
func (h *Handle) Key() []string {
	h.Lock()
	defer h.Unlock()
	return []string{h.app, h.id}
}
281896
func (c *objectCache) key(namespace, name string) string {
	if len(namespace) > 0 {
		return namespace + "/" + name
	}
	return name
}
1355697
func (privKey PrivKeyEd25519) PubKey() crypto.PubKey {
	privKeyBytes := [64]byte(privKey)
	initialized := false
	// If the latter 32 bytes of the privkey are all zero, compute the pubkey
	// otherwise privkey is initialized and we can use the cached value inside
	// of the private key.
	for _, v := range privKeyBytes[32:] {
		if v != 0 {
			initialized = true
			break
		}
	}

	if !initialized {
		panic("Expected PrivKeyEd25519 to include concatenated pubkey bytes")
	}

	var pubkeyBytes [PubKeyEd25519Size]byte
	copy(pubkeyBytes[:], privKeyBytes[32:])
	return PubKeyEd25519(pubkeyBytes)
}
787702
func (itr *goLevelDBIterator) Key() []byte {
	// Key returns a copy of the current key.
	// See https://github.com/syndtr/goleveldb/blob/52c212e6c196a1404ea59592d3f1c227c9f034b2/leveldb/iterator/iter.go#L88
	itr.assertNoError()
	itr.assertIsValid()
	return cp(itr.source.Key())
}
860065
func (ru *RelationUnit) key() string {
	return ru._key(string(ru.endpoint.Role), ru.unitName)
}
759414
func SharedKey(secretKey [32]byte, publicKey [32]byte) ([32]byte, error) {
	var sharedKey [32]byte
	curve25519.ScalarMult(&sharedKey, &secretKey, &publicKey)
	c := byte(0)
	for i := 0; i < 32; i++ {
		c |= sharedKey[i]
	}
	if c == 0 {
		return sharedKey, errors.New("weak public key")
	}
	var nonce [16]byte
	chacha.HChaCha20(&sharedKey, &nonce, &sharedKey)
	return sharedKey, nil
}
663452
func (m *Multisig) Key(seed Trytes, index uint64, security SecurityLevel, spongeFunc ...SpongeFunction) (Trytes, error) {
	h := GetSpongeFunc(spongeFunc, kerl.NewKerl)

	subseed, err := signing.Subseed(seed, index, h)
	if err != nil {
		return "", err
	}

	keyTrits, err := signing.Key(subseed, security, h)
	if err != nil {
		return "", err
	}

	return MustTritsToTrytes(keyTrits), nil
}
508265
func (p *siprng) rekey() {
	var k [16]byte
	if _, err := io.ReadFull(rand.Reader, k[:]); err != nil {
		panic(err.Error())
	}
	p.k0 = binary.LittleEndian.Uint64(k[0:8])
	p.k1 = binary.LittleEndian.Uint64(k[8:16])
	p.ctr = 1
}
351891
func HashKey(key []byte) int64 {
	h := int64(xxhash.Sum64(key))
	if h == 0 {
		h = 1
	} else if h < 0 {
		h = 0 - h
	}
	return h
}
1142407
func (s *dirStore) key(parent, scope string) string {
	data := scope + "." + parent
	sum := md5.Sum([]byte(data))
	return hex.EncodeToString(sum[:])
}
7121
func (v *VserverEntry) Key() string {
	return fmt.Sprintf("%d/%s", v.Port, v.Proto)
}