summaryrefslogtreecommitdiffstats
path: root/lib/hash.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-10-10 11:18:25 -0400
committersiddharth <s@ricketyspace.net>2021-10-10 11:18:25 -0400
commit244d10ac25d1adc0f10e089f8d457269b109897d (patch)
treee4a94f6967a973f8cd2e1edc258a7958be05e185 /lib/hash.go
parentf9c878cbad59a98490e832703f19abf49bd6738f (diff)
lib: move sha arithmetic functions to hash.go
Diffstat (limited to 'lib/hash.go')
-rw-r--r--lib/hash.go19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/hash.go b/lib/hash.go
index f0f4625..363d3d6 100644
--- a/lib/hash.go
+++ b/lib/hash.go
@@ -28,6 +28,25 @@ func shaMessageBlocks(pm []byte) [][]uint32 {
return mbs
}
+// (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))
+}
+
// Returns Merkle–Damgård padding in bytes for length of mesage `l`
// bytes.
func MDPadding(l int) []byte {