fe25519_unpack.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include "fe25519.h"
  2. void fe25519_unpack(fe25519 *r, const unsigned char x[32])
  3. {
  4. r->v[0] = x[0];
  5. r->v[0] += (unsigned long long)x[1] << 8;
  6. r->v[0] += (unsigned long long)x[2] << 16;
  7. r->v[0] += (unsigned long long)x[3] << 24;
  8. r->v[0] += (unsigned long long)x[4] << 32;
  9. r->v[0] += (unsigned long long)x[5] << 40;
  10. r->v[0] += ((unsigned long long)x[6] & 7) << 48;
  11. r->v[1] = x[6] >> 3;
  12. r->v[1] += (unsigned long long)x[7] << 5;
  13. r->v[1] += (unsigned long long)x[8] << 13;
  14. r->v[1] += (unsigned long long)x[9] << 21;
  15. r->v[1] += (unsigned long long)x[10] << 29;
  16. r->v[1] += (unsigned long long)x[11] << 37;
  17. r->v[1] += ((unsigned long long)x[12] & 63) << 45;
  18. r->v[2] = x[12] >> 6;
  19. r->v[2] += (unsigned long long)x[13] << 2;
  20. r->v[2] += (unsigned long long)x[14] << 10;
  21. r->v[2] += (unsigned long long)x[15] << 18;
  22. r->v[2] += (unsigned long long)x[16] << 26;
  23. r->v[2] += (unsigned long long)x[17] << 34;
  24. r->v[2] += (unsigned long long)x[18] << 42;
  25. r->v[2] += ((unsigned long long)x[19] & 1) << 50;
  26. r->v[3] = x[19] >> 1;
  27. r->v[3] += (unsigned long long)x[20] << 7;
  28. r->v[3] += (unsigned long long)x[21] << 15;
  29. r->v[3] += (unsigned long long)x[22] << 23;
  30. r->v[3] += (unsigned long long)x[23] << 31;
  31. r->v[3] += (unsigned long long)x[24] << 39;
  32. r->v[3] += ((unsigned long long)x[25] & 15) << 47;
  33. r->v[4] = x[25] >> 4;
  34. r->v[4] += (unsigned long long)x[26] << 4;
  35. r->v[4] += (unsigned long long)x[27] << 12;
  36. r->v[4] += (unsigned long long)x[28] << 20;
  37. r->v[4] += (unsigned long long)x[29] << 28;
  38. r->v[4] += (unsigned long long)x[30] << 36;
  39. r->v[4] += ((unsigned long long)x[31] & 127) << 44;
  40. }