Skip to content

Commit e83e419

Browse files
author
Release Manager
committed
gh-35695: Fix incorrect linear branch number for non-invertible SBox <!-- Please provide a concise, informative and self-explanatory title. --> <!-- Don't put issue numbers in the title. Put it in the Description below. --> <!-- For example, instead of "Fixes #12345", use "Add a new method to multiply two integers" --> ### 📚 Description Fixes #29769 <!-- Why is this change required? What problem does it solve? --> <!-- If this PR resolves an open issue, please link to it here. For example "Fixes #12345". --> <!-- If your change requires a documentation PR, please link it appropriately. --> ### 📝 Checklist <!-- Put an `x` in all the boxes that apply. It should be `[x]` not `[x ]`. --> - [x] The title is concise, informative, and self-explanatory. - [x] The description explains in detail what this PR is about. - [x] I have linked a relevant issue or discussion. - [x] I have created tests covering the changes. - [ ] I have updated the documentation accordingly. ### ⌛ Dependencies <!-- List all open PRs that this PR logically depends on - #12345: short description why this is a dependency - #34567: ... --> <!-- If you're unsure about any of these, don't hesitate to ask. We're here to help! --> URL: #35695 Reported by: Rusydi H. Makarim Reviewer(s): Frédéric Chapoton
2 parents 9c42d97 + a2e6c6e commit e83e419

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/sage/crypto/sbox.pyx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,15 +1409,21 @@ cdef class SBox(SageObject):
14091409
sage: S = SBox([12,5,6,11,9,0,10,13,3,14,15,8,4,7,1,2])
14101410
sage: S.linear_branch_number()
14111411
2
1412+
1413+
TESTS::
1414+
1415+
sage: f = SBox([0, 2, 0, 6, 2, 2, 3, 7])
1416+
sage: f.linear_branch_number()
1417+
1
14121418
"""
14131419
cdef Py_ssize_t m = self.m
14141420
cdef Py_ssize_t n = self.n
14151421
cdef Matrix lat = <Matrix> self.linear_approximation_table()
14161422
cdef Py_ssize_t ret = (1 << m) + (1 << n)
14171423

14181424
cdef Py_ssize_t a, b, w
1419-
for a in range(1, 1 << m):
1420-
for b in range(1 << n):
1425+
for a in range(1 << m):
1426+
for b in range(1, 1 << n):
14211427
if lat.get_unsafe(a, b) != 0:
14221428
w = hamming_weight(a) + hamming_weight(b)
14231429
if w < ret:

0 commit comments

Comments
 (0)