Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class 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 00012 /// base class for secret sharing and information dispersal 00013 class RawIDA : public AutoSignaling<Unflushable<Multichannel<Filter> > > 00014 { 00015 public: 00016 RawIDA(BufferedTransformation *attachment=NULL) 00017 : AutoSignaling<Unflushable<Multichannel<Filter> > >(attachment) {} 00018 00019 unsigned int GetThreshold() const {return m_threshold;} 00020 void AddOutputChannel(word32 channelId); 00021 void ChannelData(word32 channelId, const byte *inString, unsigned int length, bool messageEnd); 00022 unsigned int InputBuffered(word32 channelId) const; 00023 00024 void ChannelInitialize(const std::string &channel, const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1); 00025 unsigned int ChannelPut2(const std::string &channel, const byte *begin, unsigned int length, int messageEnd, bool blocking) 00026 { 00027 if (!blocking) 00028 throw BlockingInputOnly("RawIDA"); 00029 ChannelData(StringToWord<word32>(channel), begin, length, messageEnd != 0); 00030 return 0; 00031 } 00032 00033 protected: 00034 virtual void FlushOutputQueues(); 00035 virtual void OutputMessageEnds(); 00036 00037 unsigned int InsertInputChannel(word32 channelId); 00038 unsigned int LookupInputChannel(word32 channelId) const; 00039 void ComputeV(unsigned int); 00040 void PrepareInterpolation(); 00041 void ProcessInputQueues(); 00042 00043 std::map<word32, unsigned int> m_inputChannelMap; 00044 std::map<word32, unsigned int>::iterator m_lastMapPosition; 00045 std::vector<MessageQueue> m_inputQueues; 00046 std::vector<word32> m_inputChannelIds, m_outputChannelIds, m_outputToInput; 00047 std::vector<std::string> m_outputChannelIdStrings; 00048 std::vector<ByteQueue> m_outputQueues; 00049 int m_threshold; 00050 unsigned int m_channelsReady, m_channelsFinished; 00051 std::vector<SecBlock<word32> > m_v; 00052 SecBlock<word32> m_u, m_w, m_y; 00053 }; 00054 00055 /// a variant of Shamir's Secret Sharing Algorithm 00056 class SecretSharing : public CustomSignalPropagation<Filter> 00057 { 00058 public: 00059 SecretSharing(RandomNumberGenerator &rng, int threshold, int nShares, BufferedTransformation *attachment=NULL, bool addPadding=true) 00060 : CustomSignalPropagation<Filter>(attachment), m_rng(rng), m_ida(new OutputProxy(*this, true)) 00061 {Initialize(MakeParameters("RecoveryThreshold", threshold)("NumberOfShares", nShares)("AddPadding", addPadding), 0);} 00062 00063 void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1); 00064 unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking); 00065 bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) {return m_ida.Flush(hardFlush, propagation, blocking);} 00066 00067 protected: 00068 RandomNumberGenerator &m_rng; 00069 RawIDA m_ida; 00070 bool m_pad; 00071 }; 00072 00073 /// a variant of Shamir's Secret Sharing Algorithm 00074 class SecretRecovery : public RawIDA 00075 { 00076 public: 00077 SecretRecovery(int threshold, BufferedTransformation *attachment=NULL, bool removePadding=true) 00078 : RawIDA(attachment) 00079 {Initialize(MakeParameters("RecoveryThreshold", threshold)("RemovePadding", removePadding), 0);} 00080 00081 void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1); 00082 00083 protected: 00084 void FlushOutputQueues(); 00085 void OutputMessageEnds(); 00086 00087 bool m_pad; 00088 }; 00089 00090 /// a variant of Rabin's Information Dispersal Algorithm 00091 class InformationDispersal : public CustomSignalPropagation<Filter> 00092 { 00093 public: 00094 InformationDispersal(int threshold, int nShares, BufferedTransformation *attachment=NULL, bool addPadding=true) 00095 : CustomSignalPropagation<Filter>(attachment), m_ida(new OutputProxy(*this, true)) 00096 {Initialize(MakeParameters("RecoveryThreshold", threshold)("NumberOfShares", nShares)("AddPadding", addPadding), 0);} 00097 00098 void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1); 00099 unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking); 00100 bool Flush(bool hardFlush, int propagation=-1, bool blocking=true) {return m_ida.Flush(hardFlush, propagation, blocking);} 00101 00102 protected: 00103 RawIDA m_ida; 00104 bool m_pad; 00105 unsigned int m_nextChannel; 00106 }; 00107 00108 /// a variant of Rabin's Information Dispersal Algorithm 00109 class InformationRecovery : public RawIDA 00110 { 00111 public: 00112 InformationRecovery(int threshold, BufferedTransformation *attachment=NULL, bool removePadding=true) 00113 : RawIDA(attachment) 00114 {Initialize(MakeParameters("RecoveryThreshold", threshold)("RemovePadding", removePadding), 0);} 00115 00116 void Initialize(const NameValuePairs &parameters=g_nullNameValuePairs, int propagation=-1); 00117 00118 protected: 00119 void FlushOutputQueues(); 00120 void OutputMessageEnds(); 00121 00122 bool m_pad; 00123 ByteQueue m_queue; 00124 }; 00125 00126 class PaddingRemover : public Unflushable<Filter> 00127 { 00128 public: 00129 PaddingRemover(BufferedTransformation *attachment=NULL) 00130 : Unflushable<Filter>(attachment), m_possiblePadding(false) {} 00131 00132 void IsolatedInitialize(const NameValuePairs &parameters) {m_possiblePadding = false;} 00133 unsigned int Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking); 00134 00135 // GetPossiblePadding() == false at the end of a message indicates incorrect padding 00136 bool GetPossiblePadding() const {return m_possiblePadding;} 00137 00138 private: 00139 bool m_possiblePadding; 00140 unsigned long m_zeroCount; 00141 }; 00142 00143 NAMESPACE_END 00144 00145 #endif

Generated on Wed Jul 28 08:07:07 2004 for Crypto++ by doxygen 1.3.7