1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-05 19:35:48 +03:00
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
Dave Rodgman
2023-04-13 13:01:34 +01:00
parent 9dc8b6a6a2
commit 0a05e703db

View File

@@ -19,8 +19,7 @@ int parse_hex_string(char *hex_string, uint64_t *result)
} }
/* If < 8 bytes, shift right and pad with leading zeros for big-endian */ /* If < 8 bytes, shift right and pad with leading zeros for big-endian */
if (MBEDTLS_IS_BIG_ENDIAN) { if (MBEDTLS_IS_BIG_ENDIAN && olen < 8) {
if (olen < 8) {
int offset = 8 - olen; int offset = 8 - olen;
for (int i = olen - 1; i >= 0; i--) { for (int i = olen - 1; i >= 0; i--) {
raw[i + offset] = raw[i]; raw[i + offset] = raw[i];
@@ -29,7 +28,6 @@ int parse_hex_string(char *hex_string, uint64_t *result)
raw[i] = 0; raw[i] = 0;
} }
} }
}
*result = 0; *result = 0;
for (size_t i = 0; i < olen; i++) { for (size_t i = 0; i < olen; i++) {
@@ -73,13 +71,8 @@ void mbedtls_unaligned_access(int size, int offset)
/* Define expected result by manually aligning the raw bytes, and /* Define expected result by manually aligning the raw bytes, and
* reading back with a normal pointer access. */ * reading back with a normal pointer access. */
uint64_t raw_aligned = 0; uint64_t raw_aligned;
uint8_t *e8 = (uint8_t *) &raw_aligned; memcpy(&raw_aligned, ((uint8_t*)&raw) + offset, size / 8);
uint8_t *r8 = ((uint8_t *) &raw) + offset;
/* Make aligned copy */
for (int i = 0; i < size / 8; i++) {
e8[i] = r8[i];
}
/* Make a 16/32/64 byte read from the aligned location, and copy to expected */ /* Make a 16/32/64 byte read from the aligned location, and copy to expected */
uint64_t expected = 0; uint64_t expected = 0;
switch (size) { switch (size) {
@@ -98,7 +91,7 @@ void mbedtls_unaligned_access(int size, int offset)
TEST_EQUAL(r, expected); TEST_EQUAL(r, expected);
/* Write sentinel to the part of the array we will testing writing to */ /* Write sentinel to the part of the array we will test writing to */
for (size_t i = 0; i < (size_t) (size / 8); i++) { for (size_t i = 0; i < (size_t) (size / 8); i++) {
x[i + offset] = 0xff; x[i + offset] = 0xff;
} }
@@ -319,7 +312,7 @@ void unaligned_access_endian_aware(int size, int offset, int big_endian)
/* Verify read */ /* Verify read */
TEST_EQUAL(read, expected); TEST_EQUAL(read, expected);
/* Test writing back to memory. First write sentiel */ /* Test writing back to memory. First write sentinel */
for (size_t i = 0; i < (size_t) (size / 8); i++) { for (size_t i = 0; i < (size_t) (size / 8); i++) {
x[i + offset] = 0xff; x[i + offset] = 0xff;
} }