add assert for setByCSPRNG

dev
MITSUNARI Shigeo 7 years ago
parent df468426c4
commit 4f9e9f00ce
  1. 2
      readme.md
  2. 1
      src/fp.cpp

@ -2,7 +2,7 @@
# mcl # mcl
A generic and fast pairing-based cryptography library. A portable and fast pairing-based cryptography library.
# Abstract # Abstract

@ -201,6 +201,7 @@ void getRandVal(Unit *out, RandGen& rg, const Unit *in, size_t bitSize)
if (rg.isZero()) rg = RandGen::get(); if (rg.isZero()) rg = RandGen::get();
const size_t n = (bitSize + UnitBitSize - 1) / UnitBitSize; const size_t n = (bitSize + UnitBitSize - 1) / UnitBitSize;
const size_t rem = bitSize & (UnitBitSize - 1); const size_t rem = bitSize & (UnitBitSize - 1);
assert(n > 0);
for (;;) { for (;;) {
rg.read(out, n * sizeof(Unit)); rg.read(out, n * sizeof(Unit));
if (rem > 0) out[n - 1] &= (Unit(1) << rem) - 1; if (rem > 0) out[n - 1] &= (Unit(1) << rem) - 1;

Loading…
Cancel
Save