Elliptic curve point multiplication with libgcrypt

gnu cry gcrypt4 at gmail.com
Fri Dec 8 12:55:10 CET 2017


Salam Werner,
Thank you for your answer


On Thu, Dec 7, 2017 at 4:46 PM, gnu cry <gcrypt4 at gmail.com> wrote:

>
> ---------- Forwarded message ----------
> From: gnu cry <gcrypt4 at gmail.com>
> Date: Thu, Dec 7, 2017 at 12:23 PM
> Subject: Elliptic curve point multiplication with libgcrypt
> To: gnupg-users at gnupg.org
>
>
> Hi gpg hackers!
>
> 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.
> my question is how do you implement Q=dG in C with libgcrypt? any idea
> about my mistakes and how should I fix them?
>
> Thanks
>
>
>
>
> //ec.c
>
> #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
>
> }
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20171208/d60c33c4/attachment.html>


More information about the Gnupg-users mailing list