int BigNum::intoBinary(RawBuffer &buffer) const { int len = (bitLength(*this)+7)/8; buffer.erase(); int pos = 0; int bitpos = 0; // Index in reverse to get LSB first for (int i = len-1; i >= 0; --i) { int b = (((unsigned int)n[pos] >> bitpos) & 0xFFL); bitpos += 8; if (bitpos >= BITS) { bitpos -= BITS; pos++; if (bitpos > 0) b |= (n[pos] << (8-bitpos)) & 0xFFL; } buffer.insert((int)0,1,(unsigned char)b); } if(!negative && (char)buffer[0] < 0) buffer.insert((int)0,1,(unsigned char)0); return len; }
void BigNum::fromBinary(const RawBuffer &buffer) { negative = false; // Can't init negatives yet int alen = (buffer.length()*8 + BITS-1) / BITS; grow(*this, alen, false); len = alen; int pos = 0; n[pos] = 0; int bitpos = 0; // Index in reverse to get LSB first for (int i = buffer.length()-1; i >= 0; --i) { word b = buffer[i] & 0xFF; n[pos] |= (b << bitpos); bitpos += 8; if (bitpos >= BITS && i>0) { pos++; n[pos] = 0; bitpos -= BITS; if (bitpos > 0) n[pos] = b >> (8-bitpos); } }
size_t BufferChain::write(const char *data, size_t size) { RawBuffer *buf = _lastAvail; size_t nLeft = size; size_t nw = 0; //the buffer chain is empty if ((!buf && _chain.empty()) || buf->isFull()) { buf = addNewBuffer(); } do { nw = buf->write(data, nLeft); nLeft -= nw; data += nw; //if the current buffer is full if (buf->isFull()) { buf = addNewBuffer(); } } while (nLeft > 0); _totalBytes += (size - nLeft); return size - nLeft; }
void AuthContext::AppendHashes(WriteBuffer &theBuf, const RawBuffer &theChallengeSeed) { AutoCrit aCrit(mDataCrit); int aNumHashes = 0; int aNumHashPos = theBuf.length(); theBuf.SkipBytes(1); // put num hashes here AuthLoginCommunityMap::iterator anItr = mCommunityMap.begin(); while(anItr!=mCommunityMap.end()) { AuthLoginCommunityData &aData = anItr->second; if(!aData.mSimpleHash.empty()) { MD5Digest aKeyedHash; aKeyedHash.update(theChallengeSeed); aKeyedHash.update(aData.mKeyedHashData); RawBuffer aKeyedHashBuf = aKeyedHash.digest(); theBuf.AppendByte(1); // hash tag theBuf.AppendWString(anItr->first); // community theBuf.AppendBytes(aData.mSimpleHash.data(),aData.mSimpleHash.length()); theBuf.AppendBytes(aKeyedHashBuf.data(),aKeyedHashBuf.length()); aNumHashes++; } ++anItr; } theBuf.SetByte(aNumHashPos,aNumHashes); }
void DmaBufferedUart::packDmaArgs(DmaChannel::StreamDefinition&def, RawBuffer&rb, int subset ){ def.device = &Uart::dcb->DR; def.devicesize = 2; //uart allows for 9 bit words, like 8051 multidrop protocol or forced parity def.buffer = rb.item(0); def.numItems = subset > 0 ? subset : rb.length(); def.itemsize = rb.itemSize(); }
// ClientCDKey::CreateSymmetricKey // Creates a symmetric key from product name used to save/load CD-Key to/from // the registry. Symmetric key is created via a series of CRCs on the product. void ClientCDKey::CreateSymmetricKey(BFSymmetricKey& theSymKeyR) const { WTRACE("ClientCDKey::CreateSymmetricKey"); WDBG_LL("ClientCDKey::CreateSymmetricKey from product=" << mProduct); CRC16 aCRC; RawBuffer aBuf; // CRC the product and use it as 1st 2 bytes of key aCRC.Put(mProduct); unsigned short aCheckSum = aCRC.GetCRC(); WDBG_LL("ClientCDKey::CreateSymmetricKey First CRC=" << aCheckSum); aBuf.assign(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum)); // CRC each of 1st 3 chars of product and add them to key. for (int i=0; (i < 3) && (i < mProduct.size()); i++) { aCRC.Put(static_cast<unsigned char>(mProduct[i])); aCheckSum = aCRC.GetCRC(); WDBG_LL("ClientCDKey::CreateSymmetricKey Add CRC=" << aCheckSum); aBuf.append(reinterpret_cast<unsigned char*>(&aCheckSum), sizeof(aCheckSum)); } // Create the key WDBG_LL("ClientCDKey::CreateSymmetricKey Buf=" << aBuf); theSymKeyR.Create(aBuf.size(), aBuf.data()); }
int SocketChannel::writeN(const RawBuffer &rb, const CommunicatioInformation &ci) { MutexGuard mg(SessionManager::sockSendMuetx); SOCKADDR_IN addr = {0}; int addrSize = sizeof(addr); addr.sin_family = AF_INET; addr.sin_port = ci.port; addr.sin_addr.S_un.S_addr = ci.hostAddress; return sendto(_sock.getHandle(), (char *)rb.getData(), rb.getLength(), 0, (sockaddr *)&addr, addrSize); }
void CChatView::CreateBoard(const CString& theRoomName) { // Our Document CWhiteBoardDoc* pDoc = (CWhiteBoardDoc*)GetDocument(); // Construct the objects for CreateDataObjectEx RawBuffer aObjectName(OBJ_GAMEPREFIX + (unsigned char*)(LPCSTR)theRoomName); RawBuffer aObject; pDoc->mObserverIds[0] = pDoc->mRoutingServer.GetClientId(); pDoc->mNumObservers = 1; /* only 1 since we just created it */ aObject.assign((unsigned char*)pDoc->mObserverIds); pDoc->mRoutingServer.CreateDataObjectEx(RoutingServerClient::GROUPID_ALLUSERS, aObjectName, pDoc->mRoutingServer.GetClientId(), 0, aObject, (void(*)(short, CChatView*))CreateDataObjectCallback, this); }
unsigned __int64 BigInteger::GetInt64() const { BigInteger r; unsigned __int64 aVal = 0; RawBuffer aBuf = toByteArray(); for(int i=0; i<aBuf.length(); i++) { aVal = (aVal<<8)|aBuf[i]; } return aVal; }
/******************************************************************************** * Subscribe to the game list in the current chat room * ********************************************************************************/ void CChatView::SubscribeDataObjectCallback(const WONAPI::RoutingServerClient::ReadDataObjectResult& theResultR, CChatView* pThat) { // Check the result from SubscribeDataObject switch (theResultR.mStatus) { case StatusCommon_Success: { // List retrieved pThat->DisplayText("<System> Subscribed to game list successfully\r\n"); for (std::list<RoutingServerClient::DataObject>::const_iterator itr = theResultR.mDataObjectList.begin(); itr != theResultR.mDataObjectList.end(); itr++) { // Store the games in our GameMap string gamename = (char*)itr->mDataType.data() + OBJ_GAMEPREFIX.size(); ((CWhiteBoardDoc*)pThat->GetDocument())->mGameMap[gamename] = *itr; } break; } case StatusRouting_SubscriptionAlreadyExists: pThat->DisplayText("<System> ***ERROR Attemp to subscribe twice***\r\n"); break; default: pThat->DisplayText("<System> ***ERROR Failed to retrieve game list***\r\n"); break; } };
int SocketChannel::readN(RawBuffer &rb) { int hasRecvCounts = 0; char buffer[MAX_BUFFER_LENGTH] = {0}; int result = 0; while ((result = recv((SOCKET)_sock.getHandle(), buffer + hasRecvCounts, MAX_BUFFER_LENGTH - hasRecvCounts, 0))) { if (result < 0) { if (errno == EWOULDBLOCK) { break; }else if ( errno == EINTR) { break; } }else if (result == 0) { break; } hasRecvCounts += result; } result = handleResultErrorResult(result); if (result > 0) { rb.setRawData((unsigned char *)buffer, (unsigned int)hasRecvCounts); result = hasRecvCounts; } return result; }
/******************************************************************************** * Whenever the mouse moves. We need to track the path of each stroke * ********************************************************************************/ void CWhiteBoardView::OnLButtonUp(UINT nFlags, CPoint point) { // Our Document CWhiteBoardDoc* pDoc = GetDocument(); // If we're not drawing we don't need to process a mouse release if (bIsDrawing==false) { CScrollView::OnLButtonUp(nFlags, point); return; } // Finish the stroke // If we're connected to a board room let's relay this stroke to any observers if (pDoc->bOnBoard) { // Allocate a linear buffer for data storage (5 = size of message header) int buf_size = pDoc->m_pCurStroke->GetSize(); unsigned char* pDataBuffer = new unsigned char[buf_size]; // Store the stroke data into the buffer pDoc->m_pCurStroke->StoreToBuffer(pDataBuffer); // Copy the character buffer into a server readable rawbuffer for net transfer RawBuffer theRawBuf; theRawBuf.assign(pDataBuffer, buf_size); // Relay the stroke to all observers pDoc->mRoutingServer.SendData(pDoc->mObserverIds, pDoc->mNumObservers, true, theRawBuf, false); // delete our linear buffer delete[] pDataBuffer; } // Release the mouse, we don't need it anymore ReleaseCapture(); // No Longer Drawing bIsDrawing = false; pDoc->m_pCurStroke = NULL; // Call the base class implementation CScrollView::OnLButtonUp(nFlags, point); }
EGPublicKey::CryptReturn EGPublicKey::Encrypt(const void* theMsgP, unsigned long theLen) const { if ((! theMsgP) || (theLen == 0)) { return CryptReturn(NULL,0); } RawBuffer anEncrypt; if(!mElGamal.encrypt(theMsgP,theLen,anEncrypt)) return CryptReturn(NULL,0); unsigned char *anOutP = new unsigned char[anEncrypt.length()]; memcpy(anOutP,anEncrypt.data(),anEncrypt.length()); return CryptReturn(anOutP,anEncrypt.length()); }
bool ElGamal::EncodeDigest(const RawBuffer& digest, BigInteger &h) const { IntegerExtractor aDecoder(digest.data(),digest.length(),false); if(digest.length()*8 < q.bitLength()) { if(!aDecoder.Decode(digest.length(),h)) return false; } else { if(!aDecoder.Decode(q.byteLength(),h)) return false; h = h.shiftRight(q.byteLength()*8 - q.bitLength() + 1); } return true; }
KeyAESImpl::KeyAESImpl(const RawBuffer &buf) : m_key(buf) { // buf stores bytes -> compare the bit sizes switch (buf.size() * 8) { case 128: case 192: case 256: break; default: throw std::invalid_argument("invalid AES key size"); } }
bool AuthContext::LoadVerifierKey(const std::string &theFile) { mCheckedVerifierFile = true; FILE *aFile = fopen(theFile.c_str(),"rb"); if(aFile==NULL) return false; unsigned char aBuf[1024]; RawBuffer aKeyBuf; while(!feof(aFile)) { int aNumRead = fread(aBuf,1,1024,aFile); if(aNumRead>0) aKeyBuf.append(aBuf,aNumRead); } fclose(aFile); AutoCrit aCrit(GetVerifierCrit()); return mVerifierKey.SetPublicKey(aKeyBuf.data(),aKeyBuf.length()); }
int SocketChannel::readN(RawBuffer &rb, CommunicatioInformation &ci) { char buffer[MAX_READ_BUFFER_SIZE] = {0}; SOCKADDR_IN addr = {0}; int addrSize = sizeof(addr); int result = -1; result = recvfrom(_sock.getHandle(), buffer, MAX_READ_BUFFER_SIZE, 0, (sockaddr *)&addr, &addrSize); if (result > 0) { rb.setRawData((unsigned char *)buffer, result); ci.hostAddress = addr.sin_addr.S_un.S_addr; ci.port = addr.sin_port; ci.setConnectionType(CT_Socket); ci.setSocketMode(SM_UDP); } return result; }
int SocketChannel::writeN(const RawBuffer &rb) { int result = send((SOCKET)_sock.getHandle(), (char *)rb.getData(), rb.getLength(), 0); return handleResultErrorResult(result); }
void Matchmaker::GetTitanServerList() { #ifdef DLLSAMPLE mNewAuthServers.clear(); mNewContestServers.clear(); mNewEventServers.clear(); mNewFirewallServers.clear(); mNewProfileServers.clear(); HWONDATAOBJECT aDataObjectH = WONDataObjectCreate(OBJ_VALIDVERSIONS.c_str(), OBJ_VALIDVERSIONS.size(), NULL, 0); WONError aError = WONDirGetDirectoryW(NULL, mDirServers, mNumDirServers, DIR_TITANSERVER, NULL, NULL, WONDir_GF_DECOMPROOT | WONDir_GF_DECOMPRECURSIVE | WONDir_GF_DECOMPSERVICES | WONDir_GF_ADDTYPE | WONDir_GF_SERVADDNAME | WONDir_GF_SERVADDNETADDR | WONDir_GF_ADDDOTYPE | WONDir_GF_ADDDODATA, &aDataObjectH, 1, TitanServerEntityCallback, this, gRequestTimeout); CopySTLAddressListToArray(mNewAuthServers, &mAuthServers, &mNumAuthServers); CopySTLAddressListToArray(mNewContestServers, &mContestServers, &mNumContestServers); CopySTLAddressListToArray(mNewEventServers, &mEventServers, &mNumEventServers); CopySTLAddressListToArray(mNewFirewallServers, &mFirewallServers, &mNumFirewallServers); CopySTLAddressListToArray(mNewProfileServers, &mProfileServers, &mNumProfileServers); #else DataObjectTypeSet aDataObjectSet; aDataObjectSet.insert(WONCommon::DataObject(OBJ_VALIDVERSIONS)); WONMsg::DirEntityList entityList; Error aError = GetDirectory(NULL, // no identity needed to get TitanServers (after all, the AuthServers are listed in there) mDirServers, mNumDirServers, NULL, DIR_TITANSERVER, &entityList, WONMsg::GF_DECOMPROOT | WONMsg::GF_DECOMPRECURSIVE | WONMsg::GF_DECOMPSERVICES | WONMsg::GF_ADDTYPE | WONMsg::GF_SERVADDNAME | WONMsg::GF_SERVADDNETADDR | WONMsg::GF_ADDDOTYPE | WONMsg::GF_ADDDODATA, aDataObjectSet, 0, 0, gRequestTimeout); switch(aError) { case Error_Success: { delete[] mAuthServers; mNumAuthServers = 0; mAuthServers = new IPSocket::Address[entityList.size()]; delete[] mContestServers; mNumContestServers = 0; mContestServers = new IPSocket::Address[entityList.size()]; delete[] mEventServers; mNumEventServers = 0; mEventServers = new IPSocket::Address[entityList.size()]; delete[] mFirewallServers; mNumFirewallServers = 0; mFirewallServers = new IPSocket::Address[entityList.size()]; delete[] mProfileServers; mNumProfileServers = 0; mProfileServers = new IPSocket::Address[entityList.size()]; DirEntityList::const_iterator aDirEntityListItr = entityList.begin(); for( ; aDirEntityListItr != entityList.end(); ++aDirEntityListItr) { if (aDirEntityListItr->mType == WONMsg::DirEntity::ET_DIRECTORY) { DataObjectTypeSet::const_iterator aDataObjectSetItr = aDirEntityListItr->mDataObjects.begin(); for( ; aDataObjectSetItr != aDirEntityListItr->mDataObjects.end(); ++aDataObjectSetItr) { if (aDataObjectSetItr->GetDataType() == OBJ_VALIDVERSIONS) mValidVersions = reinterpret_cast<const char*>(aDataObjectSetItr->GetData().c_str()); } } else if (aDirEntityListItr->mName == SERVERNAME_AUTH) mAuthServers[mNumAuthServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_CONTEST) mContestServers[mNumContestServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_EVENT) mEventServers[mNumEventServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_FIREWALL) mFirewallServers[mNumFirewallServers++] = IPSocket::Address(*aDirEntityListItr); else if (aDirEntityListItr->mName == SERVERNAME_PROFILE) mProfileServers[mNumProfileServers++] = IPSocket::Address(*aDirEntityListItr); } break; } case StatusDir_DirNotFound: OutputError("Directory containing Titan servers not found"); break; default: OutputError("Failed to get list of Titan servers!", aError); break; } #endif // DLLSAMPLE }
/** original mesh file format. char[3] "MSH" uint8_t mesh count. reserved (2 byte) uint32_t vbo offset by the top of file(32bit alignment). uint32_t vbo byte size(32bit alignment). uint32_t ibo byte size(32bit alignment). [ uint8_t mesh name length. char[mesh name length] mesh name(without zero ternmination). uint8_t material count. padding (4 - (length + 2) % 4) % 4 byte. [ uint32_t ibo offset. uint16_t ibo size(this is the polygon counts, so actual ibo size is 3 times). uint8_t red uint8_t green uint8_t blue uint8_t alpha uint8_t metallic uint8_t roughness ] x (ibo count) ] x (mesh count) uint8_t albedo texture name length. char[albedo texture name length] albedo texture name(without zero ternmination). uint8_t normal texture name length. char[normal texture name length] normal texture name(without zero ternmination). padding (4 - (texture name block size % 4) % 4 byte. vbo vbo data. ibo ibo data. padding (4 - (ibo byte size % 4) % 4 byte. uint16_t bone count. uint16_t animation count. [ RotTrans rotation and translation for the bind pose. int32_t parent bone index. ] x (bone count) [ uint8_t animation name length. char[24] animation name. bool loop flag uint16_t key frame count. float total time. [ float time. [ RotTrans rotation and translation. ] x (bone count) ] x (key frame count) ] x (animation count) */ ImportMeshResult ImportMesh(const RawBuffer& data, GLuint& vbo, GLintptr& vboEnd, GLuint& ibo, GLintptr& iboEnd) { const uint8_t* p = &data[0]; const uint8_t* pEnd = p + data.size(); if (p[0] != 'M' || p[1] != 'S' || p[2] != 'H') { return ImportMeshResult(ImportMeshResult::Result::invalidHeader); } p += 3; const int count = *p; p += 1; /*const uint32_t vboOffset = GetValue(p, 4);*/ p += 4; const uint32_t vboByteSize = GetValue(p, 4); p += 4; const uint32_t iboByteSize = GetValue(p, 4); p += 4; if (p >= pEnd) { return ImportMeshResult(ImportMeshResult::Result::noData); } GLuint iboBaseOffset = iboEnd; ImportMeshResult result(ImportMeshResult::Result::success); result.meshes.reserve(count); for (int i = 0; i < count; ++i) { Mesh m; const uint32_t nameLength = *p++; m.id.assign(p, p + nameLength); p += nameLength; const size_t materialCount = *p++; p += (4 - (nameLength + 2) % 4) % 4; m.materialList.resize(materialCount); for (auto& e : m.materialList) { e.iboOffset = iboBaseOffset; p += 4; e.iboSize = GetValue(p, 2); p += 2; e.material.color.r = *p++; e.material.color.g = *p++; e.material.color.b = *p++; e.material.color.a = *p++; e.material.metallic.Set(static_cast<float>(*p++) / 255.0f); e.material.roughness.Set(static_cast<float>(*p++) / 255.0f); iboBaseOffset += e.iboSize * sizeof(GLushort); } result.meshes.push_back(m); if (p >= pEnd) { return ImportMeshResult(ImportMeshResult::Result::invalidMeshInfo); } } glBufferSubData(GL_ARRAY_BUFFER, vboEnd, vboByteSize, p); p += vboByteSize; if (p >= pEnd) { return ImportMeshResult(ImportMeshResult::Result::invalidVBO); } std::vector<GLushort> indices; indices.reserve(iboByteSize / sizeof(GLushort)); const uint32_t offsetTmp = vboEnd / sizeof(Vertex); if (offsetTmp > 0xffff) { return ImportMeshResult(ImportMeshResult::Result::indexOverflow); } const GLushort offset = static_cast<GLushort>(offsetTmp); for (uint32_t i = 0; i < iboByteSize; i += sizeof(GLushort)) { indices.push_back(*reinterpret_cast<const GLushort*>(p) + offset); p += sizeof(GLushort); if (p >= pEnd) { return ImportMeshResult(ImportMeshResult::Result::invalidIBO); } } glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, iboEnd, iboByteSize, &indices[0]); vboEnd += vboByteSize; iboEnd += iboByteSize; p += (4 - (reinterpret_cast<intptr_t>(p) % 4)) % 4; if (p >= pEnd) { return result; } const uint32_t boneCount = GetValue(p, 2); p += 2; const uint32_t animationCount = GetValue(p, 2); p += 2; if (boneCount) { JointList joints; joints.resize(boneCount); std::vector<std::vector<int>> parentIndexList; parentIndexList.resize(boneCount); for (uint32_t i = 0; i < boneCount; ++i) { if (p >= pEnd) { return ImportMeshResult(ImportMeshResult::Result::invalidJointInfo); } Joint& e = joints[i]; e.invBindPose.rot.x = GetFloat(p); e.invBindPose.rot.y = GetFloat(p); e.invBindPose.rot.z = GetFloat(p); e.invBindPose.rot.w = GetFloat(p); e.invBindPose.rot.Normalize(); e.invBindPose.trans.x = GetFloat(p); e.invBindPose.trans.y = GetFloat(p); e.invBindPose.trans.z = GetFloat(p); #if 0 const Matrix4x3 m43 = ToMatrix(e.invBindPose.rot); Matrix4x4 m44; m44.SetVector(0, m43.GetVector(0)); m44.SetVector(1, m43.GetVector(1)); m44.SetVector(2, m43.GetVector(2)); m44.SetVector(3, e.invBindPose.trans); m44.Inverse(); Vector3F scale; m44.Decompose(&e.initialPose.rot, &scale, &e.initialPose.trans); #else e.initialPose.rot = e.invBindPose.rot.Inverse(); e.initialPose.trans = e.initialPose.rot.Apply(-e.invBindPose.trans); #endif e.offChild = 0; e.offSibling = 0; const uint32_t parentIndex = GetValue(p, 4); p += 4; if (parentIndex != 0xffffffff) { parentIndexList[parentIndex].push_back(i); } } for (uint32_t i = 0; i < boneCount; ++i) { const auto& e = parentIndexList[i]; if (!e.empty()) { int current = e[0]; joints[i].offChild = current - i; Joint* pJoint = &joints[current]; for (auto itr = e.begin() + 1; itr != e.end(); ++itr) { const int sibling = *itr; pJoint->offSibling = sibling - current; pJoint = &joints[sibling]; current = sibling; } } } for (auto& e : result.meshes) { e.jointList = joints; } } if (animationCount) { LOGI("ImportMesh - Read animation:"); result.animations.reserve(animationCount); for (uint32_t i = 0; i < animationCount; ++i) { Animation anm; const uint32_t nameLength = GetValue(p++, 1); char name[24]; for (int i = 0; i < 24; ++i) { name[i] = static_cast<char>(GetValue(p++, 1)); } anm.id.assign(name, name + nameLength); anm.data.resize(boneCount); for (uint32_t bone = 0; bone < boneCount; ++bone) { anm.data[bone].first = bone; } anm.loopFlag = static_cast<bool>(GetValue(p++, 1) != 0); const uint32_t keyframeCount = GetValue(p, 2); p += 2; anm.totalTime = GetFloat(p); LOGI("%s: %fsec", anm.id.c_str(), anm.totalTime); for (uint32_t keyframe = 0; keyframe < keyframeCount; ++keyframe) { const float time = GetFloat(p); #ifdef DEBUG_LOG_VERBOSE LOGI("time=%f", time); #endif // DEBUG_LOG_VERBOSE for (uint32_t bone = 0; bone < boneCount; ++bone) { if (p >= pEnd) { return ImportMeshResult(ImportMeshResult::Result::invalidAnimationInfo); } Animation::Element elem; elem.time = time; elem.pose.rot.x = GetFloat(p); elem.pose.rot.y = GetFloat(p); elem.pose.rot.z = GetFloat(p); elem.pose.rot.w = GetFloat(p); elem.pose.rot.Normalize(); elem.pose.trans.x = GetFloat(p); elem.pose.trans.y = GetFloat(p); elem.pose.trans.z = GetFloat(p); anm.data[bone].second.push_back(elem); #ifdef DEBUG_LOG_VERBOSE LOGI("%02d:(%+1.3f, %+1.3f, %+1.3f, %+1.3f) (%+1.3f, %+1.3f, %+1.3f)", bone, elem.pose.rot.w, elem.pose.rot.x, elem.pose.rot.y, elem.pose.rot.z, elem.pose.trans.x, elem.pose.trans.y, elem.pose.trans.z); #endif // DEBUG_LOG_VERBOSE } } result.animations.push_back(anm); } } return result; }
HexBuffer::HexBuffer(const RawBuffer & rb) { convert(rb.getData(), rb.getLength()); }
ByteBufferPtr ElGamal::Decrypt(const void *theCipherText, int theCipherTextLen) const { if(!IsPrivate()) return NULL; const unsigned char *in = (const unsigned char*)theCipherText; int inOffset = 0; if(theCipherTextLen-inOffset<4) return NULL; int aNumBlocks = LongFromLittleEndian(*(int*)in); inOffset+=4; if(theCipherTextLen-inOffset < aNumBlocks*modulusLen*2-inOffset) return NULL; RawBuffer aBuf(modulusLen,(unsigned char)0); RawBuffer bBuf(modulusLen,(unsigned char)0); WriteBuffer aDecrypt; BigInteger a;; BigInteger b; BigInteger aPlainText; for(int i=0; i<aNumBlocks; i++) { aBuf.assign(in+inOffset,modulusLen); inOffset+=modulusLen; bBuf.assign(in+inOffset,modulusLen); inOffset+=modulusLen; a.fromBinary(aBuf); b.fromBinary(bBuf); if(!decrypt(a,b,aPlainText)) return NULL; RawBuffer aBigIntArray; aPlainText.toBinary(aBigIntArray); if(aBigIntArray.length()==0) return NULL; int aPlainLen = aBigIntArray[aBigIntArray.length() - 1]; if(aPlainLen>modulusLen - 3) return NULL; if(aBigIntArray.length() - 1 - aPlainLen < 0) { int extra = aPlainLen - (aBigIntArray.length() - 1); for(int j=0; j<extra; j++) aDecrypt.AppendByte(0); aDecrypt.AppendBytes(aBigIntArray.data(),aBigIntArray.length()); } else aDecrypt.AppendBytes(aBigIntArray.data()+aBigIntArray.length()-1-aPlainLen,aPlainLen); } return aDecrypt.ToByteBuffer(); }