1
0

fe25519_pack.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #include "fe25519.h"
  2. /* Assumes input x being reduced below 2^255 */
  3. void fe25519_pack(unsigned char r[32], const fe25519 *x)
  4. {
  5. fe25519 t;
  6. t = *x;
  7. fe25519_freeze(&t);
  8. r[0] = (unsigned char) ( t.v[0] & 0xff);
  9. r[1] = (unsigned char) ((t.v[0] >> 8) & 0xff);
  10. r[2] = (unsigned char) ((t.v[0] >> 16) & 0xff);
  11. r[3] = (unsigned char) ((t.v[0] >> 24) & 0xff);
  12. r[4] = (unsigned char) ((t.v[0] >> 32) & 0xff);
  13. r[5] = (unsigned char) ((t.v[0] >> 40) & 0xff);
  14. r[6] = (unsigned char) ((t.v[0] >> 48));
  15. r[6] ^= (unsigned char) ((t.v[1] << 3) & 0xf8);
  16. r[7] = (unsigned char) ((t.v[1] >> 5) & 0xff);
  17. r[8] = (unsigned char) ((t.v[1] >> 13) & 0xff);
  18. r[9] = (unsigned char) ((t.v[1] >> 21) & 0xff);
  19. r[10] = (unsigned char) ((t.v[1] >> 29) & 0xff);
  20. r[11] = (unsigned char) ((t.v[1] >> 37) & 0xff);
  21. r[12] = (unsigned char) ((t.v[1] >> 45));
  22. r[12] ^= (unsigned char) ((t.v[2] << 6) & 0xc0);
  23. r[13] = (unsigned char) ((t.v[2] >> 2) & 0xff);
  24. r[14] = (unsigned char) ((t.v[2] >> 10) & 0xff);
  25. r[15] = (unsigned char) ((t.v[2] >> 18) & 0xff);
  26. r[16] = (unsigned char) ((t.v[2] >> 26) & 0xff);
  27. r[17] = (unsigned char) ((t.v[2] >> 34) & 0xff);
  28. r[18] = (unsigned char) ((t.v[2] >> 42) & 0xff);
  29. r[19] = (unsigned char) ((t.v[2] >> 50));
  30. r[19] ^= (unsigned char) ((t.v[3] << 1) & 0xfe);
  31. r[20] = (unsigned char) ((t.v[3] >> 7) & 0xff);
  32. r[21] = (unsigned char) ((t.v[3] >> 15) & 0xff);
  33. r[22] = (unsigned char) ((t.v[3] >> 23) & 0xff);
  34. r[23] = (unsigned char) ((t.v[3] >> 31) & 0xff);
  35. r[24] = (unsigned char) ((t.v[3] >> 39) & 0xff);
  36. r[25] = (unsigned char) ((t.v[3] >> 47));
  37. r[25] ^= (unsigned char) ((t.v[4] << 4) & 0xf0);
  38. r[26] = (unsigned char) ((t.v[4] >> 4) & 0xff);
  39. r[27] = (unsigned char) ((t.v[4] >> 12) & 0xff);
  40. r[28] = (unsigned char) ((t.v[4] >> 20) & 0xff);
  41. r[29] = (unsigned char) ((t.v[4] >> 28) & 0xff);
  42. r[30] = (unsigned char) ((t.v[4] >> 36) & 0xff);
  43. r[31] = (unsigned char) ((t.v[4] >> 44));
  44. }