LibGCrypt Examples
kingruedi
cplusplushelp@gmx.net
Wed, 17 Apr 2002 23:40:17 +0200
> You can disable it with:
>
> gcry_control( GCRYCTL_DISABLE_SECMEM_WARN )
>
> or you can set your program set uid. It's the same with the
> GNU Privacy Guard, to use the secure memory you need root privileges.
now it works! But the output doesn't look like a md5 checksum :(
here is my source
#include <gcrypt.h>
#include <stdio.h>
int main(int argc,char **argv)
{
GCRY_MD_HD md5;
FILE *fd;
unsigned char buffer[500];
size_t len;
int a;
if(argc<2)
{
fprintf(stderr,"usage: %s <file>\n",*argv);
return 1;
}
if( (fd=fopen(*(argv+1),"r")) ==NULL)
{
perror("Couldn't open file!\n");
return 1;
}
gcry_control( GCRYCTL_DISABLE_SECMEM_WARN );
gcry_control( GCRYCTL_INIT_SECMEM, 16384, 0 );
md5=gcry_md_open(GCRY_MD_MD5,GCRY_MD_FLAG_HMAC);
if( (len=fread(buffer,sizeof(unsigned char),500,fd)) ==0)
{
if(ferror(fd))
{
perror("Couldn't read file!\n");
return 1;
}
}
gcry_md_write(md5,buffer,len); /*<-- this should create the checksum*/
printf("%s\n",buffer);
gcry_md_close(md5);
return 0;
}
sorry that I ask this simple questions but I didn't understood the reference