title: ECDSA signature generation using secp256r1 curve (BouncyCastle) giving signature with length 127
body: <p>I am implementing ECDSA signature generation using secp256r1 curve and SHA256 algorithm using BouncyCastle.</p>
  <p>For some of the inputs the signature length is 127 characters long. I feel the &quot;0&quot; at the beginning are getting removed as the signature is stored to BigInteger datatype in ECDSASigner class.</p>
  <p>I have added the sample from rfc6979 <a href="https://www.rfc-editor.org/rfc/rfc6979#page-10" rel="nofollow noreferrer">ECDSA signing using Deterministic Approach</a></p>
  <p>The relevant parts of the code :-</p>
  <pre><code>//Private key used in hex format -C9AFA9D845BA75166B5C215767B1D6934E50C3DB36E89B127B8A622B120F6721
          String secretNumberK = &quot;09F634B188CEFD98E7EC88B1AA9852D734D0BC272F7D2A47DECC6EBEB375AAD4&quot;;
          SecureRandom secureRandom = new FixedSecureRandom(Hex.decode(secretNumber));
          ECPrivateKeyParameters ecPrivateKeySpec = Util.getECPriKeyParameter(ecPrivateKey);//it is the PrivateKey of the sample shown 
          byte[]  messageInHex = Hex.decode(&quot;test&quot;);
          
           ECDSASigner ecdsaSigner = new ECDSASigner();
  
          ecdsaSigner.init(true, new ParametersWithRandom(ecPrivateKeySpec,
                  secureRandom));
  
           BigInteger[]  sig = ecdsaSigner.generateSignature(Util
                  .generateSHAHash(messageInHex));
          flag = true;
          LOG.debug(&quot;r:: &quot; + sig[0].toString(16).toString());
          LOG.debug(&quot;s:: &quot; + sig[1].toString(16).toString());
  </code></pre>
  <p>Expected R and S of Signature as per document:-</p>
  <pre><code> r = 0EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719
   s = 4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954
  </code></pre>
  <p>But Iam getting</p>
  <pre><code>r = EAFEA039B20E9B42309FB1D89E213057CBF973DC0CFC8F129EDDDC800EF7719
  s = 4861F0491E6998B9455193E34E7B0D284DDD7149A74B95B9261F13ABDE940954
  </code></pre>
  <p><strong>The only difference is the zero in the r value. And because of this length of signature is only 127.</strong></p>
  <p>Please let me know if my inference is correct. Is this a bug in Bouncy Castle?</p>