summaryrefslogtreecommitdiffstats
path: root/lib/hash.go
blob: 32c1fe553c3b3ec523dbce0ccec1856e702b6a51 (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
24
25
26
27
28
// Copyright © 2021 siddharth ravikumar <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))
}

// Right Shift
func shaShr(x uint32, n uint) uint32 {
	return x >> n
}