summaryrefslogblamecommitdiffstats
path: root/lib/hash.go
blob: c36ff4340e95d85874a8e6187efbbb24952126bc (plain) (tree)
1
2
3
4
5




                                                    

















                                         
// Copyright © 2021 rsiddharth <s@ricketyspace.net>
// SPDX-License-Identifier: ISC

package lib

// (a + b + ...) mod 2^32
func shaAdd(n ...uint32) uint32 {
	sum := uint64(0)
	for _, v := range n {
		sum += uint64(v)
	}
	return uint32(sum & 0xFFFFFFFF)
}

// Circular Right Shift
func shaRotr(x uint32, n uint) uint32 {
	return (x >> n) | (x << (32 - n))
}

// Circular Left Shift
func shaRotl(x uint32, n uint) uint32 {
	return (x << n) | (x >> (32 - n))
}