コード例 #1
0
def alloc_blob(spec, n):
    p = spec.alloc(type=blob_type, read_only=True)
    datap = alloc_bytes(spec, n)
    spec.points_to(llvm.field(p, "data"), datap)
    spec.points_to(llvm.field(p, "size"), cry_f("`{n}:[32]"))
    spec.points_to(llvm.field(p, "allocated"), cry("0:[32]"))
    spec.points_to(llvm.field(p, "growable"), cry("0:[8]"))
    return (p, datap)
コード例 #2
0
ファイル: test_salsa20.py プロジェクト: Grain/saw-script
    def specification(self):
        (k, k_p) = ptr_to_fresh(self, LLVMArrayType(i8, 32))
        (v, v_p) = ptr_to_fresh(self, LLVMArrayType(i8, 8))
        (m, m_p) = ptr_to_fresh(self, LLVMArrayType(i8, self.size))

        self.execute_func(k_p, v_p, cry('0 : [32]'), m_p,
                          cry_f('{self.size} : [32]'))

        self.points_to(m_p, cry_f("Salsa20_encrypt {(k, v, m)}"))
        self.returns(cry('0 : [32]'))
コード例 #3
0
 def specification(self):
     (sp, keyp, s) = drbg_state(self, "drbg")
     (outp, datap) = alloc_blob(self, self.n)
     self.execute_func(sp, outp)
     res = cry_f("drbg_generate_internal `{{n={self.n}*8}} {s}")
     # Remove some of the parens here to get really bad error messages
     c = cry("split (({res}).0) : [{self.n}][8]")
     self.points_to(datap, c)
     ensure_drbg_state(self, sp, keyp, cry_f("{res}.1"))
     self.returns(cry(" 0 : [32] "))
コード例 #4
0
 def specification(self):
     (key, keyp) = ptr_to_fresh_readonly(self, "ctx", ctx_type)
     (msg, msgp) = ptr_to_fresh_readonly(self, "msg", bytes_type(blocksize))
     outp = alloc_bytes(self, blocksize)
     self.execute_func(keyp, msgp, outp)
     self.points_to(outp, cry_f("encrypt_128 {key} {msg}"))
     self.returns(cry("0 : [32]"))
コード例 #5
0
 def specification(self):
     (p, datap) = alloc_blob(self, blocksize)
     v = self.fresh_var(bytes_type(blocksize), "v")
     self.points_to(datap, v)
     self.execute_func(p)
     self.points_to(datap, cry_f("split ((join {v}) +1): [{blocksize}][8]"))
     self.returns(cry("0:[32]"))
コード例 #6
0
    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(cry('zero:[2][4][32]')))
        self.returns(void)
コード例 #7
0
    def specification(self):
        x = self.alloc(ptr_ty(i8))

        self.execute_func(x)

        p = self.alloc(i8)
        self.points_to(x, p)
        self.points_to(p, cry("42 : [8]"))
        self.returns(void)
コード例 #8
0
ファイル: test_llvm_struct.py プロジェクト: Grain/saw-script
    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, cry('[0, 0] : [2][32]'))
        self.returns(void)
コード例 #9
0
 def specification(self):
     (sp, keyp, s) = drbg_state(self, "drbg")
     (psp, datap) = alloc_blob_readonly(self, self.n)
     data = self.fresh_var(bytes_type(self.n), "data")
     self.points_to(datap, data)
     self.execute_func(sp, psp)
     expr = "drbg_reseed ({s}) (fake_entropy) (join ({data}))".format(
         s=s, data=data.name())
     ensure_drbg_state(self, sp, keyp, expr)
     self.returns(cry("0:[32]"))
コード例 #10
0
 def specification(self):
     (sp, keyp, s) = drbg_state(self, "drbg")
     (providedp, datap) = alloc_blob_readonly(self, self.n)
     data = self.fresh_var(bytes_type(self.n), "data")
     self.points_to(datap, data)
     self.execute_func(sp, providedp)
     ensure_drbg_state(
         self, sp, keyp,
         "drbg_update (join {data}) ({s})".format(data=data.name(), s=s))
     self.returns(cry("0:[32]"))
コード例 #11
0
 def specification(self):
     ctx = self.alloc(ctx_type)
     #(ct, ctx) = ptr_to_fresh(self, "ctx", ctx_type)
     #(st, stp) = ptr_to_fresh(self, "st", ctx_type)
     #st = self.fresh_var(ctx_type)
     #stp = self.alloc(ctx_type, points_to = st)
     (key, keyp) = ptr_to_fresh_readonly(self, "key", ctx_type)
     #self.execute_func(ctx, stp, llvm.null, keyp, llvm.null)
     self.execute_func(ctx, llvm.null, llvm.null, keyp, llvm.null)
     self.points_to(ctx, key)
     self.returns(cry("1:[32]"))
コード例 #12
0
ファイル: test_salsa20.py プロジェクト: Grain/saw-script
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
コード例 #13
0
 def specification(self):
     # the first argument of `EVP_EncryptUpdate` is not `const`,
     # but it is constant in the DRBG cryptol specification.
     (key, keyp) = ptr_to_fresh_readonly(self, "key", ctx_type)
     outp = alloc_bytes(self, self.n)
     lenp = alloc_init(self, i32, cry_f("{self.n} : [32]"))
     (msg, msgp) = ptr_to_fresh_readonly(self, "msg", (bytes_type(self.n)))
     self.execute_func(keyp, outp, lenp, msgp, cry_f("`{blocksize} : [32]"))
     self.points_to(outp, cry_f("encrypt_128 {key} {msg}"))
     self.points_to(lenp, cry_f("{self.n} : [32]"))
     self.returns(cry("1 : [32]"))
コード例 #14
0
 def specification(self):
     (p, datap) = alloc_blob(self, seedsize)
     self.execute_func(p)
     # TODO: blocked on 'fake_entropy'
     #self.points_to(datap, cry_f("split fake_entropy : [{seedsize}][8]"))
     self.returns(cry("0: [32]"))
コード例 #15
0
 def specification(self):
     ctx = self.alloc(ctx_type, read_only=True)
     self.execute_func(ctx)
     # Specialized to AES-128 for now
     self.returns(cry("16:[32]"))
コード例 #16
0
 def specification(self):
     ctx = self.alloc(ctx_type)
     self.execute_func(ctx)
     self.points_to(ctx, cry_f("zero : [{keysize}][8]"))
     self.returns(cry("1:[32]"))
コード例 #17
0
 def specification(self):
     (sp, keyp, s) = drbg_state(self, "drbg")
     bytes_used = alloc_init(self, i64, cry("0:[64]"))
     self.execute_func(sp, bytes_used)
     self.points_to(bytes_used, cry_f("{s}.bytes_used"))
     self.returns(cry("0:[32]"))
コード例 #18
0
 def specification(self):
     (p, datap) = alloc_blob(self, self.n)
     self.execute_func(p)
     self.points_to(datap, cry_f("zero:[{self.n}][8]"))
     self.returns(cry("0:[32]"))
コード例 #19
0
    def specification(self):
        p = self.alloc(i32)

        self.execute_func(p)

        self.returns(cry("0 : [32]"))
コード例 #20
0
    def specification(self):
        self.execute_func(null())

        self.returns(cry("1 : [32]"))