// function for adding two big number in big endian
static void add(const unsigned char *a, int la, const unsigned char *b, int lb, unsigned char *mul, int *lmul)
{
int ltemp = ((la>lb)?la:lb)+1;
int lmin = ((la>lb)?lb:la);
unsigned char *temp = (unsigned char*)malloc(ltemp);
int xa = la-1, xb = lb-1, y = ltemp-1, u = 0;
int k = 0, z = 0;

memset(temp, 0, ltemp);

while(xa>=0 && xb>=0)
{
temp[y] = a[xa] + b[xb] + u;

if( temp[y] < a[xa] )
u = 1;
else
u = 0;

y--;
xa--;
xb--;
}

while(temp[++k]==0);

for(z=k ; z<ltemp ; z++)
mul[z-k] = temp[z];
*lmul = z-k;

free(temp); 
}
Posted by 배트
,