Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
#include "dat.h"
4
 
5
// convert a little endian byte array (least significant byte first) to an mpint
6
mpint*
7
letomp(uchar *s, uint n, mpint *b)
8
{
9
	int i=0, m = 0;
10
	mpdigit x=0;
11
 
12
	if(b == nil)
13
		b = mpnew(0);
14
	mpbits(b, 8*n);
15
	b->top = DIGITS(8*n);
16
	for(; n > 0; n--){
17
		x |= ((mpdigit)(*s++)) << i;
18
		i += 8;
19
		if(i == Dbits){
20
			b->p[m++] = x;
21
			i = 0;
22
			x = 0;
23
		}
24
	}
25
	if(i > 0)
26
		b->p[m++] = x;
27
	b->top = m;
28
	return b;
29
}