Apply review feedback on ECP interface

Naming conventions are revised, style issues corrected and minor
optimisation added.
diff --git a/include/mbedtls/check_config.h b/include/mbedtls/check_config.h
index 6fe6d52..a3ec49d 100644
--- a/include/mbedtls/check_config.h
+++ b/include/mbedtls/check_config.h
@@ -150,43 +150,43 @@
 #error "MBEDTLS_GCM_C defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_INIT_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_INIT_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_INIT_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_DEINIT_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_DEINIT_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_DEINIT_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_RANDOMIZE_JAC_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_ADD_MIXED_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_ADD_MIXED_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_DOUBLE_JAC_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_NORMALIZE_JAC_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_RANDOMIZE_MXZ_ALT defined, but not all prerequisites"
 #endif
 
-#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT) && !defined(MBEDTLS_ECP_INTERNAL_ALT)
 #error "MBEDTLS_ECP_NORMALIZE_MXZ_ALT defined, but not all prerequisites"
 #endif
 
diff --git a/include/mbedtls/config.h b/include/mbedtls/config.h
index 50dc70c..f5df5c9 100644
--- a/include/mbedtls/config.h
+++ b/include/mbedtls/config.h
@@ -296,7 +296,9 @@
 //#define MBEDTLS_AES_DECRYPT_ALT
 
 /**
- * \def MBEDTLS_ECP_FUNCTION_ALT
+ * \def MBEDTLS_ECP_INTERNAL_ALT
+ *
+ * Expose a part of the internal interface of the Elliptic Curve Point module.
  *
  * MBEDTLS_ECP__FUNCTION_NAME__ALT: Uncomment a macro to let mbed TLS use your
  * alternative core implementation of elliptic curve arithmetic. Keep in mind
@@ -307,37 +309,34 @@
  * is still present and it is used for group structures not supported by the
  * alternative.
  *
- * Any of these options become available by defining MBEDTLS_ECP_FUNCTION_ALT
- * and implementing the following function:
- * unsigned char mbedtls_ecp_alt_grp_capable( const mbedtls_ecp_group *grp )
- * This should return 1 if the replacement functions implement arithmetic for
- * the given group and 0 otherwise.
+ * Any of these options become available by defining MBEDTLS_ECP_INTERNAL_ALT
+ * and implementing the following functions:
+ *      unsigned char mbedtls_internal_ecp_grp_capable(
+ *          const mbedtls_ecp_group *grp )
+ *      int  mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp )
+ *      void mbedtls_internal_ecp_deinit( const mbedtls_ecp_group *grp )
+ * The mbedtls_internal_ecp_grp_capable function should return 1 if the
+ * replacement functions implement arithmetic for the given group and 0
+ * otherwise.
+ * The functions mbedtls_internal_ecp_init and mbedtls_internal_ecp_deinit are
+ * called before and after each point operation and provide an opportunity to
+ * implement optimized set up and tear down instructions.
  *
- * The functions:
- *      int  mbedtls_ecp_alt_init( const mbedtls_ecp_group *grp )
- *      void mbedtls_ecp_alt_deinit( const mbedtls_ecp_group *grp )
- * can be enabled by MBEDTLS_ECP_INIT_ALT and MBEDTLS_ECP_DEINIT_ALT.
- * They are called before and after each point operation and provide an
- * opportunity to implement optimized set up and tear down instructions.
- *
- * Example: In case you uncomment MBEDTLS_ECP_FUNCTION_ALT and
+ * Example: In case you uncomment MBEDTLS_ECP_INTERNAL_ALT and
  * MBEDTLS_ECP_DOUBLE_JAC_ALT, mbed TLS will still provide the ecp_double_jac
- * function, but will use your mbedtls_ecp_double_jac_alt if the group is
- * supported (your mbedtls_ecp_alt_grp_capable function returns 1 when receives
- * it as an argument). If the group is not supported then the original
+ * function, but will use your mbedtls_internal_ecp_double_jac if the group is
+ * supported (your mbedtls_internal_ecp_grp_capable function returns 1 when
+ * receives it as an argument). If the group is not supported then the original
  * implementation is used. The other functions and the definition of
  * mbedtls_ecp_group and mbedtls_ecp_point will not change, so your
- * implementation of mbedtls_ecp_double_jac_alt and mbedtls_ecp_alt_grp_capable
- * must be compatible with this definition.
+ * implementation of mbedtls_internal_ecp_double_jac and
+ * mbedtls_internal_ecp_grp_capable must be compatible with this definition.
  *
  * Uncomment a macro to enable alternate implementation of the corresponding
  * function.
  */
 /* Required for all the functions in this section */
-//#define MBEDTLS_ECP_FUNCTION_ALT
-/* Utility functions for setup and cleanup */
-//#define MBEDTLS_ECP_INIT_ALT
-//#define MBEDTLS_ECP_DEINIT_ALT
+//#define MBEDTLS_ECP_INTERNAL_ALT
 /* Support for Weierstrass curves with Jacobi representation */
 //#define MBEDTLS_ECP_RANDOMIZE_JAC_ALT
 //#define MBEDTLS_ECP_ADD_MIXED_ALT
diff --git a/include/mbedtls/ecp.h b/include/mbedtls/ecp.h
index 2a43a7a..bf9abef 100644
--- a/include/mbedtls/ecp.h
+++ b/include/mbedtls/ecp.h
@@ -38,11 +38,13 @@
 #define MBEDTLS_ERR_ECP_SIG_LEN_MISMATCH                  -0x4C00  /**< Signature is valid but shorter than the user-supplied length. */
 
 #if !defined(MBEDTLS_ECP_ALT)
-// default mbed TLS elliptic curve arithmetic implementation
-//
-// (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
-// alternative implementation for the whole module and it will replace this
-// one.)
+/*
+ * default mbed TLS elliptic curve arithmetic implementation
+ *
+ * (in case MBEDTLS_ECP_ALT is defined then the developer has to provide an
+ * alternative implementation for the whole module and it will replace this
+ * one.)
+ */
 
 #ifdef __cplusplus
 extern "C" {
diff --git a/include/mbedtls/ecp_internal.h b/include/mbedtls/ecp_internal.h
index eda07ba..a9f5bc5 100644
--- a/include/mbedtls/ecp_internal.h
+++ b/include/mbedtls/ecp_internal.h
@@ -21,62 +21,62 @@
  *
  *  This file is part of mbed TLS (https://tls.mbed.org)
  */
-#ifndef MBEDTLS_ECP_FUNCTION_ALT_H
-#define MBEDTLS_ECP_FUNCTION_ALT_H
+#ifndef MBEDTLS_ECP_INTERNAL_H
+#define MBEDTLS_ECP_INTERNAL_H
 
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 
-unsigned char mbedtls_int_ecp_grp_capable( const mbedtls_ecp_group *grp );
+unsigned char mbedtls_internal_ecp_grp_capable( const mbedtls_ecp_group *grp );
 
-int mbedtls_int_ecp_init( const mbedtls_ecp_group *grp );
+int mbedtls_internal_ecp_init( const mbedtls_ecp_group *grp );
 
-void mbedtls_int_ecp_deinit( const mbedtls_ecp_group *grp );
+void mbedtls_internal_ecp_free( const mbedtls_ecp_group *grp );
 
 #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
-int mbedtls_int_ecp_randomize_jac( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_randomize_jac( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *pt, int (*f_rng)(void *, unsigned char *, size_t),
         void *p_rng );
 #endif
 
 #if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
-int mbedtls_int_ecp_add_mixed( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_add_mixed( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *R, const mbedtls_ecp_point *P,
         const mbedtls_ecp_point *Q );
 #endif
 
 #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
-int mbedtls_int_ecp_double_jac( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_double_jac( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *R, const mbedtls_ecp_point *P );
 #endif
 
 #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
-int mbedtls_int_ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_normalize_jac_many( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *T[], size_t t_len );
 #endif
 
 #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
-int mbedtls_int_ecp_normalize_jac( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_normalize_jac( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *pt );
 #endif
 
 #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
-int mbedtls_int_ecp_double_add_mxz( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_double_add_mxz( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *R, mbedtls_ecp_point *S, const mbedtls_ecp_point *P,
         const mbedtls_ecp_point *Q, const mbedtls_mpi *d );
 #endif
 
 #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
-int mbedtls_int_ecp_randomize_mxz( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_randomize_mxz( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *P, int (*f_rng)(void *, unsigned char *, size_t),
         void *p_rng );
 #endif
 
 #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
-int mbedtls_int_ecp_normalize_mxz( const mbedtls_ecp_group *grp,
+int mbedtls_internal_ecp_normalize_mxz( const mbedtls_ecp_group *grp,
         mbedtls_ecp_point *P );
 #endif
 
-#endif /* MBEDTLS_ECP_FUNCTION_ALT */
+#endif /* MBEDTLS_ECP_INTERNAL_ALT */
 
-#endif /* ecp_function_alt.h */
+#endif /* ecp_internal.h */
 
diff --git a/include/mbedtls/threading.h b/include/mbedtls/threading.h
index d2d79a1..a89fd64 100644
--- a/include/mbedtls/threading.h
+++ b/include/mbedtls/threading.h
@@ -97,8 +97,8 @@
  */
 extern mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex;
 extern mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex;
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
-extern mbedtls_threading_mutex_t mbedtls_threading_cryptohw_asym_mutex;
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+extern mbedtls_threading_mutex_t mbedtls_threading_ecp_mutex;
 #endif
 #endif /* MBEDTLS_THREADING_C */
 
diff --git a/library/ecp.c b/library/ecp.c
index cf57a6b..0a989d5 100644
--- a/library/ecp.c
+++ b/library/ecp.c
@@ -754,9 +754,9 @@
         return( 0 );
 
 #if defined(MBEDTLS_ECP_NORMALIZE_JAC_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_normalize_jac( grp, pt );
+        return mbedtls_internal_ecp_normalize_jac( grp, pt );
     }
 #endif /* MBEDTLS_ECP_NORMALIZE_JAC_ALT */
     mbedtls_mpi_init( &Zi ); mbedtls_mpi_init( &ZZi );
@@ -808,9 +808,9 @@
         return( ecp_normalize_jac( grp, *T ) );
 
 #if defined(MBEDTLS_ECP_NORMALIZE_JAC_MANY_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_normalize_jac_many(grp, T, t_len);
+        return mbedtls_internal_ecp_normalize_jac_many(grp, T, t_len);
     }
 #endif
 
@@ -931,9 +931,9 @@
 #endif
 
 #if defined(MBEDTLS_ECP_DOUBLE_JAC_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_double_jac( grp, R, P );
+        return mbedtls_internal_ecp_double_jac( grp, R, P );
     }
 #endif /* MBEDTLS_ECP_DOUBLE_JAC_ALT */
 
@@ -1029,9 +1029,9 @@
 #endif
 
 #if defined(MBEDTLS_ECP_ADD_MIXED_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_add_mixed( grp, R, P, Q );
+        return mbedtls_internal_ecp_add_mixed( grp, R, P, Q );
     }
 #endif /* MBEDTLS_ECP_ADD_MIXED_ALT */
 
@@ -1116,9 +1116,9 @@
     int count = 0;
 
 #if defined(MBEDTLS_ECP_RANDOMIZE_JAC_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_randomize_jac( grp, pt, f_rng, p_rng );
+        return mbedtls_internal_ecp_randomize_jac( grp, pt, f_rng, p_rng );
     }
 #endif /* MBEDTLS_ECP_RANDOMIZE_JAC_ALT */
 
@@ -1484,9 +1484,9 @@
     int ret;
 
 #if defined(MBEDTLS_ECP_NORMALIZE_MXZ_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_normalize_mxz( grp, P );
+        return mbedtls_internal_ecp_normalize_mxz( grp, P );
     }
 #endif /* MBEDTLS_ECP_NORMALIZE_MXZ_ALT */
 
@@ -1515,9 +1515,9 @@
     int count = 0;
 
 #if defined(MBEDTLS_ECP_RANDOMIZE_MXZ_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_randomize_mxz( grp, P, f_rng, p_rng );
+        return mbedtls_internal_ecp_randomize_mxz( grp, P, f_rng, p_rng );
     }
 #endif /* MBEDTLS_ECP_RANDOMIZE_MXZ_ALT */
 
@@ -1570,9 +1570,9 @@
     mbedtls_mpi A, AA, B, BB, E, C, D, DA, CB;
 
 #if defined(MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( mbedtls_internal_ecp_grp_capable( grp ) )
     {
-        return mbedtls_int_ecp_double_add_mxz( grp, R, S, P, Q, d );
+        return mbedtls_internal_ecp_double_add_mxz( grp, R, S, P, Q, d );
     }
 #endif /* MBEDTLS_ECP_DOUBLE_ADD_MXZ_ALT */
 
@@ -1677,6 +1677,9 @@
              int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
 {
     int ret = MBEDTLS_ERR_ECP_BAD_INPUT_DATA;
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    char is_grp_capable = 0;
+#endif
 
     /* Common sanity checks */
     if( mbedtls_mpi_cmp_int( &P->Z, 1 ) != 0 )
@@ -1686,18 +1689,18 @@
         ( ret = mbedtls_ecp_check_pubkey( grp, P ) ) != 0 )
         return( ret );
 
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 #if defined(MBEDTLS_THREADING_C)
-    if( mbedtls_mutex_lock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 )
+    if( mbedtls_mutex_lock( &mbedtls_threading_ecp_mutex ) != 0 )
         return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
 
 #endif
-    if ( mbedtls_int_ecp_grp_capable( grp )  )
+    if ( is_grp_capable = mbedtls_internal_ecp_grp_capable( grp )  )
     {
-        MBEDTLS_MPI_CHK( mbedtls_int_ecp_init( grp ) );
+        MBEDTLS_MPI_CHK( mbedtls_internal_ecp_init( grp ) );
     }
 
-#endif /* MBEDTLS_ECP_FUNCTION_ALT */
+#endif /* MBEDTLS_ECP_INTERNAL_ALT */
 #if defined(ECP_MONTGOMERY)
     if( ecp_get_type( grp ) == ECP_TYPE_MONTGOMERY )
         ret = ecp_mul_mxz( grp, R, m, P, f_rng, p_rng );
@@ -1708,20 +1711,20 @@
         ret = ecp_mul_comb( grp, R, m, P, f_rng, p_rng );
 
 #endif
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
     cleanup:
 
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+    if ( is_grp_capable )
     {
-        mbedtls_int_ecp_deinit( grp );
+        mbedtls_internal_ecp_free( grp );
     }
 
 #if defined(MBEDTLS_THREADING_C)
-    if( mbedtls_mutex_unlock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 )
+    if( mbedtls_mutex_unlock( &mbedtls_threading_ecp_mutex ) != 0 )
         return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
 
 #endif
-#endif /* MBEDTLS_ECP_FUNCTION_ALT */
+#endif /* MBEDTLS_ECP_INTERNAL_ALT */
     return( ret );
 }
 
@@ -1815,6 +1818,9 @@
 {
     int ret;
     mbedtls_ecp_point mP;
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    char is_grp_capable = 0;
+#endif
 
     if( ecp_get_type( grp ) != ECP_TYPE_SHORT_WEIERSTRASS )
         return( MBEDTLS_ERR_ECP_FEATURE_UNAVAILABLE );
@@ -1824,35 +1830,35 @@
     MBEDTLS_MPI_CHK( mbedtls_ecp_mul_shortcuts( grp, &mP, m, P ) );
     MBEDTLS_MPI_CHK( mbedtls_ecp_mul_shortcuts( grp, R,   n, Q ) );
 
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
 #if defined(MBEDTLS_THREADING_C)
-    if( mbedtls_mutex_lock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 )
+    if( mbedtls_mutex_lock( &mbedtls_threading_ecp_mutex ) != 0 )
         return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
 
 #endif
-    if ( mbedtls_int_ecp_grp_capable( grp )  )
+    if (  is_grp_capable = mbedtls_internal_ecp_grp_capable( grp )  )
     {
-        MBEDTLS_MPI_CHK( mbedtls_int_ecp_init( grp ) );
+        MBEDTLS_MPI_CHK( mbedtls_internal_ecp_init( grp ) );
     }
 
-#endif /* MBEDTLS_ECP_FUNCTION_ALT */
+#endif /* MBEDTLS_ECP_INTERNAL_ALT */
     MBEDTLS_MPI_CHK( ecp_add_mixed( grp, R, &mP, R ) );
     MBEDTLS_MPI_CHK( ecp_normalize_jac( grp, R ) );
 
 cleanup:
 
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
-    if ( mbedtls_int_ecp_grp_capable( grp ) )
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    if ( is_grp_capable )
     {
-        mbedtls_int_ecp_deinit( grp );
+        mbedtls_internal_ecp_free( grp );
     }
 
 #if defined(MBEDTLS_THREADING_C)
-    if( mbedtls_mutex_unlock( &mbedtls_threading_cryptohw_asym_mutex ) != 0 )
+    if( mbedtls_mutex_unlock( &mbedtls_threading_ecp_mutex ) != 0 )
         return ( MBEDTLS_ERR_THREADING_MUTEX_ERROR );
 
 #endif
-#endif /* MBEDTLS_ECP_FUNCTION_ALT */
+#endif /* MBEDTLS_ECP_INTERNAL_ALT */
     mbedtls_ecp_point_free( &mP );
 
     return( ret );
diff --git a/library/threading.c b/library/threading.c
index b0cebd1..81c1075 100644
--- a/library/threading.c
+++ b/library/threading.c
@@ -113,8 +113,8 @@
 
     mbedtls_mutex_init( &mbedtls_threading_readdir_mutex );
     mbedtls_mutex_init( &mbedtls_threading_gmtime_mutex );
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
-    mbedtls_mutex_init( &mbedtls_threading_cryptohw_asym_mutex );
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    mbedtls_mutex_init( &mbedtls_threading_ecp_mutex );
 #endif
 }
 
@@ -125,8 +125,8 @@
 {
     mbedtls_mutex_free( &mbedtls_threading_readdir_mutex );
     mbedtls_mutex_free( &mbedtls_threading_gmtime_mutex );
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
-    mbedtls_mutex_free( &mbedtls_threading_cryptohw_asym_mutex );
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+    mbedtls_mutex_free( &mbedtls_threading_ecp_mutex );
 #endif
 }
 #endif /* MBEDTLS_THREADING_ALT */
@@ -139,8 +139,8 @@
 #endif
 mbedtls_threading_mutex_t mbedtls_threading_readdir_mutex MUTEX_INIT;
 mbedtls_threading_mutex_t mbedtls_threading_gmtime_mutex MUTEX_INIT;
-#if defined(MBEDTLS_ECP_FUNCTION_ALT)
-mbedtls_threading_mutex_t mbedtls_threading_cryptohw_asym_mutex MUTEX_INIT;
+#if defined(MBEDTLS_ECP_INTERNAL_ALT)
+mbedtls_threading_mutex_t mbedtls_threading_ecp_mutex MUTEX_INIT;
 #endif
 
 #endif /* MBEDTLS_THREADING_C */