/*

--- Key Pair -----------------

*/
420369
func (p *Postgres) AddKey(keyPair *KeyPair) error {
	if err := keyPair.Validate(); err != nil {
		return err
	}

	psql := sq.StatementBuilder.PlaceholderFormat(sq.Dollar)
	sqlQuery, args, err := psql.Insert("kite.key").Columns(
		"id",
		"public",
		"private",
	).Values(keyPair.ID, keyPair.Public, keyPair.Private).ToSql()
	if err != nil {
		return err
	}

	_, err = p.DB.Exec(sqlQuery, args...)
	return err
}
529168
func (s *Set) Keys() []Cid {
	out := make([]Cid, 0, len(s.set))
	for k := range s.set {
		out = append(out, k)
	}
	return out
}
623224
func (s *subkeys) keySchedule(key []byte) {
	var k [16]uint32
	j := 0
	for i := 0; i+4 <= len(key); i += 4 {
		k[j] = uint32(key[i]) | uint32(key[i+1])<<8 | uint32(key[i+2])<<16 | uint32(key[i+3])<<24
		j++
	}
	if j < 8 {
		k[j] = 1
	}

	for i := 8; i < 16; i++ {
		x := k[i-8] ^ k[i-5] ^ k[i-3] ^ k[i-1] ^ phi ^ uint32(i-8)
		k[i] = (x << 11) | (x >> 21)
		s[i-8] = k[i]
	}
	for i := 8; i < 132; i++ {
		x := s[i-8] ^ s[i-5] ^ s[i-3] ^ s[i-1] ^ phi ^ uint32(i)
		s[i] = (x << 11) | (x >> 21)
	}

	sb3(&s[0], &s[1], &s[2], &s[3])
	sb2(&s[4], &s[5], &s[6], &s[7])
	sb1(&s[8], &s[9], &s[10], &s[11])
	sb0(&s[12], &s[13], &s[14], &s[15])
	sb7(&s[16], &s[17], &s[18], &s[19])
	sb6(&s[20], &s[21], &s[22], &s[23])
	sb5(&s[24], &s[25], &s[26], &s[27])
	sb4(&s[28], &s[29], &s[30], &s[31])

	sb3(&s[32], &s[33], &s[34], &s[35])
	sb2(&s[36], &s[37], &s[38], &s[39])
	sb1(&s[40], &s[41], &s[42], &s[43])
	sb0(&s[44], &s[45], &s[46], &s[47])
	sb7(&s[48], &s[49], &s[50], &s[51])
	sb6(&s[52], &s[53], &s[54], &s[55])
	sb5(&s[56], &s[57], &s[58], &s[59])
	sb4(&s[60], &s[61], &s[62], &s[63])

	sb3(&s[64], &s[65], &s[66], &s[67])
	sb2(&s[68], &s[69], &s[70], &s[71])
	sb1(&s[72], &s[73], &s[74], &s[75])
	sb0(&s[76], &s[77], &s[78], &s[79])
	sb7(&s[80], &s[81], &s[82], &s[83])
	sb6(&s[84], &s[85], &s[86], &s[87])
	sb5(&s[88], &s[89], &s[90], &s[91])
	sb4(&s[92], &s[93], &s[94], &s[95])

	sb3(&s[96], &s[97], &s[98], &s[99])
	sb2(&s[100], &s[101], &s[102], &s[103])
	sb1(&s[104], &s[105], &s[106], &s[107])
	sb0(&s[108], &s[109], &s[110], &s[111])
	sb7(&s[112], &s[113], &s[114], &s[115])
	sb6(&s[116], &s[117], &s[118], &s[119])
	sb5(&s[120], &s[121], &s[122], &s[123])
	sb4(&s[124], &s[125], &s[126], &s[127])

	sb3(&s[128], &s[129], &s[130], &s[131])
}
741135
func (mr *modelRef) key() string {
	return mr.spec.name + ":" + mr.model.ModelID()
}
1019090
func (b *BigIP) Keys() (*Keys, error) {
	var keys Keys
	err, _ := b.getForEntity(&keys, uriSys, uriFile, uriSslKey)
	if err != nil {
		return nil, err
	}

	return &keys, nil
}
1292710
func DropKeys(keyvals []interface{}, dropKeyValPredicate func(key, value interface{}) bool) []interface{} {
	keyvalsDropped := make([]interface{}, 0, len(keyvals))
	for i := 0; i < 2*(len(keyvals)/2); i += 2 {
		if !dropKeyValPredicate(keyvals[i], keyvals[i+1]) {
			keyvalsDropped = append(keyvalsDropped, keyvals[i], keyvals[i+1])
		}
	}
	return keyvalsDropped
}
505520
func (s *Session) pair(secret []byte) (smartcardPairing, error) {
	err := s.Channel.Pair(secret)
	if err != nil {
		return smartcardPairing{}, err
	}

	return smartcardPairing{
		PublicKey:    s.Wallet.PublicKey,
		PairingIndex: s.Channel.PairingIndex,
		PairingKey:   s.Channel.PairingKey,
		Accounts:     make(map[common.Address]accounts.DerivationPath),
	}, nil
}
1048530
func (p *Secring) KeyIDs() []string {
	p.Lock()
	defer p.Unlock()

	ids := make([]string, 0, len(p.data.PrivateKeys))
	for _, pk := range p.data.PrivateKeys {
		ids = append(ids, pk.PublicKey.Fingerprint)
	}
	sort.Strings(ids)
	return ids
}
195409
func (c *syncClient) Keys(arg0 string) (result []string, err Error) {
	arg0bytes := []byte(arg0)

	var resp Response
	resp, err = c.conn.ServiceRequest(&KEYS, [][]byte{arg0bytes})
	if err == nil {
		//		result = strings.Split(bytes.NewBuffer(resp.GetBulkData()).String(), " ", 0);
		res := resp.GetMultiBulkData()
		result = make([]string, len(res))
		for i, key_bytes := range res {
			result[i] = string(key_bytes)
		}
	}
	return result, err

}
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
}
887239
func KeysEqual(ak, bk PublicKey) bool {

	//avoid panic if one of the keys is nil, return false instead
	if ak == nil || bk == nil {
		return false
	}

	a := ak.Marshal()
	b := bk.Marshal()
	return (len(a) == len(b) && subtle.ConstantTimeCompare(a, b) == 1)
}
254736
func (c *Client) LockKey(key string) (*Lock, error) {
	opts := &LockOptions{
		Key: key,
	}
	return c.LockOpts(opts)
}
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,
	}
}
919535
func (params Params) Keys() []string {
	length := params.Len()
	keys := make([]string, length)
	i := 0
	for key := range params {
		keys[i] = key
		i++
	}
	return keys
}
319126
func (c *signerInfoContext) Keys() string {
	sort.Strings(c.s.Keys)
	truncatedKeys := []string{}
	if c.trunc {
		for _, keyID := range c.s.Keys {
			truncatedKeys = append(truncatedKeys, stringid.TruncateID(keyID))
		}
		return strings.Join(truncatedKeys, ", ")
	}
	return strings.Join(c.s.Keys, ", ")
}
76057
func (k *Keygen) precomputeKeys() {
	for {
		privPem, pubBytes, err := GenerateKeyPair("")
		if err != nil {
			log.Errorf("Unable to generate key pair: %v.", err)
			continue
		}
		key := keyPair{
			privPem:  privPem,
			pubBytes: pubBytes,
		}

		select {
		case <-k.ctx.Done():
			log.Infof("Stopping key precomputation routine.")
			return
		case k.keysCh <- key:
			continue
		}
	}
}
1017037
func (k *Kontrol) KeyPair() (pair *KeyPair, err error) {
	if k.selfKeyPair != nil {
		return k.selfKeyPair, nil
	}

	kiteKey := k.Kite.KiteKey()

	if kiteKey == "" || len(k.lastPublic) == 0 {
		return nil, errNoSelfKeyPair
	}

	keyIndex := -1

	me := new(multiError)

	for i := range k.lastPublic {
		ri := len(k.lastPublic) - i - 1

		keyFn := func(token *jwt.Token) (interface{}, error) {
			if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
				return nil, errors.New("invalid signing method")
			}

			return jwt.ParseRSAPublicKeyFromPEM([]byte(k.lastPublic[ri]))
		}

		if _, err := jwt.ParseWithClaims(kiteKey, &kitekey.KiteClaims{}, keyFn); err != nil {
			me.err = append(me.err, err)
			continue
		}

		keyIndex = ri
		break
	}

	if keyIndex == -1 {
		return nil, fmt.Errorf("no matching self key pair found: %s", me)
	}

	k.selfKeyPair = &KeyPair{
		ID:      k.lastIDs[keyIndex],
		Public:  k.lastPublic[keyIndex],
		Private: k.lastPrivate[keyIndex],
	}

	return k.selfKeyPair, nil
}