Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Debug component_function in S-box Module and Add the S-box of WARP Block Cipher #35913

Merged
merged 24 commits into from
Jul 24, 2024

Conversation

hadipourh
Copy link
Contributor

📚 Description

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].
  • 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

  • The title is concise, informative, and self-explanatory.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation accordingly.

⌛ Dependencies

This change does not rely on any dependencies.

@@ -1334,7 +1334,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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for this?

@grhkm21
Copy link
Contributor

grhkm21 commented Feb 15, 2024

One small change, then it should be fine.

@grhkm21
Copy link
Contributor

grhkm21 commented Feb 15, 2024

@hadipourh Have you read what I wrote?

Copy link
Contributor

@grhkm21 grhkm21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@hadipourh hadipourh requested a review from grhkm21 April 6, 2024 15:23
Copy link

github-actions bot commented Apr 9, 2024

Documentation preview for this PR (built with commit f43f1f9; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@hadipourh
Copy link
Contributor Author

hadipourh commented Apr 16, 2024

I think this pull request is ready to merge.
@mkoeppe and @grhkm21 do you agree?

@grhkm21
Copy link
Contributor

grhkm21 commented May 28, 2024

Sorry for the late reply. Your added TESTS session doesn't test for the issue fixed by this PR. As you said, this PR addresses when the SBox's input_size and output_size differs, yet the example you gave have the same:

sage: from sage.crypto.sboxes import SBox
sage: sb = SBox(7, 6, 0, 4, 2, 5, 1, 3)
sage: sb.component_function([1, 0, 0])
Boolean function with 3 variables
sage: sb.input_size()
3
sage: sb.output_size()
3

(And hence this actually runs for the latest Sage version already.) Please replace it with an example that has differing input and output size

@hadipourh
Copy link
Contributor Author

hadipourh commented May 28, 2024

Thank you @grhkm21 for your review!
I replaced the TEST block with an appropriate one:

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 variabl

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 variabl
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix this :)

@grhkm21
Copy link
Contributor

grhkm21 commented Jun 17, 2024

After fixing the test output this should be ready :)

@hadipourh
Copy link
Contributor Author

The test output was fixed.

Copy link
Contributor

@grhkm21 grhkm21 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me! Thanks :)

@hadipourh
Copy link
Contributor Author

Thank you too for your review!
By the way, I have designed an extension for the Sbox module: https://github.com/hadipourh/sboxanalyzer

As seen in the road map, I would like to integrate this tool into the SageMath.
However, the tool heavily relies on a logic minimizer program written in C: https://ptolemy.berkeley.edu/projects/embedded/pubs/downloads/espresso/index.htm
Do you have any advice for integrating this tool into the SageMath? Or would you like to contribute to this project from this aspect?

@grhkm21
Copy link
Contributor

grhkm21 commented Jun 17, 2024

I took a look at your sboxanalyzer project, it looks interesting and would be great to have in Sage. Is the entire espresso folder also part of the project? I don't know what the process of including external C code is, so maybe I will ping @tscrim in. But I have seen C code in Sage (hyperelliptic Frobenius point counting and discrete gaussian sampling are two examples), so it should be possible. I can help if needed

@hadipourh
Copy link
Contributor Author

I took a look at your sboxanalyzer project, it looks interesting and would be great to have in Sage. Is the entire espresso folder also part of the project? I don't know what the process of including external C code is, so maybe I will ping @tscrim in. But I have seen C code in Sage (hyperelliptic Frobenius point counting and discrete gaussian sampling are two examples), so it should be possible. I can help if needed

The entire Espresso package is, of course, not needed, but I believe Espresso, once integrated into the SageMath project, will be incredibly useful for people working on Boolean functions and binary fields. To the best of my knowledge, Espresso is one of the most efficient (in terms of speed) open-source logic minimizers available. Hence, it makes sense to integrate the entire Espresso package together with SboxAnalyzer into SageMath. This way, Espresso can be reused for many other applications in the context of Boolean functions and binary fields. If you, @tscrim, or anyone else is interested and can help, you are very welcome to contribute to this project by integrating it into SageMath.

@grhkm21
Copy link
Contributor

grhkm21 commented Jun 25, 2024

Please do not rebase PRs after they are positively reviewed... It retriggers CI and requires a re-review (automated by bot, as you can see) etc.

@tscrim
Copy link
Collaborator

tscrim commented Jun 25, 2024

@grhkm21 So including C code in Sage is basically the same as any other bit of code (we do have some in Sage already as I recall) except with a bit of Cython bindings. It might be best to keep Espresso as a separate (upstream?) optional package with specific hooks/classes within Sage to use that.

@vbraun vbraun merged commit 114eb6a into sagemath:develop Jul 24, 2024
18 of 20 checks passed
@mkoeppe mkoeppe added this to the sage-10.5 milestone Jul 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants