crypto_curve25519.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. int curve25519_public_key_is_ok(const curve25519_public_key_t *);
  28. int curve25519_secret_key_generate(curve25519_secret_key_t *key_out,
  29. int extra_strong);
  30. void curve25519_public_key_generate(curve25519_public_key_t *key_out,
  31. const curve25519_secret_key_t *seckey);
  32. int curve25519_keypair_generate(curve25519_keypair_t *keypair_out,
  33. int extra_strong);
  34. void curve25519_handshake(uint8_t *output,
  35. const curve25519_secret_key_t *,
  36. const curve25519_public_key_t *);
  37. int curve25519_keypair_write_to_file(const curve25519_keypair_t *keypair,
  38. const char *fname,
  39. const char *tag);
  40. int curve25519_keypair_read_from_file(curve25519_keypair_t *keypair_out,
  41. char **tag_out,
  42. const char *fname);
  43. #ifdef CRYPTO_CURVE25519_PRIVATE
  44. STATIC int curve25519_impl(uint8_t *output, const uint8_t *secret,
  45. const uint8_t *basepoint);
  46. #endif
  47. #endif
  48. #define CURVE25519_BASE64_PADDED_LEN 44
  49. int curve25519_public_from_base64(curve25519_public_key_t *pkey,
  50. const char *input);
  51. int curve25519_public_to_base64(char *output,
  52. const curve25519_public_key_t *pkey);
  53. #endif