<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[wolfSSL - Embedded SSL Library — ECC signing and verify]]></title>
		<link>https://www.wolfssl.com/forums/topic1640-ecc-signing-and-verify.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic1640.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in ECC signing and verify.]]></description>
		<lastBuildDate>Thu, 03 Dec 2020 07:53:07 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5603.html#p5603</link>
			<description><![CDATA[<p>Thanks David, this solved it </p><br /><p>(I feel a little ashamed, I should have seen that)</p><p>Vitus</p>]]></description>
			<author><![CDATA[null@example.com (Vitus)]]></author>
			<pubDate>Thu, 03 Dec 2020 07:53:07 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5603.html#p5603</guid>
		</item>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5596.html#p5596</link>
			<description><![CDATA[<p>Hi Vitus,</p><p>I see your bug. In the sign.c see this line `if ((ret = wc_ecc_sign_hash(hash, sizeof(hash), signature, signature_size, &amp;rng, &amp;key)) != 0)`. You are using `sizeof(hash)` and it should be `hash_size`.</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Wed, 02 Dec 2020 16:12:14 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5596.html#p5596</guid>
		</item>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5595.html#p5595</link>
			<description><![CDATA[<p>Can only attach 1 file at a time, here is screen shot 2 mentioned in last post</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Wed, 02 Dec 2020 16:06:32 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5595.html#p5595</guid>
		</item>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5594.html#p5594</link>
			<description><![CDATA[<p>@Vitus,</p><p>One thing I noted, you are building on windows which does not support &lt;wolfssl/options.h&gt;. &lt;wolfssl/options.h&gt; is for use on *NIX systems where the ./configure script was run and options.h was auto-generated.</p><p>On windows please replace all occurrances of &lt;wolfssl/options.h&gt; with:</p><div class="codebox"><pre><code>#include &lt;wolfssl/wolfcrypt/settings.h&gt;
#ifndef WOLFSSL_USER_SETTINGS
    #error &quot;Sanity Check: Please add the PreProcessor setting WOLFSSL_USER_SETTINGS to the project&quot;
#endif</code></pre></div><p>If the above sanity check is seen please right-click on the project in the solution explorer window and open &quot;Properties&quot; -&gt;C/C++ -&gt; &quot;Preprocessor&quot; -&gt; &quot;Preprocessor Definitions&quot; and add &quot;WOLFSSL_USER_SETTINGS&quot; to the project pre-processor settings. (See attached screen shot 1)</p><p>If you then get an error about &quot;user_settings.h&quot; not being found go to &quot;Properties&quot; -&gt;C/C++ -&gt; &quot;General&quot; -&gt; &quot;Additional Include Directories&quot; and add a path to &quot;C:\path-to-wolfssl-root\IDE\WIN&quot; where the windows user_settings.h header resides. (See attached screen shot 2)</p><p>Warm Regards,</p><p>K</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Wed, 02 Dec 2020 16:05:49 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5594.html#p5594</guid>
		</item>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5593.html#p5593</link>
			<description><![CDATA[<p>Hi,</p><p>the code I posted was a sort of&nbsp; compressed summary. I did not want to overload the forum (and overload the patience of the readers) by attaching a Visual studio project here. Actually I have created a sub project in the wolfssl64.sln project and there I checked all return codes from the wc_xxx() calls,dumped the results, included &lt;wolfssl/options.h&gt; and more, and (hopefully) did the passing by reference correctly. This looked all ok, besides the result of the last wc_ecc_verify_hash(...) . I attach the sub-project folder, could be placed in the \wolfssl-4.5.0\ directory and added to the sln<br />I only posted my problem here in the forum because maybe there would be an obvious thinking errror in the code which someone in the community can immediately spot and point me to.</p><p>I will check the last argument in wc_EccPublicKeyToDer()<br />I also will look into wolfcrypt/test/test.c, the routine crypto_ecc_verify()</p><p>Goal of the project is to evaluate the WolfSSL stack for usage in embedded devices in our company, and the signature is just one first part. I will soon (today) have a meeting with WolfSSL to make contact.</p>]]></description>
			<author><![CDATA[null@example.com (Vitus)]]></author>
			<pubDate>Wed, 02 Dec 2020 06:56:23 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5593.html#p5593</guid>
		</item>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5588.html#p5588</link>
			<description><![CDATA[<p>Hi Vitus,</p><p>The last argument to `wc_EccPublicKeyToDer` is &quot;with_AlgCurve&quot; is a flag for when to include a header that has the Algorithm and Curve information&quot;. You should have it set to 1. Also you are not checking the return code from wc_EccPublicKeyDecode in the &quot;verify&quot; function.</p><p>You might find the wolfcrypt/test/test.c examples for `crypto_ecc_verify` and `crypto_ecc_sign` helpful. Those are around line 21646.</p><p>Thanks,<br />David Garske, wolfSSL</p>]]></description>
			<author><![CDATA[null@example.com (dgarske)]]></author>
			<pubDate>Tue, 01 Dec 2020 17:15:41 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5588.html#p5588</guid>
		</item>
		<item>
			<title><![CDATA[Re: ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5586.html#p5586</link>
			<description><![CDATA[<p>Hi @Vitus,</p><p>Can you tell us a bit about your project and what the end goals are? This helps us to better qualify the inquiry, thank you!</p><br /><p>Can you double check that &lt;wolfssl/options.h&gt; is included in any .c source files running wolfSSL operations BEFORE all other wolfSSL headers? This ensures the application and library have the same settings. If this does not resolve the issue you are seeing let us know and we can dig deeper.</p><p>Warm Regards,</p><p>K</p><p>P.S. take care to pass by REFERENCE when buffer is going to be updated with new values and those values need to persist beyond scope of the called function. A simple sanity check:</p><p>1) Run the app before it is split up, dump out buffer contents and relevant size values<br />2) Run the app after it is split up, dump out buffer contents and relevant sizes FROM MAIN ONLY.<br />3) Do the buffers contain the expected information in case 2 and are the relevant length values correct?</p>]]></description>
			<author><![CDATA[null@example.com (Kaleb J. Himes)]]></author>
			<pubDate>Tue, 01 Dec 2020 17:11:04 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5586.html#p5586</guid>
		</item>
		<item>
			<title><![CDATA[ECC signing and verify]]></title>
			<link>https://www.wolfssl.com/forums/post5585.html#p5585</link>
			<description><![CDATA[<p>Hi,</p><p>I have looked into ECC signature, especially into the example at \wolfssl-examples-master\signature\ecc-sign-verify. This compiles and runs. In the example a key is produced and with this key signing and subsequent verification is done. I wanted to have it more realistic, so that the key generation, the code signing and the verification are separated from each others. <br />So I splitted this into 4 independent files &quot;keymake&quot;, &quot;sign&quot;, &quot;verify&quot; and a &quot;main&quot;&nbsp; (here for simplicity put together). in &quot;keymake&quot; I generated &quot;der&quot; data for the public key and the private key , in &quot;sign&quot; I signed a hash, in &quot;validate&quot; I validated the signature, and in &quot;main&quot; I call all three others, taking care that these others only know what they need to know. </p><br /><p>(condensed) code is:</p><p>//some stuff, used separately in all modules, here&nbsp; put in one place for simplicity<br />#define BYTE_SZ 8<br />static ecc_key key;&nbsp; &nbsp;//got stack corruption when I use it as a local var<br />static WC_RNG rng;</p><p>//creates a key and corresponding public and private der data<br />int keymake(&nbsp; int eccKeySz,&nbsp; char* der_file_private,&nbsp; int* der_file_private_size,<br />&nbsp; char* der_file_public,&nbsp; int* der_file_public_size)<br />{<br />&nbsp; int ret;<br />&nbsp; int verified = 0;<br />&nbsp; int byteField = (512 + (BYTE_SZ - 1)) / BYTE_SZ;</p><p>&nbsp; wolfCrypt_Init();<br />&nbsp; ret = wc_ecc_init(&amp;key);<br />&nbsp; ret = wc_InitRng(&amp;rng);<br />&nbsp; ret = wc_ecc_make_key(&amp;rng, byteField, &amp;key);<br />&nbsp; *der_file_private_size = wc_EccPrivateKeyToDer(&amp;key, der_file_private, *der_file_private_size);<br />&nbsp; //???? what is parameter 4 ?<br />&nbsp; *der_file_public_size = wc_EccPublicKeyToDer(&amp;key, der_file_public, *der_file_public_size, ECC_SECP256R1);<br />}</p><p>//creates a signature of a hash using private der data<br />int sign(&nbsp; char* hash,&nbsp; int hash_size,&nbsp; char* der_file_private,&nbsp; int der_file_private_size,<br />&nbsp; char* signature,&nbsp; int* signature_size)<br />{<br />&nbsp; int ret;<br />&nbsp; wc_ecc_init(&amp;key);<br />&nbsp; word32 idx = 0;<br />&nbsp; wc_EccPrivateKeyDecode(der_file_private, &amp;idx, &amp;key, der_file_private_size);<br />&nbsp; ret = wc_InitRng(&amp;rng);<br />&nbsp; ret = wc_ecc_sign_hash(hash, sizeof(hash), signature, signature_size, &amp;rng, &amp;key);<br />}</p><p>//verifies a signature of a hash using public der data<br />int verify(&nbsp; char* hash,&nbsp; int hash_size,&nbsp; char* der_file_public,&nbsp; int der_file_public_size,<br />&nbsp; char* signature,&nbsp; int signature_size)<br />{<br />&nbsp; int ret;<br />&nbsp; int verified = 0;<br />&nbsp; word32 idx = 0;<br />&nbsp; wc_ecc_init(&amp;key);&nbsp; //set up a new one<br />&nbsp; ret = wc_EccPublicKeyDecode(der_file_public, &amp;idx, &amp;key, der_file_public_size);<br />&nbsp; ret = wc_ecc_verify_hash(signature, signature_size, hash, hash_size, &amp;verified, &amp;key);<br />&nbsp; if ((ret != 0) || verified != 1) { printf(&quot;verification failed\n&quot;); return(-1)}<br />&nbsp; return(0);<br />}</p><p>int main(int argc, char** argv)<br />{<br />&nbsp; unsigned char hash[32] = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0x3b, 0x07, 0x54, 0x5c, 0xfd, 0x4f, 0xb7, 0xb5,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0xaf, 0xa7, 0x7a, 0x25, 0x33, 0xa5, 0x50, 0x70,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0x4a, 0x65, 0x3e, 0x72, 0x7e, 0xcd, 0xd4, 0x5b,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0x1b, 0x36, 0x96, 0x96, 0xca, 0x4f, 0x9b, 0x6f<br />&nbsp; };<br />&nbsp; byte der_file_private[1000];<br />&nbsp; int der_file_private_size = 1000;<br />&nbsp; byte der_file_public[1000];<br />&nbsp; int&nbsp; der_file_public_size = 1000;<br />&nbsp; byte signature[ECC_MAX_SIG_SIZE];<br />&nbsp; int signature_size = ECC_MAX_SIG_SIZE;</p><p>&nbsp; int ret;</p><p>&nbsp; ret = keymake(256, der_file_private, &amp;der_file_private_size, der_file_public, &amp;der_file_public_size);<br />&nbsp; ret = sign(hash, sizeof(hash), der_file_private, der_file_private_size, signature, &amp;signature_size);<br />&nbsp; ret = verify(hash, sizeof(hash), der_file_public, der_file_public_size, signature, signature_size);<br />&nbsp; printf(&quot;verify ret=%i\n&quot;, ret);<br />}</p><p>All this compiles, runs, there are no run time errors, but the last thing in verify(),&nbsp; wc_ecc_verify_hash(signature, signature_size, hash, hash_size, &amp;verified, &amp;key), returns a 0 in &quot;verified&quot;, failing the whole thing.</p><p>Can anyone of the people who do that all the time point me to my mistake? The only change to the (working) \wolfssl-examples-master\signature\ecc-sign-verify example&nbsp; is that I tried to create public and private key as &quot;der&quot;-data and use them instead of the generated key. Also, there is the 4th parameter in wc_EccPublicKeyToDer(), which I just guessed as ECC_SECP256R1, This may be an issue.</p>]]></description>
			<author><![CDATA[null@example.com (Vitus)]]></author>
			<pubDate>Tue, 01 Dec 2020 16:29:42 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post5585.html#p5585</guid>
		</item>
	</channel>
</rss>
