<div dir="ltr"><div>Salam Werner,</div><div>Thank you for your answer</div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Dec 7, 2017 at 4:46 PM, gnu cry <span dir="ltr"><<a href="mailto:gcrypt4@gmail.com" target="_blank">gcrypt4@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><br><div class="gmail_quote"><div><div class="h5">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">gnu cry</b> <span dir="ltr"><<a href="mailto:gcrypt4@gmail.com" target="_blank">gcrypt4@gmail.com</a>></span><br>Date: Thu, Dec 7, 2017 at 12:23 PM<br>Subject: Elliptic curve point multiplication with libgcrypt<br>To: <a href="mailto:gnupg-users@gnupg.org" target="_blank">gnupg-users@gnupg.org</a><br><br><br></div></div><div dir="ltr"><div><div class="h5"><div>Hi gpg hackers!<br><br>I want to implement an elliptic curve point multiplication (Q=dG) operation with libgcrypt. I attach my code but my program doesn't work and it has many errors. I comment the workflow of my program in the attached code.<br>my question is how do you implement Q=dG in C with libgcrypt? any idea about my mistakes and how should I fix them?<br><br></div>Thanks<br></div></div><div><br><pre><code><br></code></pre><pre><code><br><br></code></pre><pre>//ec.c<br></pre><pre><code>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gcrypt.h>
//select and insert key and curve parameters
char *key521 =
"(key-data\n"
" (public-key\n"
" (ecc\n"
" (curve NIST P-521)\n"
" (q #<wbr>00F2271E305679EBF9D7673FBF75EE<wbr>A22E90D100A9E0B5DE30C500411E91<wbr>710D05826F17F2C33A9527CC679955<wbr>3C626C015ED666F63A4D5CEB27CDBE<wbr>61F34DB0AF#)\n"
" )\n"
" )\n"
" (private-key\n"
" (ecc\n"
" (curve NIST P-521)\n"
" (d #<wbr>00BC9D8FD5D0AC1C91C04A1E0A5B6A<wbr>89229924AAD20E23C5F5E3FE702C3C<wbr>4633E325D2084DC0CE2005A88FF051<wbr>2E0CACC271DF3279865DC2C33FCF57<wbr>3F7788278E#)\n"
" )\n"
" )\n"
"\n )";
// workflow for calculating of Q=dG
int main() {
gcry_check_version(NULL);
gcry_mpi_point_t Q,G; //define and hold two elliptic curve point
gcry_mpi_point_release(G);
gcry_mpi_t d; //define the scalar (d)
gcry_sexp_t dsex; //define an S-expression variable
gcry_sexp_sscan(&dsex, NULL, key521, strlen(key521)); //set dsex = d in key521 data structure
gcry_sexp_release(dsex);
d= gcry_sexp_nth_mpi(dsex, 1, GCRYMPI_FMT_USG); // convert from S-exp to MPI format
char curvename= "NIST P-521"; //define curve name
gcry_ctx_t context; //define a context (ctx)
gcry_mpi_ec_new(context, dsex, curvename); //set context
gcry_ctx_release(context);
gcry_mpi_ec_mul(Q,d,G,context)<wbr>; // calculate Q=dG
}</code></pre></div></div>
</div><br></div>
</blockquote></div><br></div>