Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

crypto: doc - Use ahash

This patch replaces the crypto_hash example in api-intro.txt with
crypto_ahash.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

+14 -9
+14 -9
Documentation/crypto/api-intro.txt
··· 49 49 50 50 Here's an example of how to use the API: 51 51 52 - #include <linux/crypto.h> 52 + #include <crypto/ahash.h> 53 53 #include <linux/err.h> 54 54 #include <linux/scatterlist.h> 55 55 56 56 struct scatterlist sg[2]; 57 57 char result[128]; 58 - struct crypto_hash *tfm; 59 - struct hash_desc desc; 58 + struct crypto_ahash *tfm; 59 + struct ahash_request *req; 60 60 61 - tfm = crypto_alloc_hash("md5", 0, CRYPTO_ALG_ASYNC); 61 + tfm = crypto_alloc_ahash("md5", 0, CRYPTO_ALG_ASYNC); 62 62 if (IS_ERR(tfm)) 63 63 fail(); 64 64 65 65 /* ... set up the scatterlists ... */ 66 66 67 - desc.tfm = tfm; 68 - desc.flags = 0; 69 - 70 - if (crypto_hash_digest(&desc, sg, 2, result)) 67 + req = ahash_request_alloc(tfm, GFP_ATOMIC); 68 + if (!req) 71 69 fail(); 70 + 71 + ahash_request_set_callback(req, 0, NULL, NULL); 72 + ahash_request_set_crypt(req, sg, result, 2); 72 73 73 - crypto_free_hash(tfm); 74 + if (crypto_ahash_digest(req)) 75 + fail(); 76 + 77 + ahash_request_free(req); 78 + crypto_free_ahash(tfm); 74 79 75 80 76 81 Many real examples are available in the regression test module (tcrypt.c).