Esempio n. 1
0
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
Esempio n. 2
0
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)
Esempio n. 3
0
def ptr_to_fresh(spec : Contract, ty : LLVMType, name : Optional[str] = None) -> Tuple[FreshVar, SetupVal]:
    """Add to``Contract`` ``spec`` 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 = spec.fresh_var(ty, name)
    ptr = spec.alloc(ty, points_to = var)
    return (var, ptr)
Esempio n. 4
0
def ptr_to_fresh(c: Contract,
                 ty: LLVMType,
                 name: Optional[str] = None,
                 read_only: bool = False) -> Tuple[FreshVar, SetupVal]:
    """Add to ``Contract`` ``c`` an allocation of a pointer of type ``ty`` initialized to an unknown fresh value.
    If ``read_only == True`` then the allocated memory is immutable.

    :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, read_only=read_only)
    return (var, ptr)
def y_spec(c: Contract) -> None:
    ss = c.alloc(alias_ty('struct.s'))
    z = c.fresh_var(i1, 'z')

    c.execute_func(ss, z)

    c.points_to_bitfield(ss, 'y', z)
    c.returns(void)
Esempio n. 6
0
def oneptr_update_func(c: Contract, ty: LLVMType, fn_name: str) -> None:
    """Updates 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, cry(fn_name)(x))
    c.returns(void)
    return None
Esempio n. 7
0
def alloc_buffer_aligned_readonly(spec: Contract, length: int) -> SetupVal:
    return spec.alloc(buffer_type(length), alignment=16, read_only=True)
Esempio n. 8
0
def alloc_buffer_aligned(spec: Contract, length: int) -> SetupVal:
    return spec.alloc(buffer_type(length), alignment=16)
Esempio n. 9
0
def pre_counter(contract: Contract, counter: GhostVariable):
    n = contract.fresh_var(i32, "n")
    contract.precondition_f("{n} < 128")
    contract.ghost_value(counter, n)
    return n
Esempio n. 10
0
def post_counter(contract: Contract, counter: GhostVariable, n: CryptolTerm):
    contract.ghost_value(counter, cry_f("{n} + 1"))
Esempio n. 11
0
def pre_counter(contract: Contract, counter: GhostVariable):
    n = contract.fresh_var(i32, "n")
    contract.precondition(n < cryptol("128"))
    contract.ghost_value(counter, n)
    return n
Esempio n. 12
0
def post_counter(contract: Contract, counter: GhostVariable, n: CryptolTerm):
    contract.ghost_value(counter, cryptol("(+)")(n, cryptol("1")))