damus

nostr ios client
git clone git://jb55.com/damus
Log | Files | Refs | README | LICENSE

secp256k1_ecdh.h (2562B)


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