def specification(self): ty = array_ty(2, array_ty(4, i32)) i = self.fresh_var(ty, "w.i") pw = self.alloc(struct_ty(ty), points_to=struct(i)) self.execute_func(pw) self.points_to(pw, struct(cryptol('zero:[2][4][32]'))) self.returns(void)
def specification(self) -> None: x = self.fresh_var(array_ty(2, i32), "x") p = self.alloc(array_ty(4, i32)) self.points_to(p, x, check_target_type=self.check_x_type) self.execute_func(p) self.points_to(p, cryptol("{x} # {x}".format(x=x.name()))) self.returns(void)
def specification(self) -> None: (s1, s1p) = ptr_to_fresh(self, array_ty(self.n, i8), name="s1") (s2, s2p) = ptr_to_fresh(self, array_ty(self.n, i8), name="s2") nval = int_to_64_cryptol(self.n) self.execute_func(s1p, s2p, nval) self.returns( cryptol( f"zext`{{32}} (foldl (||) zero (zipWith (^) {s1.name()} {s2.name()}))" ))
def specification(self) -> None: message = self.alloc(alias_ty("struct.signal_message")) (_, sender_identity_key_data, sender_identity_key) = alloc_ec_public_key(self) (_, receiver_identity_key_data, receiver_identity_key) = alloc_ec_public_key(self) mac_key_data = self.fresh_var(array_ty(self.mac_key_len, i8), "mac_key_data") mac_key = self.alloc(array_ty(self.mac_key_len, i8), points_to=mac_key_data) global_context_unused_as_far_as_i_can_tell = self.alloc( signal_context_ty, read_only=True) base = self.fresh_var(alias_ty("struct.signal_type_base"), "base") message_type = self.fresh_var(i32, "message_type") global_context = self.alloc(signal_context_ty, read_only=True) self.points_to(field(global_context, "crypto_provider"), dummy_signal_crypto_provider) serialized_message_len = self.serialized_len - SIGNAL_MESSAGE_MAC_LENGTH serialized_message_data = self.fresh_var( array_ty(serialized_message_len, i8), "serialized_message_data") expected_mac_data = mk_hmac(serialized_message_len, serialized_message_data, receiver_identity_key_data, sender_identity_key_data, self.mac_key_len, mac_key_data) serialized = alloc_buffer_aligned(self, self.serialized_len) self.points_to(elem(serialized, 0), int_to_64_cryptol(self.serialized_len), check_target_type=None) self.points_to(elem(serialized, 8), serialized_message_data, check_target_type=None) self.points_to(elem(serialized, 8 + serialized_message_len), expected_mac_data, check_target_type=None) base_message = struct(base, message_type, global_context, serialized) self.points_to(field(message, "base_message"), base_message) self.points_to(field(message, "message_version"), int_to_8_cryptol(message_version)) self.execute_func(message, sender_identity_key, receiver_identity_key, mac_key, int_to_64_cryptol(self.mac_key_len), global_context_unused_as_far_as_i_can_tell) self.returns(int_to_32_cryptol(1))
def specification(self): (x, x_p) = ptr_to_fresh(self, array_ty(2, i32), "x") p = self.alloc(alias_ty('struct.s'), points_to=struct(x_p)) self.execute_func(p) self.returns(p)
def specification(self) -> None: buf_data = self.fresh_var(array_ty(self.buf_length, i8), "buffer_data") buf = alloc_pointsto_buffer(self, self.buf_length, buf_data) (additional_data, additional_datap) = ptr_to_fresh(self, array_ty(self.additional_length, i8), name="additional_data") self.execute_func(buf, additional_datap, int_to_64_cryptol(self.additional_length)) new_length = self.buf_length + self.additional_length new_buf = alloc_pointsto_buffer( self, new_length, cryptol(f"{buf_data.name()} # {additional_data.name()}")) self.returns(new_buf)
def alloc_ec_public_key(spec: Contract) -> Tuple[FreshVar, FreshVar, SetupVal]: signal_type_base_ty = alias_ty("struct.signal_type_base") djb_array_ty = array_ty(DJB_KEY_LEN, i8) key_base = spec.fresh_var(signal_type_base_ty, "key_base") key_data = spec.fresh_var(djb_array_ty, "key_data") key = spec.alloc(struct_ty(signal_type_base_ty, djb_array_ty), points_to = struct(key_base, key_data)) return (key_base, key_data, key)
def specification(self) -> None: data = self.fresh_var(array_ty(self.length, i8), "data") buf = alloc_pointsto_buffer_readonly(self, self.length, data) self.execute_func(buf) new_buf = alloc_pointsto_buffer(self, self.length, data) self.returns(new_buf)
def specification(self): (_, x_p) = ptr_to_fresh(self, array_ty(2, i32), "x") p = self.alloc(alias_ty('struct.s'), points_to=struct(x_p)) self.execute_func(p) self.points_to(p, struct(x_p)) self.points_to(x_p, cryptol('[0, 0] : [2][32]')) self.returns(void)
def specification(self) -> None: (data, datap) = ptr_to_fresh(self, array_ty(self.length, i8), name="data") self.execute_func(datap, int_to_64_cryptol(self.length)) buf = alloc_pointsto_buffer(self, self.length, data) self.returns(buf)
def specification(self): a0 = self.fresh_var(i32, "a0") a1 = self.fresh_var(i32, "a1") a = self.alloc(array_ty(2, i32), points_to=array(a0, a1)) self.execute_func(a) self.points_to(a[0], a1) self.points_to(a[1], a0) self.returns(void)
def specification(self) -> None: context = self.alloc(signal_context_ty, read_only=True) hmac_context_data = self.fresh_var(array_ty(HMAC_CONTEXT_LENGTH, i8), "hmac_context_data") hmac_context = self.alloc(array_ty(HMAC_CONTEXT_LENGTH, i8), points_to=hmac_context_data) output = self.alloc(ptr_ty(buffer_type(SIGNAL_MESSAGE_MAC_LENGTH))) self.points_to(field(context, "crypto_provider"), dummy_signal_crypto_provider) self.execute_func(context, hmac_context, output) # output_buffer = alloc_buffer_aligned(self, SIGNAL_MESSAGE_MAC_LENGTH) # self.points_to(elem(output_buffer, 0), int_to_64_cryptol(SIGNAL_MESSAGE_MAC_LENGTH), check_target_type = i64) output_buffer = alloc_pointsto_buffer( self, SIGNAL_MESSAGE_MAC_LENGTH, cryptol(f"hmac_final {hmac_context_data.name()}")) self.points_to(output, output_buffer) self.returns(int_to_32_cryptol(0))
def test_points_to_at_type(self): if __name__ == "__main__": view(LogResults()) bcname = str(Path('tests', 'saw', 'test-files', 'points_to_at_type.bc')) mod = llvm_load_module(bcname) result = llvm_verify(mod, "f", FPointsToContract(None)) self.assertIs(result.is_success(), True) result = llvm_verify(mod, "f", FPointsToContract(array_ty(2, i32))) self.assertIs(result.is_success(), True)
def specification(self) -> None: context = self.alloc(signal_context_ty, read_only=True) hmac_context_data = self.fresh_var(array_ty(HMAC_CONTEXT_LENGTH, i8), "hmac_context_data") hmac_context = self.alloc(array_ty(HMAC_CONTEXT_LENGTH, i8), points_to=hmac_context_data) data_data = self.fresh_var(array_ty(self.data_len, i8), "data_data") data = self.alloc(array_ty(self.data_len, i8), points_to=data_data) self.points_to(field(context, "crypto_provider"), dummy_signal_crypto_provider) self.execute_func(context, hmac_context, data, int_to_64_cryptol(self.data_len)) # self.points_to(hmac_context, hmac_context_data) self.points_to( hmac_context, cryptol( f"hmac_update`{{ {self.data_len} }} {data_data.name()} {hmac_context_data.name()}" )) self.returns(int_to_32_cryptol(0))
def specification(self) -> None: context = self.alloc(signal_context_ty, read_only=True) hmac_context_ptr = self.alloc(ptr_ty(array_ty(HMAC_CONTEXT_LENGTH, i8))) key_data = self.fresh_var(array_ty(self.key_len, i8), "key_data") key = self.alloc(array_ty(self.key_len, i8), points_to=key_data) self.points_to(field(context, "crypto_provider"), dummy_signal_crypto_provider) self.execute_func(context, hmac_context_ptr, key, int_to_64_cryptol(self.key_len)) dummy_hmac_context = self.alloc(array_ty(HMAC_CONTEXT_LENGTH, i8), points_to=array(int_to_8_cryptol(42))) # self.points_to(hmac_context_ptr, dummy_hmac_context) dummy_hmac_context = self.alloc( array_ty(HMAC_CONTEXT_LENGTH, i8), points_to=cryptol( f"hmac_init`{{ {self.key_len} }} {key_data.name()}")) self.points_to(hmac_context_ptr, dummy_hmac_context) self.returns(int_to_32_cryptol(0))
def specification(self) -> None: data = self.fresh_var(array_ty(self.length, i8), "data") buf = alloc_pointsto_buffer_readonly(self, self.length, data) self.execute_func(buf, int_to_64_cryptol(self.n)) new_length = min(self.length, self.n) new_buf = alloc_pointsto_buffer( self, new_length, cryptol(f"take`{{ {new_length} }} {data.name()}")) self.returns(new_buf)
def specification(self) -> None: ec_public_key = alias_ty("struct.ec_public_key") buffer_ = self.alloc(ptr_ty(buffer_type(SIGNAL_MESSAGE_MAC_LENGTH))) (_, sender_identity_key_data, sender_identity_key) = alloc_ec_public_key(self) (_, receiver_identity_key_data, receiver_identity_key) = alloc_ec_public_key(self) mac_key_data = self.fresh_var(array_ty(self.mac_key_len, i8), "mac_key_data") mac_key = self.alloc(array_ty(self.mac_key_len, i8), points_to=mac_key_data) serialized_data = self.fresh_var(array_ty(self.serialized_len, i8), "serialized_data") serialized = self.alloc(array_ty(self.serialized_len, i8), points_to=serialized_data) global_context = self.alloc(signal_context_ty, read_only=True) self.points_to(field(global_context, "crypto_provider"), dummy_signal_crypto_provider) self.execute_func(buffer_, int_to_8_cryptol(message_version), sender_identity_key, receiver_identity_key, mac_key, int_to_64_cryptol(self.mac_key_len), serialized, int_to_64_cryptol(self.serialized_len), global_context) expected = mk_hmac(self.serialized_len, serialized_data, receiver_identity_key_data, sender_identity_key_data, self.mac_key_len, mac_key_data) # buffer_buf = alloc_buffer_aligned(self, SIGNAL_MESSAGE_MAC_LENGTH) # self.points_to(elem(buffer_buf, 0), int_to_64_cryptol(SIGNAL_MESSAGE_MAC_LENGTH), check_target_type = i64) buffer_buf = alloc_pointsto_buffer(self, SIGNAL_MESSAGE_MAC_LENGTH, expected) self.points_to(buffer_, buffer_buf) self.returns(int_to_32_cryptol(0))
def specification(self) -> None: length = DJB_KEY_LEN + 1 signal_type_base_ty = alias_ty("struct.signal_type_base") djb_array_ty = array_ty(DJB_KEY_LEN, i8) buffer_ = self.alloc(ptr_ty(buffer_type(length))) key_base = self.fresh_var(signal_type_base_ty, "key_base") key_data = self.fresh_var(djb_array_ty, "key_data") key = self.alloc(struct_ty(signal_type_base_ty, djb_array_ty), points_to=struct(key_base, key_data)) self.execute_func(buffer_, key) buf = alloc_pointsto_buffer( self, length, cryptol(f"[`({DJB_TYPE})] # {key_data.name()} : [{length}][8]")) self.points_to(buffer_, buf) self.returns(int_to_32_cryptol(0))
def buffer_type(length: int) -> LLVMType: return array_ty(8 + length, i8)