Idea cinterop stopped working, again... fixed blake2b stateless segmentation
This commit is contained in:
		
							parent
							
								
									d380863a29
								
							
						
					
					
						commit
						1be0470745
					
				@ -87,13 +87,3 @@ fun NamedDomainObjectContainer<KotlinSourceSet>.createWorkaroundNativeMainSource
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
fun NamedDomainObjectContainer<KotlinSourceSet>.createWorkaround32bitNativeMainSourceSet(name : String, nativeDeps : KotlinDependencyHandler.() -> Unit) : KotlinSourceSet {
 | 
			
		||||
    return create("${name}Workaround") {
 | 
			
		||||
        kotlin.srcDir("src/native32Main")
 | 
			
		||||
        dependencies {
 | 
			
		||||
            nativeDeps.invoke(this)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -81,16 +81,6 @@ kotlin {
 | 
			
		||||
                staticLib {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            compilations.getByName("main") {
 | 
			
		||||
                val libsodiumCinterop by cinterops.creating {
 | 
			
		||||
                    defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
 | 
			
		||||
                    compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-linux-x86-64/include/")
 | 
			
		||||
                }
 | 
			
		||||
                kotlinOptions.freeCompilerArgs = listOf(
 | 
			
		||||
                    "-include-binary", "${project.rootDir}/sodiumWrapper/static-linux-x86-64/lib/libsodium.a"
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -99,15 +89,6 @@ kotlin {
 | 
			
		||||
                staticLib {
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
            compilations.getByName("main") {
 | 
			
		||||
                val libsodiumCinterop by cinterops.creating {
 | 
			
		||||
                    defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
 | 
			
		||||
                    compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-arm64/include/")
 | 
			
		||||
                }
 | 
			
		||||
                kotlinOptions.freeCompilerArgs = listOf(
 | 
			
		||||
                    "-include-binary", "${project.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
 | 
			
		||||
                )
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        // Linux 32 is using target-sysroot-2-raspberrypi which is missing getrandom and explicit_bzero in stdlib
 | 
			
		||||
        // so konanc can't build klib because getrandom missing will cause sodium_misuse()
 | 
			
		||||
@ -296,8 +277,11 @@ kotlin {
 | 
			
		||||
        //Set up shared source sets
 | 
			
		||||
        //linux, linuxArm32Hfp, linuxArm64
 | 
			
		||||
        val linux64Bit = setOf(
 | 
			
		||||
            "linuxX64", "linuxArm64"
 | 
			
		||||
            "linuxX64"
 | 
			
		||||
        )
 | 
			
		||||
        val linuxArm64Bit = setOf {
 | 
			
		||||
            "linuxArm64"
 | 
			
		||||
        }
 | 
			
		||||
        val linux32Bit = setOf(
 | 
			
		||||
            "" // "linuxArm32Hfp"
 | 
			
		||||
        )
 | 
			
		||||
@ -330,9 +314,29 @@ kotlin {
 | 
			
		||||
            compilations.getByName("main") {
 | 
			
		||||
                if (linux64Bit.contains(this@withType.name)) {
 | 
			
		||||
                    defaultSourceSet.dependsOn(nativeMain)
 | 
			
		||||
                    compilations.getByName("main") {
 | 
			
		||||
                        val libsodiumCinterop by cinterops.creating {
 | 
			
		||||
                            defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
 | 
			
		||||
                            compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-linux-x86-64/include/")
 | 
			
		||||
                        }
 | 
			
		||||
                        kotlinOptions.freeCompilerArgs = listOf(
 | 
			
		||||
                            "-include-binary", "${project.rootDir}/sodiumWrapper/static-linux-x86-64/lib/libsodium.a"
 | 
			
		||||
                        )
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (linuxArm64Bit.contains(this@withType.name)) {
 | 
			
		||||
                    compilations.getByName("main") {
 | 
			
		||||
                        val libsodiumCinterop by cinterops.creating {
 | 
			
		||||
                            defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
 | 
			
		||||
                            compilerOpts.add("-I${project.rootDir}/sodiumWrapper/static-arm64/include/")
 | 
			
		||||
                        }
 | 
			
		||||
                        kotlinOptions.freeCompilerArgs = listOf(
 | 
			
		||||
                            "-include-binary", "${project.rootDir}/sodiumWrapper/static-arm64/lib/libsodium.a"
 | 
			
		||||
                        )
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                if (linux32Bit.contains(this@withType.name)) {
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaround32bitNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
                }
 | 
			
		||||
                if (macos64Bit.contains(this@withType.name)) {
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
@ -351,7 +355,7 @@ kotlin {
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (ios32Bit.contains(this@withType.name)) {
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaround32bitNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
                    println("Setting ios cinterop for $this")
 | 
			
		||||
                    val libsodiumCinterop by cinterops.creating {
 | 
			
		||||
                        defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
 | 
			
		||||
@ -375,7 +379,7 @@ kotlin {
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (watchos32Bit.contains(this@withType.name)) {
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaround32bitNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
                    defaultSourceSet.dependsOn(createWorkaroundNativeMainSourceSet(this@withType.name, nativeDependencies))
 | 
			
		||||
                    println("Setting ios cinterop for $this")
 | 
			
		||||
                    val libsodiumCinterop by cinterops.creating {
 | 
			
		||||
                        defFile(project.file("src/nativeInterop/cinterop/libsodium.def"))
 | 
			
		||||
 | 
			
		||||
@ -70,15 +70,16 @@ actual object Blake2bDelegatedStateless : Blake2bStateless {
 | 
			
		||||
 | 
			
		||||
    override fun digest(inputMessage: UByteArray, key: UByteArray, hashLength: Int): UByteArray {
 | 
			
		||||
        val hashResult = UByteArray(MAX_HASH_BYTES)
 | 
			
		||||
 | 
			
		||||
        val hashResultPinned = hashResult.pin()
 | 
			
		||||
        crypto_generichash(
 | 
			
		||||
            StableRef.create(hashResult).asCPointer().reinterpret(),
 | 
			
		||||
            hashResultPinned.addressOf(0),
 | 
			
		||||
            hashLength.convert(),
 | 
			
		||||
            inputMessage.toCValues(),
 | 
			
		||||
            inputMessage.size.convert(),
 | 
			
		||||
            key.toCValues(),
 | 
			
		||||
            key.size.convert() ?: 0UL
 | 
			
		||||
        )
 | 
			
		||||
        hashResultPinned.unpin()
 | 
			
		||||
        return hashResult
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -23,6 +23,7 @@ object Sample {
 | 
			
		||||
        blake2bUpdateable.update("test")
 | 
			
		||||
        println(blake2bUpdateable.digest().toHexString())
 | 
			
		||||
        println("Blake2b stateless")
 | 
			
		||||
        println("Blake2b stateless: ${Crypto.Blake2b.stateless("test".encodeToByteArray().toUByteArray())}")
 | 
			
		||||
        val statelessResult = Crypto.Blake2b.stateless("test".encodeToByteArray().toUByteArray())
 | 
			
		||||
        println("Blake2b stateless: ${statelessResult.toHexString()}")
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user