Crypto++ 8.7
Free C++ class library of cryptographic schemes
blumshub.h
Go to the documentation of this file.
1// blumshub.h - originally written and placed in the public domain by Wei Dai
2
3/// \file blumshub.h
4/// \brief Classes for Blum Blum Shub generator
5
6#ifndef CRYPTOPP_BLUMSHUB_H
7#define CRYPTOPP_BLUMSHUB_H
8
9#include "cryptlib.h"
10#include "modarith.h"
11#include "integer.h"
12
13NAMESPACE_BEGIN(CryptoPP)
14
15/// \brief BlumBlumShub without factorization of the modulus
16/// \details You should reseed the generator after a fork() to avoid multiple generators
17/// with the same internal state.
20{
21public:
22 virtual ~PublicBlumBlumShub() {}
23
24 /// \brief Construct a PublicBlumBlumShub
25 /// \param n the modulus
26 /// \param seed the seed for the generator
27 /// \details seed is the secret key and should be about as large as n.
28 PublicBlumBlumShub(const Integer &n, const Integer &seed);
29
30 unsigned int GenerateBit();
31 byte GenerateByte();
32 void GenerateBlock(byte *output, size_t size);
33 void ProcessData(byte *outString, const byte *inString, size_t length);
34
35 bool IsSelfInverting() const {return true;}
36 bool IsForwardTransformation() const {return true;}
37
38protected:
40 Integer current;
41 word maxBits, bitsLeft;
42};
43
44/// \brief BlumBlumShub with factorization of the modulus
45/// \details You should reseed the generator after a fork() to avoid multiple generators
46/// with the same internal state.
48{
49public:
50 virtual ~BlumBlumShub() {}
51
52 /// \brief Construct a BlumBlumShub
53 /// \param p the first prime factor
54 /// \param q the second prime factor
55 /// \param seed the seed for the generator
56 /// \details Esure p and q are both primes congruent to 3 mod 4 and at least 512 bits long.
57 /// seed is the secret key and should be about as large as p*q.
58 BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed);
59
60 bool IsRandomAccess() const {return true;}
61 void Seek(lword index);
62
63protected:
64 const Integer p, q;
65 const Integer x0;
66};
67
68NAMESPACE_END
69
70#endif
BlumBlumShub with factorization of the modulus.
Definition: blumshub.h:48
BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed)
Construct a BlumBlumShub.
Definition: blumshub.cpp:48
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: blumshub.h:60
void Seek(lword index)
Seek to an absolute position.
Definition: blumshub.cpp:55
Multiple precision integer with arithmetic operations.
Definition: integer.h:50
Ring of congruence classes modulo n.
Definition: modarith.h:44
BlumBlumShub without factorization of the modulus.
Definition: blumshub.h:20
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: blumshub.h:36
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: blumshub.h:35
Interface for random number generators.
Definition: cryptlib.h:1435
Interface for the data processing portion of stream ciphers.
Definition: cryptlib.h:946
word64 word
Full word used for multiprecision integer arithmetic.
Definition: config_int.h:182
word64 lword
Large word type.
Definition: config_int.h:158
Abstract base classes that provide a uniform interface to this library.
Multiple precision integer with arithmetic operations.
Class file for performing modular arithmetic.
Crypto++ library namespace.