// skeletonProof generates a partial key proof structure that device Y can
// fill in. When verifying the reverse signature we fill in the values from Y
// to check the reverse signature
493300
func (e *Kex2Provisioner) skeletonProof(m libkb.MetaContext) (sigBody string, err error) {

	// Set the local sigchain guard to tell background tasks
	// to stay off the sigchain while we do this.
	// This is released at the end of Kex2Provisioner#Run
	e.G().LocalSigchainGuard().Set(context.TODO(), "Kex2Provisioner")

	// reload the self user to make sure it is fresh
	// (this fixes TestProvisionWithRevoke [CORE-5631, CORE-5636])
	if err := e.loadMe(); err != nil {
		return "", err
	}

	delg := libkb.Delegator{
		ExistingKey:    e.signingKey,
		Me:             e.me,
		DelegationType: libkb.DelegationTypeSibkey,
		Expire:         libkb.NaclEdDSAExpireIn,
		Contextified:   libkb.NewContextified(e.G()),
	}

	e.proof, err = libkb.KeyProof(m, delg)
	if err != nil {
		return "", err
	}
	body, err := e.proof.Marshal()
	if err != nil {
		return "", err
	}
	return string(body), nil
}
426297
func (t *ImmutableTree) GetRangeWithProof(startKey []byte, endKey []byte, limit int) (keys, values [][]byte, proof *RangeProof, err error) {
	proof, keys, values, err = t.getRangeProof(startKey, endKey, limit)
	return
}
283680
func (proof *RangeProof) VerifyAbsence(key []byte) error {
	if proof == nil {
		return cmn.ErrorWrap(ErrInvalidProof, "proof is nil")
	}
	if !proof.rootVerified {
		return cmn.NewError("must call Verify(root) first.")
	}
	cmp := bytes.Compare(key, proof.Leaves[0].Key)
	if cmp < 0 {
		if proof.LeftPath.isLeftmost() {
			return nil
		} else {
			return cmn.NewError("absence not proved by left path")
		}
	} else if cmp == 0 {
		return cmn.NewError("absence disproved via first item #0")
	}
	if len(proof.LeftPath) == 0 {
		return nil // proof ok
	}
	if proof.LeftPath.isRightmost() {
		return nil
	}

	// See if any of the leaves are greater than key.
	for i := 1; i < len(proof.Leaves); i++ {
		leaf := proof.Leaves[i]
		cmp := bytes.Compare(key, leaf.Key)
		if cmp < 0 {
			return nil // proof ok
		} else if cmp == 0 {
			return cmn.NewError("absence disproved via item #%v", i)
		} else {
			if i == len(proof.Leaves)-1 {
				// If last item, check whether
				// it's the last item in teh tree.

			}
			continue
		}
	}

	// It's still a valid proof if our last leaf is the rightmost child.
	if proof.treeEnd {
		return nil // OK!
	}

	// It's not a valid absence proof.
	if len(proof.Leaves) < 2 {
		return cmn.NewError("absence not proved by right leaf (need another leaf?)")
	} else {
		return cmn.NewError("absence not proved by right leaf")
	}
}
1285319
func (r *ChannelRouter) AddProof(chanID lnwire.ShortChannelID,
	proof *channeldb.ChannelAuthProof) error {

	info, _, _, err := r.cfg.Graph.FetchChannelEdgesByID(chanID.ToUint64())
	if err != nil {
		return err
	}

	info.AuthProof = proof
	return r.cfg.Graph.UpdateChannelEdge(info)
}
821196
func (ph *ProveHandler) CheckProof(ctx context.Context, arg keybase1.CheckProofArg) (res keybase1.CheckProofStatus, err error) {
	ctx = libkb.WithLogTag(ctx, "PV")
	defer ph.G().CTraceTimed(ctx, fmt.Sprintf("CheckProof: SigID: %v", arg.SigID), func() error { return err })()
	eng := engine.NewProveCheck(ph.G(), arg.SigID)
	m := libkb.NewMetaContext(ctx, ph.G())
	if err = engine.RunEngine2(m, eng); err != nil {
		return res, err
	}
	found, status, state, text := eng.Results()
	return keybase1.CheckProofStatus{
		Found:     found,
		Status:    status,
		State:     state,
		ProofText: text,
	}, nil
}
381659
func (pka PublicKeyAlgorithm) CanEncrypt() bool {
	switch pka {
	case PubKeyAlgoRSA, PubKeyAlgoRSAEncryptOnly, PubKeyAlgoElGamal:
		return true
	}
	return false
}
1069539
func validPassword(s string) bool {
	var (
		digits    bool
		special   bool
		alphaLow  bool
		alphaHigh bool
	)
	if len(s) < 8 {
		return false
	}
	for i := 0; i < len(s); i++ {
		switch c := s[i]; {
		case '0' <= c && c <= '9':
			digits = true
		case 'a' <= c && c <= 'z':
			alphaLow = true
		case 'A' <= c && c <= 'Z':
			alphaHigh = true
		case isSpecial(c):
			special = true
		}
	}
	var n int
	if digits {
		n++
	}
	if special {
		n++
	}
	if alphaLow {
		n++
	}
	if alphaHigh {
		n++
	}
	return n >= 3
}
1072923
func (self *StateDB) GetStorageProof(a common.Address, key common.Hash) ([][]byte, error) {
	var proof proofList
	trie := self.StorageTrie(a)
	if trie == nil {
		return proof, errors.New("storage trie for requested address does not exist")
	}
	err := trie.Prove(crypto.Keccak256(key.Bytes()), 0, &proof)
	return [][]byte(proof), err
}
707693
func (d DecrypterProto) IsEncrypted(object interface{}) bool {
	_, ok := object.(proto.Message)
	if !ok {
		return false
	}
	_, ok = d.mapping[reflect.TypeOf(object)]
	return ok
}
634957
func SimpleProofsFromByteSlices(items [][]byte) (rootHash []byte, proofs []*SimpleProof) {
	trails, rootSPN := trailsFromByteSlices(items)
	rootHash = rootSPN.Hash
	proofs = make([]*SimpleProof, len(items))
	for i, trail := range trails {
		proofs[i] = &SimpleProof{
			Total:    len(items),
			Index:    i,
			LeafHash: trail.Hash,
			Aunts:    trail.FlattenAunts(),
		}
	}
	return
}
863452
func (u *User) BaseProofSet() *ProofSet {
	proofs := []Proof{
		{Key: "keybase", Value: u.name},
		{Key: "uid", Value: u.id.String()},
	}
	for _, fp := range u.GetActivePGPFingerprints(true) {
		proofs = append(proofs, Proof{Key: PGPAssertionKey, Value: fp.String()})
	}

	return NewProofSet(proofs)
}
1268609
func FuzzReadSubTreesNoProof(data []byte) int {
	buildAndCompareTreesFromFuzz(data, math.MaxUint64)
	if len(data) > 2 {
		return 1
	}
	return 0
}
128599
func (proof *RangeProof) ComputeRootHash() []byte {
	if proof == nil {
		return nil
	}
	rootHash, _ := proof.computeRootHash()
	return rootHash
}
1217901
func (ph *ProveHandler) StartProof(ctx context.Context, arg keybase1.StartProofArg) (res keybase1.StartProofResult, err error) {
	ctx = libkb.WithLogTag(ctx, "PV")
	defer ph.G().CTraceTimed(ctx, fmt.Sprintf("StartProof: Service: %v, Username: %v", arg.Service, arg.Username), func() error { return err })()
	eng := engine.NewProve(ph.G(), &arg)
	uis := libkb.UIs{
		ProveUI:   ph.getProveUI(arg.SessionID),
		SecretUI:  ph.getSecretUI(arg.SessionID, ph.G()),
		LogUI:     ph.getLogUI(arg.SessionID),
		SessionID: arg.SessionID,
	}
	m := libkb.NewMetaContext(ctx, ph.G()).WithUIs(uis)
	if err = engine.RunEngine2(m, eng); err != nil {
		return res, err
	}
	res.SigID = eng.SigID()
	return res, err
}
1001269
func StellarProof(m MetaContext, me *User, walletAddress stellar1.AccountID,
	signingKey GenericKey) (*ProofMetadataRes, error) {
	if me == nil {
		return nil, fmt.Errorf("missing user object for proof")
	}
	walletPubKey, err := MakeNaclSigningKeyPairFromStellarAccountID(walletAddress)
	if err != nil {
		return nil, err
	}
	walletKID := walletPubKey.GetKID()

	ret, err := ProofMetadata{
		Me:                  me,
		LinkType:            LinkTypeWalletStellar,
		SigningKey:          signingKey,
		SigVersion:          KeybaseSignatureV2,
		IgnoreIfUnsupported: SigIgnoreIfUnsupported(true),
	}.ToJSON2(m)
	if err != nil {
		return nil, err
	}

	walletSection := jsonw.NewDictionary()
	walletSection.SetKey("address", jsonw.NewString(walletAddress.String()))
	walletSection.SetKey("network", jsonw.NewString(string(WalletNetworkStellar)))

	// Inner links can be hidden. To prevent an attacker from figuring out the
	// contents from the hash of the inner link, add 18 random bytes.
	entropy, err := LinkEntropy()
	if err != nil {
		return nil, err
	}
	walletSection.SetKey("entropy", jsonw.NewString(entropy))

	walletKeySection := jsonw.NewDictionary()
	walletKeySection.SetKey("kid", jsonw.NewString(walletKID.String()))
	// The caller is responsible for overwriting reverse_sig after signing.
	walletKeySection.SetKey("reverse_sig", jsonw.NewNil())

	body := ret.J.AtKey("body")
	body.SetKey("wallet", walletSection)
	body.SetKey("wallet_key", walletKeySection)

	return ret, nil
}
675932
func (key Key) IsValid() bool {
	for _, supKey := range AllSupportedKeys {
		if supKey == key {
			return true
		}
	}

	return false
}
600920
func (m *SigningMethodRSA) Verify(signingString, signature string, key interface{}) error {
	var err error

	// Decode the signature
	var sig []byte
	if sig, err = DecodeSegment(signature); err != nil {
		return err
	}

	var rsaKey *rsa.PublicKey
	var ok bool

	if rsaKey, ok = key.(*rsa.PublicKey); !ok {
		return ErrInvalidKeyType
	}

	// Create hasher
	if !m.Hash.Available() {
		return ErrHashUnavailable
	}
	hasher := m.Hash.New()
	hasher.Write([]byte(signingString))

	// Verify the signature
	return rsa.VerifyPKCS1v15(rsaKey, m.Hash, hasher.Sum(nil), sig)
}