From: "MaxF (Code Review)" Date: Wed, 20 Nov 2024 16:48:24 +0000 In-Reply-To: References: Reply-To: max@...2606..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <4e09c14977bb69df482262d57813d7a0412f4652-EmailReviewComments-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="YmFy/BVmmFA="; charset=UTF-8 Subject: [Openvpn-devel] [L] Change in openvpn[master]: Implement HKDF expand function based on RFC 8446 List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: plaisthos Cc: flichtenheld , openvpn-devel --YmFy/BVmmFA= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Attention is currently required from: flichtenheld, plaisthos. MaxF has posted comments on this change. ( http://gerrit.openvpn.net/c/open= vpn/+/798?usp=3Demail ) Change subject: Implement HKDF expand function based on RFC 8446 ...................................................................... Patch Set 4: Code-Review-2 (5 comments) Patchset: PS4: The implementation of HKDF-Expand is correct, but the implementation of HKD= F-Expand-Label is slightly wrong in a way that causes different (label, con= text) pairs to produce identical keys (in a predictable way). Another thing: Are there any plans to actually use the context argument? File src/openvpn/crypto_epoch.h: http://gerrit.openvpn.net/c/openvpn/+/798/comment/152f282d_bc633665 : PS4, Line 32: * - salt is always assumed to be zero length (ie not suppor= ted) : * - IKM (secret) is assumed to be always 32 bytes salt and IKM are arguments for HKDF-Extract, not HKDF-Expand. File src/openvpn/crypto_epoch.c: http://gerrit.openvpn.net/c/openvpn/+/798/comment/006aedfa_6f857acd : PS4, Line 67: hmac_ctx_cleanup(hmac_ctx); : hmac_ctx_free(hmac_ctx); Not exactly about this commit itself, but looking at these functions, it's = not clear to me why we need both. The doc comments for both say "free the H= MAC context". http://gerrit.openvpn.net/c/openvpn/+/798/comment/ea9a9a5f_e4e2916c : PS4, Line 83: } We could check label_len and context_len too: * label_len <=3D 250 (because the total length including prefix must be <= =3D 255) * context_len <=3D 255 http://gerrit.openvpn.net/c/openvpn/+/798/comment/b32d3125_e4ee1228 : PS4, Line 86: /* 2 byte for the outlen encoded as uint16, 5 bytes for "= ovpn " */ : int hkdf_label_len =3D 2 + 5 + label_len + context_len; : struct buffer hkdf_label =3D alloc_buf_gc(hkdf_label_len,= &gc); : : : buf_write_u16(&hkdf_label, out_len); : buf_write(&hkdf_label, "ovpn ", 5); : buf_write(&hkdf_label, label, label_len); : if (context_len > 0) : { : buf_write(&hkdf_label, context, context_len); : } That's not exactly how this works. When an RFC specifies a variable-length = array, it has to be prefixed with a fixed-size length field. In this case, = the maximum length for label and context is 255 each, so the length fields = are 1 byte. See RFC 1832. That means hkdf_label_len =3D 2 + 1 + 5 + label_len + 1 + context_len. The label needs to be prefixed with label_len + 5 (the prefix is counted), = the context is prefixed with context_len. Otherwise, the inputs would be ambiguous: label =3D "abcdef", context =3D "= " and label =3D "abc", context =3D "def" would give the same result. -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/798?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: I3a1c6561f4d9a69e2a441d49dff620b4258a1bcc Gerrit-Change-Number: 798 Gerrit-PatchSet: 4 Gerrit-Owner: plaisthos Gerrit-Reviewer: MaxF Gerrit-Reviewer: flichtenheld Gerrit-CC: openvpn-devel Gerrit-Attention: plaisthos Gerrit-Attention: flichtenheld Gerrit-Comment-Date: Wed, 20 Nov 2024 16:48:24 +0000 Gerrit-HasComments: Yes Gerrit-Has-Labels: Yes Gerrit-MessageType: comment --YmFy/BVmmFA= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

Attention is currently required from: flichtenheld, plaisthos.

Patch set 4:Code-Review -2=

Vi= ew Change

5 comments:

  • Patchset:

    • Patch Set #4:

      The implementation of HKDF-Expand is correct,= but the implementation of HKDF-Expand-Label is slightly wrong in a way tha= t causes different (label, context) pairs to produce identical keys (in a p= redictable way).

      Another thing: Are there any plans to actually use the context argument= ?

  • File src/openvp= n/crypto_epoch.h:

    • = Patch Set #4, Line 32:

       *  - salt is always assumed to be =
      zero length (ie not supported)
      * - IKM (secret) is assumed to be alway= s 32 bytes

      salt and IKM are arguments for HKDF-Extract, not HKDF-= Expand.

  • File src/= openvpn/crypto_epoch.c:

    • = Patch Set #4, Line 67:

          hmac_ctx_cleanup(hmac_ctx)=
      ;
      hmac_ctx_free(hmac_ctx);

      Not exactly about this commit i= tself, but looking at these functions, it's not clear to me why we need= both. The doc comments for both say "free the HMAC context".

      =
    • Patch Set #4, Line 83: }

      We could check label_len and context_len too:

      • labe= l_len <=3D 250 (because the total length including prefix must be <= =3D 255)
      • context_len <=3D 255
    • Patch Set #= 4, Line 86:

          /* 2 byte for the outlen encoded as uint16=
      , 5 bytes for "ovpn " */
      int hkdf_label_len =3D 2 + 5 + la= bel_len + context_len;
      struct buffer hkdf_label =3D alloc_buf_gc(hkd= f_label_len, &gc);


      buf_write_u16(&hkdf_label, out_le= n);
      buf_write(&hkdf_label, "ovpn ", 5);
      buf_wri= te(&hkdf_label, label, label_len);
      if (context_len > 0)
      = {
      buf_write(&hkdf_label, context, context_len);
      }

      That's not exactly how this works. When an RFC specifies a var= iable-length array, it has to be prefixed with a fixed-size length field. I= n this case, the maximum length for label and context is 255 each, so the l= ength fields are 1 byte. See RFC 1832.

      That means hkdf_label_len =3D 2 + 1 + 5 + label_l= en + 1 + context_len.

      The label needs to be prefixed with label_len + 5 (the prefix is c= ounted), the context is prefixed with context_len.

      Otherwise, the inputs would be ambigu= ous: label =3D "abcdef", context =3D "" and label =3D &= quot;abc", context =3D "def" would give the same result.

      =

To view, visit change 798. To unsubscribe, or for help wr= iting mail filters, visit se= ttings.

<= div itemscope itemprop=3D"action" itemtype=3D"http://schema.org/ViewAction"= >
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I3a1c6561f4d9a69e2a441d49dff= 620b4258a1bcc
Gerrit-Change-Number: 798
Gerrit-PatchSet: 4
Gerrit-Owner: plaisthos <arne-openvpn@...1711...= 27...>
Gerrit-Reviewer: MaxF <max@...2606...> <= /div>
Gerrit-Reviewer: flichtenheld <frank@...2716...= 1...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
Gerrit-Attention: plaisthos <arne-openvpn@...220...= ..1227...>
Gerrit-Attention: flichtenheld <frank@...2375...= 41...>
Gerrit-Comment-Date: Wed, 20 Nov 2024 16:48:24= +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Gerrit-MessageType: comment
--YmFy/BVmmFA=--