Opened 7 years ago
Closed 7 years ago
#20336 closed enhancement (fixed)
Add more features to mq.SBox
Reported by:  Rusydi H. Makarim  Owned by:  

Priority:  major  Milestone:  sage7.2 
Component:  cryptography  Keywords:  SBox, cryptography 
Cc:  Martin Albrecht  Merged in:  
Authors:  Rusydi H. Makarim  Reviewers:  Travis Scrimshaw, Martin Albrecht 
Report Upstream:  N/A  Work issues:  
Branch:  05bc98b (Commits, GitHub, GitLab)  Commit:  05bc98b0e59ecf4a124881fc60a8b27179295bb0 
Dependencies:  Stopgaps: 
Description (last modified by )
Current implementation of mq.SBox is still lack of basic functionality to determine various cryptographic properties of an SBox such as nonlinearity, differential uniformity, etc. This commit implements some of them such as :
 Computation of nonlinearity and differential uniformity.
 Determine if the SBox is an almost bent (AB) / almost perfect nonlinear function (APN).
 Determine the balancedness of the SBox.
 Compute the maximum and minimum algebraic degree of its component function.
 Obtain the component function.
 Compute its the differential and linear branch number.
 Compute its autocorrelation matrix.
 Obtain linear structures in its component functions.
 Obtain all fixed points in the SBox.
 For an invertible SBox, obtain its inverse.
 Determine if the SBox is a monomial function.
Change History (14)
comment:1 Changed 7 years ago by
Branch:  → u/ruhm/improved_sbox 

comment:2 Changed 7 years ago by
Authors:  → Rusydi H. Makarim 

Commit:  → 1b081175e82e322d598e02448414654f2245ef14 
Component:  PLEASE CHANGE → cryptography 
Keywords:  SBox cryptography added 
Status:  new → needs_review 
Type:  PLEASE CHANGE → enhancement 
comment:3 Changed 7 years ago by
Description:  modified (diff) 

comment:4 followup: 7 Changed 7 years ago by
I can't comment to much on the code itself since it is outside of my expertise. However, I can make some comments on formatting:
 Instead of
$
for latex, you should use`
. (We do support the former, but it is not as wellsupported as the latter.)  Instead of
\mathbb{F}_2
, you should use the macro\GF{2}
for consistency with the rest of Sage.  Error statements are not sentences, and as such, should not start with a uppercase letter nor have a period. This is also to be consistent with Python.
 The input block should be formatted like this:
 ``b``  either an integer or a tuple of `\GF{2}` elements of length ``self.n``
 Remove the unnecessary parentheses here:
return (self.differential_uniformity() == 2)
.  It is better to use
\mathrm{wt}
or\operatorname{wt}
instead of\text{wt}
(this is a latex thing having to do with spacing rules).  You should use
.. MATH::
and have the equation indented on a separate line (with a blank line inbetween).  Try to keep lines less than 80 characters long
autocorrelation_matrix
should be a@cached_method
. Also make sure it returns an immutable matrix. All parentheses are extraneous here:
if ((m & 1) == 0):
. At least the outer ones are.  I prefer
EXAMPLES::
even when there is only one example; more maybe added later and this is for consistency.  In the doc, do
``TypeError``
.
Otherwise the doc and coding style looks good. I could try to review the code if no one else steps forward.
Also is this your first contribution to Sage?
comment:5 Changed 7 years ago by
Cc:  Martin Albrecht added 

comment:6 Changed 7 years ago by
Commit:  1b081175e82e322d598e02448414654f2245ef14 → 38b627e25ee6525ec6ffd83d55ecbeea574ea155 

Branch pushed to git repo; I updated commit sha1. New commits:
38b627e  various fixes based on the initial comment.

comment:7 Changed 7 years ago by
Hi,
Thanks, I have updated it according to the initial comment. And yes, this is my first contribution to SAGE.
 Rusydi
Replying to tscrim:
I can't comment to much on the code itself since it is outside of my expertise. However, I can make some comments on formatting:
 Instead of
$
for latex, you should use`
. (We do support the former, but it is not as wellsupported as the latter.) Instead of
\mathbb{F}_2
, you should use the macro\GF{2}
for consistency with the rest of Sage. Error statements are not sentences, and as such, should not start with a uppercase letter nor have a period. This is also to be consistent with Python.
 The input block should be formatted like this:
 ``b``  either an integer or a tuple of `\GF{2}` elements of length ``self.n`` Remove the unnecessary parentheses here:
return (self.differential_uniformity() == 2)
. It is better to use
\mathrm{wt}
or\operatorname{wt}
instead of\text{wt}
(this is a latex thing having to do with spacing rules). You should use
.. MATH::
and have the equation indented on a separate line (with a blank line inbetween). Try to keep lines less than 80 characters long
autocorrelation_matrix
should be a@cached_method
. Also make sure it returns an immutable matrix. All parentheses are extraneous here:
if ((m & 1) == 0):
. At least the outer ones are. I prefer
EXAMPLES::
even when there is only one example; more maybe added later and this is for consistency. In the doc, do
``TypeError``
.Otherwise the doc and coding style looks good. I could try to review the code if no one else steps forward.
Also is this your first contribution to Sage?
comment:8 Changed 7 years ago by
Reviewers:  → Travis Scrimshaw 

Welcome to Sage! This is a very welldone submission.
Now that you are using @cached_method
, you don't need the _autocorrelation_matrix
attribute and can remove this code:
try: return self._autocorrelation_matrix except AttributeError: pass
(similarly for the linearly_approximation_matrix
).
Martin, will/can you be doing a review of the math parts?
comment:9 Changed 7 years ago by
Hi all, I took a look at the ticket. It's very nice! The only thing I noticed is that you're adding new functions for differential_uniformity
. Wouldn't an alias be sufficient, e.g. differential_uniformity = maximal_difference_probability_absolute
?
comment:10 Changed 7 years ago by
PS: We should move mq.SBox to some other place. It has almost nothing to do with MQ any more, it's much more general now. But that's another ticket.
comment:11 Changed 7 years ago by
Commit:  38b627e25ee6525ec6ffd83d55ecbeea574ea155 → 05bc98b0e59ecf4a124881fc60a8b27179295bb0 

Branch pushed to git repo; I updated commit sha1. New commits:
05bc98b  cleanup linear approx matrix and autocorrelation matrix, aliasing differential_uniformity

comment:13 Changed 7 years ago by
Reviewers:  Travis Scrimshaw → Travis Scrimshaw, Martin Albrecht 

Status:  needs_review → positive_review 
Same here.
comment:14 Changed 7 years ago by
Branch:  u/ruhm/improved_sbox → 05bc98b0e59ecf4a124881fc60a8b27179295bb0 

Resolution:  → fixed 
Status:  positive_review → closed 
New commits:
Enhancement: Provide functionality to determine various cryptographic properties of SBox