removes some warnings

This commit is contained in:
Vitor Pamplona
2026-04-06 17:12:00 -04:00
parent 034c1ab2d1
commit 8a914d3130
6 changed files with 12 additions and 14 deletions
@@ -298,7 +298,7 @@ internal object FieldP {
// ==================== Reduction ====================
inline fun reduceSelf(a: LongArray) {
fun reduceSelf(a: LongArray) {
// Exploit P's structure: P = [P0, -1, -1, -1] where P[1..3] = 0xFFFFFFFFFFFFFFFF.
// a >= P only if a[3]==a[2]==a[1]==-1 AND a[0] >= P[0]. The first check (a[3]==-1)
// fails >99.99% of the time for random field elements, making this a single branch.
@@ -49,7 +49,7 @@ internal object Glv {
// ==================== GLV Scalar Decomposition ====================
data class Split(
class Split(
val k1: LongArray,
val k2: LongArray,
val negK1: Boolean,
@@ -74,8 +74,8 @@ internal object KeyCodec {
outX: LongArray,
outY: LongArray,
): Boolean =
when {
pubkey.size == 33 && (pubkey[0] == 0x02.toByte() || pubkey[0] == 0x03.toByte()) -> {
when (pubkey.size) {
33 if (pubkey[0] == 0x02.toByte() || pubkey[0] == 0x03.toByte()) -> {
val x = U256.fromBytes(pubkey.copyOfRange(1, 33))
if (U256.cmp(x, FieldP.P) >= 0) return false
val t = LongArray(4)
@@ -89,7 +89,7 @@ internal object KeyCodec {
true
}
pubkey.size == 65 && pubkey[0] == 0x04.toByte() -> {
65 if pubkey[0] == 0x04.toByte() -> {
val x = U256.fromBytes(pubkey.copyOfRange(1, 33))
val y = U256.fromBytes(pubkey.copyOfRange(33, 65))
val y2 = LongArray(4)
@@ -93,7 +93,7 @@ internal class MutablePoint(
val y: LongArray = LongArray(4),
val z: LongArray = LongArray(4),
) {
inline fun isInfinity(): Boolean = U256.isZero(z)
fun isInfinity(): Boolean = U256.isZero(z)
fun setInfinity() {
for (i in 0 until 4) {
@@ -279,7 +279,7 @@ internal object ECPoint {
val base = b * COMB_POINTS
jac[base].setInfinity()
for (m in 1 until COMB_POINTS) {
val changedBit = Integer.numberOfTrailingZeros(m)
val changedBit = m.countTrailingZeroBits()
if (m and (m - 1) == 0) {
jac[base + m].copyFrom(toothG[b * COMB_TEETH + changedBit])
} else {
@@ -122,15 +122,15 @@ object Secp256k1 {
* For already-compressed keys: returns the input unchanged.
*/
fun pubKeyCompress(pubkey: ByteArray): ByteArray =
when {
pubkey.size == 65 && pubkey[0] == 0x04.toByte() -> {
when (pubkey.size) {
65 if pubkey[0] == 0x04.toByte() -> {
val result = ByteArray(33)
result[0] = if (pubkey[64].toInt() and 1 == 0) 0x02 else 0x03
pubkey.copyInto(result, 1, 1, 33)
result
}
pubkey.size == 33 && (pubkey[0] == 0x02.toByte() || pubkey[0] == 0x03.toByte()) -> {
33 if (pubkey[0] == 0x02.toByte() || pubkey[0] == 0x03.toByte()) -> {
pubkey
}
@@ -49,9 +49,7 @@ package com.vitorpamplona.quartz.utils.secp256k1
* Raw 256-bit unsigned integer arithmetic using 4×64-bit limbs.
*/
internal object U256 {
val ZERO = LongArray(4)
inline fun isZero(a: LongArray): Boolean = (a[0] or a[1] or a[2] or a[3]) == 0L
fun isZero(a: LongArray): Boolean = (a[0] or a[1] or a[2] or a[3]) == 0L
/** Unsigned comparison. Returns -1 if a < b, 0 if equal, 1 if a > b. */
fun cmp(
@@ -254,7 +252,7 @@ internal object U256 {
}
/** Test if bit at position pos is set. Called ~2,800× per mulG (comb table lookup). */
inline fun testBit(
fun testBit(
a: LongArray,
pos: Int,
): Boolean = (a[pos / 64] ushr (pos % 64)) and 1L == 1L