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_request_ctx_dma(struct akcipher_request
*req
)
38 unsigned int align
= crypto_dma_align();
40 if (align
<= crypto_tfm_ctx_alignment())
43 return PTR_ALIGN(akcipher_request_ctx(req
), align
);
46 static inline void akcipher_set_reqsize(struct crypto_akcipher
*akcipher
,
49 akcipher
->reqsize
= reqsize
;
52 static inline void akcipher_set_reqsize_dma(struct crypto_akcipher
*akcipher
,
55 reqsize
+= crypto_dma_align() & ~(crypto_tfm_ctx_alignment() - 1);
56 akcipher
->reqsize
= reqsize
;
59 static inline void *akcipher_tfm_ctx(struct crypto_akcipher
*tfm
)
61 return crypto_tfm_ctx(&tfm
->base
);
64 static inline void *akcipher_tfm_ctx_dma(struct crypto_akcipher
*tfm
)
66 return crypto_tfm_ctx_dma(&tfm
->base
);
69 static inline void akcipher_request_complete(struct akcipher_request
*req
,
72 crypto_request_complete(&req
->base
, err
);
75 static inline const char *akcipher_alg_name(struct crypto_akcipher
*tfm
)
77 return crypto_akcipher_tfm(tfm
)->__crt_alg
->cra_name
;
80 static inline struct crypto_instance
*akcipher_crypto_instance(
81 struct akcipher_instance
*inst
)
83 return container_of(&inst
->alg
.base
, struct crypto_instance
, alg
);
86 static inline struct akcipher_instance
*akcipher_instance(
87 struct crypto_instance
*inst
)
89 return container_of(&inst
->alg
, struct akcipher_instance
, alg
.base
);
92 static inline struct akcipher_instance
*akcipher_alg_instance(
93 struct crypto_akcipher
*akcipher
)
95 return akcipher_instance(crypto_tfm_alg_instance(&akcipher
->base
));
98 static inline void *akcipher_instance_ctx(struct akcipher_instance
*inst
)
100 return crypto_instance_ctx(akcipher_crypto_instance(inst
));
103 int crypto_grab_akcipher(struct crypto_akcipher_spawn
*spawn
,
104 struct crypto_instance
*inst
,
105 const char *name
, u32 type
, u32 mask
);
107 static inline struct crypto_akcipher
*crypto_spawn_akcipher(
108 struct crypto_akcipher_spawn
*spawn
)
110 return crypto_spawn_tfm2(&spawn
->base
);
113 static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn
*spawn
)
115 crypto_drop_spawn(&spawn
->base
);
118 static inline struct akcipher_alg
*crypto_spawn_akcipher_alg(
119 struct crypto_akcipher_spawn
*spawn
)
121 return container_of(spawn
->base
.alg
, struct akcipher_alg
, base
);
125 * crypto_register_akcipher() -- Register public key algorithm
127 * Function registers an implementation of a public key cipher algorithm
129 * @alg: algorithm definition
131 * Return: zero on success; error code in case of error
133 int crypto_register_akcipher(struct akcipher_alg
*alg
);
136 * crypto_unregister_akcipher() -- Unregister public key algorithm
138 * Function unregisters an implementation of a public key cipher algorithm
140 * @alg: algorithm definition
142 void crypto_unregister_akcipher(struct akcipher_alg
*alg
);
145 * akcipher_register_instance() -- Unregister public key template instance
147 * Function registers an implementation of an asymmetric key algorithm
148 * created from a template
150 * @tmpl: the template from which the algorithm was created
151 * @inst: the template instance
153 int akcipher_register_instance(struct crypto_template
*tmpl
,
154 struct akcipher_instance
*inst
);