Skip to content

Commit

Permalink
Prevent second division
Browse files Browse the repository at this point in the history
  • Loading branch information
ligi committed Apr 11, 2020
1 parent 9c97e88 commit 6fe00e9
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions sha512/src/main/kotlin/org/komputing/khash/sha512/Sha512.kt
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ object Sha512 {
private fun padMessage(input: ByteArray): ByteArray {
// Need to append at least 17 bytes (16 for length of the message, and 1 for the '1' bit)
// then fill with 0s until multiple of 128 bytes
val size = (input.size + 17).let {
if (it % 128 == 0) it else it + 128 - it % 128
val size = (input.size + 17).let { padded_input ->
(padded_input % 128).let { remainder ->
if (remainder == 0) padded_input else padded_input + 128 - remainder
}
}

val len = input.size * 8L
Expand Down

0 comments on commit 6fe00e9

Please sign in to comment.