<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ECDSA signature reproducibility</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/49032/ecdsa-signature-reproducibility</link><description>Our device is based on nRF52840 with SDK 15.0.0 
 The device communicates over BLE with PC application (aka client) via &amp;quot;uart&amp;quot; service. 
 PC (client) messages are signed using ECDSA with secp265r1 curve and the device verifies the signature of received</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 27 Jun 2019 11:41:17 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/49032/ecdsa-signature-reproducibility" /><item><title>RE: ECDSA signature reproducibility</title><link>https://devzone.nordicsemi.com/thread/195119?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 11:41:17 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:64d61b96-6346-4a64-b301-6422d98e008a</guid><dc:creator>yes</dc:creator><description>&lt;p&gt;Regarding curve both sides is configured to secp256r1 curve&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;PC side:&lt;/p&gt;
&lt;p&gt;private static ECDsa LoadPrivateKey(byte[] key)&lt;br /&gt; {&lt;br /&gt; var privKeyInt = new Org.BouncyCastle.Math.BigInteger(+1, key);&lt;br /&gt; var parameters = SecNamedCurves.GetByName(&amp;quot;&lt;strong&gt;secp256r1&lt;/strong&gt;&amp;quot;);&lt;br /&gt; var ecPoint = parameters.G.Multiply(privKeyInt);&lt;br /&gt; var privKeyX = ecPoint.Normalize().XCoord.ToBigInteger().ToByteArrayUnsigned();&lt;br /&gt; var privKeyY = ecPoint.Normalize().YCoord.ToBigInteger().ToByteArrayUnsigned();&lt;/p&gt;
&lt;p&gt;var d = privKeyInt.ToByteArrayUnsigned();&lt;br /&gt; return ECDsa.Create(new ECParameters&lt;br /&gt; {&lt;br /&gt; Curve = ECCurve.NamedCurves.nistP256,&lt;br /&gt; D = privKeyInt.ToByteArrayUnsigned(),&lt;br /&gt; Q = new ECPoint&lt;br /&gt; {&lt;br /&gt; X = privKeyX,&lt;br /&gt; Y = privKeyY&lt;br /&gt; }&lt;br /&gt; });&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;for device side:&lt;/p&gt;
&lt;p&gt;/*static*/ bool&lt;br /&gt;bIsValidSignature(const uint8_t* a_ipHashMessage, const uint8_t* a_ipSignature, uint8_t* a_ipEcdsaPublicKey)&lt;br /&gt;// Brief: verify signature&lt;br /&gt;// Get: a_ipHashMessage - message&lt;br /&gt;// a_ipSignature - signature&lt;br /&gt;// a_ipEcdsaPublicKey - public key&lt;br /&gt;// Return: true if successful, false otherwise&lt;br /&gt;// Pre: -&lt;br /&gt;// Post: signature verified&lt;br /&gt;// Method: Trivial&lt;br /&gt;{&lt;br /&gt; // swap endian&lt;br /&gt; // ~~~~~~~~~~~&lt;br /&gt; uint8_t l_iaPkCopy[d_iAuthPubKeySize];&lt;br /&gt; &lt;strong&gt;nrf_crypto_internal_double_swap_endian(l_iaPkCopy, a_ipEcdsaPublicKey, d_iAuthPubKeySize / 2);&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;// ecc public key from raw&lt;br /&gt; // ~~~~~~~~~~~~~~~~~~~~~~~&lt;br /&gt; nrf_crypto_ecc_public_key_t l_uPublicKey;&lt;br /&gt; if (NRF_SUCCESS != nrf_crypto_ecc_public_key_from_raw(&amp;amp;&lt;strong&gt;g_nrf_crypto_ecc_secp256r1_curve_info&lt;/strong&gt;, &amp;amp;l_uPublicKey, l_iaPkCopy, d_iAuthPubKeySize))&lt;br /&gt; {&lt;br /&gt; LOG_WARNING(LOG_PRINT_CRYPTO, &amp;quot;Crypto - verify signature - failed - ecc public key from raw&amp;quot;);&lt;br /&gt; return false;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;// verify the message using ECDSA and SHA-256&lt;br /&gt; // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;br /&gt; if (NRF_SUCCESS != nrf_crypto_ecdsa_verify(NULL, &amp;amp;l_uPublicKey, a_ipHashMessage, d_iAuthHashSize, a_ipSignature, d_iAuthSigLen))&lt;br /&gt; {&lt;br /&gt; LOG_WARNING(LOG_PRINT_CRYPTO, &amp;quot;Crypto - verify signature - failed - ECDSA verify&amp;quot;);&lt;br /&gt; return false;&lt;br /&gt; }&lt;/p&gt;
&lt;p&gt;return true;&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Regarding endianness:&lt;/p&gt;
&lt;p&gt;Device code swaps it before verifying&lt;/p&gt;
&lt;p&gt;PC run on Win 10 which is little endian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ECDSA signature reproducibility</title><link>https://devzone.nordicsemi.com/thread/195111?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 11:28:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f103cd56-af5f-4211-b3e8-080d05d7f2d7</guid><dc:creator>tesc</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;Have you double checked that you use the correct curve in both ends, and that you have not introduced any errors when copying the keys e.g. due to endianness or how they are otherwise encoded?&lt;/p&gt;
&lt;p&gt;Regards,&lt;br /&gt;Terje&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: ECDSA signature reproducibility</title><link>https://devzone.nordicsemi.com/thread/195068?ContentTypeID=1</link><pubDate>Thu, 27 Jun 2019 09:24:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ae8cd9b2-11ad-4e8a-878b-e576f37ad143</guid><dc:creator>yes</dc:creator><description>&lt;p&gt;The reason for different signatures is the random number which is generated for each cycle as part of the Alice&amp;#39;s signing process&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>