You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gu...@apache.org on 2021/10/19 21:42:08 UTC

[incubator-nuttx] 04/08: arch/risc-v/esp32c3: Remove the RSA test from the driver.

This is an automated email from the ASF dual-hosted git repository.

gustavonihei pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 91cb9dafaf1eed39cfe92e397aec44fe53c372da
Author: Abdelatif Guettouche <ab...@espressif.com>
AuthorDate: Fri Oct 15 13:23:49 2021 +0200

    arch/risc-v/esp32c3: Remove the RSA test from the driver.
    
    Signed-off-by: Abdelatif Guettouche <ab...@espressif.com>
---
 arch/risc-v/src/esp32c3/Kconfig                    |   9 -
 arch/risc-v/src/esp32c3/esp32c3_rsa.c              | 199 ---------------------
 .../esp32c3/esp32c3-devkit/configs/rsa/defconfig   |   3 +-
 3 files changed, 1 insertion(+), 210 deletions(-)

diff --git a/arch/risc-v/src/esp32c3/Kconfig b/arch/risc-v/src/esp32c3/Kconfig
index 6be9855..b48b3b2 100644
--- a/arch/risc-v/src/esp32c3/Kconfig
+++ b/arch/risc-v/src/esp32c3/Kconfig
@@ -1045,13 +1045,6 @@ endmenu # Partition Configuration
 
 endif
 
-menu "RSA Accelerate Configuration"
-	depends on ESP32C3_RSA_ACCELERATOR
-
-config ESP32C3_RSA_ACCELERATOR_TEST
-	bool "RSA driver test"
-	default n
-
 menu "BIGNUM"
 	depends on ESP32C3_BIGNUM_ACCELERATOR
 
@@ -1061,6 +1054,4 @@ config ESP32C3_BIGNUM_ACCELERATOR_TEST
 
 endmenu # ESP32C3_BIGNUM_ACCELERATOR
 
-endmenu # ESP32C3_RSA_ACCELERATOR
-
 endif # ARCH_CHIP_ESP32C3
diff --git a/arch/risc-v/src/esp32c3/esp32c3_rsa.c b/arch/risc-v/src/esp32c3/esp32c3_rsa.c
index fd4d21f..f88d92a 100644
--- a/arch/risc-v/src/esp32c3/esp32c3_rsa.c
+++ b/arch/risc-v/src/esp32c3/esp32c3_rsa.c
@@ -2174,202 +2174,3 @@ void esp32c3_rsa_free(struct esp32c3_rsa_context_s *ctx)
 
 #endif
 
-/****************************************************************************
- * Test Functions
- ****************************************************************************/
-
-#ifdef CONFIG_ESP32C3_RSA_ACCELERATOR_TEST
-
-/* Example RSA-1024 keypair, for test purposes */
-
-#define KEY_LEN 128
-
-#define RSA_N   "9292758453063D803DD603D5E777D788" \
-                "8ED1D5BF35786190FA2F23EBC0848AEA" \
-                "DDA92CA6C3D80B32C4D109BE0F36D6AE" \
-                "7130B9CED7ACDF54CFC7555AC14EEBAB" \
-                "93A89813FBF3C4F8066D2D800F7C38A8" \
-                "1AE31942917403FF4946B0A83D3D3E05" \
-                "EE57C6F5F5606FB5D4BC6CD34EE0801A" \
-                "5E94BB77B07507233A0BC7BAC8F90F79"
-
-#define RSA_E   "10001"
-
-#define RSA_D   "24BF6185468786FDD303083D25E64EFC" \
-                "66CA472BC44D253102F8B4A9D3BFA750" \
-                "91386C0077937FE33FA3252D28855837" \
-                "AE1B484A8A9A45F7EE8C0C634F99E8CD" \
-                "DF79C5CE07EE72C7F123142198164234" \
-                "CABB724CF78B8173B9F880FC86322407" \
-                "AF1FEDFDDE2BEB674CA15F3E81A1521E" \
-                "071513A1E85B5DFA031F21ECAE91A34D"
-
-#define RSA_P   "C36D0EB7FCD285223CFB5AABA5BDA3D8" \
-                "2C01CAD19EA484A87EA4377637E75500" \
-                "FCB2005C5C7DD6EC4AC023CDA285D796" \
-                "C3D9E75E1EFC42488BB4F1D13AC30A57"
-
-#define RSA_Q   "C000DF51A7C77AE8D7C7370C1FF55B69" \
-                "E211C2B9E5DB1ED0BF61D0D9899620F4" \
-                "910E4168387E3C30AA1E00C339A79508" \
-                "8452DD96A9A5EA5D9DCA68DA636032AF"
-
-#define PT_LEN  24
-#define RSA_PT  "\xAA\xBB\xCC\x03\x02\x01\x00\xFF\xFF\xFF\xFF\xFF" \
-                "\x11\x22\x33\x0A\x0B\x0C\xCC\xDD\xDD\xDD\xDD\xDD"
-
-#if defined(ESP32C3_PKCS1_V15)
-static int myrand(void *rng_state, unsigned char *output, size_t len)
-{
-#if !defined(__OpenBSD__) && !defined(__NetBSD__)
-  size_t i;
-
-  if (rng_state != NULL)
-    rng_state  = NULL;
-
-  for (i = 0; i < len; ++i)
-    output[i] = rand();
-#else
-  if (rng_state != NULL)
-    rng_state = NULL;
-
-  arc4random_buf(output, len);
-#endif /* !OpenBSD && !NetBSD */
-
-  return OK;
-}
-#endif /* ESP32C3_PKCS1_V15 */
-
-/* Checkup routine */
-
-int esp32c3_rsa_self_test(int verbose)
-{
-  int ret = 0;
-#if defined(ESP32C3_PKCS1_V15)
-  size_t len;
-  struct esp32c3_rsa_context_s rsa;
-  unsigned char rsa_plaintext[PT_LEN];
-  unsigned char rsa_decrypted[PT_LEN];
-  unsigned char rsa_ciphertext[KEY_LEN];
-
-  struct esp32c3_mpi_s K;
-
-  esp32c3_mpi_init(&K);
-  esp32c3_rsa_init(&rsa, ESP32C3_RSA_PKCS_V15, 0);
-
-  ESP32C3_MPI_CHK(esp32c3_mpi_read_string(&K, 16, RSA_N), cleanup);
-  ESP32C3_MPI_CHK(esp32c3_rsa_import(&rsa, &K, NULL, NULL, NULL, NULL),
-                  cleanup);
-  ESP32C3_MPI_CHK(esp32c3_mpi_read_string(&K, 16, RSA_P), cleanup);
-  ESP32C3_MPI_CHK(esp32c3_rsa_import(&rsa, NULL, &K, NULL, NULL, NULL),
-                  cleanup);
-  ESP32C3_MPI_CHK(esp32c3_mpi_read_string(&K, 16, RSA_Q), cleanup);
-  ESP32C3_MPI_CHK(esp32c3_rsa_import(&rsa, NULL, NULL, &K, NULL, NULL),
-                  cleanup);
-  ESP32C3_MPI_CHK(esp32c3_mpi_read_string(&K, 16, RSA_D), cleanup);
-  ESP32C3_MPI_CHK(esp32c3_rsa_import(&rsa, NULL, NULL, NULL, &K, NULL),
-                  cleanup);
-  ESP32C3_MPI_CHK(esp32c3_mpi_read_string(&K, 16, RSA_E), cleanup);
-  ESP32C3_MPI_CHK(esp32c3_rsa_import(&rsa, NULL, NULL, NULL, NULL, &K),
-                  cleanup);
-
-  ESP32C3_MPI_CHK(esp32c3_rsa_complete(&rsa), cleanup);
-
-  if (verbose != 0)
-    syslog(LOG_INFO, "  RSA key validation: ");
-
-  if (esp32c3_rsa_check_pubkey(&rsa) != 0 ||
-    esp32c3_rsa_check_privkey(&rsa) != 0)
-    {
-      if (verbose != 0)
-        syslog(LOG_INFO, "failed\n");
-
-      ret = 1;
-      goto cleanup;
-    }
-
-  if (verbose != 0)
-    syslog(LOG_INFO, "passed\n  PKCS#1 encryption : ");
-
-  memcpy(rsa_plaintext, RSA_PT, PT_LEN);
-
-  if (esp32c3_rsa_encrypt(&rsa, myrand, NULL, ESP32C3_RSA_PUBLIC,
-                   PT_LEN, rsa_plaintext,
-                   rsa_ciphertext) != 0)
-    {
-      if (verbose != 0)
-        syslog(LOG_INFO, "failed\n");
-
-      ret = 1;
-      goto cleanup;
-    }
-
-  if (verbose != 0)
-    syslog(LOG_INFO, "passed\n  PKCS#1 decryption : ");
-
-  if (esp32c3_rsa_decrypt(&rsa, myrand, NULL, ESP32C3_RSA_PRIVATE,
-                   &len, rsa_ciphertext, rsa_decrypted,
-                   sizeof(rsa_decrypted)) != 0)
-    {
-      if (verbose != 0)
-        syslog(LOG_INFO, "failed\n");
-
-      ret = 1;
-      goto cleanup;
-    }
-
-  if (memcmp(rsa_decrypted, rsa_plaintext, len) != 0)
-    {
-      if (verbose != 0)
-        syslog(LOG_INFO, "failed\n");
-
-      ret = 1;
-      goto cleanup;
-    }
-
-  if (verbose != 0)
-    syslog(LOG_INFO, "passed\n");
-
-cleanup:
-  esp32c3_mpi_free(&K);
-  esp32c3_rsa_free(&rsa);
-#else /* ESP32C3_PKCS1_V15 */
-  ((void) verbose);
-#endif /* ESP32C3_PKCS1_V15 */
-  return ret;
-}
-
-/****************************************************************************
- * Name: esp32c3_rsa_main
- ****************************************************************************/
-
-int esp32c3_rsa_main(int argc, char *argv[])
-{
-  int ret = 0;
-
-  syslog(LOG_INFO, "----- BEGIN TEST -----\n");
-
-  ret = esp32c3_mpi_self_test(true);
-  if (ret)
-    {
-      goto test_end;
-    }
-
-  ret = esp32c3_rsa_self_test(true);
-  if (ret)
-    {
-      goto test_end;
-    }
-
-test_end:
-  syslog(LOG_INFO, "----- END TEST -----\n");
-
-  syslog(LOG_INFO, "\n");
-
-  syslog(LOG_INFO, "----- RESULT: %s -----\n",
-         !ret ? "SUCCESS" : "FAILED");
-
-  return 0;
-}
-
-#endif
diff --git a/boards/risc-v/esp32c3/esp32c3-devkit/configs/rsa/defconfig b/boards/risc-v/esp32c3/esp32c3-devkit/configs/rsa/defconfig
index d234f2d..b0afcbe 100644
--- a/boards/risc-v/esp32c3/esp32c3-devkit/configs/rsa/defconfig
+++ b/boards/risc-v/esp32c3/esp32c3-devkit/configs/rsa/defconfig
@@ -25,7 +25,6 @@ CONFIG_DEV_ZERO=y
 CONFIG_ESP32C3_BIGNUM_ACCELERATOR=y
 CONFIG_ESP32C3_BIGNUM_ACCELERATOR_TEST=y
 CONFIG_ESP32C3_RSA_ACCELERATOR=y
-CONFIG_ESP32C3_RSA_ACCELERATOR_TEST=y
 CONFIG_FS_PROCFS=y
 CONFIG_IDLETHREAD_STACKSIZE=2048
 CONFIG_INTELHEX_BINARY=y
@@ -47,4 +46,4 @@ CONFIG_START_YEAR=2019
 CONFIG_SYSTEM_NSH=y
 CONFIG_UART0_SERIAL_CONSOLE=y
 CONFIG_USERMAIN_STACKSIZE=4096
-CONFIG_USER_ENTRYPOINT="esp32c3_rsa_main"
+CONFIG_USER_ENTRYPOINT="nsh_main"