sign.c 812 B

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