crypto_curve25519.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (c) 2012-2013, 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. #ifdef CURVE25519_ENABLED
  27. /* These functions require that we actually know how to use curve25519 keys.
  28. * The other data structures and functions in this header let us parse them,
  29. * store them, and move them around.
  30. */
  31. int curve25519_public_key_is_ok(const curve25519_public_key_t *);
  32. int curve25519_secret_key_generate(curve25519_secret_key_t *key_out,
  33. int extra_strong);
  34. void curve25519_public_key_generate(curve25519_public_key_t *key_out,
  35. const curve25519_secret_key_t *seckey);
  36. int curve25519_keypair_generate(curve25519_keypair_t *keypair_out,
  37. int extra_strong);
  38. void curve25519_handshake(uint8_t *output,
  39. const curve25519_secret_key_t *,
  40. const curve25519_public_key_t *);
  41. int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
  42. const char *fname,
  43. const char *tag);
  44. int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
  45. char **tag_out,
  46. const char *fname);
  47. #ifdef CRYPTO_CURVE25519_PRIVATE
  48. STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret,
  49. const uint8_t *basepoint);
  50. #endif
  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. #endif