Exemplo n.º 1
0
// free and clear
void FreeL(void *mal){

	if(!globalInitDebug)
		InitDebug();

	memInfo	memS;
	memInfo	*mem = &memS;
	mem->loc = mal;
	
	memInfo	*retMem = removeSkip(globalMemHolder,mem);
	assert(retMem,"Illegal Free");

	char *retMal = retMem->loc;
	int size = retMem->size;

	assertBool((retMal==mal),"Mal Incorrect");

	// clear out memory
	int i;
	for(i=0;i<size;i++)
		retMal[i] = 0x58;

	// doesn't really free the memory to make sure that if 
	// it is called, the result will be that it was freed (0x58)

	Free(retMem);
}
Exemplo n.º 2
0
void testBools( void ) {
    int num_configs = 6; 
    XPPCItem *configs = XPPCInit( num_configs );
/*
here's a bool
0

here's another bool
1
*/
    /* for bools we'll test that real bools are read correctly and that
     * ints read as bools fail as expected to the defaults */
    bool one   = true,
         two   = false,
         three = true,
         four  = false,
         five  = true,
         six   = false;
    
    configs[0].type = XPPC_TYPE_BOOLEAN;
    configs[0].key  = "here's a bool";
    configs[0].ref  = &one;

    configs[1].type = XPPC_TYPE_BOOLEAN;
    configs[1].key  = "here's another bool";
    configs[1].ref  = &two;

    configs[2].type = XPPC_TYPE_BOOLEAN;
    configs[2].key  = "neg int";
    configs[2].ref  = &three;

    configs[3].type = XPPC_TYPE_BOOLEAN;
    configs[3].key  = "pos int";
    configs[3].ref  = &four;

    configs[4].type = XPPC_TYPE_BOOLEAN;
    configs[4].key  = "pos int2";
    configs[4].ref  = &five;

    configs[5].type = XPPC_TYPE_BOOLEAN;
    configs[5].key  = "neg int2";
    configs[5].ref  = &six;
    
    XPPCParseConfigFile( "./test_conf.txt", configs, num_configs );

    printf( "\ntesting bools....\n" );
    assertBool( one, false );
    assertBool( two, true );
    assertBool( three, true );
    assertBool( four, false );
    assertBool( five, true );
    assertBool( six, false );
}
Exemplo n.º 3
0
Arquivo: arch.c Projeto: dbunker/SABR
// may need to create a treeNode to store elab
treeNode *setCommaNode(int tok,int varId,treeNode *varList){

	if(tok == CHARVAR){
		
		// assert no varlist
		assertBool(varList == NULL,"Char VarList");
		int *dataVar = Malloc(sizeof(int));
		*dataVar = varId;

		varList = Malloc(sizeof(treeNode));
		varList->type = charType;
		varList->data = dataVar;
		return varList;
	}
	if(tok == MANYVAR){
		if(!varList){
			
			manyData *many = Malloc(sizeof(manyData));
			linkedList brackVars = createLinked(Malloc,Free);
			many->brackVars = brackVars;

			varList = Malloc(sizeof(treeNode));
			varList->type = manyType;
			varList->data = many;
		}

		manyData *md = varList->data;
		linkedList list = md->brackVars;
		int *dataVar = Malloc(sizeof(int));
		*dataVar = varId;
		pushLinked(list,dataVar);
		return varList;
	}
	if(tok == ELABVAR || tok == ELABNEG){
		if(!varList){
			
			elabData *elab = Malloc(sizeof(elabData));
			linkedList negVars = createLinked(Malloc,Free);
			linkedList posVars = createLinked(Malloc,Free);
			elab->tempVarName = 0;
			elab->isAny = 0;
			elab->negVars = negVars;
			elab->posVars = posVars;

			varList = Malloc(sizeof(treeNode));
			varList->type = elabType;
			varList->data = elab;
		}
		
		elabData *ed = varList->data;
		linkedList addToList;
		if(tok == ELABNEG)
			addToList = ed->negVars;
		else
			addToList = ed->posVars;
		
		int *dataVar = Malloc(sizeof(int));
		*dataVar = varId;
		pushLinked(addToList,dataVar);
		return varList;
	}
	// error
	return NULL;
}
Exemplo n.º 4
0
int main()
{
	SystemInit();
	const Ec1 g1(-1, 1);
	const Ec2 g2(
		Fp2(Fp(g2c.aa), Fp(g2c.ab)),
		Fp2(Fp(g2c.ba), Fp(g2c.bb))
	);
	// assertBool g2 and g1 on curve
	assertBool("g1 is on EC", g1.isValid());
	assertBool("g2 is on twist EC", g2.isValid());
	puts("order of group");
	const Mpz& r = GetParamR();
	PUT(r);
	{
		Ec1 t = g1;
		t.mul(r);
		assertBool("orgder of g1 == r", t.isZero());
	}
	{
		Ec2 t = g2;
		t.mul(r);
		assertBool("order of g2 == r", t.isZero());
	}
	const Mpz a("123456789012345");
	const Mpz b("998752342342342342424242421");

	// scalar-multiplication sample
	{
		Mpz c = a;
		c.add(b);
		Ec1 Pa = g1; Pa.mul(a);
		Ec1 Pb = g1; Pb.mul(b);
		Ec1 Pc = g1; Pc.mul(c);
		Ec1 out = Pa;
		out.add(Pb);

		assertEqual("check g1 * c = g1 * a + g1 * b", Pc, out);
	}

	Fp12 e;
	// calc e : G2 x G1 -> G3 pairing
	e.pairing(g2, g1); // e = e(g2, g1)
	PUT(e);
	{
		Fp12 t = e;
		t.power(r);
		assertEqual("order of e == r", t, Fp12(1));
	}
	Ec2 g2a = g2;
	g2a.mul(a);
	Fp12 ea1;
	ea1.pairing(g2a, g1);
	Fp12 ea2 = e;
	ea2.power(a); // ea2 = e^a
	assertEqual("e(g2 * a, g1) = e(g2, g1)^a", ea1, ea2);

	Ec1 g1b = g1;
	g1b.mul(b);
	Fp12 eb1;
	eb1.pairing(g2, g1b); // eb1 = e(g2, g1b)
	Fp12 eb2 = e;
	eb2.power(b); // eb2 = e^b
	assertEqual("e(g2a, g1 * b) = e(g2, g1)^b", eb1, eb2);

	Ec1 q1 = g1;
	q1.mul(12345);
	assertBool("q1 is on EC", q1.isValid());
	Fp12 e1, e2;
	e1.pairing(g2, g1); // e1 = e(g2, g1)
	e2.pairing(g2, q1); // e2 = e(g2, q1)
	Ec1 q2 = g1;
	q2.add(q1);
	e.pairing(g2, q2); // e = e(g2, q2)
	e1.mul(e2);
	assertEqual("e = e1 * e2", e, e1);
	/*
		reduce one copy as the following
	*/
	g2a = g2;
	g2a.mul(a);
	g1b = g1;
	g1b.mul(b);
	Ec2 g2at = g2; g2at.mul(a);
	Ec1 g1bt = g1; g1bt.mul(b);
	assertEqual("g2a == g2 * a", g2a, g2at);
	assertEqual("g1b == g1 * b", g1b, g1bt);
	printf("errNum = %d\n", errNum);
}
Exemplo n.º 5
0
Arquivo: tbl.c Projeto: dbunker/SABR
// for all distinct variables
void allDifClauses(rootData *rdata,indexList *varList,linkedList clauseList){
	
	int n,c,s,x,y;
	linkedList allDifNodes = rdata->allDifNodes;
	
	int allDifWidth = sizeLinked(allDifNodes);
	treeNode **allDifArray = toArrayLinked(allDifNodes);

	for(n=0;n<numStagesGlobal;n++){
	
		for(c=0;c<allDifWidth;c++){
		
			treeNode *allDifNode = allDifArray[c];
			nameData *allDifData = allDifNode->data;
			
			nodeStages *stages = allDifNode->stages;
			
			if(stages != NULL){
				// stages are inclusive between start and end for both
				int start = stages->start;
				int end = stages->end;
			
				if(n < start || n > end)
					continue;
			}
			
			setData *allDifSet = allDifData->set;
			manyData **many = allDifSet->setVars;
			
			int height = allDifSet->height;
			int width = allDifSet->width;
			
			if(width == 0)
				return;
			
			// these should all have the same symlist
			manyData *manyThis = many[0];
			linkedList symList = manyThis->symList;
			
			int symWidth = sizeLinked(symList);
			int **symArray = toArrayLinked(symList);
			
			for(s=0;s<symWidth;s++){
			
				int symId = *symArray[s];
				
				// must be exactly one
				linkedList singleVars = createLinked(Malloc,Free);
				
				int numCells = 0;
				for(y=0;y<height;y++){
					for(x=0;x<width;x++){
						
						manyThis = many[width*y+x];
						
						// may not have rectangle shape
						if(!manyThis)
							continue;
						
						assertBool(manyThis->symList == symList,"SymList Did Not Match.");
						
						linkedList brackVars = manyThis->brackVars;
						int *boardCellP = peekLinked(brackVars);
						int boardCell = *boardCellP;
						
						varData *v = getSymCellVarByName(varList,boardCell,symId,n);
						assert(v,"AllDif Variable Not Found.");
						
						addTailLinked(singleVars,v);
						numCells++;
					}
				}
				
				atMostOne(singleVars,clauseList);
				
				if(numCells == symWidth)
					atLeastOne(singleVars,clauseList);
				
				destroyLinked(singleVars,NULL);
			}
		}
	}
}
Exemplo n.º 6
0
Arquivo: tbl.c Projeto: dbunker/SABR
// this forces the cell to remain the same when cellUsedStageN=>N+1 is not set
void usedClauses(rootData *rdata,indexList *varList,linkedList clauseList,linkedList fullTransNodes){

	int i,n;
	linkedList clause;
	clauseVarData *clauseVar;

	// board
	treeNode *boardNode = rdata->boardNode;
	setData *boardSet = boardNode->data;
	
	int boardWidth = boardSet->width;
	int boardHeight = boardSet->height;
	cellData **boardVars = boardSet->setVars;
	int boardX, boardY;
	
	// for each cellStage used-var	
	// find all transitions that use that cell, put it into the set
	
	for(boardY=0;boardY<boardHeight;boardY++){
		for(boardX=0;boardX<boardWidth;boardX++){

			if(!boardVars[boardY*boardWidth+boardX])
				continue;

			cellData *cell = boardVars[boardY*boardWidth+boardX];
			linkedList symList = cell->symList;
			int symWidth = sizeLinked(symList);
			int **symArray = toArrayLinked(symList);

			for(n=0;n<numStagesGlobal-1;n++){

				varData *used = getUsedVar(varList,boardX,boardY,n);
				assert(used,"No Used\n");

				for(i=0;i<symWidth;i++){
					
					int sym = *symArray[i];

					// empty transitions
					// boardCell0UsedStageN=>N+1 OR NOT boardCell0IsSym0StageN OR boardCell0IsSym0StageN+1
					// and reverse
					varData *scv0 = getSymCellVar(varList,boardX,boardY,sym,n);
					assert(scv0,"No SCV0\n");
					varData *scv1 = getSymCellVar(varList,boardX,boardY,sym,n+1);
					assert(scv1,"No SCV1\n");					

					clause = createLinked(Malloc,Free);
					clauseVar = createClauseVar(used,0);
					addTailLinked(clause,clauseVar);
					clauseVar = createClauseVar(scv0,1);
					addTailLinked(clause,clauseVar);
					clauseVar = createClauseVar(scv1,0);
					addTailLinked(clause,clauseVar);

					assertBool(sizeLinked(clause) != 0,"Empty Clause Used");
					addClause(clauseList,clause);

					clause = createLinked(Malloc,Free);
					clauseVar = createClauseVar(used,0);
					addTailLinked(clause,clauseVar);
					clauseVar = createClauseVar(scv1,1);
					addTailLinked(clause,clauseVar);
					clauseVar = createClauseVar(scv0,0);
					addTailLinked(clause,clauseVar);

					assertBool(sizeLinked(clause) != 0,"Empty Clause Used");
					addClause(clauseList,clause);
				}
			}
		}
	}
}
Exemplo n.º 7
0
Arquivo: tbl.c Projeto: dbunker/SABR
// this sets cellUsedStageN=>N+1 variables when that cell is used in that transition
void setUsedClauses(rootData *rdata,indexList *varList,linkedList clauseList,linkedList fullTransNodes){

	int i,n;
	linkedList clause;
	clauseVarData *clauseVar;
	
	// trans
	int transWidth = sizeLinked(fullTransNodes);
	tempTransVar **transArray = toArrayLinked(fullTransNodes);

	// board
	treeNode *boardNode = rdata->boardNode;
	setData *boardSet = boardNode->data;
	
	int boardWidth = boardSet->width;
	int boardHeight = boardSet->height;
	cellData **boardVars = boardSet->setVars;
	
	int boardX, boardY;
	int desObjX, desObjY;
		
	// for each cellStage used-var	
	// find all transitions that use that cell, put it into the set

	for(boardY=0;boardY<boardHeight;boardY++){
		for(boardX=0;boardX<boardWidth;boardX++){

			if(!boardVars[boardY*boardWidth+boardX])
				continue;
			cellData *boardCell = boardVars[boardY*boardWidth+boardX];
			int boardCellName = boardCell->cellName;

			for(n=0;n<numStagesGlobal-1;n++){
				
				varData *used = getUsedVar(varList,boardX,boardY,n);
				assert(used,"Used NULL");

				// NOT cellUsedStageN=>N+1 OR tran1StageN=>N+1 OR tran2StageN=>N+1 OR ...
				linkedList transListClause = createLinked(Malloc,Free);
				
				// contains varData
				// this is for saying at most one of these simultaneous trans that use this cell can be used
				linkedList transSimAtMostList = createLinked(Malloc,Free);

				// try to find it in trans
				for(i=0;i<transWidth;i++){

					tempTransVar *trans = transArray[i];

					// if this trans does not occur at this stage, it is not included in list that would indicate cell is used
					nodeStages *stages = trans->stages;
					if(n < stages->start || n > stages->end)
						continue;

					varData *tv = getTransVar(varList,trans->transId,trans->desObjId,n);
					assert(tv,"Trans NULL");				

					// true if the transition operates on board cell (boardX,boardY)
					int transUsesBoardCell = 0;

					// if it is the board, this x,y is used
					setData *dos = trans->desObjSet;

					manyData **desObjSet = dos->setVars;
					int desObjHeight = dos->height;
					int desObjWidth = dos->width;	
						
					for(desObjY=0;desObjY<desObjHeight;desObjY++){
						for(desObjX=0;desObjX<desObjWidth;desObjX++){
			
							if(!desObjSet[desObjY*desObjWidth + desObjX]) 
								continue;
								
							manyData *md = desObjSet[desObjY*desObjWidth + desObjX];
							linkedList brackVars = md->brackVars;
							int *objSymP = peekLinked(brackVars);
							int desObjCellName = *objSymP;

							if(boardCellName == desObjCellName){
								transUsesBoardCell = 1;
							}
						}
					}
					
					// found board cell
					if(transUsesBoardCell){

						clause = createLinked(Malloc,Free);
						clauseVar = createClauseVar(used,0);
						addTailLinked(clause,clauseVar);
						clauseVar = createClauseVar(tv,1);
						addTailLinked(clause,clauseVar);

						assertBool(sizeLinked(clause) != 0,"Empty Clause Used");
						addClause(clauseList,clause);

						clauseVar = createClauseVar(tv,0);
						addTailLinked(transListClause,clauseVar);

						// if it is not a TransSim it is already in an at-most-one
						if(trans->isSim){
							// varData
							addTailLinked(transSimAtMostList,tv);
						}
					}
				}
				
				// connect this trans to this used cell
				clauseVar = createClauseVar(used,1);
				pushLinked(transListClause,clauseVar);

				addClause(clauseList,transListClause);

				// for TransSim
				atMostOne(transSimAtMostList,clauseList);
				destroyLinked(transSimAtMostList,NULL);
			}
		}
	}
}