how to use libgcrypt library

Neil Spring
Tue, 22 Jul 2003 20:34:13 -0700

Content-Transfer-Encoding: 7bit
Content-Type: text/plain; charset=ISO-2022-JP; format=flowed


I wrote the following today; you might find it useful, and it seems to 
work.  (I've jumped on the excuse to have folks on the list look it 
over and tell me how to do things differently.)  I'm intentionally 
using a very short key.  There's also a newer, nicer interface in CVS;  
I chose to avoid it and use the existing stuff.

#include <gcrypt.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>

int main (int argc, char **argv) {
   static const char message[] = "hello";
   GcrySexp gen_parms, sign_parms, keypair, pubkey, skey, sig;
   size_t errof=0;
   int rc;

   gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
   /* shortest key I could find */
   rc = gcry_sexp_build (&gen_parms, &errof, "(genkey (rsa (nbits 
   assert(rc == 0);
   rc = gcry_pk_genkey(&keypair, gen_parms);
   assert(rc == 0);

   skey = gcry_sexp_find_token(keypair, "private-key", 0);
   pubkey = gcry_sexp_find_token(keypair, "public-key", 0);
   assert(skey != NULL);
   assert(pubkey != NULL);

   rc = gcry_sexp_build (&sign_parms, &errof,
                         "(data (flags) (value \"%s\"))\n", message);
   assert(rc == 0);

   rc = gcry_pk_sign (&sig, sign_parms, skey);
   assert(rc == 0);

   rc = gcry_pk_verify (sig, sign_parms, pubkey);
   if(rc != 0) {
     printf("verify returns error %d: %s\n", rc, gcry_strerror(rc));


On Tuesday, July 22, 2003, at 08:19  PM, 李真 wrote:

> Hi,how to use libgcrypt library?
> I have already install it in /usr/local/bin directory on a Linux OS.I 
> want to use signature and signature verify function to integrate into 
> my network-security programm.But i find not a complete example using 
> signature.
> In /src/basic.c,it can correctly compile and run it.But when i change
> plaintext,its output is to modify it ,then i use it in my 
> programm?
> And ,i think basic.c is not very good for using,for its interface is 
> complicated for user's programm.As far as i am concerned, i hope 
> libgcrypt library can provide a lot of complete function such as 
> signature(,,), signatureverify(,,). So,i can easily intergrate it into 
> my programm.
> Do you know where have the complete example using libgcrypt?
> Thanks in advance!
> Zen
> _______________________________________________
> Gcrypt-devel mailing list

content-type: application/pgp-signature; x-mac-type=70674453;
content-disposition: inline
content-transfer-encoding: 7bit

Version: GnuPG v1.2.2 (Darwin)