<?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 — Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
		<link>https://www.wolfssl.com/forums/topic2008-using-wceccmulmod-function-in-wolfssl-produces-some-errors.html</link>
		<atom:link href="https://www.wolfssl.com/forums/feed-rss-topic2008.xml" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Using wc_ecc_mulmod() function in wolfssl produces some errors.]]></description>
		<lastBuildDate>Thu, 11 May 2023 13:04:59 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7119.html#p7119</link>
			<description><![CDATA[<p>Hi Zihao, </p><p>You&#039;re very welcome. We&#039;d still love to have a chat.&nbsp; If you have a chance, please send me a meeting invite to anthony@wolfssl.com. </p><p>Warm regards, Anthony</p>]]></description>
			<author><![CDATA[null@example.com (anthony)]]></author>
			<pubDate>Thu, 11 May 2023 13:04:59 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7119.html#p7119</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7118.html#p7118</link>
			<description><![CDATA[<p>Hello anthony,<br />Thank you very much for your enthusiastic help recently, my problem has been solved, due to my lack of mathematical knowledge and carelessness, the calculation of ra3 = ra1*ra2 mod prime is problematic, ra3 = ra1*ra2 mod order is correct<br />Reference: <a href="https://stackoverflow.com/questions/76207352/using-wc-ecc-mulmod-function-in-wolfssl-produces-some-errors">https://stackoverflow.com/questions/762 … ome-errors</a><br />Thank you again for your concern and help recently.<br />Wang Zihao</p>]]></description>
			<author><![CDATA[null@example.com (wangzihao)]]></author>
			<pubDate>Thu, 11 May 2023 03:18:35 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7118.html#p7118</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7115.html#p7115</link>
			<description><![CDATA[<p>Hi Wang Zihao, </p><p>Thank you for confirming you got the same result.&nbsp; <br />Unfortunately, I don&#039;t think I got any message from you.&nbsp; <br />Did you send it to anthony@wolfssl.com ? </p><p>Can you please re-send to that address? </p><p>Warm regards, Anthony</p>]]></description>
			<author><![CDATA[null@example.com (anthony)]]></author>
			<pubDate>Wed, 10 May 2023 15:41:33 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7115.html#p7115</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7114.html#p7114</link>
			<description><![CDATA[<p>Hello anthony,<br />&nbsp; &nbsp; &nbsp; The result of my program is the same as yours, I sent you an email, thank you very much.<br /> Wang Zihao</p>]]></description>
			<author><![CDATA[null@example.com (wangzihao)]]></author>
			<pubDate>Wed, 10 May 2023 13:57:42 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7114.html#p7114</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7110.html#p7110</link>
			<description><![CDATA[<p>Hi Wangzihao, </p><p>How are you? We would love to get on a call with you to better understand how you are using wolfSSL. Would you be open to such a call? Don&#039;t worry about potential language issues. I can speak Mandarin. Please let me know. </p><p>Warm regards, Anthony</p>]]></description>
			<author><![CDATA[null@example.com (anthony)]]></author>
			<pubDate>Tue, 09 May 2023 21:38:44 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7110.html#p7110</guid>
		</item>
		<item>
			<title><![CDATA[Re: Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7108.html#p7108</link>
			<description><![CDATA[<p>Hi Wangzihao, <br />Thank you very much for using wolfSSL!&nbsp; </p><p>I tried reproducing what you are seeing. Here is what I did : </p><div class="codebox"><pre><code>cd wolfssl
git checkout master
./autogen.sh 
./configure --enable-static --enable-sp-math-all --enable-opensslall
make all
make check 
sudo make install</code></pre></div><p>I then copied the code supplied in your post into a file called `forum.c` and did the following: </p><div class="codebox"><pre><code>g++ forum.cpp /usr/local/lib/libwolfssl.a  -o forum
./forum</code></pre></div><p>Here are the results I got: </p><br /><div class="codebox"><pre><code>get mp_int af: 0
get mp_int bf: 0
get mp_int prime: 0
get mp_int order: 0
get mp_int ra: 0
get mp_int s: 0
get ecc_point pointG: 0
point is on curve: 0
n3*G: 0
n1*G: 0
n2*B: 0
A is equal to C: 0
get mp_int ra1: 0
get mp_int ra2: 0
ra3*G: 0
ra1*G: 0
ra2*E: 0
D is equal to F: -1</code></pre></div><br /><p>Is this what you are seeing as well?&nbsp; </p><p>I will need to confer with my colleagues. Please stay tuned. </p><p>Warm regards, Anthony</p>]]></description>
			<author><![CDATA[null@example.com (anthony)]]></author>
			<pubDate>Tue, 09 May 2023 13:41:51 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7108.html#p7108</guid>
		</item>
		<item>
			<title><![CDATA[Using wc_ecc_mulmod() function in wolfssl produces some errors]]></title>
			<link>https://www.wolfssl.com/forums/post7107.html#p7107</link>
			<description><![CDATA[<p>When I use the wc_ecc_mulmod() function to perform calculations, some errors will occur. Ra1 and ra2 are two 32-bit random numbers, and G is the generator of the elliptic curve. The calculation (ra1ra2)G is not equal to ra1(ra2G). I noticed that when using wc_ecc_mulmod, the number cannot exceed the number of digits of the large prime number modulus, but I just need the product of two large prime numbers (ra1a2) , and then multiplied by the generator G. I did a test, ra3 = ra1ra2 mod prime, ra3G!=ra1(ra2G), is there any other way for wolfssl to achieve (ra1ra2)G= ra1(ra2*G) ? when ra1 and ra2 are relatively small numbers, there is no problem. For example, point A and point C in the following code are equal.thank you very much<br /></p><div class="codebox"><pre><code>#include &lt;iostream&gt;
#include &lt;string&gt;
#include &lt;unistd.h&gt;
#include &lt;wolfssl/options.h&gt;
#include &lt;wolfssl/wolfcrypt/settings.h&gt;
#include &lt;wolfssl/ssl.h&gt;
#include &lt;wolfssl/wolfcrypt/types.h&gt;
#include &lt;wolfssl/wolfcrypt/random.h&gt;
#include &lt;wolfssl/wolfcrypt/ecc.h&gt;
#include &lt;wolfssl/wolfcrypt/sp_int.h&gt;
#include &lt;wolfssl/wolfcrypt/integer.h&gt;
#include &lt;wolfssl/wolfcrypt/wolfmath.h&gt;
#include &lt;wolfssl/wolfcrypt/sha.h&gt;
#include &lt;wolfssl/wolfcrypt/error-crypt.h&gt;
#include &lt;wolfssl/wolfcrypt/hash.h&gt;
#include &lt;wolfssl/wolfcrypt/asn.h&gt;
#include &lt;wolfssl/wolfcrypt/aes.h&gt;

using namespace std;

int main(){
ecc_key key;
int ret;
WC_RNG rng;
wc_ecc_init(&amp;key);
wc_InitRng(&amp;rng);
int curveId = ECC_SECP256R1;
int keySize = wc_ecc_get_curve_size_from_id(curveId);
ret = wc_ecc_make_key_ex(&amp;rng, keySize, &amp;key, curveId);

//get param of ecc curve
mp_int a,b,prime,order,ra,s;
mp_init_multi(&amp;a,&amp;b,&amp;prime,&amp;order,&amp;ra,&amp;s);
ret = mp_read_radix(&amp;a,key.dp-&gt;Af,16);
cout&lt;&lt;&quot;get mp_int af: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = mp_read_radix(&amp;b,key.dp-&gt;Bf,16);
cout&lt;&lt;&quot;get mp_int bf: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = mp_read_radix(&amp;prime,key.dp-&gt;prime,16);
cout&lt;&lt;&quot;get mp_int prime: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = mp_read_radix(&amp;order,key.dp-&gt;order,16);
cout&lt;&lt;&quot;get mp_int order: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_gen_k(&amp;rng,32,&amp;ra,&amp;order);
cout&lt;&lt;&quot;get mp_int ra: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = mp_copy(&amp;key.k,&amp;s);
cout&lt;&lt;&quot;get mp_int s: &quot;&lt;&lt;ret&lt;&lt;endl;

ecc_point* pointG = wc_ecc_new_point();
ret = wc_ecc_get_generator(pointG,wc_ecc_get_curve_idx(ECC_SECP256R1));
cout&lt;&lt;&quot;get ecc_point pointG: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_is_point(pointG,&amp;a,&amp;b,&amp;prime);
cout&lt;&lt;&quot;point is on curve: &quot;&lt;&lt;ret&lt;&lt;endl;

//tes1:n1 = 10,n2 = 33,n3 = n1*n2, A = n3*G,B = n2*G,C = n1*B=&gt; A == C
mp_int n1,n2,n3;
mp_init_multi(&amp;n1,&amp;n2,&amp;n3,NULL,NULL,NULL);
mp_set_int(&amp;n1,10);
mp_set_int(&amp;n2,33);
ret = mp_mulmod(&amp;n1,&amp;n2,&amp;prime,&amp;n3);
ecc_point* A = wc_ecc_new_point();
ecc_point* B =wc_ecc_new_point();
ecc_point* C =wc_ecc_new_point();
ret = wc_ecc_mulmod(&amp;n3,pointG,A,&amp;a,&amp;prime,1);
cout&lt;&lt;&quot;n3*G: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_mulmod(&amp;n1,pointG,B,&amp;a,&amp;prime,1);
cout&lt;&lt;&quot;n1*G: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_mulmod(&amp;n2,B,C,&amp;a,&amp;prime,1);
cout&lt;&lt;&quot;n2*B: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_cmp_point(A,C);
cout&lt;&lt;&quot;A is equal to C: &quot;&lt;&lt;ret&lt;&lt;endl;

//test2:ra1,ra2 are big number ra3 = ra1*ra2, D = ra3*G,E = ra2*G,F = ra1*E=&gt; D != F
mp_int ra1,ra2,ra3;
mp_init_multi(&amp;ra1,&amp;ra2,&amp;ra3,NULL,NULL,NULL);
ret = wc_ecc_gen_k(&amp;rng,32,&amp;ra1,&amp;order);
cout&lt;&lt;&quot;get mp_int ra1: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_gen_k(&amp;rng,32,&amp;ra2,&amp;order);
cout&lt;&lt;&quot;get mp_int ra2: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = mp_mulmod(&amp;ra1,&amp;ra2,&amp;prime,&amp;ra3);
ecc_point* D = wc_ecc_new_point();
ecc_point* E =wc_ecc_new_point();
ecc_point* F =wc_ecc_new_point();
ret = wc_ecc_mulmod(&amp;ra3,pointG,D,&amp;a,&amp;prime,1);
cout&lt;&lt;&quot;ra3*G: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_mulmod(&amp;ra1,pointG,E,&amp;a,&amp;prime,1);
cout&lt;&lt;&quot;ra1*G: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_mulmod(&amp;ra2,E,F,&amp;a,&amp;prime,1);
cout&lt;&lt;&quot;ra2*E: &quot;&lt;&lt;ret&lt;&lt;endl;
ret = wc_ecc_cmp_point(D,F);
cout&lt;&lt;&quot;D is equal to F: &quot;&lt;&lt;ret&lt;&lt;endl;
return 0;

}</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (wangzihao)]]></author>
			<pubDate>Tue, 09 May 2023 08:45:14 +0000</pubDate>
			<guid>https://www.wolfssl.com/forums/post7107.html#p7107</guid>
		</item>
	</channel>
</rss>
