Formatting changes

Signed-off-by: Andrzej Kurek <andrzej.kurek@arm.com>
This commit is contained in:
Andrzej Kurek 2020-07-06 15:28:59 -04:00
parent 84bde419e1
commit 0919b142b6
No known key found for this signature in database
GPG Key ID: 89A90840DC388527
4 changed files with 142 additions and 143 deletions

View File

@ -2470,7 +2470,6 @@ static int ssl_cid_build_inner_plaintext( unsigned char *content,
volatile size_t *content_size_dup = content_size; volatile size_t *content_size_dup = content_size;
volatile size_t remaining_dup = remaining; volatile size_t remaining_dup = remaining;
/* Write real content type */ /* Write real content type */
if( remaining == 0 ) if( remaining == 0 )
return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL ); return( MBEDTLS_ERR_SSL_BUFFER_TOO_SMALL );
@ -4888,6 +4887,7 @@ static void ssl_bitmask_set( unsigned char *mask, size_t offset, size_t len )
memset( mask + offset / 8, 0xFF, len / 8 ); memset( mask + offset / 8, 0xFF, len / 8 );
} }
#define BITMASK_CHECK_FAILED 0x75555555
/* /*
* Check that bitmask is full * Check that bitmask is full
*/ */
@ -4897,11 +4897,11 @@ static int ssl_bitmask_check( unsigned char *mask, size_t len )
for( i = 0; i < len / 8; i++ ) for( i = 0; i < len / 8; i++ )
if( mask[i] != 0xFF ) if( mask[i] != 0xFF )
return( 0x75555555 ); return( BITMASK_CHECK_FAILED );
for( i = 0; i < len % 8; i++ ) for( i = 0; i < len % 8; i++ )
if( ( mask[len / 8] & ( 1 << ( 7 - i ) ) ) == 0 ) if( ( mask[len / 8] & ( 1 << ( 7 - i ) ) ) == 0 )
return( 0x75555555 ); return( BITMASK_CHECK_FAILED );
return( 0 ); return( 0 );
} }
@ -7129,6 +7129,7 @@ write_msg:
#if defined(MBEDTLS_SSL_RENEGOTIATION) && defined(MBEDTLS_SSL_CLI_C) #if defined(MBEDTLS_SSL_RENEGOTIATION) && defined(MBEDTLS_SSL_CLI_C)
#if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE) #if defined(MBEDTLS_SSL_KEEP_PEER_CERTIFICATE)
#define PEER_CRT_CHANGED 0x75555555
static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl, static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl,
unsigned char *crt_buf, unsigned char *crt_buf,
size_t crt_buf_len ) size_t crt_buf_len )
@ -7136,14 +7137,15 @@ static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl,
mbedtls_x509_crt const * const peer_crt = ssl->session->peer_cert; mbedtls_x509_crt const * const peer_crt = ssl->session->peer_cert;
if( peer_crt == NULL ) if( peer_crt == NULL )
return( 0x75555555 ); return( PEER_CRT_CHANGED );
if( peer_crt->raw.len != crt_buf_len ) if( peer_crt->raw.len != crt_buf_len )
return( 0x75555555 ); return( PEER_CRT_CHANGED );
return( mbedtls_platform_memcmp( peer_crt->raw.p, crt_buf, crt_buf_len ) ); return( mbedtls_platform_memcmp( peer_crt->raw.p, crt_buf, crt_buf_len ) );
} }
#elif defined(MBEDTLS_SSL_RENEGOTIATION) #elif defined(MBEDTLS_SSL_RENEGOTIATION)
#define PEER_CRT_CHANGED 0x75555555
static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl, static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl,
unsigned char *crt_buf, unsigned char *crt_buf,
size_t crt_buf_len ) size_t crt_buf_len )
@ -7161,7 +7163,7 @@ static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl,
if( peer_cert_digest == NULL || if( peer_cert_digest == NULL ||
digest_info == MBEDTLS_MD_INVALID_HANDLE ) digest_info == MBEDTLS_MD_INVALID_HANDLE )
{ {
return( 0x75555555 ); return( PEER_CRT_CHANGED );
} }
digest_len = mbedtls_md_get_size( digest_info ); digest_len = mbedtls_md_get_size( digest_info );
@ -7170,7 +7172,7 @@ static int ssl_check_peer_crt_unchanged( mbedtls_ssl_context *ssl,
ret = mbedtls_md( digest_info, crt_buf, crt_buf_len, tmp_digest ); ret = mbedtls_md( digest_info, crt_buf, crt_buf_len, tmp_digest );
if( ret != 0 ) if( ret != 0 )
return( 0x75555555 ); return( PEER_CRT_CHANGED );
return( mbedtls_platform_memcmp( tmp_digest, peer_cert_digest, digest_len ) ); return( mbedtls_platform_memcmp( tmp_digest, peer_cert_digest, digest_len ) );
} }

View File

@ -1234,13 +1234,13 @@ int uECC_valid_public_key(const uint8_t *public_key)
return uECC_valid_point(_public); return uECC_valid_point(_public);
} }
int uECC_compute_public_key(const uint8_t * private_key, uint8_t * public_key) int uECC_compute_public_key(const uint8_t *private_key, uint8_t *public_key)
{ {
int ret = UECC_FAULT_DETECTED; int ret = UECC_FAULT_DETECTED;
uECC_word_t _private[NUM_ECC_WORDS]; uECC_word_t _private[NUM_ECC_WORDS];
uECC_word_t _public[NUM_ECC_WORDS * 2]; uECC_word_t _public[NUM_ECC_WORDS * 2];
volatile const uint8_t * private_key_dup = private_key; volatile const uint8_t *private_key_dup = private_key;
volatile const uint8_t * public_key_dup = public_key; volatile const uint8_t *public_key_dup = public_key;
uECC_vli_bytesToNative( uECC_vli_bytesToNative(
_private, _private,
@ -1266,7 +1266,7 @@ int uECC_compute_public_key(const uint8_t * private_key, uint8_t * public_key)
uECC_vli_nativeToBytes( uECC_vli_nativeToBytes(
public_key + public_key +
NUM_ECC_BYTES, NUM_ECC_BYTES, _public + NUM_ECC_WORDS); NUM_ECC_BYTES, NUM_ECC_BYTES, _public + NUM_ECC_WORDS);
if(private_key_dup != private_key || public_key_dup != public_key){ if (private_key_dup != private_key || public_key_dup != public_key){
return UECC_FAULT_DETECTED; return UECC_FAULT_DETECTED;
} }
return ret; return ret;

View File

@ -150,8 +150,7 @@ int uECC_make_key(uint8_t *public_key, uint8_t *private_key)
/* erasing temporary buffer that stored secret: */ /* erasing temporary buffer that stored secret: */
mbedtls_platform_memset(_private, 0, NUM_ECC_BYTES); mbedtls_platform_memset(_private, 0, NUM_ECC_BYTES);
if(private_key == private_key_dup && if (private_key == private_key_dup && public_key == public_key_dup) {
public_key == public_key_dup){
return UECC_SUCCESS; return UECC_SUCCESS;
} }
return UECC_FAULT_DETECTED; return UECC_FAULT_DETECTED;
@ -173,7 +172,6 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
volatile const uint8_t *private_key_dup = private_key; volatile const uint8_t *private_key_dup = private_key;
volatile const uint8_t *secret_dup = secret; volatile const uint8_t *secret_dup = secret;
/* Converting buffers to correct bit order: */ /* Converting buffers to correct bit order: */
uECC_vli_bytesToNative(_private, uECC_vli_bytesToNative(_private,
private_key, private_key,
@ -190,8 +188,7 @@ int uECC_shared_secret(const uint8_t *public_key, const uint8_t *private_key,
/* erasing temporary buffer used to store secret: */ /* erasing temporary buffer used to store secret: */
mbedtls_platform_zeroize(_private, sizeof(_private)); mbedtls_platform_zeroize(_private, sizeof(_private));
if(public_key_dup != public_key || private_key_dup != private_key || if (public_key_dup != public_key || private_key_dup != private_key || secret_dup != secret) {
secret_dup != secret){
return UECC_FAULT_DETECTED; return UECC_FAULT_DETECTED;
} }

View File

@ -168,8 +168,8 @@ int uECC_sign(const uint8_t *private_key, const uint8_t *message_hash,
return r; return r;
} }
if (r == UECC_SUCCESS) { if (r == UECC_SUCCESS) {
if(private_key_dup != private_key || message_hash_dup != message_hash || if (private_key_dup != private_key || message_hash_dup != message_hash ||
hash_size_dup != hash_size || signature_dup != signature){ hash_size_dup != hash_size || signature_dup != signature) {
return UECC_FAULT_DETECTED; return UECC_FAULT_DETECTED;
} }
return UECC_SUCCESS; return UECC_SUCCESS;
@ -308,8 +308,8 @@ int uECC_verify(const uint8_t *public_key, const uint8_t *message_hash,
* 1 (base value) + num_bits - 1 (from the loop) + 5 incrementations. * 1 (base value) + num_bits - 1 (from the loop) + 5 incrementations.
*/ */
if (diff == 0 && flow_control == (num_bits + 5)) { if (diff == 0 && flow_control == (num_bits + 5)) {
if(public_key_dup != public_key || message_hash_dup != message_hash || if (public_key_dup != public_key || message_hash_dup != message_hash ||
hash_size_dup != hash_size || signature_dup != signature){ hash_size_dup != hash_size || signature_dup != signature) {
return UECC_FAULT_DETECTED; return UECC_FAULT_DETECTED;
} }
return UECC_SUCCESS; return UECC_SUCCESS;