コード例 #1
0
def _main():
    isas = list(
        itertools.product(TOPLEVELS, OPCODE_TYPES, INSTR_TYPES,
                          TERMINATE_TYPES))
    print(LINE_SEP)
    print(green("Launching %d experiments ..." % (len(isas) * len(RUNS))))
    print(LINE_SEP)

    # create a temp dir to store config files
    try:
        tmp_dir = os.path.join(os.getcwd(), "tmp%d")
        i = 0
        while os.path.isdir(tmp_dir % i):
            i += 1
        tmp_dir = tmp_dir % i
        os.mkdir(tmp_dir)

        # create config files on the fly and launch experiments
        for toplevel, opcode_type, instr_type, terminate_type in isas:
            for run in RUNS:
                # craft config dictionary
                cdict = copy.deepcopy(CONFIG_DICT)

                # Set experiment name
                experiment_name = EXPERIMENT_BASE_NAME % (
                    toplevel, opcode_type, instr_type, terminate_type, run)
                experiment_name = experiment_name.replace("_", "-")
                # print(experiment_name)
                # continue
                cdict["experiment_name"] = experiment_name
                cdict["toplevel"] = toplevel

                # Set configurations
                cdict["fuzzer_params"]["duration_mins"] = DURATION_MINS
                cdict["model_params"]["opcode_type"] = opcode_type
                cdict["model_params"]["instr_type"] = instr_type
                if terminate_type == "invalidop":
                    cdict["model_params"]["terminate_on_invalid_opcode"] = 1
                else:
                    cdict["model_params"]["terminate_on_invalid_opcode"] = 0

                # write to HJSON file
                hjson_filename = experiment_name + ".hjson"
                hjson_file_path = os.path.join(tmp_dir, hjson_filename)
                with open(hjson_file_path, "w") as fp:
                    hjson.dump(cdict, fp)

                # launch fuzz the DUT
                fuzz(["--fail-silently", hjson_file_path])

                # cleanup config file
                os.remove(hjson_file_path)

    finally:
        for directory in glob.glob("tmp*"):
            shutil.rmtree(directory)

    print(LINE_SEP)
    print(green("DONE!"))
    print(LINE_SEP)
コード例 #2
0
def _run_simulation(config_dict, output_log_file_name, aes_test):
    # Get path of experiment log file
    exp_log = os.path.join(os.getenv("HW_FUZZING"), "data",
                           config_dict["experiment_name"], "logs", "exp.log")
    # Set correct seed file
    config_dict["fuzzer_params"]["seed"] = aes_test.hwf_seed
    # Write configs to a temp HJSON file
    with open(TMP_HJSON_CONFIG, "w") as fp:
        hjson.dump(config_dict, fp)
    # Run encrypt test in HWFP
    fuzz(["-y", "--log-driver", "none", "-s", TMP_HJSON_CONFIG])
    shutil.copy(exp_log, output_log_file_name)
コード例 #3
0
def _main():
  print(LINE_SEP)
  print(green("Launching %d experiments ..." % (len(TOPLEVELS) * len(RUNS))))
  print(LINE_SEP)

  # create a temp dir to store config files
  with tempfile.TemporaryDirectory() as tmp_dir:
    # create config files on the fly and launch experiments
    for toplevel in TOPLEVELS:
      for run in RUNS:
        # craft config dictionary
        cdict = copy.deepcopy(CONFIG_DICT)

        # Set experiment name
        experiment_name = EXPERIMENT_BASE_NAME % (toplevel, DURATION_MINS, run)
        experiment_name = experiment_name.replace("_", "-").lower()
        cdict["experiment_name"] = experiment_name
        cdict["toplevel"] = toplevel

        # Set configurations
        cdict["fuzzer_params"]["duration_mins"] = DURATION_MINS

        # write to HJSON file
        hjson_filename = experiment_name + ".hjson"
        hjson_file_path = os.path.join(tmp_dir, hjson_filename)
        with open(hjson_file_path, "w") as fp:
          hjson.dump(cdict, fp)

        # launch fuzz the DUT
        # fuzz(["--fail-silently", hjson_file_path])
        fuzz([
            "-y", "--gcp-config-filename", "gcp_config.east1b.hjson",
            hjson_file_path
        ])

        # cleanup config file
        os.remove(hjson_file_path)

  print(LINE_SEP)
  print(green("DONE!"))
  print(LINE_SEP)
コード例 #4
0
def _main():
  num_experiments = len(NUM_STATES) * len(COMP_WIDTHS) * len(RUNS) * len(
      EXPERIMENT_BASE_NAMES)
  print(LINE_SEP)
  print(LINE_SEP)
  print(LINE_SEP)
  print(green("LAUNCHING %d EXPERIMENTS ..." % num_experiments))
  print(LINE_SEP)
  print(LINE_SEP)
  print(LINE_SEP)

  # create a temp dir to store config files
  try:
    tmp_dir = os.path.join(os.getcwd(), "tmp%d")
    i = 0
    while os.path.isdir(tmp_dir % i):
      i += 1
    tmp_dir = tmp_dir % i
    os.mkdir(tmp_dir)

    # create config files on the fly and launch experiments
    for experiment_base_name in EXPERIMENT_BASE_NAMES:
      for states in NUM_STATES:
        for width in COMP_WIDTHS:
          for run in RUNS:
            # craft config dictionary
            cdict = copy.deepcopy(CONFIG_DICT)

            # Set experiment name
            experiment_name = experiment_base_name % (states, width, run)
            cdict["experiment_name"] = experiment_name

            # Set test bench
            if "wopt" in experiment_name:
              cdict["tb"] = "afl_opt"
            else:
              cdict["tb"] = "afl"

            # Set instrumentation amount
            if "full-instr" in experiment_name:
              cdict["instrument_dut"] = 1
              cdict["instrument_tb"] = 1
              cdict["instrument_vltrt"] = 1
            elif "duttb-instr" in experiment_name:
              cdict["instrument_dut"] = 1
              cdict["instrument_tb"] = 1
              cdict["instrument_vltrt"] = 0
            elif "dut" in experiment_name:
              cdict["instrument_dut"] = 1
              cdict["instrument_tb"] = 0
              cdict["instrument_vltrt"] = 0
            else:
              print(red("ERROR: invalid instrumentation config. ABORTING!"))
              sys.exit(1)

            # Set lock size
            cdict["hdl_gen_params"]["num_lock_states"] = states
            cdict["hdl_gen_params"]["lock_comp_width"] = width

            # write to HJSON file
            hjson_filename = experiment_name + ".hjson"
            hjson_file_path = os.path.join(tmp_dir, hjson_filename)
            with open(hjson_file_path, "w") as fp:
              hjson.dump(cdict, fp)

            # launch fuzz the DUT
            fuzz(["--fail-silently", hjson_file_path])

            # cleanup config file
            os.remove(hjson_file_path)

  finally:
    # remove temp dir
    for tmp_dir in glob.glob("tmp*"):
      shutil.rmtree(tmp_dir, ignore_errors=True)

  print(LINE_SEP)
  print(LINE_SEP)
  print(LINE_SEP)
  print(green("DONE!"))
  print(LINE_SEP)
  print(LINE_SEP)
  print(LINE_SEP)