@@ -498,6 +498,51 @@ int secp256k1_ellswift_decode(const secp256k1_context *ctx, secp256k1_pubkey *pu
498498    return  1 ;
499499}
500500
501+ static  int  ellswift_xdh_hash_function_prefix (unsigned char   * output , const  unsigned char   * x32 , const  unsigned char   * ell_a64 , const  unsigned char   * ell_b64 , void  * data ) {
502+     secp256k1_sha256  sha ;
503+ 
504+     secp256k1_sha256_initialize (& sha );
505+     secp256k1_sha256_write (& sha , data , 64 );
506+     secp256k1_sha256_write (& sha , ell_a64 , 64 );
507+     secp256k1_sha256_write (& sha , ell_b64 , 64 );
508+     secp256k1_sha256_write (& sha , x32 , 32 );
509+     secp256k1_sha256_finalize (& sha , output );
510+ 
511+     return  1 ;
512+ }
513+ 
514+ /** Set hash state to the BIP340 tagged hash midstate for "bip324_ellswift_xonly_ecdh". */ 
515+ static  void  secp256k1_ellswift_sha256_init_bip324 (secp256k1_sha256 *  hash ) {
516+     secp256k1_sha256_initialize (hash );
517+     hash -> s [0 ] =  0x8c12d730ul ;
518+     hash -> s [1 ] =  0x827bd392ul ;
519+     hash -> s [2 ] =  0x9e4fb2eeul ;
520+     hash -> s [3 ] =  0x207b373eul ;
521+     hash -> s [4 ] =  0x2292bd7aul ;
522+     hash -> s [5 ] =  0xaa5441bcul ;
523+     hash -> s [6 ] =  0x15c3779ful ;
524+     hash -> s [7 ] =  0xcfb52549ul ;
525+ 
526+     hash -> bytes  =  64 ;
527+ }
528+ 
529+ static  int  ellswift_xdh_hash_function_bip324 (unsigned char  *  output , const  unsigned char   * x32 , const  unsigned char   * ell_a64 , const  unsigned char   * ell_b64 , void  * data ) {
530+     secp256k1_sha256  sha ;
531+ 
532+     (void )data ;
533+ 
534+     secp256k1_ellswift_sha256_init_bip324 (& sha );
535+     secp256k1_sha256_write (& sha , ell_a64 , 64 );
536+     secp256k1_sha256_write (& sha , ell_b64 , 64 );
537+     secp256k1_sha256_write (& sha , x32 , 32 );
538+     secp256k1_sha256_finalize (& sha , output );
539+ 
540+     return  1 ;
541+ }
542+ 
543+ const  secp256k1_ellswift_xdh_hash_function  secp256k1_ellswift_xdh_hash_function_prefix  =  ellswift_xdh_hash_function_prefix ;
544+ const  secp256k1_ellswift_xdh_hash_function  secp256k1_ellswift_xdh_hash_function_bip324  =  ellswift_xdh_hash_function_bip324 ;
545+ 
501546int  secp256k1_ellswift_xdh (const  secp256k1_context  * ctx , unsigned char   * output , const  unsigned char   * ell_a64 , const  unsigned char   * ell_b64 , const  unsigned char   * seckey32 , int  party , secp256k1_ellswift_xdh_hash_function  hashfp , void  * data ) {
502547    int  ret  =  0 ;
503548    int  overflow ;
0 commit comments