@@ -23,28 +23,23 @@ import com.sun.jna.Function
2323import com.sun.jna.Memory
2424import com.sun.jna.Native
2525import com.sun.jna.NativeLibrary
26- import com.sun.jna.Platform
2726import com.sun.jna.Pointer
2827import org.slf4j.LoggerFactory
2928import java.nio.ByteBuffer
30- import java.util.Properties
3129
3230/*
3331Defines mbedtls native functions that can be used from jvm.
3432 */
3533internal object MbedtlsApi {
36- private val libraryName = javaClass.classLoader.getResourceAsStream(" mbedtls.properties" ).use { resource ->
37- Properties ().apply { load(resource) }.let { props ->
38- val mbedtlsVersion = props.getProperty(" mbedtlsVersion" )
39- if (Platform .isWindows()) " libmbedtls-$mbedtlsVersion " else " mbedtls-$mbedtlsVersion "
40- }
41- }
42- private val LIB_MBEDTLS = NativeLibrary .getInstance(libraryName)
34+
35+ private var LIB_TFPSACRYPTO : NativeLibrary = NativeLibrary .getInstance(" tfpsacrypto" )
36+ private var LIB_MBEDX509 : NativeLibrary = NativeLibrary .getInstance(" mbedx509" )
37+ private var LIB_MBEDTLS : NativeLibrary = NativeLibrary .getInstance(" mbedtls" )
4338
4439 init {
4540 Native .register(LIB_MBEDTLS )
46- Native .register(Crypto ::class .java, LIB_MBEDTLS )
47- Native .register(X509 ::class .java, LIB_MBEDTLS )
41+ Native .register(X509 ::class .java, LIB_MBEDX509 )
42+ Native .register(Crypto ::class .java, LIB_TFPSACRYPTO )
4843
4944 configureLogThreshold()
5045 }
@@ -82,10 +77,6 @@ internal object MbedtlsApi {
8277 external fun mbedtls_ssl_set_mtu (sslContext : Pointer , mtu : Int )
8378 external fun mbedtls_ssl_get_peer_cert (sslContext : Pointer ): Pointer ?
8479 external fun mbedtls_ssl_set_hostname (sslContext : Pointer , hostname : String? ): Int
85- external fun psa_crypto_init (): Int
86-
87- // mbedtls/error.h
88- external fun mbedtls_strerror (errnum : Int , buffer : Pointer , buflen : Int )
8980
9081 const val MBEDTLS_ERR_SSL_TIMEOUT = - 0x6800
9182 const val MBEDTLS_ERR_SSL_WANT_READ = - 0x6900
@@ -140,6 +131,9 @@ internal object MbedtlsApi {
140131 external fun mbedtls_pk_init (ctx : Pointer )
141132 external fun mbedtls_pk_free (ctx : Pointer )
142133 external fun mbedtls_pk_parse_key (ctx : Pointer , key : ByteArray , keyLen : Int , pwd : Pointer ? , pwdLen : Int ): Int
134+
135+ // psa/crypto.h
136+ external fun psa_crypto_init (): Int
143137 }
144138
145139 internal object X509 {
@@ -148,5 +142,8 @@ internal object MbedtlsApi {
148142 external fun mbedtls_x509_crt_init (cert : Pointer )
149143 external fun mbedtls_x509_crt_free (cert : Pointer )
150144 external fun mbedtls_x509_crt_parse_der (chain : Pointer , buf : ByteArray , len : Int ): Int
145+
146+ // mbedtls/error.h
147+ external fun mbedtls_strerror (errnum : Int , buffer : Pointer , buflen : Int )
151148 }
152149}
0 commit comments