crypto_ed25519.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 read encrypted, write encrypted. */
  66. int ed25519_seckey_write_to_file(const ed25519_secret_key_t *seckey,
  67. const char *filename,
  68. const char *tag);
  69. int ed25519_seckey_read_from_file(ed25519_secret_key_t *seckey_out,
  70. char **tag_out,
  71. const char *filename);
  72. int ed25519_pubkey_write_to_file(const ed25519_public_key_t *pubkey,
  73. const char *filename,
  74. const char *tag);
  75. int ed25519_pubkey_read_from_file(ed25519_public_key_t *pubkey_out,
  76. char **tag_out,
  77. const char *filename);
  78. #endif