Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use read_only=True in test_salsa20.py #1282

Merged
merged 1 commit into from
Apr 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions saw-remote-api/python/tests/saw/test_salsa20.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@

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 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 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)
Expand Down Expand Up @@ -92,8 +92,8 @@ class ExpandContract(Contract):
def specification(self):
k = self.fresh_var(LLVMArrayType(i8, 32))
n = self.fresh_var(LLVMArrayType(i8, 16))
k_p = self.alloc(LLVMArrayType(i8, 32))
n_p = self.alloc(LLVMArrayType(i8, 16))
k_p = self.alloc(LLVMArrayType(i8, 32), read_only = True)
n_p = self.alloc(LLVMArrayType(i8, 16), read_only = True)
ks_p = self.alloc(LLVMArrayType(i8, 64))
self.points_to(k_p, k)
self.points_to(n_p, n)
Expand All @@ -117,8 +117,8 @@ def specification(self):

self.execute_func(k_p, v_p, cryptol('0 : [32]'), m_p, cryptol(f'{self.size!r} : [32]'))

self.returns(cryptol('0 : [32]'))
self.points_to(m_p, cryptol("Salsa20_encrypt")((k, v, m)))
self.returns(cryptol('0 : [32]'))

class Salsa20EasyTest(unittest.TestCase):
def test_salsa20(self):
Expand Down Expand Up @@ -146,8 +146,12 @@ def test_salsa20(self):
self.assertIs(hash_result.is_success(), True)
expand_result = llvm_verify(mod, 's20_expand32', ExpandContract(), lemmas=[hash_result])
self.assertIs(expand_result.is_success(), True)
crypt_result = llvm_verify(mod, 's20_crypt32', Salsa20CryptContract(63), lemmas=[expand_result])
self.assertIs(crypt_result.is_success(), True)
crypt_result_63 = llvm_verify(mod, 's20_crypt32', Salsa20CryptContract(63), lemmas=[expand_result])
self.assertIs(crypt_result_63.is_success(), True)
crypt_result_64 = llvm_verify(mod, 's20_crypt32', Salsa20CryptContract(64), lemmas=[expand_result])
self.assertIs(crypt_result_64.is_success(), True)
crypt_result_65 = llvm_verify(mod, 's20_crypt32', Salsa20CryptContract(65), lemmas=[expand_result])
self.assertIs(crypt_result_65.is_success(), True)

if __name__ == "__main__":
unittest.main()