crypto_curve25519.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 "torint.h"
  6. /** Length of a curve25519 public key when encoded. */
  7. #define CURVE25519_PUBKEY_LEN 32
  8. /** Length of a curve25519 secret key when encoded. */
  9. #define CURVE25519_SECKEY_LEN 32
  10. /** Length of the result of a curve25519 handshake. */
  11. #define CURVE25519_OUTPUT_LEN 32
  12. /** Wrapper type for a curve25519 public key */
  13. typedef struct curve25519_public_key_t {
  14. uint8_t public_key[CURVE25519_PUBKEY_LEN];
  15. } curve25519_public_key_t;
  16. /** Wrapper type for a curve25519 secret key */
  17. typedef struct curve25519_secret_key_t {
  18. uint8_t secret_key[CURVE25519_SECKEY_LEN];
  19. } curve25519_secret_key_t;
  20. /** A paired public and private key for curve25519. **/
  21. typedef struct curve25519_keypair_t {
  22. curve25519_public_key_t pubkey;
  23. curve25519_secret_key_t seckey;
  24. } curve25519_keypair_t;
  25. #ifdef CURVE25519_ENABLED
  26. int curve25519_public_key_is_ok(const curve25519_public_key_t *);
  27. int curve25519_secret_key_generate(curve25519_secret_key_t *key_out,
  28. int extra_strong);
  29. void curve25519_public_key_generate(curve25519_public_key_t *key_out,
  30. const curve25519_secret_key_t *seckey);
  31. int curve25519_keypair_generate(curve25519_keypair_t *keypair_out,
  32. int extra_strong);
  33. void curve25519_handshake(uint8_t *output,
  34. const curve25519_secret_key_t *,
  35. const curve25519_public_key_t *);
  36. int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
  37. const char *fname,
  38. const char *tag);
  39. int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
  40. char **tag_out,
  41. const char *fname);
  42. #define CURVE25519_BASE64_PADDED_LEN 44
  43. int curve25519_public_from_base64(curve25519_public_key_t *pkey,
  44. const char *input);
  45. int curve25519_public_to_base64(char *output,
  46. const curve25519_public_key_t *pkey);
  47. #ifdef CRYPTO_CURVE25519_PRIVATE
  48. int curve25519_impl(uint8_t *output, const uint8_t *secret,
  49. const uint8_t *basepoint);
  50. #endif
  51. #endif
  52. #endif