summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2022-03-05 13:03:53 -0500
committersiddharth <s@ricketyspace.net>2022-03-05 13:03:53 -0500
commita43f1d60b697bf4e6d96f77e24ba8095dc1bd42a (patch)
tree74808d845049deac3547a48c1b3e18e72574196b
parentd9c9edb96c2cd6e784a073894d65a843681006aa (diff)
lib: add shaStr
-rw-r--r--lib/hash.go5
-rw-r--r--lib/hash_test.go16
2 files changed, 21 insertions, 0 deletions
diff --git a/lib/hash.go b/lib/hash.go
index 8c8aeef..b636e17 100644
--- a/lib/hash.go
+++ b/lib/hash.go
@@ -21,3 +21,8 @@ func shaRotr(x uint32, n uint) uint32 {
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
+}
diff --git a/lib/hash_test.go b/lib/hash_test.go
new file mode 100644
index 0000000..bde6b3f
--- /dev/null
+++ b/lib/hash_test.go
@@ -0,0 +1,16 @@
+// Copyright © 2022 siddharth <s@ricketyspace.net>
+// SPDX-License-Identifier: ISC
+
+package lib
+
+import (
+ "testing"
+)
+
+func TestShaShr(t *testing.T) {
+ s := uint32(256)
+ sr := shaShr(s, 2)
+ if sr != s>>2 {
+ t.Errorf("shaShr test failed")
+ }
+}