Question about key generation

Andrey Mozharovskiy amzh at
Mon Jan 16 16:34:31 CET 2017

Found the problem.
These gcry_sexp_t are being returned as modulus/exp etc. It's the
modulus part which is the same for both public and private keys.
How do I extract the keys itself?
On 1/14/2017 at 4:45 PM, "Andrey Mozharovskiy"  wrote:Hello,
we're trying to generate a pair of Rsa keys (public/private), using
the latest release of libgcrypt sources,
we're using the following method:
	    gcry_sexp_t keyparm, key; 

	    int rc = -1; 
	    rc = gcry_sexp_new (&keyparm, 


	                        " (rsan" 

	                        "  (nbits 4:2048)n" 

	                        " ))", 0, 1); 

	    if (rc) 

	        return boost::make_tuple("", ""); 
	    rc = gcry_pk_genkey (&key, keyparm); 
	    if (rc) 

	        return boost::make_tuple("", ""); 
	    gcry_sexp_t pubkey = gcry_sexp_find_token(key, "public-key", 0); 

	    size_t length_publ =

	    char *buffer_publ = (char*)

	    size_t offset_publ =

	    gcry_sexp_t privkey = gcry_sexp_find_token(key, "private-key",

	    size_t length_priv =

	    char *buffer_priv = (char*)

	    size_t offset_priv =
	Thus, we now have two keys, problem is they're both exactly identical
each time we generate them..
	E.g. both keys are:
	(char *) buffer_publ = 0x00007fddf0d0f0e0 "(public-key n (rsa n  (n
 (e #010001#)n  )n )n
	(same value for buffer_priv)
	Please clarify, whether we should generate a pair of keys two times
and hence get different keys, or use a different method? 
	Regards, Andrey.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/attachments/20170116/5639edcc/attachment-0001.html>

More information about the Gnupg-devel mailing list