error handling cube attack, less round than model precomputed rounds

This commit is contained in:
2026-07-09 10:58:33 +02:00
parent 18e9eabc83
commit 27c4d2a6b0
+18 -8
View File
@@ -52,7 +52,10 @@ def build_target_poly(
if fixed_bits:
model = specialize_model(model, fixed_bits)
for _ in range((rounds - base_model.step_count) if base_model is not None else rounds):
start = model.step_count
if rounds < start:
raise ValueError(f"rounds={rounds} is smaller than current step_count={start}")
for _ in range(rounds - start):
model.step(skip_abstract=True)
return model.R_bits[target_reg][target_bit]
@@ -203,13 +206,20 @@ def run_cube_attack(
tmp_model = Tea3Model()
public_vars = pick_public_vars(tmp_model, fixed_bits=fixed_bits)
poly = build_target_poly(
rounds=rounds,
target_reg=target_reg,
target_bit=target_bit,
fixed_bits=fixed_bits,
base_model=model,
)
try:
poly = build_target_poly(
rounds=rounds,
target_reg=target_reg,
target_bit=target_bit,
fixed_bits=fixed_bits,
base_model=model,
)
except ValueError as e:
print("=" * 50)
print("Cube attack aborted.")
print(f"Error: {e}")
print("=" * 50)
return
print("=" * 50)
if model is not None: