Elliptic curve operations

Hassan Mostafa hassan.mostafa87 at gmail.com
Sat Jun 8 01:29:48 CEST 2019


dears,

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.


# include <gcrypt.h>
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# include <gpg-error.h>

# define AM_PATH_LIBGCRYPT
/* # define AM_CPPFLAGS = $(LIBGCRYPT_CFLAGS)
# define LDADD = $(LIBGCRYPT_LIBS) */



int main ()

{

/* Version check */

if (gcry_check_version(GCRYPT_VERSION))

puts ("\nIntialization Succeed\n");

else

{
puts ("libgcrypt version mismatch\n");
exit(2);
}


/* Disable secure memory */

gcry_control(GCRYCTL_DISABLE_SECMEM,0);

/* inform the libgcrypt that the intialization has completed */

gcry_control(GCRYCTL_INITIALIZATION_FINISHED,0);

if (!gcry_control(GCRYCTL_INITIALIZATION_FINISHED_P))

{
puts ("libgcrypt has not been intialized\n");
abort ();
}

/* Allocating new context for EC operations */

gcry_ctx_t my_ctx;
const char *curve = "NIST P-521" ;
gcry_error_t err = 1 ;
err = gcry_mpi_ec_new ( &my_ctx, NULL, curve);

// Displaying the error
puts("Allocating a context for EC operations is");
fputs (gcry_strerror(err), stderr);
puts ("\n");

// get the private key
const char *d = "d-mpi";
int copy1 = 1;
unsigned int x_bits = 0;
gcry_mpi_t x = gcry_mpi_new (x_bits);
x = gcry_mpi_ec_get_mpi(d, my_ctx, copy1);

//displaying the private key

gcry_buffer_t x_buffer;
x_buffer.size = 0;
x_buffer.len = 1024;
unsigned char *x_buffer_name = x_buffer.data;
size_t x_buffer_len = 1024 ;
size_t *x_size;
//unsigned int x_copy_bits = 512;
//gcry_mpi_t x_copy = gcry_mpi_new (x_copy_bits);
//const gcry_mpi_t x_copy = x;
//gcry_mpi_release (x_copy);
gcry_error_t err2 = 0;
err2 = gcry_mpi_print(GCRYMPI_FMT_USG, x_buffer_name, x_buffer_len, x_size,
x);

fputs (gcry_strerror(err2), stderr);
puts ("\n");



//gcry_mpi_release (x_copy);
gcry_ctx_release (my_ctx);
gcry_mpi_release (x);


return 0;

}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.gnupg.org/pipermail/gnupg-users/attachments/20190608/d9536a5d/attachment-0001.html>


More information about the Gnupg-users mailing list