mirror of
https://github.com/espressif/esp-idf.git
synced 2025-08-09 12:35:28 +00:00
esp32s2 SHA: fallback to hashing block by block for non DMA memory
Also adds unit test for SHA with input buffer in flash Closes IDF-1529
This commit is contained in:
@@ -305,6 +305,66 @@ TEST_CASE("mbedtls SHA session passed between tasks", "[mbedtls]")
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(sha256_thousand_as, param.result, 32, "SHA256 result from other task");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* Random input generated and hashed using python:
|
||||
|
||||
import hashlib
|
||||
import os, binascii
|
||||
|
||||
input = bytearray(os.urandom(150))
|
||||
arr = ''
|
||||
for idx, b in enumerate(input):
|
||||
if idx % 8 == 0:
|
||||
arr += '\n'
|
||||
arr += "{}, ".format(hex(b))
|
||||
digest = hashlib.sha256(input).hexdigest()
|
||||
|
||||
*/
|
||||
const uint8_t test_vector[] = {
|
||||
0xe4, 0x1a, 0x1a, 0x30, 0x71, 0xd3, 0x94, 0xb0,
|
||||
0xc3, 0x7e, 0x99, 0x9f, 0x1a, 0xde, 0x4a, 0x36,
|
||||
0xb1, 0x1, 0x81, 0x2b, 0x41, 0x91, 0x11, 0x7f,
|
||||
0xd8, 0xe1, 0xd5, 0xe5, 0x52, 0x6d, 0x92, 0xee,
|
||||
0x6c, 0xf7, 0x70, 0xea, 0x3a, 0xb, 0xc9, 0x97,
|
||||
0xc0, 0x12, 0x6f, 0x10, 0x5b, 0x90, 0xd8, 0x52,
|
||||
0x91, 0x69, 0xea, 0xc4, 0x1f, 0xc, 0xcf, 0xc6,
|
||||
0xf0, 0x43, 0xc6, 0xa3, 0x1f, 0x46, 0x3c, 0x3d,
|
||||
0x25, 0xe5, 0xa8, 0x27, 0x86, 0x85, 0x32, 0x3f,
|
||||
0x33, 0xd8, 0x40, 0xc4, 0x41, 0xf6, 0x4b, 0x12,
|
||||
0xd8, 0x5e, 0x4, 0x27, 0x42, 0x90, 0x73, 0x4,
|
||||
0x8, 0x42, 0xd1, 0x64, 0xd, 0x84, 0x3, 0x1,
|
||||
0x76, 0x88, 0xe4, 0x95, 0xdf, 0xe7, 0x62, 0xb4,
|
||||
0xb3, 0xb2, 0x7e, 0x6d, 0x78, 0xca, 0x79, 0x82,
|
||||
0xcc, 0xba, 0x22, 0xd2, 0x90, 0x2e, 0xe3, 0xa8,
|
||||
0x2a, 0x53, 0x3a, 0xb1, 0x9a, 0x7f, 0xb7, 0x8b,
|
||||
0xfa, 0x32, 0x47, 0xc1, 0x5c, 0x6, 0x4f, 0x7b,
|
||||
0xcd, 0xb3, 0xf4, 0xf1, 0xd0, 0xb5, 0xbf, 0xfb,
|
||||
0x7c, 0xc3, 0xa5, 0xb2, 0xc4, 0xd4,
|
||||
};
|
||||
|
||||
const uint8_t test_vector_digest[] = {
|
||||
0xff, 0x1c, 0x60, 0xcb, 0x21, 0xf0, 0x63, 0x68,
|
||||
0xb9, 0xfc, 0xfe, 0xad, 0x3e, 0xb0, 0x2e, 0xd1,
|
||||
0xf9, 0x08, 0x82, 0x82, 0x83, 0x06, 0xc1, 0x8a,
|
||||
0x98, 0x5d, 0x36, 0xc0, 0xb7, 0xeb, 0x35, 0xe0,
|
||||
};
|
||||
|
||||
TEST_CASE("mbedtls SHA, input in flash", "[mbedtls]")
|
||||
{
|
||||
mbedtls_sha256_context sha256_ctx;
|
||||
unsigned char sha256[32];
|
||||
|
||||
mbedtls_sha256_init(&sha256_ctx);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_starts_ret(&sha256_ctx, false));
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_update_ret(&sha256_ctx, test_vector, sizeof(test_vector)));
|
||||
TEST_ASSERT_EQUAL(0, mbedtls_sha256_finish_ret(&sha256_ctx, sha256));
|
||||
|
||||
TEST_ASSERT_EQUAL_MEMORY_MESSAGE(test_vector_digest, sha256, 32, "SHA256 calculation");
|
||||
}
|
||||
|
||||
/* ESP32 do not have SHA512/t functions */
|
||||
#if !DISABLED_FOR_TARGETS(ESP32)
|
||||
|
||||
|
Reference in New Issue
Block a user