亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ida.cpp

?? 加密函數庫:包括多種加密解密算法,數字簽名,散列算法
?? CPP
字號:
// ida.cpp - written and placed in the public domain by Wei Dai

#include "pch.h"
#include "ida.h"

#include "algebra.h"
#include "gf2_32.h"
#include "polynomi.h"

#include "polynomi.cpp"

ANONYMOUS_NAMESPACE_BEGIN
static const CryptoPP::GF2_32 field;
NAMESPACE_END

using namespace std;

NAMESPACE_BEGIN(CryptoPP)

void RawIDA::ChannelInitialize(const string &channel, const NameValuePairs &parameters, int propagation)
{
	if (!channel.empty())
		throw NotImplemented("RawIDA: can't reinitialize a channel");

	if (!parameters.GetIntValue("RecoveryThreshold", m_threshold))
		throw InvalidArgument("RawIDA: missing RecoveryThreshold argument");

	if (m_threshold <= 0)
		throw InvalidArgument("RawIDA: RecoveryThreshold must be greater than 0");

	m_lastMapPosition = m_inputChannelMap.end();
	m_channelsReady = 0;
	m_channelsFinished = 0;
	m_w.New(m_threshold);
	m_y.New(m_threshold);
	m_inputQueues.reserve(m_threshold);

	m_outputChannelIds.clear();
	m_outputChannelIdStrings.clear();
	m_outputQueues.clear();

	word32 outputChannelID;
	if (parameters.GetValue("OutputChannelID", outputChannelID))
		AddOutputChannel(outputChannelID);
	else
	{
		int nShares = parameters.GetIntValueWithDefault("NumberOfShares", m_threshold);
		for (int i=0; i<nShares; i++)
			AddOutputChannel(i);
	}

	if (propagation)
		for (unsigned int i=0; i<m_outputChannelIds.size(); i++)
			AttachedTransformation()->ChannelInitialize(m_outputChannelIdStrings[i], parameters, propagation-1);
}

unsigned int RawIDA::InsertInputChannel(word32 channelId)
{
	if (m_lastMapPosition != m_inputChannelMap.end())
	{
		if (m_lastMapPosition->first == channelId)
			goto skipFind;
		++m_lastMapPosition;
		if (m_lastMapPosition != m_inputChannelMap.end() && m_lastMapPosition->first == channelId)
			goto skipFind;
	}
	m_lastMapPosition = m_inputChannelMap.find(channelId);

skipFind:
	if (m_lastMapPosition == m_inputChannelMap.end())
	{
		if (m_inputChannelIds.size() == m_threshold)
			return m_threshold;

		m_lastMapPosition = m_inputChannelMap.insert(pair<const unsigned long, unsigned int>(channelId, m_inputChannelIds.size())).first;
		m_inputQueues.push_back(MessageQueue());
		m_inputChannelIds.push_back(channelId);

		if (m_inputChannelIds.size() == m_threshold)
			PrepareInterpolation();
	}
	return m_lastMapPosition->second;
}

unsigned int RawIDA::LookupInputChannel(word32 channelId) const
{
	map<word32, unsigned int>::const_iterator it = m_inputChannelMap.find(channelId);
	if (it == m_inputChannelMap.end())
		return m_threshold;
	else
		return it->second;
}

void RawIDA::ChannelData(word32 channelId, const byte *inString, unsigned int length, bool messageEnd)
{
	int i = InsertInputChannel(channelId);
	if (i < m_threshold)
	{
		unsigned long size = m_inputQueues[i].MaxRetrievable();
		m_inputQueues[i].Put(inString, length);
		if (size < 4 && size + length >= 4)
		{
			m_channelsReady++;
			if (m_channelsReady == m_threshold)
				ProcessInputQueues();
		}

		if (messageEnd)
		{
			m_inputQueues[i].MessageEnd();
			if (m_inputQueues[i].NumberOfMessages() == 1)
			{
				m_channelsFinished++;
				if (m_channelsFinished == m_threshold)
				{
					m_channelsReady = 0;
					for (i=0; i<m_threshold; i++)
						m_channelsReady += m_inputQueues[i].AnyRetrievable();
					ProcessInputQueues();
				}
			}
		}
	}
}

unsigned int RawIDA::InputBuffered(word32 channelId) const
{
	int i = LookupInputChannel(channelId);
	return i < m_threshold ? m_inputQueues[i].MaxRetrievable() : 0;
}

void RawIDA::ComputeV(unsigned int i)
{
	if (i >= m_v.size())
	{
		m_v.resize(i+1);
		m_outputToInput.resize(i+1);
	}

	m_outputToInput[i] = LookupInputChannel(m_outputChannelIds[i]);
	if (m_outputToInput[i] == m_threshold && i * m_threshold <= 1000*1000)
	{
		m_v[i].resize(m_threshold);
		PrepareBulkPolynomialInterpolationAt(field, m_v[i].begin(), m_outputChannelIds[i], &(m_inputChannelIds[0]), m_w.begin(), m_threshold);
	}
}

void RawIDA::AddOutputChannel(word32 channelId)
{
	m_outputChannelIds.push_back(channelId);
	m_outputChannelIdStrings.push_back(WordToString(channelId));
	m_outputQueues.push_back(ByteQueue());
	if (m_inputChannelIds.size() == m_threshold)
		ComputeV(m_outputChannelIds.size() - 1);
}

void RawIDA::PrepareInterpolation()
{
	assert(m_inputChannelIds.size() == m_threshold);
	PrepareBulkPolynomialInterpolation(field, m_w.begin(), &(m_inputChannelIds[0]), m_threshold);
	for (unsigned int i=0; i<m_outputChannelIds.size(); i++)
		ComputeV(i);
}

void RawIDA::ProcessInputQueues()
{
	bool finished = (m_channelsFinished == m_threshold);
	int i;

	while (finished ? m_channelsReady > 0 : m_channelsReady == m_threshold)
	{
		m_channelsReady = 0;
		for (i=0; i<m_threshold; i++)
		{
			MessageQueue &queue = m_inputQueues[i];
			queue.GetWord32(m_y[i]);

			if (finished)
				m_channelsReady += queue.AnyRetrievable();
			else
				m_channelsReady += queue.NumberOfMessages() > 0 || queue.MaxRetrievable() >= 4;
		}

		for (i=0; (unsigned int)i<m_outputChannelIds.size(); i++)
		{
			if (m_outputToInput[i] != m_threshold)
				m_outputQueues[i].PutWord32(m_y[m_outputToInput[i]]);
			else if (m_v[i].size() == m_threshold)
				m_outputQueues[i].PutWord32(BulkPolynomialInterpolateAt(field, m_y.begin(), m_v[i].begin(), m_threshold));
			else
			{
				m_u.resize(m_threshold);
				PrepareBulkPolynomialInterpolationAt(field, m_u.begin(), m_outputChannelIds[i], &(m_inputChannelIds[0]), m_w.begin(), m_threshold);
				m_outputQueues[i].PutWord32(BulkPolynomialInterpolateAt(field, m_y.begin(), m_u.begin(), m_threshold));
			}
		}
	}

	if (m_outputChannelIds.size() > 0 && m_outputQueues[0].AnyRetrievable())
		FlushOutputQueues();

	if (finished)
	{
		OutputMessageEnds();

		m_channelsReady = 0;
		m_channelsFinished = 0;
		m_v.clear();

		vector<MessageQueue> inputQueues;
		vector<word32> inputChannelIds;

		inputQueues.swap(m_inputQueues);
		inputChannelIds.swap(m_inputChannelIds);
		m_inputChannelMap.clear();
		m_lastMapPosition = m_inputChannelMap.end();

		for (i=0; i<m_threshold; i++)
		{
			inputQueues[i].GetNextMessage();
			inputQueues[i].TransferAllTo(*AttachedTransformation(), WordToString(inputChannelIds[i]));
		}
	}
}

void RawIDA::FlushOutputQueues()
{
	for (unsigned int i=0; i<m_outputChannelIds.size(); i++)
		m_outputQueues[i].TransferAllTo(*AttachedTransformation(), m_outputChannelIdStrings[i]);
}

void RawIDA::OutputMessageEnds()
{
	if (GetAutoSignalPropagation() != 0)
	{
		for (unsigned int i=0; i<m_outputChannelIds.size(); i++)
			AttachedTransformation()->ChannelMessageEnd(m_outputChannelIdStrings[i], GetAutoSignalPropagation()-1);
	}
}

// ****************************************************************

void SecretSharing::Initialize(const NameValuePairs &parameters, int propagation)
{
	m_pad = parameters.GetValueWithDefault("AddPadding", true);
	m_ida.Initialize(parameters, propagation);
}

unsigned int SecretSharing::Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
{
	if (!blocking)
		throw BlockingInputOnly("SecretSharing");

	SecByteBlock buf(STDMIN(length, 256U));
	unsigned int threshold = m_ida.GetThreshold();
	while (length > 0)
	{
		unsigned int len = STDMIN(length, (unsigned int)buf.size());
		m_ida.ChannelData(0xffffffff, begin, len, false);
		for (unsigned int i=0; i<threshold-1; i++)
		{
			m_rng.GenerateBlock(buf, len);
			m_ida.ChannelData(i, buf, len, false);
		}
		length -= len;
		begin += len;
	}

	if (messageEnd)
	{
		m_ida.SetAutoSignalPropagation(messageEnd-1);
		if (m_pad)
		{
			SecretSharing::Put(1);
			while (m_ida.InputBuffered(0xffffffff) > 0)
				SecretSharing::Put(0);
		}
		m_ida.ChannelData(0xffffffff, NULL, 0, true);
		for (unsigned int i=0; i<m_ida.GetThreshold()-1; i++)
			m_ida.ChannelData(i, NULL, 0, true);
	}

	return 0;
}

void SecretRecovery::Initialize(const NameValuePairs &parameters, int propagation)
{
	m_pad = parameters.GetValueWithDefault("RemovePadding", true);
	RawIDA::Initialize(CombinedNameValuePairs(parameters, MakeParameters("OutputChannelID", (word32)0xffffffff)), propagation);
}

void SecretRecovery::FlushOutputQueues()
{
	if (m_pad)
		m_outputQueues[0].TransferTo(*AttachedTransformation(), m_outputQueues[0].MaxRetrievable()-4);
	else
		m_outputQueues[0].TransferTo(*AttachedTransformation());
}

void SecretRecovery::OutputMessageEnds()
{
	if (m_pad)
	{
		PaddingRemover paddingRemover(new Redirector(*AttachedTransformation()));
		m_outputQueues[0].TransferAllTo(paddingRemover);
	}

	if (GetAutoSignalPropagation() != 0)
		AttachedTransformation()->MessageEnd(GetAutoSignalPropagation()-1);
}

// ****************************************************************

void InformationDispersal::Initialize(const NameValuePairs &parameters, int propagation)
{
	m_nextChannel = 0;
	m_pad = parameters.GetValueWithDefault("AddPadding", true);
	m_ida.Initialize(parameters, propagation);
}

unsigned int InformationDispersal::Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
{
	if (!blocking)
		throw BlockingInputOnly("InformationDispersal");
	
	while (length--)
	{
		m_ida.ChannelData(m_nextChannel, begin, 1, false);
		begin++;
		m_nextChannel++;
		if (m_nextChannel == m_ida.GetThreshold())
			m_nextChannel = 0;
	}

	if (messageEnd)
	{
		m_ida.SetAutoSignalPropagation(messageEnd-1);
		if (m_pad)
			InformationDispersal::Put(1);
		for (word32 i=0; i<m_ida.GetThreshold(); i++)
			m_ida.ChannelData(i, NULL, 0, true);
	}

	return 0;
}

void InformationRecovery::Initialize(const NameValuePairs &parameters, int propagation)
{
	m_pad = parameters.GetValueWithDefault("RemovePadding", true);
	RawIDA::Initialize(parameters, propagation);
}

void InformationRecovery::FlushOutputQueues()
{
	while (m_outputQueues[0].AnyRetrievable())
	{
		for (unsigned int i=0; i<m_outputChannelIds.size(); i++)
			m_outputQueues[i].TransferTo(m_queue, 1);
	}

	if (m_pad)
		m_queue.TransferTo(*AttachedTransformation(), m_queue.MaxRetrievable()-4*m_threshold);
	else
		m_queue.TransferTo(*AttachedTransformation());
}

void InformationRecovery::OutputMessageEnds()
{
	if (m_pad)
	{
		PaddingRemover paddingRemover(new Redirector(*AttachedTransformation()));
		m_queue.TransferAllTo(paddingRemover);
	}

	if (GetAutoSignalPropagation() != 0)
		AttachedTransformation()->MessageEnd(GetAutoSignalPropagation()-1);
}

unsigned int PaddingRemover::Put2(const byte *begin, unsigned int length, int messageEnd, bool blocking)
{
	if (!blocking)
		throw BlockingInputOnly("PaddingRemover");

	const byte *const end = begin + length;

	if (m_possiblePadding)
	{
		unsigned int len = find_if(begin, end, bind2nd(not_equal_to<byte>(), 0)) - begin;
		m_zeroCount += len;
		begin += len;
		if (begin == end)
			return 0;

		AttachedTransformation()->Put(1);
		while (m_zeroCount--)
			AttachedTransformation()->Put(0);
		AttachedTransformation()->Put(*begin++);
		m_possiblePadding = false;
	}

#if defined(_MSC_VER) && !defined(__MWERKS__)
	// VC60 workaround: built-in reverse_iterator has two template parameters, Dinkumware only has one
	typedef reverse_bidirectional_iterator<const byte *, const byte> rit;
#else
	typedef reverse_iterator<const byte *> rit;
#endif
	const byte *x = find_if(rit(end), rit(begin), bind2nd(not_equal_to<byte>(), 0)).base();
	if (x != begin && *(x-1) == 1)
	{
		AttachedTransformation()->Put(begin, x-begin-1);
		m_possiblePadding = true;
		m_zeroCount = end - x;
	}
	else
		AttachedTransformation()->Put(begin, end-begin);

	if (messageEnd)
	{
		m_possiblePadding = false;
		Output(0, begin, length, messageEnd, blocking);
	}
	return 0;
}

NAMESPACE_END

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
色999日韩国产欧美一区二区| 免费人成精品欧美精品| 成人国产精品免费网站| 国产精品免费免费| 色婷婷精品久久二区二区蜜臂av | 国产综合一区二区| 国产日产欧美一区二区三区| 不卡电影免费在线播放一区| 亚洲人亚洲人成电影网站色| 欧美性大战久久久久久久| 日产精品久久久久久久性色| 欧美不卡视频一区| 成人18视频日本| 亚洲午夜视频在线| 久久综合久色欧美综合狠狠| 99精品欧美一区二区三区综合在线| 中文字幕亚洲综合久久菠萝蜜| 91成人免费在线| 久久精品国产99| 综合激情成人伊人| 91精选在线观看| 国产精品123区| 亚洲国产精品久久一线不卡| 精品久久久三级丝袜| 不卡高清视频专区| 男女性色大片免费观看一区二区| 国产日产精品一区| 欧美性色黄大片| 国产在线观看一区二区| 亚洲精品乱码久久久久久 | 欧美视频一区在线| 精品一区二区三区在线观看 | 亚洲成av人综合在线观看| 久久久久亚洲蜜桃| 欧美色精品天天在线观看视频| 国产一区二区精品久久| 五月激情综合色| 国产精品久久久久婷婷| 欧美成人乱码一区二区三区| 欧洲亚洲精品在线| 国产成人亚洲综合a∨猫咪| 高清成人在线观看| 日本三级亚洲精品| 亚洲伊人色欲综合网| 中文字幕av一区二区三区| 欧美一级国产精品| 欧美色区777第一页| 成人精品高清在线| 久久国内精品自在自线400部| 亚洲黄色av一区| 国产亚洲欧美一区在线观看| 制服丝袜在线91| 欧美色网站导航| 一本一道综合狠狠老| 成人性生交大合| 蜜臀精品一区二区三区在线观看 | 国产精品丝袜久久久久久app| 日韩精品在线看片z| 欧美日韩在线播放一区| 99精品视频一区| 波多野结衣精品在线| 国产精品一线二线三线| 国产一区二区三区电影在线观看 | 一区二区三区欧美久久| 国产精品福利一区二区三区| 国产女同性恋一区二区| 久久精品视频在线看| 久久久久久99精品| 久久久99精品久久| 久久久精品综合| 久久久99久久| 中文字幕国产精品一区二区| 国产片一区二区三区| 国产欧美一区二区精品婷婷| 久久久不卡网国产精品一区| 久久综合丝袜日本网| 国产亚洲制服色| 国产精品婷婷午夜在线观看| 国产精品美女久久久久久久久久久 | 欧美激情一区二区| 国产一区二区精品久久| 精品一区二区三区免费| 老司机精品视频线观看86| 欧美aaaaaa午夜精品| 久久99国产精品久久99| 经典三级视频一区| 国产美女精品在线| 国产精品1区2区3区在线观看| 国产麻豆精品一区二区| 懂色av中文字幕一区二区三区| 国产精品亚洲第一区在线暖暖韩国 | 中文字幕av一区二区三区免费看 | 国内成人自拍视频| 久久成人精品无人区| 国产一区二区在线视频| 不卡视频一二三四| 欧美综合色免费| 欧美军同video69gay| 日韩免费看网站| 国产人久久人人人人爽| 亚洲欧洲美洲综合色网| 亚洲成人一二三| 老司机午夜精品99久久| 成人妖精视频yjsp地址| 91麻豆免费观看| 欧美一级欧美一级在线播放| 久久青草国产手机看片福利盒子 | ㊣最新国产の精品bt伙计久久| 亚洲美女免费在线| 99在线热播精品免费| 欧美美女一区二区在线观看| 久久久天堂av| 亚洲综合色自拍一区| 老司机午夜精品| www..com久久爱| 日韩欧美一二三区| 国产精品家庭影院| 日本在线播放一区二区三区| 成人网男人的天堂| 91精品国产综合久久婷婷香蕉 | av在线一区二区| 欧美一区二区三区四区久久| 国产精品乱子久久久久| 日韩高清欧美激情| 91在线你懂得| 精品久久久久久久久久久久久久久久久| 亚洲欧洲日产国产综合网| 麻豆高清免费国产一区| 色94色欧美sute亚洲13| 久久久亚洲精品石原莉奈 | 亚洲理论在线观看| 久久激情五月激情| 欧美日韩美女一区二区| 国产欧美一区二区精品性| 日韩av不卡一区二区| 色噜噜久久综合| 中文字幕+乱码+中文字幕一区| 五月婷婷综合在线| 94-欧美-setu| 国产日韩欧美一区二区三区乱码| 日本不卡视频在线观看| 91高清视频免费看| 中文字幕在线不卡国产视频| 国产露脸91国语对白| 欧美日韩国产精品成人| 综合激情成人伊人| 成人一区二区视频| 久久久久久亚洲综合影院红桃 | 国产欧美精品一区二区色综合| 免费成人深夜小野草| 91.com视频| 亚洲图片欧美视频| 欧洲精品在线观看| 亚洲欧美日韩国产成人精品影院| 国产91精品免费| 国产日本欧美一区二区| 国产伦理精品不卡| 日韩精品自拍偷拍| 久久精品国产秦先生| 日韩一级大片在线| 青青草国产成人av片免费| 欧美一区二区三区男人的天堂| 亚洲国产日产av| 欧美日韩亚洲综合在线| 亚洲第一会所有码转帖| 欧美综合亚洲图片综合区| 亚洲激情第一区| 欧美三区在线视频| 午夜a成v人精品| 日韩免费看的电影| 激情五月播播久久久精品| 国产网站一区二区| 99综合影院在线| 一区二区三区91| 欧美喷潮久久久xxxxx| 日韩av高清在线观看| 欧美成人女星排行榜| 国产精品自在在线| 国产精品全国免费观看高清| 成人精品小蝌蚪| 一区二区三区四区在线播放| 欧美午夜宅男影院| 天涯成人国产亚洲精品一区av| 91精品国产麻豆| 国产激情视频一区二区在线观看| 中文字幕精品综合| 91精品1区2区| 日本亚洲三级在线| 国产亚洲午夜高清国产拍精品| 成人app在线| 调教+趴+乳夹+国产+精品| 精品久久久久久久久久久久久久久 | 毛片av中文字幕一区二区| 国产欧美一区二区三区网站 | 国产精品美女久久久久aⅴ | 欧美色偷偷大香| 国产一区二区久久| 亚洲美女免费视频| 精品播放一区二区| 色久综合一二码|