summaryrefslogtreecommitdiff
path: root/CryptoPP/crypto/blumshub.cpp
diff options
context:
space:
mode:
authorwatcherhd <watcherhd@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-11-26 14:19:43 +0000
committerwatcherhd <watcherhd@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-11-26 14:19:43 +0000
commit7aff1e4cb053394db57c2814d5fe1e6493e0cc75 (patch)
treec8585e44049b37e4da152495c954242204c2c38d /CryptoPP/crypto/blumshub.cpp
parent6f3d69266933ef120d229e0daf2da164b77214d0 (diff)
Project folders rename part 2
git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@214 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
Diffstat (limited to 'CryptoPP/crypto/blumshub.cpp')
-rw-r--r--CryptoPP/crypto/blumshub.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/CryptoPP/crypto/blumshub.cpp b/CryptoPP/crypto/blumshub.cpp
new file mode 100644
index 0000000..6ab2209
--- /dev/null
+++ b/CryptoPP/crypto/blumshub.cpp
@@ -0,0 +1,63 @@
+// blumshub.cpp - written and placed in the public domain by Wei Dai
+
+#include "pch.h"
+#include "blumshub.h"
+
+NAMESPACE_BEGIN(CryptoPP)
+
+PublicBlumBlumShub::PublicBlumBlumShub(const Integer &n, const Integer &seed)
+ : modn(n),
+ maxBits(BitPrecision(n.BitCount())-1)
+{
+ current = modn.Square(modn.Square(seed));
+ bitsLeft = maxBits;
+}
+
+unsigned int PublicBlumBlumShub::GenerateBit()
+{
+ if (bitsLeft==0)
+ {
+ current = modn.Square(current);
+ bitsLeft = maxBits;
+ }
+
+ return current.GetBit(--bitsLeft);
+}
+
+byte PublicBlumBlumShub::GenerateByte()
+{
+ byte b=0;
+ for (int i=0; i<8; i++)
+ b = (b << 1) | PublicBlumBlumShub::GenerateBit();
+ return b;
+}
+
+void PublicBlumBlumShub::GenerateBlock(byte *output, size_t size)
+{
+ while (size--)
+ *output++ = PublicBlumBlumShub::GenerateByte();
+}
+
+void PublicBlumBlumShub::ProcessData(byte *outString, const byte *inString, size_t length)
+{
+ while (length--)
+ *outString++ = *inString++ ^ PublicBlumBlumShub::GenerateByte();
+}
+
+BlumBlumShub::BlumBlumShub(const Integer &p, const Integer &q, const Integer &seed)
+ : PublicBlumBlumShub(p*q, seed),
+ p(p), q(q),
+ x0(modn.Square(seed))
+{
+}
+
+void BlumBlumShub::Seek(lword index)
+{
+ Integer i(Integer::POSITIVE, index);
+ i *= 8;
+ Integer e = a_exp_b_mod_c (2, i / maxBits + 1, (p-1)*(q-1));
+ current = modn.Exponentiate(x0, e);
+ bitsLeft = maxBits - i % maxBits;
+}
+
+NAMESPACE_END