Example #1
0
def __main__():
    db = hash_framework.database()

    if len(sys.argv) >= 2:
        if sys.argv[1] == 'sqlite' or sys.argv[1] == 'sqlite3':
            db_path = config.results_dir + "/worker_results.db"
            if len(sys.argv) == 3:
                db_path = sys.argv[2]

            db.close()
            db = hash_framework.database(path=db_path)
        elif sys.argv[1] == 'psql':
            db.close()
            db.init_psql()
        else:
            print_usage()
            return


    for name in hash_framework.algorithms.all_algorithms:
        algo = hash_framework.algorithms.lookup(name)

        try:
            hash_framework.attacks.collision.create_table(algo, db)
        except:
            pass
Example #2
0
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert (len(sys.argv) == 2)
    tid = int(sys.argv[1])

    q = "SELECT id, run_return, run_time, args FROM jobs WHERE task_id=" + str(
        tid) + " AND state=2 AND run_time > 75000 ORDER BY run_time DESC;"
    r, cur = db.execute(q, cursor=True)

    row = cur.fetchone()
    while row != None:
        jid, run_return, run_time, args = row
        obj = json.loads(args)
        algo = obj['algo']
        rounds = obj['rounds']
        p = len(obj['places'])
        places = '-'.join(map(str, obj['places']))

        sat = 'SAT'
        if run_return == 20:
            sat = 'UNSAT'
        elif run_return != 10:
            sat = 'ERROR'

        print("%d %d %s # %s %s %d" % (rounds, p, places, algo, sat, run_time))

        row = cur.fetchone()
Example #3
0
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert (len(sys.argv) == 2)
    tid = int(sys.argv[1])

    q = "SELECT id, run_return, run_time, args FROM jobs WHERE task_id=" + str(
        tid
    ) + " AND state=2 AND run_time > 75000 AND run_time < 3600000 ORDER BY run_time DESC;"
    r, cur = db.execute(q, cursor=True)

    row = cur.fetchone()
    while row != None:
        jid, run_return, run_time, args = row
        obj = json.loads(args)
        algo = obj['algo']
        rounds = '-'.join(obj['rounds'])
        input_error = obj['input_error']
        output_error = obj['output_error']
        w = obj['w']
        # {'algo': 'sha3', 'cms_args': [], 'w': 4, 'rounds': ['p'], 'input_error': 20, 'output_error': 72}
        #print(obj)

        sat = 'SAT'
        if run_return == 20:
            sat = 'UNSAT'
        elif run_return != 10:
            sat = 'ERROR'

        print("%d %s %d %d # %s %s %d" %
              (w, rounds, input_error, output_error, algo, sat, run_time))

        row = cur.fetchone()
Example #4
0
def get_cw():
    db = hf.database()
    db.close()
    db.init_psql()

    results = []

    mjid = 36791300
    tid = 82
    q = ("SELECT run_return, args FROM jobs WHERE task_id=" + str(tid) +
         " AND state=2 AND id >= " + str(mjid) + ";")
    r, cur = db.execute(q, cursor=True)

    last_round = ["r", "p", "c", "i22", "t", "r", "p", "c", "i23"]

    row = cur.fetchone()
    while row != None:
        run_return, args = row
        obj = json.loads(args)
        rounds = obj["rounds"]
        diff = obj["differences"]

        if run_return == 10 and rounds == last_round:
            results.append((rounds, diff))

        row = cur.fetchone()

    print(len(results))

    return results
Example #5
0
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert(len(sys.argv) == 2)
    tid = int(sys.argv[1])

    q = "SELECT id, run_return, run_time, args FROM jobs WHERE task_id=" + str(tid) + " AND state=2 ORDER BY run_time DESC;"
    r, cur = db.execute(q, cursor=True)

    results = []

    row = cur.fetchone()
    while row != None:
        jid, run_return, run_time, args = row
        obj = json.loads(args)
        algo = obj['algo']
        rounds = obj['rounds']
        places = obj['places']

        if run_return == 10:
            write_tuple(rounds, places, 'sat')
        elif run_return == 20:
            write_tuple(rounds, places, 'unsat')

        row = cur.fetchone()
Example #6
0
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert(len(sys.argv) == 3)
    tid = int(sys.argv[1])

    q = "SELECT id, run_return, args FROM jobs WHERE task_id=" + str(tid) + " AND state=2;"
    r, cur = db.execute(q, cursor=True)

    results = {}
    for w in [1, 2, 4]:
        arr = []
        for j in range(0, 25*w):
            arr.append([0] * (25*w))
        results[w] = arr

    row = cur.fetchone()
    while row != None:
        jid, run_result, args = row
        obj = json.loads(args)
        w = obj['w']
        input_error = obj['input_error']
        output_error = obj['output_error']
        if w in results:
            results[w][input_error][output_error] = run_result
        else:
            print((w, input_error, output_error))

        row = cur.fetchone()

    for w in results:
        draw_table(results[w], 25*w, "/tmp/table-diff-" + sys.argv[2] + "-w" + str(w) + "-o0.png")
Example #7
0
def __main__():
    if len(sys.argv) != 3:
        print("Usage: " + sys.argv[0] + " algorithm /path/to/results.db")
        return

    db = hash_framework.database()
    algo = hash_framework.algorithms.lookup(sys.argv[1])()
    hash_framework.attacks.collision.import_from_other(db, algo, sys.argv[2])
def acquire_db():
    if len(db_pool) == 0:
        db = hash_framework.database()
        db.close()
        db.init_psql()
        db_pool.append(db)
        return db

    return db_pool[0]
Example #9
0
def acquire_db():
    if len(db_pool) == 0:
        db = hash_framework.database()
        db.close()
        db.init_psql()
        db_pool.append(db)
        db_pool.append(1)
        return db

    db_pool[1] += 1
    if db_pool[1] == 10000:
        db = hash_framework.database()
        db.close()
        db.init_psql()
        db_pool[0] = db
        db_pool[1] = 1

    return db_pool[0]
Example #10
0
def tc_delete_task():
    db = hf.database()
    db.close()
    db.init_psql()

    t = hf.manager.Task(db)
    t.load("test-md4-test").remove()

    return True
Example #11
0
 def __init__(self, config):
     self.jobs = {}
     self.fj = set()
     self.jq = set()
     self.wj = set()
     self.rids = {}
     self.config = config
     self.db_path = self.config.results_dir + "/worker_results.db"
     self.db = hf.database(path=self.db_path)
     self.thread_db = None
Example #12
0
def tc_create_task():
    db = hf.database()
    db.close()
    db.init_psql()

    t = hf.manager.Task(db)
    t.new("test-md4-test", "md4", 10, 10000)
    assert t.id != None

    return True
def __main__():
    if len(sys.argv) != 3:
        print("Usage: " + sys.argv[0] + " algorithm /path/to/results.db")
        return

    db = hash_framework.database()
    db.close()
    db.init_psql()

    algo = hash_framework.algorithms.lookup(sys.argv[1])()
    hash_framework.attacks.collision.clean_table(algo, db)
Example #14
0
def tc_load_task():
    db = hf.database()
    db.close()
    db.init_psql()

    t = hf.manager.Task(db)
    t.load("test-md4-test")
    assert t.name == "test-md4-test"
    assert t.algo == "md4"
    assert t.max_threads == 10
    assert t.priority == 10000

    return True
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert len(sys.argv) == 2
    tid = int(sys.argv[1])

    q = (
        "SELECT id, run_return, run_time, args FROM jobs WHERE task_id=" +
        str(tid) +
        " AND state=2 AND run_time > 75000 AND run_time < 3600000 ORDER BY run_time DESC;"
    )
    r, cur = db.execute(q, cursor=True)

    row = cur.fetchone()
    while row != None:
        jid, run_return, run_time, args = row
        obj = json.loads(args)
        algo = obj["algo"]
        rounds = "-".join(obj["rounds"])
        input_margin = obj["input_margin"]
        input_error = obj["input_error"]
        output_margin = obj["output_margin"]
        output_error = obj["output_error"]
        if obj["input_fill"] != "":
            print("WAT: " + str(jid))
        w = obj["w"]
        # {'algo': 'sha3', 'cms_args': [], 'w': 4, 'rounds': ['t', 'r', 'p', 'c'], 'input_fill': '', 'input_margin': 100, 'input_error': 93, 'intermediate_margins': [], 'output_margin': 32, 'output_error': 0}
        # print(obj)

        sat = "SAT"
        if run_return == 20:
            sat = "UNSAT"
        elif run_return != 10:
            sat = "ERROR"

        print("%d %s %d %d %d %d # %s %s %d" % (
            w,
            rounds,
            input_error,
            input_margin,
            output_error,
            output_margin,
            algo,
            sat,
            run_time,
        ))

        row = cur.fetchone()
Example #16
0
def __main__():
    print(len(cset))
    cs = hash_framework.manager.build_client_set(cset)

    kernel_name = "families"
    kernel = hash_framework.kernels.lookup(kernel_name)
    algo = hash_framework.algorithms.md4()
    db = hash_framework.database()

    c_jids = []
    for c in cs:
        c_jids.append(c.all_jobs())

    on_result = functools.partial(kernel.on_result, algo, db)
    hash_framework.manager.core.wait_results(cs, c_jids, on_result)
Example #17
0
def __main__():
    if len(sys.argv) != 2:
        print("Usage: " + sys.argv[0] + " algorithm")
        return

    db = hash_framework.database()
    algo = hash_framework.algorithms.lookup(sys.argv[1])()
    rowids = get_rowid_count(db, algo)
    print(rowids)
    while rowids > 0:
        rows = get_rows(db, algo)
        for row in rows:
            retag(db, algo, row)
        rowids = get_rowid_count(db, algo)
        print(rowids)
    db.commit()
Example #18
0
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert len(sys.argv) == 3
    tid = int(sys.argv[1])

    q = ("SELECT id, run_return, args FROM jobs WHERE task_id=" + str(tid) +
         " AND state=2;")
    r, cur = db.execute(q, cursor=True)

    results = {}
    for e_m in [128, 160, 224, 256, 384, 512]:
        results[e_m] = {}
        for w in [1, 2, 4]:
            arr = []
            for j in range(0, 25 * w):
                arr.append([0] * (25 * w))
            results[e_m][w] = arr

    row = cur.fetchone()
    while row != None:
        jid, run_result, args = row
        obj = json.loads(args)
        margin = obj["input_margin"]
        w = obj["w"]
        e_m = (25 * w - margin) * 32 // w
        input_error = obj["input_error"]
        output_error = obj["output_error"]
        if e_m in results and w in results[e_m]:
            results[e_m][w][input_error][output_error] = run_result
        else:
            print((e_m, w, input_error, output_error))

        row = cur.fetchone()

    for e_m in results:
        for w in results[e_m]:
            draw_table(
                results[e_m][w],
                25 * w,
                "/tmp/table-id-margin-" + sys.argv[2] + "-em" + str(e_m) +
                "-w" + str(w) + "-o0.png",
            )
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert len(sys.argv) == 3
    tid = int(sys.argv[1])

    q = ("SELECT id, run_return, args FROM jobs WHERE task_id=" + str(tid) +
         " AND state=2;")
    r, cur = db.execute(q, cursor=True)

    results = {}
    for i in [1, 2, 3, 4, 5, 6, 7, 8]:
        results[i] = {}
        for w in [1, 2, 4, 8, 16]:
            arr = []
            for j in range(0, 25 * w):
                arr.append([0] * (25 * w))
            results[i][w] = arr

    row = cur.fetchone()
    while row != None:
        jid, run_result, args = row
        obj = json.loads(args)
        w = obj["w"]
        input_error = obj["input_error"]
        input_margin = obj["input_margin"]
        output_margin = obj["output_margin"]
        if input_error in results and w in results[input_error]:
            results[input_error][w][input_margin][output_margin] = run_result
        else:
            print((w, input_error))

        row = cur.fetchone()

    for i in results:
        for w in results[i]:
            draw_table(
                results[i][w],
                25 * w,
                "/tmp/table-margins-" + sys.argv[2] + "-w" + str(w) + "-i" +
                str(i) + "-o0.png",
            )
def __main__():
    db = hf.database()
    db.close()
    db.init_psql()

    assert len(sys.argv) == 2
    tid = int(sys.argv[1])

    q = "SELECT args FROM jobs WHERE task_id=" + str(tid) + ";"
    r, cur = db.execute(q, cursor=True)

    row = cur.fetchone()
    while row != None:
        args = row[0]
        obj = json.loads(args)
        rounds = obj["rounds"]
        places = obj["places"]
        print("%d %s" % (rounds, "-".join(map(str, (places)))))

        row = cur.fetchone()
Example #21
0
    def do_update(self):
        self.thread_db = hf.database(path=self.db_path)
        failure_count = 0
        failure_threshold = 100
        while True:
            if failure_count > failure_threshold:
                blacklist = []
                for jid in self.jq.copy():
                    blacklist.append(jid)
                self.jq = set()

                for jid in blacklist:
                    self.wj.add(jid)

                failure_count = 0

            try:
                self.update()
            except Exception as e:
                print("do_update() - Thread Failure: " + str(e))
                failure_count += 1

            time.sleep(0.05)
Example #22
0
def handle_stats():
    return jsonify(stats)


@app.route("/update/", methods=['GET'])
def handle_update():
    print("Handling Update")
    db = acquire_db()
    results_write(db)
    release_db(db)
    return jsonify(hash_framework.manager.success)


if __name__ == "__main__":
    #from werkzeug.contrib.profiler import ProfilerMiddleware
    #app.debug = True
    #app.config['PROFILE'] = True
    #app.wsgi_app = ProfilerMiddleware(app.wsgi_app, restrictions=[30])

    if len(sys.argv) == 2 and sys.argv[1] == "db":
        db = hash_framework.database()
        db.close()
        db.init_psql()
        for algo_name in hash_framework.algorithms.all_algorithms:
            algo = hash_framework.algorithms.lookup(algo_name)
            hash_framework.attacks.collision.create_table(algo, db)
            hash_framework.attacks.preimage.create_table(algo, db)
        sys.exit(0)

    app.run(host='0.0.0.0', port='8000')
Example #23
0
import hash_framework as hf
import sys
import random

input_error = int(sys.argv[2])
out_error = 0
rounds = 1

w = int(sys.argv[1])
r = set()

algo = hf.algorithms.sha3(w=w, rounds=rounds)
db_path = hf.config.results_dir + "/worker_results.db"
db = hf.database(path=db_path)

sat = set()

for in_margin in range(input_error, 25 * w):
    min_v = 0
    max_v = 25 * w
    out_margin = (min_v + max_v) // 2

    searched = set()

    while min_v < max_v:
        m = hf.models()
        m.remote = False
        mn = ("sha3-margin-w" + str(w) + "-ie" + str(input_error) + "-im" +
              str(in_margin) + "-om" + str(out_margin))
        m.start(mn, False)
        hf.models.vars.write_header()