예제 #1
0
Status
Login::passwordAuthSet(DataSlice passwordAuth)
{
    std::lock_guard<std::mutex> lock(mutex_);
    passwordAuth_ = DataChunk(passwordAuth.begin(), passwordAuth.end());
    return Status();
}
예제 #2
0
Status
Login::rootKeyUpgrade()
{
    // Create a BIP39 mnemonic, and use it to derive the rootKey:
    DataChunk entropy;
    ABC_CHECK(randomData(entropy, 256/8));
    auto mnemonic = bc::create_mnemonic(entropy, bc::language::en);
    auto rootKeyRaw = bc::decode_mnemonic(mnemonic);
    rootKey_ = DataChunk(rootKeyRaw.begin(), rootKeyRaw.end());

    // Pack the keys into various boxes:
    JsonBox rootKeyBox;
    ABC_CHECK(rootKeyBox.encrypt(rootKey_, dataKey_));
    JsonBox mnemonicBox, dataKeyBox;
    auto infoKey = bc::hmac_sha256_hash(rootKey_, DataSlice(infoKeyHmacKey));
    ABC_CHECK(mnemonicBox.encrypt(bc::join(mnemonic), infoKey));
    ABC_CHECK(dataKeyBox.encrypt(dataKey_, infoKey));

    // Upgrade the account on the server:
    ABC_CHECK(loginServerAccountUpgrade(*this,
                                        rootKeyBox, mnemonicBox, dataKeyBox));
    ABC_CHECK(rootKeyBox.save(paths.rootKeyPath()));

    return Status();
}
예제 #3
0
파일: main.cpp 프로젝트: mrslan/toolbox
    DataChunk GetDataChunk() {
        //TODO refine this function.
        pthread_mutex_lock(&mMutex);
        mCurrentChunk += CHUNK_SIZE;
        if(mCurrentChunk > DATA_SIZE) {
            pthread_mutex_unlock(&mMutex);
            return DataChunk(NULL,0);
        }

        //TODO add DataChunk type to handle border condition
        int remainingData = DATA_SIZE - mCurrentChunk + 1;
        int chunkSize = (remainingData >= CHUNK_SIZE) ? CHUNK_SIZE: remainingData;

        int startPos = mCurrentChunk - CHUNK_SIZE;
        pthread_mutex_unlock(&mMutex);

        return DataChunk(&mData[startPos], chunkSize);
    }
예제 #4
0
void IBinSaver::StoreObject(IObjectBase *pObject)
{
    if (pObject) {
        Y_ASSERT(pSaverClasses->GetObjectTypeID(pObject) != -1 && "trying to save unregistered object");
    }

    ui64 ptrId = ((char*)pObject) - ((char*)nullptr);
    if (StableOutput) {
        ui32 id = 0;
        if (pObject) {
            if (!PtrIds.Get())
                PtrIds.Reset(new PtrIdHash);
            PtrIdHash::iterator pFound = PtrIds->find(pObject);
            if (pFound != PtrIds->end())
                id = pFound->second;
            else {
                id = PtrIds->ysize() + 1;
                PtrIds->insert(std::make_pair(pObject, id));
            }
        }
        ptrId = id;
    }

    DataChunk(&ptrId, sizeof(ptrId));
    if (!Objects.Get())
        Objects.Reset(new CObjectsHash);
    if (ptrId != 0 && Objects->find(ptrId) == Objects->end()) {
        ObjectQueue.push_back(pObject);
        (*Objects)[ptrId];
        int typeId = pSaverClasses->GetObjectTypeID(pObject);
        if (typeId == -1) {
            fprintf(stderr, "IBinSaver: trying to save unregistered object\n");
            abort();
        }
        DataChunk(&typeId, sizeof(typeId));
    }
}
예제 #5
0
IObjectBase* IBinSaver::LoadObject()
{
    ui64 ptrId = 0;
    DataChunk(&ptrId, sizeof(ptrId));
    if (ptrId != 0) {
        if (!Objects.Get())
            Objects.Reset(new CObjectsHash);
        CObjectsHash::iterator pFound = Objects->find(ptrId);
        if (pFound != Objects->end())
            return pFound->second;
        int typeId;
        DataChunk(&typeId, sizeof(typeId));
        IObjectBase *pObj = pSaverClasses->CreateObject(typeId);
        Y_ASSERT(pObj != nullptr);
        if (pObj == nullptr) {
            fprintf(stderr, "IBinSaver: trying to load unregistered object\n");
            abort();
        }
        (*Objects)[ptrId] = pObj;
        ObjectQueue.push_back(pObj);
        return pObj;
    }
    return nullptr;
}
예제 #6
0
    uint32_t DirectXInputLayoutRegistry::create(const Vertices& vertices)
    {
        TB::runtimeCheck(vertices.size() > 0);

        const char* semantics[] = { "POSITION", "NORMAL", "TEXCOORD", "COLOR" };
        const DXGI_FORMAT formats[] = { DXGI_FORMAT(0), DXGI_FORMAT_R32_FLOAT, DXGI_FORMAT_R32G32_FLOAT, DXGI_FORMAT_R32G32B32_FLOAT, DXGI_FORMAT_R32G32B32A32_FLOAT };

        // Input layout elements
        std::vector<D3D11_INPUT_ELEMENT_DESC> elements;
        for (size_t i = 0; i < vertices.size(); i++)
        {
            const auto& stream = vertices[i];
            elements.push_back({ semantics[(int)stream.semantic], (UINT)stream.usageIndex, formats[stream.elements], (UINT)i, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 });
        }

        // Hash the memory bytes of the element
        uint32_t id = hash(reinterpret_cast<uint8_t*>(&elements[0]), elements.size() * sizeof(D3D11_INPUT_ELEMENT_DESC));
        auto item = mRegistry.find(id);
        if (item == mRegistry.end())
        {
            std::stringstream fakeVSCode;
            const char* memberTypes[] = { nullptr, "float", "float2", "float3", "float4" };

            // Create a fake vertex shader for the input layout
            fakeVSCode << "struct VSInput";
            fakeVSCode << "{";
            for (size_t i = 0; i < vertices.size(); i++)
            {
                const auto& stream = vertices[i];
                fakeVSCode << memberTypes[stream.elements] << " _" << i << " : " << semantics[(int)stream.semantic] << stream.usageIndex << ";";
            }
            fakeVSCode << "};";

            fakeVSCode << "float4 MainVS(VSInput input) : SV_POSITION { return float4(0, 0, 0, 1); }";

            DirectXShader fakeVS(mRenderer, DataChunk(fakeVSCode.str()), "MainVS", ShaderType::Vertex);

            ComPtr<ID3D11InputLayout> inputLayout;
            HRESULT hr = mRenderer->getDevice()->CreateInputLayout(&elements[0], (UINT)elements.size(), fakeVS.getBlob()->GetBufferPointer(), fakeVS.getBlob()->GetBufferSize(), inputLayout.getInitRef());
            TB::runtimeCheck(hr == S_OK);

            mRegistry.emplace(id, inputLayout);
        }

        return id;
    }
예제 #7
0
파일: FileOut.cpp 프로젝트: eeeeaaii/syrinx
void FileOut::finalize()
{
	// get size of out.raw
	int fd;
	char buf[64];
	int bytesread;
	int totalsize = 0;
	fd = open("out.raw", O_RDONLY, 0);
	while((bytesread = read(fd, buf, BUFSIZE)) == BUFSIZE) totalsize += BUFSIZE;
	lseek(fd, 0, SEEK_SET);

	int outfd;
	outfd = open("out.wav", O_WRONLY|O_CREAT|O_TRUNC, S_IRWXU|S_IRWXG|S_IRWXO);

	FormatChunk fchunk;
	DataChunk dchunk = DataChunk(totalsize);
	write(outfd, &fchunk, sizeof(fchunk));
	write(outfd, &dchunk, sizeof(dchunk));
	while((bytesread = read(fd, buf, BUFSIZE)) == BUFSIZE) {
		write(outfd, buf, bytesread);
	}
	close(fd);
	close(outfd);
}