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.
 
 
 
 
 

37 lines
976 B

  1. /* Copyright (c) 2014-2016 Cryptography Research, Inc.
  2. * Released under the MIT License. See LICENSE.txt for license information.
  3. */
  4. #define GF_HEADROOM 933
  5. #define FIELD_LITERAL(a,b,c,d,e) {{ a,b,c,d,e }}
  6. #define LIMB_PLACE_VALUE(i) 51
  7. void gf_add_RAW (gf out, const gf a, const gf b) {
  8. for (unsigned int i=0; i<5; i++) {
  9. out->limb[i] = a->limb[i] + b->limb[i];
  10. }
  11. }
  12. void gf_sub_RAW (gf out, const gf a, const gf b) {
  13. for (unsigned int i=0; i<5; i++) {
  14. out->limb[i] = a->limb[i] - b->limb[i];
  15. }
  16. }
  17. void gf_bias (gf a, int amt) {
  18. a->limb[0] += ((uint64_t)(amt)<<52) - 38*amt;
  19. for (unsigned int i=1; i<5; i++) {
  20. a->limb[i] += ((uint64_t)(amt)<<52)-2*amt;
  21. }
  22. }
  23. void gf_weak_reduce (gf a) {
  24. uint64_t mask = (1ull<<51) - 1;
  25. uint64_t tmp = a->limb[4] >> 51;
  26. for (unsigned int i=4; i>0; i--) {
  27. a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>51);
  28. }
  29. a->limb[0] = (a->limb[0] & mask) + tmp*19;
  30. }