summaryrefslogtreecommitdiffstats
path: root/lib/hash.go
diff options
context:
space:
mode:
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 {