Skip to content

Commit 6fe00e9

Browse files
committed
Prevent second division
1 parent 9c97e88 commit 6fe00e9

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

  • sha512/src/main/kotlin/org/komputing/khash/sha512

sha512/src/main/kotlin/org/komputing/khash/sha512/Sha512.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ object Sha512 {
129129
private fun padMessage(input: ByteArray): ByteArray {
130130
// Need to append at least 17 bytes (16 for length of the message, and 1 for the '1' bit)
131131
// then fill with 0s until multiple of 128 bytes
132-
val size = (input.size + 17).let {
133-
if (it % 128 == 0) it else it + 128 - it % 128
132+
val size = (input.size + 17).let { padded_input ->
133+
(padded_input % 128).let { remainder ->
134+
if (remainder == 0) padded_input else padded_input + 128 - remainder
135+
}
134136
}
135137

136138
val len = input.size * 8L

0 commit comments

Comments
 (0)