size_t BufferedTransformation::Get(byte *outString, size_t getMax) { if (AttachedTransformation()) return AttachedTransformation()->Get(outString, getMax); else { ArraySink arraySink(outString, getMax); return (size_t)TransferTo(arraySink, getMax); } }
size_t BufferedTransformation::Peek(byte *outString, size_t peekMax) const { if (AttachedTransformation()) return AttachedTransformation()->Peek(outString, peekMax); else { ArraySink arraySink(outString, peekMax); return (size_t)CopyTo(arraySink, peekMax); } }
bool BufferedTransformation::AnyRetrievable() const { if (AttachedTransformation()) return AttachedTransformation()->AnyRetrievable(); else { byte b; return Peek(b) != 0; } }
void InformationRecovery::OutputMessageEnds() { if (m_pad) { PaddingRemover paddingRemover(new Redirector(*AttachedTransformation())); m_queue.TransferAllTo(paddingRemover); } if (GetAutoSignalPropagation() != 0) AttachedTransformation()->MessageEnd(GetAutoSignalPropagation()-1); }
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 VDA_CBCNotPaddedDecryptor_3_2::NextPut(const byte *inString, unsigned int) { cipher.ProcessBlock(inString, buffer); xorbuf(buffer, reg, S); AttachedTransformation()->Put(buffer, S); memcpy(reg, inString, S); }
void RawIDA::ProcessInputQueues() { bool finished = (m_channelsFinished == size_t(m_threshold)); unsigned int i; while (finished ? m_channelsReady > 0 : m_channelsReady == size_t(m_threshold)) { m_channelsReady = 0; for (i=0; i<size_t(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] != size_t(m_threshold)) m_outputQueues[i].PutWord32(m_y[m_outputToInput[i]]); else if (m_v[i].size() == size_t(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(); std::vector<MessageQueue> inputQueues; std::vector<word32> inputChannelIds; inputQueues.swap(m_inputQueues); inputChannelIds.swap(m_inputChannelIds); m_inputChannelMap.clear(); m_lastMapPosition = m_inputChannelMap.end(); for (i=0; i<size_t(m_threshold); i++) { inputQueues[i].GetNextMessage(); inputQueues[i].TransferAllTo(*AttachedTransformation(), WordToString(inputChannelIds[i])); } } }
void MeterFilter::Put(const byte *inString, unsigned int length) { m_currentMessageBytes += length; m_totalBytes += length; if (m_transparent) AttachedTransformation()->Put(inString, length); }
void HashFilter::MessageEnd(int propagation) { SecByteBlock buf(m_hashModule.DigestSize()); m_hashModule.Final(buf); AttachedTransformation()->Put(buf, buf.size); Filter::MessageEnd(propagation); }
void MeterFilter::Put(byte inByte) { m_currentMessageBytes++; m_totalBytes++; if (m_transparent) AttachedTransformation()->Put(inByte); }
size_t PaddingRemover::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) { if (!blocking) throw BlockingInputOnly("PaddingRemover"); const byte *const end = begin + length; if (m_possiblePadding) { size_t len = std::find_if(begin, end, std::bind2nd(std::not_equal_to<byte>(), 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) && (_MSC_VER <= 1300) && !defined(__MWERKS__) // VC60 and VC7 workaround: built-in reverse_iterator has two template parameters, Dinkumware only has one typedef std::reverse_bidirectional_iterator<const byte *, const byte> RevIt; #elif defined(_RWSTD_NO_CLASS_PARTIAL_SPEC) typedef std::reverse_iterator<const byte *, std::random_access_iterator_tag, const byte> RevIt; #else typedef std::reverse_iterator<const byte *> RevIt; #endif const byte *x = std::find_if(RevIt(end), RevIt(begin), std::bind2nd(std::not_equal_to<byte>(), 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; }
void SignerFilter::MessageEnd(int propagation) { SecByteBlock buf(m_signer.SignatureLength()); m_signer.Sign(m_rng, m_messageAccumulator.release(), buf); AttachedTransformation()->Put(buf, buf.size); Filter::MessageEnd(propagation); m_messageAccumulator.reset(m_signer.NewMessageAccumulator()); }
unsigned int Filter::OutputModifiable(int outputSite, byte *inString, unsigned int length, int messageEnd, bool blocking, const std::string &channel) { if (messageEnd) messageEnd--; unsigned int result = AttachedTransformation()->PutModifiable2(inString, length, messageEnd, blocking); m_continueAt = result ? outputSite : 0; return result; }
size_t Filter::Output(int outputSite, const byte *inString, size_t length, int messageEnd, bool blocking, const std::string &channel) { if (messageEnd) messageEnd--; size_t result = AttachedTransformation()->ChannelPut2(channel, inString, length, messageEnd, blocking); m_continueAt = result ? outputSite : 0; return result; }
void RawIDA::OutputMessageEnds() { if (GetAutoSignalPropagation() != 0) { for (unsigned int i=0; i<m_outputChannelIds.size(); i++) AttachedTransformation()->ChannelMessageEnd(m_outputChannelIdStrings[i], GetAutoSignalPropagation()-1); } }
void HashVerifier::FirstPut(const byte *inString) { if (m_flags & HASH_AT_BEGIN) { memcpy(m_expectedHash, inString, m_expectedHash.size); if (m_flags & PUT_HASH) AttachedTransformation()->Put(inString, m_expectedHash.size); } }
bool Filter::OutputMessageSeriesEnd(int outputSite, int propagation, bool blocking, const std::string &channel) { if (propagation && AttachedTransformation()->ChannelMessageSeriesEnd(channel, propagation-1, blocking)) { m_continueAt = outputSite; return true; } m_continueAt = 0; return false; }
void HashVerificationFilter::FirstPut(const byte *inString) { if (m_flags & HASH_AT_BEGIN) { m_expectedHash.New(m_hashModule.DigestSize()); memcpy(m_expectedHash, inString, m_expectedHash.size()); if (m_flags & PUT_HASH) AttachedTransformation()->Put(inString, m_expectedHash.size()); } }
bool Filter::OutputFlush(int outputSite, bool hardFlush, int propagation, bool blocking, const std::string &channel) { if (propagation && AttachedTransformation()->ChannelFlush(channel, hardFlush, propagation-1, blocking)) { m_continueAt = outputSite; return true; } m_continueAt = 0; return false; }
void HashVerificationFilter::LastPut(const byte *inString, size_t length) { if (m_flags & HASH_AT_BEGIN) { assert(length == 0); m_verified = m_hashModule.TruncatedVerify(m_expectedHash, m_digestSize); } else { m_verified = (length==m_digestSize && m_hashModule.TruncatedVerify(inString, length)); if (m_flags & PUT_HASH) AttachedTransformation()->Put(inString, length); } if (m_flags & PUT_RESULT) AttachedTransformation()->Put(m_verified); if ((m_flags & THROW_EXCEPTION) && !m_verified) throw HashVerificationFailed(); }
void SignatureVerificationFilter::LastPut(const byte *inString, unsigned int length) { if (m_flags & SIGNATURE_AT_BEGIN) { assert(length == 0); m_verified = m_verifier.Verify(m_messageAccumulator.release(), m_signature); } else { m_verified = (length==m_verifier.SignatureLength() && m_verifier.Verify(m_messageAccumulator.release(), inString)); if (m_flags & PUT_SIGNATURE) AttachedTransformation()->Put(inString, length); } if (m_flags & PUT_RESULT) AttachedTransformation()->Put(m_verified); if ((m_flags & THROW_EXCEPTION) && !m_verified) throw SignatureVerificationFailed(); }
void SignatureVerificationFilter::LastPut(const byte *inString, size_t length) { if (m_flags & SIGNATURE_AT_BEGIN) { assert(length == 0); m_verifier.InputSignature(*m_messageAccumulator, m_signature, m_signature.size()); m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator); } else { m_verifier.InputSignature(*m_messageAccumulator, inString, length); m_verified = m_verifier.VerifyAndRestart(*m_messageAccumulator); if (m_flags & PUT_SIGNATURE) AttachedTransformation()->Put(inString, length); } if (m_flags & PUT_RESULT) AttachedTransformation()->Put(m_verified); if ((m_flags & THROW_EXCEPTION) && !m_verified) throw SignatureVerificationFailed(); }
size_t PaddingRemover::Put2(const byte *begin, size_t length, int messageEnd, bool blocking) { if (!blocking) throw BlockingInputOnly("PaddingRemover"); const byte *const end = begin + length; if (m_possiblePadding) { size_t len = std::find_if(begin, end, std::bind2nd(std::not_equal_to<byte>(), 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; } const byte *x = std::find_if(RevIt(end), RevIt(begin), std::bind2nd(std::not_equal_to<byte>(), 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; }
void NetworkSource::GetWaitObjects(WaitObjectContainer &container, CallStack const& callStack) { if (BlockedBySpeedLimit()) LimitedBandwidth::GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - speed limit", &callStack)); else if (!m_outputBlocked) { if (m_dataBegin == m_dataEnd) AccessReceiver().GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - no data", &callStack)); else container.SetNoWait(CallStack("NetworkSource::GetWaitObjects() - have data", &callStack)); } AttachedTransformation()->GetWaitObjects(container, CallStack("NetworkSource::GetWaitObjects() - attachment", &callStack)); }
void Gzip::WritePrestreamHeader() { m_totalLen = 0; m_crc.Restart(); AttachedTransformation()->Put(MAGIC1); AttachedTransformation()->Put(MAGIC2); AttachedTransformation()->Put(DEFLATED); AttachedTransformation()->Put(0); // general flag AttachedTransformation()->PutWord32(0); // time stamp byte extra = (GetDeflateLevel() == 1) ? FAST : ((GetDeflateLevel() == 9) ? SLOW : 0); AttachedTransformation()->Put(extra); AttachedTransformation()->Put(GZIP_OS_CODE); }
size_t HashFilter::Put2(const byte *inString, size_t length, int messageEnd, bool blocking) { FILTER_BEGIN; if (m_putMessage) FILTER_OUTPUT3(1, 0, inString, length, 0, m_messagePutChannel); m_hashModule.Update(inString, length); if (messageEnd) { { size_t size; m_space = HelpCreatePutSpace(*AttachedTransformation(), m_hashPutChannel, m_digestSize, m_digestSize, size = m_digestSize); m_hashModule.TruncatedFinal(m_space, m_digestSize); } FILTER_OUTPUT3(2, 0, m_space, m_digestSize, messageEnd, m_hashPutChannel); } FILTER_END_NO_MESSAGE_END; }
unsigned int HashFilter::Put2(const byte *inString, unsigned int length, int messageEnd, bool blocking) { FILTER_BEGIN; m_hashModule.Update(inString, length); if (m_putMessage) FILTER_OUTPUT(1, inString, length, 0); if (messageEnd) { { unsigned int size, digestSize = m_hashModule.DigestSize(); m_space = HelpCreatePutSpace(*AttachedTransformation(), NULL_CHANNEL, digestSize, digestSize, size = digestSize); m_hashModule.Final(m_space); } FILTER_OUTPUT(2, m_space, m_hashModule.DigestSize(), messageEnd); } FILTER_END_NO_MESSAGE_END; }
void Inflator::ProcessInput(bool flush) { while (true) { if (m_inQueue.IsEmpty()) return; switch (m_state) { case PRE_STREAM: if (!flush && m_inQueue.CurrentSize() < MaxPrestreamHeaderSize()) return; ProcessPrestreamHeader(); m_state = WAIT_HEADER; m_maxDistance = 0; m_current = 0; m_lastFlush = 0; m_window.Resize(1 << GetLog2WindowSize()); break; case WAIT_HEADER: { // maximum number of bytes before actual compressed data starts const unsigned int MAX_HEADER_SIZE = bitsToBytes(3+5+5+4+19*7+286*15+19*15); if (m_inQueue.CurrentSize() < (flush ? 1 : MAX_HEADER_SIZE)) return; DecodeHeader(); break; } case DECODING_BODY: if (!DecodeBody()) return; break; case POST_STREAM: if (!flush && m_inQueue.CurrentSize() < MaxPoststreamTailSize()) return; ProcessPoststreamTail(); m_state = m_repeat ? PRE_STREAM : AFTER_END; Filter::MessageEnd(GetAutoSignalPropagation()); break; case AFTER_END: m_inQueue.TransferTo(*AttachedTransformation()); return; } } }
void VDA_CBCNotPaddedEncryptor_3_2::LastPut(const byte *inString, unsigned int length) { // pad last block assert(length < (unsigned int)S); xorbuf(reg, inString, length); /* byte pad = S-length; for (unsigned int i=0; i<pad; i++) reg[length+i] ^= pad; */ if (length) { cipher.ProcessBlock(reg); //AttachedTransformation()->Put(reg, S); AttachedTransformation()->Put(reg, length); } }
void Inflator::ProcessInput(bool flush) { while (true) { switch (m_state) { case PRE_STREAM: if (!flush && m_inQueue.CurrentSize() < MaxPrestreamHeaderSize()) return; ProcessPrestreamHeader(); m_state = WAIT_HEADER; m_wrappedAround = false; m_current = 0; m_lastFlush = 0; m_window.New(1 << GetLog2WindowSize()); break; case WAIT_HEADER: { // maximum number of bytes before actual compressed data starts const size_t MAX_HEADER_SIZE = BitsToBytes(3+5+5+4+19*7+286*15+19*15); if (m_inQueue.CurrentSize() < (flush ? 1 : MAX_HEADER_SIZE)) return; DecodeHeader(); break; } case DECODING_BODY: if (!DecodeBody()) return; break; case POST_STREAM: if (!flush && m_inQueue.CurrentSize() < MaxPoststreamTailSize()) return; ProcessPoststreamTail(); m_state = m_repeat ? PRE_STREAM : AFTER_END; Output(0, NULL, 0, GetAutoSignalPropagation(), true); // TODO: non-blocking if (m_inQueue.IsEmpty()) return; break; case AFTER_END: m_inQueue.TransferTo(*AttachedTransformation()); return; } } }