def alloc_pointsto_buffer_readonly(spec: Contract, length: int, data: SetupVal) -> SetupVal: buf = alloc_buffer_aligned_readonly(spec, length) spec.points_to(buf, struct(int_to_64_cryptol(length)), check_target_type=None) return buf
def ptr_to_fresh(c : Contract, ty : LLVMType, name : Optional[str] = None) -> Tuple[FreshVar, SetupVal]: """Add to``Contract`` ``c`` an allocation of a pointer of type ``ty`` initialized to an unknown fresh value. :returns A fresh variable bound to the pointers initial value and the newly allocated pointer. (The fresh variable will be assigned ``name`` if provided/available.)""" var = c.fresh_var(ty, name) ptr = c.alloc(ty, points_to = var) return (var, ptr)
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 setup_hash_state(c: Contract, pstate: SetupVal) -> Tuple[Any, FreshVar]: alg0 = c.fresh_var(ty.i32, "alg") h0 = c.fresh_var(ty.array(8, ty.i64), "h0") Nl0 = c.fresh_var(ty.i64, "Nl") Nh0 = c.fresh_var(ty.i64, "Nh") u0 = c.fresh_var(ty.array(16, ty.i64), "u") num0 = c.fresh_var(ty.i32, "h0") is_ready_for_input0 = c.fresh_var(ty.i8, "is_ready_for_input") currently_in_hash0 = c.fresh_var(ty.i64, "currently_in_hash") md_len0 = c.fresh_var(ty.i32, "md_len") (_, pimpl) = ptr_to_fresh(c, ty.alias('struct.s2n_hash'), "impl", read_only=True) c.points_to( pstate, struct(pimpl, alg0, is_ready_for_input0, currently_in_hash0, struct(struct(struct(h0, Nl0, Nh0, struct(u0), num0, md_len0)))))
def oneptr_update_func(c: Contract, ty: LLVMType, fn_name: str) -> None: """Upcates contract ``c`` to declare calling it with a pointer of type ``ty`` updates that pointer with the result, which is equal to calling the Cryptol function ``fn_name``.""" (x, x_p) = ptr_to_fresh(c, ty) c.execute_func(x_p) c.points_to(x_p, cryptol(fn_name)(x)) c.returns(void) return None
def alloc_buffer_aligned_readonly(spec: Contract, length: int) -> SetupVal: return spec.alloc(buffer_type(length), alignment=16, read_only=True)
def alloc_buffer_aligned(spec: Contract, length: int) -> SetupVal: return spec.alloc(buffer_type(length), alignment=16)