summaryrefslogtreecommitdiffstats
path: root/lib/sha1.go
diff options
context:
space:
mode:
authorsiddharth <s@ricketyspace.net>2021-10-09 16:58:52 -0400
committersiddharth <s@ricketyspace.net>2021-10-09 16:58:52 -0400
commit6233425a7f0a1a8e653485115e0677b47e93d393 (patch)
tree09e79abfcb9d77c19ba1a87ae019fd8cce1eed46 /lib/sha1.go
parent4f6d76a0053dbfdaa799729f92fbddb7890a49c5 (diff)
lib: update sha1Pad
Use MDPadding for padding the message.
Diffstat (limited to 'lib/sha1.go')
-rw-r--r--lib/sha1.go34
1 files changed, 2 insertions, 32 deletions
diff --git a/lib/sha1.go b/lib/sha1.go
index 559d515..0b6ddef 100644
--- a/lib/sha1.go
+++ b/lib/sha1.go
@@ -72,42 +72,12 @@ func sha1KT(t int) uint32 {
// SHA-1 - Pad message such that its length is a multiple of 512.
func sha1Pad(m []byte) []byte {
- l := len(m) * 8 // msg size in bits
-
- // Reckon value of `k`
- k := 0
- for ((l + 1 + k) % 512) != 448 {
- k += 1
- }
-
// Initialize padded message
pm := make([]byte, len(m))
copy(pm, m)
- // Add bit `1` as byte block.
- pm = append(pm, 0x80)
- f := 7 // unclaimed bits in last byte of `pm`
-
- // Add `k` bit `0`s
- for i := 0; i < k; i++ {
- if f == 0 {
- pm = append(pm, 0x0)
- f = 8
- }
- f = f - 1
- }
-
- // Add `l` in a 64 bit block in `pm`
- l64 := uint64(l)
- b64 := make([]byte, 8) // last 64-bits
- for i := 7; i >= 0; i-- {
- // Get 8 last bits.
- b64[i] = byte(l64 & 0xFF)
-
- // Get rid of the last 8 bits.
- l64 = l64 >> 8
- }
- pm = append(pm, b64...)
+ // Add padding.
+ pm = append(pm, MDPadding(m)...)
return pm
}