Digital Powers
Digital Powers

Reputation: 470

Using the Crypto API in the Linux Kernel on a file

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.

What I have so far is creating a struct crypto_shash using

struct crypto_shash *tfm;
struct shash_desc desc;
tfm = crypto_alloc_shash("sha1", 0, CRYPTO_ALG_ASYNC);

and i assume i am supposed to init it after that using

desc.tfm = tfm;
desc.flags = 0;

err = crypto_shash_init(&desc);

that all works fine, but then i want to use

crypto_shash_digest(&desc, ??, ??, sha_hash);

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.

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.

Thanks

Upvotes: 2

Views: 1969

Answers (1)

Dan Kruchinin
Dan Kruchinin

Reputation: 3055

I have done something similar some time ago. The only difference is that I calculated a hash of ELF sections.

  1. Probably your desc.flags should be CRYPTO_TFM_REQ_MAY_SLEEP until you have really good reason to prevent crypto operation from blocking.
  2. Are you sure you didn't confuse crypto_shash_digest with crypto_hash_digest? Because crypto_*s*hash_digest() receives a pointer to data as its 3rd argument. If it's not true for you, what linux kenrel version are you talking about?

Upvotes: 2

Related Questions