crypto_curve25519.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* Copyright (c) 2012-2016, The Tor Project, Inc. */
  2. /* See LICENSE for licensing information */
  3. #ifndef TOR_CRYPTO_CURVE25519_H
  4. #define TOR_CRYPTO_CURVE25519_H
  5. #include "testsupport.h"
  6. #include "torint.h"
  7. /** Length of a curve25519 public key when encoded. */
  8. #define CURVE25519_PUBKEY_LEN 32
  9. /** Length of a curve25519 secret key when encoded. */
  10. #define CURVE25519_SECKEY_LEN 32
  11. /** Length of the result of a curve25519 handshake. */
  12. #define CURVE25519_OUTPUT_LEN 32
  13. /** Wrapper type for a curve25519 public key */
  14. typedef struct curve25519_public_key_t {
  15. uint8_t public_key[CURVE25519_PUBKEY_LEN];
  16. } curve25519_public_key_t;
  17. /** Wrapper type for a curve25519 secret key */
  18. typedef struct curve25519_secret_key_t {
  19. uint8_t secret_key[CURVE25519_SECKEY_LEN];
  20. } curve25519_secret_key_t;
  21. /** A paired public and private key for curve25519. **/
  22. typedef struct curve25519_keypair_t {
  23. curve25519_public_key_t pubkey;
  24. curve25519_secret_key_t seckey;
  25. } curve25519_keypair_t;
  26. /* These functions require that we actually know how to use curve25519 keys.
  27. * The other data structures and functions in this header let us parse them,
  28. * store them, and move them around.
  29. */
  30. int curve25519_public_key_is_ok(const curve25519_public_key_t *);
  31. int curve25519_secret_key_generate(curve25519_secret_key_t *key_out,
  32. int extra_strong);
  33. void curve25519_public_key_generate(curve25519_public_key_t *key_out,
  34. const curve25519_secret_key_t *seckey);
  35. int curve25519_keypair_generate(curve25519_keypair_t *keypair_out,
  36. int extra_strong);
  37. void curve25519_handshake(uint8_t *output,
  38. const curve25519_secret_key_t *,
  39. const curve25519_public_key_t *);
  40. int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
  41. const char *fname,
  42. const char *tag);
  43. int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
  44. char **tag_out,
  45. const char *fname);
  46. int curve25519_rand_seckey_bytes(uint8_t *out, int extra_strong);
  47. #ifdef CRYPTO_CURVE25519_PRIVATE
  48. STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret,
  49. const uint8_t *basepoint);
  50. STATIC int curve25519_basepoint_impl(uint8_t *output, const uint8_t *secret);
  51. #endif
  52. #define CURVE25519_BASE64_PADDED_LEN 44
  53. int curve25519_public_from_base64(curve25519_public_key_t *pkey,
  54. const char *input);
  55. int curve25519_public_to_base64(char *output,
  56. const curve25519_public_key_t *pkey);
  57. void curve25519_set_impl_params(int use_ed);
  58. void curve25519_init(void);
  59. #endif