1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
use crate::default_hook::{ArgumentKind, is_or_points_to_secret};
use crate::secret;
use haybale::function_hooks::{IsCall, generic_stub_hook};
use haybale::{Project, Result, ReturnValue, State};
use llvm_ir::{Name, Type, Typed};
pub fn return_public_unconstrained(
proj: &Project,
state: &mut State<secret::Backend>,
call: &dyn IsCall,
) -> Result<ReturnValue<secret::BV>> {
generic_stub_hook(proj, state, call)
}
pub fn return_secret(
_proj: &Project,
state: &mut State<secret::Backend>,
call: &dyn IsCall,
) -> Result<ReturnValue<secret::BV>> {
match call.get_type() {
Type::VoidType => Ok(ReturnValue::ReturnVoid),
ty => {
let width = haybale::layout::size(&ty);
let bv = state.new_bv_with_name(Name::from("return_secret_retval"), width as u32)?;
Ok(ReturnValue::Return(bv))
},
}
}
pub fn propagate_taint(
proj: &Project,
state: &mut State<secret::Backend>,
call: &dyn IsCall,
) -> Result<ReturnValue<secret::BV>> {
for arg in call.get_arguments().iter().map(|(arg, _)| arg) {
let arg_bv = state.operand_to_bv(arg)?;
match is_or_points_to_secret(proj, state, &arg_bv, &arg.get_type())? {
ArgumentKind::Public | ArgumentKind::Unknown => {},
ArgumentKind::Secret => return return_secret(proj, state, call),
}
}
return_public_unconstrained(proj, state, call)
}