2022-11-30 16:20:33 +01:00
|
|
|
/* BEGIN_HEADER */
|
|
|
|
#include "../library/alignment.h"
|
|
|
|
|
|
|
|
#include <stdint.h>
|
2022-12-01 11:01:08 +01:00
|
|
|
|
2022-12-01 11:49:53 +01:00
|
|
|
#if defined(__clang__)
|
2022-12-01 11:01:08 +01:00
|
|
|
#pragma clang diagnostic ignored "-Wunreachable-code"
|
2022-12-01 11:49:53 +01:00
|
|
|
#endif
|
2022-12-01 14:31:20 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a string of the form "abcd" (case-insensitive) to a uint64_t.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
int parse_hex_string(char *hex_string, uint64_t *result)
|
2022-12-01 14:31:20 +01:00
|
|
|
{
|
|
|
|
uint8_t raw[8];
|
|
|
|
size_t olen;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (mbedtls_test_unhexify(raw, sizeof(raw), hex_string, &olen) != 0) {
|
|
|
|
return 0;
|
|
|
|
}
|
2023-04-13 13:53:35 +02:00
|
|
|
|
|
|
|
/* If < 8 bytes, shift right and pad with leading zeros for big-endian */
|
|
|
|
if (MBEDTLS_IS_BIG_ENDIAN) {
|
|
|
|
if (olen < 8) {
|
|
|
|
int offset = 8 - olen;
|
|
|
|
for (int i = olen - 1; i >= 0; i--) {
|
|
|
|
raw[i + offset] = raw[i];
|
|
|
|
}
|
|
|
|
for (int i = 0; i < offset; i++) {
|
|
|
|
raw[i] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-01 14:31:20 +01:00
|
|
|
*result = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < olen; i++) {
|
|
|
|
if (MBEDTLS_IS_BIG_ENDIAN) {
|
|
|
|
*result |= ((uint64_t) raw[i]) << (i * 8);
|
|
|
|
} else {
|
|
|
|
*result |= ((uint64_t) raw[i]) << ((olen - i - 1) * 8);
|
2022-12-01 14:31:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2022-11-30 16:20:33 +01:00
|
|
|
/* END_HEADER */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_unaligned_access(int size, int offset)
|
2022-11-30 16:20:33 +01:00
|
|
|
{
|
|
|
|
/* Define 64-bit aligned raw byte array */
|
|
|
|
uint64_t raw[2];
|
|
|
|
|
|
|
|
/* Populate with known data */
|
|
|
|
uint8_t *x = (uint8_t *) raw;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < sizeof(raw); i++) {
|
|
|
|
x[i] = (uint8_t) i;
|
|
|
|
}
|
2022-11-30 16:20:33 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(size == 16 || size == 32 || size == 64);
|
2022-11-30 16:20:33 +01:00
|
|
|
|
|
|
|
uint64_t r = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = mbedtls_get_unaligned_uint16(x + offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = mbedtls_get_unaligned_uint32(x + offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = mbedtls_get_unaligned_uint64(x + offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-04-13 13:53:35 +02:00
|
|
|
/* Define expected result by manually aligning the raw bytes, and
|
|
|
|
* reading back with a normal pointer access. */
|
|
|
|
uint64_t raw_aligned = 0;
|
|
|
|
uint8_t *e8 = (uint8_t *) &raw_aligned;
|
|
|
|
uint8_t *r8 = ((uint8_t *) &raw) + offset;
|
|
|
|
/* Make aligned copy */
|
|
|
|
for (int i = 0; i < size / 8; i++) {
|
|
|
|
e8[i] = r8[i];
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
2023-04-13 13:53:35 +02:00
|
|
|
/* Make a 16/32/64 byte read from the aligned location, and copy to expected */
|
|
|
|
uint64_t expected = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-04-13 13:53:35 +02:00
|
|
|
uint16_t *e16 = (uint16_t *) &raw_aligned;
|
|
|
|
expected = *e16;
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-04-13 13:53:35 +02:00
|
|
|
uint32_t *e32 = (uint32_t *) &raw_aligned;
|
|
|
|
expected = *e32;
|
|
|
|
break;
|
|
|
|
case 64:
|
|
|
|
expected = raw_aligned;
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(r, expected);
|
2022-11-30 16:20:33 +01:00
|
|
|
|
|
|
|
/* Write sentinel to the part of the array we will testing writing to */
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < (size_t) (size / 8); i++) {
|
2022-11-30 16:20:33 +01:00
|
|
|
x[i + offset] = 0xff;
|
|
|
|
}
|
|
|
|
/*
|
2023-01-11 14:50:10 +01:00
|
|
|
* Write back to the array with mbedtls_put_unaligned_uint16 and validate
|
|
|
|
* that the array is unchanged as a result.
|
|
|
|
*/
|
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_put_unaligned_uint16(x + offset, r);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_put_unaligned_uint32(x + offset, r);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
mbedtls_put_unaligned_uint64(x + offset, r);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < sizeof(x); i++) {
|
|
|
|
TEST_EQUAL(x[i], (uint8_t) i);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void mbedtls_byteswap(char *input_str, int size, char *expected_str)
|
2022-11-30 16:20:33 +01:00
|
|
|
{
|
2022-12-01 14:31:20 +01:00
|
|
|
uint64_t input, expected;
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(parse_hex_string(input_str, &input));
|
|
|
|
TEST_ASSERT(parse_hex_string(expected_str, &expected));
|
2022-11-30 16:20:33 +01:00
|
|
|
|
2022-12-01 14:31:20 +01:00
|
|
|
/* Check against expected result */
|
2022-12-01 11:49:53 +01:00
|
|
|
uint64_t r = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = MBEDTLS_BSWAP16(input);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = MBEDTLS_BSWAP32(input);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = MBEDTLS_BSWAP64(input);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
2022-12-01 11:49:53 +01:00
|
|
|
default:
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(!"size must be 16, 32 or 64");
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(r, expected);
|
2022-11-30 16:20:33 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check byte by byte by extracting bytes from opposite ends of
|
|
|
|
* input and r.
|
|
|
|
*/
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < (size_t) (size / 8); i++) {
|
2022-11-30 16:20:33 +01:00
|
|
|
size_t s1 = i * 8;
|
2023-01-11 14:50:10 +01:00
|
|
|
size_t s2 = ((size / 8 - 1) - i) * 8;
|
|
|
|
uint64_t a = (input & ((uint64_t) 0xff << s1)) >> s1;
|
|
|
|
uint64_t b = (r & ((uint64_t) 0xff << s2)) >> s2;
|
|
|
|
TEST_EQUAL(a, b);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check BSWAP(BSWAP(x)) == x */
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = MBEDTLS_BSWAP16(r);
|
|
|
|
TEST_EQUAL(r, input & 0xffff);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = MBEDTLS_BSWAP32(r);
|
|
|
|
TEST_EQUAL(r, input & 0xffffffff);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
r = MBEDTLS_BSWAP64(r);
|
|
|
|
TEST_EQUAL(r, input);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void get_byte()
|
|
|
|
{
|
|
|
|
uint8_t data[16];
|
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < sizeof(data); i++) {
|
2022-11-30 16:20:33 +01:00
|
|
|
data[i] = (uint8_t) i;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2022-11-30 16:20:33 +01:00
|
|
|
|
|
|
|
uint64_t u64 = 0x0706050403020100;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t b = 0; b < 8; b++) {
|
2022-12-01 12:42:29 +01:00
|
|
|
uint8_t expected = b;
|
|
|
|
uint8_t actual = b + 1;
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (b) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 0:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_0(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_1(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_2(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_3(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 4:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_4(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 5:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_5(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_6(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 7:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_7(u64);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(actual, expected);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t u32 = 0x03020100;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t b = 0; b < 4; b++) {
|
2022-12-01 12:42:29 +01:00
|
|
|
uint8_t expected = b;
|
|
|
|
uint8_t actual = b + 1;
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (b) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 0:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_0(u32);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_1(u32);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 2:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_2(u32);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 3:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_3(u32);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(actual, expected);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t u16 = 0x0100;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t b = 0; b < 2; b++) {
|
2022-12-01 12:42:29 +01:00
|
|
|
uint8_t expected = b;
|
|
|
|
uint8_t actual = b + 1;
|
2023-01-11 14:50:10 +01:00
|
|
|
switch (b) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 0:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_0(u16);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 1:
|
2023-01-11 14:50:10 +01:00
|
|
|
actual = MBEDTLS_BYTE_1(u16);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(actual, expected);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t u8 = 0x01;
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t actual = MBEDTLS_BYTE_0(u8);
|
|
|
|
TEST_EQUAL(actual, u8);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
2023-01-11 14:50:10 +01:00
|
|
|
void unaligned_access_endian_aware(int size, int offset, int big_endian)
|
2022-11-30 16:20:33 +01:00
|
|
|
{
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_ASSERT(size == 16 || size == 24 || size == 32 || size == 64);
|
|
|
|
TEST_ASSERT(offset >= 0 && offset < 8);
|
2022-11-30 16:20:33 +01:00
|
|
|
|
|
|
|
/* Define 64-bit aligned raw byte array */
|
|
|
|
uint64_t raw[2];
|
|
|
|
/* Populate with known data: x == { 0, 1, 2, ... } */
|
|
|
|
uint8_t *x = (uint8_t *) raw;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < sizeof(raw); i++) {
|
2022-11-30 16:20:33 +01:00
|
|
|
x[i] = (uint8_t) i;
|
2023-01-11 14:50:10 +01:00
|
|
|
}
|
2022-11-30 16:20:33 +01:00
|
|
|
|
2022-12-01 11:49:53 +01:00
|
|
|
uint64_t read = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
if (big_endian) {
|
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT16_BE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 24:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT24_BE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT32_BE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT64_BE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT16_LE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 24:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT24_LE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT32_LE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
read = MBEDTLS_GET_UINT64_LE(x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Build up expected value byte by byte, in either big or little endian format */
|
|
|
|
uint64_t expected = 0;
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < (size_t) (size / 8); i++) {
|
2022-11-30 16:20:33 +01:00
|
|
|
uint64_t b = x[i + offset];
|
|
|
|
uint8_t shift = (big_endian) ? (8 * ((size / 8 - 1) - i)) : (8 * i);
|
|
|
|
expected |= b << shift;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify read */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(read, expected);
|
2022-11-30 16:20:33 +01:00
|
|
|
|
|
|
|
/* Test writing back to memory. First write sentiel */
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < (size_t) (size / 8); i++) {
|
2022-11-30 16:20:33 +01:00
|
|
|
x[i + offset] = 0xff;
|
|
|
|
}
|
|
|
|
/* Overwrite sentinel with endian-aware write macro */
|
2023-01-11 14:50:10 +01:00
|
|
|
if (big_endian) {
|
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT16_BE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 24:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT24_BE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT32_BE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT64_BE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
2023-01-11 14:50:10 +01:00
|
|
|
} else {
|
|
|
|
switch (size) {
|
2022-11-30 16:20:33 +01:00
|
|
|
case 16:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT16_LE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
2023-01-11 14:50:10 +01:00
|
|
|
case 24:
|
|
|
|
MBEDTLS_PUT_UINT24_LE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 32:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT32_LE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
case 64:
|
2023-01-11 14:50:10 +01:00
|
|
|
MBEDTLS_PUT_UINT64_LE(read, x, offset);
|
2022-11-30 16:20:33 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Verify write - check memory is correct */
|
2023-01-11 14:50:10 +01:00
|
|
|
for (size_t i = 0; i < sizeof(raw); i++) {
|
|
|
|
TEST_EQUAL(x[i], (uint8_t) i);
|
|
|
|
}
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
/* END_CASE */
|
|
|
|
|
|
|
|
/* BEGIN_CASE */
|
|
|
|
void mbedtls_is_big_endian()
|
|
|
|
{
|
|
|
|
uint16_t check = 0x1234;
|
2023-01-11 14:50:10 +01:00
|
|
|
uint8_t *p = (uint8_t *) ✓
|
2022-11-30 16:20:33 +01:00
|
|
|
|
2023-01-11 14:50:10 +01:00
|
|
|
if (MBEDTLS_IS_BIG_ENDIAN) {
|
2022-11-30 16:20:33 +01:00
|
|
|
/* Big-endian: data stored MSB first, i.e. p == { 0x12, 0x34 } */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(p[0], 0x12);
|
|
|
|
TEST_EQUAL(p[1], 0x34);
|
|
|
|
} else {
|
2022-11-30 16:20:33 +01:00
|
|
|
/* Little-endian: data stored LSB first, i.e. p == { 0x34, 0x12 } */
|
2023-01-11 14:50:10 +01:00
|
|
|
TEST_EQUAL(p[0], 0x34);
|
|
|
|
TEST_EQUAL(p[1], 0x12);
|
2022-11-30 16:20:33 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
/* END_CASE */
|