Remove bignum dep
This commit is contained in:
parent
67723d2a4b
commit
ed7cb7482b
@ -23,7 +23,7 @@ object Versions {
|
|||||||
val nodePlugin = "1.3.0"
|
val nodePlugin = "1.3.0"
|
||||||
val dokkaPlugin = "1.4.0-rc"
|
val dokkaPlugin = "1.4.0-rc"
|
||||||
val taskTreePlugin = "1.5"
|
val taskTreePlugin = "1.5"
|
||||||
val kotlinBigNumVersion = "0.2.8-SNAPSHOT"
|
val kotlinBigNumVersion = "0.2.8"
|
||||||
val jna = "5.7.0"
|
val jna = "5.7.0"
|
||||||
val kotlinPoet = "1.6.0"
|
val kotlinPoet = "1.6.0"
|
||||||
val libsodiumBindings = "0.1.1-SNAPSHOT"
|
val libsodiumBindings = "0.1.1-SNAPSHOT"
|
||||||
|
@ -254,7 +254,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Common.stdLib))
|
implementation(kotlin(Deps.Common.stdLib))
|
||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val commonTest by getting {
|
val commonTest by getting {
|
||||||
|
@ -26,3 +26,13 @@ fun UByteArray.toHexString() : String {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Array<UByte>.hexColumnsPrint(chunk: Int = 16) {
|
||||||
|
val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk)
|
||||||
|
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||||
|
}
|
||||||
|
|
||||||
|
fun UByteArray.hexColumnsPrint(chunk: Int = 16) {
|
||||||
|
val printout = this.map { it.toString(16).padStart(2, '0') }.chunked(chunk)
|
||||||
|
printout.forEach { println(it.joinToString(separator = " ") { it.toUpperCase() }) }
|
||||||
|
}
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
package com.ionspin.kotlin.crypto.secretstream
|
package com.ionspin.kotlin.crypto.secretstream
|
||||||
|
|
||||||
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
||||||
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
import com.ionspin.kotlin.crypto.util.encodeToUByteArray
|
||||||
import com.ionspin.kotlin.crypto.util.testBlocking
|
import com.ionspin.kotlin.crypto.util.hexColumnsPrint
|
||||||
import com.ionspin.kotlin.crypto.util.runTest
|
import com.ionspin.kotlin.crypto.util.runTest
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
import kotlin.test.assertFailsWith
|
import kotlin.test.assertFailsWith
|
||||||
@ -58,19 +57,19 @@ class SecretStreamTest {
|
|||||||
0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU,
|
0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU,
|
||||||
0xcfU, 0x49U
|
0xcfU, 0x49U
|
||||||
)
|
)
|
||||||
message.hexColumsPrint()
|
message.hexColumnsPrint()
|
||||||
println("---- init enc ----")
|
println("---- init enc ----")
|
||||||
val stateAndHeader = SecretStream.xChaCha20Poly1305InitPush(key)
|
val stateAndHeader = SecretStream.xChaCha20Poly1305InitPush(key)
|
||||||
println("---- encrypt ----")
|
println("---- encrypt ----")
|
||||||
val encrypted =
|
val encrypted =
|
||||||
SecretStream.xChaCha20Poly1305Push(stateAndHeader.state, message, ubyteArrayOf(), 0U)
|
SecretStream.xChaCha20Poly1305Push(stateAndHeader.state, message, ubyteArrayOf(), 0U)
|
||||||
encrypted.hexColumsPrint()
|
encrypted.hexColumnsPrint()
|
||||||
println("---- init dec ----")
|
println("---- init dec ----")
|
||||||
val decryptState = SecretStream.xChaCha20Poly1305InitPull(key, stateAndHeader.header)
|
val decryptState = SecretStream.xChaCha20Poly1305InitPull(key, stateAndHeader.header)
|
||||||
println("---- decrypt ----")
|
println("---- decrypt ----")
|
||||||
val decrypted =
|
val decrypted =
|
||||||
SecretStream.xChaCha20Poly1305Pull(decryptState.state, encrypted, ubyteArrayOf())
|
SecretStream.xChaCha20Poly1305Pull(decryptState.state, encrypted, ubyteArrayOf())
|
||||||
decrypted.decryptedData.hexColumsPrint()
|
decrypted.decryptedData.hexColumnsPrint()
|
||||||
assertTrue {
|
assertTrue {
|
||||||
decrypted.decryptedData.contentEquals(message)
|
decrypted.decryptedData.contentEquals(message)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.ionspin.kotlin.crypto.util
|
package com.ionspin.kotlin.crypto.util
|
||||||
|
|
||||||
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
||||||
import kotlin.math.exp
|
import kotlin.math.exp
|
||||||
import com.ionspin.kotlin.crypto.util.runTest
|
import com.ionspin.kotlin.crypto.util.runTest
|
||||||
@ -47,9 +46,9 @@ class LibsodiumUtilTest {
|
|||||||
val input = ubyteArrayOf(1U, 2U)
|
val input = ubyteArrayOf(1U, 2U)
|
||||||
val blocksize = 16
|
val blocksize = 16
|
||||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||||
println(padded.hexColumsPrint())
|
println(padded.hexColumnsPrint())
|
||||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||||
println(unpadded.hexColumsPrint())
|
println(unpadded.hexColumnsPrint())
|
||||||
|
|
||||||
assertTrue {
|
assertTrue {
|
||||||
input.contentEquals(unpadded)
|
input.contentEquals(unpadded)
|
||||||
@ -63,9 +62,9 @@ class LibsodiumUtilTest {
|
|||||||
val input = charArrayOf('a', 'b', 'c', 'd').map { it.toByte().toUByte() }.toUByteArray()
|
val input = charArrayOf('a', 'b', 'c', 'd').map { it.toByte().toUByte() }.toUByteArray()
|
||||||
val blocksize = 4
|
val blocksize = 4
|
||||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||||
println(padded.hexColumsPrint())
|
println(padded.hexColumnsPrint())
|
||||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||||
println(unpadded.hexColumsPrint())
|
println(unpadded.hexColumnsPrint())
|
||||||
|
|
||||||
assertTrue {
|
assertTrue {
|
||||||
input.contentEquals(unpadded)
|
input.contentEquals(unpadded)
|
||||||
@ -80,10 +79,10 @@ class LibsodiumUtilTest {
|
|||||||
val blocksize = 2
|
val blocksize = 2
|
||||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||||
val expected = ubyteArrayOf(1U, 2U, 0x80U, 0x00U)
|
val expected = ubyteArrayOf(1U, 2U, 0x80U, 0x00U)
|
||||||
println(padded.hexColumsPrint())
|
println(padded.hexColumnsPrint())
|
||||||
assertTrue { padded.contentEquals(expected) }
|
assertTrue { padded.contentEquals(expected) }
|
||||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||||
println(unpadded.hexColumsPrint())
|
println(unpadded.hexColumnsPrint())
|
||||||
|
|
||||||
assertTrue {
|
assertTrue {
|
||||||
input.contentEquals(unpadded)
|
input.contentEquals(unpadded)
|
||||||
@ -98,10 +97,10 @@ class LibsodiumUtilTest {
|
|||||||
val blocksize = 4
|
val blocksize = 4
|
||||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||||
val expected = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U, 0x80U, 0x00U)
|
val expected = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U, 0x80U, 0x00U)
|
||||||
println(padded.hexColumsPrint())
|
println(padded.hexColumnsPrint())
|
||||||
assertTrue { padded.contentEquals(expected) }
|
assertTrue { padded.contentEquals(expected) }
|
||||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||||
println(unpadded.hexColumsPrint())
|
println(unpadded.hexColumnsPrint())
|
||||||
|
|
||||||
assertTrue {
|
assertTrue {
|
||||||
input.contentEquals(unpadded)
|
input.contentEquals(unpadded)
|
||||||
@ -114,13 +113,13 @@ class LibsodiumUtilTest {
|
|||||||
LibsodiumInitializer.initializeWithCallback {
|
LibsodiumInitializer.initializeWithCallback {
|
||||||
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
|
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
|
||||||
val expected = "AQIDBAUgQID_"
|
val expected = "AQIDBAUgQID_"
|
||||||
val output = LibsodiumUtil.toBase64(input)
|
val output = LibsodiumUtil.toBase64(input, Base64Variants.URLSAFE_NO_PADDING)
|
||||||
println("Output: |$output|")
|
println("Output: |$output|")
|
||||||
println("Expected|$expected| ")
|
println("Expected|$expected| ")
|
||||||
assertTrue {
|
assertTrue {
|
||||||
output == expected
|
output == expected
|
||||||
}
|
}
|
||||||
val reconstructed = LibsodiumUtil.fromBase64(output)
|
val reconstructed = LibsodiumUtil.fromBase64(output, Base64Variants.URLSAFE_NO_PADDING)
|
||||||
println("Reconstructed: ${reconstructed.toHexString()}")
|
println("Reconstructed: ${reconstructed.toHexString()}")
|
||||||
assertTrue {
|
assertTrue {
|
||||||
reconstructed.contentEquals(input)
|
reconstructed.contentEquals(input)
|
||||||
@ -133,13 +132,13 @@ class LibsodiumUtilTest {
|
|||||||
LibsodiumInitializer.initializeWithCallback {
|
LibsodiumInitializer.initializeWithCallback {
|
||||||
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
|
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
|
||||||
val expected = "AQIDBAUgQID_gA"
|
val expected = "AQIDBAUgQID_gA"
|
||||||
val output = LibsodiumUtil.toBase64(input)
|
val output = LibsodiumUtil.toBase64(input, Base64Variants.URLSAFE_NO_PADDING)
|
||||||
println("Output: |$output|")
|
println("Output: |$output|")
|
||||||
println("Expected|$expected| ")
|
println("Expected|$expected| ")
|
||||||
assertTrue {
|
assertTrue {
|
||||||
output == expected
|
output == expected
|
||||||
}
|
}
|
||||||
val reconstructed = LibsodiumUtil.fromBase64(output)
|
val reconstructed = LibsodiumUtil.fromBase64(output, Base64Variants.URLSAFE_NO_PADDING)
|
||||||
println("Reconstructed: ${reconstructed.toHexString()}")
|
println("Reconstructed: ${reconstructed.toHexString()}")
|
||||||
assertTrue {
|
assertTrue {
|
||||||
reconstructed.contentEquals(input)
|
reconstructed.contentEquals(input)
|
||||||
|
@ -186,7 +186,6 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
implementation(kotlin(Deps.Common.stdLib))
|
implementation(kotlin(Deps.Common.stdLib))
|
||||||
implementation(kotlin(Deps.Common.test))
|
implementation(kotlin(Deps.Common.test))
|
||||||
implementation(Deps.Common.kotlinBigNum)
|
|
||||||
implementation(Deps.Common.serialization)
|
implementation(Deps.Common.serialization)
|
||||||
api(project(":multiplatform-crypto-libsodium-bindings"))
|
api(project(":multiplatform-crypto-libsodium-bindings"))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user