diff --git a/src/coreclr/debug/di/rspriv.h b/src/coreclr/debug/di/rspriv.h index eea9a94b58182d..33d54ee398199a 100644 --- a/src/coreclr/debug/di/rspriv.h +++ b/src/coreclr/debug/di/rspriv.h @@ -6397,8 +6397,8 @@ class CordbThread : public CordbBase, public ICorDebugThread, // Lazily initialized. EXCEPTION_RECORD * m_pExceptionRecord; - static const CorDebugUserState kInvalidUserState = CorDebugUserState(-1); - CorDebugUserState m_userState; // This is the current state of the + static const int kInvalidUserState = -1; + int m_userState; // This is the current state of the // thread, at the time that the // left side synchronized diff --git a/src/coreclr/debug/di/rsthread.cpp b/src/coreclr/debug/di/rsthread.cpp index 07e591d15fb116..28703f55ed71d7 100644 --- a/src/coreclr/debug/di/rsthread.cpp +++ b/src/coreclr/debug/di/rsthread.cpp @@ -782,7 +782,7 @@ CorDebugUserState CordbThread::GetUserState() m_userState = pDAC->GetUserState(m_vmThreadToken); } - return m_userState; + return (CorDebugUserState)m_userState; } @@ -886,7 +886,7 @@ HRESULT CordbThread::CreateStepper(ICorDebugStepper ** ppStepper) //Returns true if current user state of a thread is USER_WAIT_SLEEP_JOIN bool CordbThread::IsThreadWaitingOrSleeping() { - CorDebugUserState userState = m_userState; + int userState = m_userState; if (userState == kInvalidUserState) { //If m_userState is not ready, we'll read from DAC only part of it which diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index 38486322526b08..3b460d4c4e8296 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -407,8 +407,10 @@ int32_t SystemNative_GetHostEntryForName(const uint8_t* address, int32_t address char name[_POSIX_HOST_NAME_MAX]; result = gethostname((char*)name, _POSIX_HOST_NAME_MAX); - bool includeIPv4Loopback = true; - bool includeIPv6Loopback = true; + bool includeIPv4Loopback; + bool includeIPv6Loopback; + includeIPv4Loopback = true; + includeIPv6Loopback = true; if (result == 0 && strcasecmp((const char*)address, name) == 0) { @@ -1526,7 +1528,7 @@ int32_t SystemNative_ReceiveSocketError(intptr_t socket, MessageHeader* messageH #if HAVE_LINUX_ERRQUEUE_H char buffer[sizeof(struct sock_extended_err) + sizeof(struct sockaddr_storage)]; messageHeader->ControlBufferLen = sizeof(buffer); - messageHeader->ControlBuffer = (void*)buffer; + messageHeader->ControlBuffer = (uint8_t*)buffer; struct msghdr header; struct icmphdr icmph; diff --git a/src/native/libs/System.Native/pal_process.c b/src/native/libs/System.Native/pal_process.c index ca982ebbf48a23..129fd612e33168 100644 --- a/src/native/libs/System.Native/pal_process.c +++ b/src/native/libs/System.Native/pal_process.c @@ -254,7 +254,7 @@ int32_t SystemNative_ForkAndExecProcess(const char* filename, if (setCredentials && groupsLength > 0) { - getGroupsBuffer = malloc(sizeof(uint32_t) * Int32ToSizeT(groupsLength)); + getGroupsBuffer = (uint32_t*)(malloc(sizeof(uint32_t) * Int32ToSizeT(groupsLength))); if (getGroupsBuffer == NULL) { success = false; diff --git a/src/native/libs/System.Native/pal_signal.c b/src/native/libs/System.Native/pal_signal.c index bf59c24b9df96d..352458c8719f08 100644 --- a/src/native/libs/System.Native/pal_signal.c +++ b/src/native/libs/System.Native/pal_signal.c @@ -130,7 +130,7 @@ static bool TryConvertSignalCodeToPosixSignal(int signalCode, PosixSignal* posix return true; default: - *posixSignal = signalCode; + *posixSignal = (PosixSignal)signalCode; return false; } } diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index 1d573af075355c..db6133d49df6b9 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -82,9 +82,9 @@ LowLevelMonitor* SystemNative_LowLevelMonitor_Create(void) error = pthread_cond_init(&monitor->Condition, &conditionAttributes); - int condAttrDestroyError = pthread_condattr_destroy(&conditionAttributes); + int condAttrDestroyError; + condAttrDestroyError = pthread_condattr_destroy(&conditionAttributes); assert(condAttrDestroyError == 0); - (void)condAttrDestroyError; // unused in release build #else error = pthread_cond_init(&monitor->Condition, NULL); #endif @@ -118,8 +118,6 @@ void SystemNative_LowLevelMonitor_Destroy(LowLevelMonitor* monitor) error = pthread_mutex_destroy(&monitor->Mutex); assert(error == 0); - (void)error; // unused in release build - free(monitor); } @@ -127,9 +125,10 @@ void SystemNative_LowLevelMonitor_Acquire(LowLevelMonitor* monitor) { assert(monitor != NULL); - int error = pthread_mutex_lock(&monitor->Mutex); + int error; + + error = pthread_mutex_lock(&monitor->Mutex); assert(error == 0); - (void)error; // unused in release build SetIsLocked(monitor, true); } @@ -140,9 +139,10 @@ void SystemNative_LowLevelMonitor_Release(LowLevelMonitor* monitor) SetIsLocked(monitor, false); - int error = pthread_mutex_unlock(&monitor->Mutex); + int error; + + error = pthread_mutex_unlock(&monitor->Mutex); assert(error == 0); - (void)error; // unused in release build } void SystemNative_LowLevelMonitor_Wait(LowLevelMonitor* monitor) @@ -151,9 +151,10 @@ void SystemNative_LowLevelMonitor_Wait(LowLevelMonitor* monitor) SetIsLocked(monitor, false); - int error = pthread_cond_wait(&monitor->Condition, &monitor->Mutex); + int error; + + error = pthread_cond_wait(&monitor->Condition, &monitor->Mutex); assert(error == 0); - (void)error; // unused in release build SetIsLocked(monitor, true); } @@ -213,8 +214,6 @@ void SystemNative_LowLevelMonitor_Signal_Release(LowLevelMonitor* monitor) error = pthread_mutex_unlock(&monitor->Mutex); assert(error == 0); - - (void)error; // unused in release build } int32_t SystemNative_CreateThread(uintptr_t stackSize, void *(*startAddress)(void*), void *parameter) diff --git a/src/native/libs/System.Net.Security.Native/pal_gssapi.c b/src/native/libs/System.Net.Security.Native/pal_gssapi.c index c12f4c26cf1b72..9be66b8a7566c2 100644 --- a/src/native/libs/System.Net.Security.Native/pal_gssapi.c +++ b/src/native/libs/System.Net.Security.Native/pal_gssapi.c @@ -244,7 +244,7 @@ uint32_t NetSecurityNative_ImportPrincipalName(uint32_t* minorStatus, // Principal name will usually be in the form SERVICE/HOST. But SPNEGO protocol prefers // GSS_C_NT_HOSTBASED_SERVICE format. That format uses '@' separator instead of '/' between // service name and host name. So convert input string into that format. - char* ptrSlash = memchr(inputName, '/', inputNameLen); + char* ptrSlash = (char*)memchr(inputName, '/', inputNameLen); char* inputNameCopy = NULL; if (ptrSlash != NULL) { diff --git a/src/native/libs/System.Security.Cryptography.Native/memory_debug.c b/src/native/libs/System.Security.Cryptography.Native/memory_debug.c index ed24da7086028a..d742dd5698b5e4 100644 --- a/src/native/libs/System.Security.Cryptography.Native/memory_debug.c +++ b/src/native/libs/System.Security.Cryptography.Native/memory_debug.c @@ -164,7 +164,7 @@ static void do_track_entry(header_t* entry, int32_t add) static void* mallocFunction(size_t size, const char *file, int line) { - header_t* entry = malloc(size + sizeof(header_t)); + header_t* entry = (header_t*)malloc(size + sizeof(header_t)); if (entry != NULL) { init_memory_entry(entry, size, file, line); @@ -187,7 +187,7 @@ static void* reallocFunction (void *ptr, size_t size, const char *file, int line } void* toReturn = NULL; - header_t* newEntry = (header_t*) realloc((void*)entry, size + sizeof(header_t)); + header_t* newEntry = (header_t*)realloc((void*)entry, size + sizeof(header_t)); if (newEntry != NULL) { entry = newEntry; @@ -279,7 +279,7 @@ void CryptoNative_ForEachTrackedAllocation(void (*callback)(void* ptr, uint64_t static void init_tracking_lists(void) { - g_trackedMemory = malloc(kPartitionCount * sizeof(list_t)); + g_trackedMemory = (list_t*)malloc(kPartitionCount * sizeof(list_t)); for (uint32_t i = 0; i < kPartitionCount; i++) { list_init(&g_trackedMemory[i]); diff --git a/src/native/libs/System.Security.Cryptography.Native/openssl.c b/src/native/libs/System.Security.Cryptography.Native/openssl.c index 7257101cde22ff..f84246656932d8 100644 --- a/src/native/libs/System.Security.Cryptography.Native/openssl.c +++ b/src/native/libs/System.Security.Cryptography.Native/openssl.c @@ -1371,6 +1371,7 @@ static int32_t EnsureOpenSsl10Initialized(void) int numLocks = 0; int locksInitialized = 0; int randPollResult = 0; + size_t allocationSize = 0; pthread_mutex_lock(&g_initLock); @@ -1390,7 +1391,6 @@ static int32_t EnsureOpenSsl10Initialized(void) } // Create the locks array - size_t allocationSize = 0; if (!multiply_s(sizeof(pthread_mutex_t), (size_t)numLocks, &allocationSize)) { ret = 2; diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_ecc_import_export.c b/src/native/libs/System.Security.Cryptography.Native/pal_ecc_import_export.c index 8f7bc880cfb74d..2dc23d98036760 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_ecc_import_export.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_ecc_import_export.c @@ -790,6 +790,8 @@ int32_t CryptoNative_EvpPKeyGetEcCurveParameters( EC_GROUP* group = NULL; size_t generatorBufferSize = 0; unsigned char* generatorBuffer = NULL; + int curveTypeNID; + int fieldTypeNID; // Exit if CryptoNative_EvpPKeyGetEcKeyParameters failed if (rc != 1) @@ -798,7 +800,6 @@ int32_t CryptoNative_EvpPKeyGetEcCurveParameters( if (!xBn || !yBn) goto error; - int curveTypeNID; if (!CryptoNative_EvpPKeyGetEcGroupNid(pkey, &curveTypeNID) || !curveTypeNID) goto error; @@ -819,7 +820,7 @@ int32_t CryptoNative_EvpPKeyGetEcCurveParameters( // and some providers seem to be ignoring OSSL_PKEY_PARAM_EC_FIELD_TYPE. // This is specifically true for tpm2 provider. // We can reliably get the field type from the EC_GROUP. - int fieldTypeNID = EC_GROUP_get_field_type(group); + fieldTypeNID = EC_GROUP_get_field_type(group); *curveType = NIDToCurveType(fieldTypeNID); if (*curveType == Unspecified) diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_kdf.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_kdf.c index 31d5c0eaadec81..0c573575fd34d0 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_kdf.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_kdf.c @@ -112,24 +112,26 @@ int32_t CryptoNative_KbkdfHmacOneShot( goto cleanup; } - size_t keyLengthT = Int32ToSizeT(keyLength); - size_t destinationLengthT = Int32ToSizeT(destinationLength); - size_t labelLengthT = Int32ToSizeT(labelLength); - size_t contextLengthT = Int32ToSizeT(contextLength); - - OSSL_PARAM params[] = - { - OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0), - OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "HMAC", 0), - OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT), - OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)label, labelLengthT), - OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)context, contextLengthT), - OSSL_PARAM_construct_end(), - }; - - if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0) { - goto cleanup; + size_t keyLengthT = Int32ToSizeT(keyLength); + size_t destinationLengthT = Int32ToSizeT(destinationLength); + size_t labelLengthT = Int32ToSizeT(labelLength); + size_t contextLengthT = Int32ToSizeT(contextLength); + + OSSL_PARAM params[] = + { + OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0), + OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_MAC, "HMAC", 0), + OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT), + OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)label, labelLengthT), + OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)context, contextLengthT), + OSSL_PARAM_construct_end(), + }; + + if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0) + { + goto cleanup; + } } ret = 1; @@ -199,33 +201,35 @@ static int32_t HkdfCore( goto cleanup; } - size_t keyLengthT = Int32ToSizeT(keyLength); - size_t destinationLengthT = Int32ToSizeT(destinationLength); - - OSSL_PARAM params[6] = {{0}}; - int i = 0; - params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT); - params[i++] = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0); - - if (salt != NULL && saltLength > 0) { - size_t saltLengthT = Int32ToSizeT(saltLength); - params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)salt, saltLengthT); - } - - if (info != NULL && infoLength > 0) - { - size_t infoLengthT = Int32ToSizeT(infoLength); - params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)info, infoLengthT); - } - - params[i++] = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &operation); - params[i] = OSSL_PARAM_construct_end(); - assert(i < 6); - - if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0) - { - goto cleanup; + size_t keyLengthT = Int32ToSizeT(keyLength); + size_t destinationLengthT = Int32ToSizeT(destinationLength); + + OSSL_PARAM params[6] = {{0}}; + int i = 0; + params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (void*)key, keyLengthT); + params[i++] = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, algorithm, 0); + + if (salt != NULL && saltLength > 0) + { + size_t saltLengthT = Int32ToSizeT(saltLength); + params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (void*)salt, saltLengthT); + } + + if (info != NULL && infoLength > 0) + { + size_t infoLengthT = Int32ToSizeT(infoLength); + params[i++] = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (void*)info, infoLengthT); + } + + params[i++] = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &operation); + params[i] = OSSL_PARAM_construct_end(); + assert(i < 6); + + if (EVP_KDF_derive(ctx, destination, destinationLengthT, params) <= 0) + { + goto cleanup; + } } ret = 1; diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_kem.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_kem.c index 29ec92a988fba6..c751a0a1328a4e 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_kem.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_kem.c @@ -162,6 +162,8 @@ int32_t CryptoNative_EvpKemEncapsulate(EVP_PKEY* pKey, EVP_PKEY_CTX* ctx = NULL; ctx = EvpPKeyCtxCreateFromPKey(pKey, extraHandle); int32_t ret = 0; + size_t ciphertextLengthT; + size_t sharedSecretLengthT; if (ctx == NULL) { @@ -173,8 +175,8 @@ int32_t CryptoNative_EvpKemEncapsulate(EVP_PKEY* pKey, goto done; } - size_t ciphertextLengthT = Int32ToSizeT(ciphertextLength); - size_t sharedSecretLengthT = Int32ToSizeT(sharedSecretLength); + ciphertextLengthT = Int32ToSizeT(ciphertextLength); + sharedSecretLengthT = Int32ToSizeT(sharedSecretLength); if (EVP_PKEY_encapsulate(ctx, ciphertext, &ciphertextLengthT, sharedSecret, &sharedSecretLengthT) != 1) { @@ -228,6 +230,8 @@ int32_t CryptoNative_EvpKemDecapsulate(EVP_PKEY* pKey, EVP_PKEY_CTX* ctx = NULL; ctx = EvpPKeyCtxCreateFromPKey(pKey, extraHandle); int32_t ret = 0; + size_t ciphertextLengthT; + size_t sharedSecretLengthT; if (ctx == NULL) { @@ -239,8 +243,8 @@ int32_t CryptoNative_EvpKemDecapsulate(EVP_PKEY* pKey, goto done; } - size_t ciphertextLengthT = Int32ToSizeT(ciphertextLength); - size_t sharedSecretLengthT = Int32ToSizeT(sharedSecretLength); + ciphertextLengthT = Int32ToSizeT(ciphertextLength); + sharedSecretLengthT = Int32ToSizeT(sharedSecretLength); if (EVP_PKEY_decapsulate(ctx, sharedSecret, &sharedSecretLengthT, ciphertext, ciphertextLengthT) != 1) { diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_mac.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_mac.c index 6927392d91e455..a6468e63daf299 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_mac.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_mac.c @@ -356,6 +356,8 @@ int32_t CryptoNative_EvpMacOneShot(EVP_MAC* mac, OSSL_PARAM params[5] = {{0}}; int i = 0; + int32_t ret = 0; + size_t written = 0; params[i++] = OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY, (void*)key, keyLengthT); params[i++] = OSSL_PARAM_construct_int32(OSSL_MAC_PARAM_SIZE, &destinationLength); @@ -369,8 +371,6 @@ int32_t CryptoNative_EvpMacOneShot(EVP_MAC* mac, params[i] = OSSL_PARAM_construct_end(); - int32_t ret = 0; - if (!EVP_MAC_init(ctx, NULL, 0, params)) { goto done; @@ -381,8 +381,6 @@ int32_t CryptoNative_EvpMacOneShot(EVP_MAC* mac, goto done; } - size_t written = 0; - if (!EVP_MAC_final(ctx, destination, &written, macLengthT)) { goto done; diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c index d71c5f7fa97b12..ba64585e477494 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey.c @@ -832,25 +832,27 @@ EVP_PKEY* CryptoNative_EvpPKeyFromData(const char* algorithmName, uint8_t* key, goto done; } - const char* paramName = privateKey == 0 ? OSSL_PKEY_PARAM_PUB_KEY : OSSL_PKEY_PARAM_PRIV_KEY; - int selection = privateKey == 0 ? EVP_PKEY_PUBLIC_KEY : EVP_PKEY_KEYPAIR; - size_t keyLengthT = Int32ToSizeT(keyLength); - - OSSL_PARAM params[] = { - OSSL_PARAM_construct_octet_string(paramName, (void*)key, keyLengthT), - OSSL_PARAM_construct_end(), - }; + const char* paramName = privateKey == 0 ? OSSL_PKEY_PARAM_PUB_KEY : OSSL_PKEY_PARAM_PRIV_KEY; + int selection = privateKey == 0 ? EVP_PKEY_PUBLIC_KEY : EVP_PKEY_KEYPAIR; + size_t keyLengthT = Int32ToSizeT(keyLength); - if (EVP_PKEY_fromdata(ctx, &pkey, selection, params) != 1) - { - if (pkey != NULL) + OSSL_PARAM params[] = { - EVP_PKEY_free(pkey); - pkey = NULL; - } + OSSL_PARAM_construct_octet_string(paramName, (void*)key, keyLengthT), + OSSL_PARAM_construct_end(), + }; - goto done; + if (EVP_PKEY_fromdata(ctx, &pkey, selection, params) != 1) + { + if (pkey != NULL) + { + EVP_PKEY_free(pkey); + pkey = NULL; + } + + goto done; + } } done: diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ecdsa.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ecdsa.c index 86f6916297c3db..f7b6ec260f23b1 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ecdsa.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ecdsa.c @@ -16,6 +16,8 @@ int32_t CryptoNative_EcDsaSignHash(EVP_PKEY* pkey, assert(pkey != NULL); assert(destination != NULL); + size_t written; + ERR_clear_error(); EVP_PKEY_CTX* ctx = EvpPKeyCtxCreateFromPKey(pkey, extraHandle); @@ -27,7 +29,7 @@ int32_t CryptoNative_EcDsaSignHash(EVP_PKEY* pkey, goto done; } - size_t written = Int32ToSizeT(destinationLen); + written = Int32ToSizeT(destinationLen); if (EVP_PKEY_sign(ctx, destination, &written, hash, Int32ToSizeT(hashLen)) > 0) { diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ml_dsa.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ml_dsa.c index 49b280a2eb5289..027c49c1b180b4 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ml_dsa.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_ml_dsa.c @@ -181,34 +181,36 @@ int32_t CryptoNative_MLDsaSignExternalMu(EVP_PKEY* pKey, goto done; } - int muYes = 1; - - OSSL_PARAM initParams[] = - { - OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MU, &muYes), - OSSL_PARAM_construct_end(), - }; - - if (EVP_PKEY_sign_message_init(ctx, NULL, initParams) <= 0) { - goto done; - } + int muYes = 1; - size_t dstLen = Int32ToSizeT(destinationLen); + OSSL_PARAM initParams[] = + { + OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MU, &muYes), + OSSL_PARAM_construct_end(), + }; - if (EVP_PKEY_sign(ctx, destination, &dstLen, mu, Int32ToSizeT(muLen)) == 1) - { - if (dstLen != Int32ToSizeT(destinationLen)) + if (EVP_PKEY_sign_message_init(ctx, NULL, initParams) <= 0) { - assert(false); // length mismatch goto done; } - ret = 1; - } - else - { - ret = 0; + size_t dstLen = Int32ToSizeT(destinationLen); + + if (EVP_PKEY_sign(ctx, destination, &dstLen, mu, Int32ToSizeT(muLen)) == 1) + { + if (dstLen != Int32ToSizeT(destinationLen)) + { + assert(false); // length mismatch + goto done; + } + + ret = 1; + } + else + { + ret = 0; + } } done: @@ -254,20 +256,22 @@ int32_t CryptoNative_MLDsaVerifyExternalMu(EVP_PKEY* pKey, goto done; } - int muYes = 1; - - OSSL_PARAM initParams[] = { - OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MU, &muYes), - OSSL_PARAM_construct_end(), - }; + int muYes = 1; - if (EVP_PKEY_verify_message_init(ctx, NULL, initParams) <= 0) - { - goto done; - } + OSSL_PARAM initParams[] = + { + OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MU, &muYes), + OSSL_PARAM_construct_end(), + }; - ret = EVP_PKEY_verify(ctx, sig, Int32ToSizeT(sigLen), mu, Int32ToSizeT(muLen)) == 1; + if (EVP_PKEY_verify_message_init(ctx, NULL, initParams) <= 0) + { + goto done; + } + + ret = EVP_PKEY_verify(ctx, sig, Int32ToSizeT(sigLen), mu, Int32ToSizeT(muLen)) == 1; + } done: if (ctx != NULL) EVP_PKEY_CTX_free(ctx); diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_raw_signverify.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_raw_signverify.c index 29852282a2cdda..019b1a917f45c8 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_raw_signverify.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_raw_signverify.c @@ -38,36 +38,38 @@ int32_t CryptoNative_EvpPKeySignPure(EVP_PKEY *pkey, goto done; } - OSSL_PARAM contextParams[] = { - OSSL_PARAM_construct_end(), - OSSL_PARAM_construct_end(), - }; - - if (context) - { - contextParams[0] = OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (void*)context, Int32ToSizeT(contextLen)); - } + OSSL_PARAM contextParams[] = + { + OSSL_PARAM_construct_end(), + OSSL_PARAM_construct_end(), + }; - if (EVP_PKEY_sign_message_init(ctx, NULL, contextParams) <= 0) - { - goto done; - } + if (context) + { + contextParams[0] = OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (void*)context, Int32ToSizeT(contextLen)); + } - size_t dstLen = Int32ToSizeT(destinationLen); - if (EVP_PKEY_sign(ctx, destination, &dstLen, msg, Int32ToSizeT(msgLen)) == 1) - { - if (dstLen != Int32ToSizeT(destinationLen)) + if (EVP_PKEY_sign_message_init(ctx, NULL, contextParams) <= 0) { - assert(false); // length mismatch goto done; } - ret = 1; - } - else - { - ret = 0; + size_t dstLen = Int32ToSizeT(destinationLen); + if (EVP_PKEY_sign(ctx, destination, &dstLen, msg, Int32ToSizeT(msgLen)) == 1) + { + if (dstLen != Int32ToSizeT(destinationLen)) + { + assert(false); // length mismatch + goto done; + } + + ret = 1; + } + else + { + ret = 0; + } } done: @@ -116,23 +118,25 @@ int32_t CryptoNative_EvpPKeyVerifyPure(EVP_PKEY *pkey, goto done; } - OSSL_PARAM contextParams[] = { - OSSL_PARAM_construct_end(), - OSSL_PARAM_construct_end(), - }; + OSSL_PARAM contextParams[] = + { + OSSL_PARAM_construct_end(), + OSSL_PARAM_construct_end(), + }; - if (context) - { - contextParams[0] = OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (void*)context, Int32ToSizeT(contextLen)); - } + if (context) + { + contextParams[0] = OSSL_PARAM_construct_octet_string(OSSL_SIGNATURE_PARAM_CONTEXT_STRING, (void*)context, Int32ToSizeT(contextLen)); + } - if (EVP_PKEY_verify_message_init(ctx, NULL, contextParams) <= 0) - { - goto done; - } + if (EVP_PKEY_verify_message_init(ctx, NULL, contextParams) <= 0) + { + goto done; + } - ret = EVP_PKEY_verify(ctx, sig, Int32ToSizeT(sigLen), msg, Int32ToSizeT(msgLen)) == 1; + ret = EVP_PKEY_verify(ctx, sig, Int32ToSizeT(sigLen), msg, Int32ToSizeT(msgLen)) == 1; + } done: if (ctx != NULL) EVP_PKEY_CTX_free(ctx); @@ -179,32 +183,34 @@ int32_t CryptoNative_EvpPKeySignPreEncoded(EVP_PKEY *pkey, goto done; } - int messageEncoding = 0; - OSSL_PARAM messageEncodingParams[] = { - OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MESSAGE_ENCODING, &messageEncoding), - OSSL_PARAM_construct_end(), - }; - - if (EVP_PKEY_sign_message_init(ctx, NULL, messageEncodingParams) <= 0) - { - goto done; - } + int messageEncoding = 0; + OSSL_PARAM messageEncodingParams[] = + { + OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MESSAGE_ENCODING, &messageEncoding), + OSSL_PARAM_construct_end(), + }; - size_t dstLen = Int32ToSizeT(destinationLen); - if (EVP_PKEY_sign(ctx, destination, &dstLen, msg, Int32ToSizeT(msgLen)) == 1) - { - if (dstLen != Int32ToSizeT(destinationLen)) + if (EVP_PKEY_sign_message_init(ctx, NULL, messageEncodingParams) <= 0) { - assert(false); // length mismatch goto done; } - ret = 1; - } - else - { - ret = 0; + size_t dstLen = Int32ToSizeT(destinationLen); + if (EVP_PKEY_sign(ctx, destination, &dstLen, msg, Int32ToSizeT(msgLen)) == 1) + { + if (dstLen != Int32ToSizeT(destinationLen)) + { + assert(false); // length mismatch + goto done; + } + + ret = 1; + } + else + { + ret = 0; + } } done: @@ -249,19 +255,21 @@ int32_t CryptoNative_EvpPKeyVerifyPreEncoded(EVP_PKEY *pkey, goto done; } - int messageEncoding = 0; - OSSL_PARAM messageEncodingParams[] = { - OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MESSAGE_ENCODING, &messageEncoding), - OSSL_PARAM_construct_end(), - }; + int messageEncoding = 0; + OSSL_PARAM messageEncodingParams[] = + { + OSSL_PARAM_construct_int(OSSL_SIGNATURE_PARAM_MESSAGE_ENCODING, &messageEncoding), + OSSL_PARAM_construct_end(), + }; - if (EVP_PKEY_verify_message_init(ctx, NULL, messageEncodingParams) <= 0) - { - goto done; - } + if (EVP_PKEY_verify_message_init(ctx, NULL, messageEncodingParams) <= 0) + { + goto done; + } - ret = EVP_PKEY_verify(ctx, sig, Int32ToSizeT(sigLen), msg, Int32ToSizeT(msgLen)) == 1; + ret = EVP_PKEY_verify(ctx, sig, Int32ToSizeT(sigLen), msg, Int32ToSizeT(msgLen)) == 1; + } done: if (ctx != NULL) EVP_PKEY_CTX_free(ctx); diff --git a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c index f4a79df5fa1498..764bd2870d1912 100644 --- a/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c +++ b/src/native/libs/System.Security.Cryptography.Native/pal_evp_pkey_rsa.c @@ -119,6 +119,8 @@ int32_t CryptoNative_RsaDecrypt(EVP_PKEY* pkey, assert(padding >= RsaPaddingPkcs1 && padding <= RsaPaddingOaepOrPss); assert(digest != NULL || padding == RsaPaddingPkcs1); + size_t written; + ERR_clear_error(); EVP_PKEY_CTX* ctx = EvpPKeyCtxCreateFromPKey(pkey, extraHandle); @@ -151,7 +153,7 @@ int32_t CryptoNative_RsaDecrypt(EVP_PKEY* pkey, } } - size_t written = Int32ToSizeT(destinationLen); + written = Int32ToSizeT(destinationLen); if (EVP_PKEY_decrypt(ctx, destination, &written, source, Int32ToSizeT(sourceLen)) > 0) { @@ -181,6 +183,8 @@ int32_t CryptoNative_RsaEncrypt(EVP_PKEY* pkey, assert(padding >= RsaPaddingPkcs1 && padding <= RsaPaddingOaepOrPss); assert(digest != NULL || padding == RsaPaddingPkcs1); + size_t written; + ERR_clear_error(); EVP_PKEY_CTX* ctx = EvpPKeyCtxCreateFromPKey(pkey, extraHandle); @@ -197,7 +201,7 @@ int32_t CryptoNative_RsaEncrypt(EVP_PKEY* pkey, goto done; } - size_t written = Int32ToSizeT(destinationLen); + written = Int32ToSizeT(destinationLen); if (EVP_PKEY_encrypt(ctx, destination, &written, source, Int32ToSizeT(sourceLen)) > 0) { @@ -259,6 +263,8 @@ int32_t CryptoNative_RsaSignHash(EVP_PKEY* pkey, assert(padding >= RsaPaddingPkcs1 && padding <= RsaPaddingOaepOrPss); assert(digest != NULL || padding == RsaPaddingPkcs1); + size_t written; + ERR_clear_error(); EVP_PKEY_CTX* ctx = EvpPKeyCtxCreateFromPKey(pkey, extraHandle); @@ -291,7 +297,7 @@ int32_t CryptoNative_RsaSignHash(EVP_PKEY* pkey, } } - size_t written = Int32ToSizeT(destinationLen); + written = Int32ToSizeT(destinationLen); if (EVP_PKEY_sign(ctx, destination, &written, hash, Int32ToSizeT(hashLen)) > 0) {