Merge pull request #9 from ionspin/add-64bit-arm-linux
Add arm64 .so, add branch for arm in loader
This commit is contained in:
commit
7b394017e3
@ -23,7 +23,7 @@ object Versions {
|
||||
val nodePlugin = "1.3.0"
|
||||
val dokkaPlugin = "1.4.0-rc"
|
||||
val taskTreePlugin = "1.5"
|
||||
val kotlinBigNumVersion = "0.2.8-SNAPSHOT"
|
||||
val kotlinBigNumVersion = "0.2.8"
|
||||
val jna = "5.7.0"
|
||||
val kotlinPoet = "1.6.0"
|
||||
val libsodiumBindings = "0.1.1-SNAPSHOT"
|
||||
|
@ -254,7 +254,6 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(kotlin(Deps.Common.stdLib))
|
||||
implementation(kotlin(Deps.Common.test))
|
||||
implementation(Deps.Common.kotlinBigNum)
|
||||
}
|
||||
}
|
||||
val commonTest by getting {
|
||||
|
@ -21,10 +21,10 @@ expect object LibsodiumUtil {
|
||||
fun pad(unpaddedData : UByteArray, blocksize: Int) : UByteArray
|
||||
fun unpad(paddedData: UByteArray, blocksize: Int) : UByteArray
|
||||
|
||||
fun toBase64(data: UByteArray, variant : Base64Variants = Base64Variants.URLSAFE_NO_PADDING) : String
|
||||
fun toBase64(data: UByteArray, variant : Base64Variants = Base64Variants.ORIGINAL) : String
|
||||
fun toHex(data: UByteArray) : String
|
||||
|
||||
fun fromBase64(data: String, variant : Base64Variants = Base64Variants.URLSAFE_NO_PADDING) : UByteArray
|
||||
fun fromBase64(data: String, variant : Base64Variants = Base64Variants.ORIGINAL) : UByteArray
|
||||
fun fromHex(data: String) : UByteArray
|
||||
|
||||
}
|
||||
|
@ -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
|
||||
|
||||
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
|
||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
||||
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 kotlin.test.Test
|
||||
import kotlin.test.assertFailsWith
|
||||
@ -58,19 +57,19 @@ class SecretStreamTest {
|
||||
0x98U, 0x79U, 0x47U, 0xdeU, 0xafU, 0xd8U, 0x78U, 0x0aU,
|
||||
0xcfU, 0x49U
|
||||
)
|
||||
message.hexColumsPrint()
|
||||
message.hexColumnsPrint()
|
||||
println("---- init enc ----")
|
||||
val stateAndHeader = SecretStream.xChaCha20Poly1305InitPush(key)
|
||||
println("---- encrypt ----")
|
||||
val encrypted =
|
||||
SecretStream.xChaCha20Poly1305Push(stateAndHeader.state, message, ubyteArrayOf(), 0U)
|
||||
encrypted.hexColumsPrint()
|
||||
encrypted.hexColumnsPrint()
|
||||
println("---- init dec ----")
|
||||
val decryptState = SecretStream.xChaCha20Poly1305InitPull(key, stateAndHeader.header)
|
||||
println("---- decrypt ----")
|
||||
val decrypted =
|
||||
SecretStream.xChaCha20Poly1305Pull(decryptState.state, encrypted, ubyteArrayOf())
|
||||
decrypted.decryptedData.hexColumsPrint()
|
||||
decrypted.decryptedData.hexColumnsPrint()
|
||||
assertTrue {
|
||||
decrypted.decryptedData.contentEquals(message)
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
package com.ionspin.kotlin.crypto.util
|
||||
|
||||
import com.ionspin.kotlin.bignum.integer.util.hexColumsPrint
|
||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer
|
||||
import kotlin.math.exp
|
||||
import com.ionspin.kotlin.crypto.util.runTest
|
||||
@ -47,9 +46,9 @@ class LibsodiumUtilTest {
|
||||
val input = ubyteArrayOf(1U, 2U)
|
||||
val blocksize = 16
|
||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||
println(padded.hexColumsPrint())
|
||||
println(padded.hexColumnsPrint())
|
||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||
println(unpadded.hexColumsPrint())
|
||||
println(unpadded.hexColumnsPrint())
|
||||
|
||||
assertTrue {
|
||||
input.contentEquals(unpadded)
|
||||
@ -63,9 +62,9 @@ class LibsodiumUtilTest {
|
||||
val input = charArrayOf('a', 'b', 'c', 'd').map { it.toByte().toUByte() }.toUByteArray()
|
||||
val blocksize = 4
|
||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||
println(padded.hexColumsPrint())
|
||||
println(padded.hexColumnsPrint())
|
||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||
println(unpadded.hexColumsPrint())
|
||||
println(unpadded.hexColumnsPrint())
|
||||
|
||||
assertTrue {
|
||||
input.contentEquals(unpadded)
|
||||
@ -80,10 +79,10 @@ class LibsodiumUtilTest {
|
||||
val blocksize = 2
|
||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||
val expected = ubyteArrayOf(1U, 2U, 0x80U, 0x00U)
|
||||
println(padded.hexColumsPrint())
|
||||
println(padded.hexColumnsPrint())
|
||||
assertTrue { padded.contentEquals(expected) }
|
||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||
println(unpadded.hexColumsPrint())
|
||||
println(unpadded.hexColumnsPrint())
|
||||
|
||||
assertTrue {
|
||||
input.contentEquals(unpadded)
|
||||
@ -98,10 +97,10 @@ class LibsodiumUtilTest {
|
||||
val blocksize = 4
|
||||
val padded = LibsodiumUtil.pad(input, blocksize)
|
||||
val expected = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 6U, 0x80U, 0x00U)
|
||||
println(padded.hexColumsPrint())
|
||||
println(padded.hexColumnsPrint())
|
||||
assertTrue { padded.contentEquals(expected) }
|
||||
val unpadded = LibsodiumUtil.unpad(padded, blocksize)
|
||||
println(unpadded.hexColumsPrint())
|
||||
println(unpadded.hexColumnsPrint())
|
||||
|
||||
assertTrue {
|
||||
input.contentEquals(unpadded)
|
||||
@ -114,13 +113,13 @@ class LibsodiumUtilTest {
|
||||
LibsodiumInitializer.initializeWithCallback {
|
||||
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U)
|
||||
val expected = "AQIDBAUgQID_"
|
||||
val output = LibsodiumUtil.toBase64(input)
|
||||
val output = LibsodiumUtil.toBase64(input, Base64Variants.URLSAFE_NO_PADDING)
|
||||
println("Output: |$output|")
|
||||
println("Expected|$expected| ")
|
||||
assertTrue {
|
||||
output == expected
|
||||
}
|
||||
val reconstructed = LibsodiumUtil.fromBase64(output)
|
||||
val reconstructed = LibsodiumUtil.fromBase64(output, Base64Variants.URLSAFE_NO_PADDING)
|
||||
println("Reconstructed: ${reconstructed.toHexString()}")
|
||||
assertTrue {
|
||||
reconstructed.contentEquals(input)
|
||||
@ -133,13 +132,13 @@ class LibsodiumUtilTest {
|
||||
LibsodiumInitializer.initializeWithCallback {
|
||||
val input = ubyteArrayOf(1U, 2U, 3U, 4U, 5U, 32U, 64U, 128U, 255U, 128U)
|
||||
val expected = "AQIDBAUgQID_gA"
|
||||
val output = LibsodiumUtil.toBase64(input)
|
||||
val output = LibsodiumUtil.toBase64(input, Base64Variants.URLSAFE_NO_PADDING)
|
||||
println("Output: |$output|")
|
||||
println("Expected|$expected| ")
|
||||
assertTrue {
|
||||
output == expected
|
||||
}
|
||||
val reconstructed = LibsodiumUtil.fromBase64(output)
|
||||
val reconstructed = LibsodiumUtil.fromBase64(output, Base64Variants.URLSAFE_NO_PADDING)
|
||||
println("Reconstructed: ${reconstructed.toHexString()}")
|
||||
assertTrue {
|
||||
reconstructed.contentEquals(input)
|
||||
|
@ -19,7 +19,12 @@ actual object LibsodiumInitializer {
|
||||
SharedLibraryLoader.get().load("dynamic-macos-x86-64.dylib", JnaLibsodiumInterface::class.java)
|
||||
}
|
||||
Platform.isLinux() -> {
|
||||
SharedLibraryLoader.get().load("dynamic-linux-x86-64-libsodium.so", JnaLibsodiumInterface::class.java)
|
||||
if (Platform.isARM()) {
|
||||
SharedLibraryLoader.get().load("dynamic-linux-arm64-libsodium.so", JnaLibsodiumInterface::class.java)
|
||||
} else {
|
||||
SharedLibraryLoader.get()
|
||||
.load("dynamic-linux-x86-64-libsodium.so", JnaLibsodiumInterface::class.java)
|
||||
}
|
||||
}
|
||||
Platform.isWindows() -> {
|
||||
SharedLibraryLoader.get().load("dynamic-msvc-x86-64-libsodium.dll", JnaLibsodiumInterface::class.java)
|
||||
|
Binary file not shown.
@ -186,7 +186,6 @@ kotlin {
|
||||
dependencies {
|
||||
implementation(kotlin(Deps.Common.stdLib))
|
||||
implementation(kotlin(Deps.Common.test))
|
||||
implementation(Deps.Common.kotlinBigNum)
|
||||
implementation(Deps.Common.serialization)
|
||||
api(project(":multiplatform-crypto-libsodium-bindings"))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user