word32 SetLength(word32 length, byte* output) { word32 i = 0; if (length < LONG_LENGTH) output[i++] = length; else { output[i++] = BytePrecision(length) | 0x80; for (int j = BytePrecision(length); j; --j) { output[i] = length >> (j - 1) * 8; i++; } } return i; }
unsigned int PolynomialMod2::ByteCount() const { unsigned wordCount = WordCount(); if (wordCount) return (wordCount-1)*WORD_SIZE + BytePrecision(reg[wordCount-1]); else return 0; }
/** * Gets the number of bytes required to represent this RInteger. * * @return The size of the integer in bytes. * */ EXPORT_C TUint TInteger::ByteCount() const { TUint wordCount = WordCount(); if(wordCount) { return (wordCount-1)*WORD_SIZE + BytePrecision((Ptr())[wordCount-1]); } else { return 0; } }
word32 RandomNumberGenerator::GenerateWord32(word32 min, word32 max) { word32 range = max-min; const int maxBytes = BytePrecision(range); const int maxBits = BitPrecision(range); word32 value; do { value = 0; for (int i=0; i<maxBytes; i++) value = (value << 8) | GenerateByte(); value = Crop(value, maxBits); } while (value > range); return value+min; }