<div dir="ltr"><div dir="ltr">dears,<div><br></div><div>It's my first time to use this library and I am not a developer. all what I am doing is elliptic curve operations to simulate some EC based algorithms. first of all I wrote the following code to generate a curve and just get the secret key and display it. it gives me segmentation fault 11. please I need an urgent help in this.</div><div><br></div><div><br></div><div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)"># include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><gcrypt.h></span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)"># include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><stdio.h></span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)"># include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><string.h></span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)"># include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><stdlib.h></span><span style="color:rgb(0,0,255)"> </span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)"># include</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(163,21,21)"><gpg-error.h></span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)"># define</span><span style="color:rgb(0,0,255)"> </span><span style="color:rgb(121,94,38)">AM_PATH_LIBGCRYPT</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">/* # define AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS)</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)"># define LDADD = $(LIBGCRYPT_LIBS) */</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">int</span> <span style="color:rgb(121,94,38)">main</span> ()</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">{</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">/* Version check */</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)">if</span> (<span style="color:rgb(121,94,38)">gcry_check_version</span>(GCRYPT_VERSION))</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">puts</span> (<span style="color:rgb(163,21,21)">"</span><span style="color:rgb(255,0,0)">\n</span><span style="color:rgb(163,21,21)">Intialization Succeed</span><span style="color:rgb(255,0,0)">\n</span><span style="color:rgb(163,21,21)">"</span>);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">    <span style="color:rgb(175,0,219)">else</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">    {   </div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">        <span style="color:rgb(121,94,38)">puts</span> (<span style="color:rgb(163,21,21)">"libgcrypt version mismatch</span><span style="color:rgb(255,0,0)">\n</span><span style="color:rgb(163,21,21)">"</span>);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">        <span style="color:rgb(121,94,38)">exit</span>(<span style="color:rgb(9,136,90)">2</span>);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">    }</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">/* Disable secure memory */</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">gcry_control</span>(GCRYCTL_DISABLE_SECMEM,<span style="color:rgb(9,136,90)">0</span>);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">/* inform the libgcrypt that the intialization has completed */</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">gcry_control</span>(GCRYCTL_INITIALIZATION_FINISHED,<span style="color:rgb(9,136,90)">0</span>);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)">if</span> (!<span style="color:rgb(121,94,38)">gcry_control</span>(GCRYCTL_INITIALIZATION_FINISHED_P))</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">    {</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">        <span style="color:rgb(121,94,38)">puts</span> (<span style="color:rgb(163,21,21)">"libgcrypt has not been intialized</span><span style="color:rgb(255,0,0)">\n</span><span style="color:rgb(163,21,21)">"</span>);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">        <span style="color:rgb(121,94,38)">abort</span> ();</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">    }</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">/* Allocating new context for EC operations */</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(38,127,153)">gcry_ctx_t</span> my_ctx;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">const</span> <span style="color:rgb(0,0,255)">char</span> *curve = <span style="color:rgb(163,21,21)">"NIST P-521"</span> ;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(38,127,153)">gcry_error_t</span> err = <span style="color:rgb(9,136,90)">1</span> ;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">err = <span style="color:rgb(121,94,38)">gcry_mpi_ec_new</span> ( &my_ctx, <span style="color:rgb(0,0,255)">NULL</span>, curve);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">// Displaying the error  </span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">puts</span>(<span style="color:rgb(163,21,21)">"Allocating a context for EC operations is"</span>);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">fputs</span> (<span style="color:rgb(121,94,38)">gcry_strerror</span>(err), stderr);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">puts</span> (<span style="color:rgb(163,21,21)">"</span><span style="color:rgb(255,0,0)">\n</span><span style="color:rgb(163,21,21)">"</span>);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">// get the private key</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">const</span> <span style="color:rgb(0,0,255)">char</span> *d = <span style="color:rgb(163,21,21)">"d-mpi"</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">int</span> copy1 = <span style="color:rgb(9,136,90)">1</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">unsigned</span> <span style="color:rgb(0,0,255)">int</span> x_bits = <span style="color:rgb(9,136,90)">0</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(38,127,153)">gcry_mpi_t</span> x = <span style="color:rgb(121,94,38)">gcry_mpi_new</span> (x_bits);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"> x = <span style="color:rgb(121,94,38)">gcry_mpi_ec_get_mpi</span>(d, my_ctx, copy1);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">//displaying the private key</span></div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(38,127,153)">gcry_buffer_t</span> x_buffer;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,16,128)">x_buffer</span>.<span style="color:rgb(0,16,128)">size</span> = <span style="color:rgb(9,136,90)">0</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,16,128)">x_buffer</span>.<span style="color:rgb(0,16,128)">len</span> = <span style="color:rgb(9,136,90)">1024</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">unsigned</span> <span style="color:rgb(0,0,255)">char</span> *x_buffer_name = <span style="color:rgb(0,16,128)">x_buffer</span>.<span style="color:rgb(0,16,128)">data</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">size_t</span> x_buffer_len = <span style="color:rgb(9,136,90)">1024</span> ;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,0,255)">size_t</span> *x_size;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">//unsigned int x_copy_bits = 512;</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">//gcry_mpi_t x_copy = gcry_mpi_new (x_copy_bits);</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">//const gcry_mpi_t x_copy = x;</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">//gcry_mpi_release (x_copy);</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(38,127,153)">gcry_error_t</span> err2 = <span style="color:rgb(9,136,90)">0</span>;</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">err2 = <span style="color:rgb(121,94,38)">gcry_mpi_print</span>(GCRYMPI_FMT_USG, x_buffer_name, x_buffer_len, x_size, x);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">fputs</span> (<span style="color:rgb(121,94,38)">gcry_strerror</span>(err2), stderr);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">puts</span> (<span style="color:rgb(163,21,21)">"</span><span style="color:rgb(255,0,0)">\n</span><span style="color:rgb(163,21,21)">"</span>); </div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">        </div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(0,128,0)">//gcry_mpi_release (x_copy);</span></div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">gcry_ctx_release</span> (my_ctx);</div><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(121,94,38)">gcry_mpi_release</span> (x);</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><span style="color:rgb(175,0,219)">return</span> <span style="color:rgb(9,136,90)">0</span>;</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><div style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre">}</div><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"><br style="color:rgb(0,0,0);font-family:Menlo,Monaco,"Courier New",monospace;font-size:12px;white-space:pre"></div></div></div>