@@ -299,6 +299,76 @@ int wp_ecc_get_size(wp_Ecc* ecc)
299299 return (ecc -> bits + 7 ) / 8 ;
300300}
301301
302+ /**
303+ * Lock the ECC key mutex.
304+ *
305+ * This function locks the mutex associated with the ECC key object.
306+ * Use wp_ecc_unlock() to unlock after operations are complete.
307+ *
308+ * @param [in] ecc ECC key object.
309+ * @return 1 on success.
310+ * @return 0 on failure or when single-threaded build.
311+ */
312+ int wp_ecc_lock (wp_Ecc * ecc )
313+ {
314+ #ifndef WP_SINGLE_THREADED
315+ int ok = 1 ;
316+ int rc ;
317+
318+ if (ecc == NULL ) {
319+ ok = 0 ;
320+ }
321+ else {
322+ rc = wc_LockMutex (& ecc -> mutex );
323+ if (rc < 0 ) {
324+ ok = 0 ;
325+ }
326+ }
327+
328+ WOLFPROV_LEAVE (WP_LOG_KE , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), ok );
329+ return ok ;
330+ #else
331+ (void )ecc ;
332+ WOLFPROV_LEAVE (WP_LOG_KE , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), 1 );
333+ return 1 ;
334+ #endif
335+ }
336+
337+ /**
338+ * Unlock the ECC key mutex.
339+ *
340+ * This function unlocks the mutex associated with the ECC key object.
341+ * Should only be called after a successful wp_ecc_lock() call.
342+ *
343+ * @param [in] ecc ECC key object.
344+ * @return 1 on success.
345+ * @return 0 on failure or when single-threaded build.
346+ */
347+ int wp_ecc_unlock (wp_Ecc * ecc )
348+ {
349+ #ifndef WP_SINGLE_THREADED
350+ int ok = 1 ;
351+ int rc ;
352+
353+ if (ecc == NULL ) {
354+ ok = 0 ;
355+ }
356+ else {
357+ rc = wc_UnLockMutex (& ecc -> mutex );
358+ if (rc < 0 ) {
359+ ok = 0 ;
360+ }
361+ }
362+
363+ WOLFPROV_LEAVE (WP_LOG_KE , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), ok );
364+ return ok ;
365+ #else
366+ (void )ecc ;
367+ WOLFPROV_LEAVE (WP_LOG_KE , __FILE__ ":" WOLFPROV_STRINGIZE (__LINE__ ), 1 );
368+ return 1 ;
369+ #endif
370+ }
371+
302372/**
303373 * Create a new ECC key object.
304374 *
0 commit comments