<?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>27602</bug_id>
          
          <creation_ts>2014-12-13 02:12:07 +0000</creation_ts>
          <short_desc>ECDSA&apos;s Sign operation is not explicit about how r and s are concatenated (padding)</short_desc>
          <delta_ts>2016-05-24 00:07:59 +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>Linux</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</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="Eric Roman">ericroman</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>116249</commentid>
    <comment_count>0</comment_count>
    <who name="Eric Roman">ericroman</who>
    <bug_when>2014-12-13 02:12:07 +0000</bug_when>
    <thetext>The spec says the following:

---------------------
2. Let r and s be the pair of integers resulting from performing the ECDSA signing process.
3. Let result be a new ArrayBuffer.
4. Convert r to a bitstring and append the sequence of bytes to result.
5. Convert s to a bitstring and append the sequence of bytes to result.
---------------------

As I understand &quot;r&quot; and &quot;s&quot; are big integers in big-endian order.

Prior to concatenation r and s must be padded to a fixed length, otherwise when reversing the process during verify() it is unclear unclear how to extract r and s. I believe they should be zero-padded to the group order size in bytes.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116797</commentid>
    <comment_count>1</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2015-01-05 18:03:56 +0000</bug_when>
    <thetext>r and s are just integers in the interval [ 1, n-1 ] where n is the order of the base point G of the elliptic curve.

The ambiguity is in &quot;Convert r/s to a bitstring&quot; since it is not specified what the output bitstring length should be.

I assume it should be the smallest multiple of 8 bits which can represent the value n-1 (I expect this is also what Eric meant in comment #0).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>116867</commentid>
    <comment_count>2</comment_count>
    <who name="Eric Roman">ericroman</who>
    <bug_when>2015-01-07 02:18:27 +0000</bug_when>
    <thetext>Yes, that is along the lines of what I was thinking.

To copy some language from the JWA spec [1] as an example, it says this about ECDSA (P-256):

&quot;
   2.  Turn R and S into octet sequences in big endian order, with each
       array being be 32 octets long.  The octet sequence
       representations MUST NOT be shortened to omit any leading zero
       octets contained in the values.

   3.  Concatenate the two octet sequences in the order R and then S.
&quot;

Except instead of &quot;32 octets&quot; we would say something more general like (also from JWA):

  &quot;ceiling(log-base-2(n)/8) octets (where n is the order of the curve)&quot;



My primary concern for compatibility is being explicit that the leading zeros are mandatory.

Otherwise we could have implementations for which it is sufficient that len(r) == len(s), and not the stronger requirement that len(r) == len(s) == ceiling(log-base-2(n)/8).

Cheers.

[1] https://tools.ietf.org/html/draft-ietf-jose-json-web-algorithms-39#section-6.2.1</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126525</commentid>
    <comment_count>3</comment_count>
    <who name="Mark Watson">watsonm</who>
    <bug_when>2016-05-24 00:07:59 +0000</bug_when>
    <thetext>Moved to https://github.com/w3c/webcrypto/issues/65</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>