keypair.c 750 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #include <string.h>
  2. #include "randombytes.h"
  3. #include "crypto_sign.h"
  4. #include "crypto_hash_sha512.h"
  5. #include "ge.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. ge_p3 A;
  25. ge_scalarmult_base(&A,sk);
  26. ge_p3_tobytes(pk,&A);
  27. return 0;
  28. }
  29. int crypto_sign_keypair(unsigned char *pk,unsigned char *sk)
  30. {
  31. crypto_sign_seckey(sk);
  32. crypto_sign_pubkey(pk,sk);
  33. return 0;
  34. }