|
Good news, I resolved all the problems, now I'm going to do a summary of all:
I used the PolarSSL library, but not all of it, indeed I only copied these files:
bignum.h
bn_mul.h
config.h
rsa.h
bignum.c
rsa.c
and removed the POLARSSL_PKCS1_V21 and POLARSSL_SELF_TEST defines from config.h
With some compilers and version of PolarSSL there will be some errors, in this case it needs to edit bignum.c as descript in this page: http://e2e.ti.com/support/development_tools/compiler/f/343/t/197852.aspx
add this lines:
#define MULADDC_INIT \
{ \
t_uint s0, s1, b0, b1; \
t_uint r0, r1, rx, ry; \
b0 = ( b << biH ) >> biH; \
b1 = ( b >> biH );
#define MULADDC_CORE \
s0 = ( *s << biH ) >> biH; \
s1 = ( *s >> biH ); s++; \
rx = s0 * b1; r0 = s0 * b0; \
ry = s1 * b0; r1 = s1 * b1; \
r1 += ( rx >> biH ); \
r1 += ( ry >> biH ); \
rx <<= biH; ry <<= biH; \
r0 += rx; r1 += (r0 < rx); \
r0 += ry; r1 += (r0 < ry); \
r0 += c; r1 += (r0 < c); \
r0 += *d; r1 += (r0 < *d); \
c = r1; *(d++) = r0;
#define MULADDC_STOP \
}
and replace these lines:
do {
*d += c; c = ( *d < c ); d++;
}
while( c != 0 );
with these lines:
do {
t_uint temp = *d;
if (c != 0)
*d = temp + c;
c = ( *d < c );
d++;
}
while( c != 0 );
Ok, now it works, if you want to set your private key and you have the XML fornat you can use this functions:
rsa.len = MAXDIGITS;
mpi_read_string( &rsa.N , 16, RSA_N );
mpi_read_string( &rsa.E , 16, RSA_E );
mpi_read_string( &rsa.D , 16, RSA_D );
mpi_read_string( &rsa.P , 16, RSA_P );
mpi_read_string( &rsa.Q , 16, RSA_Q );
mpi_read_string( &rsa.DP, 16, RSA_DP );
mpi_read_string( &rsa.DQ, 16, RSA_DQ );
mpi_read_string( &rsa.QP, 16, RSA_QP );
Finally I want to thank hli for his contribute to solve the problem. Thank you very much, I hope these posts will help someone else have to implements RSA1024
Antonio
|