Removed lazy sodium both java and android
This commit is contained in:
parent
574377da3c
commit
b85b75e732
23
README.md
23
README.md
@ -5,12 +5,26 @@
|
|||||||
|
|
||||||
# Libsodium bindings for Kotiln Multiplatform
|
# Libsodium bindings for Kotiln Multiplatform
|
||||||
|
|
||||||
Libsodium bindings project uses libsodium c sources, libsodium.js as well as LazySodium Java and Android to provide a kotlin multiplatform wrapper library for libsodium.
|
Libsodium bindings project uses libsodium c sources and libsodium.js to provide a kotlin multiplatform wrapper library for libsodium.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
The libsodium binding library is not published yet, once the sample showing the basic usage is ready, the library will be published. You can track the implementation
|
#### Gradle
|
||||||
[progress here](https://github.com/ionspin/kotlin-multiplatform-crypto/blob/master/supported_bindings_list.md)
|
```kotlin
|
||||||
|
implementation("com.ionspin.kotlin:multiplatform-crypto-lisodium-bindings:0.8.0")
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Snapshot builds
|
||||||
|
```kotlin
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
implementation("com.ionspin.kotlin:multiplatform-crypto-lisodium-bindings:0.8.1-SNAPSHOT ")
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
@ -18,7 +32,6 @@ The libsodium binding library is not published yet, once the sample showing the
|
|||||||
Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach
|
Before using the wrapper you need to initialize the underlying libsodium library. You can use either a callback or coroutines approach
|
||||||
|
|
||||||
```
|
```
|
||||||
= runTest {
|
|
||||||
LibsodiumInitializer.initializeWithCallback {
|
LibsodiumInitializer.initializeWithCallback {
|
||||||
// Libsodium initialized
|
// Libsodium initialized
|
||||||
}
|
}
|
||||||
@ -125,7 +138,7 @@ Currently supported native platforms:
|
|||||||
|minGW X86 64| :heavy_check_mark: |
|
|minGW X86 64| :heavy_check_mark: |
|
||||||
|minGW X86 32| :x: |
|
|minGW X86 32| :x: |
|
||||||
|
|
||||||
|
[List of supported bindings](https://github.com/ionspin/kotlin-multiplatform-crypto/blob/master/supported_bindings_list.md)
|
||||||
### Where do the compiled libraries used by JVM and Android come from
|
### Where do the compiled libraries used by JVM and Android come from
|
||||||
Android .so files come from running dist-build scripts in libsodium which you can find in the libsodium submodule
|
Android .so files come from running dist-build scripts in libsodium which you can find in the libsodium submodule
|
||||||
Java Linux Arm/X86_64 and Mac so and dylib are the same as produced by multiplatform builds, also based on the same submodule commit
|
Java Linux Arm/X86_64 and Mac so and dylib are the same as produced by multiplatform builds, also based on the same submodule commit
|
||||||
|
@ -24,7 +24,6 @@ object Versions {
|
|||||||
val dokkaPlugin = "1.4.20"
|
val dokkaPlugin = "1.4.20"
|
||||||
val taskTreePlugin = "1.5"
|
val taskTreePlugin = "1.5"
|
||||||
val kotlinBigNumVersion = "0.2.8-SNAPSHOT"
|
val kotlinBigNumVersion = "0.2.8-SNAPSHOT"
|
||||||
val lazySodium = "4.3.1-SNAPSHOT"
|
|
||||||
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"
|
||||||
@ -118,10 +117,6 @@ object Deps {
|
|||||||
val resourceLoader = "co.libly:resource-loader:${Versions.resourceLoader}"
|
val resourceLoader = "co.libly:resource-loader:${Versions.resourceLoader}"
|
||||||
|
|
||||||
object Delegated {
|
object Delegated {
|
||||||
// Temporary until reported lazysodium issues are fixed. My snapshot build with
|
|
||||||
// And cause I registered com.ionspin.kotlin as maven central package root now I have to use
|
|
||||||
// that even though this is pure java library. :)
|
|
||||||
val lazysodium = "com.ionspin.kotlin:lazysodium-java:${Versions.lazySodium}"
|
|
||||||
val jna = "net.java.dev.jna:jna:${Versions.jna}"
|
val jna = "net.java.dev.jna:jna:${Versions.jna}"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -48,7 +48,6 @@ val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"]
|
|||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
jcenter()
|
jcenter()
|
||||||
maven("https://dl.bintray.com/terl/lazysodium-maven")
|
|
||||||
maven {
|
maven {
|
||||||
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
|
||||||
}
|
}
|
||||||
@ -74,7 +73,7 @@ android {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sourceSets.getByName("main") {
|
sourceSets.getByName("main") {
|
||||||
jniLibs.srcDir("libs")
|
// jniLibs.srcDir("src/androidMain/libs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,13 +441,12 @@ kotlin {
|
|||||||
|
|
||||||
val androidMain by getting {
|
val androidMain by getting {
|
||||||
isNotRunningInIdea {
|
isNotRunningInIdea {
|
||||||
kotlin.srcDirs("src/androidSpecific", "src/jvmMain/kotlin")
|
kotlin.srcDirs("src/androidMain", "src/androidSpecific", "src/jvmMain/kotlin")
|
||||||
}
|
}
|
||||||
isRunningInIdea {
|
isRunningInIdea {
|
||||||
kotlin.srcDirs("src/androidSpecific", "src/jvmMain/kotlin")
|
kotlin.srcDirs("src/androidSpecific", "src/jvmMain/kotlin")
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("com.goterl.lazycode:lazysodium-android:4.2.0@aar")
|
|
||||||
implementation("net.java.dev.jna:jna:5.5.0@aar")
|
implementation("net.java.dev.jna:jna:5.5.0@aar")
|
||||||
implementation(Deps.Jvm.resourceLoader) {
|
implementation(Deps.Jvm.resourceLoader) {
|
||||||
exclude("net.java.dev.jna", "jna")
|
exclude("net.java.dev.jna", "jna")
|
||||||
@ -474,9 +472,9 @@ kotlin {
|
|||||||
|
|
||||||
implementation(Deps.Jvm.resourceLoader)
|
implementation(Deps.Jvm.resourceLoader)
|
||||||
|
|
||||||
//lazysodium
|
|
||||||
implementation(Deps.Jvm.Delegated.lazysodium)
|
|
||||||
implementation(Deps.Jvm.Delegated.jna)
|
implementation(Deps.Jvm.Delegated.jna)
|
||||||
|
|
||||||
|
implementation("org.slf4j:slf4j-api:1.7.30")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
val jvmTest by getting {
|
val jvmTest by getting {
|
||||||
|
@ -1,11 +1,2 @@
|
|||||||
package com.ionspin.kotlin.crypto
|
package com.ionspin.kotlin.crypto
|
||||||
|
|
||||||
import com.goterl.lazycode.lazysodium.SodiumAndroid
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Ugljesa Jovanovic
|
|
||||||
* ugljesa.jovanovic@ionspin.com
|
|
||||||
* on 22-Aug-2020
|
|
||||||
*/
|
|
||||||
typealias SodiumWrapper = SodiumAndroid
|
|
||||||
|
@ -1278,8 +1278,11 @@ interface JnaLibsodiumInterface : Library {
|
|||||||
//
|
//
|
||||||
// // ---- Scalar multiplication ----
|
// // ---- Scalar multiplication ----
|
||||||
//
|
//
|
||||||
// fun crypto_scalarmult(privateKey: Uint8Array, publicKey: Uint8Array) : Uint8Array
|
// int crypto_scalarmult(unsigned char *q, const unsigned char *n,
|
||||||
// fun crypto_scalarmult_base(privateKey: Uint8Array) : Uint8Array
|
// const unsigned char *p)
|
||||||
|
fun crypto_scalarmult(q: ByteArray, n: ByteArray, p: ByteArray)
|
||||||
|
// int crypto_scalarmult_base(unsigned char *q, const unsigned char *n)
|
||||||
|
fun crypto_scalarmult_base(q: ByteArray, b: ByteArray)
|
||||||
//
|
//
|
||||||
// // ---- Scalar multiplication end ----
|
// // ---- Scalar multiplication end ----
|
||||||
}
|
}
|
||||||
|
@ -45,16 +45,14 @@ actual object LibsodiumInitializer {
|
|||||||
return library
|
return library
|
||||||
}
|
}
|
||||||
|
|
||||||
lateinit var sodium : SodiumWrapper
|
|
||||||
lateinit var sodiumJna : JnaLibsodiumInterface
|
lateinit var sodiumJna : JnaLibsodiumInterface
|
||||||
actual suspend fun initialize() {
|
actual suspend fun initialize() {
|
||||||
sodium = SodiumWrapper()
|
|
||||||
sodiumJna = loadLibrary()
|
sodiumJna = loadLibrary()
|
||||||
isPlatformInitialized = true
|
isPlatformInitialized = true
|
||||||
}
|
}
|
||||||
|
|
||||||
actual fun initializeWithCallback(done: () -> Unit) {
|
actual fun initializeWithCallback(done: () -> Unit) {
|
||||||
sodium = SodiumWrapper()
|
|
||||||
sodiumJna = loadLibrary()
|
sodiumJna = loadLibrary()
|
||||||
isPlatformInitialized = true
|
isPlatformInitialized = true
|
||||||
done()
|
done()
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.ionspin.kotlin.crypto.kdf
|
package com.ionspin.kotlin.crypto.kdf
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
|
|
||||||
actual object Kdf {
|
actual object Kdf {
|
||||||
/**
|
/**
|
||||||
@ -26,7 +26,7 @@ actual object Kdf {
|
|||||||
val subkey = UByteArray(subkeyLength)
|
val subkey = UByteArray(subkeyLength)
|
||||||
val contextEncoded = context.encodeToByteArray()
|
val contextEncoded = context.encodeToByteArray()
|
||||||
|
|
||||||
sodium.crypto_kdf_derive_from_key(
|
sodiumJna.crypto_kdf_derive_from_key(
|
||||||
subkey.asByteArray(),
|
subkey.asByteArray(),
|
||||||
subkeyLength,
|
subkeyLength,
|
||||||
subkeyId.toLong(),
|
subkeyId.toLong(),
|
||||||
@ -42,7 +42,7 @@ actual object Kdf {
|
|||||||
*/
|
*/
|
||||||
actual fun keygen(): UByteArray {
|
actual fun keygen(): UByteArray {
|
||||||
val masterKey = UByteArray(crypto_kdf_KEYBYTES)
|
val masterKey = UByteArray(crypto_kdf_KEYBYTES)
|
||||||
sodium.crypto_kdf_keygen(masterKey.asByteArray())
|
sodiumJna.crypto_kdf_keygen(masterKey.asByteArray())
|
||||||
return masterKey
|
return masterKey
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package com.ionspin.kotlin.crypto.scalarmult
|
package com.ionspin.kotlin.crypto.scalarmult
|
||||||
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
|
|
||||||
actual object ScalarMultiplication {
|
actual object ScalarMultiplication {
|
||||||
/**
|
/**
|
||||||
@ -18,7 +18,7 @@ actual object ScalarMultiplication {
|
|||||||
actual fun scalarMultiplication(secretKeyN: UByteArray, publicKeyP: UByteArray): UByteArray {
|
actual fun scalarMultiplication(secretKeyN: UByteArray, publicKeyP: UByteArray): UByteArray {
|
||||||
val result = UByteArray(crypto_scalarmult_BYTES)
|
val result = UByteArray(crypto_scalarmult_BYTES)
|
||||||
|
|
||||||
sodium.crypto_scalarmult(result.asByteArray(), secretKeyN.asByteArray(), publicKeyP.asByteArray())
|
sodiumJna.crypto_scalarmult(result.asByteArray(), secretKeyN.asByteArray(), publicKeyP.asByteArray())
|
||||||
|
|
||||||
|
|
||||||
return result
|
return result
|
||||||
@ -35,7 +35,7 @@ actual object ScalarMultiplication {
|
|||||||
): UByteArray {
|
): UByteArray {
|
||||||
val result = UByteArray(crypto_scalarmult_BYTES)
|
val result = UByteArray(crypto_scalarmult_BYTES)
|
||||||
|
|
||||||
sodium.crypto_scalarmult_base(result.asByteArray(), secretKeyN.asByteArray())
|
sodiumJna.crypto_scalarmult_base(result.asByteArray(), secretKeyN.asByteArray())
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.ionspin.kotlin.crypto.secretstream
|
package com.ionspin.kotlin.crypto.secretstream
|
||||||
|
|
||||||
import com.goterl.lazycode.lazysodium.interfaces.SecretStream
|
|
||||||
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
|
||||||
import com.ionspin.kotlin.crypto.SecretStreamXChaCha20Poly1305State
|
import com.ionspin.kotlin.crypto.SecretStreamXChaCha20Poly1305State
|
||||||
|
|
||||||
|
@ -35,8 +35,6 @@ actual object LibsodiumRandom {
|
|||||||
* The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included).
|
* The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included).
|
||||||
*/
|
*/
|
||||||
actual fun random(): UInt {
|
actual fun random(): UInt {
|
||||||
//Broken in lazysodium-java https://github.com/terl/lazysodium-java/issues/86
|
|
||||||
//Using temporary forked and fixed build until pull request is accepted in original repo
|
|
||||||
return sodiumJna.randombytes_random().toUInt()
|
return sodiumJna.randombytes_random().toUInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,2 @@
|
|||||||
package com.ionspin.kotlin.crypto
|
package com.ionspin.kotlin.crypto
|
||||||
|
|
||||||
import com.goterl.lazycode.lazysodium.LazySodiumJava
|
|
||||||
import com.goterl.lazycode.lazysodium.SodiumJava
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by Ugljesa Jovanovic
|
|
||||||
* ugljesa.jovanovic@ionspin.com
|
|
||||||
* on 22-Aug-2020
|
|
||||||
*/
|
|
||||||
typealias SodiumWrapper = SodiumJava
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user