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
mpint*
6
mprand(int bits, void (*gen)(uchar*, int), mpint *b)
7
{
8
	mpdigit mask;
9
 
33 7u83 10
	if(b == nil){
2 - 11
		b = mpnew(bits);
33 7u83 12
		setmalloctag(b, getcallerpc(&bits));
13
	}else
2 - 14
		mpbits(b, bits);
15
 
33 7u83 16
	b->sign = 1;
17
	b->top = DIGITS(bits);
18
	(*gen)((uchar*)b->p, b->top*Dbytes);
2 - 19
 
33 7u83 20
	mask = ((mpdigit)1 << (bits%Dbits))-1;
21
	if(mask != 0)
22
		b->p[b->top-1] &= mask;
2 - 23
 
33 7u83 24
	return mpnorm(b);
2 - 25
}