blumshub.h
Go to the documentation of this file.
// blumshub.h - originally written and placed in the public domain by Wei Dai
/// \file blumshub.h
/// \brief Classes for Blum Blum Shub generator
#ifndef CRYPTOPP_BLUMSHUB_H
#define CRYPTOPP_BLUMSHUB_H
#include "cryptlib.h"
#include "modarith.h"
#include "integer.h"
NAMESPACE_BEGIN(CryptoPP)
/// \brief BlumBlumShub without factorization of the modulus
/// \details You should reseed the generator after a fork() to avoid multiple generators
/// with the same internal state.
class PublicBlumBlumShub : public RandomNumberGenerator,
public StreamTransformation
{
public:
virtual ~PublicBlumBlumShub() {}
/// \brief Construct a PublicBlumBlumShub
/// \param n the modulus
/// \param seed the seed for the generator
/// \details seed is the secret key and should be about as large as n.
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;}
protected:
ModularArithmetic modn;
Integer current;
word maxBits, bitsLeft;
};
/// \brief BlumBlumShub with factorization of the modulus
/// \details You should reseed the generator after a fork() to avoid multiple generators
/// with the same internal state.
class BlumBlumShub : public PublicBlumBlumShub
{
public:
virtual ~BlumBlumShub() {}
/// \brief Construct a BlumBlumShub
/// \param p the first prime factor
/// \param q the second prime factor
/// \param seed the seed for the generator
/// \details Esure 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 large as p*q.
BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed);
bool IsRandomAccess() const {return true;}
void Seek(lword index);
protected:
const Integer p, q;
const Integer x0;
};
NAMESPACE_END
#endif
BlumBlumShub::BlumBlumShub
BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed)
Construct a BlumBlumShub.
Definition blumshub.cpp:48
BlumBlumShub::IsRandomAccess
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition blumshub.h:60
BlumBlumShub::Seek
void Seek(lword index)
Seek to an absolute position.
Definition blumshub.cpp:55
Integer
Multiple precision integer with arithmetic operations.
Definition integer.h:50
ModularArithmetic
Ring of congruence classes modulo n.
Definition modarith.h:44
PublicBlumBlumShub::IsForwardTransformation
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition blumshub.h:36
PublicBlumBlumShub::PublicBlumBlumShub
PublicBlumBlumShub(const Integer &n, const Integer &seed)
Construct a PublicBlumBlumShub.
Definition blumshub.cpp:9
PublicBlumBlumShub::GenerateBit
unsigned int GenerateBit()
Generate new random bit and return it.
Definition blumshub.cpp:17
PublicBlumBlumShub::GenerateBlock
void GenerateBlock(byte *output, size_t size)
Generate random array of bytes.
Definition blumshub.cpp:36
PublicBlumBlumShub::GenerateByte
byte GenerateByte()
Generate new random byte and return it.
Definition blumshub.cpp:28
PublicBlumBlumShub::IsSelfInverting
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition blumshub.h:35
PublicBlumBlumShub::ProcessData
void ProcessData(byte *outString, const byte *inString, size_t length)
Encrypt or decrypt an array of bytes.
Definition blumshub.cpp:42
RandomNumberGenerator
Interface for random number generators.
Definition cryptlib.h:1440
StreamTransformation
Interface for the data processing portion of stream ciphers.
Definition cryptlib.h:951
word
word64 word
Full word used for multiprecision integer arithmetic.
Definition config_int.h:192
lword
word64 lword
Large word type.
Definition config_int.h:168
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
integer.h
Multiple precision integer with arithmetic operations.
modarith.h
Class file for performing modular arithmetic.
CryptoPP
Crypto++ library namespace.