<div dir="ltr">I don't expect this to influence the design of Noise very much, but in case it's useful to have, here's the "public" API that my Noise implementation exposes to the rest of the codebase. The functions that consume messages take a pointer to a structure elsewhere in my code, and return a pointer to another structure. <div><br></div><div><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="" style="color:rgb(136,136,136);font-weight:bold">bool</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_handshake_create_initiation</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_message_handshake_initiation</span> <span class="">*</span><span class="">dst</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">,</span> <span class="">u16</span> <span class="">self_index</span><span class="">);</span>
<span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">wireguard_peer</span> <span class="">*</span><span class="" style="color:rgb(0,102,187);font-weight:bold">noise_handshake_consume_initiation</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_message_handshake_initiation</span> <span class="">*</span><span class="">src</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">wireguard_device</span> <span class="">*</span><span class="">wg</span><span class="">);</span></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="" style="color:rgb(136,136,136);font-weight:bold">bool</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_handshake_create_response</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_message_handshake_response</span> <span class="">*</span><span class="">dst</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">,</span> <span class="">u16</span> <span class="">self_index</span><span class="">);</span>
<span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">wireguard_peer</span> <span class="">*</span><span class="" style="color:rgb(0,102,187);font-weight:bold">noise_handshake_consume_response</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_message_handshake_response</span> <span class="">*</span><span class="">src</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">wireguard_device</span> <span class="">*</span><span class="">wg</span><span class="">);</span></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="" style="color:rgb(136,136,136);font-weight:bold">bool</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_handshake_begin_session</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">,</span> <span class="" style="color:rgb(136,136,136);font-weight:bold">bool</span> <span class="">i_am_the_initator</span><span class="">);</span></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="" style="color:rgb(136,136,136);font-weight:bold">bool</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_message_create_data</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_message_data</span> <span class="">*</span><span class="">dst</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">const</span> <span class="">u8</span> <span class="">*</span><span class="">src</span><span class="">,</span> <span class="" style="color:rgb(136,136,136);font-weight:bold">size_t</span> <span class="">src_len</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">);</span></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">wireguard_peer</span> <span class="">*</span><span class="" style="color:rgb(0,102,187);font-weight:bold">noise_message_consume_data</span><span class="">(</span><span class="">u8</span> <span class="">*</span><span class="">dst</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">const</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_message_data</span> <span class="">*</span><span class="">src</span><span class="">,</span> <span class="" style="color:rgb(136,136,136);font-weight:bold">size_t</span> <span class="">src_len</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">wireguard_device</span> <span class="">*</span><span class="">wg</span><span class="">);</span></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="" style="color:rgb(136,136,136);font-weight:bold">void</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_peer_init</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">const</span> <span class="">u8</span> <span class="">my_private_key</span><span class="">[</span><span class="">NOISE_PUBLIC_KEY_LEN</span><span class="">],</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">const</span> <span class="">u8</span> <span class="">their_public_key</span><span class="">[</span><span class="">NOISE_PUBLIC_KEY_LEN</span><span class="">]);</span>
<span class="" style="color:rgb(136,136,136);font-weight:bold">void</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_peer_set_private_key</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">,</span> <span class="" style="color:rgb(0,136,0);font-weight:bold">const</span> <span class="">u8</span> <span class="">my_private_key</span><span class="">[</span><span class="">NOISE_PUBLIC_KEY_LEN</span><span class="">]);</span>
<span class="" style="color:rgb(136,136,136);font-weight:bold">void</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_peer_clear</span><span class="">(</span><span class="" style="color:rgb(0,136,0);font-weight:bold">struct</span> <span class="">noise_peer</span> <span class="">*</span><span class="">peer</span><span class="">);</span></pre><pre style="padding:0px;margin-top:0px;margin-bottom:0px;color:rgb(0,0,0);font-size:13.3333px"><span class="">u8</span> <span class="" style="color:rgb(0,102,187);font-weight:bold">noise_message_determine_type</span><span class="">(</span><span class="" style="color:rgb(136,136,136);font-weight:bold">void</span> <span class="">*</span><span class="">src</span><span class="">,</span> <span class="" style="color:rgb(136,136,136);font-weight:bold">size_t</span> <span class="">src_len</span><span class="">);</span></pre></div></div>