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)
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
);
22 char head
[offsetof(struct akcipher_alg
, base
)];
23 struct crypto_instance base
;
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
)
41 static inline void *akcipher_tfm_ctx(struct crypto_akcipher
*tfm
)
43 return tfm
->base
.__crt_ctx
;
46 static inline void akcipher_request_complete(struct akcipher_request
*req
,
49 req
->base
.complete(&req
->base
, err
);
52 static inline const char *akcipher_alg_name(struct crypto_akcipher
*tfm
)
54 return crypto_akcipher_tfm(tfm
)->__crt_alg
->cra_name
;
57 static inline struct crypto_instance
*akcipher_crypto_instance(
58 struct akcipher_instance
*inst
)
60 return container_of(&inst
->alg
.base
, struct crypto_instance
, alg
);
63 static inline struct akcipher_instance
*akcipher_instance(
64 struct crypto_instance
*inst
)
66 return container_of(&inst
->alg
, struct akcipher_instance
, alg
.base
);
69 static inline struct akcipher_instance
*akcipher_alg_instance(
70 struct crypto_akcipher
*akcipher
)
72 return akcipher_instance(crypto_tfm_alg_instance(&akcipher
->base
));
75 static inline void *akcipher_instance_ctx(struct akcipher_instance
*inst
)
77 return crypto_instance_ctx(akcipher_crypto_instance(inst
));
80 static inline void crypto_set_akcipher_spawn(
81 struct crypto_akcipher_spawn
*spawn
,
82 struct crypto_instance
*inst
)
84 crypto_set_spawn(&spawn
->base
, inst
);
87 int crypto_grab_akcipher(struct crypto_akcipher_spawn
*spawn
, const char *name
,
90 static inline struct crypto_akcipher
*crypto_spawn_akcipher(
91 struct crypto_akcipher_spawn
*spawn
)
93 return crypto_spawn_tfm2(&spawn
->base
);
96 static inline void crypto_drop_akcipher(struct crypto_akcipher_spawn
*spawn
)
98 crypto_drop_spawn(&spawn
->base
);
101 static inline struct akcipher_alg
*crypto_spawn_akcipher_alg(
102 struct crypto_akcipher_spawn
*spawn
)
104 return container_of(spawn
->base
.alg
, struct akcipher_alg
, base
);
108 * crypto_register_akcipher() -- Register public key algorithm
110 * Function registers an implementation of a public key verify algorithm
112 * @alg: algorithm definition
114 * Return: zero on success; error code in case of error
116 int crypto_register_akcipher(struct akcipher_alg
*alg
);
119 * crypto_unregister_akcipher() -- Unregister public key algorithm
121 * Function unregisters an implementation of a public key verify algorithm
123 * @alg: algorithm definition
125 void crypto_unregister_akcipher(struct akcipher_alg
*alg
);
128 * akcipher_register_instance() -- Unregister public key template instance
130 * Function registers an implementation of an asymmetric key algorithm
131 * created from a template
133 * @tmpl: the template from which the algorithm was created
134 * @inst: the template instance
136 int akcipher_register_instance(struct crypto_template
*tmpl
,
137 struct akcipher_instance
*inst
);