crypto_curve25519.h 2.9 KB

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