Skip to content

Commit 3b827a9

Browse files
committed
Add test suite and bump version to 0.0.1
1 parent 73b01c6 commit 3b827a9

5 files changed

Lines changed: 516 additions & 23 deletions

File tree

README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ After installation, you can use S-box Analyzer directly in Python:
9090
from sboxanalyzer import *
9191
from sage.crypto.sboxes import GIFT as sb
9292
sa = SboxAnalyzer(sb)
93-
cnf, milp = sa.minimized_diff_constraints()
93+
cnf, milp, cp = sa.minimized_diff_constraints()
9494

9595
# Output:
9696
# Simplifying the MILP/SAT constraints ...
@@ -194,7 +194,7 @@ sage: S = [
194194
....: (0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0),
195195
....: (0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1)
196196
....: ]
197-
sage: cnf, milp = SA.encode_set_of_binary_vectors(S, mode=6)
197+
sage: cnf, milp, cp = SA.encode_set_of_binary_vectors(S, mode=6)
198198
Generateing and simplifying the MILP/SAT constraints ...
199199
Time used to simplify the constraints: 0.12 seconds
200200
Number of constraints: 27
@@ -245,7 +245,7 @@ We can use S-box Analyzer to encode the truth table of $f$ to (minimized) CNF/MI
245245

246246
```python
247247
sage: from sboxanalyzer import SboxAnalyzer as SA
248-
sage: cnf, milp = SA.encode_boolean_function(BF, mode=6)
248+
sage: cnf, milp, cp = SA.encode_boolean_function(BF, mode=6)
249249
Generateing and simplifying the MILP/SAT constraints ...
250250
Time used to simplify the constraints: 0.00 seconds
251251
Number of constraints: 5
@@ -268,7 +268,7 @@ sage: pretty_print(cnf)
268268
sage: from sboxanalyzer import *
269269
sage: from sage.crypto.sboxes import SKINNY_4 as sb
270270
sage: sa = SboxAnalyzer(sb)
271-
sage: cnf, milp = sa.minimized_diff_constraints()
271+
sage: cnf, milp, cp = sa.minimized_diff_constraints()
272272

273273
Simplifying the MILP/SAT constraints ...
274274
Time used to simplify the constraints: 0.02 seconds
@@ -281,7 +281,7 @@ Weight: 3.0000 p0 + 2.0000 p1
281281
To make a trade-off between the time of simplification and the solution's optimality, S-Box Analyzer supports seven different modes, i.e., `[mode=1,...,mode=7]`. The default mode is 6, which is the best choice for both simplification time and optimality. For example, using the following command, we can minimize the number of constraints a little more:
282282

283283
```python
284-
sage: cnf, milp = sa.minimized_diff_constraints(mode=5)
284+
sage: cnf, milp, cp = sa.minimized_diff_constraints(mode=5)
285285

286286
Simplifying the MILP/SAT constraints ...
287287
Time used to simplify the constraints: 0.22 seconds
@@ -296,7 +296,7 @@ Weight: 3.0000 p0 + 2.0000 p1
296296
```python
297297
sage: from sage.crypto.sboxes import Ascon as sb
298298
sage: sa = SboxAnalyzer(sb)
299-
sage: cnf, milp = sa.minimized_diff_constraints()
299+
sage: cnf, milp, cp = sa.minimized_diff_constraints()
300300

301301
Simplifying the MILP/SAT constraints ...
302302
Time used to simplify the constraints: 0.04 seconds
@@ -311,7 +311,7 @@ Weight: 4.0000 p0 + 3.0000 p1 + 2.0000 p2
311311
```python
312312
sage: from sage.crypto.sboxes import PRESENT as sb
313313
sage: sa = SboxAnalyzer(sb)
314-
sage: cnf, milp = sa.minimized_diff_constraints()
314+
sage: cnf, milp, cp = sa.minimized_diff_constraints()
315315

316316
Simplifying the MILP/SAT constraints ...
317317
Time used to simplify the constraints: 0.03 seconds
@@ -333,7 +333,7 @@ sage: sa = SboxAnalyzer(sb)
333333
sage: sa.get_differential_spectrum()
334334
[2, 4, 6, 8, 12, 16, 20, 24, 28, 32, 40, 48, 64]
335335

336-
sage: cnf, milp = sa.minimized_diff_constraints(subtable=2, mode=2)
336+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable=2, mode=2)
337337

338338
Simplifying the MILP/SAT constraints ...
339339
Time used to simplify the constraints: 0.50 seconds
@@ -345,7 +345,7 @@ Output: b0||b1||b2||b3||b4||b5||b6||b7; b0: msb
345345
***Encode 4-DDT***
346346

347347
```python
348-
sage: cnf, milp = sa.minimized_diff_constraints(subtable=4)
348+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable=4)
349349

350350
Simplifying the MILP/SAT constraints ...
351351
Time used to simplify the constraints: 0.67 seconds
@@ -357,7 +357,7 @@ Output: b0||b1||b2||b3||b4||b5||b6||b7; b0: msb
357357
***Encode 6-DDT***
358358

359359
```python
360-
sage: cnf, milp = sa.minimized_diff_constraints(subtable=6)
360+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable=6)
361361

362362
Simplifying the MILP/SAT constraints ...
363363
Time used to simplify the constraints: 0.03 seconds
@@ -369,7 +369,7 @@ Output: b0||b1||b2||b3||b4||b5||b6||b7; b0: msb
369369
***Encode 8-DDT***
370370

371371
```python
372-
sage: cnf, milp = sa.minimized_diff_constraints(subtable=8)
372+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable=8)
373373
Simplifying the MILP/SAT constraints ...
374374
Time used to simplify the constraints: 0.75 seconds
375375
Number of constraints: 235
@@ -387,15 +387,15 @@ sage: sa = SboxAnalyzer(sb)
387387
sage: sa.get_differential_spectrum()
388388
[2, 4]
389389

390-
sage: cnf, milp = sa.minimized_diff_constraints(subtable=2)
390+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable=2)
391391

392392
Simplifying the MILP/SAT constraints ...
393393
Time used to simplify the constraints: 65.11 seconds
394394
Number of constraints: 7967
395395
Input: a0||a1||a2||a3||a4||a5||a6||a7; a0: msb
396396
Output: b0||b1||b2||b3||b4||b5||b6||b7; b0: msb
397397

398-
sage: cnf, milp = sa.minimized_diff_constraints(subtable=4)
398+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable=4)
399399
Simplifying the MILP/SAT constraints ...
400400
Time used to simplify the constraints: 869.08 seconds
401401
Number of constraints: 321
@@ -413,7 +413,7 @@ In impossible differential attack (or zero correlation linear attacks) we only e
413413
sage: from sboxanalyzer import *
414414
sage: from sage.crypto.sboxes import Midori_Sb0 as sb
415415
sage: sa = SboxAnalyzer(sb)
416-
sage: cnf, milp = sa.minimized_diff_constraints(subtable="star", mode=5)
416+
sage: cnf, milp, cp = sa.minimized_diff_constraints(subtable="star", mode=5)
417417

418418
Simplifying the MILP/SAT constraints ...
419419
Time used to simplify the constraints: 0.01 seconds
@@ -430,7 +430,7 @@ By setting the `cryptosmt_compatible` argument to `True`, you can generate an SM
430430
sage: from sboxanalyzer import *
431431
sage: from sage.crypto.sboxes import CRAFT as sb
432432
sage: sa = SboxAnalyzer(sb)
433-
sage: cnf, milp = sa.minimized_diff_constraints(cryptosmt_compatible=True)
433+
sage: cnf, milp, cp = sa.minimized_diff_constraints(cryptosmt_compatible=True)
434434

435435
Simplifying the MILP/SAT constraints ...
436436
Time used to simplify the constraints: 0.02 seconds
@@ -504,7 +504,7 @@ Here, we show how to encode the (squared) LAT of S-boxes.
504504
sage: from sboxanalyzer import *
505505
sage: from sage.crypto.sboxes import SKINNY_4 as sb
506506
sage: sa = SboxAnalyzer(sb)
507-
sage: cnf, milp = sa.minimized_linear_constraints()
507+
sage: cnf, milp, cp = sa.minimized_linear_constraints()
508508

509509
Simplifying the MILP/SAT constraints ...
510510
Time used to simplify the constraints: 0.01 seconds
@@ -521,7 +521,7 @@ Note that `sa.minimized_linear_constraints()` encode the squared LAT scaled by c
521521
```python
522522
sage: from sage.crypto.sboxes import Ascon as sb
523523
sage: sa = SboxAnalyzer(sb)
524-
sage: cnf, milp = sa.minimized_linear_constraints()
524+
sage: cnf, milp, cp = sa.minimized_linear_constraints()
525525

526526
Simplifying the MILP/SAT constraints ...
527527
Time used to simplify the constraints: 0.04 seconds
@@ -598,7 +598,7 @@ sage: mpt = sa.monomial_prediction_table(); mpt
598598
[0, 0, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0],
599599
[0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1],
600600
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]
601-
sage: cnf, milp = sa.minimized_integral_constraints()
601+
sage: cnf, milp, cp = sa.minimized_integral_constraints()
602602

603603
Simplifying the MILP/SAT constraints ...
604604
Time used to simplify the constraints: 0.00 seconds
@@ -613,7 +613,7 @@ Output: b0||b1||b2||b3; b0: msb
613613
sage: from sboxanalyzer import *
614614
sage: from sage.crypto.sboxes import Ascon as sb
615615
sage: sa = SboxAnalyzer(sb)
616-
sage: cnf, milp = sa.minimized_integral_constraints()
616+
sage: cnf, milp, cp = sa.minimized_integral_constraints()
617617

618618
Simplifying the MILP/SAT constraints ...
619619
Time used to simplify the constraints: 0.01 seconds
@@ -632,7 +632,7 @@ Here, we show how to encode the DLCT of S-boxes.
632632
sage: from sboxanalyzer import *
633633
sage: from sage.crypto.sboxes import KNOT as sb
634634
sage: sa = SboxAnalyzer(sb)
635-
sage: cnf, milp = sa.minimized_differential_linear_constraints(subtable='star')
635+
sage: cnf, milp, cp = sa.minimized_differential_linear_constraints(subtable='star')
636636

637637
Simplifying the MILP/SAT constraints ...
638638
Time used to simplify the constraints: 0.00 seconds
@@ -647,7 +647,7 @@ Output: b0||b1||b2||b3; b0: msb
647647
sage: from sboxanalyzer import *
648648
sage: from sage.crypto.sboxes import Midori_Sb0 as sb
649649
sage: sa = SboxAnalyzer(sb)
650-
sage: cnf, milp = sa.minimized_differential_linear_constraints(subtable='star')
650+
sage: cnf, milp, cp = sa.minimized_differential_linear_constraints(subtable='star')
651651

652652
Simplifying the MILP/SAT constraints ...
653653
Time used to simplify the constraints: 0.00 seconds

pyproject.toml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "sboxanalyzer"
7-
version = "0.0.0"
7+
version = "0.0.1"
88
description = "A tool for analyzing S-boxes and Boolean functions against differential, linear, differential-linear, boomerang, and integral attacks"
99
readme = "README.md"
1010
authors = [
@@ -73,3 +73,10 @@ sboxanalyzer = [
7373
"espresso_src/__pycache__",
7474
"espresso_build/*"
7575
]
76+
77+
[tool.pytest.ini_options]
78+
testpaths = ["tests"]
79+
python_files = ["test_*.py"]
80+
python_classes = ["Test*"]
81+
python_functions = ["test_*"]
82+
addopts = "-v"

sboxanalyzer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
# In case you use this tool please include the above copyright informations (name, contact, license)
7070
#*****************************************************************************
7171

72-
__version__ = "0.0.0"
72+
__version__ = "0.0.1"
7373

7474
import subprocess
7575
import os

tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Test package for sboxanalyzer

0 commit comments

Comments
 (0)