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

Implement rank syndrome decoding estimator #209

Merged
merged 46 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
7c4126e
feat: A new set of classes for RSDProblem
ricardovp85 Oct 9, 2024
8be269c
adds some validations and changes some names
ricardovp85 Oct 9, 2024
18bb788
adding more features
ricardovp85 Oct 10, 2024
8fbef18
More combinatorial algorithms
ricardovp85 Oct 16, 2024
34cebf5
More combinatorial algorithms
ricardovp85 Oct 16, 2024
94a9362
feat: some new algorithms added to RSDEstimator
ricardovp85 Oct 22, 2024
c41c9a9
feat: Adding more algorithms
ricardovp85 Oct 22, 2024
db39e8c
feat: some deletions
ricardovp85 Oct 25, 2024
d186128
refactor: some deletions
ricardovp85 Oct 25, 2024
75ab5ad
feat: adding memory complexity
ricardovp85 Oct 30, 2024
ac7d40f
Docs: Adding comments to the code
ricardovp85 Nov 4, 2024
eb21485
docs: adding some tests and comments
ricardovp85 Nov 4, 2024
4a21450
refactor: Delete some code
ricardovp85 Nov 4, 2024
1835ab7
refactor some code
ricardovp85 Nov 4, 2024
1f4b3df
docs: Added comments to algorithm classes
ricardovp85 Nov 4, 2024
7227b78
docs: Added comments to algorithm classes
ricardovp85 Nov 4, 2024
a74ef2b
docs: Added comments to algorithm classes
ricardovp85 Nov 4, 2024
0a549af
README changes
ricardovp85 Nov 6, 2024
6e1f674
docs: updated some docs
ricardovp85 Nov 6, 2024
05b85b1
fix: Fixing some errors
ricardovp85 Nov 7, 2024
402dc25
refactor: renaming of classes
ricardovp85 Nov 7, 2024
f0fff91
Merge branch 'develop' into feature/implement_RankSD_estimator
Javierverbel Nov 19, 2024
e2dd450
refactor: addressing comments by reviewers
ricardovp85 Nov 22, 2024
344c28f
Merge remote-tracking branch 'origin/feature/implement_RankSD_estimat…
ricardovp85 Nov 22, 2024
47096d9
docs: Documentation only changes
ricardovp85 Nov 22, 2024
fb5c848
Adds RankSD to the imput_dictionary.json
ricardovp85 Nov 26, 2024
373c774
fix: SM memory estimate
ricardovp85 Nov 29, 2024
ad85657
Refactor some code and add a new algorithm (HL)
ricardovp85 Dec 4, 2024
b78d6ee
Merge branch 'develop' into feature/implement_RankSD_estimator
Javierverbel Dec 5, 2024
995db23
docs: Identation of kwargs, format of references and comments
ricardovp85 Dec 5, 2024
97678e8
Fix: Adding missing validations and fixing some comments
ricardovp85 Dec 6, 2024
6215917
Merge branch 'develop' into feature/implement_RankSD_estimator
ricardovp85 Dec 6, 2024
0796576
Merge branch 'develop' into feature/implement_RankSD_estimator
Javierverbel Dec 6, 2024
b246427
Merge branch 'develop' into feature/implement_RankSD_estimator
Javierverbel Dec 6, 2024
3fd62ce
Fix: Validating some corner cases
ricardovp85 Dec 7, 2024
7ce5b5a
Merge branch 'develop' into feature/implement_RankSD_estimator
ricardovp85 Dec 7, 2024
246e6f3
Merge remote-tracking branch 'origin/feature/implement_RankSD_estimat…
ricardovp85 Dec 7, 2024
72b297d
adjusting a plus
ricardovp85 Dec 7, 2024
4200e82
Merge branch 'develop' into feature/implement_RankSD_estimator
Javierverbel Dec 7, 2024
7034d50
refactor: Minor Changes
ricardovp85 Dec 8, 2024
e6eca23
Merge branch 'develop' into feature/implement_RankSD_estimator
ricardovp85 Dec 8, 2024
11ce537
Merge remote-tracking branch 'origin/feature/implement_RankSD_estimat…
ricardovp85 Dec 8, 2024
5666907
docs: removing some unused imports and a doctest
ricardovp85 Dec 8, 2024
7d2609b
refactor: Arranging some imports
ricardovp85 Dec 9, 2024
eb06cf6
Merge branch 'develop' into feature/implement_RankSD_estimator
ricardovp85 Dec 9, 2024
b261c7a
Merge branch 'develop' into feature/implement_RankSD_estimator
Javierverbel Dec 9, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ well as some cryptographic schemes. Currently, the implemented estimators are:
- Linear Equivalence
- MinRank
- Regular Syndrome Decoding
- Rank Syndrome Decoding

- ### Scheme Estimators
- [BIKE](https://bikesuite.org)
- [MAYO](https://pqmayo.org)
Expand Down
3 changes: 1 addition & 2 deletions cryptographic_estimators/MAYOEstimator/mayo_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@


from ..base_problem import BaseProblem
from ..MQEstimator.mq_helper import ngates
from .mayo_constants import *
from ..helper import is_prime_power
from ..helper import is_prime_power, ngates
from math import log2, ceil


Expand Down
3 changes: 2 additions & 1 deletion cryptographic_estimators/MQEstimator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from .degree_of_regularity import generic_system, regular_system, semi_regular_system, quadratic_system
from .mq_algorithm import MQAlgorithm
from .mq_estimator import MQEstimator
from .mq_helper import ngates, nmonomials_of_degree, nmonomials_up_to_degree, sum_of_binomial_coefficients
from .mq_helper import nmonomials_of_degree, nmonomials_up_to_degree, sum_of_binomial_coefficients
from ..helper import ngates
from .mq_problem import MQProblem
from .witness_degree import semi_regular_system, quadratic_system
from .MQAlgorithms import Bjorklund, BooleanSolveFXL, CGMTA, Crossbred, DinurFirst, DinurSecond, ExhaustiveSearch, F5, HybridF5, KPG, Lokshtanov, MHT, Hashimoto
30 changes: 1 addition & 29 deletions cryptographic_estimators/MQEstimator/mq_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,35 +17,7 @@


from cryptographic_estimators.MQEstimator.series.nmonomial import NMonomialSeries
from math import log2, comb as binomial
from cryptographic_estimators.helper import is_prime_power


def ngates(q, n, theta=2):
"""Returns the number of gates for the given number of multiplications in a finite field.

Args:
q (int): The order of the finite field.
n (int): The number of multiplications (logarithmic).
theta (int): The exponent of the conversion factor (default: 2).

Examples:
>>> from cryptographic_estimators.MQEstimator.mq_helper import ngates
>>> ngates(16, 16)
20.0

Tests:
>>> ngates(6, 2**16)
Traceback (most recent call last):
...
ValueError: q must be a prime power
"""
if not is_prime_power(q):
raise ValueError("q must be a prime power")
if theta is None:
return n + log2(2 * log2(q) ** 2 + log2(q))
else:
return n + log2(log2(q)) * theta
from math import comb as binomial


def nmonomials_of_degree(d, n, q=None):
Expand Down
3 changes: 1 addition & 2 deletions cryptographic_estimators/MQEstimator/mq_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@


from cryptographic_estimators.base_problem import BaseProblem
from cryptographic_estimators.MQEstimator.mq_helper import ngates
from cryptographic_estimators.MQEstimator.mq_constants import (
MQ_NUMBER_VARIABLES,
MQ_NUMBER_POLYNOMIALS,
MQ_FIELD_SIZE,
)
from cryptographic_estimators.helper import is_prime_power
from cryptographic_estimators.helper import is_prime_power, ngates
from math import log2, ceil


Expand Down
3 changes: 1 addition & 2 deletions cryptographic_estimators/MREstimator/mr_problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@

from ..base_problem import BaseProblem
from .mr_constants import *
from ..MQEstimator.mq_helper import ngates
from cryptographic_estimators.helper import is_prime_power
from cryptographic_estimators.helper import is_prime_power, ngates
from math import log2, ceil


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from .basis_enumeration import BasisEnumeration
from .ourivski_johansson_1 import OJ1
from .ourivski_johansson_2 import OJ2
from .grs import GRS
from .improved_grs import ImprovedGRS
from .guessing_enhanced_grs import GuessingEnhancedGRS
from .hybrid_linearization import HybridLinearization
from .max_minors import MaxMinors
from .support_minors import SupportMinors
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# ****************************************************************************
# Copyright 2023 Technology Innovation Institute
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ****************************************************************************


from math import log2

from ..ranksd_algorithm import RankSDAlgorithm
from ..ranksd_problem import RankSDProblem


class BasisEnumeration(RankSDAlgorithm):
"""Construct an instance of Basis Enumeration estimator.

This algorithm tries to solve a given instance by enumerating
the possible supports for the vector x, and solving the linear system
given by the parity-check equations [CS96]_

Args:
problem (RankSDProblem): An instance of the RankSDProblem class.
**kwargs: Additional keyword arguments.
ricardovp85 marked this conversation as resolved.
Show resolved Hide resolved
w (int): Linear algebra constant (default: 3).
theta (int): Exponent of the conversion factor (default: 2).

Examples:
>>> from cryptographic_estimators.RankSDEstimator.RankSDAlgorithms.basis_enumeration import BasisEnumeration
>>> from cryptographic_estimators.RankSDEstimator.ranksd_problem import RankSDProblem
>>> BE = BasisEnumeration(RankSDProblem(q=2,m=127,n=118,k=48,r=7))
>>> BE
BasisEnumeration estimator for the Rank Syndrome Decoding problem with (q, m, n, k, r) = (2, 127, 118, 48, 7)
"""

def __init__(self, problem: RankSDProblem, **kwargs):
super(BasisEnumeration, self).__init__(problem, **kwargs)
self.on_base_field = True
self._name = "BasisEnumeration"

def _compute_time_complexity(self, parameters: dict):
"""Return the time complexity of the algorithm for a given set of parameters.

Args:
parameters (dict): Dictionary including the parameters.

Tests:
>>> from cryptographic_estimators.RankSDEstimator.RankSDAlgorithms.basis_enumeration import BasisEnumeration
>>> from cryptographic_estimators.RankSDEstimator.ranksd_problem import RankSDProblem
>>> BE = BasisEnumeration(RankSDProblem(q=2,m=127,n=118,k=48,r=7))
>>> BE.time_complexity()
749.6889972117298
"""
q, m, n, _, r = self.problem.get_parameters()
self.problem.set_operations_on_base_field(self.on_base_field)
time_complexity = self._w * log2(n * r + m) + (m - r) * (r - 1) * log2(q)
return time_complexity

def _compute_memory_complexity(self, parameters: dict):
"""Return the memory complexity of the algorithm for a given set of parameters.

Args:
parameters (dict): Dictionary including the parameters.

Tests:
>>> from cryptographic_estimators.RankSDEstimator.RankSDAlgorithms.basis_enumeration import BasisEnumeration
>>> from cryptographic_estimators.RankSDEstimator.ranksd_problem import RankSDProblem
>>> BE = BasisEnumeration(RankSDProblem(q=2,m=127,n=118,k=48,r=7))
>>> BE.memory_complexity()
23.014300107627076
"""
_, m, n, k, r = self.problem.get_parameters()
n_rows = (n - k) * m
n_columns = n * r + m
return self.__compute_memory_complexity_helper__(n_rows, n_columns, self.on_base_field)
104 changes: 104 additions & 0 deletions cryptographic_estimators/RankSDEstimator/RankSDAlgorithms/grs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# ****************************************************************************
# Copyright 2023 Technology Innovation Institute
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ****************************************************************************


from math import log2, ceil, inf

from ..ranksd_algorithm import RankSDAlgorithm
from ..ranksd_problem import RankSDProblem


class GRS(RankSDAlgorithm):
"""Construct an instance of GRS estimator.

This algorithm tries to solve a given instance by searching a linear subspace E'
of dimension r' ≥ r such that Suppx ⊆ E', and solving the linear system
given by the parity-check equations [GRS16]_

Args:
problem (RankSDProblem): An instance of the RankSDProblem class.
**kwargs: Additional keyword arguments.
w (int): Linear algebra constant (default: 3).
theta (int): Exponent of the conversion factor (default: 2).

Examples:
>>> from cryptographic_estimators.RankSDEstimator.RankSDAlgorithms.grs import GRS
>>> from cryptographic_estimators.RankSDEstimator.ranksd_problem import RankSDProblem
>>> GRSA = GRS(RankSDProblem(q=2,m=127,n=118,k=48,r=7))
>>> GRSA
GRS estimator for the Rank Syndrome Decoding problem with (q, m, n, k, r) = (2, 127, 118, 48, 7)
"""

def __init__(self, problem: RankSDProblem, **kwargs):
super(GRS, self).__init__(problem, **kwargs)
self.on_base_field = True
self._name = "GRS"

def _compute_time_complexity(self, parameters: dict):
"""Return the time complexity of the algorithm for a given set of parameters.

Args:
parameters (dict): Dictionary including the parameters.

Tests:
>>> from cryptographic_estimators.RankSDEstimator.RankSDAlgorithms.grs import GRS
>>> from cryptographic_estimators.RankSDEstimator.ranksd_problem import RankSDProblem
>>> GRSA = GRS(RankSDProblem(q=2,m=127,n=118,k=48,r=7))
>>> GRSA.time_complexity()
357.3539031111514
"""

q, m, n, k, r = self.problem.get_parameters()
self.problem.set_operations_on_base_field(self.on_base_field)

r1 = m - ceil(k * m / n)
t1 = self._w * log2((n - k) * m)
time_complexity_1 = inf
if r1 > 0:
mu1 = r * (m - r1)
time_complexity_1 = t1 + mu1 * log2(q)

r1 = m - ceil((k + 1) * m / n)
time_complexity_2 = inf
if r1 > 0:
mu2 = (r - 1) * (m - r1)
time_complexity_2 = t1 + mu2 * log2(q)

return min(time_complexity_1, time_complexity_2)

def _compute_memory_complexity(self, parameters: dict):
"""Return the memory complexity of the algorithm for a given set of parameters.

Args:
parameters (dict): Dictionary including the parameters.

Tests:
>>> from cryptographic_estimators.RankSDEstimator.RankSDAlgorithms.grs import GRS
>>> from cryptographic_estimators.RankSDEstimator.ranksd_problem import RankSDProblem
>>> GRSA = GRS(RankSDProblem(q=2,m=127,n=118,k=48,r=7))
>>> GRSA.memory_complexity()
26.229429443574855
"""

_, m, n, k, _ = self.problem.get_parameters()
r1 = m - ceil(k * m / n)
if r1 > 0:
n_columns = r1 * n
n_rows = (n - k) * m
return self.__compute_memory_complexity_helper__(n_rows, n_columns, self.on_base_field)
else:
return inf
Loading
Loading