sign_ed25519.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <string.h>
  2. #include "crypto_hash_sha512.h"
  3. #include "crypto_sign_ed25519.h"
  4. #include "ref10/sign_ed25519_ref10.h"
  5. size_t
  6. crypto_sign_ed25519ph_statebytes(void)
  7. {
  8. return sizeof(crypto_sign_ed25519ph_state);
  9. }
  10. size_t
  11. crypto_sign_ed25519_bytes(void)
  12. {
  13. return crypto_sign_ed25519_BYTES;
  14. }
  15. size_t
  16. crypto_sign_ed25519_seedbytes(void)
  17. {
  18. return crypto_sign_ed25519_SEEDBYTES;
  19. }
  20. size_t
  21. crypto_sign_ed25519_publickeybytes(void)
  22. {
  23. return crypto_sign_ed25519_PUBLICKEYBYTES;
  24. }
  25. size_t
  26. crypto_sign_ed25519_secretkeybytes(void)
  27. {
  28. return crypto_sign_ed25519_SECRETKEYBYTES;
  29. }
  30. size_t
  31. crypto_sign_ed25519_messagebytes_max(void)
  32. {
  33. return crypto_sign_ed25519_MESSAGEBYTES_MAX;
  34. }
  35. int
  36. crypto_sign_ed25519_sk_to_seed(unsigned char *seed, const unsigned char *sk)
  37. {
  38. memmove(seed, sk, crypto_sign_ed25519_SEEDBYTES);
  39. return 0;
  40. }
  41. int
  42. crypto_sign_ed25519_sk_to_pk(unsigned char *pk, const unsigned char *sk)
  43. {
  44. memmove(pk, sk + crypto_sign_ed25519_SEEDBYTES,
  45. crypto_sign_ed25519_PUBLICKEYBYTES);
  46. return 0;
  47. }
  48. int
  49. crypto_sign_ed25519ph_init(crypto_sign_ed25519ph_state *state)
  50. {
  51. crypto_hash_sha512_init(&state->hs);
  52. return 0;
  53. }
  54. int
  55. crypto_sign_ed25519ph_update(crypto_sign_ed25519ph_state *state,
  56. const unsigned char *m, unsigned long long mlen)
  57. {
  58. return crypto_hash_sha512_update(&state->hs, m, mlen);
  59. }
  60. int
  61. crypto_sign_ed25519ph_final_create(crypto_sign_ed25519ph_state *state,
  62. unsigned char *sig,
  63. unsigned long long *siglen_p,
  64. const unsigned char *sk)
  65. {
  66. unsigned char ph[crypto_hash_sha512_BYTES];
  67. crypto_hash_sha512_final(&state->hs, ph);
  68. return _crypto_sign_ed25519_detached(sig, siglen_p, ph, sizeof ph, sk, 1);
  69. }
  70. int
  71. crypto_sign_ed25519ph_final_verify(crypto_sign_ed25519ph_state *state,
  72. const unsigned char *sig,
  73. const unsigned char *pk)
  74. {
  75. unsigned char ph[crypto_hash_sha512_BYTES];
  76. crypto_hash_sha512_final(&state->hs, ph);
  77. return _crypto_sign_ed25519_verify_detached(sig, ph, sizeof ph, pk, 1);
  78. }