TEST(NodeToStringTests, PairSingle)
{
    Node node;
    
    Node pair;
    pair.addChild(IntLeaf(1));
    pair.addChild(IntLeaf(2));

    node.addChild(pair);
    node.addChild(IntLeaf(3));

    EXPECT_EQ(node.toString(), "((1, 2), 3)");
}
TEST(NodeToStringTests, PairVector)
{
    Node node;

    for(unsigned int i=0; i<7; i++)
    {
		Node pair;
		pair.addChild(IntLeaf(i));
		pair.addChild(IntLeaf(10+i));

		node.addChild(pair);
    }

    EXPECT_EQ(node.toString(), "((0, 10), (1, 11), (2, 12), (3, 13), (4, 14), (5, 15), (6, 16))");
}
Beispiel #3
0
bool isElemOfGq(const Node &group, const IntLeaf &elem)
{
    // For convenience
    const IntLeaf &p = group.getIntLeafChild(0);
    const IntLeaf &q = group.getIntLeafChild(1);

    // Make sure elem is in allowed range for elements in Gq
    if(!(elem < p) || (elem < IntLeaf(1)))
	return false;

    // A group element raised to the group order equals identity
    if(elem.expMod(q, p) != IntLeaf(1))
	return false;

    return true;
}
Beispiel #4
0
bool isElemOfZn(const IntLeaf &n, const IntLeaf &elem)
{
    // Need only test to make sure elem is within allowed range
    if(!(elem < n) || elem < IntLeaf(0))
	return false;

    return true;
}
Beispiel #5
0
static void FixupC99MainReturn( SYM_HANDLE func_result, struct return_info *info )
{
    TREEPTR             tree;
    TYPEPTR             main_type;

    /* In C99 mode, return statement need not be explicit for main()... */
    main_type = CurFunc->sym_type->object;
    SKIP_TYPEDEFS( main_type );
    /* ... as long as return type is compatible with int */
    if( main_type->decl_type == TYPE_INT ) {
        tree = IntLeaf( 0 );    /* zero is the default return value */
        tree = ExprNode( 0, OPR_RETURN, tree );
        tree->expr_type = main_type;
        tree->op.sym_handle = func_result;
        AddStmt( tree );
        info->with_expr = TRUE;
    }
}
Beispiel #6
0
local void InitStructVar( unsigned base, SYMPTR sym, SYM_HANDLE sym_handle, TYPEPTR typ)
{
    TYPEPTR     typ2;
    TREEPTR     opnd;
    TREEPTR     value;
    FIELDPTR    field;
    TOKEN       token;

    for( field = typ->u.tag->u.field_list; field; ) {
        token = CurToken;
        if( token == T_LEFT_BRACE )  NextToken();  //allow {}, and extra {expr}..}
        typ2 = field->field_type;
        SKIP_TYPEDEFS( typ2 );
        if( CurToken == T_RIGHT_BRACE ) {
            value = IntLeaf( 0 );
        } else {
            value = CommaExpr();
        }
        opnd = VarLeaf( sym, sym_handle );
        if( typ2->decl_type == TYPE_UNION ) {
            FIELDPTR    ufield;

            ufield = typ2->u.tag->u.field_list;
            typ2 = ufield->field_type;
            SKIP_TYPEDEFS( typ2 );
        }
        opnd = ExprNode( opnd, OPR_DOT, UIntLeaf( base + field->offset ) );
        opnd->expr_type = typ2;
        opnd->op.result_type = typ2;
        AddStmt( AsgnOp( opnd, T_ASSIGN_LAST, value ) );
        if( token == T_LEFT_BRACE )  MustRecog( T_RIGHT_BRACE );
        if( CurToken == T_EOF ) break;
        field = field->next_field;
        if( field == NULL ) break;
        if( CurToken != T_RIGHT_BRACE ) {
            MustRecog( T_COMMA );
        }
    }
}
Beispiel #7
0
local void InitArrayVar( SYMPTR sym, SYM_HANDLE sym_handle, TYPEPTR typ )
{
    unsigned    i;
    unsigned    n;
    TYPEPTR     typ2;
    SYM_HANDLE  sym2_handle;
    SYM_ENTRY   sym2;
    TREEPTR     opnd;
    TREEPTR     value;
    TOKEN       token;

    typ2 = typ->object;
    SKIP_TYPEDEFS( typ2 );
    switch( typ2->decl_type ) {
    case TYPE_CHAR:
    case TYPE_UCHAR:
    case TYPE_SHORT:
    case TYPE_USHORT:
    case TYPE_INT:
    case TYPE_UINT:
    case TYPE_LONG:
    case TYPE_ULONG:
    case TYPE_LONG64:
    case TYPE_ULONG64:
    case TYPE_FLOAT:
    case TYPE_DOUBLE:
    case TYPE_POINTER:
    case TYPE_LONG_DOUBLE:
    case TYPE_FIMAGINARY:
    case TYPE_DIMAGINARY:
    case TYPE_LDIMAGINARY:
    case TYPE_BOOL:
        NextToken();                    // skip over T_LEFT_BRACE
        if( CharArray( typ->object ) ) {
            sym2_handle = MakeNewSym( &sym2, 'X', typ, SC_STATIC );
            sym2.flags |= SYM_INITIALIZED;
            if( sym2.u.var.segment == 0 ) {             /* 01-dec-91 */
                SetFarHuge( &sym2, 0 );
                SetSegment( &sym2 );
                SetSegAlign( &sym2 );                     /* 02-feb-92 */
            }
            SymReplace( &sym2, sym2_handle );
            GenStaticDataQuad( sym2_handle );
            InitCharArray( typ );
            AssignAggregate( VarLeaf( sym, sym_handle ),
                             VarLeaf( &sym2, sym2_handle ), typ );
        } else if( WCharArray( typ->object ) ) {
            sym2_handle = MakeNewSym( &sym2, 'X', typ, SC_STATIC );
            sym2.flags |= SYM_INITIALIZED;
            if( sym2.u.var.segment == 0 ) {             /* 01-dec-91 */
                SetFarHuge( &sym2, 0 );
                SetSegment( &sym2 );
                SetSegAlign( &sym2 );                   /* 02-feb-92 */
            }
            SymReplace( &sym2, sym2_handle );
            GenStaticDataQuad( sym2_handle );
            InitWCharArray( typ );
            AssignAggregate( VarLeaf( sym, sym_handle ),
                             VarLeaf( &sym2, sym2_handle ), typ );
        } else {
            n = typ->u.array->dimension;
            i = 0;
            for( ;; ) {     // accept some C++ { {1},.. }
                token = CurToken;
                if( token == T_LEFT_BRACE )  NextToken();
                opnd = VarLeaf( sym, sym_handle );
                value = CommaExpr();
                opnd = ExprNode( opnd, OPR_INDEX, IntLeaf( i ) );
                opnd->expr_type = typ2;
                opnd->op.result_type = typ2;
                AddStmt( AsgnOp( opnd, T_ASSIGN_LAST, value ) );
                if( token == T_LEFT_BRACE )  MustRecog( T_RIGHT_BRACE );
                ++i;
                if( CurToken == T_EOF ) break;
                if( CurToken == T_RIGHT_BRACE )break;
                MustRecog( T_COMMA );
                if( CurToken == T_RIGHT_BRACE )break;
                if( i == n ) {
                    CErr1( ERR_TOO_MANY_INITS );
               }
            }
            if( typ->u.array->unspecified_dim ) {
                typ->u.array->dimension = i;
            } else {
                while( i < n ) {
                    value = IntLeaf( 0 );
                    opnd = VarLeaf( sym, sym_handle );
                    opnd = ExprNode( opnd, OPR_INDEX, IntLeaf( i ) );
                    opnd->expr_type = typ2;
                    opnd->op.result_type = typ2;
                    AddStmt( AsgnOp( opnd, T_ASSIGN_LAST, value ) );
                    ++i;
                }
            }
        }
        MustRecog( T_RIGHT_BRACE );
        break;
    case TYPE_FCOMPLEX:
    case TYPE_DCOMPLEX:
    case TYPE_LDCOMPLEX:
    case TYPE_STRUCT:
    case TYPE_UNION:
        if( SimpleStruct( typ2 ) ) {
            unsigned    base;
            unsigned    size;

            NextToken();                    // skip over T_LEFT_BRACE
            n = typ->u.array->dimension;
            i = 0;
            base = 0;
            size = SizeOfArg( typ2 );
            for( ;; ) {
                token = CurToken;
                if( token == T_LEFT_BRACE ) {
                    NextToken();
                }
                InitStructVar( base, sym, sym_handle, typ2 );
                if( token == T_LEFT_BRACE ) {
                    MustRecog( T_RIGHT_BRACE );
                }
                ++i;
                if( CurToken == T_EOF ) break;
                if( CurToken == T_RIGHT_BRACE ) break;
                MustRecog( T_COMMA );
                if( CurToken == T_RIGHT_BRACE ) break;
                if( i == n ) {
                    CErr1( ERR_TOO_MANY_INITS );
               }
               base += size;
            }
            if( typ->u.array->unspecified_dim ) {
                typ->u.array->dimension = i;
            } else {
                while( i < n ) { // mop up
                    base += size;
                    InitStructVar( base, sym, sym_handle, typ2 );
                    ++i;
                }
            }
           NextToken();                    // skip over T_RIGHT_BRACE
           break;
        }
    default:
        AggregateVarDeclEquals( sym, sym_handle );
        break;
    }
}
bool DecryptionVerifier(const proofStruct &ps, const Node L, const Node m) {

    IntLeaf p = ps.Gq.getIntLeafChild(0);

	//Step 1
    Node f, tauDec, sigmaDec;
    try 
    {
	for (unsigned int l = 1; l <= ps.lambda; l++)
	{
	    char filename[FILENAME_BUFFER_SIZE];
	    sprintf(filename, DECRYPTION_FACTORS_FILE_TMPL.c_str(), l);
	    Node f_l = Node(ps.directory + "/proofs/" + filename);
	    f.addChild(f_l);

	    sprintf(filename, DECR_FACT_COMMITMENT_FILE_TMPL.c_str(), l);
	    Node tauDec_l = Node(ps.directory + "/proofs/" + filename);
	    tauDec.addChild(tauDec_l);

	    sprintf(filename, DECR_FACT_REPLY_FILE_TMPL.c_str(), l);
	    std::ifstream sigmaDec_l_file((ps.directory + "/proofs/" + filename).c_str(), std::fstream::in | std::fstream::binary);
	    IntLeaf sigmaDec_l = IntLeaf(sigmaDec_l_file);
	    sigmaDec.addChild(sigmaDec_l);
    
	    print_debug("DecryptionVerifier: f", l, f_l.serialize());
	}
    }
    catch(...)
    {
	return false;
    }
    


    //Step 2
    bool result = DecryptionFactorsVerifier(0, ps, f, tauDec, sigmaDec, L);

    if(!result) {
	//Step 3
	for (int l = 0; l < f.getLength(); l++)
	{
	    result = DecryptionFactorsVerifier(l+1, ps, f, tauDec, sigmaDec, L);

	    IntLeaf xL = ps.x.getIntLeafChild(l);
			

	    if(!result && (xL == BOTTOM || f.getIntLeafChild(l) != PDec(xL, L.getIntLeafChild(l), p))) {
		return false;
	    }
	}
    }

    //Step 4
    IntLeaf x = f.prod();
    for(int i = 0; i < L.getLength(); i++) {
	if(m.getIntLeafChild(i) != TDec(L.getIntLeafChild(i), x, p)) {
	    return false;
	}
    }

    return true;
}