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.
 
 
 
 
 

35 lines
938 B

  1. /* Copyright (c) 2014-2016 Cryptography Research, Inc.
  2. * Released under the MIT License. See LICENSE.txt for license information.
  3. */
  4. #define LIMB_PLACE_VALUE(i) 58
  5. void gf_add_RAW (gf out, const gf a, const gf b) {
  6. for (unsigned int i=0; i<9; 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<<58)-1)*4, co2 = ((1ull<<57)-1)*4;
  13. for (unsigned int i=0; i<9; i++) {
  14. out->limb[i] = a->limb[i] - b->limb[i] + ((i==8) ? 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<<58) - 1;
  24. uint64_t tmp = a->limb[8] >> 57;
  25. for (unsigned int i=8; i>0; i--) {
  26. a->limb[i] = (a->limb[i] & ((i==8) ? mask>>1 : mask)) + (a->limb[i-1]>>58);
  27. }
  28. a->limb[0] = (a->limb[0] & mask) + tmp;
  29. }