crypto_curve25519.h 3.0 KB

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