diff --git a/buildSrc/src/main/kotlin/Deps.kt b/buildSrc/src/main/kotlin/Deps.kt index 42e6ed7..1104855 100644 --- a/buildSrc/src/main/kotlin/Deps.kt +++ b/buildSrc/src/main/kotlin/Deps.kt @@ -16,16 +16,16 @@ object Versions { val klock = "1.1.1" - val kotlinCoroutines = "1.3.0-M2" + val kotlinCoroutines = "1.3.0" val timber = "5.0.0-SNAPSHOT" val oshi = "3.12.0" - val kotlin = "1.3.40" + val kotlin = "1.3.50" val ktor = "1.1.1" val kotlinSerialization = "0.11.1" val nodePlugin = "1.3.0" val dokkaPlugin = "0.9.18" - val kotlinBigNumVersion = "0.1.0-SNAPSHOT" + val kotlinBigNumVersion = "0.1.1-SNAPSHOT" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d83a619..4e8cbd5 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -16,6 +16,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt new file mode 100644 index 0000000..c11ff7a --- /dev/null +++ b/multiplatform-crypto/src/commonMain/kotlin/com/ionspin/kotlin/crypto/symmetric/Aes.kt @@ -0,0 +1,66 @@ +package com.ionspin.kotlin.crypto.symmetric + +/** + * Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 07/Sep/2019 + */ +@ExperimentalUnsignedTypes +class Aes { + companion object { + val sBox : UByteArray = + ubyteArrayOf( + 0x63U, 0x7cU, 0x77U, 0x7bU, 0xf2U, 0x6bU, 0x6fU, 0xc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aU, 0x0aU, 0x49U, 0x06U, 0x24U, 0x5cU, 0xc2U, 0xd3U, 0xacU, 0x62U, 0x91U, 0x95U, 0xe4U, 0x79U, + 0xe7U, 0xc8U, 0x37U, 0x6dU, 0x8dU, 0xd5U, 0x4eU, 0xa9U, 0x6cU, 0x56U, 0xf4U, 0xeaU, 0x65U, 0x7aU, 0xaeU, 0x08U, + 0xbaU, 0x78U, 0x25U, 0x2eU, 0x1cU, 0xa6U, 0xb4U, 0xc6U, 0xe8U, 0xddU, 0x74U, 0x1fU, 0x4bU, 0xbdU, 0x8bU, 0x8aU, + 0x70U, 0x3eU, 0xb5U, 0x66U, 0x48U, 0x03U, 0xf6U, 0x0eU, 0x61U, 0x35U, 0x57U, 0xb9U, 0x86U, 0xc1U, 0x1dU, 0x9eU, + 0xe1U, 0xf8U, 0x98U, 0x11U, 0x69U, 0xd9U, 0x8eU, 0x94U, 0x9bU, 0x1eU, 0x87U, 0xe9U, 0xceU, 0x55U, 0x28U, 0xdfU, + 0x8cU, 0xa1U, 0x89U, 0x0dU, 0xbfU, 0xe6U, 0x42U, 0x68U, 0x41U, 0x99U, 0x2dU, 0x0fU, 0xb0U, 0x54U, 0xbbU, 0x16U + ) + } + + sealed class AesKey(val key: String, val keyLength: Int) { + class Aes128Key(key: String) : AesKey(key, 128) + class Aes192Key(key: String) : AesKey(key, 192) + class Aes256Key(key: String) : AesKey(key, 256) + + init { + checkKeyLength(key, keyLength) + } + + fun checkKeyLength(key: String, expectedLength: Int) { + if ((key.length / 2) != expectedLength) { + throw RuntimeException("Invalid key length") + } + } + } + + val state : UByteArray = UByteArray(16) { 0U } + + val stateMatrix : Array> = (0 until 4).map { + Array(4) { 0U } + }.toTypedArray() + + fun subBytes() { + stateMatrix.forEachIndexed { indexRow, row -> + row.forEachIndexed { indexColumn, element -> + val firstDigit = (element / 16U).toInt() + val secondDigit = (element % 16U).toInt() + val substitutionValue = sBox[firstDigit * 16 + secondDigit] + stateMatrix[indexRow][indexColumn] = substitutionValue + } + } + } + + fun expandKey(key: AesKey) { + + } +} diff --git a/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt new file mode 100644 index 0000000..8e6a06c --- /dev/null +++ b/multiplatform-crypto/src/commonTest/kotlin/com/ionspin/kotlin/crypto/symmetric/AesTest.kt @@ -0,0 +1,30 @@ +package com.ionspin.kotlin.crypto.symmetric + +import kotlin.test.Test +import kotlin.test.assertTrue + +/** + * Created by Ugljesa Jovanovic (jovanovic.ugljesa@gmail.com) on 10/Sep/2019 + */ +@ExperimentalUnsignedTypes +class AesTest { + + @Test + fun testSubBytes() { + val fakeState = arrayOf( + ubyteArrayOf(0x53U, 0U, 0U, 0U).toTypedArray(), + ubyteArrayOf(0U, 0U, 0U, 0U).toTypedArray(), + ubyteArrayOf(0U, 0U, 0U, 0U).toTypedArray(), + ubyteArrayOf(0U, 0U, 0U, 0U).toTypedArray() + ) + val aes = Aes() + fakeState.copyInto(aes.stateMatrix) + aes.subBytes() + aes.stateMatrix.forEach{ + println(it.joinToString { it.toString(16) }) + } + assertTrue { + aes.stateMatrix[0][0] == 0xEDU.toUByte() + } + } +} \ No newline at end of file