title: Using the Crypto API in the Linux Kernel on a file
body: <p>I have been trying to use the crypto api in the linux kernel, what i need to do is sha a file that is being opened.  I am using the LSM to catch those file opens.  </p>
  
  <p>What I have so far is creating a struct crypto_shash using</p>
  
  <pre><code>struct crypto_shash *tfm;
  struct shash_desc desc;
  tfm = crypto_alloc_shash("sha1", 0, CRYPTO_ALG_ASYNC);
  </code></pre>
  
  <p>and i assume i am supposed to init it after that using </p>
  
  <pre><code>desc.tfm = tfm;
  desc.flags = 0;
  
  err = crypto_shash_init(&amp;desc);
  </code></pre>
  
  <p>that all works fine, but then i want to use </p>
  
  <pre><code>crypto_shash_digest(&amp;desc, ??, ??, sha_hash);
  </code></pre>
  
  <p>and i realize that it expects a scatterlist as its second argument and the length of that scatter list as the third argument.  What i cant figure out is how I am supposed to load the file into a scatterlist in order to give it to the crypto system.</p>
  
  <p>I have done quite a bit of reading but have thus far been unable to find any details about getting a files contents loaded into a scatterlist. So any pointers in the right direction would be appreciated.</p>
  
  <p>Thanks</p>