libmp: simplify mpnrand(), as mpnew() cannot return nil

This commit is contained in:
cinap_lenrek 2015-08-26 05:44:26 +02:00
parent 8f2e408448
commit 844bbecadb

View file

@ -13,16 +13,11 @@ mpnrand(mpint *n, void (*gen)(uchar*, int), mpint *b)
/* m = 2^bits - 1 */
bits = mpsignif(n);
m = mpnew(bits+1);
if(m == nil)
sysfatal("mpnrand: %r");
mpleft(mpone, bits, m);
mpsub(m, mpone, m);
if(b == nil){
if(b == nil)
b = mpnew(bits);
if(b == nil)
sysfatal("mpnrand: %r");
}
/* m = m - (m % n) */
mpmod(m, n, b);