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.

66 líneas
1.6 KiB

  1. # P434
  2. e2 = 0xD8
  3. e3 = 0x89
  4. # P503
  5. # e2=0xFA
  6. # e3=0x9F
  7. #e2=0x174
  8. #e3=0xEF
  9. Nsk2_max_val = (2^e2) - 1
  10. Nsk2_bytes = floor(e2/8)
  11. Nsk3_S = ceil(RDF(log(3^e3,2)))
  12. Nsk3_bytes = floor(Nsk3_S/8)
  13. Nsk3_max_val = (2^Nsk3_S) - 1
  14. p = 2^e2 * 3^e3 - 1
  15. Fp = GF(p)
  16. R.<x> = Fp[]
  17. Fp2 = Fp.extension(x^2 + 1, 'i')
  18. i = Fp2.gen()
  19. E0Fp = EllipticCurve(Fp, [0,6,0,1,0])
  20. E0Fp2 = EllipticCurve(Fp2, [0,6,0,1,0])
  21. # Montgomery R
  22. # 448 = 7*(8*8)
  23. R = 2^448
  24. # P503
  25. # R = 2^512
  26. def calc_Y_in_Fp2(x, xi):
  27. fp2X= Fp2(x+xi*i)
  28. fp2Y2 = Fp2(fp2X^3 + fp2X)
  29. ret = fp2Y2.sqrt()
  30. return ret
  31. def calc_proj_point_A(fp2X, fp2Y): return (3^e3 * E0Fp2((fp2X, fp2Y)))
  32. def calc_proj_point_B(fp2X, fp2Y): return (2^e2 * E0Fp2(fp2X, fp2Y))
  33. def tau(P): return E0Fp2(-P.xy()[0], i*P.xy()[1])
  34. def hd(val):
  35. return ", 0x".join([x.hex().upper() for x in Integer(val).digits(base=2^64)])
  36. def hcp(point):
  37. print("X: "); hd(point[0])
  38. print("Y: "); hd(point[1])
  39. print("Z: "); hd(point[2])
  40. def print_fp2_hex(Fp2_el):
  41. fp2_pol = Fp2_el.polynomial()
  42. print("A: FpElement{0x" + hd(fp2_pol[1]) + "},")
  43. print("B: FpElement{0x" + hd(fp2_pol[0]) + "}}")
  44. def print_fp2_in_mont_hex(Fp2_el, text):
  45. print(text)
  46. mul = Integer(R)*Fp2_el
  47. fp2_pol = mul.polynomial()
  48. print("A: FpElement{0x" + hd(fp2_pol[0]) + "},")
  49. print("B: FpElement{0x" + hd(fp2_pol[1]) + "}}")
  50. Integer(2^4 - 1).digits(2)
  51. print("\n P =\n"+hd(p))
  52. print("\n pX2 =\n"+hd(2*p))
  53. print("\n p+1 =\n"+hd(p+1))
  54. print("\n R^2 mod p =\n"+hd((R^2) % p))
  55. print("\n1/2 * R mod p =\n"+hd(((1/2)*R) % p))
  56. print("\n R mod p =\n"+hd(R % p))
  57. print("\n 6 * R mod p =\n"+hd(((6*R) % p)))