[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-kotlin] branch master updated: add build configuration for
From: |
gnunet |
Subject: |
[taler-wallet-kotlin] branch master updated: add build configuration for ios |
Date: |
Tue, 28 Jul 2020 22:20:28 +0200 |
This is an automated email from the git hooks/post-receive script.
jonathan-buchanan pushed a commit to branch master
in repository wallet-kotlin.
The following commit(s) were added to refs/heads/master by this push:
new 6251cc6 add build configuration for ios
6251cc6 is described below
commit 6251cc652720ab0fefa4e5fd7238ee2f043838e3
Author: Jonathan Buchanan <jonathan.russ.buchanan@gmail.com>
AuthorDate: Tue Jul 28 16:20:18 2020 -0400
add build configuration for ios
---
build.gradle | 26 +++
.../kotlin/net/taler/wallet/kotlin/TestUtils.kt | 1 +
src/iosMain/kotlin/net/taler/wallet/kotlin/Db.kt | 23 +++
.../taler/wallet/kotlin/crypto/CryptoFactory.kt | 187 +++++++++++++++++++++
.../kotlin/net/taler/wallet/kotlin/TestUtils.kt | 24 +++
src/nativeInterop/cinterop/sodium.def | 4 +-
6 files changed, 263 insertions(+), 2 deletions(-)
diff --git a/build.gradle b/build.gradle
index 007a4bd..d053bc7 100644
--- a/build.gradle
+++ b/build.gradle
@@ -43,6 +43,18 @@ kotlin {
}
}
// For ARM, should be changed to iosArm32 or iosArm64
+ ios {
+ compilations.main.cinterops {
+ sodium {
+ packageName 'org.libsodium'
+ }
+ }
+ binaries {
+ framework {
+ baseName = "TalerWallet"
+ }
+ }
+ }
// For Linux, should be changed to e.g. linuxX64
// For MacOS, should be changed to e.g. macosX64
// For Windows, should be changed to e.g. mingwX64
@@ -78,6 +90,20 @@ kotlin {
api "io.ktor:ktor-client-mock:$ktor_version"
}
}
+ iosMain {
+ dependencies {
+ implementation
"org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
+ implementation "io.ktor:ktor-client-ios:$ktor_version"
+ implementation
"io.ktor:ktor-client-logging-native:$ktor_version"
+ implementation
"io.ktor:ktor-client-serialization-native:$ktor_version"
+ }
+ }
+ iosTest {
+ dependencies {
+ implementation
"org.jetbrains.kotlinx:kotlinx-coroutines-core-native:$coroutines_version"
+ api "io.ktor:ktor-client-mock-native:$ktor_version"
+ }
+ }
androidMain {
dependencies {
implementation kotlin('stdlib-jdk8')
diff --git a/src/commonTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
b/src/commonTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
index 72e4b4b..4b04ebf 100644
--- a/src/commonTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
+++ b/src/commonTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
@@ -34,6 +34,7 @@ import kotlinx.serialization.json.Json
enum class PlatformTarget {
ANDROID,
+ NATIVE_IOS,
JS,
NATIVE_LINUX,
}
diff --git a/src/iosMain/kotlin/net/taler/wallet/kotlin/Db.kt
b/src/iosMain/kotlin/net/taler/wallet/kotlin/Db.kt
new file mode 100644
index 0000000..45cbfc3
--- /dev/null
+++ b/src/iosMain/kotlin/net/taler/wallet/kotlin/Db.kt
@@ -0,0 +1,23 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.kotlin
+
+internal actual class DbFactory {
+ actual fun openDb(): Db {
+ return FakeDb()
+ }
+}
diff --git a/src/iosMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoFactory.kt
b/src/iosMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoFactory.kt
new file mode 100644
index 0000000..7860607
--- /dev/null
+++ b/src/iosMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoFactory.kt
@@ -0,0 +1,187 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.kotlin.crypto
+
+import kotlinx.cinterop.CValuesRef
+import kotlinx.cinterop.UByteVar
+import kotlinx.cinterop.alloc
+import kotlinx.cinterop.free
+import kotlinx.cinterop.nativeHeap
+import kotlinx.cinterop.ptr
+import kotlinx.cinterop.refTo
+import org.libsodium.crypto_hash_sha256
+import org.libsodium.crypto_hash_sha256_bytes
+import org.libsodium.crypto_hash_sha512
+import org.libsodium.crypto_hash_sha512_bytes
+import org.libsodium.crypto_hash_sha512_final
+import org.libsodium.crypto_hash_sha512_init
+import org.libsodium.crypto_hash_sha512_state
+import org.libsodium.crypto_hash_sha512_update
+import org.libsodium.crypto_scalarmult
+import org.libsodium.crypto_scalarmult_BYTES
+import org.libsodium.crypto_scalarmult_base
+import org.libsodium.crypto_scalarmult_curve25519_BYTES
+import org.libsodium.crypto_sign_BYTES
+import org.libsodium.crypto_sign_PUBLICKEYBYTES
+import org.libsodium.crypto_sign_SECRETKEYBYTES
+import org.libsodium.crypto_sign_detached
+import org.libsodium.crypto_sign_ed25519_pk_to_curve25519
+import org.libsodium.crypto_sign_seed_keypair
+import org.libsodium.crypto_sign_verify_detached
+import org.libsodium.randombytes
+
+internal actual object CryptoFactory {
+ internal actual fun getCrypto(): Crypto = CryptoNativeImpl
+}
+
+@OptIn(ExperimentalUnsignedTypes::class)
+internal object CryptoNativeImpl : CryptoImpl() {
+
+ override fun sha256(input: ByteArray): ByteArray {
+ val output = ByteArray(crypto_hash_sha256_bytes().toInt())
+ val cInput = if (input.isEmpty()) null else input.toCValuesRef()
+ crypto_hash_sha256(output.toCValuesRef(), cInput, input.size.toULong())
+ return output
+ }
+
+ override fun sha512(input: ByteArray): ByteArray {
+ val output = ByteArray(crypto_hash_sha512_bytes().toInt())
+ val cInput = if (input.isEmpty()) null else input.toCValuesRef()
+ crypto_hash_sha512(output.toCValuesRef(), cInput, input.size.toULong())
+ return output
+ }
+
+ override fun getHashSha512State(): HashSha512State {
+ return NativeHashSha512State()
+ }
+
+ override fun getRandomBytes(num: Int): ByteArray {
+ val bytes = ByteArray(num)
+ randombytes(bytes.toCValuesRef(), num.toULong())
+ return bytes
+ }
+
+ override fun eddsaGetPublic(eddsaPrivateKey: ByteArray): ByteArray {
+ val publicKey = ByteArray(crypto_sign_PUBLICKEYBYTES.toInt())
+ val privateKey = ByteArray(crypto_sign_SECRETKEYBYTES.toInt())
+ crypto_sign_seed_keypair(publicKey.toCValuesRef(),
privateKey.toCValuesRef(), eddsaPrivateKey.toCValuesRef())
+ return publicKey
+ }
+
+ override fun ecdheGetPublic(ecdhePrivateKey: ByteArray): ByteArray {
+ val publicKey = ByteArray(crypto_scalarmult_BYTES.toInt())
+ crypto_scalarmult_base(publicKey.toCValuesRef(),
ecdhePrivateKey.toCValuesRef())
+ return publicKey
+ }
+
+ override fun createEddsaKeyPair(): EddsaKeyPair {
+ val privateKey = ByteArray(crypto_sign_SECRETKEYBYTES.toInt())
+ randombytes(privateKey.toCValuesRef(),
crypto_sign_SECRETKEYBYTES.toULong())
+ val publicKey = eddsaGetPublic(privateKey)
+ return EddsaKeyPair(privateKey, publicKey)
+ }
+
+ override fun createEcdheKeyPair(): EcdheKeyPair {
+ val privateKey = ByteArray(crypto_scalarmult_BYTES.toInt())
+ randombytes(privateKey.toCValuesRef(),
crypto_scalarmult_BYTES.toULong())
+ val publicKey = ecdheGetPublic(privateKey)
+ return EcdheKeyPair(privateKey, publicKey)
+ }
+
+ override fun eddsaSign(msg: ByteArray, eddsaPrivateKey: ByteArray):
ByteArray {
+ val publicKey = ByteArray(crypto_sign_PUBLICKEYBYTES.toInt())
+ val privateKey = ByteArray(crypto_sign_SECRETKEYBYTES.toInt())
+ crypto_sign_seed_keypair(publicKey.toCValuesRef(),
privateKey.toCValuesRef(), eddsaPrivateKey.toCValuesRef())
+
+ val signatureBytes = ByteArray(crypto_sign_BYTES.toInt())
+ crypto_sign_detached(
+ signatureBytes.toCValuesRef(),
+ null,
+ msg.toCValuesRef(),
+ msg.size.toULong(),
+ privateKey.toCValuesRef()
+ )
+ return signatureBytes
+ }
+
+ override fun eddsaVerify(msg: ByteArray, sig: ByteArray, eddsaPub:
ByteArray): Boolean {
+ return crypto_sign_verify_detached(
+ sig.toCValuesRef(),
+ msg.toCValuesRef(),
+ msg.size.toULong(),
+ eddsaPub.toCValuesRef()
+ ) == 0
+ }
+
+ override fun keyExchangeEddsaEcdhe(eddsaPrivateKey: ByteArray,
ecdhePublicKey: ByteArray): ByteArray {
+ val privateKey = sha512(eddsaPrivateKey).copyOfRange(0, 32)
+ val sharedKey = ByteArray(crypto_scalarmult_BYTES.toInt())
+ crypto_scalarmult(sharedKey.toCValuesRef(), privateKey.toCValuesRef(),
ecdhePublicKey.toCValuesRef())
+ return sha512(sharedKey)
+ }
+
+ override fun keyExchangeEcdheEddsa(ecdhePrivateKey: ByteArray,
eddsaPublicKey: ByteArray): ByteArray {
+ val curve25519Pub =
ByteArray(crypto_scalarmult_curve25519_BYTES.toInt())
+ val cCurve25519Pub = curve25519Pub.toCValuesRef()
+ crypto_sign_ed25519_pk_to_curve25519(cCurve25519Pub,
eddsaPublicKey.toCValuesRef())
+
+ val sharedKey = ByteArray(crypto_scalarmult_BYTES.toInt())
+ crypto_scalarmult(sharedKey.toCValuesRef(),
ecdhePrivateKey.toCValuesRef(), cCurve25519Pub)
+ return sha512(sharedKey)
+ }
+
+ override fun rsaBlind(hm: ByteArray, bks: ByteArray, rsaPubEnc:
ByteArray): ByteArray {
+ TODO("Not yet implemented")
+ }
+
+ override fun rsaUnblind(sig: ByteArray, rsaPubEnc: ByteArray, bks:
ByteArray): ByteArray {
+ TODO("Not yet implemented")
+ }
+
+ override fun rsaVerify(hm: ByteArray, rsaSig: ByteArray, rsaPubEnc:
ByteArray): Boolean {
+ TODO("Not yet implemented")
+ }
+
+ private class NativeHashSha512State : HashSha512State {
+ private val state = nativeHeap.alloc<crypto_hash_sha512_state>()
+ private val statePointer = state.ptr
+
+ init {
+ check(crypto_hash_sha512_init(statePointer) == 0) { "Error doing
crypto_hash_sha512_init" }
+ }
+
+ override fun update(data: ByteArray): HashSha512State {
+ val cInput = if (data.isEmpty()) null else data.toCValuesRef()
+ crypto_hash_sha512_update(statePointer, cInput,
data.size.toULong())
+ return this
+ }
+
+ override fun final(): ByteArray {
+ val output = ByteArray(crypto_hash_sha512_bytes().toInt())
+ crypto_hash_sha512_final(statePointer, output.toCValuesRef())
+ nativeHeap.free(statePointer)
+ return output
+ }
+
+ }
+
+ private fun ByteArray.toCValuesRef(): CValuesRef<UByteVar> {
+ @Suppress("UNCHECKED_CAST")
+ return this.refTo(0) as CValuesRef<UByteVar>
+ }
+
+}
diff --git a/src/iosTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
b/src/iosTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
new file mode 100644
index 0000000..fd053fa
--- /dev/null
+++ b/src/iosTest/kotlin/net/taler/wallet/kotlin/TestUtils.kt
@@ -0,0 +1,24 @@
+/*
+ * This file is part of GNU Taler
+ * (C) 2020 Taler Systems S.A.
+ *
+ * GNU Taler is free software; you can redistribute it and/or modify it under
the
+ * terms of the GNU General Public License as published by the Free Software
+ * Foundation; either version 3, or (at your option) any later version.
+ *
+ * GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR
+ * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package net.taler.wallet.kotlin
+
+import kotlinx.coroutines.CoroutineScope
+import kotlinx.coroutines.runBlocking
+
+actual fun runCoroutine(block: suspend (scope : CoroutineScope) -> Unit) =
runBlocking { block(this) }
+
+actual fun getPlatformTarget(): PlatformTarget = PlatformTarget.NATIVE_IOS
diff --git a/src/nativeInterop/cinterop/sodium.def
b/src/nativeInterop/cinterop/sodium.def
index b41f11b..1c90295 100644
--- a/src/nativeInterop/cinterop/sodium.def
+++ b/src/nativeInterop/cinterop/sodium.def
@@ -1,4 +1,4 @@
headers = sodium.h
headerFilter = sodium.h sodium/**
-compilerOpts = -I/usr/include -I/usr/include/x86_64-linux-gnu/
-linkerOpts = -lsodium -L/usr/lib/x86_64-linux-gnu -L/usr/lib64/
+compilerOpts = -I/usr/include -I/usr/local/include
-I/usr/include/x86_64-linux-gnu/
+linkerOpts = -lsodium -L/usr/lib/x86_64-linux-gnu -L/usr/lib64/
-L/usr/local/lib
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [taler-wallet-kotlin] branch master updated: add build configuration for ios,
gnunet <=