diff --git a/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/keys/OpenSSLKey.kt b/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/keys/OpenSSLKey.kt index 0af939e..48d7f94 100644 --- a/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/keys/OpenSSLKey.kt +++ b/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/keys/OpenSSLKey.kt @@ -27,7 +27,7 @@ import kotlinx.cinterop.UByteVar import kotlinx.cinterop.get import kotlinx.cinterop.reinterpret import kotlinx.cinterop.toKString -import libssl.ERR_func_error_string +import libssl.ERR_error_string import libssl.ERR_get_error import libssl.RAND_bytes @@ -57,8 +57,8 @@ class OpenSSLKey(private val secureHeap: SecureHeap, ): OpenSSLKey { val dataSize = (keySize / 8).toULong() val rawDataPtr = secureHeap.allocate((keySize / 8).toULong()).reinterpret() - if (RAND_bytes(rawDataPtr, 1) != 1) { - throw Exception(ERR_func_error_string(ERR_get_error())?.toKString()) + if (RAND_bytes(rawDataPtr, dataSize.toInt()) != 1) { + throw Exception(ERR_error_string(ERR_get_error(), null)?.toKString()) } return OpenSSLKey(secureHeap, purposes, algorithm, rawDataPtr, dataSize, type) diff --git a/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/providers/OpenSSLCryptoProvider.kt b/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/providers/OpenSSLCryptoProvider.kt index 60b688d..92f2857 100644 --- a/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/providers/OpenSSLCryptoProvider.kt +++ b/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/providers/OpenSSLCryptoProvider.kt @@ -25,12 +25,8 @@ import io.karma.advcrypto.keys.enum.KeyType import io.karma.advcrypto.linux.keys.OpenSSLKey import io.karma.advcrypto.linux.keys.OpenSSLPKey import io.karma.advcrypto.linux.utils.SecureHeap -import kotlinx.cinterop.CPointer -import kotlinx.cinterop.CPointerVar import kotlinx.cinterop.CValuesRef import kotlinx.cinterop.ExperimentalForeignApi -import kotlinx.cinterop.IntVar -import kotlinx.cinterop.UByteVar import kotlinx.cinterop.UIntVar import kotlinx.cinterop.addressOf import kotlinx.cinterop.alloc @@ -48,7 +44,6 @@ import libssl.EVP_DigestInit import libssl.EVP_DigestUpdate import libssl.EVP_MAX_MD_SIZE import libssl.EVP_MD -import libssl.EVP_MD_CTX import libssl.EVP_MD_CTX_free import libssl.EVP_MD_CTX_new import libssl.EVP_PKEY_free @@ -64,21 +59,11 @@ import libssl.EVP_sha3_256 import libssl.EVP_sha3_384 import libssl.EVP_sha3_512 import libssl.EVP_sha512 -import libssl.MD5 import libssl.RSAPublicKey_dup import libssl.RSA_F4 import libssl.RSA_free import libssl.RSA_generate_key_ex import libssl.RSA_new -import libssl.SHA1 -import libssl.SHA224 -import libssl.SHA224_DIGEST_LENGTH -import libssl.SHA256 -import libssl.SHA256_DIGEST_LENGTH -import libssl.SHA384 -import libssl.SHA384_DIGEST_LENGTH -import libssl.SHA512 -import libssl.SHA512_DIGEST_LENGTH class OpenSSLCryptoProvider: AbstractProvider( "Default", diff --git a/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/utils/SecureHeap.kt b/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/utils/SecureHeap.kt index b55f7ab..dba0e25 100644 --- a/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/utils/SecureHeap.kt +++ b/kmp-advcrypto/src/linuxX64Main/kotlin/io/karma/advcrypto/linux/utils/SecureHeap.kt @@ -24,7 +24,7 @@ import libssl.CRYPTO_secure_malloc import libssl.CRYPTO_secure_malloc_done import libssl.CRYPTO_secure_malloc_init import libssl.CRYPTO_secure_malloc_initialized -import libssl.ERR_func_error_string +import libssl.ERR_error_string import libssl.ERR_get_error /** @@ -66,7 +66,7 @@ class SecureHeap(size: ULong, minSize: ULong): AutoCloseable { * @since 12/06/2024 */ fun allocate(size: ULong): COpaquePointer = CRYPTO_secure_malloc(size, this.toString(), 47) - ?: throw Exception(ERR_func_error_string(ERR_get_error())?.toKString()) + ?: throw Exception(ERR_error_string(ERR_get_error(), null)?.toKString()) /** * This method frees the allocated memory from the secure heap. This also deletes the data