Subversion Repositories planix.SVN

Rev

Rev 33 | 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
 
33 7u83 12
	if(b == nil){
2 - 13
		b = mpnew(0);
33 7u83 14
		setmalloctag(b, getcallerpc(&s));
15
	}
2 - 16
	mpbits(b, 8*n);
17
	for(; n > 0; n--){
18
		x |= ((mpdigit)(*s++)) << i;
19
		i += 8;
20
		if(i == Dbits){
21
			b->p[m++] = x;
22
			i = 0;
23
			x = 0;
24
		}
25
	}
26
	if(i > 0)
27
		b->p[m++] = x;
28
	b->top = m;
33 7u83 29
	b->sign = 1;
30
	return mpnorm(b);
2 - 31
}