예제 #1
0
파일: test.cpp 프로젝트: NotHawthorne/umbra
void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed)
{
	assert(nShares<=1000);

	RandomPool rng;
	rng.IncorporateEntropy((byte *)seed, strlen(seed));

	ChannelSwitch *channelSwitch;
	FileSource source(filename, false, new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch));

	vector_member_ptrs<FileSink> fileSinks(nShares);
	string channel;
	for (int i=0; i<nShares; i++)
	{
		char extension[5] = ".000";
		extension[1]='0'+byte(i/100);
		extension[2]='0'+byte((i/10)%10);
		extension[3]='0'+byte(i%10);
		fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));

		channel = WordToString<word32>(i);
		fileSinks[i]->Put((byte *)channel.data(), 4);
		channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL);
	}

	source.PumpAll();
}
예제 #2
0
void SecretShareFile(int threshold, int nShares, const char *filename, const char *seed)
{
	assert(nShares<=1000);
	RandomPool rng;
	rng.IncorporateEntropy((byte *)seed, strlen(seed));
	ChannelSwitch *channelSwitch;
	string data = "ABCDABCD";
	//FileSource source(filename, false, new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch));
	ArraySource source((byte *)data.c_str(), data.length() + 4, false, new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch));
	std::vector<string> buf(nShares);
	/*SecretSharing *sss = new SecretSharing(rng, threshold, nShares, channelSwitch = new ChannelSwitch);
	string pt = "abcd";
	const unsigned char *c = (const unsigned char*) pt.c_str();
	sss->Put(c, 5, true);
	sss->MessageEnd(-1, true);
	bool mesgs = sss->AnyMessages();
	cout<<mesgs<<endl;
	lword max_ret = sss->MaxRetrievable();
	cout<<max_ret<<endl;
	*/
	vector_member_ptrs<FileSink> fileSinks(nShares);
	vector_member_ptrs<ArraySink> sinks(nShares);
	string channel;
	for (int i=0; i<nShares; i++)
	{
		char extension[5] = ".000";
		extension[1]='0'+byte(i/100);
		extension[2]='0'+byte((i/10)%10);
		extension[3]='0'+byte(i%10);
		fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));
		sinks[i].reset(new ArraySink((byte *) buf.at(i).c_str(), buf.at(i).length()));
		channel = WordToString<word32>(i);
		//cout<<channel.data()<<endl;
		//fileSinks[i]->Put((byte *)channel.data(), 4);
		sinks[i]->Put((byte *) channel.data(), 4);
		//channelSwitch->AddRoute(channel, *fileSinks[i], DEFAULT_CHANNEL);
		channelSwitch->AddRoute(channel, *sinks[i], DEFAULT_CHANNEL);
	}
	//istream *is = source.GetStream();
	//cout<<is->rdbuf();
	/*char cs = is->get();
	while(is) {
		//cout<<cs;
		cs = is->get();
	}*/
	source.PumpAll();
	cout<<buf.at(0)<<endl;
} 
예제 #3
0
파일: test.cpp 프로젝트: acat/emule
void InformationDisperseFile(int threshold, int nShares, const char *filename)
{
	assert(nShares<=1000);

	ChannelSwitch *channelSwitch;
	FileSource source(filename, false, new InformationDispersal(threshold, nShares, channelSwitch = new ChannelSwitch));

	vector_member_ptrs<FileSink> fileSinks(nShares);
	string channel;
	for (unsigned int i=0; i<nShares; i++)
	{
		char extension[5] = ".000";
		extension[1]='0'+byte(i/100);
		extension[2]='0'+byte((i/10)%10);
		extension[3]='0'+byte(i%10);
		fileSinks[i].reset(new FileSink((string(filename)+extension).c_str()));

		channel = WordToString<word32>(i);
		fileSinks[i]->Put((byte *)channel.data(), 4);
		channelSwitch->AddRoute(channel, *fileSinks[i], BufferedTransformation::NULL_CHANNEL);
	}

	source.PumpAll();
}