You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

50 lines
1.4 KiB

  1. /**
  2. * @cond internal
  3. * @file f_arithmetic.c
  4. * @copyright
  5. * Copyright (c) 2014 Cryptography Research, Inc. \n
  6. * Released under the MIT License. See LICENSE.txt for license information.
  7. * @author Mike Hamburg
  8. * @brief Field-specific arithmetic.
  9. */
  10. #include "field.h"
  11. const gf MODULUS = {FIELD_LITERAL(
  12. 0x3ffffffffffffff, 0x3ffffffffffffff, 0x3ffffffffffffff,
  13. 0x3ffffffffffffff, 0x3ffffffffffffff, 0x3ffffffffffffff,
  14. 0x3ffffffffffffff, 0x3ffffffffffffff, 0x1ffffffffffffff
  15. )};
  16. void
  17. gf_isr (
  18. gf_a_t a,
  19. const gf_a_t x
  20. ) {
  21. gf_a_t L0, L1, L2;
  22. gf_sqr ( L1, x );
  23. gf_mul ( L0, x, L1 );
  24. gf_sqrn ( L2, L0, 2 );
  25. gf_mul ( L1, L0, L2 );
  26. gf_sqrn ( L2, L1, 4 );
  27. gf_mul ( L0, L1, L2 );
  28. gf_sqrn ( L2, L0, 8 );
  29. gf_mul ( L1, L0, L2 );
  30. gf_sqrn ( L2, L1, 16 );
  31. gf_mul ( L0, L1, L2 );
  32. gf_sqrn ( L2, L0, 32 );
  33. gf_mul ( L1, L0, L2 );
  34. gf_sqr ( L2, L1 );
  35. gf_mul ( L0, x, L2 );
  36. gf_sqrn ( L2, L0, 64 );
  37. gf_mul ( L0, L1, L2 );
  38. gf_sqrn ( L2, L0, 129 );
  39. gf_mul ( L1, L0, L2 );
  40. gf_sqr ( L2, L1 );
  41. gf_mul ( L0, x, L2 );
  42. gf_sqrn ( L2, L0, 259 );
  43. gf_mul ( L1, L0, L2 );
  44. gf_sqr ( L0, L1 );
  45. gf_mul ( a, x, L0 );
  46. }