aboutsummaryrefslogtreecommitdiff
path: root/src/libmp/port/letomp.c
blob: e23fed21e865b6627ce742aff121fcaf04f79200 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "os.h"
#include <mp.h>
#include "dat.h"

// convert a little endian byte array (least significant byte first) to an mpint
mpint*
letomp(uchar *s, uint n, mpint *b)
{
	int i=0, m = 0;
	mpdigit x=0;

	if(b == nil)
		b = mpnew(0);
	mpbits(b, 8*n);
	for(; n > 0; n--){
		x |= ((mpdigit)(*s++)) << i;
		i += 8;
		if(i == Dbits){
			b->p[m++] = x;
			i = 0;
			x = 0;
		}
	}
	if(i > 0)
		b->p[m++] = x;
	b->top = m;
	return b;
}