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.
 
 
 
 
 

34 lines
920 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) {{ a,b,c,d,e }}
  5. void gf_add_RAW (gf out, const gf a, const gf b) {
  6. for (unsigned int i=0; i<5; i++) {
  7. out->limb[i] = a->limb[i] + b->limb[i];
  8. }
  9. }
  10. void gf_sub_RAW (gf out, const gf a, const gf b) {
  11. for (unsigned int i=0; i<5; i++) {
  12. out->limb[i] = a->limb[i] - b->limb[i];
  13. }
  14. }
  15. void gf_bias (gf a, int amt) {
  16. a->limb[0] += ((uint64_t)(amt)<<52) - 38*amt;
  17. for (unsigned int i=1; i<5; i++) {
  18. a->limb[i] += ((uint64_t)(amt)<<52)-2*amt;
  19. }
  20. }
  21. void gf_weak_reduce (gf a) {
  22. uint64_t mask = (1ull<<51) - 1;
  23. uint64_t tmp = a->limb[4] >> 51;
  24. for (unsigned int i=4; i>0; i--) {
  25. a->limb[i] = (a->limb[i] & mask) + (a->limb[i-1]>>51);
  26. }
  27. a->limb[0] = (a->limb[0] & mask) + tmp*19;
  28. }