Linux 4.16.11
[linux/fpc-iii.git] / include / crypto / internal / akcipher.h
blob805686ba2be47969213cf1f6a1547bbfcab77186
1 /*
2 * Public Key Encryption
4 * Copyright (c) 2015, Intel Corporation
5 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
10 * any later version.
13 #ifndef _CRYPTO_AKCIPHER_INT_H
14 #define _CRYPTO_AKCIPHER_INT_H
15 #include <crypto/akcipher.h>
16 #include <crypto/algapi.h>
18 struct akcipher_instance {
19 void (*free)(struct akcipher_instance *inst);
20 union {
21 struct {
22 char head[offsetof(struct akcipher_alg, base)];
23 struct crypto_instance base;
24 } s;
25 struct akcipher_alg alg;
29 struct crypto_akcipher_spawn {
30 struct crypto_spawn base;
34 * Transform internal helpers.
36 static inline void *akcipher_request_ctx(struct akcipher_request *req)
38 return req->__ctx;
41 static inline void akcipher_set_reqsize(struct crypto_akcipher *akcipher,
42 unsigned int reqsize)
44 crypto_akcipher_alg(akcipher)->reqsize = reqsize;
47 static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm)
49 return tfm->base.__crt_ctx;
52 static inline void akcipher_request_complete(struct akcipher_request *req,
53 int err)
55 req->base.complete(&req->base, err);
58 static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm)
60 return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name;
63 static inline struct crypto_instance *akcipher_crypto_instance(
64 struct akcipher_instance *inst)
66 return container_of(&inst->alg.base, struct crypto_instance, alg);
69 static inline struct akcipher_instance *akcipher_instance(
70 struct crypto_instance *inst)
72 return container_of(&inst->alg, struct akcipher_instance, alg.base);
75 static inline struct akcipher_instance *akcipher_alg_instance(
76 struct crypto_akcipher *akcipher)
78 return akcipher_instance(crypto_tfm_alg_instance(&akcipher->base));
81 static inline void *akcipher_instance_ctx(struct akcipher_instance *inst)
83 return crypto_instance_ctx(akcipher_crypto_instance(inst));
86 static inline void crypto_set_akcipher_spawn(
87 struct crypto_akcipher_spawn *spawn,
88 struct crypto_instance *inst)
90 crypto_set_spawn(&spawn->base, inst);
93 int crypto_grab_akcipher(struct crypto_akcipher_spawn *spawn, const char *name,
94 u32 type, u32 mask);
96 static inline struct crypto_akcipher *crypto_spawn_akcipher(
97 struct crypto_akcipher_spawn *spawn)
99 return crypto_spawn_tfm2(&spawn->base);
102 static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn *spawn)
104 crypto_drop_spawn(&spawn->base);
107 static inline struct akcipher_alg *crypto_spawn_akcipher_alg(
108 struct crypto_akcipher_spawn *spawn)
110 return container_of(spawn->base.alg, struct akcipher_alg, base);
114 * crypto_register_akcipher() -- Register public key algorithm
116 * Function registers an implementation of a public key verify algorithm
118 * @alg: algorithm definition
120 * Return: zero on success; error code in case of error
122 int crypto_register_akcipher(struct akcipher_alg *alg);
125 * crypto_unregister_akcipher() -- Unregister public key algorithm
127 * Function unregisters an implementation of a public key verify algorithm
129 * @alg: algorithm definition
131 void crypto_unregister_akcipher(struct akcipher_alg *alg);
134 * akcipher_register_instance() -- Unregister public key template instance
136 * Function registers an implementation of an asymmetric key algorithm
137 * created from a template
139 * @tmpl: the template from which the algorithm was created
140 * @inst: the template instance
142 int akcipher_register_instance(struct crypto_template *tmpl,
143 struct akcipher_instance *inst);
144 #endif