fp12e.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * File: dclxvi-20130329/fp12e.h
  3. * Author: Ruben Niederhagen, Peter Schwabe
  4. * Public Domain
  5. */
  6. #ifndef FP12E_H
  7. #define FP12E_H
  8. #include "fp6e.h"
  9. #include "scalar.h"
  10. #ifdef BENCH
  11. unsigned long long multp12cycles; unsigned long long nummultp12;
  12. unsigned long long sqp12cycles; unsigned long long numsqp12;
  13. unsigned long long sqp12norm1cycles; unsigned long long numsqp12norm1;
  14. unsigned long long invp12cycles; unsigned long long numinvp12;
  15. #endif
  16. // Elements from F_{p^{12}}= F_{p^6}[Z] / (Z^2 - tau)F_{p^6}[Z] are represented as aZ + b
  17. typedef struct fp12e_struct fp12e_struct_t;
  18. struct fp12e_struct
  19. {
  20. fp6e_t m_a;
  21. fp6e_t m_b;
  22. };
  23. typedef fp12e_struct_t fp12e_t[1];
  24. // Set fp12e_t rop to given value:
  25. void fp12e_set(fp12e_t rop, const fp12e_t op);
  26. // Initialize an fp12e, set to value given in two fp6es
  27. void fp12e_set_fp6e(fp12e_t rop, const fp6e_t a, const fp6e_t b);
  28. // Set rop to one:
  29. void fp12e_setone(fp12e_t rop);
  30. // Set rop to zero:
  31. void fp12e_setzero(fp12e_t rop);
  32. // Compare for equality:
  33. int fp12e_iseq(const fp12e_t op1, const fp12e_t op2);
  34. int fp12e_isone(const fp12e_t op);
  35. int fp12e_iszero(const fp12e_t op);
  36. void fp12e_cmov(fp12e_t rop, const fp12e_t op, int c);
  37. // Compute conjugate over Fp6:
  38. void fp12e_conjugate(fp12e_t rop, const fp12e_t op2);
  39. // Add two fp12e, store result in rop:
  40. void fp12e_add(fp12e_t rop, const fp12e_t op1, const fp12e_t op2);
  41. // Subtract op2 from op1, store result in rop:
  42. void fp12e_sub(fp12e_t rop, const fp12e_t op1, const fp12e_t op2);
  43. // Multiply two fp12e, store result in rop:
  44. void fp12e_mul(fp12e_t rop, const fp12e_t op1, const fp12e_t op2);
  45. void fp12e_mul_fp6e(fp12e_t rop, const fp12e_t op1, const fp6e_t op2);
  46. // Square an fp12e, store result in rop:
  47. void fp12e_square(fp12e_t rop, const fp12e_t op);
  48. // Multiply an fp12e by a line function value, store result in rop:
  49. // The line function is given by 3 fp2e elements op2, op3, op4 as
  50. // line = (op2*tau + op3)*z + op4 = a2*z + b2.
  51. void fp12e_mul_line(fp12e_t rop, const fp12e_t op1, const fp2e_t op2, const fp2e_t op3, const fp2e_t op4);
  52. void fp12e_pow_vartime(fp12e_t rop, const fp12e_t op, const scalar_t exp);
  53. //void fp12e_pow_norm1(fp12e_t rop, const fp12e_t op, const scalar_t exp, const unsigned int exp_bitsize);
  54. // Implicit fp4 squaring for Granger/Scott special squaring in final expo
  55. // fp4e_square takes two fp2e op1, op2 representing the fp4 element
  56. // op1*z^3 + op2, writes the square to rop1, rop2 representing rop1*z^3 + rop2.
  57. // (op1*z^3 + op2)^2 = (2*op1*op2)*z^3 + (op1^2*xi + op2^2).
  58. void fp4e_square(fp2e_t rop1, fp2e_t rop2, const fp2e_t op1, const fp2e_t op2);
  59. // Special squaring for use on elements in T_6(fp2) (after the
  60. // easy part of the final exponentiation. Used in the hard part
  61. // of the final exponentiation. Function uses formulas in
  62. // Granger/Scott (PKC2010).
  63. void fp12e_special_square_finexp(fp12e_t rop, const fp12e_t op);
  64. void fp12e_invert(fp12e_t rop, const fp12e_t op);
  65. void fp12e_frobenius_p(fp12e_t rop, const fp12e_t op);
  66. void fp12e_frobenius_p2(fp12e_t rop, const fp12e_t op);
  67. // Scalar multiple of an fp12e, store result in rop:
  68. void fp12e_mul_scalar(fp12e_t rop, const fp12e_t op1, const scalar_t op2);
  69. // Print the element to stdout:
  70. void fp12e_print(FILE *outfile, const fp12e_t op);
  71. #endif // ifndef FP12E_H