<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>26950</bug_id>
          
          <creation_ts>2014-10-02 04:14:15 +0000</creation_ts>
          <short_desc>Default HMAC keys should be output length, not block length</short_desc>
          <delta_ts>2014-10-22 21:32:38 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>Web Cryptography</product>
          <component>Web Cryptography API Document</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Richard Barnes">rlb</reporter>
          <assigned_to name="Ryan Sleevi">sleevi</assigned_to>
          <cc>public-webcrypto</cc>
    
    <cc>watsonm</cc>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>112553</commentid>
    <comment_count>0</comment_count>
    <who name="Richard Barnes">rlb</who>
    <bug_when>2014-10-02 04:14:15 +0000</bug_when>
    <thetext>Currently the HMAC Operations section for generateKey requires the default key length to be equal to the block size of the underlying hash algorithm.
https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#hmac-operations

RFC 2104, which defines HMAC, says that there&apos;s no point to having keys longer than the *output* length of the hash (L):
&quot;&quot;&quot;
   Keys longer than L bytes are acceptable but the extra
   length would not significantly increase the function strength.
&quot;&quot;&quot;
http://tools.ietf.org/html/rfc2104#section-3

The block length is typically much larger than the output length.  In the case of SHA-256, for example, the block length is 512 bits.  In order to avoid wasting bytes, the default key length for WebCrypto should be the output length of the hash.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>112608</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2014-10-02 21:23:03 +0000</bug_when>
    <thetext>From Jeff Walton:

&quot;Another reason this could cause problems is SHA3. Its a recursive hash
function, and not an iterative hash with  block size.&quot;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>112609</commentid>
    <comment_count>2</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2014-10-02 21:23:57 +0000</bug_when>
    <thetext>I think this is just a mistake and it should indeed be the output length.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>112612</commentid>
    <comment_count>3</comment_count>
    <who name="Ryan Sleevi">sleevi</who>
    <bug_when>2014-10-02 22:05:34 +0000</bug_when>
    <thetext>(In reply to Richard Barnes from comment #0)
&gt; Currently the HMAC Operations section for generateKey requires the default
&gt; key length to be equal to the block size of the underlying hash algorithm.
&gt; https://dvcs.w3.org/hg/webcrypto-api/raw-file/tip/spec/Overview.html#hmac-
&gt; operations
&gt; 
&gt; RFC 2104, which defines HMAC, says that there&apos;s no point to having keys
&gt; longer than the *output* length of the hash (L):
&gt; &quot;&quot;&quot;
&gt;    Keys longer than L bytes are acceptable but the extra
&gt;    length would not significantly increase the function strength.
&gt; &quot;&quot;&quot;
&gt; http://tools.ietf.org/html/rfc2104#section-3
&gt; 
&gt; The block length is typically much larger than the output length.  In the
&gt; case of SHA-256, for example, the block length is 512 bits.  In order to
&gt; avoid wasting bytes, the default key length for WebCrypto should be the
&gt; output length of the hash.

Can you describe what you mean by &quot;wasting&quot; bytes. The terminology implies a particular assumption about usage.

Keys longer than B are compressed to L bytes (through an iteration of the hash), and keys less than L are dangerous. 

The choice of language was not accidental, and reflect the discussions within SP800-107 r1 (5.3.4 and 5.3.5). In these cases, the &apos;maximum&apos; effective security strength for HMAC-SHA1/SHA-256/SHA-512 is 2C (where C = L, see the spec).

If one generates a key of size L, it&apos;s effectively a key at half the length.

The choice of using B, rather than L, was to generalize this across all constructions. Yes, there is limited value where B &gt; 2C, but there is value with B &gt; L, with all included hash functions having L &lt;= C</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>113606</commentid>
    <comment_count>4</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2014-10-22 21:32:38 +0000</bug_when>
    <thetext>Closing as per conf call discussion.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>