<signed_datafeed_article>
<datafeed_article>
<datafeed_name>edgecase_datafeed</datafeed_name>
<datafeed_article_id>232</datafeed_article_id>
<date>2021-11-17
<note>This is the date at the time of creation of this datafeed article. A checkpoint article containing a hash of this datafeed article may be created on this date or at a later date.</note>
</date>
<previous_checkpoint>
<datafeed_article_id>215</datafeed_article_id>
<checkpoint_id>10</checkpoint_id>
<date>2021-04-10</date>
<transaction>
<blockchain_name>bitcoin</blockchain_name>
<transaction_id>fe062b308ad6254b71ae4af5bbe8ec485105ebb9ae9cf1b905b115f596dd827a</transaction_id>
<block_height>678607</block_height>
<source_address>1HtwyqFWNVDoSEVqZwjBRRAV2oEsi8aQXr</source_address>
<source_address>13MfGs39pR5aEK4iKdoLjVYXKwi6Y3uyPq</source_address>
<destination_address>1Hdv9WprSk5ugh12TpsLvEt6tfdSmnz1SG</destination_address>
</transaction>
</previous_checkpoint>
<signed_article>
<article>
<title>ECDSA_Deterministic_Signing</title>
<author_name>nicholas_piano_2</author_name>
<date>2021-09-19</date>
<signed_by_author>yes</signed_by_author>
<content>


<heading_lines>
Introduction
</heading_lines>

The ECDSA signature scheme requires fresh, high-quality entropy for each signature generation. This presents two problems:
1. The availability of a source of high-quality entropy for signing
2. The inability of automated tests to verify that a signature was created using sufficiently high-quality entropy

The solution is to use a deterministic method of the producing the required entropy. That is, an entropy value that is a pure function of the data to be signed. The required value for each signing operation is commonly known as <code>k</code>.

Firstly, non-deterministic ECDSA signing will be discussed, followed by the deterministic variant and some of its disadvantages.


<heading_lines>
Non-deterministic signing
</heading_lines>

Signature generation begins with a randomly chosen point on an elliptic curve. This point is calculated by using a random value <code>k</code>, starting from a known generator point <code>G</code>. The first part of the signature <code>r</code> is simply:

<code_lines>
r = kG
</code_lines>

This equation relies on elliptic curve arithmetic. <code>r</code> represents the x-coordinate of the resulting point on the curve. The second part of the signature <code>s</code> is calculated as follows:

<code_lines>
s = (k^-1) * (H(M) + r * secret)
</code_lines>

Where:
1. <code>H(M)</code> is the hash of the message <code>M</code> converted to an integer
2. <code>secret</code> is the secret key of the signer

The concatenation of the two values <code>r</code> and <code>s</code> is the signature.

Given two messages signed using the same secret key and the same nonce <code>k</code> (hence the same <code>r</code>), the secret key can be recovered as follows:

<code_lines>
h1 = H(M1)
h2 = H(M2)

secret = (s2 * h1 + s1 * h2) / [r * (s1 + s2)]
</code_lines>

It is therefore imperative that a different nonce <code>k</code> be used for each signature.


<heading_lines>
Deterministic signing
</heading_lines>

The objective of deterministic signing is to avoid the need to generate a new value <code>k</code> for each operation. In short, the means of doing this involves combining the secret key with the hash of the message, yielding a value that cannot be known unless the secret key is known.

Note: This does provide less security than using a fresh value for <code>k</code>. 1 unknown highly-random value (the secret) is technically easier to guess than 2 unknown highly-random values (the secret and the random k value).


<bold_lines>
Algorithm
</bold_lines>

According to RFC6979, the steps to generate a value <code>k</code> from the message and secret are as follows:

1. Hash the message

<code_lines>
h1 = H(M)
</code_lines>

2. Begin first initialisation of <code>V</code> and <code>K</code> parameters

- Initialise <code>V</code> to all 1s equal to the length of the hash

<code_lines>
V = 0x01 0x01 0x01 ... 0x01
</code_lines>

For SHA-256, this equates to 32 octets set to 1.

- Initialise <code>K</code> to all 0s equal to the length of the hash

<code_lines>
K = 0x00 0x00 0x00 ... 0x00
</code_lines>

3. Begin second initialisation

- Set the value of
<code>K = HMAC_K(V || 0x00 || int2octets(secret) || bits2octets(h1))</code>

Where:
<indent_lines>
- <code>HMAC_K</code> is the HMAC function using the same hash as step (1) with key <code>K</code>
- <code>||</code> denotes concatenation
</indent_lines>

- Set the value of <code>V = HMAC_K(V)</code>

4. Begin third initialisation

- Set the value of
<code>K = HMAC_K(V || 0x01 || int2octets(secret) || bits2octets(h1))</code>

Only the second concatenation, <code>0x01</code> has changed.

- Set the value of <code>V = HMAC_K(V)</code>

5. Begin main loop

- Set <code>T</code> to an empty sequence such that the length of <code>T</code> is 0
- While <code>length(T) \< length(secret)</code>:
<indent_lines>
  - <code>V = HMAC_K(V)</code>
  - <code>T = T || V</code>
</indent_lines>

6. Finally, <code>k = bits2int(T)</code>

7. If the value of <code>k</code> is not within the range <code>[1, secret-1]</code> (i.e. the value of <code>r</code> is 0), the following should be run:

- <code>K = HMAC_K(V || 0x00)</code>
- <code>V = HMAC_K(V)</code>
- Return to step (4)

It should be noted that, while possible, this scenario is vanishingly unlikely to occur.


<heading_lines>
Conclusion
</heading_lines>

The deterministic signing scheme can be used in place of the normal signing schema for ECDSA.


<heading_lines>
Sources
</heading_lines>

<link>
<type>hyperlink</type>
<reference>http://github.com/tlsfuzzer/python-ecdsa/blob/c7b5e063447e5d67acc61ec35d9521fa0fce7a24/src/ecdsa/keys.py#L1346-L1407</reference>
<text>github.com/tlsfuzzer/python-ecdsa/blob/c7b5e063447e5d67acc61ec35d9521fa0fce7a24/src/ecdsa/keys.py#L1346-L1407</text>
</link>

<link>
<type>hyperlink</type>
<reference>http://medium.com/@simonwarta/signature-determinism-for-blockchain-developers-dbd84865a93e</reference>
<text>medium.com/@simonwarta/signature-determinism-for-blockchain-developers-dbd84865a93e</text>
</link>

<link>
<type>hyperlink</type>
<reference>http://datatracker.ietf.org/doc/html/rfc6979</reference>
<text>datatracker.ietf.org/doc/html/rfc6979</text>
</link>

<link>
<type>hyperlink</type>
<reference>http://billatnapier.medium.com/ecdsa-weakness-where-nonces-are-reused-2be63856a01a</reference>
<text>billatnapier.medium.com/ecdsa-weakness-where-nonces-are-reused-2be63856a01a</text>
</link>




</content>
</article>
<author_signature>
iQIcBAABAgAGBQJhiYWRAAoJED8P6ID17071OwMP/AuN5weoG0YGH1R8Kc3S2cPm
h46prD5yL/96l3bBLrV9QwU4sa3c3aaBGiwDOt/EkLzDS65Q38uAubcjR5T7Jq7M
PDG0BRLluTskJPw2ZY0h/petLxTngdSeOAfip4RN45xpoEn6M6DNyIbj2+VTKgfi
hseS1ljFwpwfoQIpDM3OKr69iFwy0Dpnm8FgV0qZ34J4hnFhAIeOMZrYrzjrquUk
nZ7fLMTK9dZJcsdElGXqt1GLhBXr41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3CrKRXGsV
9Bwd9Vw+ENNvx/mxVsQdJBU1mf1UQ50KMqgo9F9rtZL/KPzNuwzVOEt0YVMsdrSw
sJUulX36fabk7Zdf/gE6Ojq2w4Jwi15kG/fZEHWMU2vI19c2qdFQXE3ah4YxYsIl
pbOjB7k1robnCTqcqIGE
=BYFg
</datafeed_signature>
</signed_datafeed_article>