How to use the cryptographic API (e.g. md5 checksum)?

Arvid Brodin arvid.brodin at enea.com
Mon May 23 18:43:50 EDT 2011


Hi,

I want to perform an md5 checksum on a process' text segment (I create a file
/proc/<pid>/text_checksum that, when read, should give the md5sum).

The crypto api documentation (Documentation/crypto/api-intro.txt) seems to be
quite lacking. The only example is:

	tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC);
	if (IS_ERR(tfm))
		fail();
                
        /* ... set up the scatterlists ... */

	desc.tfm = tfm;
	desc.flags = 0;
        
	if (crypto_hash_digest(&desc, sg, 2, result))
		fail();
        
	crypto_free_hash(tfm);

Looking at some existing code, I see usage of crypto_hash_init(),
crypto_hash_final(), desc.flag set to CRYPTO_TFM_REQ_MAY_SLEEP,
... (e.g. in fs/ecryptfs/crypto.c). Does anybody know what they do? Do I need
to, or should I, use them? The functions are are declared in include/linux/crypto.h
as some kind of wrapper functions, but lack documentation. Also, Google has not
been my friend here.

Thanks,
Arvid Brodin
Enea Services Stockholm AB



More information about the Kernelnewbies mailing list