@@ -159,7 +159,7 @@ struct handshake {
159159 struct secret temp_k ;
160160 struct sha256 h ;
161161 struct keypair e ;
162- struct secret ss ;
162+ struct secret * ss ;
163163
164164 /* Used between the Acts */
165165 struct pubkey re ;
@@ -473,18 +473,19 @@ static struct io_plan *act_three_initiator(struct io_conn *conn,
473473 * * where `re` is the ephemeral public key of the responder
474474 *
475475 */
476- if (!hsm_do_ecdh (& h -> ss , & h -> re ))
476+ h -> ss = hsm_do_ecdh (h , & h -> re );
477+ if (!h -> ss )
477478 return handshake_failed (conn , h );
478479
479- SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , & h -> ss , sizeof (h -> ss )));
480+ SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss , sizeof (* h -> ss )));
480481
481482 /* BOLT #8:
482483 *
483484 * 4. `ck, temp_k3 = HKDF(ck, ss)`
484485 * * The final intermediate shared secret is mixed into the running
485486 * chaining key.
486487 */
487- hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , & h -> ss , sizeof (h -> ss ));
488+ hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , h -> ss , sizeof (* h -> ss ));
488489 SUPERVERBOSE ("# ck,temp_k3=0x%s,0x%s" ,
489490 tal_hexstr (tmpctx , & h -> ck , sizeof (h -> ck )),
490491 tal_hexstr (tmpctx , & h -> temp_k , sizeof (h -> temp_k )));
@@ -549,19 +550,19 @@ static struct io_plan *act_two_initiator2(struct io_conn *conn,
549550 * 5. `ss = ECDH(re, e.priv)`
550551 * * where `re` is the responder's ephemeral public key
551552 */
552- if (!secp256k1_ecdh (secp256k1_ctx , h -> ss . data , & h -> re .pubkey ,
553+ if (!secp256k1_ecdh (secp256k1_ctx , h -> ss -> data , & h -> re .pubkey ,
553554 h -> e .priv .secret .data ))
554555 return handshake_failed (conn , h );
555556
556- SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , & h -> ss , sizeof (h -> ss )));
557+ SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss , sizeof (* h -> ss )));
557558
558559 /* BOLT #8:
559560 *
560561 * 6. `ck, temp_k2 = HKDF(ck, ss)`
561562 * * A new temporary encryption key is generated, which is
562563 * used to generate the authenticating MAC.
563564 */
564- hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , & h -> ss , sizeof (h -> ss ));
565+ hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , h -> ss , sizeof (* h -> ss ));
565566 SUPERVERBOSE ("# ck,temp_k2=0x%s,0x%s" ,
566567 tal_hexstr (tmpctx , & h -> ck , sizeof (h -> ck )),
567568 tal_hexstr (tmpctx , & h -> temp_k , sizeof (h -> temp_k )));
@@ -639,19 +640,20 @@ static struct io_plan *act_one_initiator(struct io_conn *conn,
639640 * * The initiator performs an ECDH between its newly generated
640641 * ephemeral key and the remote node's static public key.
641642 */
642- if (!secp256k1_ecdh (secp256k1_ctx , h -> ss .data ,
643+ h -> ss = tal (h , struct secret );
644+ if (!secp256k1_ecdh (secp256k1_ctx , h -> ss -> data ,
643645 & h -> their_id .pubkey , h -> e .priv .secret .data ))
644646 return handshake_failed (conn , h );
645647
646- SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss . data , sizeof (h -> ss . data )));
648+ SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss -> data , sizeof (h -> ss -> data )));
647649
648650 /* BOLT #8:
649651 *
650652 * 4. `ck, temp_k1 = HKDF(ck, ss)`
651653 * * A new temporary encryption key is generated, which is
652654 * used to generate the authenticating MAC.
653655 */
654- hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , & h -> ss , sizeof (h -> ss ));
656+ hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , h -> ss , sizeof (* h -> ss ));
655657 SUPERVERBOSE ("# ck,temp_k1=0x%s,0x%s" ,
656658 tal_hexstr (tmpctx , & h -> ck , sizeof (h -> ck )),
657659 tal_hexstr (tmpctx , & h -> temp_k , sizeof (h -> temp_k )));
@@ -740,16 +742,16 @@ static struct io_plan *act_three_responder2(struct io_conn *conn,
740742 * 6. `ss = ECDH(rs, e.priv)`
741743 * * where `e` is the responder's original ephemeral key
742744 */
743- if (!secp256k1_ecdh (secp256k1_ctx , h -> ss . data , & h -> their_id .pubkey ,
745+ if (!secp256k1_ecdh (secp256k1_ctx , h -> ss -> data , & h -> their_id .pubkey ,
744746 h -> e .priv .secret .data ))
745747 return handshake_failed (conn , h );
746748
747- SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , & h -> ss , sizeof (h -> ss )));
749+ SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss , sizeof (* h -> ss )));
748750
749751 /* BOLT #8:
750752 * 7. `ck, temp_k3 = HKDF(ck, ss)`
751753 */
752- hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , & h -> ss , sizeof (h -> ss ));
754+ hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , h -> ss , sizeof (* h -> ss ));
753755 SUPERVERBOSE ("# ck,temp_k3=0x%s,0x%s" ,
754756 tal_hexstr (tmpctx , & h -> ck , sizeof (h -> ck )),
755757 tal_hexstr (tmpctx , & h -> temp_k , sizeof (h -> temp_k )));
@@ -815,18 +817,18 @@ static struct io_plan *act_two_responder(struct io_conn *conn,
815817 * * where `re` is the ephemeral key of the initiator, which was
816818 * received during Act One
817819 */
818- if (!secp256k1_ecdh (secp256k1_ctx , h -> ss . data , & h -> re .pubkey ,
820+ if (!secp256k1_ecdh (secp256k1_ctx , h -> ss -> data , & h -> re .pubkey ,
819821 h -> e .priv .secret .data ))
820822 return handshake_failed (conn , h );
821- SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , & h -> ss , sizeof (h -> ss )));
823+ SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss , sizeof (* h -> ss )));
822824
823825 /* BOLT #8:
824826 *
825827 * 4. `ck, temp_k2 = HKDF(ck, ss)`
826828 * * A new temporary encryption key is generated, which is
827829 * used to generate the authenticating MAC.
828830 */
829- hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , & h -> ss , sizeof (h -> ss ));
831+ hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , h -> ss , sizeof (* h -> ss ));
830832 SUPERVERBOSE ("# ck,temp_k2=0x%s,0x%s" ,
831833 tal_hexstr (tmpctx , & h -> ck , sizeof (h -> ck )),
832834 tal_hexstr (tmpctx , & h -> temp_k , sizeof (h -> temp_k )));
@@ -902,18 +904,19 @@ static struct io_plan *act_one_responder2(struct io_conn *conn,
902904 * * The responder performs an ECDH between its static private key and
903905 * the initiator's ephemeral public key.
904906 */
905- if (!hsm_do_ecdh (& h -> ss , & h -> re ))
907+ h -> ss = hsm_do_ecdh (h , & h -> re );
908+ if (!h -> ss )
906909 return handshake_failed (conn , h );
907910
908- SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , & h -> ss , sizeof (h -> ss )));
911+ SUPERVERBOSE ("# ss=0x%s" , tal_hexstr (tmpctx , h -> ss , sizeof (* h -> ss )));
909912
910913 /* BOLT #8:
911914 *
912915 * 6. `ck, temp_k1 = HKDF(ck, ss)`
913916 * * A new temporary encryption key is generated, which will
914917 * shortly be used to check the authenticating MAC.
915918 */
916- hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , & h -> ss , sizeof (h -> ss ));
919+ hkdf_two_keys (& h -> ck , & h -> temp_k , & h -> ck , h -> ss , sizeof (* h -> ss ));
917920 SUPERVERBOSE ("# ck,temp_k1=0x%s,0x%s" ,
918921 tal_hexstr (tmpctx , & h -> ck , sizeof (h -> ck )),
919922 tal_hexstr (tmpctx , & h -> temp_k , sizeof (h -> temp_k )));
0 commit comments