crypto_ed25519.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 64
  9. #define ED25519_SECKEY_SEED_LEN 32
  10. #define ED25519_SIG_LEN 64
  11. /** An Ed25519 signature. */
  12. typedef struct {
  13. uint8_t sig[ED25519_SIG_LEN];
  14. } ed25519_signature_t;
  15. /** An Ed25519 public key */
  16. typedef struct {
  17. uint8_t pubkey[ED25519_PUBKEY_LEN];
  18. } ed25519_public_key_t;
  19. /** An Ed25519 secret key */
  20. typedef struct {
  21. uint8_t seckey[ED25519_SECKEY_LEN];
  22. } ed25519_secret_key_t;
  23. /** An Ed25519 keypair. */
  24. typedef struct {
  25. ed25519_public_key_t pubkey;
  26. ed25519_secret_key_t seckey;
  27. } ed25519_keypair_t;
  28. #ifdef CURVE25519_ENABLED
  29. int ed25519_secret_key_generate(ed25519_secret_key_t *seckey_out,
  30. int extra_strong);
  31. int ed25519_secret_key_from_seed(ed25519_secret_key_t *seckey_out,
  32. const uint8_t *seed);
  33. int ed25519_public_key_generate(ed25519_public_key_t *pubkey_out,
  34. const ed25519_secret_key_t *seckey);
  35. int ed25519_keypair_generate(ed25519_keypair_t *keypair_out, int extra_strong);
  36. int ed25519_sign(ed25519_signature_t *signature_out,
  37. const uint8_t *msg, size_t len,
  38. const ed25519_keypair_t *key);
  39. int ed25519_checksig(const ed25519_signature_t *signature,
  40. const uint8_t *msg, size_t len,
  41. const ed25519_public_key_t *pubkey);
  42. /**
  43. * A collection of information necessary to check an Ed25519 signature. Used
  44. * for batch verification.
  45. */
  46. typedef struct {
  47. /** The public key that supposedly generated the signature. */
  48. ed25519_public_key_t *pubkey;
  49. /** The signature to check. */
  50. ed25519_signature_t signature;
  51. /** The message that the signature is supposed to have been applied to. */
  52. const uint8_t *msg;
  53. /** The length of the message. */
  54. size_t len;
  55. } ed25519_checkable_t;
  56. int ed25519_checksig_batch(int *okay_out,
  57. const ed25519_checkable_t *checkable,
  58. int n_checkable);
  59. #endif
  60. #define ED25519_BASE64_LEN 43
  61. int ed25519_public_from_base64(ed25519_public_key_t *pkey,
  62. const char *input);
  63. int ed25519_public_to_base64(char *output,
  64. const ed25519_public_key_t *pkey);
  65. /* XXXX write secret keys to disk, load secret keys from disk, read encrypted,
  66. * write encrypted. */
  67. #endif