Hi guys, I am using Kotlin multiplatform 1.3.11 an...
# kotlin-native
c
Hi guys, I am using Kotlin multiplatform 1.3.11 and I am working on a android/iOS library. I have trouble with some of the crypto related functions on iOS. So far I manage to successfully use CCCrypt, CCCryptorCreate, CCCryptorUpdate and CCCryptorFinal. However when I try to use asymmetric encryption method such as SecKeyCreateRandomKey I got a signal 11: Segmentation fault. Worth mentioning that I am testing those methods via unit test witch launch an iOS simulator without UI. I read that some other people had issue with encryption method and Kotlin native so maybe these are related?? If any of you has an idea ? And also how is it best to debug ? Can I debug Kotlin native code? How can I have a stacktrace or something that will help me identifying the root cause. I know for sure that the call that fails is SecKeyCreateRandomKey regardless of all the parameters variations i tried I always get a segmentation fault.
o
code like this
Copy code
fun main(): Unit = memScoped {
    val error = alloc<CFErrorRefVar>()
    val cfAttributes = CFDictionaryCreateMutable(null, 2, null, null)
    CFDictionaryAddValue(cfAttributes, kSecAttrKeyType, kSecAttrKeyTypeEC)
    CFDictionaryAddValue(cfAttributes, kSecAttrKeySizeInBits, CFBridgingRetain(NSNumber(int = 256)))
    val privateKey = SecKeyCreateRandomKey(cfAttributes, error.ptr)
    if (error.value != null)
        println("error ${CFBridgingRelease(error.value)}")
    if (privateKey != null)
        println("got key ${CFBridgingRelease(privateKey)}")
    CFBridgingRelease(cfAttributes)
    CFBridgingRelease(privateKey)
}
works for me. Maybe you just hit some troubles with toll-free bridges on CoreFoundation collections
c
Thank you! The problem was indeed around the toll free bridging, for the key size I was not using CFBridgingRetain. Now it works !!!!