from estimator import * def SVP_Classical(dim): return 8*(dim)*(3/2)**(dim/2) def SVP_Quantum(dim): return 8*(dim)*ZZ(2)**RR(0.265*dim) # LWR def LWR_estiamtes(n, l, k, q, p, s, model=SVP_Classical): nLWE = n*l m = k*n # m = k*n s_bound = s secret_distribution = (-s_bound, s_bound) alpha = sqrt(2*pi)*1/RR(2*p) success_probability = 0.99 reduction_cost_model = lambda beta, d, B: model(beta) res_primal = primal_usvp(nLWE, alpha, q, secret_distribution=secret_distribution, m=m, success_probability=success_probability, reduction_cost_model=reduction_cost_model) res_dual = dual_scale(nLWE, alpha, q, secret_distribution=secret_distribution, m=m, success_probability=success_probability, reduction_cost_model=reduction_cost_model) return res_primal, res_dual # Testing SIS # This analysis is given in Dilithium, C3 # https://eprint.iacr.org/eprint-bin/getfile.pl?entry=2017/633&version=20180910:112250&file=633.pdf # go from beta to delta for BKZ def get_delta(beta): return RR(beta/(2*pi*e) * (pi*beta)**(1/beta))**(1/(2*(beta-1))) def getGSA(d, q, beta, nrows): delta = get_delta(beta) log_delta =log(delta,2) log_q = log(q) zone1 = nrows*[log_q] slope = -(1/(beta-1))*log(beta/(2*pi*e)*(pi*beta)^(1/beta)) zone2_length = int(floor(log(q)/-slope)) zone2 = [log_q + i * slope for i in range(1, zone2_length+1)] zone3 =(d-nrows)*[0] GSA = zone1+zone2+zone3 lattice_vol = nrows*log_q current_vol = sum(GSA[i] for i in range(d)) #correct the volume since now current_vol > lattice_vol ind = 0 while current_vol>lattice_vol: current_vol -= GSA[ind] current_vol += GSA[ind+d] ind += 1 GSA = GSA[ind:ind+d] i_index = max(0, nrows-ind) j_index = min(i_index + zone2_length, d) #error we make by overshooting the while loop err = lattice_vol - current_vol for i in range(i_index, j_index): GSA[i] += err / (j_index-i_index+1) return GSA, i_index, j_index def getGSA_noq(d, q, beta, nrows): delta = get_delta(beta) log_delta =log(delta,2) log_q = log(q) slope = -(1/(beta-1))*log(beta/(2*pi*e)*(pi*beta)^(1/beta)) lattice_vol = nrows*log_q current_vol = 0 GSA_tmp = 0 GSA = [] for i in range(d): GSA_tmp -= slope current_vol += GSA_tmp if lattice_vol=0, 'i_index>=0' assert j_index<=len(GSA), 'j_index<=N' assert i_index!=j_index, 'i_index!=j_index' Pr1 = (2.*B)/q log_Pr1 = ((i_index)*(log(Pr1, 2))) norm_BKZ = exp(GSA[i_index]) sigma = norm_BKZ / sqrt(j_index - i_index + 1) Pr2 = erf(B / (sigma * sqrt(2.))) log_Pr2 = (j_index-i_index+1)* log(Pr2, 2) logPr_total_ = (beta/2.0)*log(4./3., 2) + log_Pr1+log_Pr2 logPr_total = min(0,logPr_total_) log_runTimeSVP = log(model(beta),2).n() log_runTime = log_runTimeSVP - logPr_total return [i_index, j_index, round(log_Pr1+log_Pr2), log_runTimeSVP, round(log_runTime)] def SIS_esimates(n, l, k, q, B, model=SVP_Classical): d = n*(k + l + 1) m = n*k best_rt = 10000 beta_range = range(100, d, 10) for beta in beta_range: if (log(model(beta),2) > best_rt): break for w in [d]: lat_dim = w log_runtime = RunTime(beta, lat_dim, q, m, B, model=model) if(log_runtime[4]