1#ifndef CRYPTOPP_BLUMSHUB_H 2#define CRYPTOPP_BLUMSHUB_H 3 4#include "modarith.h" 5 6NAMESPACE_BEGIN(CryptoPP) 7 8class BlumGoldwasserPublicKey; 9class BlumGoldwasserPrivateKey; 10 11//! BlumBlumShub without factorization of the modulus 12class PublicBlumBlumShub : public RandomNumberGenerator, 13 public StreamTransformation 14{ 15public: 16 PublicBlumBlumShub(const Integer &n, const Integer &seed); 17 18 unsigned int GenerateBit(); 19 byte GenerateByte(); 20 void GenerateBlock(byte *output, size_t size); 21 void ProcessData(byte *outString, const byte *inString, size_t length); 22 23 bool IsSelfInverting() const {return true;} 24 bool IsForwardTransformation() const {return true;} 25 26protected: 27 ModularArithmetic modn; 28 word maxBits, bitsLeft; 29 Integer current; 30 31 friend class BlumGoldwasserPublicKey; 32 friend class BlumGoldwasserPrivateKey; 33}; 34 35//! BlumBlumShub with factorization of the modulus 36class BlumBlumShub : public PublicBlumBlumShub 37{ 38public: 39 // Make sure p and q are both primes congruent to 3 mod 4 and at least 512 bits long, 40 // seed is the secret key and should be about as big as p*q 41 BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed); 42 43 bool IsRandomAccess() const {return true;} 44 void Seek(lword index); 45 46protected: 47 const Integer p, q; 48 const Integer x0; 49}; 50 51NAMESPACE_END 52 53#endif 54