Skip to content

Commit

Permalink
Merge pull request #97 from malb/bdd-speed-fix
Browse files Browse the repository at this point in the history
BDD / Hybrid-BDD speed improvement for FHE-sized parameters
  • Loading branch information
malb committed Feb 6, 2024
2 parents e3f49d0 + 30f840d commit 49d8e4f
Showing 1 changed file with 30 additions and 5 deletions.
35 changes: 30 additions & 5 deletions estimator/lwe_primal.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,10 +300,20 @@ def gaussian_heuristic_log_input(r):

d = len(r)
r = [log(x) for x in r]
for i, _ in enumerate(r):
if gaussian_heuristic_log_input(r[i:]) < D.stddev**2 * (d - i):
return ZZ(d - (i - 1))
return ZZ(2)

if d > 4096:
for i, _ in enumerate(r):
# chosen since RC.ADPS16(1754, 1754).log(2.) = 512.168000000000
j = d - 1754 + i
if gaussian_heuristic_log_input(r[j:]) < D.stddev**2 * (d - j):
return ZZ(d - (j - 1))
return ZZ(2)

else:
for i, _ in enumerate(r):
if gaussian_heuristic_log_input(r[i:]) < D.stddev**2 * (d - i):
return ZZ(d - (i - 1))
return ZZ(2)

@staticmethod
@cached_function
Expand Down Expand Up @@ -588,8 +598,23 @@ def __call__(
log_level=log_level + 1,
)

def find_zeta_max(params, red_cost_model):
usvp_cost = primal_usvp(params, red_cost_model=red_cost_model)["rop"]
zeta_max = 1
while zeta_max < params.n:
# TODO: once support_size() is supported for NTRU, remove the below try/except
try:
if params.Xs.support_size(zeta_max) > usvp_cost:
# double it for mitm
return 2 * zeta_max
zeta_max +=1
except NotImplementedError:
return params.n
return params.n

if zeta is None:
with local_minimum(0, params.n, log_level=log_level) as it:
zeta_max = find_zeta_max(params, red_cost_model)
with local_minimum(0, min(zeta_max, params.n), log_level=log_level) as it:
for zeta in it:
it.update(
f(
Expand Down

0 comments on commit 49d8e4f

Please sign in to comment.