mirror of
				https://github.com/Mbed-TLS/mbedtls.git
				synced 2025-11-03 20:33:16 +03:00 
			
		
		
		
	Merge pull request #4779 from yutotakano/fix-reserved-identifier-clash-2.x
Backport 2.x: Replace reserved identifier clashes with suitable replacements
This commit is contained in:
		
							
								
								
									
										2
									
								
								ChangeLog.d/issue4630.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								ChangeLog.d/issue4630.txt
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					Bugfix
 | 
				
			||||||
 | 
					   * Stop using reserved identifiers as local variables. Fixes #4630.
 | 
				
			||||||
@@ -829,14 +829,14 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
 | 
				
			|||||||
 * \param E        The exponent MPI. This must point to an initialized MPI.
 | 
					 * \param E        The exponent MPI. This must point to an initialized MPI.
 | 
				
			||||||
 * \param N        The base for the modular reduction. This must point to an
 | 
					 * \param N        The base for the modular reduction. This must point to an
 | 
				
			||||||
 *                 initialized MPI.
 | 
					 *                 initialized MPI.
 | 
				
			||||||
 * \param _RR      A helper MPI depending solely on \p N which can be used to
 | 
					 * \param prec_RR  A helper MPI depending solely on \p N which can be used to
 | 
				
			||||||
 *                 speed-up multiple modular exponentiations for the same value
 | 
					 *                 speed-up multiple modular exponentiations for the same value
 | 
				
			||||||
 *                 of \p N. This may be \c NULL. If it is not \c NULL, it must
 | 
					 *                 of \p N. This may be \c NULL. If it is not \c NULL, it must
 | 
				
			||||||
 *                 point to an initialized MPI. If it hasn't been used after
 | 
					 *                 point to an initialized MPI. If it hasn't been used after
 | 
				
			||||||
 *                 the call to mbedtls_mpi_init(), this function will compute
 | 
					 *                 the call to mbedtls_mpi_init(), this function will compute
 | 
				
			||||||
 *                 the helper value and store it in \p _RR for reuse on
 | 
					 *                 the helper value and store it in \p prec_RR for reuse on
 | 
				
			||||||
 *                 subsequent calls to this function. Otherwise, the function
 | 
					 *                 subsequent calls to this function. Otherwise, the function
 | 
				
			||||||
 *                 will assume that \p _RR holds the helper value set by a
 | 
					 *                 will assume that \p prec_RR holds the helper value set by a
 | 
				
			||||||
 *                 previous call to mbedtls_mpi_exp_mod(), and reuse it.
 | 
					 *                 previous call to mbedtls_mpi_exp_mod(), and reuse it.
 | 
				
			||||||
 *
 | 
					 *
 | 
				
			||||||
 * \return         \c 0 if successful.
 | 
					 * \return         \c 0 if successful.
 | 
				
			||||||
@@ -848,7 +848,7 @@ int mbedtls_mpi_mod_int( mbedtls_mpi_uint *r, const mbedtls_mpi *A,
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
 | 
					int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
 | 
				
			||||||
                         const mbedtls_mpi *E, const mbedtls_mpi *N,
 | 
					                         const mbedtls_mpi *E, const mbedtls_mpi *N,
 | 
				
			||||||
                         mbedtls_mpi *_RR );
 | 
					                         mbedtls_mpi *prec_RR );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					/**
 | 
				
			||||||
 * \brief          Fill an MPI with a number of random bytes.
 | 
					 * \brief          Fill an MPI with a number of random bytes.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1587,17 +1587,17 @@ cleanup:
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b )
 | 
					int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    mbedtls_mpi _B;
 | 
					    mbedtls_mpi B;
 | 
				
			||||||
    mbedtls_mpi_uint p[1];
 | 
					    mbedtls_mpi_uint p[1];
 | 
				
			||||||
    MPI_VALIDATE_RET( X != NULL );
 | 
					    MPI_VALIDATE_RET( X != NULL );
 | 
				
			||||||
    MPI_VALIDATE_RET( A != NULL );
 | 
					    MPI_VALIDATE_RET( A != NULL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p[0] = ( b < 0 ) ? -b : b;
 | 
					    p[0] = ( b < 0 ) ? -b : b;
 | 
				
			||||||
    _B.s = ( b < 0 ) ? -1 : 1;
 | 
					    B.s = ( b < 0 ) ? -1 : 1;
 | 
				
			||||||
    _B.n = 1;
 | 
					    B.n = 1;
 | 
				
			||||||
    _B.p = p;
 | 
					    B.p = p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( mbedtls_mpi_add_mpi( X, A, &_B ) );
 | 
					    return( mbedtls_mpi_add_mpi( X, A, &B ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -1605,17 +1605,17 @@ int mbedtls_mpi_add_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b )
 | 
					int mbedtls_mpi_sub_int( mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    mbedtls_mpi _B;
 | 
					    mbedtls_mpi B;
 | 
				
			||||||
    mbedtls_mpi_uint p[1];
 | 
					    mbedtls_mpi_uint p[1];
 | 
				
			||||||
    MPI_VALIDATE_RET( X != NULL );
 | 
					    MPI_VALIDATE_RET( X != NULL );
 | 
				
			||||||
    MPI_VALIDATE_RET( A != NULL );
 | 
					    MPI_VALIDATE_RET( A != NULL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p[0] = ( b < 0 ) ? -b : b;
 | 
					    p[0] = ( b < 0 ) ? -b : b;
 | 
				
			||||||
    _B.s = ( b < 0 ) ? -1 : 1;
 | 
					    B.s = ( b < 0 ) ? -1 : 1;
 | 
				
			||||||
    _B.n = 1;
 | 
					    B.n = 1;
 | 
				
			||||||
    _B.p = p;
 | 
					    B.p = p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( mbedtls_mpi_sub_mpi( X, A, &_B ) );
 | 
					    return( mbedtls_mpi_sub_mpi( X, A, &B ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/** Helper for mbedtls_mpi multiplication.
 | 
					/** Helper for mbedtls_mpi multiplication.
 | 
				
			||||||
@@ -2027,16 +2027,16 @@ int mbedtls_mpi_div_int( mbedtls_mpi *Q, mbedtls_mpi *R,
 | 
				
			|||||||
                         const mbedtls_mpi *A,
 | 
					                         const mbedtls_mpi *A,
 | 
				
			||||||
                         mbedtls_mpi_sint b )
 | 
					                         mbedtls_mpi_sint b )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    mbedtls_mpi _B;
 | 
					    mbedtls_mpi B;
 | 
				
			||||||
    mbedtls_mpi_uint p[1];
 | 
					    mbedtls_mpi_uint p[1];
 | 
				
			||||||
    MPI_VALIDATE_RET( A != NULL );
 | 
					    MPI_VALIDATE_RET( A != NULL );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    p[0] = ( b < 0 ) ? -b : b;
 | 
					    p[0] = ( b < 0 ) ? -b : b;
 | 
				
			||||||
    _B.s = ( b < 0 ) ? -1 : 1;
 | 
					    B.s = ( b < 0 ) ? -1 : 1;
 | 
				
			||||||
    _B.n = 1;
 | 
					    B.n = 1;
 | 
				
			||||||
    _B.p = p;
 | 
					    B.p = p;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( mbedtls_mpi_div_mpi( Q, R, A, &_B ) );
 | 
					    return( mbedtls_mpi_div_mpi( Q, R, A, &B ) );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
@@ -2297,7 +2297,7 @@ cleanup:
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
 | 
					int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
 | 
				
			||||||
                         const mbedtls_mpi *E, const mbedtls_mpi *N,
 | 
					                         const mbedtls_mpi *E, const mbedtls_mpi *N,
 | 
				
			||||||
                         mbedtls_mpi *_RR )
 | 
					                         mbedtls_mpi *prec_RR )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
 | 
					    int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED;
 | 
				
			||||||
    size_t wbits, wsize, one = 1;
 | 
					    size_t wbits, wsize, one = 1;
 | 
				
			||||||
@@ -2365,17 +2365,17 @@ int mbedtls_mpi_exp_mod( mbedtls_mpi *X, const mbedtls_mpi *A,
 | 
				
			|||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * If 1st call, pre-compute R^2 mod N
 | 
					     * If 1st call, pre-compute R^2 mod N
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    if( _RR == NULL || _RR->p == NULL )
 | 
					    if( prec_RR == NULL || prec_RR->p == NULL )
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &RR, 1 ) );
 | 
					        MBEDTLS_MPI_CHK( mbedtls_mpi_lset( &RR, 1 ) );
 | 
				
			||||||
        MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &RR, N->n * 2 * biL ) );
 | 
					        MBEDTLS_MPI_CHK( mbedtls_mpi_shift_l( &RR, N->n * 2 * biL ) );
 | 
				
			||||||
        MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &RR, &RR, N ) );
 | 
					        MBEDTLS_MPI_CHK( mbedtls_mpi_mod_mpi( &RR, &RR, N ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if( _RR != NULL )
 | 
					        if( prec_RR != NULL )
 | 
				
			||||||
            memcpy( _RR, &RR, sizeof( mbedtls_mpi ) );
 | 
					            memcpy( prec_RR, &RR, sizeof( mbedtls_mpi ) );
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else
 | 
					    else
 | 
				
			||||||
        memcpy( &RR, _RR, sizeof( mbedtls_mpi ) );
 | 
					        memcpy( &RR, prec_RR, sizeof( mbedtls_mpi ) );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
     * W[1] = A * R^2 * R^-1 mod N = A * R mod N
 | 
					     * W[1] = A * R^2 * R^-1 mod N = A * R mod N
 | 
				
			||||||
@@ -2523,7 +2523,7 @@ cleanup:
 | 
				
			|||||||
    mbedtls_mpi_free( &W[1] ); mbedtls_mpi_free( &T ); mbedtls_mpi_free( &Apos );
 | 
					    mbedtls_mpi_free( &W[1] ); mbedtls_mpi_free( &T ); mbedtls_mpi_free( &Apos );
 | 
				
			||||||
    mbedtls_mpi_free( &WW );
 | 
					    mbedtls_mpi_free( &WW );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if( _RR == NULL || _RR->p == NULL )
 | 
					    if( prec_RR == NULL || prec_RR->p == NULL )
 | 
				
			||||||
        mbedtls_mpi_free( &RR );
 | 
					        mbedtls_mpi_free( &RR );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( ret );
 | 
					    return( ret );
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user