Removed lazy sodium both java and android

This commit is contained in:
Ugljesa Jovanovic 2021-02-23 21:50:56 +01:00
parent 574377da3c
commit b85b75e732
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
16 changed files with 36 additions and 50 deletions

View File

@ -5,12 +5,26 @@
# 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
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
[progress here](https://github.com/ionspin/kotlin-multiplatform-crypto/blob/master/supported_bindings_list.md)
#### Gradle
```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
@ -18,8 +32,7 @@ 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
```
= runTest {
LibsodiumInitializer.initializeWithCallback {
LibsodiumInitializer.initializeWithCallback {
// Libsodium initialized
}
```
@ -125,7 +138,7 @@ Currently supported native platforms:
|minGW X86 64| :heavy_check_mark: |
|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
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

View File

@ -24,7 +24,6 @@ object Versions {
val dokkaPlugin = "1.4.20"
val taskTreePlugin = "1.5"
val kotlinBigNumVersion = "0.2.8-SNAPSHOT"
val lazySodium = "4.3.1-SNAPSHOT"
val jna = "5.7.0"
val kotlinPoet = "1.6.0"
val libsodiumBindings = "0.1.1-SNAPSHOT"
@ -118,10 +117,6 @@ object Deps {
val resourceLoader = "co.libly:resource-loader:${Versions.resourceLoader}"
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}"
}
}

View File

@ -48,7 +48,6 @@ val sonatypeUsernameEnv: String? = System.getenv()["SONATYPE_USERNAME"]
repositories {
mavenCentral()
jcenter()
maven("https://dl.bintray.com/terl/lazysodium-maven")
maven {
url = uri("https://oss.sonatype.org/content/repositories/snapshots")
}
@ -74,7 +73,7 @@ android {
}
}
sourceSets.getByName("main") {
jniLibs.srcDir("libs")
// jniLibs.srcDir("src/androidMain/libs")
}
}
@ -442,13 +441,12 @@ kotlin {
val androidMain by getting {
isNotRunningInIdea {
kotlin.srcDirs("src/androidSpecific", "src/jvmMain/kotlin")
kotlin.srcDirs("src/androidMain", "src/androidSpecific", "src/jvmMain/kotlin")
}
isRunningInIdea {
kotlin.srcDirs("src/androidSpecific", "src/jvmMain/kotlin")
}
dependencies {
implementation("com.goterl.lazycode:lazysodium-android:4.2.0@aar")
implementation("net.java.dev.jna:jna:5.5.0@aar")
implementation(Deps.Jvm.resourceLoader) {
exclude("net.java.dev.jna", "jna")
@ -474,9 +472,9 @@ kotlin {
implementation(Deps.Jvm.resourceLoader)
//lazysodium
implementation(Deps.Jvm.Delegated.lazysodium)
implementation(Deps.Jvm.Delegated.jna)
implementation("org.slf4j:slf4j-api:1.7.30")
}
}
val jvmTest by getting {

View File

@ -1,11 +1,2 @@
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

View File

@ -1278,8 +1278,11 @@ interface JnaLibsodiumInterface : Library {
//
// // ---- Scalar multiplication ----
//
// fun crypto_scalarmult(privateKey: Uint8Array, publicKey: Uint8Array) : Uint8Array
// fun crypto_scalarmult_base(privateKey: Uint8Array) : Uint8Array
// int crypto_scalarmult(unsigned char *q, const unsigned char *n,
// 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 ----
}

View File

@ -45,16 +45,14 @@ actual object LibsodiumInitializer {
return library
}
lateinit var sodium : SodiumWrapper
lateinit var sodiumJna : JnaLibsodiumInterface
actual suspend fun initialize() {
sodium = SodiumWrapper()
sodiumJna = loadLibrary()
isPlatformInitialized = true
}
actual fun initializeWithCallback(done: () -> Unit) {
sodium = SodiumWrapper()
sodiumJna = loadLibrary()
isPlatformInitialized = true
done()

View File

@ -1,6 +1,6 @@
package com.ionspin.kotlin.crypto.kdf
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
actual object Kdf {
/**
@ -26,7 +26,7 @@ actual object Kdf {
val subkey = UByteArray(subkeyLength)
val contextEncoded = context.encodeToByteArray()
sodium.crypto_kdf_derive_from_key(
sodiumJna.crypto_kdf_derive_from_key(
subkey.asByteArray(),
subkeyLength,
subkeyId.toLong(),
@ -42,8 +42,8 @@ actual object Kdf {
*/
actual fun keygen(): UByteArray {
val masterKey = UByteArray(crypto_kdf_KEYBYTES)
sodium.crypto_kdf_keygen(masterKey.asByteArray())
sodiumJna.crypto_kdf_keygen(masterKey.asByteArray())
return masterKey
}
}
}

View File

@ -1,6 +1,6 @@
package com.ionspin.kotlin.crypto.scalarmult
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodium
import com.ionspin.kotlin.crypto.LibsodiumInitializer.sodiumJna
actual object ScalarMultiplication {
/**
@ -18,7 +18,7 @@ actual object ScalarMultiplication {
actual fun scalarMultiplication(secretKeyN: UByteArray, publicKeyP: UByteArray): UByteArray {
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
@ -35,7 +35,7 @@ actual object ScalarMultiplication {
): UByteArray {
val result = UByteArray(crypto_scalarmult_BYTES)
sodium.crypto_scalarmult_base(result.asByteArray(), secretKeyN.asByteArray())
sodiumJna.crypto_scalarmult_base(result.asByteArray(), secretKeyN.asByteArray())
return result
}

View File

@ -1,6 +1,5 @@
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.SecretStreamXChaCha20Poly1305State

View File

@ -35,8 +35,6 @@ actual object LibsodiumRandom {
* The randombytes_random() function returns an unpredictable value between 0 and 0xffffffff (included).
*/
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()
}

View File

@ -1,11 +1,2 @@
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