1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * Public Key Encryption
5 * Copyright (c) 2015, Intel Corporation
6 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
8 #ifndef _CRYPTO_AKCIPHER_INT_H
9 #define _CRYPTO_AKCIPHER_INT_H
10 #include <crypto/akcipher.h>
11 #include <crypto/algapi.h>
13 struct akcipher_instance {
14 void (*free)(struct akcipher_instance *inst);
17 char head[offsetof(struct akcipher_alg, base)];
18 struct crypto_instance base;
20 struct akcipher_alg alg;
24 struct crypto_akcipher_spawn {
25 struct crypto_spawn base;
29 * Transform internal helpers.
31 static inline void *akcipher_request_ctx(struct akcipher_request *req)
36 static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher,
39 crypto_akcipher_alg(akcipher)->reqsize = reqsize;
42 static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm)
44 return tfm->base.__crt_ctx;
47 static inline void akcipher_request_complete(struct akcipher_request *req,
50 req->base.complete(&req->base, err);
53 static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm)
55 return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name;
58 static inline struct crypto_instance *akcipher_crypto_instance(
59 struct akcipher_instance *inst)
61 return container_of(&inst->alg.base, struct crypto_instance, alg);
64 static inline struct akcipher_instance *akcipher_instance(
65 struct crypto_instance *inst)
67 return container_of(&inst->alg, struct akcipher_instance, alg.base);
70 static inline struct akcipher_instance *akcipher_alg_instance(
71 struct crypto_akcipher *akcipher)
73 return akcipher_instance(crypto_tfm_alg_instance(&akcipher->base));
76 static inline void *akcipher_instance_ctx(struct akcipher_instance *inst)
78 return crypto_instance_ctx(akcipher_crypto_instance(inst));
81 static inline void crypto_set_akcipher_spawn(
82 struct crypto_akcipher_spawn *spawn,
83 struct crypto_instance *inst)
85 crypto_set_spawn(&spawn->base, inst);
88 int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name,
91 static inline struct crypto_akcipher *crypto_spawn_akcipher(
92 struct crypto_akcipher_spawn *spawn)
94 return crypto_spawn_tfm2(&spawn->base);
97 static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn *spawn)
99 crypto_drop_spawn(&spawn->base);
102 static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
103 struct crypto_akcipher_spawn *spawn)
105 return container_of(spawn->base.alg, struct akcipher_alg, base);
109 * crypto_register_akcipher() -- Register public key algorithm
111 * Function registers an implementation of a public key verify algorithm
113 * @alg: algorithm definition
115 * Return: zero on success; error code in case of error
117 int crypto_register_akcipher(struct akcipher_alg *alg);
120 * crypto_unregister_akcipher() -- Unregister public key algorithm
122 * Function unregisters an implementation of a public key verify algorithm
124 * @alg: algorithm definition
126 void crypto_unregister_akcipher(struct akcipher_alg *alg);
129 * akcipher_register_instance() -- Unregister public key template instance
131 * Function registers an implementation of an asymmetric key algorithm
132 * created from a template
134 * @tmpl: the template from which the algorithm was created
135 * @inst: the template instance
137 int akcipher_register_instance(struct crypto_template *tmpl,
138 struct akcipher_instance *inst);