summaryrefslogtreecommitdiffstats
path: root/lib/hash.go
blob: 8c8aeeffd6ce71615a272f663f2168aa49c2b289 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
// Copyright © 2021 siddharth <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))
}