S-Expression help

Warren, Tony tonyw@prairiesys.com
Mon, 2 Jun 2003 11:54:26 -0500

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)))",
  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));

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
moment I am working on attempting to generate an ElGamel key of size

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

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
mailing list.

Thank you for your assistance.

Garrett Kajmowicz

Gcrypt-devel mailing list