crypto_ed25519.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* Copyright (c) 2012-2013, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_CRYPTO_ED25519_H
  4. #define TOR_CRYPTO_ED25519_H
  5. #include "testsupport.h"
  6. #include "torint.h"
  7. #define ED25519_PUBKEY_LEN 32
  8. #define ED25519_SECKEY_LEN 32
  9. #define ED25519_SIG_LEN 64
  10. /** An Ed25519 signature. */
  11. typedef struct {
  12. uint8_t sig[ED25519_SIG_LEN];
  13. } ed25519_signature_t;
  14. /** An Ed25519 public key */
  15. typedef struct {
  16. uint8_t pubkey[ED25519_PUBKEY_LEN];
  17. } ed25519_public_key_t;
  18. /** An Ed25519 secret key */
  19. typedef struct {
  20. uint8_t seckey[ED25519_SECKEY_LEN];
  21. } ed25519_secret_key_t;
  22. /** An Ed25519 keypair. */
  23. typedef struct {
  24. ed25519_public_key_t pubkey;
  25. ed25519_secret_key_t seckey;
  26. } ed25519_keypair_t;
  27. #ifdef CURVE25519_ENABLED
  28. int ed25519_secret_key_generate(ed25519_secret_key_t *seckey_out,
  29. int extra_strong);
  30. int ed25519_public_key_generate(ed25519_public_key_t *pubkey_out,
  31. const ed25519_secret_key_t *seckey);
  32. int ed25519_keypair_generate(ed25519_keypair_t *keypair_out, int extra_strong);
  33. int ed25519_sign(ed25519_signature_t *signature_out,
  34. const uint8_t *msg, size_t len,
  35. const ed25519_keypair_t *key);
  36. int ed25519_checksig(const ed25519_signature_t *signature,
  37. const uint8_t *msg, size_t len,
  38. const ed25519_public_key_t *pubkey);
  39. /**
  40. * A collection of information necessary to check an Ed25519 signature. Used
  41. * for batch verification.
  42. */
  43. typedef struct {
  44. /** The public key that supposedly generated the signature. */
  45. ed25519_public_key_t *pubkey;
  46. /** The signature to check. */
  47. ed25519_signature_t signature;
  48. /** The message that the signature is supposed to have been applied to. */
  49. const uint8_t *msg;
  50. /** The length of the message. */
  51. size_t len;
  52. } ed25519_checkable_t;
  53. int ed25519_checksig_batch(int *okay_out,
  54. const ed25519_checkable_t *checkable,
  55. int n_checkable);
  56. #endif
  57. /* XXXX write secret keys to disk, load secret keys from disk, read encrypted,
  58. * write encrypted. serialize public. parse public. */
  59. #endif