I am trying to extract data (that is about to be written) from a Bio (Block I/O) structure in linux. I want to get the MD5 hash of the raw data. My strategy was to map the part of the data I wanted to a new page I allocated in memory. Then I would use a pointer to that new spot as an input to a crypto-function. However, I have no found any good examples of how to use these crypto functions and my strategy is not working. Can anyone help? Here is the code:

void fingerprint(struct bio * bio, unsigned char * result)
    struct page * page;
    int total;
    struct scatterlist sg[1];

    struct hash_desc desc = {
        .tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC),
        .flags = 0
    total = 0;

    page = alloc_page(GFP_KERNEL);
    memset(kmap(page), 0, bio->bi_io_vec[0].bv_len);

    memcpy(kmap(page), kmap(bio->bi_io_vec[0].bv_page), bio->bi_io_vec[0].bv_len);

    sg_init_one(&sg, (u8 *)page, bio->bi_io_vec[0].bv_len);
    crypto_hash_digest(&desc, sg, 1, result);
    total += bio->bi_io_vec[0].bv_len;