sign.c 715 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <string.h>
  2. #include "crypto_sign.h"
  3. #include "crypto_hash_sha512.h"
  4. #include "ge.h"
  5. #include "sc.h"
  6. int crypto_sign(
  7. unsigned char *sm,unsigned long long *smlen,
  8. const unsigned char *m,unsigned long long mlen,
  9. const unsigned char *sk
  10. )
  11. {
  12. unsigned char pk[32];
  13. unsigned char nonce[64];
  14. unsigned char hram[64];
  15. ge_p3 R;
  16. crypto_sign_pubkey(pk,sk);
  17. *smlen = mlen + 64;
  18. memmove(sm + 64,m,mlen);
  19. memmove(sm + 32,sk + 32,32);
  20. crypto_hash_sha512(nonce,sm + 32,mlen + 32);
  21. memmove(sm + 32,pk,32);
  22. sc_reduce(nonce);
  23. ge_scalarmult_base(&R,nonce);
  24. ge_p3_tobytes(sm,&R);
  25. crypto_hash_sha512(hram,sm,mlen + 64);
  26. sc_reduce(hram);
  27. sc_muladd(sm + 32,hram,sk,nonce);
  28. return 0;
  29. }