arch/risc-v/esp32c3: Remove the SHA test from the driver.

Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
This commit is contained in:
Abdelatif Guettouche 2021-10-15 13:19:07 +02:00 committed by Gustavo Henrique Nihei
parent 5d1c01aea7
commit 652d77efd2
3 changed files with 1 additions and 592 deletions

View File

@ -1045,15 +1045,6 @@ endmenu # Partition Configuration
endif
menu "SHA accelerator"
depends on ESP32C3_SHA_ACCELERATOR
config ESP32C3_SHA_ACCELERATOR_TEST
bool "SHA accelerator test"
default n
endmenu # ESP32C3_SHA_ACCELERATOR
menu "RSA Accelerate Configuration"
depends on ESP32C3_RSA_ACCELERATOR

View File

@ -1132,584 +1132,3 @@ int esp32c3_sha_init(void)
#endif
/****************************************************************************
* Test Functions
****************************************************************************/
#ifdef CONFIG_ESP32C3_SHA_ACCELERATOR_TEST
/****************************************************************************
* Name: esp32c3_sha1_self_test
*
* Description:
* Checkup routine
*
* Input Parameters:
* verbose - The result output or not
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
static int esp32c3_sha1_self_test(bool verbose)
{
int i;
int j;
int buflen;
int ret = 0;
unsigned char buf[1024];
unsigned char sha1sum[20];
struct esp32c3_sha1_context_s ctx;
/* FIPS-180-1 test vectors */
const unsigned char sha1_test_buf[3][57] =
{
{
"abc"
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
},
{
""
}
};
const size_t sha1_test_buflen[3] =
{
3, 56, 1000
};
const unsigned char sha1_test_sum[3][20] =
{
{
0xa9, 0x99, 0x3e, 0x36, 0x47, 0x06, 0x81, 0x6a, 0xba, 0x3e,
0x25, 0x71, 0x78, 0x50, 0xc2, 0x6c, 0x9c, 0xd0, 0xd8, 0x9d
},
{
0x84, 0x98, 0x3e, 0x44, 0x1c, 0x3b, 0xd2, 0x6e, 0xba, 0xae,
0x4a, 0xa1, 0xf9, 0x51, 0x29, 0xe5, 0xe5, 0x46, 0x70, 0xf1
},
{
0x34, 0xaa, 0x97, 0x3c, 0xd4, 0xc4, 0xda, 0xa4, 0xf6, 0x1e,
0xeb, 0x2b, 0xdb, 0xad, 0x27, 0x31, 0x65, 0x34, 0x01, 0x6f
}
};
esp32c3_sha1_init(&ctx);
for (i = 0; i < 3; i++)
{
if (verbose)
{
syslog(LOG_INFO, " SHA-1 test #%d: ", i + 1);
}
ret = esp32c3_sha1_starts(&ctx);
if (ret != 0)
{
goto fail;
}
if (i == 2)
{
memset(buf, 'a', buflen = 1000);
for (j = 0; j < 1000; j++)
{
ret = esp32c3_sha1_update(&ctx, buf, buflen);
if (ret != 0)
{
goto fail;
}
}
}
else
{
ret = esp32c3_sha1_update(&ctx,
sha1_test_buf[i],
sha1_test_buflen[i]);
if (ret != 0)
{
goto fail;
}
}
ret = esp32c3_sha1_finish(&ctx, sha1sum);
if (ret != 0)
{
goto fail;
}
if (memcmp(sha1sum, sha1_test_sum[i], 20) != 0)
{
ret = 1;
goto fail;
}
if (verbose)
{
syslog(LOG_INFO, "passed\n");
}
}
if (verbose)
{
syslog(LOG_INFO, "\n");
}
goto exit;
fail:
if (verbose)
{
syslog(LOG_INFO, "failed\n");
}
exit:
esp32c3_sha1_free(&ctx);
return (ret);
}
/****************************************************************************
* Name: esp32c3_sha256_self_test
*
* Description:
* Checkup routine
*
* Input Parameters:
* verbose - The result output or not
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
static int esp32c3_sha256_self_test(bool verbose)
{
int i;
int j;
int k;
int buflen;
int ret = 0;
unsigned char *buf;
unsigned char sha256sum[32];
struct esp32c3_sha256_context_s ctx;
/* FIPS-180-2 test vectors */
const unsigned char sha256_test_buf[3][57] =
{
{
"abc"
},
{
"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
},
{
""
}
};
const size_t sha256_test_buflen[3] =
{
3, 56, 1000
};
const unsigned char sha256_test_sum[6][32] =
{
/* SHA-224 test vectors */
{
0x23, 0x09, 0x7d, 0x22, 0x34, 0x05, 0xd8, 0x22,
0x86, 0x42, 0xa4, 0x77, 0xbd, 0xa2, 0x55, 0xb3,
0x2a, 0xad, 0xbc, 0xe4, 0xbd, 0xa0, 0xb3, 0xf7,
0xe3, 0x6c, 0x9d, 0xa7
},
{
0x75, 0x38, 0x8b, 0x16, 0x51, 0x27, 0x76, 0xcc,
0x5d, 0xba, 0x5d, 0xa1, 0xfd, 0x89, 0x01, 0x50,
0xb0, 0xc6, 0x45, 0x5c, 0xb4, 0xf5, 0x8b, 0x19,
0x52, 0x52, 0x25, 0x25
},
{
0x20, 0x79, 0x46, 0x55, 0x98, 0x0c, 0x91, 0xd8,
0xbb, 0xb4, 0xc1, 0xea, 0x97, 0x61, 0x8a, 0x4b,
0xf0, 0x3f, 0x42, 0x58, 0x19, 0x48, 0xb2, 0xee,
0x4e, 0xe7, 0xad, 0x67
},
/* SHA-256 test vectors */
{
0xba, 0x78, 0x16, 0xbf, 0x8f, 0x01, 0xcf, 0xea,
0x41, 0x41, 0x40, 0xde, 0x5d, 0xae, 0x22, 0x23,
0xb0, 0x03, 0x61, 0xa3, 0x96, 0x17, 0x7a, 0x9c,
0xb4, 0x10, 0xff, 0x61, 0xf2, 0x00, 0x15, 0xad
},
{
0x24, 0x8d, 0x6a, 0x61, 0xd2, 0x06, 0x38, 0xb8,
0xe5, 0xc0, 0x26, 0x93, 0x0c, 0x3e, 0x60, 0x39,
0xa3, 0x3c, 0xe4, 0x59, 0x64, 0xff, 0x21, 0x67,
0xf6, 0xec, 0xed, 0xd4, 0x19, 0xdb, 0x06, 0xc1
},
{
0xcd, 0xc7, 0x6e, 0x5c, 0x99, 0x14, 0xfb, 0x92,
0x81, 0xa1, 0xc7, 0xe2, 0x84, 0xd7, 0x3e, 0x67,
0xf1, 0x80, 0x9a, 0x48, 0xa4, 0x97, 0x20, 0x0e,
0x04, 0x6d, 0x39, 0xcc, 0xc7, 0x11, 0x2c, 0xd0
}
};
buf = calloc(1024, sizeof(unsigned char));
if (NULL == buf)
{
if (verbose)
{
syslog(LOG_INFO, "Buffer allocation failed\n");
}
return (1);
}
esp32c3_sha256_init(&ctx);
for (i = 0; i < 6; i++)
{
j = i % 3;
k = i < 3;
if (verbose)
{
syslog(LOG_INFO, " SHA-%d test #%d: ", 256 - k * 32, j + 1);
}
ret = esp32c3_sha256_starts(&ctx, k);
if (ret != 0)
{
goto fail;
}
if (j == 2)
{
memset(buf, 'a', buflen = 1000);
for (j = 0; j < 1000; j++)
{
ret = esp32c3_sha256_update(&ctx, buf, buflen);
if (ret != 0)
{
goto fail;
}
}
}
else
{
ret = esp32c3_sha256_update(&ctx,
sha256_test_buf[j],
sha256_test_buflen[j]);
if (ret != 0)
{
goto fail;
}
}
ret = esp32c3_sha256_finish(&ctx, sha256sum);
if (ret != 0)
{
goto fail;
}
if (memcmp(sha256sum, sha256_test_sum[i], 32 - k * 4) != 0)
{
ret = 1;
goto fail;
}
if (verbose)
{
syslog(LOG_INFO, "passed\n");
}
}
if (verbose)
{
syslog(LOG_INFO, "\n");
}
goto exit;
fail:
if (verbose)
{
syslog(LOG_INFO, "failed\n");
}
exit:
esp32c3_sha256_free(&ctx);
free(buf);
return (ret);
}
/****************************************************************************
* Name: esp32c3_sha512_self_test
*
* Description:
* Checkup routine
*
* Input Parameters:
* verbose - The result output or not
*
* Returned Value:
* OK on success; Negated errno on failure.
*
****************************************************************************/
static int esp32c3_sha512_self_test(bool verbose)
{
int i;
int j;
int k;
int buflen;
int ret = 0;
unsigned char *buf;
unsigned char sha512sum[64];
struct esp32c3_sha512_context_s ctx;
/* FIPS-180-2 test vectors */
const unsigned char sha512_test_buf[3][113] =
{
{
"abc"
},
{
"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmn"
"hijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
},
{
""
}
};
const size_t sha512_test_buflen[3] =
{
3, 112, 1000
};
const unsigned char sha512_test_sum[6][64] =
{
/* SHA-384 test vectors */
{
0xcb, 0x00, 0x75, 0x3f, 0x45, 0xa3, 0x5e, 0x8b,
0xb5, 0xa0, 0x3d, 0x69, 0x9a, 0xc6, 0x50, 0x07,
0x27, 0x2c, 0x32, 0xab, 0x0e, 0xde, 0xd1, 0x63,
0x1a, 0x8b, 0x60, 0x5a, 0x43, 0xff, 0x5b, 0xed,
0x80, 0x86, 0x07, 0x2b, 0xa1, 0xe7, 0xcc, 0x23,
0x58, 0xba, 0xec, 0xa1, 0x34, 0xc8, 0x25, 0xa7
},
{
0x09, 0x33, 0x0c, 0x33, 0xf7, 0x11, 0x47, 0xe8,
0x3d, 0x19, 0x2f, 0xc7, 0x82, 0xcd, 0x1b, 0x47,
0x53, 0x11, 0x1b, 0x17, 0x3b, 0x3b, 0x05, 0xd2,
0x2f, 0xa0, 0x80, 0x86, 0xe3, 0xb0, 0xf7, 0x12,
0xfc, 0xc7, 0xc7, 0x1a, 0x55, 0x7e, 0x2d, 0xb9,
0x66, 0xc3, 0xe9, 0xfa, 0x91, 0x74, 0x60, 0x39
},
{
0x9d, 0x0e, 0x18, 0x09, 0x71, 0x64, 0x74, 0xcb,
0x08, 0x6e, 0x83, 0x4e, 0x31, 0x0a, 0x4a, 0x1c,
0xed, 0x14, 0x9e, 0x9c, 0x00, 0xf2, 0x48, 0x52,
0x79, 0x72, 0xce, 0xc5, 0x70, 0x4c, 0x2a, 0x5b,
0x07, 0xb8, 0xb3, 0xdc, 0x38, 0xec, 0xc4, 0xeb,
0xae, 0x97, 0xdd, 0xd8, 0x7f, 0x3d, 0x89, 0x85
},
/* SHA-512 test vectors */
{
0xdd, 0xaf, 0x35, 0xa1, 0x93, 0x61, 0x7a, 0xba,
0xcc, 0x41, 0x73, 0x49, 0xae, 0x20, 0x41, 0x31,
0x12, 0xe6, 0xfa, 0x4e, 0x89, 0xa9, 0x7e, 0xa2,
0x0a, 0x9e, 0xee, 0xe6, 0x4b, 0x55, 0xd3, 0x9a,
0x21, 0x92, 0x99, 0x2a, 0x27, 0x4f, 0xc1, 0xa8,
0x36, 0xba, 0x3c, 0x23, 0xa3, 0xfe, 0xeb, 0xbd,
0x45, 0x4d, 0x44, 0x23, 0x64, 0x3c, 0xe8, 0x0e,
0x2a, 0x9a, 0xc9, 0x4f, 0xa5, 0x4c, 0xa4, 0x9f
},
{
0x8e, 0x95, 0x9b, 0x75, 0xda, 0xe3, 0x13, 0xda,
0x8c, 0xf4, 0xf7, 0x28, 0x14, 0xfc, 0x14, 0x3f,
0x8f, 0x77, 0x79, 0xc6, 0xeb, 0x9f, 0x7f, 0xa1,
0x72, 0x99, 0xae, 0xad, 0xb6, 0x88, 0x90, 0x18,
0x50, 0x1d, 0x28, 0x9e, 0x49, 0x00, 0xf7, 0xe4,
0x33, 0x1b, 0x99, 0xde, 0xc4, 0xb5, 0x43, 0x3a,
0xc7, 0xd3, 0x29, 0xee, 0xb6, 0xdd, 0x26, 0x54,
0x5e, 0x96, 0xe5, 0x5b, 0x87, 0x4b, 0xe9, 0x09
},
{
0xe7, 0x18, 0x48, 0x3d, 0x0c, 0xe7, 0x69, 0x64,
0x4e, 0x2e, 0x42, 0xc7, 0xbc, 0x15, 0xb4, 0x63,
0x8e, 0x1f, 0x98, 0xb1, 0x3b, 0x20, 0x44, 0x28,
0x56, 0x32, 0xa8, 0x03, 0xaf, 0xa9, 0x73, 0xeb,
0xde, 0x0f, 0xf2, 0x44, 0x87, 0x7e, 0xa6, 0x0a,
0x4c, 0xb0, 0x43, 0x2c, 0xe5, 0x77, 0xc3, 0x1b,
0xeb, 0x00, 0x9c, 0x5c, 0x2c, 0x49, 0xaa, 0x2e,
0x4e, 0xad, 0xb2, 0x17, 0xad, 0x8c, 0xc0, 0x9b
}
};
buf = calloc(1024, sizeof(unsigned char));
if (NULL == buf)
{
if (verbose)
{
syslog(LOG_INFO, "Buffer allocation failed\n");
}
return (1);
}
esp32c3_sha512_init(&ctx);
for (i = 0; i < 6; i++)
{
j = i % 3;
k = i < 3;
if (verbose)
{
syslog(LOG_INFO, " SHA-%d test #%d: ", 512 - k * 128, j + 1);
}
ret = esp32c3_sha512_starts(&ctx, k);
if (ret != 0)
{
goto fail;
}
if (j == 2)
{
memset(buf, 'a', buflen = 1000);
for (j = 0; j < 1000; j++)
{
ret = esp32c3_sha512_update(&ctx, buf, buflen);
if (ret != 0)
{
goto fail;
}
}
}
else
{
ret = esp32c3_sha512_update(&ctx,
sha512_test_buf[j],
sha512_test_buflen[j]);
if (ret != 0)
{
goto fail;
}
}
ret = esp32c3_sha512_finish(&ctx, sha512sum);
if (ret != 0)
{
goto fail;
}
if (memcmp(sha512sum, sha512_test_sum[i], 64 - k * 16) != 0)
{
ret = 1;
goto fail;
}
if (verbose)
{
syslog(LOG_INFO, "passed\n");
}
}
if (verbose)
{
syslog(LOG_INFO, "\n");
}
goto exit;
fail:
if (verbose)
{
syslog(LOG_INFO, "failed\n");
}
exit:
esp32c3_sha512_free(&ctx);
free(buf);
return (ret);
}
/****************************************************************************
* Name: esp32c3_sha_main
****************************************************************************/
int esp32c3_sha_main(int argc, char *argv[])
{
int ret = 0;
syslog(LOG_INFO, "----- BEGIN TEST -----\n");
esp32c3_sha_init();
ret = esp32c3_sha1_self_test(true);
if (ret)
{
goto test_end;
}
ret = esp32c3_sha256_self_test(true);
if (ret)
{
goto test_end;
}
ret = esp32c3_sha512_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 OK;
}
#endif

View File

@ -23,7 +23,6 @@ CONFIG_DEBUG_ASSERTIONS=y
CONFIG_DEBUG_FEATURES=y
CONFIG_DEV_ZERO=y
CONFIG_ESP32C3_SHA_ACCELERATOR=y
CONFIG_ESP32C3_SHA_ACCELERATOR_TEST=y
CONFIG_FS_PROCFS=y
CONFIG_IDLETHREAD_STACKSIZE=2048
CONFIG_INTELHEX_BINARY=y
@ -44,4 +43,4 @@ CONFIG_START_MONTH=11
CONFIG_START_YEAR=2019
CONFIG_SYSTEM_NSH=y
CONFIG_UART0_SERIAL_CONSOLE=y
CONFIG_USER_ENTRYPOINT="esp32c3_sha_main"
CONFIG_USER_ENTRYPOINT="nsh_main"