mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-03-28 19:21:08 +00:00
New helper function to allocate and read a modulus
When including <test/bignum_helpers.h>, the library/ directory now needs to be on the include path. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
881447d411
commit
195f998107
@ -30,6 +30,7 @@
|
|||||||
#if defined(MBEDTLS_BIGNUM_C)
|
#if defined(MBEDTLS_BIGNUM_C)
|
||||||
|
|
||||||
#include <mbedtls/bignum.h>
|
#include <mbedtls/bignum.h>
|
||||||
|
#include <bignum_mod.h>
|
||||||
|
|
||||||
/** Allocate and populate a core MPI from a test case argument.
|
/** Allocate and populate a core MPI from a test case argument.
|
||||||
*
|
*
|
||||||
@ -54,6 +55,25 @@
|
|||||||
int mbedtls_test_read_mpi_core( mbedtls_mpi_uint **pX, size_t *plimbs,
|
int mbedtls_test_read_mpi_core( mbedtls_mpi_uint **pX, size_t *plimbs,
|
||||||
const char *input );
|
const char *input );
|
||||||
|
|
||||||
|
/** Read a modulus from a hexadecimal string.
|
||||||
|
*
|
||||||
|
* This function allocates exactly as many limbs as necessary to fit
|
||||||
|
* the length of the input. In other words, it preserves leading zeros.
|
||||||
|
*
|
||||||
|
* The limb array is allocated with mbedtls_calloc() and must later be
|
||||||
|
* freed with mbedtls_free().
|
||||||
|
*
|
||||||
|
* \param[in,out] N A modulus structure. It must be initialized, but
|
||||||
|
* not set up.
|
||||||
|
* \param[in] s The null-terminated hexadecimal string to read from.
|
||||||
|
* \param int_rep The desired representation of residues.
|
||||||
|
*
|
||||||
|
* \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise.
|
||||||
|
*/
|
||||||
|
int mbedtls_test_read_mpi_modulus( mbedtls_mpi_mod_modulus *N,
|
||||||
|
const char *s,
|
||||||
|
mbedtls_mpi_mod_rep_selector int_rep );
|
||||||
|
|
||||||
/** Read an MPI from a hexadecimal string.
|
/** Read an MPI from a hexadecimal string.
|
||||||
*
|
*
|
||||||
* Like mbedtls_mpi_read_string(), but with tighter guarantees around
|
* Like mbedtls_mpi_read_string(), but with tighter guarantees around
|
||||||
|
@ -85,6 +85,23 @@ exit:
|
|||||||
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int mbedtls_test_read_mpi_modulus( mbedtls_mpi_mod_modulus *N,
|
||||||
|
const char *s,
|
||||||
|
mbedtls_mpi_mod_rep_selector int_rep )
|
||||||
|
{
|
||||||
|
mbedtls_mpi_uint *p = NULL;
|
||||||
|
size_t limbs = 0;
|
||||||
|
if( N->limbs != 0 )
|
||||||
|
return( MBEDTLS_ERR_MPI_BAD_INPUT_DATA );
|
||||||
|
int ret = mbedtls_test_read_mpi_core( &p, &limbs, s );
|
||||||
|
if( ret != 0 )
|
||||||
|
return( ret );
|
||||||
|
ret = mbedtls_mpi_mod_modulus_setup( N, p, limbs, int_rep );
|
||||||
|
if( ret != 0 )
|
||||||
|
mbedtls_free( p );
|
||||||
|
return( ret );
|
||||||
|
}
|
||||||
|
|
||||||
int mbedtls_test_read_mpi( mbedtls_mpi *X, const char *s )
|
int mbedtls_test_read_mpi( mbedtls_mpi *X, const char *s )
|
||||||
{
|
{
|
||||||
int negative = 0;
|
int negative = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user