sign.c 797 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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,uint64_t *smlen,
  8. const unsigned char *m,uint64_t mlen,
  9. const unsigned char *sk
  10. )
  11. {
  12. unsigned char pk[32];
  13. unsigned char az[64];
  14. unsigned char nonce[64];
  15. unsigned char hram[64];
  16. ge_p3 R;
  17. memmove(pk,sk + 32,32);
  18. crypto_hash_sha512(az,sk,32);
  19. az[0] &= 248;
  20. az[31] &= 63;
  21. az[31] |= 64;
  22. *smlen = mlen + 64;
  23. memmove(sm + 64,m,mlen);
  24. memmove(sm + 32,az + 32,32);
  25. crypto_hash_sha512(nonce,sm + 32,mlen + 32);
  26. memmove(sm + 32,pk,32);
  27. sc_reduce(nonce);
  28. ge_scalarmult_base(&R,nonce);
  29. ge_p3_tobytes(sm,&R);
  30. crypto_hash_sha512(hram,sm,mlen + 64);
  31. sc_reduce(hram);
  32. sc_muladd(sm + 32,hram,az,nonce);
  33. return 0;
  34. }