コード例 #1
0
    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))
コード例 #2
0
    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)
コード例 #3
0
    def specification(self):
        tp = self.alloc(alias_ty('struct.t'))
        b = self.fresh_var(i32, "b")
        self.points_to(field(field(tp, "n"), "b"), b)

        self.execute_func(tp)

        self.returns(b)
コード例 #4
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)
コード例 #5
0
    def specification(self):
        tp = self.alloc(alias_ty('struct.t'))
        b = self.fresh_var(i32, "b")
        self.points_to(tp['n']['b'], b)

        self.execute_func(tp)

        self.returns(b)
コード例 #6
0
    def specification(self) -> None:
        instance = self.alloc(alias_ty("struct.signal_type_base"))
        destroy_func = global_var("signal_message_destroy")

        self.execute_func(instance, destroy_func)

        self.points_to(field(instance, "ref_count"), int_to_32_cryptol(1))
        self.points_to(field(instance, "destroy"), destroy_func)
        self.returns(void)
コード例 #7
0
    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)
コード例 #8
0
    def specification(self) -> None:
        ref_count = self.fresh_var(i32, "ref_count")
        self.precondition(cryptol(f"{ref_count.name()} > 0"))
        instance = self.alloc(alias_ty("struct.signal_type_base"))
        self.points_to(field(instance, "ref_count"), ref_count)

        self.execute_func(instance)

        self.points_to(field(instance, "ref_count"),
                       cryptol(f"{ref_count.name()} + 1"))
        self.returns(void)
コード例 #9
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))
コード例 #10
0
    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))
コード例 #11
0
import os
import os.path

from saw import cryptol_load_file, llvm_assume, llvm_verify
from saw.llvm import Contract, alias_ty, array, array_ty, cryptol, elem, field, global_var, i8, i32, i64, null, ptr_ty, struct, void
from saw.proofscript import ProofScript, z3

from buffer_helpers import *
from curve import *
from load import *
from saw_helpers import *

cryptol_load_file("cryptol/HMAC.cry")

signal_context_ty = alias_ty("struct.signal_context")

message_version = 3

HMAC_CONTEXT_LENGTH = 1
RATCHET_MAC_KEY_LENGTH = 32
SERIALIZED_LENGTH = 42
SIGNAL_MESSAGE_MAC_LENGTH = 8

dummy_signal_crypto_provider = struct(
    global_var("dummy_random_func"), global_var("dummy_hmac_sha256_init_func"),
    global_var("dummy_hmac_sha256_update_func"),
    global_var("dummy_hmac_sha256_final_func"),
    global_var("dummy_hmac_sha256_cleanup_func"),
    global_var("dummy_sha512_digest_init_func"),
    global_var("dummy_sha512_digest_update_func"),
    global_var("dummy_sha512_digest_final_func"),