Crypto++ 8.6 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
13 NAMESPACE_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.
18 class PublicBlumBlumShub : public RandomNumberGenerator,
19 public StreamTransformation
20 {
21 public:
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
38 protected:
39 ModularArithmetic modn;
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.
47 class BlumBlumShub : public PublicBlumBlumShub
48 {
49 public:
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
63 protected:
64 const Integer p, q;
65 const Integer x0;
66 };
67
68 NAMESPACE_END
69
70 #endif
PublicBlumBlumShub
BlumBlumShub without factorization of the modulus.
Definition: blumshub.h:18
BlumBlumShub::IsRandomAccess
bool IsRandomAccess() const
Determines whether the cipher supports random access.
Definition: blumshub.h:60
ModularArithmetic
Ring of congruence classes modulo n.
Definition: modarith.h:43
modarith.h
Class file for performing modular arithmetic.
RandomNumberGenerator
Interface for random number generators.
Definition: cryptlib.h:1434
word
word64 word
Full word used for multiprecision integer arithmetic.
Definition: config_int.h:182
BlumBlumShub
BlumBlumShub with factorization of the modulus.
Definition: blumshub.h:47
lword
word64 lword
Large word type.
Definition: config_int.h:158
BlumBlumShub::Seek
void Seek(lword index)
Seek to an absolute position.
Definition: blumshub.cpp:55
CryptoPP
Crypto++ library namespace.
BlumBlumShub::BlumBlumShub
BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed)
Construct a BlumBlumShub.
Definition: blumshub.cpp:48
StreamTransformation
Interface for the data processing portion of stream ciphers.
Definition: cryptlib.h:945
PublicBlumBlumShub::IsForwardTransformation
bool IsForwardTransformation() const
Determines if the cipher is being operated in its forward direction.
Definition: blumshub.h:36
PublicBlumBlumShub::IsSelfInverting
bool IsSelfInverting() const
Determines whether the cipher is self-inverting.
Definition: blumshub.h:35
cryptlib.h
Abstract base classes that provide a uniform interface to this library.
integer.h
Multiple precision integer with arithmetic operations.
Integer
Multiple precision integer with arithmetic operations.
Definition: integer.h:49