diff options
author | Kirill Volinsky <mataes2007@gmail.com> | 2012-07-20 16:21:49 +0000 |
---|---|---|
committer | Kirill Volinsky <mataes2007@gmail.com> | 2012-07-20 16:21:49 +0000 |
commit | f424a18112032cf61d2871a6b91a5af607c171ae (patch) | |
tree | 88fedc4e28941ceecda7026f0b06eba6271f91d5 /plugins/CryptoPP/crypto/src/blumshub.cpp | |
parent | bfe1bd0fc087be44c70904aee0fe4276643d206d (diff) |
CryptoPP:
changed folder structure
git-svn-id: http://svn.miranda-ng.org/main/trunk@1083 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/CryptoPP/crypto/src/blumshub.cpp')
-rw-r--r-- | plugins/CryptoPP/crypto/src/blumshub.cpp | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/plugins/CryptoPP/crypto/src/blumshub.cpp b/plugins/CryptoPP/crypto/src/blumshub.cpp new file mode 100644 index 0000000000..6ab2209925 --- /dev/null +++ b/plugins/CryptoPP/crypto/src/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
|