mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-29 08:04:24 +01:00
Add new error code PLATFORM_ALLOC_FAILED for mbedtls_platform_memmove()
Signed-off-by: Piotr Nowicki <piotr.nowicki@arm.com>
This commit is contained in:
parent
5d5841f450
commit
ce0aab4474
@ -86,7 +86,7 @@
|
|||||||
* CHACHA20 3 0x0051-0x0055
|
* CHACHA20 3 0x0051-0x0055
|
||||||
* POLY1305 3 0x0057-0x005B
|
* POLY1305 3 0x0057-0x005B
|
||||||
* CHACHAPOLY 2 0x0054-0x0056
|
* CHACHAPOLY 2 0x0054-0x0056
|
||||||
* PLATFORM 3 0x0070-0x0072 0x0071-0x0071
|
* PLATFORM 4 0x0070-0x0072 0x0071-0x0071 0x0076-0x0076
|
||||||
*
|
*
|
||||||
* High-level module nr (3 bits - 0x0...-0x7...)
|
* High-level module nr (3 bits - 0x0...-0x7...)
|
||||||
* Name ID Nr of Errors
|
* Name ID Nr of Errors
|
||||||
|
@ -133,6 +133,7 @@ void mbedtls_nist_kw_free( mbedtls_nist_kw_context *ctx );
|
|||||||
*
|
*
|
||||||
* \return \c 0 on success.
|
* \return \c 0 on success.
|
||||||
* \return \c MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA for invalid input length.
|
* \return \c MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA for invalid input length.
|
||||||
|
* \return \c MBEDTLS_ERR_PLATFORM_ALLOC_FAILED in case of a memory allocation failure.
|
||||||
* \return cipher-specific error code on failure of the underlying cipher.
|
* \return cipher-specific error code on failure of the underlying cipher.
|
||||||
*/
|
*/
|
||||||
int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode,
|
int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx, mbedtls_nist_kw_mode_t mode,
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */
|
#define MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED -0x0070 /**< Hardware accelerator failed */
|
||||||
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */
|
#define MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED -0x0072 /**< The requested feature is not supported by the platform */
|
||||||
#define MBEDTLS_ERR_PLATFORM_FAULT_DETECTED -0x0071 /**< A hardware fault was detected in a critical path. As a security precaution this should be treated as a potential physical attack */
|
#define MBEDTLS_ERR_PLATFORM_FAULT_DETECTED -0x0071 /**< A hardware fault was detected in a critical path. As a security precaution this should be treated as a potential physical attack */
|
||||||
|
#define MBEDTLS_ERR_PLATFORM_ALLOC_FAILED -0x0076 /**< Memory allocation failed */
|
||||||
|
|
||||||
#if defined(MBEDTLS_PLATFORM_C)
|
#if defined(MBEDTLS_PLATFORM_C)
|
||||||
|
|
||||||
|
@ -209,8 +209,8 @@ void *mbedtls_platform_memcpy( void *dst, const void *src, size_t num );
|
|||||||
* \param src Source buffer where the data is being moved from.
|
* \param src Source buffer where the data is being moved from.
|
||||||
* \param num The length of the buffers in bytes.
|
* \param num The length of the buffers in bytes.
|
||||||
*
|
*
|
||||||
* \return 0 if the operation was successful or -1 if memory allocation
|
* \return 0 if the operation was successful
|
||||||
* failed.
|
* \return #MBEDTLS_ERR_PLATFORM_ALLOC_FAILED if a memory allocation failed
|
||||||
*/
|
*/
|
||||||
int mbedtls_platform_memmove( void *dst, const void *src, size_t num );
|
int mbedtls_platform_memmove( void *dst, const void *src, size_t num );
|
||||||
|
|
||||||
|
@ -558,11 +558,7 @@ static int mpi_write_hlp( mbedtls_mpi *X, int radix,
|
|||||||
length++;
|
length++;
|
||||||
} while( mbedtls_mpi_cmp_int( X, 0 ) != 0 );
|
} while( mbedtls_mpi_cmp_int( X, 0 ) != 0 );
|
||||||
|
|
||||||
if( 0 != mbedtls_platform_memmove( *p, p_end, length ) )
|
MBEDTLS_MPI_CHK( mbedtls_platform_memmove( *p, p_end, length ) );
|
||||||
{
|
|
||||||
ret = MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
*p += length;
|
*p += length;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
|
@ -843,6 +843,8 @@ void mbedtls_strerror( int ret, char *buf, size_t buflen )
|
|||||||
mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
|
mbedtls_snprintf( buf, buflen, "PLATFORM - The requested feature is not supported by the platform" );
|
||||||
if( use_ret == -(MBEDTLS_ERR_PLATFORM_FAULT_DETECTED) )
|
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" );
|
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 */
|
#endif /* MBEDTLS_PLATFORM_C */
|
||||||
|
|
||||||
#if defined(MBEDTLS_POLY1305_C)
|
#if defined(MBEDTLS_POLY1305_C)
|
||||||
|
@ -222,9 +222,10 @@ int mbedtls_nist_kw_wrap( mbedtls_nist_kw_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_platform_memcpy( output, NIST_KW_ICV1, KW_SEMIBLOCK_LENGTH );
|
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
|
else
|
||||||
@ -346,10 +347,11 @@ static int unwrap( mbedtls_nist_kw_context *ctx,
|
|||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_platform_memcpy( A, input, KW_SEMIBLOCK_LENGTH );
|
mbedtls_platform_memcpy( A, input, KW_SEMIBLOCK_LENGTH );
|
||||||
if( 0 != mbedtls_platform_memmove( output, input + KW_SEMIBLOCK_LENGTH,
|
ret = mbedtls_platform_memmove( output, input + KW_SEMIBLOCK_LENGTH,
|
||||||
( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH ) )
|
( semiblocks - 1 ) * KW_SEMIBLOCK_LENGTH );
|
||||||
|
if( ret != 0 )
|
||||||
{
|
{
|
||||||
return( MBEDTLS_ERR_CIPHER_ALLOC_FAILED );
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate intermediate values */
|
/* Calculate intermediate values */
|
||||||
|
12
library/pk.c
12
library/pk.c
@ -623,15 +623,17 @@ static int asn1_write_mpibuf( unsigned char **p, unsigned char *start,
|
|||||||
size_t n_len )
|
size_t n_len )
|
||||||
{
|
{
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
int ret = MBEDTLS_ERR_PLATFORM_FAULT_DETECTED;
|
||||||
|
|
||||||
if( (size_t)( *p - start ) < n_len )
|
if( (size_t)( *p - start ) < n_len )
|
||||||
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
return( MBEDTLS_ERR_ASN1_BUF_TOO_SMALL );
|
||||||
|
|
||||||
len = n_len;
|
len = n_len;
|
||||||
*p -= 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.
|
/* ASN.1 DER encoding requires minimal length, so skip leading 0s.
|
||||||
@ -694,11 +696,11 @@ static int pk_ecdsa_sig_asn1_from_uecc( unsigned char *sig, size_t *sig_len,
|
|||||||
*--p = MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE;
|
*--p = MBEDTLS_ASN1_CONSTRUCTED | MBEDTLS_ASN1_SEQUENCE;
|
||||||
len += 2;
|
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;
|
*sig_len = len;
|
||||||
|
|
||||||
return( ret );
|
return( ret );
|
||||||
|
@ -141,7 +141,7 @@ int mbedtls_platform_memmove( void *dst, const void *src, size_t num )
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return MBEDTLS_ERR_PLATFORM_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num )
|
int mbedtls_platform_memcmp( const void *buf1, const void *buf2, size_t num )
|
||||||
|
Loading…
Reference in New Issue
Block a user