mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Fix mpi_bigendian_to_host() on bigendian systems
The previous implementation of mpi_bigendian_to_host() did a byte-swapping regardless of the endianness of the system. Fixes #2622.
This commit is contained in:
		
							parent
							
								
									1cd7bea2b1
								
							
						
					
					
						commit
						031d6335b7
					
				@ -742,10 +742,15 @@ cleanup:
 | 
				
			|||||||
static mbedtls_mpi_uint mpi_uint_bigendian_to_host_c( mbedtls_mpi_uint x )
 | 
					static mbedtls_mpi_uint mpi_uint_bigendian_to_host_c( mbedtls_mpi_uint x )
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    uint8_t i;
 | 
					    uint8_t i;
 | 
				
			||||||
 | 
					    unsigned char *x_ptr;
 | 
				
			||||||
    mbedtls_mpi_uint tmp = 0;
 | 
					    mbedtls_mpi_uint tmp = 0;
 | 
				
			||||||
    /* This works regardless of the endianness. */
 | 
					
 | 
				
			||||||
    for( i = 0; i < ciL; i++, x >>= 8 )
 | 
					    for( i = 0, x_ptr = (unsigned char*) &x; i < ciL; i++, x_ptr++ )
 | 
				
			||||||
        tmp |= ( x & 0xFF ) << ( ( ciL - 1 - i ) << 3 );
 | 
					    {
 | 
				
			||||||
 | 
					        tmp <<= CHAR_BIT;
 | 
				
			||||||
 | 
					        tmp |= (mbedtls_mpi_uint) *x_ptr;
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return( tmp );
 | 
					    return( tmp );
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user