Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

ida.h

00001 #ifndef CRYPTOPP_IDA_H
00002 #define CRYPTOPP_IDA_H
00003 
00004 #include "mqueue.h"
00005 #include "filters.h"
00006 #include "channels.h"
00007 #include <map>
00008 #include <vector>
00009 
00010 NAMESPACE_BEGIN(CryptoPP)
00011 
00013 class RawIDA : public Filter, public BufferedTransformationWithAutoSignal
00014 {
00015 public:
00016         RawIDA(unsigned int threshold, BufferedTransformation *outQueue=NULL);
00017 
00018         unsigned int GetThreshold() const {return m_threshold;}
00019         void AddOutputChannel(word32 channelId);
00020         void ChannelData(word32 channelId, const byte *inString, unsigned int length);
00021         unsigned int InputBuffered(word32 channelId) const;
00022 
00023         void ChannelPut(const std::string &channel, byte inByte)
00024                 {ChannelData(StringToWord<word32>(channel), &inByte, 1);}
00025         void ChannelPut(const std::string &channel, const byte *inString, unsigned int length)
00026                 {ChannelData(StringToWord<word32>(channel), inString, length);}
00027         void ChannelMessageEnd(const std::string &channel, int propagation=-1);
00028 
00029         void Put(byte inByte) {}
00030         void Put(const byte *inString, unsigned int length) {}
00031 
00032 protected:
00033         virtual void FlushOutputQueues();
00034         virtual void OutputMessageEnds();
00035 
00036         unsigned int InsertInputChannel(word32 channelId);
00037         unsigned int LookupInputChannel(word32 channelId) const;
00038         void ComputeV(unsigned int);
00039         void PrepareInterpolation();
00040         void ProcessInputQueues();
00041 
00042         std::map<word32, unsigned int> m_inputChannelMap;
00043         std::map<word32, unsigned int>::iterator m_lastMapPosition;
00044         std::vector<MessageQueue> m_inputQueues;
00045         std::vector<word32> m_inputChannelIds, m_outputChannelIds, m_outputToInput;
00046         std::vector<ByteQueue> m_outputQueues;
00047         std::vector<ChannelSwitch> m_channelSwitches;
00048         unsigned int m_threshold, m_channelsReady, m_channelsFinished;
00049         std::vector<SecBlock<word32> > m_v;
00050         SecBlock<word32> m_u, m_w, m_y;
00051 };
00052 
00054 class SecretSharing : public Filter
00055 {
00056 public:
00057         SecretSharing(RandomNumberGenerator &rng, unsigned int threshold, unsigned int nShares, BufferedTransformation *outQueue=NULL, bool addPadding=true);
00058 
00059         void Put(byte inByte)
00060                 {SecretSharing::Put(&inByte, 1);}
00061         void Put(const byte *inString, unsigned int length);
00062         void MessageEnd(int propagation=-1);
00063 
00064 protected:
00065         RandomNumberGenerator &m_rng;
00066         RawIDA m_ida;
00067         bool m_pad;
00068 };
00069 
00071 class SecretRecovery : public RawIDA
00072 {
00073 public:
00074         SecretRecovery(unsigned int threshold, BufferedTransformation *outQueue=NULL, bool removePadding=true);
00075 
00076 protected:
00077         void FlushOutputQueues();
00078         void OutputMessageEnds();
00079 
00080         bool m_pad;
00081 };
00082 
00084 class InformationDispersal : public Filter
00085 {
00086 public:
00087         InformationDispersal(unsigned int threshold, unsigned int nShares, BufferedTransformation *outQueue=NULL, bool addPadding=true);
00088 
00089         void Put(byte inByte)
00090                 {InformationDispersal::Put(&inByte, 1);}
00091         void Put(const byte *inString, unsigned int length);
00092         void MessageEnd(int propagation=-1);
00093 
00094 protected:
00095         RawIDA m_ida;
00096         bool m_pad;
00097         unsigned int m_nextChannel;
00098 };
00099 
00101 class InformationRecovery : public RawIDA
00102 {
00103 public:
00104         InformationRecovery(unsigned int threshold, BufferedTransformation *outQueue=NULL, bool removePadding=true);
00105 
00106 protected:
00107         void FlushOutputQueues();
00108         void OutputMessageEnds();
00109 
00110         bool m_pad;
00111         ByteQueue m_queue;
00112 };
00113 
00114 class PaddingRemover : public Filter
00115 {
00116 public:
00117         PaddingRemover(BufferedTransformation *outQueue=NULL)
00118                 : Filter(outQueue), m_possiblePadding(false) {}
00119 
00120         void Put(byte inByte);
00121         void Put(const byte *inString, unsigned int length);
00122         void MessageEnd(int propagation=-1);
00123 
00124         // GetPossiblePadding() == false at the end of a message indicates incorrect padding
00125         bool GetPossiblePadding() const {return m_possiblePadding;}
00126 
00127 private:
00128         bool m_possiblePadding;
00129         unsigned long m_zeroCount;
00130 };
00131 
00132 NAMESPACE_END
00133 
00134 #endif

Generated at Mon Jan 15 01:16:33 2001 for Crypto++ by doxygen1.2.4 written by Dimitri van Heesch, © 1997-2000