def harakatruncated(config): """ Find best attack in our truncated model for Haraka. """ num_states = ((config["aesrounds"] + 1) * config["rounds"]) + 1 # Iterate over all possible starting states for the attack best_attack = 999999 best_round = -1 best_model = 0 for rnd in range(num_states - 1): if haraka.isAESround(rnd, config["aesrounds"]): config["attackerstart"] = rnd model = haraka.buildmodel(config) attack_costs = round(solvemodel(model).objVal) print("Subround {} - Best Attack: {}".format(rnd, attack_costs)) if attack_costs < best_attack: best_attack = attack_costs best_round = rnd best_model = model print("Found best attack in round {} with costs {}".format(best_round, best_attack)) haraka.printmodel(best_model, config) return
def findminactivesbox(config): """ Example which finds the minimum number of active S-boxes for AES like ciphers, with the parameters given in the config file. """ if config["name"] == "aeslike": model = aeslike.buildmodel(config) solved_model = solvemodel(model) aeslike.printmodel(solved_model, config) elif config["name"] == "haraka": model = haraka.buildmodel(config) solved_model = solvemodel(model) haraka.printmodel(solved_model, config) return
def activesboxharaka(): config = {"rounds": 1, "wordsize": 8, "branchnumber": 5, "statedimension": 4, "aesstates": 4, "aesrounds": 2, "collisiononly": False, "mixlayer": "mix", "securitymodel": "sbox"} print("Rounds", "S-boxes", sep="\t") for num_rounds in range(1, 8): print(num_rounds, end='') for aes_rounds in range(1, 6): config["rounds"] = num_rounds config["aesrounds"] = aes_rounds solved_model = solvemodel(haraka.buildmodel(config)) print(" ", round(solved_model.ObjVal), end="") print("")
def activesboxharaka(): config = { "rounds": 1, "wordsize": 8, "branchnumber": 5, "statedimension": 4, "aesstates": 4, "aesrounds": 2, "collisiononly": False, "mixlayer": "mix", "securitymodel": "sbox" } print("Rounds", "S-boxes", sep="\t") for num_rounds in range(1, 8): print(num_rounds, end='') for aes_rounds in range(1, 6): config["rounds"] = num_rounds config["aesrounds"] = aes_rounds solved_model = solvemodel(haraka.buildmodel(config)) print(" ", round(solved_model.ObjVal), end="") print("")