cloud9_root/src/cloud9/lib/Core/CacheDriver.cpp
// constrain one bit at a time for a secret input
constrain one bit at a time for a secret input
constrain one bit at a time for a secret input
ref<Expr> CacheDriver::constrainOneBit(ExecutionState& state, int nbit, bool trueorfalse) {
	ref<Expr> ret = NULL;
	for (unsigned SI = 0; SI < state.symbolics.size(); SI++) {
			UpdateList ul(state.symbolics[SI].second, 0);
			int nbyte = nbit/SIZE_OF_BYTE;
			int posbyte = nbit % SIZE_OF_BYTE;
			ref<Expr> read = ReadExpr::create(ul, ConstantExpr::create(nbyte, Expr::Int32));
			for (int num = 0x00; num <= 0xFF; num++) {
				bool check = (trueorfalse) ? ((num & (1 << posbyte)) != 0) : ((num & (1 << posbyte)) == 0);
				if (check) {
					ref<Expr> value = ConstantExpr::alloc(num, read->getWidth());
					if (ret.isNull())
						ret = EqExpr::create(read, value);
					else
						ret = OrExpr::create(ret, EqExpr::create(read, value));
				}
			}
		}
		assert(!ret.isNull() && "bit constraint checking went wrong");
		return ret;
}
ref < Expr > CacheDriver :: constrainOneBit ( ExecutionState & state , int nbit , bool trueorfalse ) { ref < Expr > ret = NULL ; for ( unsigned SI = 0 ; SI < state . symbolics . size ( ) ; SI ++ ) { UpdateList ul ( state . symbolics [ SI ] . second , 0 ) ; int nbyte = nbit / SIZE_OF_BYTE ; int posbyte = nbit % SIZE_OF_BYTE ; ref < Expr > read = ReadExpr :: create ( ul , ConstantExpr :: create ( nbyte , Expr :: Int32 ) ) ; for ( int num = 0x00 ; num <= 0xFF ; num ++ ) { bool check = ( trueorfalse ) ? ( ( num & ( 1 << posbyte ) ) != 0 ) : ( ( num & ( 1 << posbyte ) ) == 0 ) ; if ( check ) { ref < Expr > value = ConstantExpr :: alloc ( num , read -> getWidth ( ) ) ; if ( ret . isNull ( ) ) ret = EqExpr :: create ( read , value ) ; else ret = OrExpr :: create ( ret , EqExpr :: create ( read , value ) ) ; } } } assert ( ! ret . isNull ( ) && " " ) ; return ret ; }
constrain one bit at a time for a secret input
constrain one bit at a time for a secret input
/* get the byte position from the bit number */ /* TODO: change to a more efficient implementation with bit-level read? */