Fork of the official github repository of the framework Leaky-LWE-Estimator, a Sage Toolkit to attack and estimate the hardness of LWE with Side Information. https://github.com/lducas/leaky-LWE-Estimator
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

compare_usvp_models.sage 2.4KB

  1. from multiprocessing import Pool
  2. from map_drop import map_drop
  3. from numpy.random import seed as np_seed
  4. load("../framework/instance_gen.sage")
  5. Derr = build_centered_binomial_law(6)
  6. modulus = 11
  7. try:
  8. N_tests = int(sys.argv[1])
  9. threads = int(sys.argv[2])
  10. except:
  11. N_tests = 5
  12. threads = 1
  13. def v(i):
  14. return canonical_vec(d, i)
  15. def randv():
  16. vv = v(randint(0, d - 1))
  17. vv -= v(randint(0, d - 1))
  18. vv += v(randint(0, d - 1))
  19. vv -= v(randint(0, d - 1))
  20. vv += v(randint(0, d - 1))
  21. return vv
  22. def one_experiment(id, aargs):
  23. N_hints, T_hints, simul, probabilistic = aargs
  24. mu, variance = average_variance(Derr)
  25. set_random_seed(id)
  26. np_seed(seed=id)
  27. A, b, dbdd = initialize_from_LWE_instance(DBDD_predict if simul else DBDD,
  28. n, q, m, D_e, D_s, verbosity=0)
  29. if simul:
  30. beta, _ = dbdd.estimate_attack(tours=1, probabilistic=probabilistic)
  31. return beta
  32. else:
  33. beta, _ = dbdd.attack(tours=1)
  34. return beta
  35. dic = {" ": None}
  36. def validation_prediction(N_tests, N_hints, T_hints):
  37. # Estimation
  38. import datetime
  39. ttt = datetime.datetime.now()
  40. pred_N_test = int(ceil(threads / 2))
  41. res = map_drop(pred_N_test, pred_N_test, one_experiment,
  42. (N_hints, T_hints, True, True))
  43. beta_pred_proba = RR(sum(res)) / (pred_N_test)
  44. res = map_drop(pred_N_test, pred_N_test, one_experiment,
  45. (N_hints, T_hints, True, False))
  46. beta_pred_intersect = RR(sum(res)) / (pred_N_test)
  47. res = map_drop(N_tests, threads, one_experiment,
  48. (N_hints, T_hints, False, None))
  49. beta_real = RR(sum(res)) / N_tests
  50. print("n:%3d Beta Real: %2.3f Beta predicted: %2.3f beta predicted(intersect): %2.3f "
  51. % (n, beta_real, beta_pred_proba, beta_pred_intersect), end=" \t")
  52. print("Walltime: ", datetime.datetime.now() - ttt, end=" \t")
  53. print("DIFF \t\t%.3f,\t%.3f,\t%.3f"
  54. % (beta_real, beta_pred_proba - beta_real,
  55. beta_pred_intersect - beta_real))
  56. return
  57. logging("Number of threads : %d" % threads, style="DATA")
  58. logging("Number of Samples : %d" % N_tests, style="DATA")
  59. logging(" Validation tests ", style="HEADER")
  60. for k in range(30, 100, 2):
  61. n = k
  62. m = n
  63. q = 3301
  64. D_s = build_centered_binomial_law(40)
  65. D_e = build_centered_binomial_law(40)
  66. d = m + n
  67. validation_prediction(N_tests, 0, "None") # Line 0