Skip to content

Commit

Permalink
Fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
ludopulles committed Sep 19, 2024
1 parent b5781ba commit cca27c0
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 22 deletions.
4 changes: 2 additions & 2 deletions estimator/lwe_dual.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def __call__(
>>> LWE.dual(params)
rop: ≈2^103.4, mem: ≈2^63.9, m: 904, β: 251, d: 1928, ↻: 1, tag: dual
>>> dual_hybrid(params)
rop: ≈2^92.1, mem: ≈2^78.2, m: 716, β: 170, d: 1464, ↻: 1989, ζ: 276, h1: 8, tag: dual_hybrid
rop: ≈2^91.6, mem: ≈2^77.2, m: 711, β: 168, d: 1456, ↻: ≈2^11.2, ζ: 279, h1: 8, tag: dual_hybrid
>>> dual_hybrid(params, mitm_optimization=True)
rop: ≈2^98.2, mem: ≈2^78.6, m: 728, k: 292, ↻: ≈2^18.7, β: 180, d: 1267, ζ: 485, h1: 17, tag: ...
Expand All @@ -399,7 +399,7 @@ def __call__(
rop: ≈2^160.7, mem: ≈2^156.8, m: 1473, k: 25, ↻: 1, β: 456, d: 2472, ζ: 25, tag: dual_mitm_hybrid
>>> dual_hybrid(schemes.NTRUHPS2048509Enc)
rop: ≈2^131.7, mem: ≈2^128.5, m: 436, β: 358, d: 906, ↻: 1, ζ: 38, tag: dual_hybrid
rop: ≈2^136.2, mem: ≈2^127.8, m: 434, β: 356, d: 902, ↻: 35, ζ: 40, h1: 19, tag: dual_hybrid
>>> LWE.dual(schemes.CHHS_4096_67)
rop: ≈2^206.9, mem: ≈2^137.5, m: ≈2^11.8, β: 616, d: 7779, ↻: 1, tag: dual
Expand Down
8 changes: 4 additions & 4 deletions estimator/lwe_guess.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"""

from sage.all import binomial, ceil, e, exp, floor, log, oo, pi, round, RR, sqrt, ZZ
from sage.all import binomial, ceil, e, exp, floor, log, oo, pi, QQ, round, RR, sqrt, ZZ

from .conf import mitm_opt
from .cost import Cost
Expand Down Expand Up @@ -133,7 +133,7 @@ def __call__(self, params, log_level=5, **kwds):
Compare::
>>> LWE.primal_hybrid(schemes.Kyber512.updated(Xs=ND.SparseTernary(512, 16)))
rop: ≈2^85.8, red: ≈2^84.8, svp: ≈2^84.8, β: 105, η: 2, ζ: 366, |S|: ≈2^85.1, d: 315, prob: ≈2^-23.4, ...
rop: ≈2^136.4, red: ≈2^136.3, svp: ≈2^131.1, β: 251, η: 2, ζ: 203, |S|: ≈2^152.6, d: 673, ...
"""
params = LWEParameters.normalize(params)
Expand Down Expand Up @@ -241,7 +241,7 @@ def mitm_analytical(self, params: LWEParameters, success_probability=0.99):

if params.Xs.is_sparse:
h = params.Xs.hamming_weight
split_h = round(h * k / n)
split_h = QQ(h * k / n).round('down')
success_probability_ = (
binomial(k, split_h) * binomial(n - k, h - split_h) / binomial(n, h)
)
Expand Down Expand Up @@ -283,7 +283,7 @@ def cost(

# we assume the hamming weight to be distributed evenly across the two parts
# if not we can rerandomize on the coordinates and try again -> repeat
split_h = round(h * k / n)
split_h = QQ(h * k / n).round('down')
size_tab = RR((sd_rng - 1) ** split_h * binomial(k, split_h))
size_sea = RR((sd_rng - 1) ** (h - split_h) * binomial(n - k, h - split_h))
success_probability_ = (
Expand Down
6 changes: 3 additions & 3 deletions estimator/lwe_primal.py
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,13 @@ def __call__(
rop: ≈2^97.3, red: ≈2^96.3, svp: ≈2^96.3, β: 170, η: 142, ζ: 203, |S|: ≈2^16.3, d: 574, ...
>>> LWE.primal_hybrid(schemes.Kyber512.updated(Xs=ND.SparseTernary(512, 16)), mitm = False, babai = True)
rop: ≈2^88.7, red: ≈2^88.0, svp: ≈2^87.2, β: 98, η: 2, ζ: 323, |S|: ≈2^39.7, d: 346, ...
rop: ≈2^102.4, red: ≈2^102.2, svp: ≈2^99.8, β: 216, η: 2, ζ: 203, |S|: ≈2^69.7, d: 632, prob: 0.002, ...
>>> LWE.primal_hybrid(schemes.Kyber512.updated(Xs=ND.SparseTernary(512, 16)), mitm = True, babai = False)
rop: ≈2^74.1, red: ≈2^73.7, svp: ≈2^71.9, β: 104, η: 16, ζ: 320, |S|: ≈2^77.1, d: 359, ...
rop: ≈2^90.6, red: ≈2^89.7, svp: ≈2^89.6, β: 173, η: 138, ζ: 203, |S|: ≈2^36.4, d: 578, prob: 0.002, ...
>>> LWE.primal_hybrid(schemes.Kyber512.updated(Xs=ND.SparseTernary(512, 16)), mitm = True, babai = True)
rop: ≈2^85.8, red: ≈2^84.8, svp: ≈2^84.8, β: 105, η: 2, ζ: 366, |S|: ≈2^85.1, d: 315, ...
rop: ≈2^136.4, red: ≈2^136.3, svp: ≈2^131.1, β: 251, η: 2, ζ: 203, |S|: ≈2^152.6, d: 673, ...
TESTS:
Expand Down
12 changes: 6 additions & 6 deletions estimator/nd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from copy import copy
from dataclasses import dataclass

from sage.all import binomial, ceil, exp, log, oo, parent, pi, RealField, RR, sqrt
from sage.all import binomial, ceil, exp, log, oo, parent, pi, QQ, RealField, RR, sqrt


def stddevf(sigma):
Expand Down Expand Up @@ -253,7 +253,7 @@ def support_size(self, fraction=1.0):
)

b = 2 * t * sigmaf(self.stddev) + 1
return (2 * b + 1)**n
return RR(2.0 * b + 1)**n


def DiscreteGaussianAlpha(alpha, q, mean=0, n=None):
Expand Down Expand Up @@ -338,10 +338,10 @@ def __hash__(self):
EXAMPLE::
>>> from estimator import *
>>> hash(ND.Uniform(-10, 10)) == hash(("Uniform", 10, 10, None))
>>> hash(ND.Uniform(-10, 10)) == hash(("Uniform", (-10, 10), None))
True
"""
return hash(("Uniform", self.a, self.b, self.n))
return hash(("Uniform", self.bounds, self.n))

def support_size(self, fraction=1.0):
"""
Expand Down Expand Up @@ -435,9 +435,9 @@ def split_balanced(self, new_n, new_hw=None):
n, hw = len(self), self.hamming_weight
if new_hw is None:
# Most likely split has same density: new_hw / new_n = hw / n.
new_hw = int(round(hw * new_n / n))
new_hw = int(QQ(hw * new_n / n).round('down'))

new_p = int(round((new_hw * self.p) / hw))
new_p = int((QQ(new_hw * self.p) / hw).round('down'))
new_m = new_hw - new_p
return (
SparseTernary(new_n, new_p, new_m),
Expand Down
6 changes: 3 additions & 3 deletions estimator/ntru_primal.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,15 +369,15 @@ def __call__(
>>> NTRU.primal_hybrid(schemes.NTRUHPS2048509Enc.updated(Xs=ND.SparseTernary(508,16)),
... mitm = False, babai = True)
rop: ≈2^88.0, red: ≈2^87.4, svp: ≈2^86.4, β: 98, η: 2, ζ: 318, |S|: ≈2^39.6, d: 328, prob: ≈2^-27.9, ...
rop: ≈2^101.6, red: ≈2^101.5, svp: ≈2^96.5, β: 205, η: 2, ζ: 197, |S|: ≈2^64.1, d: 596, prob: ≈2^-11.7, ...
>>> NTRU.primal_hybrid(schemes.NTRUHPS2048509Enc.updated(Xs=ND.SparseTernary(508,16)),
... mitm = True, babai = False)
rop: ≈2^80.1, red: ≈2^79.7, svp: ≈2^78.3, β: 170, η: 22, ζ: 254, |S|: ≈2^103.7, d: 495, prob: 0.708, ...
rop: ≈2^89.6, red: ≈2^88.9, svp: ≈2^88.2, β: 172, η: 135, ζ: 197, |S|: ≈2^36.1, d: 555, prob: 0.003, ...
>>> NTRU.primal_hybrid(schemes.NTRUHPS2048509Enc.updated(Xs=ND.SparseTernary(508,16)),
... mitm = True, babai = True)
rop: ≈2^85.1, red: ≈2^84.1, svp: ≈2^84.0, β: 105, η: 2, ζ: 363, |S|: ≈2^85.0, d: 294, prob: ≈2^-22.9, ...
rop: ≈2^134.5, red: ≈2^134.4, svp: ≈2^129.2, β: 248, η: 2, ζ: 197, |S|: ≈2^151.2, d: 645, ...
TESTS:
Expand Down
4 changes: 2 additions & 2 deletions estimator/reduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,8 +515,8 @@ def __call__(self, beta, d, B=None):
>>> from sage.all import var, find_fit
>>> dim = [100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250]
>>> nodes = [39.0, 44.0, 49.0, 54.0, 60.0, 66.0, 72.0, 78.0, 84.0, 96.0, \
99.0, 105.0, 111.0, 120.0, 127.0, 134.0]
>>> nodes = [39.0, 44.0, 49.0, 54.0, 60.0, 66.0, 72.0, 78.0, 84.0, 96.0 ]
>>> nodes += [ 99.0, 105.0, 111.0, 120.0, 127.0, 134.0] # couldn't use \\ breaks stuff
>>> times = [c + log(200,2).n() for c in nodes]
>>> T = list(zip(dim, nodes))
>>> var("a,b,c,beta")
Expand Down
5 changes: 3 additions & 2 deletions estimator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,8 +443,9 @@ def batch_estimate(params, algorithm, jobs=1, log_level=0, catch_exceptions=True
>>> from estimator import LWE
>>> from estimator.schemes import Kyber512
>>> _ = batch_estimate(Kyber512, [LWE.primal_usvp, LWE.primal_bdd])
>>> _ = batch_estimate(Kyber512, [LWE.primal_usvp, LWE.primal_bdd], jobs=2)
>>> from estimator.util import batch_estimate
>>> _ = batch_estimate(Kyber512, [LWE.primal_usvp, LWE.primal_bdd], log_level=1)
>>> _ = batch_estimate(Kyber512, [LWE.primal_usvp, LWE.primal_bdd], jobs=2, log_level=1)
"""

Expand Down

0 comments on commit cca27c0

Please sign in to comment.