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

perf(prob): improve performance of hybrid bdd #137

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions estimator/prob.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,23 @@ def mitm_babai_probability(r, stddev, fast=False):
:param fast: toggle for setting p = 1 (faster, but underestimates security)
:return: probability for the mitm process
"""
import numpy as np
from scipy.special import erf as erf_s

if fast:
# overestimate the probability -> underestimate security
return 1

# 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)
assert 0.0 <= p <= 1.0

# Take constant sqrt(pi) out of the array so we only compute once
sqrt_pi = np.sqrt(np.pi)
# Use numpy for fast computation of sqrt, erf, exp
xs = np.sqrt(0.5 * np.array(r)) / stddev
erf_xs = erf_s(xs)
p_vec = erf_xs - (1 - np.exp(-xs**2)) / (xs * sqrt_pi)
p = RR(np.prod(p_vec))

return p


Expand Down