esp32: use ccomp_timer in SHA test
This commit is contained in:
parent
36a66a7243
commit
1e12199832
1 changed files with 8 additions and 7 deletions
|
@ -14,6 +14,7 @@
|
||||||
#include "mbedtls/sha256.h"
|
#include "mbedtls/sha256.h"
|
||||||
#include "mbedtls/sha512.h"
|
#include "mbedtls/sha512.h"
|
||||||
#include "esp32/sha.h"
|
#include "esp32/sha.h"
|
||||||
|
#include "ccomp_timer.h"
|
||||||
|
|
||||||
/* Note: Most of the SHA functions are called as part of mbedTLS, so
|
/* Note: Most of the SHA functions are called as part of mbedTLS, so
|
||||||
are tested as part of mbedTLS tests. Only esp_sha() is different.
|
are tested as part of mbedTLS tests. Only esp_sha() is different.
|
||||||
|
@ -25,7 +26,7 @@ TEST_CASE("Test esp_sha()", "[hw_crypto]")
|
||||||
{
|
{
|
||||||
const size_t BUFFER_SZ = 32 * 1024 + 6; // NB: not an exact multiple of SHA block size
|
const size_t BUFFER_SZ = 32 * 1024 + 6; // NB: not an exact multiple of SHA block size
|
||||||
|
|
||||||
int64_t begin, end;
|
int64_t elapsed;
|
||||||
uint32_t us_sha1, us_sha512;
|
uint32_t us_sha1, us_sha512;
|
||||||
uint8_t sha1_result[20] = { 0 };
|
uint8_t sha1_result[20] = { 0 };
|
||||||
uint8_t sha512_result[64] = { 0 };
|
uint8_t sha512_result[64] = { 0 };
|
||||||
|
@ -45,19 +46,19 @@ TEST_CASE("Test esp_sha()", "[hw_crypto]")
|
||||||
0x1e, 0x07, 0xc6, 0xa2, 0x9e, 0x3b, 0x65, 0x75,
|
0x1e, 0x07, 0xc6, 0xa2, 0x9e, 0x3b, 0x65, 0x75,
|
||||||
0x80, 0x7d, 0xe6, 0x6e, 0x47, 0x61, 0x2c, 0x94 };
|
0x80, 0x7d, 0xe6, 0x6e, 0x47, 0x61, 0x2c, 0x94 };
|
||||||
|
|
||||||
begin = esp_timer_get_time();
|
ccomp_timer_start();
|
||||||
esp_sha(SHA1, buffer, BUFFER_SZ, sha1_result);
|
esp_sha(SHA1, buffer, BUFFER_SZ, sha1_result);
|
||||||
end = esp_timer_get_time();
|
elapsed = ccomp_timer_stop();
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha1_expected, sha1_result, sizeof(sha1_expected));
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha1_expected, sha1_result, sizeof(sha1_expected));
|
||||||
us_sha1 = end - begin;
|
us_sha1 = elapsed;
|
||||||
ESP_LOGI(TAG, "esp_sha() 32KB SHA1 in %u us", us_sha1);
|
ESP_LOGI(TAG, "esp_sha() 32KB SHA1 in %u us", us_sha1);
|
||||||
|
|
||||||
begin = esp_timer_get_time();
|
ccomp_timer_start();
|
||||||
esp_sha(SHA2_512, buffer, BUFFER_SZ, sha512_result);
|
esp_sha(SHA2_512, buffer, BUFFER_SZ, sha512_result);
|
||||||
end = esp_timer_get_time();
|
elapsed = ccomp_timer_stop();
|
||||||
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha512_expected, sha512_result, sizeof(sha512_expected));
|
TEST_ASSERT_EQUAL_HEX8_ARRAY(sha512_expected, sha512_result, sizeof(sha512_expected));
|
||||||
|
|
||||||
us_sha512 = end - begin;
|
us_sha512 = elapsed;
|
||||||
ESP_LOGI(TAG, "esp_sha() 32KB SHA512 in %u us", us_sha512);
|
ESP_LOGI(TAG, "esp_sha() 32KB SHA512 in %u us", us_sha512);
|
||||||
|
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
Loading…
Reference in a new issue