mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-07-29 11:41:15 +03:00
bignum_mod_raw: Renamed m
-> N in mbedtls_mpi_mod_raw_neg()
Signed-off-by: Mihir Raj Singh <mihirrajsingh123@gmail.com>
This commit is contained in:
@ -34,10 +34,10 @@
|
|||||||
#include "bignum_mod_raw.h"
|
#include "bignum_mod_raw.h"
|
||||||
#include "constant_time_internal.h"
|
#include "constant_time_internal.h"
|
||||||
|
|
||||||
int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r,
|
int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
mbedtls_mpi_uint *p,
|
mbedtls_mpi_uint *p,
|
||||||
size_t p_limbs )
|
size_t p_limbs)
|
||||||
{
|
{
|
||||||
if (p_limbs != N->limbs || !mbedtls_mpi_core_lt_ct(p, N->p, N->limbs)) {
|
if (p_limbs != N->limbs || !mbedtls_mpi_core_lt_ct(p, N->p, N->limbs)) {
|
||||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||||
@ -59,7 +59,7 @@ void mbedtls_mpi_mod_residue_release(mbedtls_mpi_mod_residue *r)
|
|||||||
r->p = NULL;
|
r->p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *N )
|
void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *N)
|
||||||
{
|
{
|
||||||
if (N == NULL) {
|
if (N == NULL) {
|
||||||
return;
|
return;
|
||||||
@ -71,26 +71,24 @@ void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *N )
|
|||||||
N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
|
N->int_rep = MBEDTLS_MPI_MOD_REP_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *N )
|
void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *N)
|
||||||
{
|
{
|
||||||
if (N == NULL) {
|
if (N == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch( N->int_rep )
|
switch (N->int_rep) {
|
||||||
{
|
|
||||||
case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
|
case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
|
||||||
if (N->rep.mont.rr != NULL)
|
if (N->rep.mont.rr != NULL) {
|
||||||
{
|
mbedtls_platform_zeroize((mbedtls_mpi_uint *) N->rep.mont.rr,
|
||||||
mbedtls_platform_zeroize( (mbedtls_mpi_uint *) N->rep.mont.rr,
|
N->limbs * sizeof(mbedtls_mpi_uint));
|
||||||
N->limbs * sizeof(mbedtls_mpi_uint) );
|
mbedtls_free((mbedtls_mpi_uint *) N->rep.mont.rr);
|
||||||
mbedtls_free( (mbedtls_mpi_uint *)N->rep.mont.rr );
|
|
||||||
N->rep.mont.rr = NULL;
|
N->rep.mont.rr = NULL;
|
||||||
}
|
}
|
||||||
N->rep.mont.mm = 0;
|
N->rep.mont.mm = 0;
|
||||||
break;
|
break;
|
||||||
case MBEDTLS_MPI_MOD_REP_OPT_RED:
|
case MBEDTLS_MPI_MOD_REP_OPT_RED:
|
||||||
mbedtls_free( N->rep.ored );
|
mbedtls_free(N->rep.ored);
|
||||||
break;
|
break;
|
||||||
case MBEDTLS_MPI_MOD_REP_INVALID:
|
case MBEDTLS_MPI_MOD_REP_INVALID:
|
||||||
break;
|
break;
|
||||||
@ -138,22 +136,22 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *N,
|
int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
|
||||||
const mbedtls_mpi_uint *p,
|
const mbedtls_mpi_uint *p,
|
||||||
size_t p_limbs,
|
size_t p_limbs,
|
||||||
mbedtls_mpi_mod_rep_selector int_rep )
|
mbedtls_mpi_mod_rep_selector int_rep)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
N->p = p;
|
N->p = p;
|
||||||
N->limbs = p_limbs;
|
N->limbs = p_limbs;
|
||||||
N->bits = mbedtls_mpi_core_bitlen( p, p_limbs );
|
N->bits = mbedtls_mpi_core_bitlen(p, p_limbs);
|
||||||
|
|
||||||
switch (int_rep) {
|
switch (int_rep) {
|
||||||
case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
|
case MBEDTLS_MPI_MOD_REP_MONTGOMERY:
|
||||||
N->int_rep = int_rep;
|
N->int_rep = int_rep;
|
||||||
N->rep.mont.mm = mbedtls_mpi_core_montmul_init( N->p );
|
N->rep.mont.mm = mbedtls_mpi_core_montmul_init(N->p);
|
||||||
ret = set_mont_const_square( &N->rep.mont.rr, N->p, N->limbs );
|
ret = set_mont_const_square(&N->rep.mont.rr, N->p, N->limbs);
|
||||||
break;
|
break;
|
||||||
case MBEDTLS_MPI_MOD_REP_OPT_RED:
|
case MBEDTLS_MPI_MOD_REP_OPT_RED:
|
||||||
N->int_rep = int_rep;
|
N->int_rep = int_rep;
|
||||||
@ -166,9 +164,8 @@ int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *N,
|
|||||||
|
|
||||||
exit:
|
exit:
|
||||||
|
|
||||||
if( ret != 0 )
|
if (ret != 0) {
|
||||||
{
|
mbedtls_mpi_mod_modulus_free(N);
|
||||||
mbedtls_mpi_mod_modulus_free( N );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
@ -351,11 +348,11 @@ int mbedtls_mpi_mod_random(mbedtls_mpi_mod_residue *X,
|
|||||||
/* END MERGE SLOT 6 */
|
/* END MERGE SLOT 6 */
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 7 */
|
/* BEGIN MERGE SLOT 7 */
|
||||||
int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
|
int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
const unsigned char *buf,
|
const unsigned char *buf,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep )
|
mbedtls_mpi_mod_ext_rep ext_rep)
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||||
|
|
||||||
@ -374,17 +371,17 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
|
|||||||
|
|
||||||
r->limbs = N->limbs;
|
r->limbs = N->limbs;
|
||||||
|
|
||||||
ret = mbedtls_mpi_mod_raw_canonical_to_modulus_rep( r->p, N );
|
ret = mbedtls_mpi_mod_raw_canonical_to_modulus_rep(r->p, N);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
|
int mbedtls_mpi_mod_write(const mbedtls_mpi_mod_residue *r,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
unsigned char *buf,
|
unsigned char *buf,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep )
|
mbedtls_mpi_mod_ext_rep ext_rep)
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
int ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||||
|
|
||||||
@ -403,10 +400,9 @@ int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mbedtls_mpi_mod_raw_write( r->p, N, buf, buflen, ext_rep );
|
ret = mbedtls_mpi_mod_raw_write(r->p, N, buf, buflen, ext_rep);
|
||||||
|
|
||||||
if( N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY )
|
if (N->int_rep == MBEDTLS_MPI_MOD_REP_MONTGOMERY) {
|
||||||
{
|
|
||||||
/* If this fails, the value of r is corrupted and we want to return
|
/* If this fails, the value of r is corrupted and we want to return
|
||||||
* this error (as opposed to the error code from the write above) to
|
* this error (as opposed to the error code from the write above) to
|
||||||
* let the caller know. If it succeeds, we want to return the error
|
* let the caller know. If it succeeds, we want to return the error
|
||||||
|
@ -166,10 +166,10 @@ typedef struct {
|
|||||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p p_limbs is less than the
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p p_limbs is less than the
|
||||||
* limbs in \p N or if \p p is not less than \p N.
|
* limbs in \p N or if \p p is not less than \p N.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_residue_setup( mbedtls_mpi_mod_residue *r,
|
int mbedtls_mpi_mod_residue_setup(mbedtls_mpi_mod_residue *r,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
mbedtls_mpi_uint *p,
|
mbedtls_mpi_uint *p,
|
||||||
size_t p_limbs );
|
size_t p_limbs);
|
||||||
|
|
||||||
/** Unbind elements of a residue structure.
|
/** Unbind elements of a residue structure.
|
||||||
*
|
*
|
||||||
@ -187,7 +187,7 @@ void mbedtls_mpi_mod_residue_release(mbedtls_mpi_mod_residue *r);
|
|||||||
*
|
*
|
||||||
* \param[out] N The address of the modulus structure to initialize.
|
* \param[out] N The address of the modulus structure to initialize.
|
||||||
*/
|
*/
|
||||||
void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *N );
|
void mbedtls_mpi_mod_modulus_init(mbedtls_mpi_mod_modulus *N);
|
||||||
|
|
||||||
/** Setup a modulus structure.
|
/** Setup a modulus structure.
|
||||||
*
|
*
|
||||||
@ -203,10 +203,10 @@ void mbedtls_mpi_mod_modulus_init( mbedtls_mpi_mod_modulus *N );
|
|||||||
* \return \c 0 if successful.
|
* \return \c 0 if successful.
|
||||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p int_rep is invalid.
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p int_rep is invalid.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *N,
|
int mbedtls_mpi_mod_modulus_setup(mbedtls_mpi_mod_modulus *N,
|
||||||
const mbedtls_mpi_uint *p,
|
const mbedtls_mpi_uint *p,
|
||||||
size_t p_limbs,
|
size_t p_limbs,
|
||||||
mbedtls_mpi_mod_rep_selector int_rep );
|
mbedtls_mpi_mod_rep_selector int_rep);
|
||||||
|
|
||||||
/** Free elements of a modulus structure.
|
/** Free elements of a modulus structure.
|
||||||
*
|
*
|
||||||
@ -218,7 +218,7 @@ int mbedtls_mpi_mod_modulus_setup( mbedtls_mpi_mod_modulus *N,
|
|||||||
*
|
*
|
||||||
* \param[in,out] N The address of the modulus structure to free.
|
* \param[in,out] N The address of the modulus structure to free.
|
||||||
*/
|
*/
|
||||||
void mbedtls_mpi_mod_modulus_free( mbedtls_mpi_mod_modulus *N );
|
void mbedtls_mpi_mod_modulus_free(mbedtls_mpi_mod_modulus *N);
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 1 */
|
/* BEGIN MERGE SLOT 1 */
|
||||||
|
|
||||||
@ -421,11 +421,11 @@ int mbedtls_mpi_mod_random(mbedtls_mpi_mod_residue *X,
|
|||||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p ext_rep
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if \p ext_rep
|
||||||
* is invalid or the value in the buffer is not less than \p N.
|
* is invalid or the value in the buffer is not less than \p N.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
|
int mbedtls_mpi_mod_read(mbedtls_mpi_mod_residue *r,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
const unsigned char *buf,
|
const unsigned char *buf,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep );
|
mbedtls_mpi_mod_ext_rep ext_rep);
|
||||||
|
|
||||||
/** Write a residue into a byte buffer.
|
/** Write a residue into a byte buffer.
|
||||||
*
|
*
|
||||||
@ -459,11 +459,11 @@ int mbedtls_mpi_mod_read( mbedtls_mpi_mod_residue *r,
|
|||||||
* memory for conversion. Can occur only for moduli with
|
* memory for conversion. Can occur only for moduli with
|
||||||
* MBEDTLS_MPI_MOD_REP_MONTGOMERY.
|
* MBEDTLS_MPI_MOD_REP_MONTGOMERY.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_write( const mbedtls_mpi_mod_residue *r,
|
int mbedtls_mpi_mod_write(const mbedtls_mpi_mod_residue *r,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
unsigned char *buf,
|
unsigned char *buf,
|
||||||
size_t buflen,
|
size_t buflen,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep );
|
mbedtls_mpi_mod_ext_rep ext_rep);
|
||||||
/* END MERGE SLOT 7 */
|
/* END MERGE SLOT 7 */
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 8 */
|
/* BEGIN MERGE SLOT 8 */
|
||||||
|
@ -49,22 +49,22 @@ void mbedtls_mpi_mod_raw_cond_swap(mbedtls_mpi_uint *X,
|
|||||||
mbedtls_mpi_core_cond_swap(X, Y, N->limbs, swap);
|
mbedtls_mpi_core_cond_swap(X, Y, N->limbs, swap);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
|
int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep )
|
mbedtls_mpi_mod_ext_rep ext_rep)
|
||||||
{
|
{
|
||||||
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
|
||||||
|
|
||||||
switch (ext_rep) {
|
switch (ext_rep) {
|
||||||
case MBEDTLS_MPI_MOD_EXT_REP_LE:
|
case MBEDTLS_MPI_MOD_EXT_REP_LE:
|
||||||
ret = mbedtls_mpi_core_read_le( X, N->limbs,
|
ret = mbedtls_mpi_core_read_le(X, N->limbs,
|
||||||
input, input_length );
|
input, input_length);
|
||||||
break;
|
break;
|
||||||
case MBEDTLS_MPI_MOD_EXT_REP_BE:
|
case MBEDTLS_MPI_MOD_EXT_REP_BE:
|
||||||
ret = mbedtls_mpi_core_read_be( X, N->limbs,
|
ret = mbedtls_mpi_core_read_be(X, N->limbs,
|
||||||
input, input_length );
|
input, input_length);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||||
@ -74,8 +74,7 @@ int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !mbedtls_mpi_core_lt_ct( X, N->p, N->limbs ) )
|
if (!mbedtls_mpi_core_lt_ct(X, N->p, N->limbs)) {
|
||||||
{
|
|
||||||
ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
ret = MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -85,19 +84,19 @@ cleanup:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A,
|
int mbedtls_mpi_mod_raw_write(const mbedtls_mpi_uint *A,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
unsigned char *output,
|
unsigned char *output,
|
||||||
size_t output_length,
|
size_t output_length,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep )
|
mbedtls_mpi_mod_ext_rep ext_rep)
|
||||||
{
|
{
|
||||||
switch (ext_rep) {
|
switch (ext_rep) {
|
||||||
case MBEDTLS_MPI_MOD_EXT_REP_LE:
|
case MBEDTLS_MPI_MOD_EXT_REP_LE:
|
||||||
return( mbedtls_mpi_core_write_le( A, N->limbs,
|
return mbedtls_mpi_core_write_le(A, N->limbs,
|
||||||
output, output_length ) );
|
output, output_length);
|
||||||
case MBEDTLS_MPI_MOD_EXT_REP_BE:
|
case MBEDTLS_MPI_MOD_EXT_REP_BE:
|
||||||
return( mbedtls_mpi_core_write_be( A, N->limbs,
|
return mbedtls_mpi_core_write_be(A, N->limbs,
|
||||||
output, output_length ) );
|
output, output_length);
|
||||||
default:
|
default:
|
||||||
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
return MBEDTLS_ERR_MPI_BAD_INPUT_DATA;
|
||||||
}
|
}
|
||||||
@ -229,35 +228,35 @@ int mbedtls_mpi_mod_raw_random(mbedtls_mpi_uint *X,
|
|||||||
/* END MERGE SLOT 6 */
|
/* END MERGE SLOT 6 */
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 7 */
|
/* BEGIN MERGE SLOT 7 */
|
||||||
int mbedtls_mpi_mod_raw_to_mont_rep( mbedtls_mpi_uint *X,
|
int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_mod_modulus *N )
|
const mbedtls_mpi_mod_modulus *N)
|
||||||
{
|
{
|
||||||
mbedtls_mpi_uint *T;
|
mbedtls_mpi_uint *T;
|
||||||
const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs( N->limbs );
|
const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs(N->limbs);
|
||||||
|
|
||||||
if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) {
|
if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) {
|
||||||
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_mpi_core_to_mont_rep( X, X, N->p, N->limbs,
|
mbedtls_mpi_core_to_mont_rep(X, X, N->p, N->limbs,
|
||||||
N->rep.mont.mm, N->rep.mont.rr, T );
|
N->rep.mont.mm, N->rep.mont.rr, T);
|
||||||
|
|
||||||
mbedtls_platform_zeroize(T, t_limbs * ciL);
|
mbedtls_platform_zeroize(T, t_limbs * ciL);
|
||||||
mbedtls_free(T);
|
mbedtls_free(T);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mbedtls_mpi_mod_raw_from_mont_rep( mbedtls_mpi_uint *X,
|
int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_mod_modulus *N )
|
const mbedtls_mpi_mod_modulus *N)
|
||||||
{
|
{
|
||||||
const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs( N->limbs );
|
const size_t t_limbs = mbedtls_mpi_core_montmul_working_limbs(N->limbs);
|
||||||
mbedtls_mpi_uint *T;
|
mbedtls_mpi_uint *T;
|
||||||
|
|
||||||
if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) {
|
if ((T = (mbedtls_mpi_uint *) mbedtls_calloc(t_limbs, ciL)) == NULL) {
|
||||||
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
return MBEDTLS_ERR_MPI_ALLOC_FAILED;
|
||||||
}
|
}
|
||||||
|
|
||||||
mbedtls_mpi_core_from_mont_rep( X, X, N->p, N->limbs, N->rep.mont.mm, T );
|
mbedtls_mpi_core_from_mont_rep(X, X, N->p, N->limbs, N->rep.mont.mm, T);
|
||||||
|
|
||||||
mbedtls_platform_zeroize(T, t_limbs * ciL);
|
mbedtls_platform_zeroize(T, t_limbs * ciL);
|
||||||
mbedtls_free(T);
|
mbedtls_free(T);
|
||||||
@ -266,14 +265,14 @@ int mbedtls_mpi_mod_raw_from_mont_rep( mbedtls_mpi_uint *X,
|
|||||||
|
|
||||||
void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X,
|
void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_uint *A,
|
const mbedtls_mpi_uint *A,
|
||||||
const mbedtls_mpi_mod_modulus *m)
|
const mbedtls_mpi_mod_modulus *N)
|
||||||
{
|
{
|
||||||
mbedtls_mpi_core_sub(X, m->p, A, m->limbs);
|
mbedtls_mpi_core_sub(X, N->p, A, N->limbs);
|
||||||
|
|
||||||
/* If A=0 initially, then X=N now. Detect this by
|
/* If A=0 initially, then X=N now. Detect this by
|
||||||
* subtracting N and catching the carry. */
|
* subtracting N and catching the carry. */
|
||||||
mbedtls_mpi_uint borrow = mbedtls_mpi_core_sub(X, X, m->p, m->limbs);
|
mbedtls_mpi_uint borrow = mbedtls_mpi_core_sub(X, X, N->p, N->limbs);
|
||||||
(void) mbedtls_mpi_core_add_if(X, m->p, m->limbs, (unsigned) borrow);
|
(void) mbedtls_mpi_core_add_if(X, N->p, N->limbs, (unsigned) borrow);
|
||||||
}
|
}
|
||||||
/* END MERGE SLOT 7 */
|
/* END MERGE SLOT 7 */
|
||||||
|
|
||||||
|
@ -159,11 +159,11 @@ void mbedtls_mpi_mod_raw_cond_swap(mbedtls_mpi_uint *X,
|
|||||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
|
||||||
* of \p N is invalid or \p X is not less than \p N.
|
* of \p N is invalid or \p X is not less than \p N.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
|
int mbedtls_mpi_mod_raw_read(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
const unsigned char *input,
|
const unsigned char *input,
|
||||||
size_t input_length,
|
size_t input_length,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep );
|
mbedtls_mpi_mod_ext_rep ext_rep);
|
||||||
|
|
||||||
/** Export A into unsigned binary data.
|
/** Export A into unsigned binary data.
|
||||||
*
|
*
|
||||||
@ -181,11 +181,11 @@ int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
|
|||||||
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
|
||||||
* of \p N is invalid.
|
* of \p N is invalid.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A,
|
int mbedtls_mpi_mod_raw_write(const mbedtls_mpi_uint *A,
|
||||||
const mbedtls_mpi_mod_modulus *N,
|
const mbedtls_mpi_mod_modulus *N,
|
||||||
unsigned char *output,
|
unsigned char *output,
|
||||||
size_t output_length,
|
size_t output_length,
|
||||||
mbedtls_mpi_mod_ext_rep ext_rep );
|
mbedtls_mpi_mod_ext_rep ext_rep);
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 1 */
|
/* BEGIN MERGE SLOT 1 */
|
||||||
|
|
||||||
@ -416,8 +416,8 @@ int mbedtls_mpi_mod_raw_random(mbedtls_mpi_uint *X,
|
|||||||
*
|
*
|
||||||
* \return \c 0 if successful.
|
* \return \c 0 if successful.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_raw_to_mont_rep( mbedtls_mpi_uint *X,
|
int mbedtls_mpi_mod_raw_to_mont_rep(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_mod_modulus *N );
|
const mbedtls_mpi_mod_modulus *N);
|
||||||
|
|
||||||
/** Convert an MPI back from Montgomery representation.
|
/** Convert an MPI back from Montgomery representation.
|
||||||
*
|
*
|
||||||
@ -428,25 +428,25 @@ int mbedtls_mpi_mod_raw_to_mont_rep( mbedtls_mpi_uint *X,
|
|||||||
*
|
*
|
||||||
* \return \c 0 if successful.
|
* \return \c 0 if successful.
|
||||||
*/
|
*/
|
||||||
int mbedtls_mpi_mod_raw_from_mont_rep( mbedtls_mpi_uint *X,
|
int mbedtls_mpi_mod_raw_from_mont_rep(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_mod_modulus *N );
|
const mbedtls_mpi_mod_modulus *N);
|
||||||
|
|
||||||
/** \brief Perform fixed width modular negation.
|
/** \brief Perform fixed width modular negation.
|
||||||
*
|
*
|
||||||
* The size of the operation is determined by \p m. \p A must have
|
* The size of the operation is determined by \p N. \p A must have
|
||||||
* the same number of limbs as \p m.
|
* the same number of limbs as \p N.
|
||||||
*
|
*
|
||||||
* \p X may be aliased to \p A.
|
* \p X may be aliased to \p A.
|
||||||
*
|
*
|
||||||
* \param[out] X The result of the modular negation.
|
* \param[out] X The result of the modular negation.
|
||||||
* This must be initialized.
|
* This must be initialized.
|
||||||
* \param[in] A Little-endian presentation of the input operand. This
|
* \param[in] A Little-endian presentation of the input operand. This
|
||||||
* must be less than or equal to \p m.
|
* must be less than or equal to \p N.
|
||||||
* \param[in] m The modulus to use.
|
* \param[in] N The modulus to use.
|
||||||
*/
|
*/
|
||||||
void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X,
|
void mbedtls_mpi_mod_raw_neg(mbedtls_mpi_uint *X,
|
||||||
const mbedtls_mpi_uint *A,
|
const mbedtls_mpi_uint *A,
|
||||||
const mbedtls_mpi_mod_modulus *m);
|
const mbedtls_mpi_mod_modulus *N);
|
||||||
/* END MERGE SLOT 7 */
|
/* END MERGE SLOT 7 */
|
||||||
|
|
||||||
/* BEGIN MERGE SLOT 8 */
|
/* BEGIN MERGE SLOT 8 */
|
||||||
|
Reference in New Issue
Block a user