ext-cryptopp/blumshub.h

59 lines
1.4 KiB
C
Raw Normal View History

// blumshub.h - originally written and placed in the public domain by Wei Dai
2018-01-22 14:53:49 +00:00
/// \file blumshub.h
/// \brief Classes for Blum Blum Shub generator
2015-11-05 06:59:46 +00:00
#ifndef CRYPTOPP_BLUMSHUB_H
#define CRYPTOPP_BLUMSHUB_H
#include "cryptlib.h"
#include "modarith.h"
#include "integer.h"
NAMESPACE_BEGIN(CryptoPP)
/// BlumBlumShub without factorization of the modulus
2015-11-05 06:59:46 +00:00
class PublicBlumBlumShub : public RandomNumberGenerator,
public StreamTransformation
{
public:
virtual ~PublicBlumBlumShub() {}
2015-11-05 06:59:46 +00:00
PublicBlumBlumShub(const Integer &n, const Integer &seed);
unsigned int GenerateBit();
byte GenerateByte();
void GenerateBlock(byte *output, size_t size);
void ProcessData(byte *outString, const byte *inString, size_t length);
bool IsSelfInverting() const {return true;}
bool IsForwardTransformation() const {return true;}
2016-09-10 08:57:48 +00:00
2015-11-05 06:59:46 +00:00
protected:
ModularArithmetic modn;
Integer current;
word maxBits, bitsLeft;
2015-11-05 06:59:46 +00:00
};
/// BlumBlumShub with factorization of the modulus
2015-11-05 06:59:46 +00:00
class BlumBlumShub : public PublicBlumBlumShub
{
public:
virtual ~BlumBlumShub() {}
2015-11-05 06:59:46 +00:00
// Make sure p and q are both primes congruent to 3 mod 4 and at least 512 bits long,
// seed is the secret key and should be about as big as p*q
BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed);
2016-09-10 08:57:48 +00:00
2015-11-05 06:59:46 +00:00
bool IsRandomAccess() const {return true;}
void Seek(lword index);
protected:
const Integer p, q;
const Integer x0;
};
NAMESPACE_END
#endif