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