tor

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

keypair.c (916B)


      1 /* Modified for Tor: new API, 64-byte secret keys. */
      2 
      3 #include "randombytes.h"
      4 #include <string.h>
      5 #include "crypto_sign.h"
      6 #include "crypto_hash_sha512.h"
      7 #include "ge.h"
      8 
      9 #include "lib/crypt_ops/crypto_rand.h"
     10 #include "lib/crypt_ops/crypto_util.h"
     11 
     12 int
     13 crypto_sign_seckey(unsigned char *sk)
     14 {
     15  unsigned char seed[32];
     16 
     17  if (randombytes(seed,32) < 0)
     18    return -1;
     19 
     20  crypto_sign_seckey_expand(sk, seed);
     21 
     22  memwipe(seed, 0, 32);
     23 
     24  return 0;
     25 }
     26 
     27 int crypto_sign_seckey_expand(unsigned char *sk, const unsigned char *skseed)
     28 {
     29  crypto_hash_sha512(sk,skseed,32);
     30  sk[0] &= 248;
     31  sk[31] &= 63;
     32  sk[31] |= 64;
     33 
     34  return 0;
     35 }
     36 
     37 int crypto_sign_pubkey(unsigned char *pk,const unsigned char *sk)
     38 {
     39  ge_p3 A;
     40 
     41  ge_scalarmult_base(&A,sk);
     42  ge_p3_tobytes(pk,&A);
     43 
     44  return 0;
     45 }
     46 
     47 
     48 int crypto_sign_keypair(unsigned char *pk,unsigned char *sk)
     49 {
     50  crypto_sign_seckey(sk);
     51  crypto_sign_pubkey(pk, sk);
     52 
     53  return 0;
     54 }