- First replacement of xyssl by polarssl where needed

This commit is contained in:
Paul Bakker 2009-01-03 21:51:57 +00:00
parent 8e831edc24
commit 40e46940df
70 changed files with 833 additions and 1201 deletions

View file

@ -25,12 +25,12 @@
* http://math.libtomcrypt.com/files/tommath.pdf
*/
#include "xyssl/config.h"
#include "polarssl/config.h"
#if defined(XYSSL_BIGNUM_C)
#if defined(POLARSSL_BIGNUM_C)
#include "xyssl/bignum.h"
#include "xyssl/bn_mul.h"
#include "polarssl/bignum.h"
#include "polarssl/bn_mul.h"
#include <string.h>
#include <stdlib.h>
@ -232,7 +232,7 @@ static int mpi_get_digit( t_int *d, int radix, char c )
if( c >= 0x61 && c <= 0x66 ) *d = c - 0x57;
if( *d >= (t_int) radix )
return( XYSSL_ERR_MPI_INVALID_CHARACTER );
return( POLARSSL_ERR_MPI_INVALID_CHARACTER );
return( 0 );
}
@ -247,7 +247,7 @@ int mpi_read_string( mpi *X, int radix, char *s )
mpi T;
if( radix < 2 || radix > 16 )
return( XYSSL_ERR_MPI_BAD_INPUT_DATA );
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
mpi_init( &T, NULL );
@ -304,7 +304,7 @@ static int mpi_write_hlp( mpi *X, int radix, char **p )
t_int r;
if( radix < 2 || radix > 16 )
return( XYSSL_ERR_MPI_BAD_INPUT_DATA );
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
MPI_CHK( mpi_mod_int( &r, X, radix ) );
MPI_CHK( mpi_div_int( X, NULL, X, radix ) );
@ -332,7 +332,7 @@ int mpi_write_string( mpi *X, int radix, char *s, int *slen )
mpi T;
if( radix < 2 || radix > 16 )
return( XYSSL_ERR_MPI_BAD_INPUT_DATA );
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
n = mpi_msb( X );
if( radix >= 4 ) n >>= 1;
@ -342,7 +342,7 @@ int mpi_write_string( mpi *X, int radix, char *s, int *slen )
if( *slen < n )
{
*slen = n;
return( XYSSL_ERR_MPI_BUFFER_TOO_SMALL );
return( POLARSSL_ERR_MPI_BUFFER_TOO_SMALL );
}
p = s;
@ -397,7 +397,7 @@ int mpi_read_file( mpi *X, int radix, FILE *fin )
memset( s, 0, sizeof( s ) );
if( fgets( s, sizeof( s ) - 1, fin ) == NULL )
return( XYSSL_ERR_MPI_FILE_IO_ERROR );
return( POLARSSL_ERR_MPI_FILE_IO_ERROR );
slen = strlen( s );
if( s[slen - 1] == '\n' ) { slen--; s[slen] = '\0'; }
@ -438,7 +438,7 @@ int mpi_write_file( char *p, mpi *X, int radix, FILE *fout )
{
if( fwrite( p, 1, plen, fout ) != plen ||
fwrite( s, 1, slen, fout ) != slen )
return( XYSSL_ERR_MPI_FILE_IO_ERROR );
return( POLARSSL_ERR_MPI_FILE_IO_ERROR );
}
else
printf( "%s%s", p, s );
@ -480,7 +480,7 @@ int mpi_write_binary( mpi *X, unsigned char *buf, int buflen )
n = mpi_size( X );
if( buflen < n )
return( XYSSL_ERR_MPI_BUFFER_TOO_SMALL );
return( POLARSSL_ERR_MPI_BUFFER_TOO_SMALL );
memset( buf, 0, buflen );
@ -734,7 +734,7 @@ int mpi_sub_abs( mpi *X, mpi *A, mpi *B )
int ret, n;
if( mpi_cmp_abs( A, B ) < 0 )
return( XYSSL_ERR_MPI_NEGATIVE_VALUE );
return( POLARSSL_ERR_MPI_NEGATIVE_VALUE );
mpi_init( &TB, NULL );
@ -981,7 +981,7 @@ int mpi_div_mpi( mpi *Q, mpi *R, mpi *A, mpi *B )
mpi X, Y, Z, T1, T2;
if( mpi_cmp_int( B, 0 ) == 0 )
return( XYSSL_ERR_MPI_DIVISION_BY_ZERO );
return( POLARSSL_ERR_MPI_DIVISION_BY_ZERO );
mpi_init( &X, &Y, &Z, &T1, &T2, NULL );
@ -1027,7 +1027,7 @@ int mpi_div_mpi( mpi *Q, mpi *R, mpi *A, mpi *B )
Z.p[i - t - 1] = ~0;
else
{
#if defined(XYSSL_HAVE_LONGLONG)
#if defined(POLARSSL_HAVE_LONGLONG)
t_dbl r;
r = (t_dbl) X.p[i] << biL;
@ -1138,7 +1138,7 @@ cleanup:
*
* Returns 0 if successful
* 1 if memory allocation failed
* XYSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0
* POLARSSL_ERR_MPI_DIVISION_BY_ZERO if b == 0
*/
int mpi_div_int( mpi *Q, mpi *R, mpi *A, int b )
{
@ -1182,7 +1182,7 @@ int mpi_mod_int( t_int *r, mpi *A, int b )
t_int x, y, z;
if( b == 0 )
return( XYSSL_ERR_MPI_DIVISION_BY_ZERO );
return( POLARSSL_ERR_MPI_DIVISION_BY_ZERO );
if( b < 0 )
b = -b;
@ -1303,7 +1303,7 @@ int mpi_exp_mod( mpi *X, mpi *A, mpi *E, mpi *N, mpi *_RR )
mpi RR, T, W[64];
if( mpi_cmp_int( N, 0 ) < 0 || ( N->p[0] & 1 ) == 0 )
return( XYSSL_ERR_MPI_BAD_INPUT_DATA );
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
/*
* Init temps and window size
@ -1469,7 +1469,7 @@ cleanup:
return( ret );
}
#if defined(XYSSL_GENPRIME)
#if defined(POLARSSL_GENPRIME)
/*
* Greatest common divisor: G = gcd(A, B) (HAC 14.54)
@ -1522,7 +1522,7 @@ int mpi_inv_mod( mpi *X, mpi *A, mpi *N )
mpi G, TA, TU, U1, U2, TB, TV, V1, V2;
if( mpi_cmp_int( N, 0 ) <= 0 )
return( XYSSL_ERR_MPI_BAD_INPUT_DATA );
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
mpi_init( &TA, &TU, &U1, &U2, &G,
&TB, &TV, &V1, &V2, NULL );
@ -1531,7 +1531,7 @@ int mpi_inv_mod( mpi *X, mpi *A, mpi *N )
if( mpi_cmp_int( &G, 1 ) != 0 )
{
ret = XYSSL_ERR_MPI_NOT_ACCEPTABLE;
ret = POLARSSL_ERR_MPI_NOT_ACCEPTABLE;
goto cleanup;
}
@ -1651,7 +1651,7 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng )
* test trivial factors first
*/
if( ( X->p[0] & 1 ) == 0 )
return( XYSSL_ERR_MPI_NOT_ACCEPTABLE );
return( POLARSSL_ERR_MPI_NOT_ACCEPTABLE );
for( i = 0; small_prime[i] > 0; i++ )
{
@ -1663,7 +1663,7 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng )
MPI_CHK( mpi_mod_int( &r, X, small_prime[i] ) );
if( r == 0 )
return( XYSSL_ERR_MPI_NOT_ACCEPTABLE );
return( POLARSSL_ERR_MPI_NOT_ACCEPTABLE );
}
/*
@ -1728,7 +1728,7 @@ int mpi_is_prime( mpi *X, int (*f_rng)(void *), void *p_rng )
if( mpi_cmp_mpi( &A, &W ) != 0 ||
mpi_cmp_int( &A, 1 ) == 0 )
{
ret = XYSSL_ERR_MPI_NOT_ACCEPTABLE;
ret = POLARSSL_ERR_MPI_NOT_ACCEPTABLE;
break;
}
}
@ -1753,7 +1753,7 @@ int mpi_gen_prime( mpi *X, int nbits, int dh_flag,
mpi Y;
if( nbits < 3 )
return( XYSSL_ERR_MPI_BAD_INPUT_DATA );
return( POLARSSL_ERR_MPI_BAD_INPUT_DATA );
mpi_init( &Y, NULL );
@ -1776,7 +1776,7 @@ int mpi_gen_prime( mpi *X, int nbits, int dh_flag,
{
while( ( ret = mpi_is_prime( X, f_rng, p_rng ) ) != 0 )
{
if( ret != XYSSL_ERR_MPI_NOT_ACCEPTABLE )
if( ret != POLARSSL_ERR_MPI_NOT_ACCEPTABLE )
goto cleanup;
MPI_CHK( mpi_add_int( X, X, 2 ) );
@ -1794,11 +1794,11 @@ int mpi_gen_prime( mpi *X, int nbits, int dh_flag,
if( ( ret = mpi_is_prime( &Y, f_rng, p_rng ) ) == 0 )
break;
if( ret != XYSSL_ERR_MPI_NOT_ACCEPTABLE )
if( ret != POLARSSL_ERR_MPI_NOT_ACCEPTABLE )
goto cleanup;
}
if( ret != XYSSL_ERR_MPI_NOT_ACCEPTABLE )
if( ret != POLARSSL_ERR_MPI_NOT_ACCEPTABLE )
goto cleanup;
MPI_CHK( mpi_add_int( &Y, X, 1 ) );
@ -1816,7 +1816,7 @@ cleanup:
#endif
#if defined(XYSSL_SELF_TEST)
#if defined(POLARSSL_SELF_TEST)
/*
* Checkup routine