1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-28 00:21:48 +03:00

Add a set of I/O functions for the modulus structure

Signed-off-by: Gabor Mezei <gabor.mezei@arm.com>
This commit is contained in:
Gabor Mezei
2022-07-18 23:13:13 +02:00
committed by Janos Follath
parent b903070cec
commit c5328cf9a6
3 changed files with 84 additions and 0 deletions

View File

@ -28,6 +28,7 @@
#include "mbedtls/bignum.h"
#include "bignum_core.h"
#include "bignum_mod.h"
#include "bignum_mod_raw.h"
#define MPI_VALIDATE_RET( cond ) \
MBEDTLS_INTERNAL_VALIDATE_RET( cond, MBEDTLS_ERR_MPI_BAD_INPUT_DATA )
@ -407,4 +408,38 @@ int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *X,
return( 0 );
}
int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
mbedtls_mpi_mod_modulus *m,
unsigned char *buf,
size_t buflen )
{
if( m->ext_rep & MBEDTLS_MI_MOD_EXT_REP_LE )
return mbedtls_mpi_core_read_le( X, m->n, buf, buflen );
else if( m->ext_rep & MBEDTLS_MI_MOD_EXT_REP_BE )
return mbedtls_mpi_core_read_be( X, m->n, buf, buflen );
else
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
return( 0 );
}
int mbedtls_mpi_mod_raw_write( mbedtls_mpi_uint *X,
mbedtls_mpi_mod_modulus *m,
unsigned char *buf,
size_t buflen )
{
if( m->ext_rep & MBEDTLS_MI_MOD_EXT_REP_LE )
return mbedtls_mpi_core_write_le( X, m->n, buf, buflen );
else if( m->ext_rep & MBEDTLS_MI_MOD_EXT_REP_BE )
return mbedtls_mpi_core_write_be( X, m->n, buf, buflen );
else
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
return( 0 );
}
#endif /* MBEDTLS_BIGNUM_C */