keypair.c 837 B

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