mirror of
https://github.com/espressif/esp-idf.git
synced 2024-10-05 20:47:46 -04:00
Merge branch 'bugfix/crypto_perf_fail' into 'master'
s2 crypto: update perf test to use cache comp timer Closes IDF-1174 See merge request espressif/esp-idf!8075
This commit is contained in:
commit
6c0a1aab50
@ -4,15 +4,15 @@
|
||||
#define IDF_PERFORMANCE_MIN_AES_GCM_THROUGHPUT_MBSEC 2.1
|
||||
|
||||
// SHA256 hardware throughput at 240MHz, threshold set lower than worst case
|
||||
#define IDF_PERFORMANCE_MIN_SHA256_THROUGHPUT_MBSEC 70.0
|
||||
#define IDF_PERFORMANCE_MIN_SHA256_THROUGHPUT_MBSEC 90.0
|
||||
// esp_sha() time to process 32KB of input data from RAM
|
||||
#define IDF_PERFORMANCE_MAX_TIME_SHA1_32KB 900
|
||||
#define IDF_PERFORMANCE_MAX_TIME_SHA512_32KB 800
|
||||
|
||||
#define IDF_PERFORMANCE_MAX_RSA_2048KEY_PUBLIC_OP 19000
|
||||
#define IDF_PERFORMANCE_MAX_RSA_2048KEY_PRIVATE_OP 160000
|
||||
#define IDF_PERFORMANCE_MAX_RSA_4096KEY_PUBLIC_OP 90000
|
||||
#define IDF_PERFORMANCE_MAX_RSA_4096KEY_PRIVATE_OP 850000
|
||||
#define IDF_PERFORMANCE_MAX_RSA_2048KEY_PUBLIC_OP 13500
|
||||
#define IDF_PERFORMANCE_MAX_RSA_2048KEY_PRIVATE_OP 130000
|
||||
#define IDF_PERFORMANCE_MAX_RSA_4096KEY_PUBLIC_OP 62000
|
||||
#define IDF_PERFORMANCE_MAX_RSA_4096KEY_PRIVATE_OP 800000
|
||||
|
||||
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING 32
|
||||
#define IDF_PERFORMANCE_MAX_SPI_PER_TRANS_NO_POLLING_NO_DMA 30
|
||||
|
@ -8,16 +8,16 @@
|
||||
#include "mbedtls/gcm.h"
|
||||
#include "unity.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "test_utils.h"
|
||||
#include "ccomp_timer.h"
|
||||
|
||||
TEST_CASE("mbedtls AES performance", "[aes]")
|
||||
{
|
||||
const unsigned CALLS = 256;
|
||||
const unsigned CALL_SZ = 32 * 1024;
|
||||
mbedtls_aes_context ctx;
|
||||
int64_t start, end;
|
||||
float elapsed_usec;
|
||||
uint8_t iv[16];
|
||||
uint8_t key[16];
|
||||
|
||||
@ -30,12 +30,12 @@ TEST_CASE("mbedtls AES performance", "[aes]")
|
||||
mbedtls_aes_init(&ctx);
|
||||
mbedtls_aes_setkey_enc(&ctx, key, 128);
|
||||
|
||||
start = esp_timer_get_time();
|
||||
ccomp_timer_start();
|
||||
for (int c = 0; c < CALLS; c++) {
|
||||
memset(buf, 0xAA, CALL_SZ);
|
||||
mbedtls_aes_crypt_cbc(&ctx, MBEDTLS_AES_ENCRYPT, CALL_SZ, iv, buf, buf);
|
||||
}
|
||||
end = esp_timer_get_time();
|
||||
elapsed_usec = ccomp_timer_stop();
|
||||
|
||||
/* Sanity check: make sure the last ciphertext block matches
|
||||
what we expect to see.
|
||||
@ -59,9 +59,8 @@ TEST_CASE("mbedtls AES performance", "[aes]")
|
||||
|
||||
free(buf);
|
||||
|
||||
float usecs = end - start;
|
||||
// bytes/usec = MB/sec
|
||||
float mb_sec = (CALL_SZ * CALLS) / usecs;
|
||||
float mb_sec = (CALL_SZ * CALLS) / elapsed_usec;
|
||||
printf("Encryption rate %.3fMB/sec\n", mb_sec);
|
||||
#ifdef CONFIG_MBEDTLS_HARDWARE_AES
|
||||
// Don't put a hard limit on software AES performance
|
||||
@ -74,7 +73,7 @@ TEST_CASE("mbedtls AES GCM performance", "[aes]")
|
||||
{
|
||||
const unsigned CALL_SZ = 32 * 1024;
|
||||
mbedtls_gcm_context ctx;
|
||||
int64_t start, end;
|
||||
float elapsed_usec;
|
||||
unsigned char tag_buf[16];
|
||||
mbedtls_cipher_id_t cipher = MBEDTLS_CIPHER_ID_AES;
|
||||
uint8_t iv[16];
|
||||
@ -92,12 +91,12 @@ TEST_CASE("mbedtls AES GCM performance", "[aes]")
|
||||
mbedtls_gcm_init(&ctx);
|
||||
mbedtls_gcm_setkey( &ctx, cipher, key, 128);
|
||||
|
||||
start = esp_timer_get_time();
|
||||
ccomp_timer_start();
|
||||
|
||||
memset(buf, 0xAA, CALL_SZ);
|
||||
mbedtls_gcm_crypt_and_tag(&ctx, MBEDTLS_AES_ENCRYPT, CALL_SZ, iv, sizeof(iv), aad, sizeof(aad), buf, buf, 16, tag_buf);
|
||||
|
||||
end = esp_timer_get_time();
|
||||
elapsed_usec = ccomp_timer_stop();
|
||||
|
||||
/* Sanity check: make sure the last ciphertext block matches
|
||||
what we expect to see.
|
||||
@ -131,9 +130,8 @@ TEST_CASE("mbedtls AES GCM performance", "[aes]")
|
||||
|
||||
free(buf);
|
||||
|
||||
float usecs = end - start;
|
||||
// bytes/usec = MB/sec
|
||||
float mb_sec = CALL_SZ / usecs;
|
||||
float mb_sec = CALL_SZ / elapsed_usec;
|
||||
printf("GCM encryption rate %.3fMB/sec\n", mb_sec);
|
||||
|
||||
#ifdef CONFIG_MBEDTLS_HARDWARE_GCM
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "unity.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "test_utils.h"
|
||||
#include "ccomp_timer.h"
|
||||
|
||||
#define PRINT_DEBUG_INFO
|
||||
|
||||
@ -306,7 +307,7 @@ static void print_rsa_details(mbedtls_rsa_context *rsa)
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST_CASE("test performance RSA key operations", "[bignum][ignore]")
|
||||
TEST_CASE("test performance RSA key operations", "[bignum]")
|
||||
{
|
||||
for (int keysize = 2048; keysize <= 4096; keysize += 2048) {
|
||||
rsa_key_operations(keysize, true, false, false);
|
||||
@ -325,7 +326,6 @@ static void rsa_key_operations(int keysize, bool check_performance, bool use_bli
|
||||
unsigned char orig_buf[4096 / 8];
|
||||
unsigned char encrypted_buf[4096 / 8];
|
||||
unsigned char decrypted_buf[4096 / 8];
|
||||
int64_t start;
|
||||
int public_perf, private_perf;
|
||||
|
||||
printf("First, orig_buf is encrypted by the public key, and then decrypted by the private key\n");
|
||||
@ -357,13 +357,13 @@ static void rsa_key_operations(int keysize, bool check_performance, bool use_bli
|
||||
TEST_ASSERT_EQUAL(keysize, (int)rsa.len * 8);
|
||||
TEST_ASSERT_EQUAL(keysize, (int)rsa.D.n * sizeof(mbedtls_mpi_uint) * 8); // The private exponent
|
||||
|
||||
start = esp_timer_get_time();
|
||||
ccomp_timer_start();;
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_rsa_public(&rsa, orig_buf, encrypted_buf));
|
||||
public_perf = esp_timer_get_time() - start;
|
||||
public_perf = ccomp_timer_stop();
|
||||
|
||||
start = esp_timer_get_time();
|
||||
ccomp_timer_start();;
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_rsa_private(&rsa, use_blinding?myrand:NULL, NULL, encrypted_buf, decrypted_buf));
|
||||
private_perf = esp_timer_get_time() - start;
|
||||
private_perf = ccomp_timer_stop();
|
||||
|
||||
if (check_performance && keysize == 2048) {
|
||||
TEST_PERFORMANCE_LESS_THAN(RSA_2048KEY_PUBLIC_OP, "public operations %d us", public_perf);
|
||||
|
@ -6,17 +6,17 @@
|
||||
#include "mbedtls/sha256.h"
|
||||
#include "unity.h"
|
||||
#include "sdkconfig.h"
|
||||
#include "esp_timer.h"
|
||||
#include "esp_heap_caps.h"
|
||||
#include "test_utils.h"
|
||||
#include "sodium/utils.h"
|
||||
#include "ccomp_timer.h"
|
||||
|
||||
TEST_CASE("mbedtls SHA performance", "[aes]")
|
||||
{
|
||||
const unsigned CALLS = 256;
|
||||
const unsigned CALL_SZ = 16 * 1024;
|
||||
mbedtls_sha256_context sha256_ctx;
|
||||
int64_t start, end;
|
||||
float elapsed_usec;
|
||||
unsigned char sha256[32];
|
||||
|
||||
// allocate internal memory
|
||||
@ -25,13 +25,13 @@ TEST_CASE("mbedtls SHA performance", "[aes]")
|
||||
memset(buf, 0x55, CALL_SZ);
|
||||
|
||||
mbedtls_sha256_init(&sha256_ctx);
|
||||
start = esp_timer_get_time();
|
||||
ccomp_timer_start();
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_starts_ret(&sha256_ctx, false));
|
||||
for (int c = 0; c < CALLS; c++) {
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_update_ret(&sha256_ctx, buf, CALL_SZ));
|
||||
}
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_finish_ret(&sha256_ctx, sha256));
|
||||
end = esp_timer_get_time();
|
||||
elapsed_usec = ccomp_timer_stop();
|
||||
|
||||
free(buf);
|
||||
mbedtls_sha256_free(&sha256_ctx);
|
||||
@ -45,9 +45,8 @@ TEST_CASE("mbedtls SHA performance", "[aes]")
|
||||
|
||||
TEST_ASSERT_EQUAL_STRING(expected_hash, hash_str);
|
||||
|
||||
float usecs = end - start;
|
||||
// bytes/usec = MB/sec
|
||||
float mb_sec = (CALL_SZ * CALLS) / usecs;
|
||||
float mb_sec = (CALL_SZ * CALLS) / elapsed_usec;
|
||||
printf("SHA256 rate %.3fMB/sec\n", mb_sec);
|
||||
#ifdef CONFIG_MBEDTLS_HARDWARE_SHA
|
||||
// Don't put a hard limit on software SHA performance
|
||||
|
Loading…
Reference in New Issue
Block a user