Bump version to 0.1.0 cause a lot of things changed since 0.0.4, mac builds are working, now to get Windows to work, updated readme, copied crypto API to pure variant

This commit is contained in:
Ugljesa Jovanovic 2020-06-11 20:29:03 +02:00 committed by Ugljesa Jovanovic
parent 4eb8970fd3
commit 1db2547967
No known key found for this signature in database
GPG Key ID: 178E6DFCECCB0E0F
6 changed files with 112 additions and 32 deletions

View File

@ -5,9 +5,6 @@
Kotlin Multiplatform Crypto is a library for various cryptographic applications. Kotlin Multiplatform Crypto is a library for various cryptographic applications.
API is very opinionated, meant to be used on both encrypting and decrypting side. The idea is that API leaves less room for
errors when using it.
The library comes in two flavors `multiplatform-crypto` and `multiplatform-crypto-delegated` The library comes in two flavors `multiplatform-crypto` and `multiplatform-crypto-delegated`
* `multiplatform-crypto` contains pure kotlin implementations, is not reviewed, should be considered unsafe and only * `multiplatform-crypto` contains pure kotlin implementations, is not reviewed, should be considered unsafe and only
@ -15,6 +12,27 @@ for prototyping or experimentation purposes.
* `multiplatform-crypto-delegated` relies on platform specific implementations, like libsodium, but care should still be taken that the kotlin code is not reviewed or proven safe. * `multiplatform-crypto-delegated` relies on platform specific implementations, like libsodium, but care should still be taken that the kotlin code is not reviewed or proven safe.
APIs of both variants are identical.
## Supported platforms by variant
|Platform|Pure variant| Delegated variant|
|--------|------------|------------------|
|Linux X86 64| :heavy_check_mark: | :heavy_check_mark: |
|Linux Arm 64| :heavy_check_mark: | :heavy_check_mark: |
|Linux Arm 32| :heavy_check_mark: | :x: |
|macOS X86 64| :heavy_check_mark: | :heavy_check_mark: |
|iOS x86 64 | :heavy_check_mark: | :heavy_check_mark: |
|iOS Arm 64 | :heavy_check_mark: | :heavy_check_mark: |
|iOS Arm 32 | :heavy_check_mark: | :heavy_check_mark: |
|watchOS X86 32 | :heavy_check_mark: | :heavy_check_mark: |
|watchOS Arm 64(_32) | :heavy_check_mark: | :heavy_check_mark: |
|watchos Arm 32 | :heavy_check_mark: | :heavy_check_mark: |
|tvOS X86 64 | :heavy_check_mark: | :heavy_check_mark: |
|tvOS Arm 64 | :heavy_check_mark: | :heavy_check_mark: |
|minGW X86 64| :heavy_check_mark: | :heavy_check_mark: |
|minGW X86 32| :x: | :x: |
## Notes & Roadmap ## Notes & Roadmap
@ -29,7 +47,7 @@ No, until it is reviewed.
## Should I use this in code that is *critical* in any way, shape or form? ## Should I use this in code that is *critical* in any way, shape or form?
No, but even if after being warned you decide to, then use `multiplatform-crypto-delegated`. No, but even if after being warned you decide to, then use `multiplatform-crypto-delegated` as it relies on reputable libraries.
## Why? ## Why?
@ -61,11 +79,11 @@ The following table describes which library is used for particular cryptographic
| Primitive | JVM | JS | Native | | Primitive | JVM | JS | Native |
| ----------|-----|----|--------| | ----------|-----|----|--------|
| Blake2b | JCE | libsodium.js | libsodium | | Blake2b | LazySodium | libsodium.js | libsodium |
| SHA256 | JCE | libsodium.js | libsodium | SHA256 | LazySodium | libsodium.js | libsodium |
| SHA512 | JCE | libsodium.js | libsodium | SHA512 | LazySodium | libsodium.js | libsodium |
| AES-CBC | JCE | libsodium.js | libsodium | AES-CBC | LazySodium | libsodium.js | libsodium |
| AES-CTR | JCE | libsodium.js | libsodium | AES-CTR | LazySodium | libsodium.js | libsodium |
## Integration ## Integration
@ -93,6 +111,13 @@ implementation("com.ionspin.kotlin:multiplatform-crypto:0.0.6-SNAPSHOT")
## Usage ## Usage
### Helper functions
All API take `UByteArray` as message/key/nonce/etc parameter. For convenience when working with strings we provide
`String.enocdeToUbyteArray()` extensions function, and `UByteArray.toHexString` extension function.
More convenience functions will be added.
### Hashes ### Hashes
Hashes are provided in two versions, "stateless", usually the companion object of the hash, Hashes are provided in two versions, "stateless", usually the companion object of the hash,
@ -108,7 +133,7 @@ You need to deliver the complete data that is to be hashed in one go
```kotlin ```kotlin
val input = "abc" val input = "abc"
val result = Blake2b.digest(input) val result = Crypto.Blake2b.stateless(input.encodeToUByteArray())
``` ```
Result is returned as a `UByteArray` Result is returned as a `UByteArray`
@ -122,9 +147,9 @@ If you want to use Blake2b with a key, you should supply it when creating the `B
```kotlin ```kotlin
val test = "abc" val test = "abc"
val key = "key" val key = "key"
val blake2b = Blake2b(key) val blake2b = Crypto.Blake2b.updateable(key.encodeToUByteArray())
blake2b.update(test) blake2b.update(test.encodeToUByteArray())
val result = blake2b.digest() val result = blake2b.digest().toHexString()
``` ```
After digest is called, the instance is reset and can be reused (Keep in mind key stays the same for the particular instance). After digest is called, the instance is reset and can be reused (Keep in mind key stays the same for the particular instance).
@ -137,12 +162,12 @@ or `String`. Result is always returned as `UByteArray` (At least in verision 0.0
```kotlin ```kotlin
val input = "abc" val input = "abc"
val result = Sha256.digest(input) val result = Crypto.Sha256.stateless(input.encodeToUByteArray())
``` ```
```kotlin ```kotlin
val input ="abc" val input ="abc"
val result = Sha512.digest(message = input.encodeToByteArray().map { it.toUByte() }.toTypedArray()) val result = Crypto.Sha512.stateless(input.encodeToUByteArray())
``` ```
Result is returned as a `UByteArray` Result is returned as a `UByteArray`
@ -152,16 +177,17 @@ Result is returned as a `UByteArray`
Or you can use the updatable instance version Or you can use the updatable instance version
```kotlin ```kotlin
val sha256 = Sha256() val sha256 = Crypto.Sha256.updateable()
sha256.update("abc") sha256.update("abc".encodeToUByteArray())
val result = sha256.digest() val result = sha256.digest()
``` ```
```kotlin ```kotlin
val sha512 = Sha512() val sha512 = Crypto.Sha512.updateable()
sha512.update("abc") sha512.update("abc".encodeToUByteArray())
val result = sha512.digest() val result = sha512.digest()
``` ```
### Symmetric encryption ### Symmetric encryption
#### AES #### AES

View File

@ -33,7 +33,7 @@ object Versions {
object ReleaseInfo { object ReleaseInfo {
val group = "com.ionspin.kotlin" val group = "com.ionspin.kotlin"
val version = "0.0.5-SNAPSHOT" val version = "0.1.0-SNAPSHOT"
} }
object Deps { object Deps {

View File

@ -56,11 +56,12 @@ kotlin {
browser { browser {
testTask { testTask {
isRunningInTravis { // isRunningInTravis {
enabled = false //Until I sort out testing on travis enabled = false //Until I sort out testing on travis, and figure out how to increase karma timeout
} // }
useKarma { useKarma {
useChrome() useChrome()
} }
} }
} }

View File

@ -1,5 +1,6 @@
package com.ionspin.kotlin.crypto package com.ionspin.kotlin.crypto
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bProperties
import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure import com.ionspin.kotlin.crypto.hash.blake2b.Blake2bPure
import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure import com.ionspin.kotlin.crypto.hash.sha.Sha256Pure
import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure
@ -9,6 +10,58 @@ import com.ionspin.kotlin.crypto.hash.sha.Sha512Pure
* ugljesa.jovanovic@ionspin.com * ugljesa.jovanovic@ionspin.com
* on 24-May-2020 * on 24-May-2020
*/ */
typealias Blake2bStateless = Blake2bPure.Companion typealias Blake2bPureStateless = Blake2bPure.Companion
typealias Sha256Stateless = Sha256Pure.Companion typealias Sha256PureStateless = Sha256Pure.Companion
typealias Sha512Stateless = Sha512Pure.Companion typealias Sha512PureStateless = Sha512Pure.Companion
object Crypto : CryptoProvider {
override suspend fun initialize() {
//Nothing to do atm.
}
fun initializeWithCallback(done: () -> Unit) {
done()
}
object Blake2b {
fun updateable(key: UByteArray? = null, hashLength: Int = Blake2bProperties.MAX_HASH_BYTES): com.ionspin.kotlin.crypto.hash.blake2b.Blake2b {
checkInitialization()
return Blake2bPure(key, hashLength)
}
fun stateless(message: UByteArray, key: UByteArray = ubyteArrayOf(), hashLength: Int = Blake2bProperties.MAX_HASH_BYTES): UByteArray {
checkInitialization()
return Blake2bPureStateless.digest(message, key, hashLength)
}
}
object Sha256 {
fun updateable(): com.ionspin.kotlin.crypto.hash.sha.Sha256 {
checkInitialization()
return Sha256Pure()
}
fun stateless(message: UByteArray) : UByteArray{
checkInitialization()
return Sha256PureStateless.digest(inputMessage = message)
}
}
object Sha512 {
fun updateable(): com.ionspin.kotlin.crypto.hash.sha.Sha512 {
checkInitialization()
return Sha512Pure()
}
fun stateless(message: UByteArray) : UByteArray {
checkInitialization()
return Sha512PureStateless.digest(inputMessage = message)
}
}
private fun checkInitialization() {
// Nothing to do atm
}
}

View File

@ -19,7 +19,7 @@
package com.ionspin.kotlin.crypto.keyderivation.argon2 package com.ionspin.kotlin.crypto.keyderivation.argon2
import com.ionspin.kotlin.bignum.integer.toBigInteger import com.ionspin.kotlin.bignum.integer.toBigInteger
import com.ionspin.kotlin.crypto.Blake2bStateless import com.ionspin.kotlin.crypto.Blake2bPureStateless
import com.ionspin.kotlin.crypto.SRNG import com.ionspin.kotlin.crypto.SRNG
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.argonBlake2bArbitraryLenghtHash import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.argonBlake2bArbitraryLenghtHash
import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.compressionFunctionG import com.ionspin.kotlin.crypto.keyderivation.argon2.Argon2Utils.compressionFunctionG
@ -296,7 +296,7 @@ class Argon2Pure(
salt.size.toUInt().toLittleEndianUByteArray() + salt + salt.size.toUInt().toLittleEndianUByteArray() + salt +
key.size.toUInt().toLittleEndianUByteArray() + key + key.size.toUInt().toLittleEndianUByteArray() + key +
associatedData.size.toUInt().toLittleEndianUByteArray() + associatedData associatedData.size.toUInt().toLittleEndianUByteArray() + associatedData
val h0 = Blake2bStateless.digest( val h0 = Blake2bPureStateless.digest(
blakeInput blakeInput
) )

View File

@ -159,7 +159,7 @@ class ReadmeTest {
@Test @Test
fun debugTest() { fun debugTest() {
val result = Blake2bStateless.digest("test".encodeToUByteArray()) val result = Blake2bPureStateless.digest("test".encodeToUByteArray())
println(result.toHexString()) println(result.toHexString())
} }