MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / pad

Function pad

hashing/sha1/sha1.go:23–35  ·  view source on GitHub ↗

pad pads the input message so that its length is congruent to 448 modulo 512

(message []byte)

Source from the content-addressed store, hash-verified

21
22// pad pads the input message so that its length is congruent to 448 modulo 512
23func pad(message []byte) []byte {
24 originalLength := len(message) * 8
25 message = append(message, 0x80)
26 for (len(message)*8)%512 != 448 {
27 message = append(message, 0x00)
28 }
29
30 lengthBytes := make([]byte, 8)
31 binary.BigEndian.PutUint64(lengthBytes, uint64(originalLength))
32 message = append(message, lengthBytes...)
33
34 return message
35}
36
37// leftRotate rotates x left by n bits
38func leftRotate(x, n uint32) uint32 {

Callers 1

HashFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected