gcry_md_open gcry_md_enable gcry_md_close create and destroy a message digest context #include <gcrypt.h> GCRY_MD_HD gcry_md_open int algo unsigned int flags void gcry_md_enable GCRY_MD_HD h int algo void gcry_md_close GCRY_MD_HD h Description hash functions gcry_md_open hash functions gcry_md_enable hash functions gcry_md_close gcry_md_open creates the context required for the message digest functions. The hash algorithm may optionally be specified. It is possible to use these functions as MAC functons; therefore the flag gcry_md_setkey function. gcry_md_close releases all resources associated with the context. gcry_md_enable may be used to enable hash algorithms. This function may be used multiple times to create a hash context for multiple algorithms. Adding an already enabled algorithm has no effect. A algorithm must be enabled prios to calculate hash algorithms. gcry_md_copy create and copy of a message digest context #include <gcrypt.h> GCRY_MD_HD gcry_md_copy GCRY_MD_HD h Description hash functions gcry_md_copy gcry_md_copy creates an excat copy of the given context. This is useful to calculate hashes with a common initial part of the plaintext. gcry_md_reset reset a message digest context #include <gcrypt.h> void gcry_md_reset GCRY_MD_HD h Description hash functions gcry_md_reset gcry_md_reset is used to reuse a message context without the overhead of an open and close operation. gcry_md_ctl gcry_md_final gcry_md_setkey perform special operations on a digest context #include <gcrypt.h> int gcry_md_ctl GCRY_MD_HD h int cmd unsigned char * buffer size_t buflen Description hash functions gcry_md_ctl gcry_md_ctl is a multi-purpose function to control the behaviour of all gcry_md functions or one instance of it. Currently defined values for cmd are: GCRYCTL_FINALIZE and the convenience macro gcry_md_final(a) GCRYCTL_SET_KEY and the convenience macro gcry_md_setkey(a). This is used to turn these hash functions into MAC functions. The key may be any string of the speicified length. The type of the MAC is determined by special flags set with the open function. NEW: There is now a function to do this gcry_md_write gcry_md_putc calculate the message digest of a buffer #include <gcrypt.h> int gcry_md_write GCRY_MD_HD h unsigned char * buffer size_t buflen int gcry_md_putc GCRY_MD_HD h int c Description hash functions gcry_md_write hash functions gcry_md_putc gcry_md_write is used to actually calulate the message digest of a buffer. This function updates the internal state of the message digest. gcry_md_putc is a macro which is used to update the message digest by one byte. this is the preferred way to calculate a digest if only a few bytes at a time are available. gcry_md_read read out the message digest #include <gcrypt.h> unsigned char * gcry_md_read GCRY_MD_HD h int algo Description hash functions gcry_md_read hash functions gcry_md_putc gcry_md_read returns the message digest after finalizing the calculation. This function may be used as often as required but it will alwas return the same value for one handle. The returned message digest is allocated within the message context and therefore valid until the conext is released. algo may be given as 0 to return the only enbaled message digest or it may specify one of the enabled algorithms. The function will return NULL if the algorithm has not been enabled. gcry_md_info get information about a handle #include <gcrypt.h> int gcry_md_info GCRY_MD_HD h int what void * buffer size_t buflen Description hash functions gcry_md_info gcry_md_info returns some information about the handle or an global parameter. The only defined value for what is GCRYCTL_IS_SECURE to return whether the handle has been allocated in secure memory. Buffer and buflen are not needed in this cases. The convenience macro gcry_md_is_secure(a) may be also used for this purpose. gcry_md_algo_info gcry_md_test_algo gcry_md_get_algo_dlen get information about an algorithm #include <gcrypt.h> int gcry_md_algo_info int algo int what void * buffer size_t buflen unsigned int gcry_md_get_algo_dlen int algo Description hash functions gcry_md_algo_info gcry_md_algo_info returns some information about an algorithm. On error the value -1 is return and a more detailed error description is available with gcry_errno. The defined values for what are GCRYCTL_TEST_ALGO to return whether the algorithm is supported. Buffer and buflen are not needed in this cases. The convenience macro gcry_md_test_algo(a) may be used for this purpose. GCRYCTL_GET_ASNOID to return whether the ASN.1 object identifier. IF buffer is specified as NULL, only the required length for the buffer is returned. hash functions gcry_md_get_algo_dlen gcry_md_get_algo_dlen returns the length of the digest for a given algorithm in bytes. gcry_md_algo_name gcry_md_map_name map algorithm to string #include <gcrypt.h> const char * gcry_md_algo_name int algo int gcry_md_map_name const char*name Description hash functions gcry_md_algo_name hash functions gcry_md_map_name These both functions are used to map a string with the algorithm name to the internal algorithm identifier value and vice versa. gcry_md_algo_name never returns NULL even in cases where the algorithm string is not available. Instead a string consisting of a single question mark is returned. Do not use this function to test for the existence of an algorithm. gcry_md_map_name returns 0 if the algorithm is not known to &libgcrypt;. gcry_md_hash_buffer fast message calculation #include <gcrypt.h> int gcry_md_hash_buffer int algo char * digest const char * buffer size_t buflen Description hash functions gcry_md_hash_buffer gcry_md_hash_buffer is a shortcut function to calculate a message digest of a buffer. This function does not require a context and immediatley returns the message digest. digest must be string large enough to hold the digest given by algo. This length may be obtained by using the function gcry_md_get_algo_dlen but in most cases it will be a statically allocated buffer.