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