diff --git a/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloL0Interface.kt b/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloL0Interface.kt index a787a17..54274a9 100644 --- a/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloL0Interface.kt +++ b/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloL0Interface.kt @@ -1,10 +1,6 @@ package net.sergeych.kiloparsec import kotlinx.coroutines.CompletableDeferred -import net.sergeych.mp_logger.LogTag -import net.sergeych.mp_logger.Loggable -import net.sergeych.mp_logger.debug -import net.sergeych.mp_logger.info import net.sergeych.tools.AtomicCounter import net.sergeych.utools.pack @@ -19,7 +15,10 @@ private val idCounter = AtomicCounter(0) internal class KiloL0Interface( private val clientInterface: LocalInterface>, private val deferredParams: CompletableDeferred>, -) : LocalInterface(), Loggable by LogTag("KL0:${idCounter.incrementAndGet()}") { +) : LocalInterface() { + + override var logTag: String = "KL0:${idCounter.incrementAndGet()}" + init { // local interface uses the same session as a client: addErrorProvider(clientInterface) diff --git a/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloParams.kt b/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloParams.kt index e484519..7d29ca3 100644 --- a/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloParams.kt +++ b/src/commonMain/kotlin/net/sergeych/kiloparsec/KiloParams.kt @@ -47,23 +47,9 @@ data class KiloParams( blake2b("token_".encodeToUByteArray() + sessionKey.sessionTag).sliceArray(0.. 0u) { - result[i] = result[i] xor (x and 0xFFu).toUByte() - x = x shr 8 - i++ - } - return result - } + private val numericNonce = NumericNonce(token) - private inline fun encodeSendNonce(nonce: ULong): UByteArray = encodeNonce(token, nonce) - private inline fun encodeReceiveNonce(nonce: ULong): UByteArray = encodeNonce(token, nonce) - - - private val proptectedOp = ProtectedOp() + private val protectedOp = ProtectedOp() /** * Encrypt using send keys and proper nonce @@ -74,10 +60,10 @@ data class KiloParams( else null - val n = proptectedOp.invoke { nonce++ } + val n = protectedOp.invoke { nonce++ } return pack( - Package(n, sessionKey.encryptWithNonce(message, encodeSendNonce(n), fill)) + Package(n, sessionKey.encryptWithNonce(message, numericNonce.withULong(n), fill)) ) } @@ -85,7 +71,7 @@ data class KiloParams( fun decrypt(encryptedMessage: UByteArray): UByteArray = protectDecryption { val p: Package = BipackDecoder.decode(encryptedMessage.toDataSource()) - sessionKey.decryptWithNonce(p.encryptedMessage, encodeReceiveNonce(p.nonce)) + sessionKey.decryptWithNonce(p.encryptedMessage, numericNonce.withULong(p.nonce)) } } \ No newline at end of file