// calcMac calculates HMAC-SHA-256 over the message using the passed secret key
// as input to the HMAC.
195690
func calcMac(key [keyLen]byte, msg []byte) [HMACSize]byte {
	hmac := hmac.New(sha256.New, key[:])
	hmac.Write(msg)
	h := hmac.Sum(nil)

	var mac [HMACSize]byte
	copy(mac[:], h[:HMACSize])

	return mac
}
543122
func HashByteSecret(secret []byte) []byte {
	var r [32]byte
	r = sha256.Sum256([]byte(secret))
	return r[:]
}
639969
func HmacSha1(secret string, message string) string {
	key := []byte(secret)
	h := hmac.New(sha1.New, key)
	h.Write([]byte(message))

	return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
68490
func (m *merkleBlock) calcHash(height, pos uint32) *chainhash.Hash {
	if height == 0 {
		return m.allHashes[pos]
	}

	var right *chainhash.Hash
	left := m.calcHash(height-1, pos*2)
	if pos*2+1 < m.calcTreeWidth(height-1) {
		right = m.calcHash(height-1, pos*2+1)
	} else {
		right = left
	}
	return blockchain.HashMerkleBranches(left, right)
}
839663
func ValidTruncMAC(msg, expectedMAC, key []byte) bool {
	actualMAC := ComputeTruncatedMAC(msg, key, len(expectedMAC))
	return hmac.Equal(actualMAC, expectedMAC)
}
2771
func createHMAC(key, value string) (string, error) {
	if key == "" {
		return "", fmt.Errorf("invalid HMAC key")
	}
	hm := hmac.New(sha256.New, []byte(key))
	hm.Write([]byte(value))
	return hex.EncodeToString(hm.Sum(nil)), nil
}
605509
func calc(v1, v2 interface{}, op int) interface{} {

	i1, ok := _int64(v1)
	i2, ok2 := _int64(v2)

	var ok3, ok4 bool
	var i3, i4 float64

	if !ok {
		i3, ok3 = _float64(v1)
	}
	if !ok2 {
		i4, ok4 = _float64(v2)
	}

	if ok && ok2 {
		switch op {
		case '+':
			return i1 + i2
		case '-':
			return i1 - i2
		case '*':
			return i1 * i2
		case '/':
			return i1 / i2
		case '%':
			return i1 % i2
		}
	}
	if ok3 && ok4 {
		switch op {
		case '+':
			return i3 + i4
		case '-':
			return i3 - i4
		case '*':
			return i3 * i4
		case '/':
			return i3 / i4
		case '%':
			return int(i3) % int(i4)
		}
	}
	if ok && ok4 {
		i3 = float64(i1)
		switch op {
		case '+':
			return i3 + i4
		case '-':
			return i3 - i4
		case '*':
			return i3 * i4
		case '/':
			return i3 / i4
		case '%':
			return i1 % int64(i4)
		}
	}
	if ok3 && ok2 {
		i4 = float64(i2)
		switch op {
		case '+':
			return i3 + i4
		case '-':
			return i3 - i4
		case '*':
			return i3 * i4
		case '/':
			return i3 / i4
		case '%':
			return int64(i3) % i2
		}
	}

	if op != '+' {
		return nil
	}

	return _string(v1) + _string(v2)
}
171089
func (p *Params) Check() error {
	// Validate N
	if p.N > maxInt || p.N <= 1 || p.N%2 != 0 {
		return ErrInvalidParams
	}

	// Validate r
	if p.R < 1 || p.R > maxInt {
		return ErrInvalidParams
	}

	// Validate p
	if p.P < 1 || p.P > maxInt {
		return ErrInvalidParams
	}

	// Validate that r & p don't exceed 2^30 and that N, r, p values don't
	// exceed the limits defined by the scrypt algorithm.
	if uint64(p.R)*uint64(p.P) >= 1<<30 || p.R > maxInt/128/p.P || p.R > maxInt/256 || p.N > maxInt/128/p.R {
		return ErrInvalidParams
	}

	// Validate the salt length
	if p.SaltLen < minSaltLen || p.SaltLen > maxInt {
		return ErrInvalidParams
	}

	// Validate the derived key length
	if p.DKLen < minDKLen || p.DKLen > maxInt {
		return ErrInvalidParams
	}

	return nil
}
395105
func CalculateSPKI(cert *x509.Certificate) string {
	sum := sha256.Sum256(cert.RawSubjectPublicKeyInfo)
	return "sha256:" + hex.EncodeToString(sum[:])
}
1017382
func (b UDP) CalculateChecksum(partialChecksum uint16) uint16 {
	// Calculate the rest of the checksum.
	return Checksum(b[:UDPMinimumSize], partialChecksum)
}
911201
func ComputeHmac256(tags []byte, key []byte) ([]byte, error) {

	var buffer bytes.Buffer
	if err := binary.Write(&buffer, binary.BigEndian, tags); err != nil {
		return []byte{}, err
	}

	h := hmac.New(sha256.New, key)

	if _, err := h.Write(buffer.Bytes()); err != nil {
		return []byte{}, err
	}

	return h.Sum(nil), nil

}
1171162
func Sum(msg []byte, hashsize int, conf *Config) ([]byte, error) {
	h, err := New(hashsize, conf)
	if err != nil {
		return nil, err
	}

	h.Write(msg)

	return h.Sum(nil), nil
}
207550
func ComputeTruncatedMAC(msg, key []byte, size int) []byte {
	m := hmac.New(sha256.New, key)
	m.Write(msg)
	return m.Sum(nil)[:size]
}
549821
func Checksum(buf []byte, initial uint16) uint16 {
	return calculateChecksum(buf, uint32(initial))
}
1235886
func calcMemSize64(off, l *big.Int) (uint64, bool) {
	if !l.IsUint64() {
		return 0, true
	}
	return calcMemSize64WithUint(off, l.Uint64())
}
354292
func sign(message, key string) string {
	hashfun := hmac.New(sha1.New, []byte(key))
	hashfun.Write([]byte(message))
	rawsignature := hashfun.Sum(nil)
	base64signature := make([]byte, base64.StdEncoding.EncodedLen(len(rawsignature)))
	base64.StdEncoding.Encode(base64signature, rawsignature)

	return string(base64signature)
}
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[:]
	}
}