pad returns a padded version of the input message, such as the padded message's length is a multiple of 512 bits. The padding methodology is as follows: A "1" bit is appended at the end of the input message, followed by m "0" bits such as the length is 64 bits short of a 512 bits multiple. The remai
(message []byte)
| 35 | // message, represented as a 64-bits unsigned integer. |
| 36 | // For more details, see: https://datatracker.ietf.org/doc/html/rfc6234#section-4.1 |
| 37 | func pad(message []byte) []byte { |
| 38 | L := make([]byte, 8) |
| 39 | binary.BigEndian.PutUint64(L, uint64(len(message)*8)) |
| 40 | message = append(message, 0x80) // "1" bit followed by 7 "0" bits |
| 41 | for (len(message)+8)%64 != 0 { |
| 42 | message = append(message, 0x00) // 8 "0" bits |
| 43 | } |
| 44 | message = append(message, L...) |
| 45 | |
| 46 | return message |
| 47 | } |
| 48 | |
| 49 | // Hash hashes the input message using the sha256 hashing function, and return a 32 byte array. |
| 50 | // The implementation follows the RGC6234 standard, which is documented |