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
00013 class
RawIDA : public
AutoSignaling<
Unflushable<
Multichannel<
Filter> > >
00014 {
00015
public:
00016
RawIDA(
BufferedTransformation *attachment=NULL)
00017 {Detach(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 IsolatedInitialize(
const NameValuePairs ¶meters=g_nullNameValuePairs);
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
00056 class SecretSharing :
public CustomFlushPropagation<Filter>
00057 {
00058
public:
00059
SecretSharing(
RandomNumberGenerator &rng,
int threshold,
int nShares,
BufferedTransformation *attachment=NULL,
bool addPadding=
true)
00060 : m_rng(rng), m_ida(
new OutputProxy(*
this,
true))
00061 {
00062
Detach(attachment);
00063 IsolatedInitialize(MakeParameters(
"RecoveryThreshold", threshold)(
"NumberOfShares", nShares)(
"AddPadding", addPadding));
00064 }
00065
00066
void IsolatedInitialize(
const NameValuePairs ¶meters=g_nullNameValuePairs);
00067
unsigned int Put2(
const byte *begin,
unsigned int length,
int messageEnd,
bool blocking);
00068 bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true) {
return m_ida.
Flush(hardFlush, propagation, blocking);}
00069
00070
protected:
00071
RandomNumberGenerator &m_rng;
00072
RawIDA m_ida;
00073
bool m_pad;
00074 };
00075
00076
00077 class SecretRecovery :
public RawIDA
00078 {
00079
public:
00080
SecretRecovery(
int threshold,
BufferedTransformation *attachment=NULL,
bool removePadding=
true)
00081 :
RawIDA(attachment)
00082 {IsolatedInitialize(MakeParameters(
"RecoveryThreshold", threshold)(
"RemovePadding", removePadding));}
00083
00084
void IsolatedInitialize(
const NameValuePairs ¶meters=g_nullNameValuePairs);
00085
00086
protected:
00087
void FlushOutputQueues();
00088
void OutputMessageEnds();
00089
00090
bool m_pad;
00091 };
00092
00093
00094 class InformationDispersal :
public CustomFlushPropagation<Filter>
00095 {
00096
public:
00097
InformationDispersal(
int threshold,
int nShares,
BufferedTransformation *attachment=NULL,
bool addPadding=
true)
00098 : m_ida(
new OutputProxy(*
this,
true))
00099 {
00100
Detach(attachment);
00101 IsolatedInitialize(MakeParameters(
"RecoveryThreshold", threshold)(
"NumberOfShares", nShares)(
"AddPadding", addPadding));
00102 }
00103
00104
void IsolatedInitialize(
const NameValuePairs ¶meters=g_nullNameValuePairs);
00105
unsigned int Put2(
const byte *begin,
unsigned int length,
int messageEnd,
bool blocking);
00106 bool Flush(
bool hardFlush,
int propagation=-1,
bool blocking=
true) {
return m_ida.
Flush(hardFlush, propagation, blocking);}
00107
00108
protected:
00109
RawIDA m_ida;
00110
bool m_pad;
00111
unsigned int m_nextChannel;
00112 };
00113
00114
00115 class InformationRecovery :
public RawIDA
00116 {
00117
public:
00118
InformationRecovery(
int threshold,
BufferedTransformation *attachment=NULL,
bool removePadding=
true)
00119 :
RawIDA(attachment)
00120 {IsolatedInitialize(MakeParameters(
"RecoveryThreshold", threshold)(
"RemovePadding", removePadding));}
00121
00122
void IsolatedInitialize(
const NameValuePairs ¶meters=g_nullNameValuePairs);
00123
00124
protected:
00125
void FlushOutputQueues();
00126
void OutputMessageEnds();
00127
00128
bool m_pad;
00129
ByteQueue m_queue;
00130 };
00131
00132
class PaddingRemover :
public Unflushable<Filter>
00133 {
00134
public:
00135 PaddingRemover(
BufferedTransformation *attachment=NULL)
00136 : m_possiblePadding(false) {Detach(attachment);}
00137
00138
void IsolatedInitialize(
const NameValuePairs ¶meters) {m_possiblePadding =
false;}
00139
unsigned int Put2(
const byte *begin,
unsigned int length,
int messageEnd,
bool blocking);
00140
00141
00142
bool GetPossiblePadding()
const {
return m_possiblePadding;}
00143
00144
private:
00145
bool m_possiblePadding;
00146
unsigned long m_zeroCount;
00147 };
00148
00149 NAMESPACE_END
00150
00151
#endif