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.
 
 
 
 
 

42 lines
1.3 KiB

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