fp2e.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /*
  2. * File: dclxvi-20130329/fp2e.h
  3. * Author: Ruben Niederhagen, Peter Schwabe
  4. * Public Domain
  5. */
  6. #ifndef FP2E_H
  7. #define FP2E_H
  8. #include <stdio.h>
  9. #include "fpe.h"
  10. #include "mydouble.h"
  11. // Elements from F_{p^2}= F_p[X] / (x^2 - alpha)F_p[X] are represented as aX + b
  12. typedef struct fp2e_struct
  13. {
  14. // Arrangement in memory: (b0, a0, b1, a1, ... b11,a11)
  15. mydouble v[24];
  16. } __attribute__ ((aligned (16))) fp2e_struct_t;
  17. typedef fp2e_struct_t fp2e_t[1];
  18. void fp2e_to_2fpe(fpe_t ropa, fpe_t ropb, const fp2e_t op);
  19. void _2fpe_to_fp2e(fp2e_t rop, const fpe_t opa, const fpe_t opb);
  20. #ifdef QHASM
  21. #define fp2e_short_coeffred fp2e_short_coeffred_qhasm
  22. #else
  23. #define fp2e_short_coeffred fp2e_short_coeffred_c
  24. #endif
  25. void fp2e_short_coeffred(fp2e_t rop);
  26. // Set fp2e_t rop to given value:
  27. void fp2e_set(fp2e_t rop, const fp2e_t op);
  28. /* Communicate the fact that the fp2e is reduced (and that we don't know anything more about it) */
  29. void fp2e_isreduced(fp2e_t rop);
  30. // Set fp2e_t rop to given value contained in the subfield F_p:
  31. void fp2e_set_fpe(fp2e_t rop, const fpe_t op);
  32. // Set rop to one
  33. void fp2e_setone(fp2e_t rop);
  34. // Set rop to zero
  35. void fp2e_setzero(fp2e_t rop);
  36. // Compare for equality:
  37. int fp2e_iseq(const fp2e_t op1, const fp2e_t op2);
  38. int fp2e_isone(const fp2e_t op);
  39. int fp2e_iszero(const fp2e_t op);
  40. void fp2e_cmov(fp2e_t rop, const fp2e_t op, int c);
  41. #ifdef QHASM
  42. #define fp2e_double fp2e_double_qhasm
  43. #else
  44. #define fp2e_double fp2e_double_c
  45. #endif
  46. // Double an fp2e:
  47. void fp2e_double(fp2e_t rop, const fp2e_t op);
  48. // Double an fp2e:
  49. #ifdef QHASM
  50. #define fp2e_double2 fp2e_double2_qhasm
  51. #else
  52. #define fp2e_double2 fp2e_double2_c
  53. #endif
  54. void fp2e_double2(fp2e_t rop);
  55. #ifdef QHASM
  56. #define fp2e_triple fp2e_triple_qhasm
  57. #else
  58. #define fp2e_triple fp2e_triple_c
  59. #endif
  60. // Triple an fp2e:
  61. void fp2e_triple(fp2e_t rop, const fp2e_t op);
  62. // Triple an fp2e:
  63. #ifdef QHASM
  64. #define fp2e_triple2 fp2e_triple2_qhasm
  65. #else
  66. #define fp2e_triple2 fp2e_triple2_c
  67. #endif
  68. void fp2e_triple2(fp2e_t rop);
  69. void fp2e_mul_scalar(fp2e_t rop, const fp2e_t op, const int s);
  70. #ifdef QHASM
  71. #define fp2e_add fp2e_add_qhasm
  72. #else
  73. #define fp2e_add fp2e_add_c
  74. #endif
  75. // Add two fp2e, store result in rop:
  76. void fp2e_add(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
  77. // Add rop to up, store result in rop:
  78. #ifdef QHASM
  79. #define fp2e_add2 fp2e_add2_qhasm
  80. #else
  81. #define fp2e_add2 fp2e_add2_c
  82. #endif
  83. void fp2e_add2(fp2e_t rop, const fp2e_t op);
  84. // Load from mem
  85. void fp2e_load(fp2e_struct_t *rop, const fp2e_t op);
  86. //void fp2e_load(fp2e_t rop, const fp2e_t op);
  87. // store to mem
  88. void fp2e_store(fp2e_struct_t *rop, const fp2e_t op);
  89. //void fp2e_store(fp2e_t rop, const fp2e_t op);
  90. #ifdef QHASM
  91. #define fp2e_sub fp2e_sub_qhasm
  92. #else
  93. #define fp2e_sub fp2e_sub_c
  94. #endif
  95. // Subtract op2 from op1, store result in rop:
  96. void fp2e_sub(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
  97. #ifdef QHASM
  98. #define fp2e_sub2 fp2e_sub2_qhasm
  99. #else
  100. #define fp2e_sub2 fp2e_sub2_c
  101. #endif
  102. // Subtract op from rop, store result in rop:
  103. void fp2e_sub2(fp2e_t rop, const fp2e_t op);
  104. #ifdef QHASM
  105. #define fp2e_neg2 fp2e_neg2_qhasm
  106. #else
  107. #define fp2e_neg2 fp2e_neg2_c
  108. #endif
  109. void fp2e_neg2(fp2e_t op);
  110. #ifdef QHASM
  111. #define fp2e_neg fp2e_neg_qhasm
  112. #else
  113. #define fp2e_neg fp2e_neg_c
  114. #endif
  115. void fp2e_neg(fp2e_t rop, const fp2e_t op);
  116. #ifdef QHASM
  117. #define fp2e_conjugate fp2e_conjugate_qhasm
  118. #else
  119. #define fp2e_conjugate fp2e_conjugate_c
  120. #endif
  121. // Conjugates: aX+b to -aX+b
  122. void fp2e_conjugate(fp2e_t rop, const fp2e_t op);
  123. #ifdef QHASM
  124. #define fp2e_mul fp2e_mul_qhasm
  125. #else
  126. #define fp2e_mul fp2e_mul_c
  127. #endif
  128. // Multiply two fp2e, store result in rop:
  129. void fp2e_mul(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
  130. // Square an fp2e, store result in rop:
  131. #ifdef QHASM
  132. #define fp2e_square fp2e_square_qhasm
  133. #else
  134. #define fp2e_square fp2e_square_c
  135. #endif
  136. void fp2e_square(fp2e_t rop, const fp2e_t op);
  137. // Multiply by xi which is used to construct F_p^6
  138. #ifdef QHASM
  139. #define fp2e_mulxi fp2e_mulxi_qhasm
  140. #else
  141. #define fp2e_mulxi fp2e_mulxi_c
  142. #endif
  143. void fp2e_mulxi(fp2e_t rop, const fp2e_t op);
  144. // Multiple of an fp2e, store result in rop:
  145. #ifdef QHASM
  146. #define fp2e_mul_fpe fp2e_mul_fpe_qhasm
  147. #else
  148. #define fp2e_mul_fpe fp2e_mul_fpe_c
  149. #endif
  150. void fp2e_mul_fpe(fp2e_t rop, const fp2e_t op1, const fpe_t op2);
  151. #ifdef QHASM
  152. #define fp2e_parallel_coeffmul fp2e_parallel_coeffmul_qhasm
  153. #else
  154. #define fp2e_parallel_coeffmul fp2e_parallel_coeffmul_c
  155. #endif
  156. /* computes (op1->m_a*op2->m_a, op1->m_b*op2->m_b) */
  157. void fp2e_parallel_coeffmul(fp2e_t rop, const fp2e_t op1, const fp2e_t op2);
  158. // Inverse multiple of an fp2e, store result in rop:
  159. void fp2e_invert(fp2e_t rop, const fp2e_t op1);
  160. // Print the element to stdout:
  161. void fp2e_print(FILE * outfile, const fp2e_t op);
  162. #endif // ifndef FP2E_H