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.
 
 
 
 
 

36 lines
957 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. void gf_add_RAW (gf out, const gf a, const gf b) {
  6. for (unsigned int i=0; i<8; i++) {
  7. out->limb[i] = a->limb[i] + b->limb[i];
  8. }
  9. gf_weak_reduce(out);
  10. }
  11. void gf_sub_RAW (gf out, const gf a, const gf b) {
  12. uint64_t co1 = ((1ull<<56)-1)*2, co2 = co1-2;
  13. for (unsigned int i=0; i<8; i++) {
  14. out->limb[i] = a->limb[i] - b->limb[i] + ((i==4) ? co2 : co1);
  15. }
  16. gf_weak_reduce(out);
  17. }
  18. void gf_bias (gf a, int amt) {
  19. (void) a;
  20. (void) amt;
  21. }
  22. void gf_weak_reduce (gf a) {
  23. uint64_t mask = (1ull<<56) - 1;
  24. uint64_t tmp = a->limb[7] >> 56;
  25. a->limb[4] += tmp;
  26. for (unsigned int i=7; i>0; i--) {
  27. a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>56);
  28. }
  29. a->limb[0] = (a->limb[0] & mask) + tmp;
  30. }