<div dir="ltr"><br><div class="gmail_quote">---------- Forwarded message ----------<br>From: <b class="gmail_sendername">gnu cry</b> <span dir="ltr"><<a href="mailto:gcrypt4@gmail.com">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">gnupg-users@gnupg.org</a><br><br><br><div dir="ltr"><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><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 #00F2271E305679EBF9D7673FBF75EEA22E90D100A9E0B5DE30C500411E91710D05826F17F2C33A9527CC6799553C626C015ED666F63A4D5CEB27CDBE61F34DB0AF#)\n"
" )\n"
" )\n"
" (private-key\n"
" (ecc\n"
" (curve NIST P-521)\n"
" (d #00BC9D8FD5D0AC1C91C04A1E0A5B6A89229924AAD20E23C5F5E3FE702C3C4633E325D2084DC0CE2005A88FF0512E0CACC271DF3279865DC2C33FCF573F7788278E#)\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); // calculate Q=dG
}</code></pre></div></div>
</div><br></div>