예제 #1
0
파일: Encryptor.cpp 프로젝트: Vieteg/EACirc
int Encryptor::loadState(TiXmlNode* pRoot) {
    if (m_cipher == NULL) { return STAT_PROJECT_ERROR; }
    int status = STAT_OK;
    if (atoi(getXMLElementValue(pRoot, "algorithm").c_str()) != pCaesarSettings->algorithm) {
        mainLogger.out(LOGGER_ERROR) << "Incompatible algorithm types." << endl;
        return STAT_CONFIG_INCORRECT;
    }
    status = CommonFnc::hexaToArray(getXMLElementValue(pRoot, "plaintext"), 
        static_cast<unsigned int>(pCaesarSettings->plaintextLength), m_plaintext);
    if (status != STAT_OK) return status;
    status = CommonFnc::hexaToArray(getXMLElementValue(pRoot, "key"), 
        static_cast<unsigned int>(pCaesarSettings->keyLength), m_key);
    if (status != STAT_OK) return status;
    status = CommonFnc::hexaToArray(getXMLElementValue(pRoot, "ad"), 
        static_cast<unsigned int>(pCaesarSettings->adLength), m_ad);
    if (status != STAT_OK) return status;
    status = CommonFnc::hexaToArray(getXMLElementValue(pRoot, "smn"), 
        static_cast<unsigned int>(pCaesarSettings->smnLength), m_smn);
    if (status != STAT_OK) return status;
    status = CommonFnc::hexaToArray(getXMLElementValue(pRoot, "pmn"), 
        static_cast<unsigned int>(pCaesarSettings->pmnLength), m_pmn);
    if (status != STAT_OK) return status;

    m_setup = true;
    return status;
}
예제 #2
0
int GateCircuit::loadCircuitConfiguration(TiXmlNode* pRoot) {
    // parsing EACIRC/GATE_CIRCUIT
    pGlobals->settings->gateCircuit.numLayers = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/NUM_LAYERS").c_str());
    pGlobals->settings->gateCircuit.sizeLayer = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/SIZE_LAYER").c_str());
    pGlobals->settings->gateCircuit.numConnectors = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/NUM_CONNECTORS").c_str());
    pGlobals->settings->gateCircuit.useMemory = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/USE_MEMORY").c_str()) ? true : false;
    pGlobals->settings->gateCircuit.sizeMemory = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/SIZE_MEMORY").c_str());
    // parsing EACIRC/GATE_CIRCUIT/ALLOWED_FUNCTIONS
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_NOP] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_NOP").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_CONS] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_CONS").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_AND] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_AND").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_NAND] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_NAND").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_OR] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_OR").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_XOR] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_XOR").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_NOR] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_NOR").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_NOT] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_NOT").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_SHIL] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_SHIL").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_SHIR] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_SHIR").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_ROTL] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_ROTL").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_ROTR] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_ROTR").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_EQ] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_EQ").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_LT] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_LT").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_GT] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_GT").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_LEQ] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_LEQ").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_GEQ] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_GEQ").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_BSLC] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_BSLC").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_READ] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_READ").c_str());
    pGlobals->settings->gateCircuit.allowedFunctions[FNC_JVM] = atoi(getXMLElementValue(pRoot,"GATE_CIRCUIT/ALLOWED_FUNCTIONS/FNC_JVM").c_str());

    // update extra info
    if (!pGlobals->settings->gateCircuit.useMemory) {
        pGlobals->settings->gateCircuit.sizeMemory = 0;
    }
    pGlobals->settings->gateCircuit.sizeOutputLayer = pGlobals->settings->main.circuitSizeOutput + pGlobals->settings->gateCircuit.sizeMemory;
    pGlobals->settings->gateCircuit.sizeInputLayer = pGlobals->settings->main.circuitSizeInput + pGlobals->settings->gateCircuit.sizeMemory;
    pGlobals->settings->gateCircuit.genomeWidth = max(pGlobals->settings->gateCircuit.sizeLayer, pGlobals->settings->gateCircuit.sizeOutputLayer);
    // Compute genome size: genomeWidth for number of layers (each layer is twice - function and connector)
    pGlobals->settings->gateCircuit.genomeSize = pGlobals->settings->gateCircuit.numLayers * 2 * pGlobals->settings->gateCircuit.genomeWidth;

    if (pGlobals->settings->gateCircuit.sizeLayer > MAX_LAYER_SIZE || pGlobals->settings->gateCircuit.numConnectors > MAX_LAYER_SIZE
            || pGlobals->settings->gateCircuit.sizeInputLayer > MAX_LAYER_SIZE || pGlobals->settings->gateCircuit.sizeOutputLayer > MAX_LAYER_SIZE) {
        mainLogger.out(LOGGER_ERROR) << "Maximum layer size exceeded (internal size || connectors || total input|| total output)." << endl;
        return STAT_CONFIG_INCORRECT;
    }
    if (pGlobals->settings->gateCircuit.useMemory && pGlobals->settings->gateCircuit.sizeMemory <= 0) {
        mainLogger.out(LOGGER_ERROR) << "Memory enabled but size incorrectly set (negative or zero)." << endl;
        return STAT_CONFIG_INCORRECT;
    }

    return STAT_OK;
}
예제 #3
0
int PolynomialCircuit::loadCircuitConfiguration(TiXmlNode* pRoot) {
    // parsing EACIRC/POLYNOMIAL_CIRCUIT
    pGlobals->settings->polyCircuit.numPolynomials                 = atoi(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/NUM_POLYNOMIALS").c_str());
    pGlobals->settings->polyCircuit.mutateTermStrategy             = atoi(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/MUTATE_TERM_STRATEGY").c_str());
    pGlobals->settings->polyCircuit.genomeInitMaxTerms             = atoi(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/MAX_TERMS").c_str());
    pGlobals->settings->polyCircuit.genomeInitTermCountProbability = atof(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/TERM_COUNT_P").c_str());
    pGlobals->settings->polyCircuit.genomeInitTermStopProbability  = atof(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/TERM_VAR_P").c_str());
    pGlobals->settings->polyCircuit.mutateAddTermProbability       = atof(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/ADD_TERM_P").c_str());
    pGlobals->settings->polyCircuit.mutateAddTermStrategy          = atoi(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/ADD_TERM_STRATEGY").c_str());
    pGlobals->settings->polyCircuit.mutateRemoveTermProbability    = atof(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/RM_TERM_P").c_str());
    pGlobals->settings->polyCircuit.mutateRemoveTermStrategy       = atoi(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/RM_TERM_STRATEGY").c_str());
    pGlobals->settings->polyCircuit.crossoverRandomizePolySelect   = atoi(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/CROSSOVER_RANDOMIZE_POLY").c_str()) ? true : false;
    pGlobals->settings->polyCircuit.crossoverTermsProbability      = atof(getXMLElementValue(pRoot,"POLYNOMIAL_CIRCUIT/CROSSOVER_TERM_P").c_str());
    
    // Not defined ? use main configuration.
    if (pGlobals->settings->polyCircuit.numPolynomials<=0){
        pGlobals->settings->polyCircuit.numPolynomials = 8*pGlobals->settings->main.circuitSizeOutput;
        mainLogger.out(LOGGER_INFO) << "Number of polynomials not set properly. Falling back to " << pGlobals->settings->polyCircuit.numPolynomials << endl;
    }
    
    // Configuration check - invariant.
    if (pGlobals->settings->polyCircuit.numPolynomials > 8*pGlobals->settings->main.circuitSizeOutput){
        mainLogger.out(LOGGER_ERROR) << "Number of polynomials is larger than 8 * circuit size output " << pGlobals->settings->polyCircuit.numPolynomials << endl;
        return STAT_CONFIG_INCORRECT;
    }
    
    return STAT_OK;
}