Skip to content

Commit

Permalink
Do not process most significant bits if 0
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm committed Jan 3, 2025
1 parent c17f0e9 commit ba8d668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ POM_DEVELOPER_ID=KotlinCrypto
POM_DEVELOPER_NAME=Kotlin Crypto
POM_DEVELOPER_URL=https://github.com/KotlinCrypto/

VERSION_NAME=1.0.0-SNAPSHOT
VERSION_NAME=1.0.0-alpha01-SNAPSHOT
# 0.1.0-alpha01 = 00 01 00 11
# 0.1.0-beta01 = 00 01 00 21
# 0.1.0-rc01 = 00 01 00 31
# 0.1.0 = 00 01 00 99
# 1.1.0 = 01 01 00 99
VERSION_CODE=01000099
VERSION_CODE=01000011
37 changes: 23 additions & 14 deletions library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/Xof.kt
Original file line number Diff line number Diff line change
Expand Up @@ -238,22 +238,31 @@ public sealed class Xof<A: XofAlgorithm>: Algorithm, Copyable<Xof<A>>, Resettabl

@JvmStatic
private fun encode(lo: Int, hi: Int, left: Boolean): ByteArray {
if (lo == 0 && hi == 0) {
// If it's zero, return early
return if (left) byteArrayOf(1, 0) else byteArrayOf(0, 1)
val a = if (hi == 0) {
if (lo == 0) {
// If it's zero, return early
return if (left) byteArrayOf(1, 0) else byteArrayOf(0, 1)
}

byteArrayOf(
(lo ushr 24).toByte(),
(lo ushr 16).toByte(),
(lo ushr 8).toByte(),
(lo ).toByte(),
)
} else {
byteArrayOf(
(hi ushr 24).toByte(),
(hi ushr 16).toByte(),
(hi ushr 8).toByte(),
(hi ).toByte(),
(lo ushr 24).toByte(),
(lo ushr 16).toByte(),
(lo ushr 8).toByte(),
(lo ).toByte(),
)
}

val a = byteArrayOf(
(hi ushr 24).toByte(),
(hi ushr 16).toByte(),
(hi ushr 8).toByte(),
(hi ).toByte(),
(lo ushr 24).toByte(),
(lo ushr 16).toByte(),
(lo ushr 8).toByte(),
(lo ).toByte(),
)

// Find index of first non-zero byte
var i = 0
while (i < a.size && a[i] == ZERO) {
Expand Down

0 comments on commit ba8d668

Please sign in to comment.