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
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

exploiting_design_ntru.sage 2.1KB

  1. #!/usr/bin/sage -python
  2. # -*- coding: latin-1 -*-
  3. load("../framework/instance_gen.sage")
  4. verbosity = 0
  5. report_every = None
  6. """ Example
  7. Uncomment the following to get the detailed computation
  8. """
  9. # verbosity = 2
  10. # report_every = 20
  11. for params in [ 'ntruhps2048509', 'ntruhps2048677', 'ntruhps4096821']:
  12. logging("Set of parameters: " + params)
  13. if params == 'ntruhps2048509':
  14. n = 509
  15. m = 509
  16. q = 2048
  17. elif params == 'ntruhps2048677':
  18. n = 677
  19. m = 677
  20. q = 2048
  21. elif params == 'ntruhps4096821':
  22. n = 821
  23. m = 821
  24. q = 4096
  25. hamming_weight = (q / 16 - 1)
  26. if q / 8 - 2 <= 2 * n / 3:
  27. hamming_weight = (q / 16 - 1)
  28. else:
  29. hamming_weight = floor(n / 3)
  30. D_s = {- 1: RR(hamming_weight / n),
  31. 0: 1 - RR(2 * hamming_weight / n),
  32. 1: RR(hamming_weight / n)}
  33. # D_e = {- 1: RR(hamming_weight / n),
  34. # 0: 1 - RR(2 * hamming_weight / n),
  35. # 1: RR(hamming_weight / n)}
  36. D_e = {-1: RR(1 / 3), 0: RR(1 / 3), 1: RR(1 / 3)}
  37. # Assessement of the attack without hints
  38. A, b, dbdd = initialize_NTRU_instance(DBDD_predict_diag,
  39. n, q, m, D_e, D_s,
  40. verbosity=verbosity)
  41. if report_every is not None:
  42. dbdd.integrate_q_vectors(q, indices=range(0, n + m), report_every=report_every)
  43. else:
  44. dbdd.integrate_q_vectors(q, indices=range(0, n + m))
  45. (beta, _) = dbdd.estimate_attack()
  46. logging("Attack without hints: %3.2f bikz" % beta, style="HEADER")
  47. # Assessement of the attack with hints
  48. A, b, dbdd = initialize_NTRU_instance(DBDD_predict,
  49. n, q, m, D_e, D_s,
  50. verbosity=verbosity)
  51. v = vec([0 if i < m else 1 for i in range(m + n)])
  52. dbdd.integrate_perfect_hint(v, 0)
  53. if report_every is not None:
  54. dbdd.integrate_q_vectors(q, indices=range(0, m), report_every=report_every)
  55. else:
  56. dbdd.integrate_q_vectors(q, indices=range(0, m))
  57. (beta, _) = dbdd.estimate_attack()
  58. logging("Attack without hints: %3.2f bikz" % beta, style="HEADER")