123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387 |
- #ifndef _CRYPTO_AKCIPHER_H
- #define _CRYPTO_AKCIPHER_H
- #include <linux/crypto.h>
- struct akcipher_request {
- struct crypto_async_request base;
- struct scatterlist *src;
- struct scatterlist *dst;
- unsigned int src_len;
- unsigned int dst_len;
- void *__ctx[] CRYPTO_MINALIGN_ATTR;
- };
- struct crypto_akcipher {
- struct crypto_tfm base;
- };
- struct akcipher_alg {
- int (*sign)(struct akcipher_request *req);
- int (*verify)(struct akcipher_request *req);
- int (*encrypt)(struct akcipher_request *req);
- int (*decrypt)(struct akcipher_request *req);
- int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key,
- unsigned int keylen);
- int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key,
- unsigned int keylen);
- int (*max_size)(struct crypto_akcipher *tfm);
- int (*init)(struct crypto_akcipher *tfm);
- void (*exit)(struct crypto_akcipher *tfm);
- unsigned int reqsize;
- struct crypto_alg base;
- };
- struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type,
- u32 mask);
- static inline struct crypto_tfm *crypto_akcipher_tfm(
- struct crypto_akcipher *tfm)
- {
- return &tfm->base;
- }
- static inline struct akcipher_alg *__crypto_akcipher_alg(struct crypto_alg *alg)
- {
- return container_of(alg, struct akcipher_alg, base);
- }
- static inline struct crypto_akcipher *__crypto_akcipher_tfm(
- struct crypto_tfm *tfm)
- {
- return container_of(tfm, struct crypto_akcipher, base);
- }
- static inline struct akcipher_alg *crypto_akcipher_alg(
- struct crypto_akcipher *tfm)
- {
- return __crypto_akcipher_alg(crypto_akcipher_tfm(tfm)->__crt_alg);
- }
- static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm)
- {
- return crypto_akcipher_alg(tfm)->reqsize;
- }
- static inline void akcipher_request_set_tfm(struct akcipher_request *req,
- struct crypto_akcipher *tfm)
- {
- req->base.tfm = crypto_akcipher_tfm(tfm);
- }
- static inline struct crypto_akcipher *crypto_akcipher_reqtfm(
- struct akcipher_request *req)
- {
- return __crypto_akcipher_tfm(req->base.tfm);
- }
- static inline void crypto_free_akcipher(struct crypto_akcipher *tfm)
- {
- crypto_destroy_tfm(tfm, crypto_akcipher_tfm(tfm));
- }
- static inline struct akcipher_request *akcipher_request_alloc(
- struct crypto_akcipher *tfm, gfp_t gfp)
- {
- struct akcipher_request *req;
- req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp);
- if (likely(req))
- akcipher_request_set_tfm(req, tfm);
- return req;
- }
- static inline void akcipher_request_free(struct akcipher_request *req)
- {
- kzfree(req);
- }
- static inline void akcipher_request_set_callback(struct akcipher_request *req,
- u32 flgs,
- crypto_completion_t cmpl,
- void *data)
- {
- req->base.complete = cmpl;
- req->base.data = data;
- req->base.flags = flgs;
- }
- static inline void akcipher_request_set_crypt(struct akcipher_request *req,
- struct scatterlist *src,
- struct scatterlist *dst,
- unsigned int src_len,
- unsigned int dst_len)
- {
- req->src = src;
- req->dst = dst;
- req->src_len = src_len;
- req->dst_len = dst_len;
- }
- static inline int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)
- {
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->max_size(tfm);
- }
- static inline int crypto_akcipher_encrypt(struct akcipher_request *req)
- {
- struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->encrypt(req);
- }
- static inline int crypto_akcipher_decrypt(struct akcipher_request *req)
- {
- struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->decrypt(req);
- }
- static inline int crypto_akcipher_sign(struct akcipher_request *req)
- {
- struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->sign(req);
- }
- static inline int crypto_akcipher_verify(struct akcipher_request *req)
- {
- struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->verify(req);
- }
- static inline int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm,
- const void *key,
- unsigned int keylen)
- {
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->set_pub_key(tfm, key, keylen);
- }
- static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
- const void *key,
- unsigned int keylen)
- {
- struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
- return alg->set_priv_key(tfm, key, keylen);
- }
- #endif
|