fpe.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * File: dclxvi-20130329/fpe.h
  3. * Author: Ruben Niederhagen, Peter Schwabe
  4. * Public Domain
  5. */
  6. #ifndef FPE_H
  7. #define FPE_H
  8. #include <stdio.h>
  9. #include "mydouble.h"
  10. #ifdef BENCH
  11. unsigned long long int multpcycles; unsigned long long int nummultp;
  12. unsigned long long int nummultzerop;
  13. unsigned long long int nummultonep;
  14. unsigned long long int sqpcycles; unsigned long long int numsqp;
  15. unsigned long long invpcycles; unsigned long long numinvp;
  16. #endif
  17. typedef struct fpe_struct fpe_struct_t;
  18. struct fpe_struct
  19. {
  20. mydouble v[12];
  21. } __attribute__ ((aligned (16)));
  22. typedef fpe_struct_t fpe_t[1];
  23. void fpe_short_coeffred(fpe_t rop);
  24. // Set fpe_t rop to given value:
  25. void fpe_set(fpe_t rop, const fpe_t op);
  26. /* Communicate the fact that the fpe is reduced (and that we don't know anything more about it) */
  27. void fpe_isreduced(fpe_t rop);
  28. // Set fpe_t rop to value given in bytearray -- inverse function to fpe_to_bytearray
  29. void fpe_set_bytearray(fpe_t rop, const unsigned char *op, size_t oplen);
  30. // Set fpe_t rop to value given in double array of length 12
  31. void fpe_set_doublearray(fpe_t rop, const mydouble op[12]);
  32. // Set rop to one
  33. void fpe_setone(fpe_t rop);
  34. // Set rop to zero
  35. void fpe_setzero(fpe_t rop);
  36. // Compare for equality:
  37. int fpe_iseq(const fpe_t op1, const fpe_t op2);
  38. // Is the element equal to 1:
  39. int fpe_isone(const fpe_t op);
  40. // Is the element equal to 0:
  41. int fpe_iszero(const fpe_t op);
  42. // Compute the negative of an fpe
  43. void fpe_neg(fpe_t rop, const fpe_t op);
  44. // Double an fpe:
  45. void fpe_double(fpe_t rop, const fpe_t op);
  46. // Triple an fpe:
  47. void fpe_triple(fpe_t rop, const fpe_t op);
  48. // Add two fpe, store result in rop:
  49. void fpe_add(fpe_t rop, const fpe_t op1, const fpe_t op2);
  50. // Subtract op2 from op1, store result in rop:
  51. void fpe_sub(fpe_t rop, const fpe_t op1, const fpe_t op2);
  52. #ifdef QHASM
  53. #define fpe_mul fpe_mul_qhasm
  54. #else
  55. #define fpe_mul fpe_mul_c
  56. #endif
  57. // Multiply two fpe, store result in rop:
  58. void fpe_mul(fpe_t rop, const fpe_t op1, const fpe_t op2);
  59. // Square an fpe, store result in rop:
  60. void fpe_square(fpe_t rop, const fpe_t op);
  61. // Compute inverse of an fpe, store result in rop:
  62. void fpe_invert(fpe_t rop, const fpe_t op1);
  63. // Print the element to stdout:
  64. void fpe_print(FILE * outfile, const fpe_t op);
  65. // Convert fpe into a bytearray
  66. void fpe_to_bytearray(unsigned char * rop, const fpe_t op);
  67. /*
  68. // Field constants
  69. fpe_t fpe_one;
  70. fpe_t zeta; // Third root of unity in F_p fulfilling Z^{p^2} = -zeta * Z
  71. fpe_t _1o3modp; // 1/3 \in \F_p
  72. // Two constants needed for the cometa-pairing computation
  73. fpe_t cometa_c0_const;
  74. fpe_t cometa_c1_const;
  75. */
  76. #endif