fp12e.h 3.3 KB

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