OutputAESEncodeStream::OutputAESEncodeStream(IByteWriterWithPosition* inTargetStream, const ByteList& inEncryptionKey, bool inOwnsStream) { mTargetStream = inTargetStream; mOwnsStream = inOwnsStream; if (!mTargetStream) return; mInIndex = mIn; // convert inEncryptionKey to internal rep and init encrypt [let's hope its 16...] mEncryptionKey = new unsigned char[inEncryptionKey.size()]; mEncryptionKeyLength = inEncryptionKey.size(); ByteList::const_iterator it = inEncryptionKey.begin(); size_t i = 0; for (; it != inEncryptionKey.end(); ++i, ++it) mEncryptionKey[i] = *it; mEncrypt.key(mEncryptionKey, mEncryptionKeyLength); // create IV and write it to output file [use existing PDFDate] MD5Generator md5; // encode current time PDFDate currentTime; currentTime.SetToCurrentTime(); md5.Accumulate(currentTime.ToString()); memcpy(mIV, (const unsigned char*)md5.ToStringAsString().c_str(),AES_BLOCK_SIZE); // md5 should give us the desired 16 bytes // now write mIV to the output stream mTargetStream->Write(mIV, AES_BLOCK_SIZE); }
void InputAESDecodeStream::Assign(IByteReader* inSourceReader, const ByteList& inKey) { mSourceStream = inSourceReader; // convert inEncryptionKey to internal rep and init decrypt [let's hope its 16...] mKeyLength = inKey.size(); mKey = new unsigned char[mKeyLength]; ByteList::const_iterator it = inKey.begin(); size_t i = 0; for (; it != inKey.end(); ++i, ++it) mKey[i] = *it; mDecrypt.key(mKey, mKeyLength); mIsIvInit = false; // first read flag. still need to read IV mReadBlockSize = AES_BLOCK_SIZE; mOutIndex = mOut + mReadBlockSize; mHitEnd = false; }
static void fuzzPacket(const char *hex, size_t start = 0) { ByteList buf{HexToRawData(hex)}; ByteList result; EXPECT_GE(buf.size(), 14); // Insert two zero bytes at the beginning. MatchPacket expects packet data // to be aligned at 2 bytes past the 8-byte alignment. buf.insertZeros(buf.begin(), 2); const UInt8 kFuzzValues[] = {0x00, 0xFF}; // Mutate each byte one at a time. for (size_t i = start + 2; i < buf.size(); ++i) { UInt8 saved = buf[i]; for (UInt8 val : kFuzzValues) { if (buf[i] == val) continue; buf[i] = val; ByteRange pkt{buf.data() + 2, buf.size() - 2}; MatchPacket match{pkt}; EXPECT_GT(match.size(), 0); MatchPacketBuilder builder{match.toRange()}; size_t offset = match.toRange().get<X_PKT_POS>(); if (offset == 0) { offset = buf.size() - 2; } ByteRange remaining = SafeByteRange(buf.data() + 2, buf.size() - 2, offset); result.clear(); builder.build(&result, remaining); EXPECT_GT(result.size(), 0); } buf[i] = saved; } }
int EmClipboardWidget::handle (int event) { // It's a "paste" event, meaning that our application has requested // data to paste, and it just showed up from the X server. if (event == FL_PASTE) { // Get exclusive access to our clipboard data. omni_mutex_lock lock (gClipboardMutex); // Say that the data is here. gClipboardPendingIncomingData = false; gClipboardHaveIncomingData = true; // Copy the data to the host data clipboard. The Palm-specific // clipboard will remain empty, and the host data will get // convert to it on demand. gClipboardDataPalm.clear (); gClipboardDataHost.clear (); copy ((char*) Fl::e_text, (char*) Fl::e_text + Fl::e_length, back_inserter (gClipboardDataHost)); // Tell the CPU thread that the new data is here. gClipboardCondition.broadcast (); // Return that we handled the event. return 1; } // Return that we didn't handle the event. return 0; }
void MatchPacketBuilder::buildICMPv6_ND(ByteList *msg) const { assert(icmpType_ == ICMPV6_TYPE_NEIGHBOR_SOLICIT || icmpType_ == ICMPV6_TYPE_NEIGHBOR_ADVERTISE); Big8 hdr[2]; hdr[0] = (icmpType_ == ICMPV6_TYPE_NEIGHBOR_SOLICIT) ? ICMPV6_OPTION_SLL : ICMPV6_OPTION_TLL; hdr[1] = 1; // length in 8-octet units ByteList buf; Big32 ndRes = (icmpType_ == ICMPV6_TYPE_NEIGHBOR_ADVERTISE) ? ndRes_ : 0; buf.add(&ndRes, sizeof(ndRes)); buf.add(&ndTarget_, sizeof(ndTarget_)); buf.add(&hdr[0], sizeof(hdr)); buf.add(&ndLl_, sizeof(ndLl_)); buildICMPv6(msg, buf.toRange()); }
void Normalize::normalizeQueueGetConfigReplyV2() { // Pad all queues to a multiple of 8. You can only get a queue whose size is // not a multiple of 8 if it contains an experimenter property with an // unusual length. Header *hdr = header(); size_t length = hdr->length(); if (length < sizeof(QueueGetConfigReply)) return; ByteRange data = SafeByteRange(buf_.mutableData(), buf_.size(), sizeof(QueueGetConfigReply)); size_t remaining = data.size(); const UInt8 *ptr = data.data(); ByteList newBuf; while (remaining > 16) { // Read 16-bit queue length from a potentially mis-aligned position. UInt16 queueLen = Big16_unaligned(ptr + 8); if (queueLen > remaining || queueLen < 16) return; // Copy queue header. newBuf.add(ptr, 16); // Iterate over properties and pad out the properties whose sizes are not // multiples of 8. const UInt8 *prop = ptr + 16; size_t propLeft = queueLen - 16; while (propLeft > 4) { UInt16 propSize = Big16_unaligned(prop + 2); if (propSize > propLeft || propSize < 4) return; newBuf.add(prop, propSize); if ((propSize % 8) != 0) { newBuf.addZeros(PadLength(propSize) - propSize); } prop += propSize; propLeft -= propSize; } if (propLeft != 0) { log_debug("normalizeQueueGetConfigReplyV2: propLeft != 0"); return; } ptr += queueLen; assert(prop == ptr); remaining -= queueLen; } if (remaining != 0) { log_debug("normalizeQueueGetConfigReplyV2: remaining != 0"); return; } // When padding the regular `Queue` structure, we may exceed the max // message size of 65535. if (newBuf.size() > 65535 - sizeof(QueueGetConfigReply)) { markInputTooBig("QueueGetConfigReply is too big"); return; } buf_.replace(data.begin(), data.end(), newBuf.data(), newBuf.size()); }