forked from pq-crystals/security-estimates
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKyber_failure.py
36 lines (29 loc) · 1.51 KB
/
Kyber_failure.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import operator as op
from math import factorial as fac
from math import sqrt, log
import sys
from proba_util import *
def p2_cyclotomic_final_error_distribution(ps):
""" construct the final error distribution in our encryption scheme
:param ps: parameter set (ParameterSet)
"""
chis = build_centered_binomial_law(ps.ks) # LWE error law for the key
chie = build_centered_binomial_law(ps.ke_ct) # LWE error law for the ciphertext
chie_pk = build_centered_binomial_law(ps.ke)
Rk = build_mod_switching_error_law(ps.q, ps.rqk) # Rounding error public key
Rc = build_mod_switching_error_law(ps.q, ps.rqc) # rounding error first ciphertext
chiRs = law_convolution(chis, Rk) # LWE+Rounding error key
chiRe = law_convolution(chie, Rc) # LWE + rounding error ciphertext
B1 = law_product(chie_pk, chiRs) # (LWE+Rounding error) * LWE (as in a E*S product)
B2 = law_product(chis, chiRe)
C1 = iter_law_convolution(B1, ps.m * ps.n)
C2 = iter_law_convolution(B2, ps.m * ps.n)
C=law_convolution(C1, C2)
R2 = build_mod_switching_error_law(ps.q, ps.rq2) # Rounding2 (in the ciphertext mask part)
F = law_convolution(R2, chie) # LWE+Rounding2 error
D = law_convolution(C, F) # Final error
return D
def p2_cyclotomic_error_probability(ps):
F = p2_cyclotomic_final_error_distribution(ps)
proba = tail_probability(F, ps.q/4)
return F, ps.n*proba