1
0

keypair.c 823 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <string.h>
  2. #include "crypto_sign.h"
  3. #include "crypto_hash_sha512.h"
  4. #include "randombytes.h"
  5. #include "ge25519.h"
  6. int crypto_sign_seckey_expand(unsigned char *sk,const unsigned char *seed)
  7. {
  8. crypto_hash_sha512(sk,seed,32);
  9. sk[0] &= 248;
  10. sk[31] &= 63;
  11. sk[31] |= 64;
  12. return 0;
  13. }
  14. int crypto_sign_seckey(unsigned char *sk)
  15. {
  16. unsigned char seed[32];
  17. if (randombytes(seed,32) < 0)
  18. return -1;
  19. crypto_sign_seckey_expand(sk,seed);
  20. return 0;
  21. }
  22. int crypto_sign_pubkey(unsigned char *pk,const unsigned char *sk)
  23. {
  24. sc25519 scsk;
  25. ge25519_p3 gepk;
  26. sc25519_from32bytes(&scsk,sk);
  27. ge25519_scalarmult_base(&gepk,&scsk);
  28. ge25519_pack(pk,&gepk);
  29. return 0;
  30. }
  31. int crypto_sign_keypair(unsigned char *pk,unsigned char *sk)
  32. {
  33. crypto_sign_seckey(sk);
  34. crypto_sign_pubkey(pk,sk);
  35. return 0;
  36. }