diff --git a/korge-foundation/build.gradle.kts b/korge-foundation/build.gradle.kts index fb8cff4520..2e794c4072 100644 --- a/korge-foundation/build.gradle.kts +++ b/korge-foundation/build.gradle.kts @@ -23,6 +23,7 @@ dependencies { //add("commonTestApi", project(":korge-test")) commonTestApi(libs.kotlinx.coroutines.test) commonMainApi(project(":korlibs-time")) + commonMainApi(project(":korlibs-crypto")) } //korlibs.korge.gradle.generate.TemplateGenerator.synchronize(new File(projectDir, "template")) diff --git a/korlibs-crypto/.gitignore b/korlibs-crypto/.gitignore new file mode 100644 index 0000000000..796b96d1c4 --- /dev/null +++ b/korlibs-crypto/.gitignore @@ -0,0 +1 @@ +/build diff --git a/korlibs-crypto/build.gradle.kts b/korlibs-crypto/build.gradle.kts new file mode 100644 index 0000000000..16bcb5c664 --- /dev/null +++ b/korlibs-crypto/build.gradle.kts @@ -0,0 +1,26 @@ + +import korlibs.* +import korlibs.korge.gradle.generate.* + +description = "Korlibs Cryptography Library" + +project.extensions.extraProperties.properties.apply { + applyProjectProperties("https://github.com/korlibs/korge/korge-foundation", + "Apache 2.0", + "https://raw.githubusercontent.com/korlibs/korge/master/korge-foundation/LICENSE" + ) +} + +dependencies { + //add("commonMainImplementation", "org.jetbrains.kotlinx:atomicfu:${libs.versions.kotlinx.atomicfu.get()}") + //add("commonMainApi", "org.jetbrains.kotlinx:atomicfu:${libs.versions.kotlinx.atomicfu.get()}") + //add("jvmTestApi", "org.powermock:powermock-mockito-release-full:1.6.4") + //add("jvmTestApi", "org.fuin:units4j:0.8.4") + //add("jvmTestApi", "org.ow2.asm:asm:8.0.1") + commonMainApi(libs.kotlinx.coroutines.core) + commonMainApi(libs.kotlinx.atomicfu) + //add("commonMainApi", libs.kotlinx.atomicfu) + //add("commonTestApi", project(":korge-test")) + commonTestApi(libs.kotlinx.coroutines.test) + commonMainApi(project(":korlibs-time")) +} diff --git a/korge-foundation/src/korlibs/crypto/AES.kt b/korlibs-crypto/src/korlibs/crypto/AES.kt similarity index 100% rename from korge-foundation/src/korlibs/crypto/AES.kt rename to korlibs-crypto/src/korlibs/crypto/AES.kt diff --git a/korge-foundation/src/korlibs/crypto/Cipher.kt b/korlibs-crypto/src/korlibs/crypto/Cipher.kt similarity index 100% rename from korge-foundation/src/korlibs/crypto/Cipher.kt rename to korlibs-crypto/src/korlibs/crypto/Cipher.kt diff --git a/korge-foundation/src/korlibs/crypto/CipherMode.kt b/korlibs-crypto/src/korlibs/crypto/CipherMode.kt similarity index 99% rename from korge-foundation/src/korlibs/crypto/CipherMode.kt rename to korlibs-crypto/src/korlibs/crypto/CipherMode.kt index daf3d8ff7c..43346e3492 100644 --- a/korge-foundation/src/korlibs/crypto/CipherMode.kt +++ b/korlibs-crypto/src/korlibs/crypto/CipherMode.kt @@ -1,7 +1,7 @@ package korlibs.crypto -import korlibs.memory.* -import kotlin.experimental.* +import korlibs.internal.arraycopy +import kotlin.experimental.xor /** * Symmetric Cipher Mode diff --git a/korge-foundation/src/korlibs/crypto/CipherPadding.kt b/korlibs-crypto/src/korlibs/crypto/CipherPadding.kt similarity index 98% rename from korge-foundation/src/korlibs/crypto/CipherPadding.kt rename to korlibs-crypto/src/korlibs/crypto/CipherPadding.kt index 957c2cb77c..feb0ba7b49 100644 --- a/korge-foundation/src/korlibs/crypto/CipherPadding.kt +++ b/korlibs-crypto/src/korlibs/crypto/CipherPadding.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy import kotlin.random.Random typealias Padding = CipherPadding diff --git a/korge-foundation/src/korlibs/crypto/HMAC.kt b/korlibs-crypto/src/korlibs/crypto/HMAC.kt similarity index 97% rename from korge-foundation/src/korlibs/crypto/HMAC.kt rename to korlibs-crypto/src/korlibs/crypto/HMAC.kt index b617d9fb61..94ed09ca03 100644 --- a/korge-foundation/src/korlibs/crypto/HMAC.kt +++ b/korlibs-crypto/src/korlibs/crypto/HMAC.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy class HMAC { diff --git a/korge-foundation/src/korlibs/crypto/Hasher.kt b/korlibs-crypto/src/korlibs/crypto/Hasher.kt similarity index 99% rename from korge-foundation/src/korlibs/crypto/Hasher.kt rename to korlibs-crypto/src/korlibs/crypto/Hasher.kt index 969aeae8b7..df2457f1e3 100644 --- a/korge-foundation/src/korlibs/crypto/Hasher.kt +++ b/korlibs-crypto/src/korlibs/crypto/Hasher.kt @@ -2,7 +2,7 @@ package korlibs.crypto import korlibs.encoding.Base64 import korlibs.encoding.Hex -import korlibs.memory.* +import korlibs.internal.arraycopy import kotlin.math.min open class HasherFactory(val name: String, val create: () -> Hasher) { diff --git a/korge-foundation/src/korlibs/crypto/MD4.kt b/korlibs-crypto/src/korlibs/crypto/MD4.kt similarity index 100% rename from korge-foundation/src/korlibs/crypto/MD4.kt rename to korlibs-crypto/src/korlibs/crypto/MD4.kt diff --git a/korge-foundation/src/korlibs/crypto/MD5.kt b/korlibs-crypto/src/korlibs/crypto/MD5.kt similarity index 100% rename from korge-foundation/src/korlibs/crypto/MD5.kt rename to korlibs-crypto/src/korlibs/crypto/MD5.kt diff --git a/korge-foundation/src/korlibs/crypto/PBKDF2.kt b/korlibs-crypto/src/korlibs/crypto/PBKDF2.kt similarity index 98% rename from korge-foundation/src/korlibs/crypto/PBKDF2.kt rename to korlibs-crypto/src/korlibs/crypto/PBKDF2.kt index 6a084370a2..78431d08c1 100644 --- a/korge-foundation/src/korlibs/crypto/PBKDF2.kt +++ b/korlibs-crypto/src/korlibs/crypto/PBKDF2.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy class PBKDF2 { companion object { diff --git a/korge-foundation/src/korlibs/crypto/SHA.kt b/korlibs-crypto/src/korlibs/crypto/SHA.kt similarity index 100% rename from korge-foundation/src/korlibs/crypto/SHA.kt rename to korlibs-crypto/src/korlibs/crypto/SHA.kt diff --git a/korge-foundation/src/korlibs/crypto/SHA1.kt b/korlibs-crypto/src/korlibs/crypto/SHA1.kt similarity index 98% rename from korge-foundation/src/korlibs/crypto/SHA1.kt rename to korlibs-crypto/src/korlibs/crypto/SHA1.kt index edf4a2e072..48f73b3df0 100644 --- a/korge-foundation/src/korlibs/crypto/SHA1.kt +++ b/korlibs-crypto/src/korlibs/crypto/SHA1.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy import kotlin.rotateLeft class SHA1 : SHA(chunkSize = 64, digestSize = 20, name = "SHA1") { diff --git a/korge-foundation/src/korlibs/crypto/SHA256.kt b/korlibs-crypto/src/korlibs/crypto/SHA256.kt similarity index 98% rename from korge-foundation/src/korlibs/crypto/SHA256.kt rename to korlibs-crypto/src/korlibs/crypto/SHA256.kt index df1c1ca2df..90dcc63f95 100644 --- a/korge-foundation/src/korlibs/crypto/SHA256.kt +++ b/korlibs-crypto/src/korlibs/crypto/SHA256.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy import kotlin.rotateRight class SHA256 : SHA(chunkSize = 64, digestSize = 32) { diff --git a/korge-foundation/src/korlibs/crypto/SHA3.kt b/korlibs-crypto/src/korlibs/crypto/SHA3.kt similarity index 100% rename from korge-foundation/src/korlibs/crypto/SHA3.kt rename to korlibs-crypto/src/korlibs/crypto/SHA3.kt diff --git a/korge-foundation/src/korlibs/crypto/SHA512.kt b/korlibs-crypto/src/korlibs/crypto/SHA512.kt similarity index 99% rename from korge-foundation/src/korlibs/crypto/SHA512.kt rename to korlibs-crypto/src/korlibs/crypto/SHA512.kt index 310743d640..bb1d2e941a 100644 --- a/korge-foundation/src/korlibs/crypto/SHA512.kt +++ b/korlibs-crypto/src/korlibs/crypto/SHA512.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy // https://git.suckless.org/sbase/file/libutil/sha512.c.html // https://git.suckless.org/sbase/file/sha512.h.html diff --git a/korge-foundation/src/korlibs/crypto/SecureRandom.kt b/korlibs-crypto/src/korlibs/crypto/SecureRandom.kt similarity index 97% rename from korge-foundation/src/korlibs/crypto/SecureRandom.kt rename to korlibs-crypto/src/korlibs/crypto/SecureRandom.kt index 5b6e0b0ec9..c53224ea65 100644 --- a/korge-foundation/src/korlibs/crypto/SecureRandom.kt +++ b/korlibs-crypto/src/korlibs/crypto/SecureRandom.kt @@ -1,6 +1,6 @@ package korlibs.crypto -import korlibs.memory.* +import korlibs.internal.arraycopy import kotlin.random.Random expect fun fillRandomBytes(array: ByteArray) diff --git a/korge-foundation/src/korlibs/encoding/ASCII.kt b/korlibs-crypto/src/korlibs/encoding/ASCII.kt similarity index 100% rename from korge-foundation/src/korlibs/encoding/ASCII.kt rename to korlibs-crypto/src/korlibs/encoding/ASCII.kt diff --git a/korge-foundation/src/korlibs/encoding/Base64.kt b/korlibs-crypto/src/korlibs/encoding/Base64.kt similarity index 99% rename from korge-foundation/src/korlibs/encoding/Base64.kt rename to korlibs-crypto/src/korlibs/encoding/Base64.kt index e09780eff9..647db5a8a5 100644 --- a/korge-foundation/src/korlibs/encoding/Base64.kt +++ b/korlibs-crypto/src/korlibs/encoding/Base64.kt @@ -1,7 +1,5 @@ package korlibs.encoding -import korlibs.encoding.* - object Base64 { private val TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=" private val TABLE_URL = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=" diff --git a/korge-foundation/src/korlibs/encoding/Hex.kt b/korlibs-crypto/src/korlibs/encoding/Hex.kt similarity index 100% rename from korge-foundation/src/korlibs/encoding/Hex.kt rename to korlibs-crypto/src/korlibs/encoding/Hex.kt diff --git a/korlibs-crypto/src/korlibs/internal/InternalCryptoArrays.kt b/korlibs-crypto/src/korlibs/internal/InternalCryptoArrays.kt new file mode 100644 index 0000000000..5faba5c563 --- /dev/null +++ b/korlibs-crypto/src/korlibs/internal/InternalCryptoArrays.kt @@ -0,0 +1,11 @@ +package korlibs.internal + +/** Copies [size] elements of [src] starting at [srcPos] into [dst] at [dstPos] */ +internal fun arraycopy(src: ByteArray, srcPos: Int, dst: ByteArray, dstPos: Int, size: Int) { + src.copyInto(dst, dstPos, srcPos, srcPos + size) +} + +/** Copies [size] elements of [src] starting at [srcPos] into [dst] at [dstPos] */ +internal fun arraycopy(src: IntArray, srcPos: Int, dst: IntArray, dstPos: Int, size: Int) { + src.copyInto(dst, dstPos, srcPos, srcPos + size) +} diff --git a/korge-foundation/src@android/korlibs/crypto/PRNGFixes.kt b/korlibs-crypto/src@android/korlibs/crypto/PRNGFixes.kt similarity index 100% rename from korge-foundation/src@android/korlibs/crypto/PRNGFixes.kt rename to korlibs-crypto/src@android/korlibs/crypto/PRNGFixes.kt diff --git a/korge-foundation/src@android/korlibs/crypto/SecureRandomJvm.kt b/korlibs-crypto/src@android/korlibs/crypto/SecureRandomJvm.kt similarity index 100% rename from korge-foundation/src@android/korlibs/crypto/SecureRandomJvm.kt rename to korlibs-crypto/src@android/korlibs/crypto/SecureRandomJvm.kt diff --git a/korge-foundation/src@darwin/korlibs/crypto/SecureRandomNativePosix.kt b/korlibs-crypto/src@darwin/korlibs/crypto/SecureRandomNativePosix.kt similarity index 100% rename from korge-foundation/src@darwin/korlibs/crypto/SecureRandomNativePosix.kt rename to korlibs-crypto/src@darwin/korlibs/crypto/SecureRandomNativePosix.kt diff --git a/korge-foundation/src@js/korlibs/crypto/SecureRandomJs.kt b/korlibs-crypto/src@js/korlibs/crypto/SecureRandomJs.kt similarity index 100% rename from korge-foundation/src@js/korlibs/crypto/SecureRandomJs.kt rename to korlibs-crypto/src@js/korlibs/crypto/SecureRandomJs.kt diff --git a/korge-foundation/src@jvm/korlibs/crypto/SecureRandomJvm.kt b/korlibs-crypto/src@jvm/korlibs/crypto/SecureRandomJvm.kt similarity index 100% rename from korge-foundation/src@jvm/korlibs/crypto/SecureRandomJvm.kt rename to korlibs-crypto/src@jvm/korlibs/crypto/SecureRandomJvm.kt diff --git a/korge-foundation/src@wasmJs/korlibs/crypto/SecureRandomNativeWasm.kt b/korlibs-crypto/src@wasmJs/korlibs/crypto/SecureRandomNativeWasm.kt similarity index 100% rename from korge-foundation/src@wasmJs/korlibs/crypto/SecureRandomNativeWasm.kt rename to korlibs-crypto/src@wasmJs/korlibs/crypto/SecureRandomNativeWasm.kt diff --git a/korge-foundation/test/korlibs/crypto/AESTest.kt b/korlibs-crypto/test/korlibs/crypto/AESTest.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/AESTest.kt rename to korlibs-crypto/test/korlibs/crypto/AESTest.kt diff --git a/korge-foundation/test/korlibs/crypto/Base64Test.kt b/korlibs-crypto/test/korlibs/crypto/Base64Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/Base64Test.kt rename to korlibs-crypto/test/korlibs/crypto/Base64Test.kt diff --git a/korge-foundation/test/korlibs/crypto/Base64UrlTest.kt b/korlibs-crypto/test/korlibs/crypto/Base64UrlTest.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/Base64UrlTest.kt rename to korlibs-crypto/test/korlibs/crypto/Base64UrlTest.kt diff --git a/korge-foundation/test/korlibs/crypto/CipherTest.kt b/korlibs-crypto/test/korlibs/crypto/CipherTest.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/CipherTest.kt rename to korlibs-crypto/test/korlibs/crypto/CipherTest.kt diff --git a/korge-foundation/test/korlibs/crypto/HMACTest.kt b/korlibs-crypto/test/korlibs/crypto/HMACTest.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/HMACTest.kt rename to korlibs-crypto/test/korlibs/crypto/HMACTest.kt diff --git a/korge-foundation/test/korlibs/crypto/MD4Test.kt b/korlibs-crypto/test/korlibs/crypto/MD4Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/MD4Test.kt rename to korlibs-crypto/test/korlibs/crypto/MD4Test.kt diff --git a/korge-foundation/test/korlibs/crypto/MD5Test.kt b/korlibs-crypto/test/korlibs/crypto/MD5Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/MD5Test.kt rename to korlibs-crypto/test/korlibs/crypto/MD5Test.kt diff --git a/korge-foundation/test/korlibs/crypto/PBKDF2Test.kt b/korlibs-crypto/test/korlibs/crypto/PBKDF2Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/PBKDF2Test.kt rename to korlibs-crypto/test/korlibs/crypto/PBKDF2Test.kt diff --git a/korge-foundation/test/korlibs/crypto/SHA1Test.kt b/korlibs-crypto/test/korlibs/crypto/SHA1Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/SHA1Test.kt rename to korlibs-crypto/test/korlibs/crypto/SHA1Test.kt diff --git a/korge-foundation/test/korlibs/crypto/SHA256Test.kt b/korlibs-crypto/test/korlibs/crypto/SHA256Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/SHA256Test.kt rename to korlibs-crypto/test/korlibs/crypto/SHA256Test.kt diff --git a/korge-foundation/test/korlibs/crypto/SHA512Test.kt b/korlibs-crypto/test/korlibs/crypto/SHA512Test.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/SHA512Test.kt rename to korlibs-crypto/test/korlibs/crypto/SHA512Test.kt diff --git a/korge-foundation/test/korlibs/crypto/SecureRandomTest.kt b/korlibs-crypto/test/korlibs/crypto/SecureRandomTest.kt similarity index 100% rename from korge-foundation/test/korlibs/crypto/SecureRandomTest.kt rename to korlibs-crypto/test/korlibs/crypto/SecureRandomTest.kt diff --git a/korge-foundation/test@jvm/korlibs/crypto/AESJvmTest.kt b/korlibs-crypto/test@jvm/korlibs/crypto/AESJvmTest.kt similarity index 100% rename from korge-foundation/test@jvm/korlibs/crypto/AESJvmTest.kt rename to korlibs-crypto/test@jvm/korlibs/crypto/AESJvmTest.kt diff --git a/korge-foundation/test@jvm/korlibs/crypto/PBKDF2JvmTest.kt b/korlibs-crypto/test@jvm/korlibs/crypto/PBKDF2JvmTest.kt similarity index 100% rename from korge-foundation/test@jvm/korlibs/crypto/PBKDF2JvmTest.kt rename to korlibs-crypto/test@jvm/korlibs/crypto/PBKDF2JvmTest.kt diff --git a/korge-foundation/test@jvm/korlibs/crypto/SHA512JvmTest.kt b/korlibs-crypto/test@jvm/korlibs/crypto/SHA512JvmTest.kt similarity index 100% rename from korge-foundation/test@jvm/korlibs/crypto/SHA512JvmTest.kt rename to korlibs-crypto/test@jvm/korlibs/crypto/SHA512JvmTest.kt diff --git a/settings.gradle.kts b/settings.gradle.kts index e984d8aab1..e5e661d798 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -26,6 +26,7 @@ val inCI = isPropertyTrue("CI") val disabledExtraKorgeLibs = isPropertyTrue("DISABLED_EXTRA_KORGE_LIBS") include(":korlibs-time") +include(":korlibs-crypto") include(":korlibs-template") include(":korge-foundation") include(":korge-core")