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 big-endian byte array (most significant byte first) to an mpint
6
mpint*
7
betomp(uchar *p, uint n, mpint *b)
8
{
9
	int m, s;
10
	mpdigit x;
11
 
12
	if(b == nil){
13
		b = mpnew(0);
14
		setmalloctag(b, getcallerpc(&p));
15
	}
33 7u83 16
	mpbits(b, n*8);
2 - 17
 
33 7u83 18
	m = DIGITS(n*8);
19
	b->top = m--;
20
	b->sign = 1;
2 - 21
 
22
	s = ((n-1)*8)%Dbits;
23
	x = 0;
24
	for(; n > 0; n--){
25
		x |= ((mpdigit)(*p++)) << s;
26
		s -= 8;
27
		if(s < 0){
28
			b->p[m--] = x;
29
			s = Dbits-8;
30
			x = 0;
31
		}
32
	}
33 7u83 33
	return mpnorm(b);
2 - 34
}