Question about key generation

Andrey Mozharovskiy amzh at hushmail.com
Mon Jan 16 10:24:06 CET 2017


Just to make sure, did I ask this in the right mailing list?

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, 

	                        "(genkeyn" 

	                        " (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 =
gcry_sexp_sprint(pubkey,GCRYSEXP_FMT_ADVANCED,NULL,0); 

	    char *buffer_publ = (char*)
gcry_malloc(length_publ*sizeof(char)); 

	    size_t offset_publ =
gcry_sexp_sprint(pubkey,GCRYSEXP_FMT_ADVANCED,buffer_publ,length_publ);

	    gcry_sexp_t privkey = gcry_sexp_find_token(key, "private-key",
0); 

	    size_t length_priv =
gcry_sexp_sprint(privkey,GCRYSEXP_FMT_ADVANCED,NULL,0); 

	    char *buffer_priv = (char*)
gcry_malloc(length_priv*sizeof(char)); 

	    size_t offset_priv =
gcry_sexp_sprint(privkey,GCRYSEXP_FMT_ADVANCED,buffer_priv,length_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
#00B30C503943A56EBD82AEC5A8CFDC49563BBD3A7E3938973F7642BAC50CA4CC26917B9DD7BF6840CF310EFB3910EE166312BA38FE8B0AC987FD2DF8D55342B6378AA49061C302A1776B897CC11A0D08558C4C0E6C1A86E7CD8A858A2D6786C29577829B8401A2DBEF8FA106F98195ED98B9745F7BC8B02048B1DBA33D12E78DC1E34F0C59E4205C8EEB5C6E0926DFD560E9EB36D42C3161FCA5C92D9C1AE64795C68D312C167803A685709C52D9FFF7914FCF1143BF9134A6ED0F30525A83DD950979D61098F953C70C2D91998F886B403295D82837BF0C9664842D92E94404A606882C326A44802E105574A7754EF073C9DC4B7593E7D429AD33DA9B5276A705#)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/7310978d/attachment.html>


More information about the Gnupg-devel mailing list