Skip to content

Commit

Permalink
perf(prob): speed-up e-admissibility probability computation
Browse files Browse the repository at this point in the history
  • Loading branch information
bencrts committed Dec 18, 2024
1 parent f015f49 commit 6dcc5a0
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions estimator/prob.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def gaussian_cdf(mu, sigma, t):
return RR((1/2)*(1 + erf((t - mu)/(sqrt(2)*sigma))))


from math import sqrt, erf, exp, pi
from functools import reduce

def mitm_babai_probability(r, stddev, fast=False):
"""
Compute the "e-admissibility" probability associated to the mitm step, according to
Expand All @@ -88,17 +91,25 @@ def mitm_babai_probability(r, stddev, fast=False):
:return: probability for the mitm process
"""
if fast:
# overestimate the probability -> underestimate security
return 1
return 1

# compute once to not repeat
pi_const = 1 / sqrt(pi)

# Note: `r` contains *square norms*, so convert to non-square norms.
# Follow the proof of Lemma 4.2 [WAHC:SonChe19]_, because that one uses standard deviation.
xs = [sqrt(.5 * ri) / stddev for ri in r]
p = prod(RR(erf(x) - (1 - exp(-x**2)) / (x * sqrt(pi))) for x in xs)
# compute product term-by-term to use reduce
def p_i(ri):
x = sqrt(0.5 * ri) / stddev
return erf(x) - (1 - exp(-x**2) ) * pi_const / x

# Use reduce for efficient multiplication instead of `prod`
p = reduce(lambda a, b: a * p_i(b), r, 1.0)

# Ensure the result remains a valid probability
assert 0.0 <= p <= 1.0
return p



def babai(r, norm):
"""
Babai probability following [JMC:Wunderer19]_.
Expand Down

0 comments on commit 6dcc5a0

Please sign in to comment.