Add new error code PLATFORM_ALLOC_FAILED for mbedtls_platform_memmove()
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
diff --git a/library/bignum.c b/library/bignum.c
index 2cc8e22..f4ab0db 100644
--- a/library/bignum.c
+++ b/library/bignum.c
@@ -558,11 +558,7 @@
length++;
} while( mbedtls_mpi_cmp_int( X, 0 ) != 0 );
- if( 0 != mbedtls_platform_memmove( *p, p_end, length ) )
- {
- ret = MBEDTLS_ERR_MPI_ALLOC_FAILED;
- goto cleanup;
- }
+ MBEDTLS_MPI_CHK( mbedtls_platform_memmove( *p, p_end, length ) );
*p += length;
cleanup:
diff --git a/library/error.c b/library/error.c
index ecdec78..893de7f 100644
--- a/library/error.c
+++ b/library/error.c
@@ -843,6 +843,8 @@
mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
if( use_ret == -(MBEDTLS_ERR_PLATFORM_FAULT_DETECTED) )
mbedtls_snprintf( buf, buflen, "PLATFORM - A hardware fault was detected in a critical path. As a security precaution this should be treated as a potential physical attack" );
+ if( use_ret == -(MBEDTLS_ERR_PLATFORM_ALLOC_FAILED) )
+ mbedtls_snprintf( buf, buflen, "PLATFORM - Memory allocation failed" );
#endif /* MBEDTLS_PLATFORM_C */
#if defined(MBEDTLS_POLY1305_C)
diff --git a/library/nist_kw.c b/library/nist_kw.c
index 5b5aa1c..2f7f082 100644
--- a/library/nist_kw.c
+++ b/library/nist_kw.c
@@ -222,9 +222,10 @@
}
mbedtls_platform_memcpy( output, NIST_KW_ICV1, KW_SEMIBLOCK_LENGTH );
- if( 0 != mbedtls_platform_memmove( output + KW_SEMIBLOCK_LENGTH, input, in_len ) )
+ ret = mbedtls_platform_memmove( output + KW_SEMIBLOCK_LENGTH, input, in_len );
+ if( ret != 0 )
{
- return MBEDTLS_ERR_CIPHER_ALLOC_FAILED;
+ return ret;
}
}
else
@@ -346,10 +347,11 @@
}
mbedtls_platform_memcpy( A, input, KW_SEMIBLOCK_LENGTH );
- if( 0 != mbedtls_platform_memmove( output, input + KW_SEMIBLOCK_LENGTH,
- ( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH ) )
+ ret = mbedtls_platform_memmove( output, input + KW_SEMIBLOCK_LENGTH,
+ ( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH );
+ if( ret != 0 )
{
- return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
+ return ret;
}
/* Calculate intermediate values */
diff --git a/library/pk.c b/library/pk.c
index f2df7db..cf4cfbb 100644
--- a/library/pk.c
+++ b/library/pk.c
@@ -623,15 +623,17 @@
size_t n_len )
{
size_t len = 0;
+ int ret = MBEDTLS_ERR_PLATFORM_FAULT_DETECTED;
if( (size_t)( *p - start ) < n_len )
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
len = n_len;
*p -= len;
- if( 0 != mbedtls_platform_memmove( *p, start, len ) )
+ ret = mbedtls_platform_memmove( *p, start, len );
+ if( ret != 0 )
{
- return( MBEDTLS_ERR_PK_ALLOC_FAILED );
+ return( ret );
}
/* ASN.1 DER encoding requires minimal length, so skip leading 0s.
@@ -694,11 +696,11 @@
*--p = MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE;
len += 2;
- if( 0 != mbedtls_platform_memmove( sig, p, len ) )
+ ret = mbedtls_platform_memmove( sig, p, len );
+ if( ret != 0 )
{
- return( MBEDTLS_ERR_PK_ALLOC_FAILED );
+ return( ret );
}
- ret = 0;
*sig_len = len;
return( ret );
diff --git a/library/platform_util.c b/library/platform_util.c
index 694e23a..17913b4 100644
--- a/library/platform_util.c
+++ b/library/platform_util.c
@@ -141,7 +141,7 @@
return 0;
}
- return -1;
+ return MBEDTLS_ERR_PLATFORM_ALLOC_FAILED;
}
int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num )