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

int main(int argc, char **argv){

	printf("argc: %d\n", argc);
	printf("argv[1] len: %lu argv[1] str: %s\n", strlen(argv[1]), argv[1] );
	
//	return 0;
	gcry_error_t error_val;
	size_t length;
	void *digest;
	//GCRY_MD_SHA256  = 8
	int algo = GCRY_MD_SHA256;
	size_t buf_length = strlen(argv[1]);
//	char *myword;
//	int counter1;

//	myword = malloc(sizeof(char)*buf_length);
//	strcpy(myword, argv[1]);

	const void *buffer = argv[1];

	printf("test\n");
	//const char GCRYPT_VERSION = 140;

       /* Version check should be the very first call because it
          makes sure that important subsystems are intialized. */
       if (!gcry_check_version (GCRYPT_VERSION))
         {
           fputs ("libgcrypt version mismatch\n", stderr);
           exit (2);
         }
     
       /* Disable secure memory.  */
       gcry_control (GCRYCTL_DISABLE_SECMEM, 0);
     
       /* ... If required, other initialization goes here.  */
     
       /* Tell Libgcrypt that initialization has completed. */
       gcry_control (GCRYCTL_INITIALIZATION_FINISHED, 0);

	printf("done\n");

	//create context
	//gcry_error_t gcry_md_open (gcry_md_hd_t *hd, int algo, unsigned int flags)

	//get length for message digest
	length = gcry_md_get_algo_dlen (algo);
	digest = malloc(sizeof(char)*length);

	//calculate message digest
	gcry_md_hash_buffer (algo, digest, buffer, buf_length);


	printf("sha256: %s\n", digest);



	return 1;
}
