mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-29 22:20:30 +00:00
Improve parsing of test data
Signed-off-by: Dave Rodgman <dave.rodgman@arm.com>
This commit is contained in:
parent
7fc53dd83d
commit
481a5e427b
@ -44,31 +44,37 @@ Unaligned 64-bit access offset=8
|
|||||||
mbedtls_unaligned_access:64:8
|
mbedtls_unaligned_access:64:8
|
||||||
|
|
||||||
Byteswap 16
|
Byteswap 16
|
||||||
mbedtls_byteswap:0x07060504:0x03020100:16:0x00:0x01
|
mbedtls_byteswap:"0100":16:"0001"
|
||||||
|
|
||||||
|
Byteswap 16 with truncation
|
||||||
|
mbedtls_byteswap:"0706050403020100":16:"0001"
|
||||||
|
|
||||||
Byteswap 16 all-zero
|
Byteswap 16 all-zero
|
||||||
mbedtls_byteswap:0x0:0x0:16:0x00:0x0
|
mbedtls_byteswap:"0000":16:"0000"
|
||||||
|
|
||||||
Byteswap 16 all-ones
|
Byteswap 16 all-ones
|
||||||
mbedtls_byteswap:0xffffffff:0xffffffff:16:0x00:0xffff
|
mbedtls_byteswap:"ffffffffffffffff":16:"ffff"
|
||||||
|
|
||||||
Byteswap 32
|
Byteswap 32
|
||||||
mbedtls_byteswap:0x07060504:0x03020100:32:0x00:0x010203
|
mbedtls_byteswap:"03020100":32:"00010203"
|
||||||
|
|
||||||
|
Byteswap 32 with truncation
|
||||||
|
mbedtls_byteswap:"0706050403020100":32:"00010203"
|
||||||
|
|
||||||
Byteswap 32 all-zero
|
Byteswap 32 all-zero
|
||||||
mbedtls_byteswap:0x0:0x0:32:0x00:0x0
|
mbedtls_byteswap:"00000000":32:"00000000"
|
||||||
|
|
||||||
Byteswap 32 all-ones
|
Byteswap 32 all-ones
|
||||||
mbedtls_byteswap:0xffffffff:0xffffffff:32:0x00:0xffffffff
|
mbedtls_byteswap:"ffffffffffffffff":32:"ffffffff"
|
||||||
|
|
||||||
Byteswap 64
|
Byteswap 64
|
||||||
mbedtls_byteswap:0x07060504:0x03020100:64:0x010203:0x04050607
|
mbedtls_byteswap:"0706050403020100":64:"01020304050607"
|
||||||
|
|
||||||
Byteswap 64 all-zero
|
Byteswap 64 all-zero
|
||||||
mbedtls_byteswap:0x0:0x0:64:0x00:0x0
|
mbedtls_byteswap:"0000000000000000":64:"0000000000000000"
|
||||||
|
|
||||||
Byteswap 64 all-ones
|
Byteswap 64 all-ones
|
||||||
mbedtls_byteswap:0xffffffff:0xffffffff:64:0xffffffff:0xffffffff
|
mbedtls_byteswap:"ffffffffffffffff":64:"ffffffffffffffff"
|
||||||
|
|
||||||
Get individual bytes
|
Get individual bytes
|
||||||
get_byte
|
get_byte
|
||||||
|
@ -6,6 +6,30 @@
|
|||||||
#if defined(__clang__)
|
#if defined(__clang__)
|
||||||
#pragma clang diagnostic ignored "-Wunreachable-code"
|
#pragma clang diagnostic ignored "-Wunreachable-code"
|
||||||
#endif
|
#endif
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert a string of the form "abcd" (case-insensitive) to a uint64_t.
|
||||||
|
*/
|
||||||
|
int parse_hex_string( char* hex_string, uint64_t *result )
|
||||||
|
{
|
||||||
|
uint8_t raw[8];
|
||||||
|
size_t olen;
|
||||||
|
if ( mbedtls_test_unhexify(raw, sizeof(raw), hex_string, &olen) != 0 ) return 0;
|
||||||
|
*result = 0;
|
||||||
|
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 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
/* END_HEADER */
|
/* END_HEADER */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
@ -104,13 +128,13 @@ void mbedtls_unaligned_access( int size, int offset )
|
|||||||
/* END_CASE */
|
/* END_CASE */
|
||||||
|
|
||||||
/* BEGIN_CASE */
|
/* BEGIN_CASE */
|
||||||
void mbedtls_byteswap( unsigned int input_h, unsigned int input_l, int size,
|
void mbedtls_byteswap( char* input_str, int size, char *expected_str )
|
||||||
unsigned int expected_h, unsigned int expected_l )
|
|
||||||
{
|
{
|
||||||
uint64_t input = ( ((uint64_t)input_h ) << 32 ) | ( (uint64_t)input_l );
|
uint64_t input, expected;
|
||||||
uint64_t expected = ( ((uint64_t)expected_h) << 32 ) | ( (uint64_t)expected_l );
|
TEST_ASSERT( parse_hex_string( input_str, &input ) );
|
||||||
|
TEST_ASSERT( parse_hex_string( expected_str, &expected ) );
|
||||||
|
|
||||||
/* Check against expected */
|
/* Check against expected result */
|
||||||
uint64_t r = 0;
|
uint64_t r = 0;
|
||||||
switch ( size )
|
switch ( size )
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user