// UBI256 does a Threefish256 encryption of the given block using
// the chain values hVal and the tweak.
// The chain values are updated through hVal[i] = block[i] ^ Enc(block)[i]
975363
func UBI256(block *[4]uint64, hVal *[5]uint64, tweak *[3]uint64) {
	b0, b1, b2, b3 := block[0], block[1], block[2], block[3]

	hVal[4] = C240 ^ hVal[0] ^ hVal[1] ^ hVal[2] ^ hVal[3]
	tweak[2] = tweak[0] ^ tweak[1]

	Encrypt256(block, hVal, tweak)

	hVal[0] = block[0] ^ b0
	hVal[1] = block[1] ^ b1
	hVal[2] = block[2] ^ b2
	hVal[3] = block[3] ^ b3
}
208601
func (s *PublicWeb3API) Sha3(input hexutil.Bytes) hexutil.Bytes {
	return crypto.Keccak256(input)
}
1873
func newUnconfirmedBlocks(chain chainRetriever, depth uint) *unconfirmedBlocks {
	return &unconfirmedBlocks{
		chain: chain,
		depth: depth,
	}
}
1218227
func Aes256CBCDecrypt(key [32]byte, ciphertext []byte) (plaintext []byte, err error) {
	return aesCBCDec(key[:], ciphertext)
}
985663
func (api *PublicEthereumAPI) ChainId() hexutil.Uint64 {
	chainID := new(big.Int)
	if config := api.e.blockchain.Config(); config.IsEIP155(api.e.blockchain.CurrentBlock().Number()) {
		chainID = config.ChainID
	}
	return (hexutil.Uint64)(chainID.Uint64())
}
376784
func sum256Hex(data []byte) string {
	hash := sha256.New()
	hash.Write(data)
	return hex.EncodeToString(hash.Sum(nil))
}
949793
func (hc *halfConn) encrypt(b *block, explicitIVLen int) (bool, alert) {
	// mac
	if hc.mac != nil {
		mac := hc.mac.MAC(hc.outDigestBuf, hc.seq[0:], b.data[:recordHeaderLen], b.data[recordHeaderLen+explicitIVLen:])

		n := len(b.data)
		b.resize(n + len(mac))
		copy(b.data[n:], mac)
		hc.outDigestBuf = mac
	}

	payload := b.data[recordHeaderLen:]

	// encrypt
	if hc.cipher != nil {
		switch c := hc.cipher.(type) {
		case cipher.Stream:
			c.XORKeyStream(payload, payload)
		case cipher.AEAD:
			payloadLen := len(b.data) - recordHeaderLen - explicitIVLen
			b.resize(len(b.data) + c.Overhead())
			nonce := b.data[recordHeaderLen : recordHeaderLen+explicitIVLen]
			payload := b.data[recordHeaderLen+explicitIVLen:]
			payload = payload[:payloadLen]

			copy(hc.additionalData[:], hc.seq[:])
			copy(hc.additionalData[8:], b.data[:3])
			hc.additionalData[11] = byte(payloadLen >> 8)
			hc.additionalData[12] = byte(payloadLen)

			c.Seal(payload[:0], nonce, payload, hc.additionalData[:])
		case cbcMode:
			blockSize := c.BlockSize()
			if explicitIVLen > 0 {
				c.SetIV(payload[:explicitIVLen])
				payload = payload[explicitIVLen:]
			}
			prefix, finalBlock := padToBlockSize(payload, blockSize)
			b.resize(recordHeaderLen + explicitIVLen + len(prefix) + len(finalBlock))
			c.CryptBlocks(b.data[recordHeaderLen+explicitIVLen:], prefix)
			c.CryptBlocks(b.data[recordHeaderLen+explicitIVLen+len(prefix):], finalBlock)
		default:
			panic("unknown cipher type")
		}
	}

	// update length to include MAC and any block padding needed.
	n := len(b.data) - recordHeaderLen
	b.data[3] = byte(n >> 8)
	b.data[4] = byte(n)
	hc.incSeq()

	return true, 0
}
690178
func CompareChainHashUbiquity(chain1, chain2 []*x509.Certificate) int {
	hu1 := ChainHashUbiquity(chain1)
	hu2 := ChainHashUbiquity(chain2)
	return int(hu1) - int(hu2)
}
1272691
func (ns *Namespace) SHA256(in interface{}) (string, error) {
	conv, err := cast.ToStringE(in)
	if err != nil {
		return "", err
	}

	hash := sha256.Sum256([]byte(conv))
	return hex.EncodeToString(hash[:]), nil
}
1342600
func ParseBig256(s string) (*big.Int, bool) {
	if s == "" {
		return new(big.Int), true
	}
	var bigint *big.Int
	var ok bool
	if len(s) >= 2 && (s[:2] == "0x" || s[:2] == "0X") {
		bigint, ok = new(big.Int).SetString(s[2:], 16)
	} else {
		bigint, ok = new(big.Int).SetString(s, 10)
	}
	if ok && bigint.BitLen() > 256 {
		bigint, ok = nil, false
	}
	return bigint, ok
}
55026
func Decrypt256(block *[4]uint64, keys *[5]uint64, tweak *[3]uint64) {
	b0, b1, b2, b3 := block[0], block[1], block[2], block[3]

	var tmp uint64
	for r := 18; r > 1; r-- {
		b0 -= keys[r%5]
		b1 -= keys[(r+1)%5] + tweak[r%3]
		b2 -= keys[(r+2)%5] + tweak[(r+1)%3]
		b3 -= keys[(r+3)%5] + uint64(r)

		tmp = b1 ^ b2
		b1 = (tmp >> 32) | (tmp << (64 - 32))
		b2 -= b1
		tmp = b3 ^ b0
		b3 = (tmp >> 32) | (tmp << (64 - 32))
		b0 -= b3

		tmp = b3 ^ b2
		b3 = (tmp >> 22) | (tmp << (64 - 22))
		b2 -= b3
		tmp = b1 ^ b0
		b1 = (tmp >> 58) | (tmp << (64 - 58))
		b0 -= b1

		tmp = b1 ^ b2
		b1 = (tmp >> 12) | (tmp << (64 - 12))
		b2 -= b1
		tmp = b3 ^ b0
		b3 = (tmp >> 46) | (tmp << (64 - 46))
		b0 -= b3

		tmp = b3 ^ b2
		b3 = (tmp >> 33) | (tmp << (64 - 33))
		b2 -= b3
		tmp = b1 ^ b0
		b1 = (tmp >> 25) | (tmp << (64 - 25))
		b0 -= b1

		r--

		b0 -= keys[r%5]
		b1 -= keys[(r+1)%5] + tweak[r%3]
		b2 -= keys[(r+2)%5] + tweak[(r+1)%3]
		b3 -= keys[(r+3)%5] + uint64(r)

		tmp = b1 ^ b2
		b1 = (tmp >> 37) | (tmp << (64 - 37))
		b2 -= b1
		tmp = b3 ^ b0
		b3 = (tmp >> 5) | (tmp << (64 - 5))
		b0 -= b3

		tmp = b3 ^ b2
		b3 = (tmp >> 40) | (tmp << (64 - 40))
		b2 -= b3
		tmp = b1 ^ b0
		b1 = (tmp >> 23) | (tmp << (64 - 23))
		b0 -= b1

		tmp = b1 ^ b2
		b1 = (tmp >> 57) | (tmp << (64 - 57))
		b2 -= b1
		tmp = b3 ^ b0
		b3 = (tmp >> 52) | (tmp << (64 - 52))
		b0 -= b3

		tmp = b3 ^ b2
		b3 = (tmp >> 16) | (tmp << (64 - 16))
		b2 -= b3
		tmp = b1 ^ b0
		b1 = (tmp >> 14) | (tmp << (64 - 14))
		b0 -= b1
	}

	b0 -= keys[0]
	b1 -= keys[1] + tweak[0]
	b2 -= keys[2] + tweak[1]
	b3 -= keys[3]

	block[0], block[1], block[2], block[3] = b0, b1, b2, b3
}
923103
func ComputeSHA256(data []byte) (hash []byte) {
	hash, err := factory.GetDefault().Hash(data, &bccsp.SHA256Opts{})
	if err != nil {
		panic(fmt.Errorf("Failed computing SHA256 on [% x]", data))
	}
	return
}
928161
func nonceForChunkSigncryption(headerHash headerHash, isFinal bool, i encryptionBlockNumber) Nonce {
	var n Nonce
	off := len(n) - 8
	copyEqualSize(n[:off], headerHash[:off])
	// Set LSB of last byte based on isFinal.
	n[off-1] &^= 1
	if isFinal {
		n[off-1] |= 1
	}
	binary.BigEndian.PutUint64(n[off:], uint64(i))
	return n
}
478852
func CryptEncoderSSHA256(salt string) func(pass []byte, hash interface{}) []byte {
	return func(pass []byte, hash interface{}) []byte {
		s := []byte(salt)
		p := append(pass, s...)
		h := sha256.Sum256(p)
		return h[:]
	}
}
437683
func NewBlowfishBlockCrypt(key []byte) (BlockCrypt, error) {
	c := new(blowfishBlockCrypt)
	block, err := blowfish.NewCipher(key)
	if err != nil {
		return nil, err
	}
	c.block = block
	return c, nil
}
387696
func encrypt(block cipher.Block, dst, src, buf []byte) {
	switch block.BlockSize() {
	case 8:
		encrypt8(block, dst, src, buf)
	case 16:
		encrypt16(block, dst, src, buf)
	default:
		encryptVariant(block, dst, src, buf)
	}
}
479115
func New256(key []byte) hash.Hash {
	s := new(hashFunc)

	if len(key) > 0 {
		s.initialize(32, &Config{Key: key})
	} else {
		copy(s.hVal[:8], iv256[:])
		s.hValCpy = s.hVal
		s.hashsize = 32
		s.tweak[0] = 0
		s.tweak[1] = CfgMessage<<56 | FirstBlock
	}

	return s
}