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.
 
 
 
 
 

38 lines
993 B

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