keyconv.c 863 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Added to ref10 for Tor. We place this in the public domain. Alternatively,
  2. * you may have it under the Creative Commons 0 "CC0" license. */
  3. #include "fe.h"
  4. #include "ed25519_ref10.h"
  5. int ed25519_ref10_pubkey_from_curve25519_pubkey(unsigned char *out,
  6. const unsigned char *inp,
  7. int signbit)
  8. {
  9. fe u;
  10. fe one;
  11. fe y;
  12. fe uplus1;
  13. fe uminus1;
  14. fe inv_uplus1;
  15. /* From prop228:
  16. Given a curve25519 x-coordinate (u), we can get the y coordinate
  17. of the ed25519 key using
  18. y = (u-1)/(u+1)
  19. */
  20. fe_frombytes(u, inp);
  21. fe_1(one);
  22. fe_sub(uminus1, u, one);
  23. fe_add(uplus1, u, one);
  24. fe_invert(inv_uplus1, uplus1);
  25. fe_mul(y, uminus1, inv_uplus1);
  26. fe_tobytes(out, y);
  27. /* propagate sign. */
  28. out[31] |= (!!signbit) << 7;
  29. return 0;
  30. }