sign.c 827 B

1234567891011121314151617181920212223242526272829303132
  1. #include "ed25519.h"
  2. #include "sha512.h"
  3. #include "ge.h"
  4. #include "sc.h"
  5. void ed25519_sign(unsigned char *signature, const unsigned char *message, size_t message_len, const unsigned char *public_key, const unsigned char *private_key) {
  6. sha512_context hash;
  7. unsigned char hram[64];
  8. unsigned char r[64];
  9. ge_p3 R;
  10. sha512_init(&hash);
  11. sha512_update(&hash, private_key + 32, 32);
  12. sha512_update(&hash, message, message_len);
  13. sha512_final(&hash, r);
  14. sc_reduce(r);
  15. ge_scalarmult_base(&R, r);
  16. ge_p3_tobytes(signature, &R);
  17. sha512_init(&hash);
  18. sha512_update(&hash, signature, 32);
  19. sha512_update(&hash, public_key, 32);
  20. sha512_update(&hash, message, message_len);
  21. sha512_final(&hash, hram);
  22. sc_reduce(hram);
  23. sc_muladd(signature + 32, hram, private_key, r);
  24. }