tor

The Tor anonymity network
git clone https://git.dasho.dev/tor.git
Log | Files | Refs | README | LICENSE

keyconv.c (863B)


      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 
      6 int ed25519_ref10_pubkey_from_curve25519_pubkey(unsigned char *out,
      7                                                const unsigned char *inp,
      8                                                int signbit)
      9 {
     10  fe u;
     11  fe one;
     12  fe y;
     13  fe uplus1;
     14  fe uminus1;
     15  fe inv_uplus1;
     16 
     17  /* From prop228:
     18 
     19   Given a curve25519 x-coordinate (u), we can get the y coordinate
     20   of the ed25519 key using
     21 
     22         y = (u-1)/(u+1)
     23  */
     24  fe_frombytes(u, inp);
     25  fe_1(one);
     26  fe_sub(uminus1, u, one);
     27  fe_add(uplus1, u, one);
     28  fe_invert(inv_uplus1, uplus1);
     29  fe_mul(y, uminus1, inv_uplus1);
     30 
     31  fe_tobytes(out, y);
     32 
     33  /* propagate sign. */
     34  out[31] |= (!!signbit) << 7;
     35 
     36  return 0;
     37 }