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

[CRYPTO] aead: Add top-level givencrypt/givdecrypt calls

This patch finally makes the givencrypt/givdecrypt operations available
to users by adding crypto_aead_givencrypt and crypto_aead_givdecrypt.
A suite of helpers to allocate and fill in the request is also available.

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

+67
+67
include/crypto/aead.h
··· 15 15 16 16 #include <linux/crypto.h> 17 17 #include <linux/kernel.h> 18 + #include <linux/slab.h> 18 19 19 20 /** 20 21 * struct aead_givcrypt_request - AEAD request with IV generation ··· 34 33 struct aead_givcrypt_request *req) 35 34 { 36 35 return crypto_aead_reqtfm(&req->areq); 36 + } 37 + 38 + static inline int crypto_aead_givencrypt(struct aead_givcrypt_request *req) 39 + { 40 + struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req)); 41 + return crt->givencrypt(req); 42 + }; 43 + 44 + static inline int crypto_aead_givdecrypt(struct aead_givcrypt_request *req) 45 + { 46 + struct aead_tfm *crt = crypto_aead_crt(aead_givcrypt_reqtfm(req)); 47 + return crt->givdecrypt(req); 48 + }; 49 + 50 + static inline void aead_givcrypt_set_tfm(struct aead_givcrypt_request *req, 51 + struct crypto_aead *tfm) 52 + { 53 + req->areq.base.tfm = crypto_aead_tfm(tfm); 54 + } 55 + 56 + static inline struct aead_givcrypt_request *aead_givcrypt_alloc( 57 + struct crypto_aead *tfm, gfp_t gfp) 58 + { 59 + struct aead_givcrypt_request *req; 60 + 61 + req = kmalloc(sizeof(struct aead_givcrypt_request) + 62 + crypto_aead_reqsize(tfm), gfp); 63 + 64 + if (likely(req)) 65 + aead_givcrypt_set_tfm(req, tfm); 66 + 67 + return req; 68 + } 69 + 70 + static inline void aead_givcrypt_free(struct aead_givcrypt_request *req) 71 + { 72 + kfree(req); 73 + } 74 + 75 + static inline void aead_givcrypt_set_callback( 76 + struct aead_givcrypt_request *req, u32 flags, 77 + crypto_completion_t complete, void *data) 78 + { 79 + aead_request_set_callback(&req->areq, flags, complete, data); 80 + } 81 + 82 + static inline void aead_givcrypt_set_crypt(struct aead_givcrypt_request *req, 83 + struct scatterlist *src, 84 + struct scatterlist *dst, 85 + unsigned int nbytes, void *iv) 86 + { 87 + aead_request_set_crypt(&req->areq, src, dst, nbytes, iv); 88 + } 89 + 90 + static inline void aead_givcrypt_set_assoc(struct aead_givcrypt_request *req, 91 + struct scatterlist *assoc, 92 + unsigned int assoclen) 93 + { 94 + aead_request_set_assoc(&req->areq, assoc, assoclen); 95 + } 96 + 97 + static inline void aead_givcrypt_set_giv(struct aead_givcrypt_request *req, 98 + u8 *giv, u64 seq) 99 + { 100 + req->giv = giv; 101 + req->seq = seq; 37 102 } 38 103 39 104 #endif /* _CRYPTO_AEAD_H */