]> granicus.if.org Git - esp-idf/commitdiff
mbedtls hardware RSA: Put into menuconfig, squash warnings
authorAngus Gratton <angus@espressif.com>
Fri, 18 Nov 2016 03:26:02 +0000 (14:26 +1100)
committerAngus Gratton <angus@espressif.com>
Fri, 18 Nov 2016 04:50:45 +0000 (15:50 +1100)
All combinations of enabling/disabling hardware acceleration no longer
show unused warnings.

components/mbedtls/Kconfig
components/mbedtls/library/bignum.c
components/mbedtls/port/esp_bignum.c
components/mbedtls/port/include/mbedtls/esp_config.h

index 60facc7d276e3a35d568b03285ea17ef4b5cbdc6..bb2aa8f6a30212aace23e19bcdf93aa594c47161 100644 (file)
@@ -22,7 +22,7 @@ config MBEDTLS_SSL_MAX_CONTENT_LEN
 
 config MBEDTLS_DEBUG
    bool "Enable mbedTLS debugging"
-   default "no"
+   default n
    help
        Enable mbedTLS debugging functions.
        
@@ -34,4 +34,23 @@ config MBEDTLS_DEBUG
        functionality. See the "https_request_main" example for a
        sample function which connects the two together.
 
+config MBEDTLS_HARDWARE_AES
+   bool "Enable hardware AES acceleration"
+   default y
+   help
+       Enable hardware accelerated AES encryption & decryption.
+
+config MBEDTLS_HARDWARE_MPI
+   bool "Enable hardware MPI (bignum) acceleration"
+   default y
+   help
+       Enable hardware accelerated multiple precision integer operations.
+
+       Hardware accelerated multiplication, modulo multiplication,
+       and modular exponentiation for up to 4096 bit results.
+
+       These operations are used by RSA.
+
+
+
 endmenu
index e739bc1d3822bcbd22cd0e61e756d49645edab4b..04ff9e07b2c81adf06b19e6dad0877319dafab3c 100644 (file)
@@ -1092,6 +1092,8 @@ int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint
     return( mbedtls_mpi_sub_mpi( X, A, &_B ) );
 }
 
+#if !defined(MBEDTLS_MPI_MUL_MPI_ALT) || !defined(MBEDTLS_MPI_EXP_MOD_ALT)
+
 /*
  * Helper for mbedtls_mpi multiplication
  */
@@ -1103,6 +1105,7 @@ static
  */
 __attribute__ ((noinline))
 #endif
+
 void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mpi_uint b )
 {
     mbedtls_mpi_uint c = 0, t = 0;
@@ -1164,6 +1167,8 @@ void mpi_mul_hlp( size_t i, mbedtls_mpi_uint *s, mbedtls_mpi_uint *d, mbedtls_mp
     while( c != 0 );
 }
 
+#endif
+
 #if !defined(MBEDTLS_MPI_MUL_MPI_ALT)
 /*
  * Baseline multiplication: X = A * B  (HAC 14.12)
@@ -1526,6 +1531,8 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_
     return( 0 );
 }
 
+#if !defined(MBEDTLS_MPI_EXP_MOD_ALT)
+
 /*
  * Fast Montgomery initialization (thanks to Tom St Denis)
  */
@@ -1600,7 +1607,6 @@ static int mpi_montred( mbedtls_mpi *A, const mbedtls_mpi *N, mbedtls_mpi_uint m
     return( mpi_montmul( A, &U, N, mm, T ) );
 }
 
-#if !defined(MBEDTLS_MPI_EXP_MOD_ALT)
 /*
  * Sliding-window exponentiation: X = A^E mod N  (HAC 14.85)
  */
index 076234b55bcaa99f3654852e2f82abd5ec3c58ae..11a1c63973c7620d17c72e90208f6a859464a887 100644 (file)
@@ -35,8 +35,6 @@
 #include "freertos/FreeRTOS.h"
 #include "freertos/task.h"
 
-static const char *TAG = "bignum";
-
 #if defined(MBEDTLS_MPI_MUL_MPI_ALT) || defined(MBEDTLS_MPI_EXP_MOD_ALT)
 
 static _lock_t mpi_lock;
@@ -330,6 +328,8 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi* Z, const mbedtls_mpi* X, const mbedtls_mpi
 /* Second & final step of a modular multiply - load second multiplication
  * factor Y, run the multiply, read back the result into Z.
  *
+ * Called from both mbedtls_mpi_exp_mod and mbedtls_mpi_mod_mpi.
+ *
  * @param Z result value
  * @param X first multiplication factor (used to set sign of result).
  * @param Y second multiplication factor.
@@ -338,7 +338,7 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi* Z, const mbedtls_mpi* X, const mbedtls_mpi
  *
  *  Caller must have already called esp_mpi_acquire_hardware().
  */
-inline static int modular_multiply_finish(mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, size_t num_words)
+static int modular_multiply_finish(mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, size_t num_words)
 {
     int ret;
     /* Load Y to X input memory block, rerun */
@@ -356,6 +356,8 @@ inline static int modular_multiply_finish(mbedtls_mpi *Z, const mbedtls_mpi *X,
 
 #if defined(MBEDTLS_MPI_MUL_MPI_ALT) /* MBEDTLS_MPI_MUL_MPI_ALT */
 
+static const char *TAG = "bignum";
+
 static int mpi_mult_mpi_failover_mod_mult(mbedtls_mpi *Z, const mbedtls_mpi *X, const mbedtls_mpi *Y, size_t num_words);
 
 /* Z = X * Y */
index 2b47d84ea4923779924c9042b19939e6e1f64aa6..db87c6ef31cd19449e8ed21bc90cd28ae0a830f9 100644 (file)
 /* The following units have ESP32 hardware support,
    uncommenting each _ALT macro will use the
    hardware-accelerated implementation. */
+#ifdef CONFIG_MBEDTLS_HARDWARE_AES
 #define MBEDTLS_AES_ALT
+#endif
 
 /* Currently hardware SHA does not work with TLS handshake,
    due to concurrency issue. Internal TW#7111. */
    Uncommenting these macros will use the hardware-accelerated
    implementations.
 */
+#ifdef CONFIG_MBEDTLS_HARDWARE_MPI
 #define MBEDTLS_MPI_EXP_MOD_ALT
 #define MBEDTLS_MPI_MUL_MPI_ALT
+#endif
 
 /**
  * \def MBEDTLS_MD2_PROCESS_ALT