[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-wallet-kotlin] 02/02: Implement setupRefreshPlanchet
From: |
gnunet |
Subject: |
[taler-wallet-kotlin] 02/02: Implement setupRefreshPlanchet |
Date: |
Mon, 08 Jun 2020 14:54:04 +0200 |
This is an automated email from the git hooks/post-receive script.
torsten-grote pushed a commit to branch master
in repository wallet-kotlin.
commit 504e4e90fa7e2b2da2d1b8cda3baef3b38290a84
Author: Torsten Grote <t@grobox.de>
AuthorDate: Mon Jun 8 09:53:34 2020 -0300
Implement setupRefreshPlanchet
---
.idea/dictionaries/user.xml | 1 +
.../kotlin/net/taler/wallet/kotlin/crypto/Crypto.kt | 2 ++
.../net/taler/wallet/kotlin/crypto/CryptoImpl.kt | 19 +++++++++++++++++++
3 files changed, 22 insertions(+)
diff --git a/.idea/dictionaries/user.xml b/.idea/dictionaries/user.xml
index 5f88694..a7b3027 100644
--- a/.idea/dictionaries/user.xml
+++ b/.idea/dictionaries/user.xml
@@ -5,6 +5,7 @@
<w>eddsa</w>
<w>hmac</w>
<w>nacl</w>
+ <w>planchet</w>
</words>
</dictionary>
</component>
\ No newline at end of file
diff --git a/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/Crypto.kt
b/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/Crypto.kt
index a55c91d..ba43c18 100644
--- a/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/Crypto.kt
+++ b/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/Crypto.kt
@@ -15,10 +15,12 @@ internal interface Crypto {
fun rsaBlind(hm: ByteArray, bks: ByteArray, rsaPubEnc: ByteArray):
ByteArray
fun rsaUnblind(sig: ByteArray, rsaPubEnc: ByteArray, bks: ByteArray):
ByteArray
fun rsaVerify(hm: ByteArray, rsaSig: ByteArray, rsaPubEnc: ByteArray):
Boolean
+ fun setupRefreshPlanchet(secretSeed: ByteArray, coinNumber: Int): FreshCoin
}
class EddsaKeyPair(val privateKey: ByteArray, val publicKey: ByteArray)
class EcdheKeyPair(val privateKey: ByteArray, val publicKey: ByteArray)
+class FreshCoin(val coinPublicKey: ByteArray, coinPrivateKey: ByteArray, bks:
ByteArray)
internal expect object CryptoFactory {
internal fun getCrypto(): Crypto
diff --git a/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoImpl.kt
b/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoImpl.kt
index ae333eb..a21c156 100644
--- a/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoImpl.kt
+++ b/src/commonMain/kotlin/net/taler/wallet/kotlin/crypto/CryptoImpl.kt
@@ -6,4 +6,23 @@ abstract class CryptoImpl : Crypto {
return Kdf.kdf(outputLength, ikm, salt, info, { sha256(it) }, {
sha512(it) })
}
+ override fun setupRefreshPlanchet(secretSeed: ByteArray, coinNumber: Int):
FreshCoin {
+ val info = "taler-coin-derivation".encodeToByteArray()
+ val salt = coinNumber.toByteArray()
+ val out = kdf(64, secretSeed, salt, info)
+ val coinPriv = out.copyOfRange(0, 32)
+ val bks = out.copyOfRange(32, 64)
+ return FreshCoin(bks, coinPriv, eddsaGetPublic(coinPriv))
+ }
+
+ // TODO check if this is the correct coinNumber to ByteArray conversion
+ private fun Int.toByteArray(): ByteArray {
+ val bytes = ByteArray(4)
+ bytes[3] = (this and 0xFFFF).toByte()
+ bytes[2] = ((this ushr 8) and 0xFFFF).toByte()
+ bytes[1] = ((this ushr 16) and 0xFFFF).toByte()
+ bytes[0] = ((this ushr 24) and 0xFFFF).toByte()
+ return bytes
+ }
+
}
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.