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

Feat/integerfactoring #222

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .gnfs import GNFS
92 changes: 92 additions & 0 deletions cryptographic_estimators/IFEstimator/IFAlgorithms/gnfs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# ****************************************************************************
# 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 ..if_algorithm import IFAlgorithm
from ..if_problem import IFProblem
from ..if_constants import *
from ..if_helper import *
from math import exp, log


class GNFS(IFAlgorithm):
"""
Construct an instance of IFAlgorithm1 estimator
The estimates as per Sec. 5.5.4
https://eprint.iacr.org/2017/1087.pdf

INPUT:

- ``problem`` -- an instance of the IFProblem class
"""

def __init__(self, problem: IFProblem, **kwargs):
self._name = "GNFS"
super(GNFS, self).__init__(problem, **kwargs)

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

The correcting factor is per https://people.rennes.inria.fr/Aurore.Guillevic/talks/2024-07-Douala/24-07-Douala-RSA.pdf

INPUT:

- ``parameters`` -- dictionary including the parameters

"""
n = self.problem.parameters["n"]
n = n/lge # n is given log2-based, convert to ln-base

k = (64 / 9) ** (1 / 3)

T = k*(n**(1 / 3))*((log(n))**(1 - 1/3))*lge
#T = Lfunction(1/3, k, log(n)) * lge

if correctingfactor:
T = T - correcting_factor

return T

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

INPUT:

- ``parameters`` -- dictionary including the parameters

"""
n = self.problem.parameters["n"]
n = n/lge

k = 2/(3 ** (2/3))

#b1 = b2
b1 = exp(k * (log(n) ** (1 / 3)) * (log(log(n)) ** (1-1/3)))

#B'_1 / B'_2 ( B'_1 * log(B_1) + B'_2)

b1_prime = pifunction(b1) + 1
b2_prime = pifunction(b1) + log(n)

T = (b1_prime / b2_prime) * (b1_prime * log(b1) + b2_prime) * lge

if correcting_factor:
T = T - correcting_factor

return T
4 changes: 4 additions & 0 deletions cryptographic_estimators/IFEstimator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from .if_algorithm import IFAlgorithm
from .if_estimator import IFEstimator
from .if_problem import IFProblem
from .IFAlgorithms import *
34 changes: 34 additions & 0 deletions cryptographic_estimators/IFEstimator/if_algorithm.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# ****************************************************************************
# 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 ..base_algorithm import BaseAlgorithm
from .if_problem import IFProblem


class IFAlgorithm(BaseAlgorithm):
def __init__(self, problem: IFProblem, **kwargs):
"""
Base class for IF algorithms complexity estimator

INPUT:

- ``problem`` -- IFProblem object including all necessary parameters

"""
super(IFAlgorithm, self).__init__(problem, **kwargs)
self._name = "sample_name"
19 changes: 19 additions & 0 deletions cryptographic_estimators/IFEstimator/if_constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ****************************************************************************
# 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/>.
# ****************************************************************************

correcting_factor = 11.91 # as per https://people.rennes.inria.fr/Aurore.Guillevic/talks/2024-07-Douala/24-07-Douala-RSA.pdf
lge = 1.44269504088896
59 changes: 59 additions & 0 deletions cryptographic_estimators/IFEstimator/if_estimator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ****************************************************************************
# 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 .if_algorithm import IFAlgorithm
from .if_problem import IFProblem
from ..base_estimator import BaseEstimator
from math import inf


class IFEstimator(BaseEstimator):
"""
Construct an instance of IFEstimator

INPUT:

- ``excluded_algorithm`` -- A list/tuple of excluded algorithms (default: None)

"""
excluded_algorithms_by_default = []

def __init__(self, n:int, memory_bound=inf, **kwargs): # Fill with parameters
super(IFEstimator, self).__init__(
IFAlgorithm,
IFProblem(n, memory_bound=memory_bound, **kwargs),
**kwargs
)

def table(self, show_quantum_complexity=0, show_tilde_o_time=0,
show_all_parameters=0, precision=1, truncate=0):
"""
Print table describing the complexity of each algorithm and its optimal parameters

INPUT:

- ``show_quantum_complexity`` -- show quantum time complexity (default: False)
- ``show_tilde_o_time`` -- show Ō time complexity (default: False)
- ``show_all_parameters`` -- show all optimization parameters (default: False)
- ``precision`` -- number of decimal digits output (default: 1)
- ``truncate`` -- truncate rather than round the output (default: False)
"""
super(IFEstimator, self).table(show_quantum_complexity=show_quantum_complexity,
show_tilde_o_time=show_tilde_o_time,
show_all_parameters=show_all_parameters,
precision=precision, truncate=truncate)
31 changes: 31 additions & 0 deletions cryptographic_estimators/IFEstimator/if_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# ****************************************************************************
# 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 log

def Lfunction(alpha, beta, logN):
"""
implements the exponent of the L-function
L[alpha, beta] = exp((beta+o(1))*logN**alpha * log(logN)**(1-alpha) )
"""
assert alpha >= 0
assert beta >= 0
assert alpha <= 1
assert beta <= 1
return beta*(logN**alpha)*(log(logN))**(1-alpha)

def pifunction(x):
return x/log(x)
72 changes: 72 additions & 0 deletions cryptographic_estimators/IFEstimator/if_problem.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# ****************************************************************************
# 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 ..base_problem import BaseProblem


class IFProblem(BaseProblem):
"""
Construct an instance of IFProblem. Contains the parameters to optimize
over.

INPUT:
- Fill with parameters

"""

def __init__(self, n:int , **kwargs): # Fill with parameters
super().__init__(**kwargs)
self.parameters["n"] = n

def to_bitcomplexity_time(self, basic_operations: float):
"""
Return the bit-complexity corresponding to a certain amount of basic_operations

INPUT:

- ``basic_operations`` -- Number of basic operations (logarithmic)

"""
return basic_operations

def to_bitcomplexity_memory(self, elements_to_store: float):
"""
Return the memory bit-complexity associated to a given number of elements to store

INPUT:

- ``elements_to_store`` -- number of memory operations (logarithmic)

"""
return elements_to_store

def expected_number_solutions(self):
"""
Return the logarithm of the expected number of existing solutions to the problem

"""
pass

def get_parameters(self):
"""
Return the optimizations parameters
"""
return list(self.parameters.values())

def __repr__(self):
return "IFProblem"
3 changes: 3 additions & 0 deletions tests/test_if.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from cryptographic_estimators.IFEstimator import *
A = IFEstimator(n=795)
A.table()
Loading