Mailing List Archive

S-Expression help
I'm currently attempting to write a crypto application use gcrypt. At the
moment I am working on attempting to generate an ElGamel key of size 2048
bits.

For some reason I am *always* getting error 45 (GCRYERR_INV_ARG). I have
never worked with s-expressions before, and the 'manual' is less than
helpful.

Code I am using:

GcrySexp *keyExp=NULL;
GcrySexp *keyParms=NULL;
int retVal;

std::string tempString;

std::cout << "Initializing data structures\n";
tempString = "(genkey(elg(nbits 2048)))";
retVal=gcry_sexp_new (keyParms, tempString.c_str(),
tempString.length(), 1);
std::cout <<"Return Value: " << retVal << std::endl;

Please reply by e-mail - I have yet to figure out how to subscribe to this
mailing list.

Thank you for your assistance.

Garrett Kajmowicz
gkajmowi@tbaytel.net
RE: S-Expression help [ In reply to ]
Well, I never got the gcry_sexp_new to work for me, but here is the bit
of code I'm using to generate my key-pair...
(It's in C, but you shouldn't have any trouble translating to C++)

int makeKeyPair (GcrySexp *pKey, GcrySexp *sKey) {
char secKey[] = "private-key";
char pubkey[] = "public-key";
GcrySexp PARMS, Key;
int rcode, nbits = 1024;
size_t keySize;

gcry_control (GCRYCTL_INIT_SECMEM, 16384, 0);

/* Build parameter Sexp 'PARMS' to describe the type of public key
desired (RSA) */
rcode = gcry_sexp_build (&PARMS, NULL, "(genkey(rsa(nbits %d)))",
nbits);
printf ("return code for sexp_new(PARMS) is [%d]\n\n", rcode);

/* Build a public key pair as defined in PARMS */
rcode = gcry_pk_genkey (&Key, PARMS);
printf ("return code for genkey is [%d]\n\n", rcode);
if (rcode) { // failure
printf ("genkey failed - exiting...\n\n");
}

/* return the portion of the key pair that is only the public key */
*pKey = gcry_sexp_find_token (Key, pubkey, strlen (pubkey));
:
:
:
<--snip-->

I'm still having trouble with the basic encrypt/decryption sequence of a
simple (short) string, so if you get a working sequence going from
buffer to encrypted file & back to buffer, I'd love to discuss it with
you! Good luck!
--
Tony Warren
<}-:



-----Original Message-----
From: Garrett Kajmowicz [mailto:gkajmowi@tbaytel.net]
Sent: Monday, June 02, 2003 11:23 AM
To: gcrypt-devel@gnupg.org
Subject: S-Expression help


I'm currently attempting to write a crypto application use gcrypt. At
the
moment I am working on attempting to generate an ElGamel key of size
2048
bits.

For some reason I am *always* getting error 45 (GCRYERR_INV_ARG). I
have
never worked with s-expressions before, and the 'manual' is less than
helpful.

Code I am using:

GcrySexp *keyExp=NULL;
GcrySexp *keyParms=NULL;
int retVal;

std::string tempString;

std::cout << "Initializing data structures\n";
tempString = "(genkey(elg(nbits 2048)))";
retVal=gcry_sexp_new (keyParms, tempString.c_str(),
tempString.length(), 1);
std::cout <<"Return Value: " << retVal << std::endl;

Please reply by e-mail - I have yet to figure out how to subscribe to
this
mailing list.

Thank you for your assistance.

Garrett Kajmowicz
gkajmowi@tbaytel.net


_______________________________________________
Gcrypt-devel mailing list
Gcrypt-devel@gnupg.org
http://lists.gnupg.org/mailman/listinfo/gcrypt-devel
Re: S-Expression help [ In reply to ]
On Mon, 2 Jun 2003 12:22:37 -0400, Garrett Kajmowicz said:

> GcrySexp *keyExp=NULL;
> GcrySexp *keyParms=NULL;

GCrySexp keyParms = NULL;

Define a variable of type GcrySexp and not a pointer tosuch a variable.

> std::cout << "Initializing data structures\n";
> tempString = "(genkey(elg(nbits 2048)))";
> retVal=gcry_sexp_new (keyParms, tempString.c_str(),

retVal=gcry_sexp_new (&keyParms, tempString.c_str(),

i.e. you must pass the address of keyParms to the function. What you
did is the same as

retVal=gcry_sexp_new (NULL, tempString.c_str(),

> Please reply by e-mail - I have yet to figure out how to subscribe to this
> mailing list.

See here:

> http://lists.gnupg.org/mailman/listinfo/gcrypt-devel


hth,

Werner



--
Nonviolence is the greatest force at the disposal of
mankind. It is mightier than the mightiest weapon of
destruction devised by the ingenuity of man. -Gandhi