1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /*
3 * Public Key Encryption
4 *
5 * Copyright (c) 2015, Intel Corporation
6 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
7 */
8 #ifndef _CRYPTO_AKCIPHER_INT_H
9 #define _CRYPTO_AKCIPHER_INT_H
10 #include <crypto/akcipher.h>
11 #include <crypto/algapi.h>
12
13 struct akcipher_instance {
14 void (*free)(struct akcipher_instance *inst);
15 union {
16 struct {
17 char head[offsetof(struct akcipher_alg, base)];
18 struct crypto_instance base;
19 } s;
20 struct akcipher_alg alg;
21 };
22 };
23
24 struct crypto_akcipher_spawn {
25 struct crypto_spawn base;
26 };
27
28 /*
29 * Transform internal helpers.
30 */
akcipher_request_ctx(struct akcipher_request * req)31 static inline void *akcipher_request_ctx(struct akcipher_request *req)
32 {
33 return req->__ctx;
34 }
35
akcipher_set_reqsize(struct crypto_akcipher * akcipher,unsigned int reqsize)36 static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher,
37 unsigned int reqsize)
38 {
39 crypto_akcipher_alg(akcipher)->reqsize = reqsize;
40 }
41
akcipher_tfm_ctx(struct crypto_akcipher * tfm)42 static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm)
43 {
44 return tfm->base.__crt_ctx;
45 }
46
akcipher_request_complete(struct akcipher_request * req,int err)47 static inline void akcipher_request_complete(struct akcipher_request *req,
48 int err)
49 {
50 req->base.complete(&req->base, err);
51 }
52
akcipher_alg_name(struct crypto_akcipher * tfm)53 static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm)
54 {
55 return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name;
56 }
57
akcipher_crypto_instance(struct akcipher_instance * inst)58 static inline struct crypto_instance *akcipher_crypto_instance(
59 struct akcipher_instance *inst)
60 {
61 return container_of(&inst->alg.base, struct crypto_instance, alg);
62 }
63
akcipher_instance(struct crypto_instance * inst)64 static inline struct akcipher_instance *akcipher_instance(
65 struct crypto_instance *inst)
66 {
67 return container_of(&inst->alg, struct akcipher_instance, alg.base);
68 }
69
akcipher_alg_instance(struct crypto_akcipher * akcipher)70 static inline struct akcipher_instance *akcipher_alg_instance(
71 struct crypto_akcipher *akcipher)
72 {
73 return akcipher_instance(crypto_tfm_alg_instance(&akcipher->base));
74 }
75
akcipher_instance_ctx(struct akcipher_instance * inst)76 static inline void *akcipher_instance_ctx(struct akcipher_instance *inst)
77 {
78 return crypto_instance_ctx(akcipher_crypto_instance(inst));
79 }
80
81 int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn,
82 struct crypto_instance *inst,
83 const char *name, u32 type, u32 mask);
84
crypto_spawn_akcipher(struct crypto_akcipher_spawn * spawn)85 static inline struct crypto_akcipher *crypto_spawn_akcipher(
86 struct crypto_akcipher_spawn *spawn)
87 {
88 return crypto_spawn_tfm2(&spawn->base);
89 }
90
crypto_drop_akcipher(struct crypto_akcipher_spawn * spawn)91 static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn *spawn)
92 {
93 crypto_drop_spawn(&spawn->base);
94 }
95
crypto_spawn_akcipher_alg(struct crypto_akcipher_spawn * spawn)96 static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
97 struct crypto_akcipher_spawn *spawn)
98 {
99 return container_of(spawn->base.alg, struct akcipher_alg, base);
100 }
101
102 /**
103 * crypto_register_akcipher() -- Register public key algorithm
104 *
105 * Function registers an implementation of a public key verify algorithm
106 *
107 * @alg: algorithm definition
108 *
109 * Return: zero on success; error code in case of error
110 */
111 int crypto_register_akcipher(struct akcipher_alg *alg);
112
113 /**
114 * crypto_unregister_akcipher() -- Unregister public key algorithm
115 *
116 * Function unregisters an implementation of a public key verify algorithm
117 *
118 * @alg: algorithm definition
119 */
120 void crypto_unregister_akcipher(struct akcipher_alg *alg);
121
122 /**
123 * akcipher_register_instance() -- Unregister public key template instance
124 *
125 * Function registers an implementation of an asymmetric key algorithm
126 * created from a template
127 *
128 * @tmpl: the template from which the algorithm was created
129 * @inst: the template instance
130 */
131 int akcipher_register_instance(struct crypto_template *tmpl,
132 struct akcipher_instance *inst);
133 #endif
134