You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

secp256k1_ecdh.h 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #ifndef SECP256K1_ECDH_H
  2. #define SECP256K1_ECDH_H
  3. #include "secp256k1.h"
  4. #ifdef __cplusplus
  5. extern "C" {
  6. #endif
  7. /** A pointer to a function that hashes an EC point to obtain an ECDH secret
  8. *
  9. * Returns: 1 if the point was successfully hashed.
  10. * 0 will cause secp256k1_ecdh to fail and return 0.
  11. * Other return values are not allowed, and the behaviour of
  12. * secp256k1_ecdh is undefined for other return values.
  13. * Out: output: pointer to an array to be filled by the function
  14. * In: x32: pointer to a 32-byte x coordinate
  15. * y32: pointer to a 32-byte y coordinate
  16. * data: arbitrary data pointer that is passed through
  17. */
  18. typedef int (*secp256k1_ecdh_hash_function)(
  19. unsigned char *output,
  20. const unsigned char *x32,
  21. const unsigned char *y32,
  22. void *data
  23. );
  24. /** An implementation of SHA256 hash function that applies to compressed public key.
  25. * Populates the output parameter with 32 bytes. */
  26. SECP256K1_API extern const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_sha256;
  27. /** A default ECDH hash function (currently equal to secp256k1_ecdh_hash_function_sha256).
  28. * Populates the output parameter with 32 bytes. */
  29. SECP256K1_API extern const secp256k1_ecdh_hash_function secp256k1_ecdh_hash_function_default;
  30. /** Compute an EC Diffie-Hellman secret in constant time
  31. *
  32. * Returns: 1: exponentiation was successful
  33. * 0: scalar was invalid (zero or overflow) or hashfp returned 0
  34. * Args: ctx: pointer to a context object (cannot be NULL)
  35. * Out: output: pointer to an array to be filled by hashfp
  36. * In: pubkey: a pointer to a secp256k1_pubkey containing an
  37. * initialized public key
  38. * seckey: a 32-byte scalar with which to multiply the point
  39. * hashfp: pointer to a hash function. If NULL, secp256k1_ecdh_hash_function_sha256 is used
  40. * (in which case, 32 bytes will be written to output)
  41. * data: arbitrary data pointer that is passed through to hashfp
  42. */
  43. SECP256K1_API SECP256K1_WARN_UNUSED_RESULT int secp256k1_ecdh(
  44. const secp256k1_context* ctx,
  45. unsigned char *output,
  46. const secp256k1_pubkey *pubkey,
  47. const unsigned char *seckey,
  48. secp256k1_ecdh_hash_function hashfp,
  49. void *data
  50. ) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3) SECP256K1_ARG_NONNULL(4);
  51. #ifdef __cplusplus
  52. }
  53. #endif
  54. #endif /* SECP256K1_ECDH_H */