Skip to content

Commit

Permalink
gh-35913: Debug component_function in S-box Module and Add the S-bo…
Browse files Browse the repository at this point in the history
…x of WARP Block Cipher

    
<!-- 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

<!-- Describe your changes here in detail. -->
<!-- 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. -->

1- Debugging `component_function` in sbox module:
 - The `from_bits(self, x, n=None)` function is invoked within the
`component_function` of the Sbox class. When the `input_size` and
`output_size` of the S-box differ, the `from_bits` function operates
correctly if the `n` argument is specified. However, the current
implementation of the `component_function` calls `from_bits` without
setting the `n` argument. Consequently, calling the `component_function`
of the Sbox class with differing `input_size` and `output_size` results
in an error.
- To resolve this issue, we only need to pass the argument `n` into the
`from_bits` functions inside the `component_function`.

2- Adding the s-box of WARP to s-box suite of SageMath

- I have added the S-box of the WARP block cipher to SageMath. WARP is a
block cipher that follows the Generalized Feistel Structure (GFS) and
was proposed as a lightweight alternative to AES-128 in SAC 2022. You
can find more information about WARP in
[[1]](https://link.springer.com/chapter/10.1007/978-3-030-81652-0_21).
- This addition is necessary to keep the S-box suite of SageMath up to
date and allows cryptographers to analyze the S-box of WARP using
SageMath.
- Fortunately, this update doesn't require any changes to the
documentation. I only needed to make a minor update in the comment
section, which I have already done.

[1] - https://link.springer.com/chapter/10.1007/978-3-030-81652-0_21

### 📝 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.
- [x] I have updated the documentation accordingly.

### ⌛ Dependencies

This change does not rely on any 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: #35913
Reported by: Hosein Hadipour
Reviewer(s): grhkm21
  • Loading branch information
Release Manager committed Jul 20, 2024
2 parents b6c1456 + f43f1f9 commit 114eb6a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/sage/crypto/sbox.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -1326,6 +1326,13 @@ cdef class SBox(SageObject):
sage: f5 = S.component_function([1, 0, 1])
sage: f5.algebraic_normal_form() # needs sage.rings.polynomial.pbori
x0*x2 + x0 + x1*x2
TESTS::
sage: from sage.crypto.sboxes import SBox
sage: sb = SBox([0, 1, 2, 3, 0, 1, 2, 3])
sage: sb.component_function([1, 0])
Boolean function with 3 variables
"""
cdef Py_ssize_t m = self.m
cdef Py_ssize_t n = self.n
Expand All @@ -1334,7 +1341,7 @@ cdef class SBox(SageObject):
b = list(b)
if len(b) > n:
raise ValueError("input (%s) is too long and would be truncated" % (b,))
b = self.from_bits(b)
b = self.from_bits(b, n)
except TypeError:
try:
b = ZZ(b)
Expand Down
3 changes: 2 additions & 1 deletion src/sage/crypto/sboxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
- SERPENT_S0, ..., SERPENT_S7 ([BAK1998]_)
- KLEIN ([GNL2011]_)
- MIBS ([ISSK2009)]
- Midori_Sb0 (MANTIS, CRAFT), Midori_Sb1 ([BBISHAR2015]_)
- Midori_Sb0 (MANTIS, CRAFT, WARP), Midori_Sb1 ([BBISHAR2015]_)
- Noekeon ([DPVAR2000]_)
- Piccolo ([SIHMAS2011]_)
- Panda ([YWHWXSW2014]_)
Expand Down Expand Up @@ -1574,6 +1574,7 @@ def monomial_function(n, e):
MIBS = SBox([4,15,3,8,13,10,12,0,11,5,7,14,2,6,1,9])
Midori_Sb0 = SBox([0xc,0xa,0xd,0x3,0xe,0xb,0xf,0x7,0x8,0x9,0x1,0x5,0x0,0x2,0x4,0x6])
MANTIS = Midori_Sb0
WARP = Midori_Sb0
CRAFT = Midori_Sb0
Midori_Sb1 = SBox([0x1,0x0,0x5,0x3,0xe,0x2,0xf,0x7,0xd,0xa,0x9,0xb,0xc,0x8,0x4,0x6])
Noekeon = SBox([0x7,0xA,0x2,0xC,0x4,0x8,0xF,0x0,0x5,0x9,0x1,0xE,0x3,0xD,0xB,0x6])
Expand Down

0 comments on commit 114eb6a

Please sign in to comment.