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

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

This patch finally makes the givencrypt/givdecrypt operations available
to users by adding crypto_skcipher_givencrypt and crypto_skcipher_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>

+72
+72
include/crypto/skcipher.h
··· 14 14 #define _CRYPTO_SKCIPHER_H 15 15 16 16 #include <linux/crypto.h> 17 + #include <linux/kernel.h> 18 + #include <linux/slab.h> 17 19 18 20 /** 19 21 * struct skcipher_givcrypt_request - Crypto request with IV generation ··· 34 32 struct skcipher_givcrypt_request *req) 35 33 { 36 34 return crypto_ablkcipher_reqtfm(&req->creq); 35 + } 36 + 37 + static inline int crypto_skcipher_givencrypt( 38 + struct skcipher_givcrypt_request *req) 39 + { 40 + struct ablkcipher_tfm *crt = 41 + crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req)); 42 + return crt->givencrypt(req); 43 + }; 44 + 45 + static inline int crypto_skcipher_givdecrypt( 46 + struct skcipher_givcrypt_request *req) 47 + { 48 + struct ablkcipher_tfm *crt = 49 + crypto_ablkcipher_crt(skcipher_givcrypt_reqtfm(req)); 50 + return crt->givdecrypt(req); 51 + }; 52 + 53 + static inline void skcipher_givcrypt_set_tfm( 54 + struct skcipher_givcrypt_request *req, struct crypto_ablkcipher *tfm) 55 + { 56 + req->creq.base.tfm = crypto_ablkcipher_tfm(tfm); 57 + } 58 + 59 + static inline struct skcipher_givcrypt_request *skcipher_givcrypt_cast( 60 + struct crypto_async_request *req) 61 + { 62 + return container_of(ablkcipher_request_cast(req), 63 + struct skcipher_givcrypt_request, creq); 64 + } 65 + 66 + static inline struct skcipher_givcrypt_request *skcipher_givcrypt_alloc( 67 + struct crypto_ablkcipher *tfm, gfp_t gfp) 68 + { 69 + struct skcipher_givcrypt_request *req; 70 + 71 + req = kmalloc(sizeof(struct skcipher_givcrypt_request) + 72 + crypto_ablkcipher_reqsize(tfm), gfp); 73 + 74 + if (likely(req)) 75 + skcipher_givcrypt_set_tfm(req, tfm); 76 + 77 + return req; 78 + } 79 + 80 + static inline void skcipher_givcrypt_free(struct skcipher_givcrypt_request *req) 81 + { 82 + kfree(req); 83 + } 84 + 85 + static inline void skcipher_givcrypt_set_callback( 86 + struct skcipher_givcrypt_request *req, u32 flags, 87 + crypto_completion_t complete, void *data) 88 + { 89 + ablkcipher_request_set_callback(&req->creq, flags, complete, data); 90 + } 91 + 92 + static inline void skcipher_givcrypt_set_crypt( 93 + struct skcipher_givcrypt_request *req, 94 + struct scatterlist *src, struct scatterlist *dst, 95 + unsigned int nbytes, void *iv) 96 + { 97 + ablkcipher_request_set_crypt(&req->creq, src, dst, nbytes, iv); 98 + } 99 + 100 + static inline void skcipher_givcrypt_set_giv( 101 + struct skcipher_givcrypt_request *req, u8 *giv, u64 seq) 102 + { 103 + req->giv = giv; 104 + req->seq = seq; 37 105 } 38 106 39 107 #endif /* _CRYPTO_SKCIPHER_H */