// Inverse S-Box 2
172385
func sb2Inv(r0, r1, r2, r3 *uint32) {
	*r2 ^= *r3
	*r3 ^= *r0
	r4 := *r3
	*r3 &= *r2
	*r3 ^= *r1
	*r1 |= *r2
	*r1 ^= r4
	r4 &= *r3
	*r2 ^= *r3
	r4 &= *r0
	r4 ^= *r2
	*r2 &= *r1
	*r2 |= *r0
	*r3 = ^*r3
	*r2 ^= *r3
	*r0 ^= *r3
	*r0 &= *r1
	*r3 ^= r4
	*r3 ^= *r0
	//return *r1, r4, *r2, *r3
	*r0 = *r1
	*r1 = r4
}
410154
func reverse(s string) string {
	var rs []rune
	for len(s) > 0 {
		r, size := utf8.DecodeLastRuneInString(s)
		s = s[:len(s)-size]

		rs = append(rs, r)
	}

	return string(rs)
}
1153684
func sb0Inv(r0, r1, r2, r3 *uint32) {
	*r2 = ^*r2
	r4 := *r1
	*r1 |= *r0
	r4 = ^r4
	*r1 ^= *r2
	*r2 |= r4
	*r1 ^= *r3
	*r0 ^= r4
	*r2 ^= *r0
	*r0 &= *r3
	r4 ^= *r0
	*r0 |= *r1
	*r0 ^= *r2
	*r3 ^= r4
	*r2 ^= *r1
	*r3 ^= *r0
	*r3 ^= *r1
	*r2 &= *r3
	r4 ^= *r2
	//return *r0, r4, *r1, *r3
	*r2 = *r1
	*r1 = r4
}
910298
func ReverseLess(Less func(i, j int) bool) func(i, j int) bool {
	return func(i, j int) bool {
		return Less(j, i)
	}
}
987904
func (o *InsideBoundingBoxOption) UnmarshalJSON(data []byte) error {
	if string(data) == "null" {
		return nil
	}

	var boxes [][4]float64
	if err := json.Unmarshal(data, &boxes); err == nil {
		o.boxes = boxes
		return nil
	}

	var coordinates string
	if err := json.Unmarshal(data, &coordinates); err == nil {
		o.coordinates = coordinates
		return nil
	}

	return errs.ErrJSONDecode(data, "InsideBoundingBox")
}
550104
func (b *BiMap) GetInverse(v interface{}) (interface{}, bool) {
	if !b.ExistsInverse(v) {
		return "", false
	}
	b.s.RLock()
	defer b.s.RUnlock()
	return b.inverse[v], true

}
733819
func (b Box) Constrain(other Box) Box {
	newBox := b.Clone()

	newBox.Top = util.Math.MaxInt(newBox.Top, other.Top)
	newBox.Left = util.Math.MaxInt(newBox.Left, other.Left)
	newBox.Right = util.Math.MinInt(newBox.Right, other.Right)
	newBox.Bottom = util.Math.MinInt(newBox.Bottom, other.Bottom)

	return newBox
}
766236
func UpsideDown(s string) string {
	ss := strings.Split(s, "")
	ns := ""

	for i := len(ss) - 1; i >= 0; i-- {
		uc := upsideDownChars[ss[i]]

		if uc == "" {
			uc = upsideDownChars[strings.ToLower(ss[i])]
		}

		if uc != "" {
			ns += uc
		}
	}

	return ns
}
854954
func (r *ReverseTunnelV1) V2() *ReverseTunnelV2 {
	return &ReverseTunnelV2{
		Kind:    KindReverseTunnel,
		Version: V2,
		Metadata: Metadata{
			Name:      r.DomainName,
			Namespace: defaults.Namespace,
		},
		Spec: ReverseTunnelSpecV2{
			ClusterName: r.DomainName,
			Type:        ProxyTunnel,
			DialAddrs:   r.DialAddrs,
		},
	}
}
1204200
func (bv *BitVector) InvertAll() {
	if bv.count != -1 {
		bv.count = bv.size - bv.count
	}
	if len(bv.bits) > 0 {
		for idx, v := range bv.bits {
			bv.bits[idx] = byte(^v)
		}
	}
}
174849
func (k Key) Reverse() Key {
	l := k.List()
	r := make([]string, len(l), len(l))
	for i, e := range l {
		r[len(l)-i-1] = e
	}
	return KeyWithNamespaces(r)
}
694558
func invert(r *[5]uint64, x *[5]uint64) {
	var z2, z9, z11, z2_5_0, z2_10_0, z2_20_0, z2_50_0, z2_100_0, t [5]uint64

	square(&z2, x)        /* 2 */
	square(&t, &z2)       /* 4 */
	square(&t, &t)        /* 8 */
	mul(&z9, &t, x)       /* 9 */
	mul(&z11, &z9, &z2)   /* 11 */
	square(&t, &z11)      /* 22 */
	mul(&z2_5_0, &t, &z9) /* 2^5 - 2^0 = 31 */

	square(&t, &z2_5_0)      /* 2^6 - 2^1 */
	for i := 1; i < 5; i++ { /* 2^20 - 2^10 */
		square(&t, &t)
	}
	mul(&z2_10_0, &t, &z2_5_0) /* 2^10 - 2^0 */

	square(&t, &z2_10_0)      /* 2^11 - 2^1 */
	for i := 1; i < 10; i++ { /* 2^20 - 2^10 */
		square(&t, &t)
	}
	mul(&z2_20_0, &t, &z2_10_0) /* 2^20 - 2^0 */

	square(&t, &z2_20_0)      /* 2^21 - 2^1 */
	for i := 1; i < 20; i++ { /* 2^40 - 2^20 */
		square(&t, &t)
	}
	mul(&t, &t, &z2_20_0) /* 2^40 - 2^0 */

	square(&t, &t)            /* 2^41 - 2^1 */
	for i := 1; i < 10; i++ { /* 2^50 - 2^10 */
		square(&t, &t)
	}
	mul(&z2_50_0, &t, &z2_10_0) /* 2^50 - 2^0 */

	square(&t, &z2_50_0)      /* 2^51 - 2^1 */
	for i := 1; i < 50; i++ { /* 2^100 - 2^50 */
		square(&t, &t)
	}
	mul(&z2_100_0, &t, &z2_50_0) /* 2^100 - 2^0 */

	square(&t, &z2_100_0)      /* 2^101 - 2^1 */
	for i := 1; i < 100; i++ { /* 2^200 - 2^100 */
		square(&t, &t)
	}
	mul(&t, &t, &z2_100_0) /* 2^200 - 2^0 */

	square(&t, &t)            /* 2^201 - 2^1 */
	for i := 1; i < 50; i++ { /* 2^250 - 2^50 */
		square(&t, &t)
	}
	mul(&t, &t, &z2_50_0) /* 2^250 - 2^0 */

	square(&t, &t) /* 2^251 - 2^1 */
	square(&t, &t) /* 2^252 - 2^2 */
	square(&t, &t) /* 2^253 - 2^3 */

	square(&t, &t) /* 2^254 - 2^4 */

	square(&t, &t)   /* 2^255 - 2^5 */
	mul(r, &t, &z11) /* 2^255 - 21 */
}
1143612
func BoxAndEncode(a *stellar1.Bundle, pukGen keybase1.PerUserKeyGeneration, puk libkb.PerUserKeySeed) (*BoxedEncoded, error) {
	err := a.CheckInvariants()
	if err != nil {
		return nil, err
	}

	accountsVisible, accountsSecret := visibilitySplit(a)

	// visible portion parent
	visibleV2 := newVisibleParent(a, accountsVisible)

	boxed := newBoxedEncoded()

	// encrypted account bundles
	for i, acctEntry := range visibleV2.Accounts {
		secret, ok := a.AccountBundles[acctEntry.AccountID]
		if !ok {
			continue
		}
		ab, err := accountBoxAndEncode(acctEntry.AccountID, secret, pukGen, puk)
		if err != nil {
			return nil, err
		}
		boxed.AcctBundles[acctEntry.AccountID] = *ab

		visibleV2.Accounts[i].EncAcctBundleHash = ab.EncHash
	}

	// have to do this after to get hashes of encrypted account bundles
	visiblePack, err := libkb.MsgpackEncode(visibleV2)
	if err != nil {
		return nil, err
	}
	visibleHash := sha256.Sum256(visiblePack)
	boxed.VisParentB64 = base64.StdEncoding.EncodeToString(visiblePack)

	// secret portion parent
	versionedSecret := stellar1.NewBundleSecretVersionedWithV2(stellar1.BundleSecretV2{
		VisibleHash: visibleHash[:],
		Accounts:    accountsSecret,
	})
	boxed.EncParent, boxed.EncParentB64, err = parentBoxAndEncode(versionedSecret, pukGen, puk)
	if err != nil {
		return nil, err
	}

	return boxed, nil
}
286608
func NewInvertedIndex(cfg Config) *InvertedIndex {
	idx := &InvertedIndex{index: make(map[string]map[Keyword][]Document), cfg: cfg}
	for _, conf := range cfg.Indices {
		idx.index[conf.Name] = make(map[Keyword][]Document)
		if conf.Weight < idx.minWeight {
			// By default, the weight scale starts at 0, but we allow
			// negative weights.
			idx.minWeight = conf.Weight
		}
		if conf.Weight > idx.maxWeight {
			idx.maxWeight = conf.Weight
		}
	}
	return idx
}
79468
func (b Box) Clone() Box {
	return Box{
		IsSet:  b.IsSet,
		Top:    b.Top,
		Left:   b.Left,
		Right:  b.Right,
		Bottom: b.Bottom,
	}
}
434739
func (b *Boxer) boxV2orV3orV4(ctx context.Context, messagePlaintext chat1.MessagePlaintext,
	baseEncryptionKey types.CryptKey, ephemeralSeed *keybase1.TeamEk, signingKeyPair libkb.NaclSigningKeyPair,
	version chat1.MessageBoxedVersion, pairwiseMACRecipients []keybase1.KID) (res chat1.MessageBoxed, err error) {

	if messagePlaintext.ClientHeader.MerkleRoot == nil {
		return res, NewBoxingError("cannot send message without merkle root", false)
	}
	headerEncryptionKey, err := libkb.DeriveSymmetricKey(
		libkb.NaclSecretBoxKey(baseEncryptionKey.Material()), libkb.EncryptionReasonChatMessage)
	if err != nil {
		return res, err
	}

	// Regular messages use the same encryption key for the header and for the
	// body. Exploding messages use a derived ephemeral key for the body.
	bodyEncryptionKey := headerEncryptionKey
	if messagePlaintext.IsEphemeral() {
		bodyEncryptionKey, err = libkb.DeriveFromSecret(ephemeralSeed.Seed, libkb.DeriveReasonTeamEKExplodingChat)
		if err != nil {
			return res, err
		}
		// The MessagePlaintext supplied by the caller has a Lifetime, but we
		// expect the Generation is left uninitialized, and we set it here.
		messagePlaintext.ClientHeader.EphemeralMetadata.Generation = ephemeralSeed.Metadata.Generation
	}

	bodyVersioned := chat1.NewBodyPlaintextWithV1(chat1.BodyPlaintextV1{
		MessageBody: messagePlaintext.MessageBody,
	})
	bodyEncrypted, err := b.seal(bodyVersioned, bodyEncryptionKey)
	if err != nil {
		return res, err
	}

	bodyHash, err := b.makeBodyHash(*bodyEncrypted)
	if err != nil {
		return res, err
	}

	// create the v1 header, adding hash
	headerVersioned := chat1.NewHeaderPlaintextWithV1(chat1.HeaderPlaintextV1{
		Conv:              messagePlaintext.ClientHeader.Conv,
		TlfName:           messagePlaintext.ClientHeader.TlfName,
		TlfPublic:         messagePlaintext.ClientHeader.TlfPublic,
		MessageType:       messagePlaintext.ClientHeader.MessageType,
		Prev:              messagePlaintext.ClientHeader.Prev,
		Sender:            messagePlaintext.ClientHeader.Sender,
		SenderDevice:      messagePlaintext.ClientHeader.SenderDevice,
		BodyHash:          bodyHash,
		MerkleRoot:        messagePlaintext.ClientHeader.MerkleRoot,
		OutboxInfo:        messagePlaintext.ClientHeader.OutboxInfo,
		OutboxID:          messagePlaintext.ClientHeader.OutboxID,
		KbfsCryptKeysUsed: messagePlaintext.ClientHeader.KbfsCryptKeysUsed,
		EphemeralMetadata: messagePlaintext.ClientHeader.EphemeralMetadata,
		// In MessageBoxed.V2 HeaderSignature is nil.
		HeaderSignature: nil,
	})

	// signencrypt the header
	headerSealed, err := b.signEncryptMarshal(headerVersioned, headerEncryptionKey,
		signingKeyPair, kbcrypto.SignaturePrefixChatMBv2)
	if err != nil {
		return res, err
	}

	// Make pairwise MACs if there are any pairwise recipients supplied. Note
	// that we still sign+encrypt with a signing key above. If we want
	// repudiability, it's the caller's responsibility to provide a zero
	// signing key or similar. Signing with a real key and also MAC'ing is
	// redundant, but it will let us test the MAC code in prod in a backwards
	// compatible way.
	if len(pairwiseMACRecipients) > 0 {
		pairwiseMACs, err := b.makeAllPairwiseMACs(ctx, headerSealed, pairwiseMACRecipients)
		if err != nil {
			return res, err
		}
		messagePlaintext.ClientHeader.PairwiseMacs = pairwiseMACs
	}

	// verify
	verifyKey := signingKeyPair.GetBinaryKID()

	return chat1.MessageBoxed{
		Version:          version,
		ServerHeader:     nil,
		ClientHeader:     messagePlaintext.ClientHeader,
		HeaderCiphertext: headerSealed.AsSealed(),
		BodyCiphertext:   *bodyEncrypted,
		VerifyKey:        verifyKey,
		KeyGeneration:    baseEncryptionKey.Generation(),
	}, nil
}
714791
func (bp *Bypass) Reversed() bool {
	bp.mux.RLock()
	defer bp.mux.RUnlock()

	return bp.reversed
}