keypair.c 916 B

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