diff options
author | Tadeusz Struk <tadeusz.struk@intel.com> | 2015-06-16 13:30:55 -0400 |
---|---|---|
committer | Herbert Xu <herbert@gondor.apana.org.au> | 2015-06-17 05:03:14 -0400 |
commit | 3c339ab83fc09d9d91fb7e8b4a60e8ddc91de417 (patch) | |
tree | b9e262f57e0acad14b05b0545dfd5c690f78f356 | |
parent | c2b7b20aedfa10de3634877c3e4b7bc9a7d6461e (diff) |
crypto: akcipher - add PKE API
Add Public Key Encryption API.
Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Made CRYPTO_AKCIPHER invisible like other type config options.
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r-- | crypto/Kconfig | 9 | ||||
-rw-r--r-- | crypto/Makefile | 1 | ||||
-rw-r--r-- | crypto/akcipher.c | 117 | ||||
-rw-r--r-- | crypto/crypto_user.c | 22 | ||||
-rw-r--r-- | include/crypto/akcipher.h | 340 | ||||
-rw-r--r-- | include/crypto/internal/akcipher.h | 60 | ||||
-rw-r--r-- | include/linux/crypto.h | 1 | ||||
-rw-r--r-- | include/linux/cryptouser.h | 5 |
8 files changed, 555 insertions, 0 deletions
diff --git a/crypto/Kconfig b/crypto/Kconfig index f6fc054eb2d1..eb0aca45d430 100644 --- a/crypto/Kconfig +++ b/crypto/Kconfig | |||
@@ -91,6 +91,15 @@ config CRYPTO_PCOMP2 | |||
91 | tristate | 91 | tristate |
92 | select CRYPTO_ALGAPI2 | 92 | select CRYPTO_ALGAPI2 |
93 | 93 | ||
94 | config CRYPTO_AKCIPHER2 | ||
95 | tristate | ||
96 | select CRYPTO_ALGAPI2 | ||
97 | |||
98 | config CRYPTO_AKCIPHER | ||
99 | tristate | ||
100 | select CRYPTO_AKCIPHER2 | ||
101 | select CRYPTO_ALGAPI | ||
102 | |||
94 | config CRYPTO_MANAGER | 103 | config CRYPTO_MANAGER |
95 | tristate "Cryptographic algorithm manager" | 104 | tristate "Cryptographic algorithm manager" |
96 | select CRYPTO_MANAGER2 | 105 | select CRYPTO_MANAGER2 |
diff --git a/crypto/Makefile b/crypto/Makefile index c84203572477..1ed382df7db9 100644 --- a/crypto/Makefile +++ b/crypto/Makefile | |||
@@ -28,6 +28,7 @@ crypto_hash-y += shash.o | |||
28 | obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o | 28 | obj-$(CONFIG_CRYPTO_HASH2) += crypto_hash.o |
29 | 29 | ||
30 | obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o | 30 | obj-$(CONFIG_CRYPTO_PCOMP2) += pcompress.o |
31 | obj-$(CONFIG_CRYPTO_AKCIPHER2) += akcipher.o | ||
31 | 32 | ||
32 | cryptomgr-y := algboss.o testmgr.o | 33 | cryptomgr-y := algboss.o testmgr.o |
33 | 34 | ||
diff --git a/crypto/akcipher.c b/crypto/akcipher.c new file mode 100644 index 000000000000..d7986414814e --- /dev/null +++ b/crypto/akcipher.c | |||
@@ -0,0 +1,117 @@ | |||
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 | #include <linux/errno.h> | ||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/module.h> | ||
16 | #include <linux/seq_file.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/string.h> | ||
19 | #include <linux/crypto.h> | ||
20 | #include <crypto/algapi.h> | ||
21 | #include <linux/cryptouser.h> | ||
22 | #include <net/netlink.h> | ||
23 | #include <crypto/akcipher.h> | ||
24 | #include <crypto/public_key.h> | ||
25 | #include "internal.h" | ||
26 | |||
27 | #ifdef CONFIG_NET | ||
28 | static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) | ||
29 | { | ||
30 | struct crypto_report_akcipher rakcipher; | ||
31 | |||
32 | strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); | ||
33 | |||
34 | if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, | ||
35 | sizeof(struct crypto_report_akcipher), &rakcipher)) | ||
36 | goto nla_put_failure; | ||
37 | return 0; | ||
38 | |||
39 | nla_put_failure: | ||
40 | return -EMSGSIZE; | ||
41 | } | ||
42 | #else | ||
43 | static int crypto_akcipher_report(struct sk_buff *skb, struct crypto_alg *alg) | ||
44 | { | ||
45 | return -ENOSYS; | ||
46 | } | ||
47 | #endif | ||
48 | |||
49 | static void crypto_akcipher_show(struct seq_file *m, struct crypto_alg *alg) | ||
50 | __attribute__ ((unused)); | ||
51 | |||
52 | static void crypto_akcipher_show(struct seq_file *m, struct crypto_alg *alg) | ||
53 | { | ||
54 | seq_puts(m, "type : akcipher\n"); | ||
55 | } | ||
56 | |||
57 | static void crypto_akcipher_exit_tfm(struct crypto_tfm *tfm) | ||
58 | { | ||
59 | struct crypto_akcipher *akcipher = __crypto_akcipher_tfm(tfm); | ||
60 | struct akcipher_alg *alg = crypto_akcipher_alg(akcipher); | ||
61 | |||
62 | alg->exit(akcipher); | ||
63 | } | ||
64 | |||
65 | static int crypto_akcipher_init_tfm(struct crypto_tfm *tfm) | ||
66 | { | ||
67 | struct crypto_akcipher *akcipher = __crypto_akcipher_tfm(tfm); | ||
68 | struct akcipher_alg *alg = crypto_akcipher_alg(akcipher); | ||
69 | |||
70 | if (alg->exit) | ||
71 | akcipher->base.exit = crypto_akcipher_exit_tfm; | ||
72 | |||
73 | if (alg->init) | ||
74 | return alg->init(akcipher); | ||
75 | |||
76 | return 0; | ||
77 | } | ||
78 | |||
79 | static const struct crypto_type crypto_akcipher_type = { | ||
80 | .extsize = crypto_alg_extsize, | ||
81 | .init_tfm = crypto_akcipher_init_tfm, | ||
82 | #ifdef CONFIG_PROC_FS | ||
83 | .show = crypto_akcipher_show, | ||
84 | #endif | ||
85 | .report = crypto_akcipher_report, | ||
86 | .maskclear = ~CRYPTO_ALG_TYPE_MASK, | ||
87 | .maskset = CRYPTO_ALG_TYPE_MASK, | ||
88 | .type = CRYPTO_ALG_TYPE_AKCIPHER, | ||
89 | .tfmsize = offsetof(struct crypto_akcipher, base), | ||
90 | }; | ||
91 | |||
92 | struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, | ||
93 | u32 mask) | ||
94 | { | ||
95 | return crypto_alloc_tfm(alg_name, &crypto_akcipher_type, type, mask); | ||
96 | } | ||
97 | EXPORT_SYMBOL_GPL(crypto_alloc_akcipher); | ||
98 | |||
99 | int crypto_register_akcipher(struct akcipher_alg *alg) | ||
100 | { | ||
101 | struct crypto_alg *base = &alg->base; | ||
102 | |||
103 | base->cra_type = &crypto_akcipher_type; | ||
104 | base->cra_flags &= ~CRYPTO_ALG_TYPE_MASK; | ||
105 | base->cra_flags |= CRYPTO_ALG_TYPE_AKCIPHER; | ||
106 | return crypto_register_alg(base); | ||
107 | } | ||
108 | EXPORT_SYMBOL_GPL(crypto_register_akcipher); | ||
109 | |||
110 | void crypto_unregister_akcipher(struct akcipher_alg *alg) | ||
111 | { | ||
112 | crypto_unregister_alg(&alg->base); | ||
113 | } | ||
114 | EXPORT_SYMBOL_GPL(crypto_unregister_akcipher); | ||
115 | |||
116 | MODULE_LICENSE("GPL"); | ||
117 | MODULE_DESCRIPTION("Generic public key cihper type"); | ||
diff --git a/crypto/crypto_user.c b/crypto/crypto_user.c index 41dfe762b7fb..11dbd5a81c72 100644 --- a/crypto/crypto_user.c +++ b/crypto/crypto_user.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <net/net_namespace.h> | 27 | #include <net/net_namespace.h> |
28 | #include <crypto/internal/aead.h> | 28 | #include <crypto/internal/aead.h> |
29 | #include <crypto/internal/skcipher.h> | 29 | #include <crypto/internal/skcipher.h> |
30 | #include <crypto/akcipher.h> | ||
30 | 31 | ||
31 | #include "internal.h" | 32 | #include "internal.h" |
32 | 33 | ||
@@ -110,6 +111,21 @@ nla_put_failure: | |||
110 | return -EMSGSIZE; | 111 | return -EMSGSIZE; |
111 | } | 112 | } |
112 | 113 | ||
114 | static int crypto_report_akcipher(struct sk_buff *skb, struct crypto_alg *alg) | ||
115 | { | ||
116 | struct crypto_report_akcipher rakcipher; | ||
117 | |||
118 | strncpy(rakcipher.type, "akcipher", sizeof(rakcipher.type)); | ||
119 | |||
120 | if (nla_put(skb, CRYPTOCFGA_REPORT_AKCIPHER, | ||
121 | sizeof(struct crypto_report_akcipher), &rakcipher)) | ||
122 | goto nla_put_failure; | ||
123 | return 0; | ||
124 | |||
125 | nla_put_failure: | ||
126 | return -EMSGSIZE; | ||
127 | } | ||
128 | |||
113 | static int crypto_report_one(struct crypto_alg *alg, | 129 | static int crypto_report_one(struct crypto_alg *alg, |
114 | struct crypto_user_alg *ualg, struct sk_buff *skb) | 130 | struct crypto_user_alg *ualg, struct sk_buff *skb) |
115 | { | 131 | { |
@@ -154,6 +170,12 @@ static int crypto_report_one(struct crypto_alg *alg, | |||
154 | goto nla_put_failure; | 170 | goto nla_put_failure; |
155 | 171 | ||
156 | break; | 172 | break; |
173 | |||
174 | case CRYPTO_ALG_TYPE_AKCIPHER: | ||
175 | if (crypto_report_akcipher(skb, alg)) | ||
176 | goto nla_put_failure; | ||
177 | |||
178 | break; | ||
157 | } | 179 | } |
158 | 180 | ||
159 | out: | 181 | out: |
diff --git a/include/crypto/akcipher.h b/include/crypto/akcipher.h new file mode 100644 index 000000000000..69d163e39101 --- /dev/null +++ b/include/crypto/akcipher.h | |||
@@ -0,0 +1,340 @@ | |||
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_H | ||
14 | #define _CRYPTO_AKCIPHER_H | ||
15 | #include <linux/crypto.h> | ||
16 | |||
17 | /** | ||
18 | * struct akcipher_request - public key request | ||
19 | * | ||
20 | * @base: Common attributes for async crypto requests | ||
21 | * @src: Pointer to memory containing the input parameters | ||
22 | * The format of the parameter(s) is expeted to be Octet String | ||
23 | * @dst: Pointer to memory whare the result will be stored | ||
24 | * @src_len: Size of the input parameter | ||
25 | * @dst_len: Size of the output buffer. It needs to be at leaset | ||
26 | * as big as the expected result depending on the operation | ||
27 | * After operation it will be updated with the acctual size of the | ||
28 | * result. In case of error, where the dst_len was insufficient, | ||
29 | * it will be updated to the size required for the operation. | ||
30 | * @__ctx: Start of private context data | ||
31 | */ | ||
32 | struct akcipher_request { | ||
33 | struct crypto_async_request base; | ||
34 | void *src; | ||
35 | void *dst; | ||
36 | unsigned int src_len; | ||
37 | unsigned int dst_len; | ||
38 | void *__ctx[] CRYPTO_MINALIGN_ATTR; | ||
39 | }; | ||
40 | |||
41 | /** | ||
42 | * struct crypto_akcipher - user-instantiated objects which encapsulate | ||
43 | * algorithms and core processing logic | ||
44 | * | ||
45 | * @base: Common crypto API algorithm data structure | ||
46 | */ | ||
47 | struct crypto_akcipher { | ||
48 | struct crypto_tfm base; | ||
49 | }; | ||
50 | |||
51 | /** | ||
52 | * struct akcipher_alg - generic public key algorithm | ||
53 | * | ||
54 | * @sign: Function performs a sign operation as defined by public key | ||
55 | * algorithm. In case of error, where the dst_len was insufficient, | ||
56 | * the req->dst_len will be updated to the size required for the | ||
57 | * operation | ||
58 | * @verify: Function performs a sign operation as defined by public key | ||
59 | * algorithm. In case of error, where the dst_len was insufficient, | ||
60 | * the req->dst_len will be updated to the size required for the | ||
61 | * operation | ||
62 | * @encrypt: Function performs an encrytp operation as defined by public key | ||
63 | * algorithm. In case of error, where the dst_len was insufficient, | ||
64 | * the req->dst_len will be updated to the size required for the | ||
65 | * operation | ||
66 | * @decrypt: Function performs a decrypt operation as defined by public key | ||
67 | * algorithm. In case of error, where the dst_len was insufficient, | ||
68 | * the req->dst_len will be updated to the size required for the | ||
69 | * operation | ||
70 | * @setkey: Function invokes the algorithm specific set key function, which | ||
71 | * knows how to decode and interpret the BER encoded key | ||
72 | * @init: Initialize the cryptographic transformation object. | ||
73 | * This function is used to initialize the cryptographic | ||
74 | * transformation object. This function is called only once at | ||
75 | * the instantiation time, right after the transformation context | ||
76 | * was allocated. In case the cryptographic hardware has some | ||
77 | * special requirements which need to be handled by software, this | ||
78 | * function shall check for the precise requirement of the | ||
79 | * transformation and put any software fallbacks in place. | ||
80 | * @exit: Deinitialize the cryptographic transformation object. This is a | ||
81 | * counterpart to @init, used to remove various changes set in | ||
82 | * @init. | ||
83 | * | ||
84 | * @reqsize: Request context size required by algorithm implementation | ||
85 | * @base: Common crypto API algorithm data structure | ||
86 | */ | ||
87 | struct akcipher_alg { | ||
88 | int (*sign)(struct akcipher_request *req); | ||
89 | int (*verify)(struct akcipher_request *req); | ||
90 | int (*encrypt)(struct akcipher_request *req); | ||
91 | int (*decrypt)(struct akcipher_request *req); | ||
92 | int (*setkey)(struct crypto_akcipher *tfm, const void *key, | ||
93 | unsigned int keylen); | ||
94 | int (*init)(struct crypto_akcipher *tfm); | ||
95 | void (*exit)(struct crypto_akcipher *tfm); | ||
96 | |||
97 | unsigned int reqsize; | ||
98 | struct crypto_alg base; | ||
99 | }; | ||
100 | |||
101 | /** | ||
102 | * DOC: Generic Public Key API | ||
103 | * | ||
104 | * The Public Key API is used with the algorithms of type | ||
105 | * CRYPTO_ALG_TYPE_AKCIPHER (listed as type "akcipher" in /proc/crypto) | ||
106 | */ | ||
107 | |||
108 | /** | ||
109 | * crypto_alloc_akcipher() -- allocate AKCIPHER tfm handle | ||
110 | * @alg_name: is the cra_name / name or cra_driver_name / driver name of the | ||
111 | * public key algorithm e.g. "rsa" | ||
112 | * @type: specifies the type of the algorithm | ||
113 | * @mask: specifies the mask for the algorithm | ||
114 | * | ||
115 | * Allocate a handle for public key algorithm. The returned struct | ||
116 | * crypto_akcipher is the handle that is required for any subsequent | ||
117 | * API invocation for the public key operations. | ||
118 | * | ||
119 | * Return: allocated handle in case of success; IS_ERR() is true in case | ||
120 | * of an error, PTR_ERR() returns the error code. | ||
121 | */ | ||
122 | struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type, | ||
123 | u32 mask); | ||
124 | |||
125 | static inline struct crypto_tfm *crypto_akcipher_tfm( | ||
126 | struct crypto_akcipher *tfm) | ||
127 | { | ||
128 | return &tfm->base; | ||
129 | } | ||
130 | |||
131 | static inline struct akcipher_alg *__crypto_akcipher_alg(struct crypto_alg *alg) | ||
132 | { | ||
133 | return container_of(alg, struct akcipher_alg, base); | ||
134 | } | ||
135 | |||
136 | static inline struct crypto_akcipher *__crypto_akcipher_tfm( | ||
137 | struct crypto_tfm *tfm) | ||
138 | { | ||
139 | return container_of(tfm, struct crypto_akcipher, base); | ||
140 | } | ||
141 | |||
142 | static inline struct akcipher_alg *crypto_akcipher_alg( | ||
143 | struct crypto_akcipher *tfm) | ||
144 | { | ||
145 | return __crypto_akcipher_alg(crypto_akcipher_tfm(tfm)->__crt_alg); | ||
146 | } | ||
147 | |||
148 | static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm) | ||
149 | { | ||
150 | return crypto_akcipher_alg(tfm)->reqsize; | ||
151 | } | ||
152 | |||
153 | static inline void akcipher_request_set_tfm(struct akcipher_request *req, | ||
154 | struct crypto_akcipher *tfm) | ||
155 | { | ||
156 | req->base.tfm = crypto_akcipher_tfm(tfm); | ||
157 | } | ||
158 | |||
159 | static inline struct crypto_akcipher *crypto_akcipher_reqtfm( | ||
160 | struct akcipher_request *req) | ||
161 | { | ||
162 | return __crypto_akcipher_tfm(req->base.tfm); | ||
163 | } | ||
164 | |||
165 | /** | ||
166 | * crypto_free_akcipher() -- free AKCIPHER tfm handle | ||
167 | * | ||
168 | * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() | ||
169 | */ | ||
170 | static inline void crypto_free_akcipher(struct crypto_akcipher *tfm) | ||
171 | { | ||
172 | crypto_destroy_tfm(tfm, crypto_akcipher_tfm(tfm)); | ||
173 | } | ||
174 | |||
175 | /** | ||
176 | * akcipher_request_alloc() -- allocates public key request | ||
177 | * | ||
178 | * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher() | ||
179 | * @gfp: allocation flags | ||
180 | * | ||
181 | * Return: allocated handle in case of success or NULL in case of an error. | ||
182 | */ | ||
183 | static inline struct akcipher_request *akcipher_request_alloc( | ||
184 | struct crypto_akcipher *tfm, gfp_t gfp) | ||
185 | { | ||
186 | struct akcipher_request *req; | ||
187 | |||
188 | req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp); | ||
189 | if (likely(req)) | ||
190 | akcipher_request_set_tfm(req, tfm); | ||
191 | |||
192 | return req; | ||
193 | } | ||
194 | |||
195 | /** | ||
196 | * akcipher_request_free() -- zeroize and free public key request | ||
197 | * | ||
198 | * @req: request to free | ||
199 | */ | ||
200 | static inline void akcipher_request_free(struct akcipher_request *req) | ||
201 | { | ||
202 | kzfree(req); | ||
203 | } | ||
204 | |||
205 | /** | ||
206 | * akcipher_request_set_callback() -- Sets an asynchronous callback. | ||
207 | * | ||
208 | * Callback will be called when an asynchronous operation on a given | ||
209 | * request is finished. | ||
210 | * | ||
211 | * @req: request that the callback will be set for | ||
212 | * @flgs: specify for instance if the operation may backlog | ||
213 | * @cmlp: callback which will be called | ||
214 | * @data: private data used by the caller | ||
215 | */ | ||
216 | static inline void akcipher_request_set_callback(struct akcipher_request *req, | ||
217 | u32 flgs, | ||
218 | crypto_completion_t cmpl, | ||
219 | void *data) | ||
220 | { | ||
221 | req->base.complete = cmpl; | ||
222 | req->base.data = data; | ||
223 | req->base.flags = flgs; | ||
224 | } | ||
225 | |||
226 | /** | ||
227 | * akcipher_request_set_crypt() -- Sets reqest parameters | ||
228 | * | ||
229 | * Sets parameters required by crypto operation | ||
230 | * | ||
231 | * @req: public key request | ||
232 | * @src: ptr to input parameter | ||
233 | * @dst: ptr of output parameter | ||
234 | * @src_len: size of the input buffer | ||
235 | * @dst_len: size of the output buffer. It will be updated by the | ||
236 | * implementation to reflect the acctual size of the result | ||
237 | */ | ||
238 | static inline void akcipher_request_set_crypt(struct akcipher_request *req, | ||
239 | void *src, void *dst, | ||
240 | unsigned int src_len, | ||
241 | unsigned int dst_len) | ||
242 | { | ||
243 | req->src = src; | ||
244 | req->dst = dst; | ||
245 | req->src_len = src_len; | ||
246 | req->dst_len = dst_len; | ||
247 | } | ||
248 | |||
249 | /** | ||
250 | * crypto_akcipher_encrypt() -- Invoke public key encrypt operation | ||
251 | * | ||
252 | * Function invokes the specific public key encrypt operation for a given | ||
253 | * public key algorithm | ||
254 | * | ||
255 | * @req: asymmetric key request | ||
256 | * | ||
257 | * Return: zero on success; error code in case of error | ||
258 | */ | ||
259 | static inline int crypto_akcipher_encrypt(struct akcipher_request *req) | ||
260 | { | ||
261 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
262 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
263 | |||
264 | return alg->encrypt(req); | ||
265 | } | ||
266 | |||
267 | /** | ||
268 | * crypto_akcipher_decrypt() -- Invoke public key decrypt operation | ||
269 | * | ||
270 | * Function invokes the specific public key decrypt operation for a given | ||
271 | * public key algorithm | ||
272 | * | ||
273 | * @req: asymmetric key request | ||
274 | * | ||
275 | * Return: zero on success; error code in case of error | ||
276 | */ | ||
277 | static inline int crypto_akcipher_decrypt(struct akcipher_request *req) | ||
278 | { | ||
279 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
280 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
281 | |||
282 | return alg->decrypt(req); | ||
283 | } | ||
284 | |||
285 | /** | ||
286 | * crypto_akcipher_sign() -- Invoke public key sign operation | ||
287 | * | ||
288 | * Function invokes the specific public key sign operation for a given | ||
289 | * public key algorithm | ||
290 | * | ||
291 | * @req: asymmetric key request | ||
292 | * | ||
293 | * Return: zero on success; error code in case of error | ||
294 | */ | ||
295 | static inline int crypto_akcipher_sign(struct akcipher_request *req) | ||
296 | { | ||
297 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
298 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
299 | |||
300 | return alg->sign(req); | ||
301 | } | ||
302 | |||
303 | /** | ||
304 | * crypto_akcipher_verify() -- Invoke public key verify operation | ||
305 | * | ||
306 | * Function invokes the specific public key verify operation for a given | ||
307 | * public key algorithm | ||
308 | * | ||
309 | * @req: asymmetric key request | ||
310 | * | ||
311 | * Return: zero on success; error code in case of error | ||
312 | */ | ||
313 | static inline int crypto_akcipher_verify(struct akcipher_request *req) | ||
314 | { | ||
315 | struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req); | ||
316 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
317 | |||
318 | return alg->verify(req); | ||
319 | } | ||
320 | |||
321 | /** | ||
322 | * crypto_akcipher_setkey() -- Invoke public key setkey operation | ||
323 | * | ||
324 | * Function invokes the algorithm specific set key function, which knows | ||
325 | * how to decode and interpret the encoded key | ||
326 | * | ||
327 | * @tfm: tfm handle | ||
328 | * @key: BER encoded private or public key | ||
329 | * @keylen: length of the key | ||
330 | * | ||
331 | * Return: zero on success; error code in case of error | ||
332 | */ | ||
333 | static inline int crypto_akcipher_setkey(struct crypto_akcipher *tfm, void *key, | ||
334 | unsigned int keylen) | ||
335 | { | ||
336 | struct akcipher_alg *alg = crypto_akcipher_alg(tfm); | ||
337 | |||
338 | return alg->setkey(tfm, key, keylen); | ||
339 | } | ||
340 | #endif | ||
diff --git a/include/crypto/internal/akcipher.h b/include/crypto/internal/akcipher.h new file mode 100644 index 000000000000..9a2bda15e454 --- /dev/null +++ b/include/crypto/internal/akcipher.h | |||
@@ -0,0 +1,60 @@ | |||
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 | |||
17 | /* | ||
18 | * Transform internal helpers. | ||
19 | */ | ||
20 | static inline void *akcipher_request_ctx(struct akcipher_request *req) | ||
21 | { | ||
22 | return req->__ctx; | ||
23 | } | ||
24 | |||
25 | static inline void *akcipher_tfm_ctx(struct crypto_akcipher *tfm) | ||
26 | { | ||
27 | return tfm->base.__crt_ctx; | ||
28 | } | ||
29 | |||
30 | static inline void akcipher_request_complete(struct akcipher_request *req, | ||
31 | int err) | ||
32 | { | ||
33 | req->base.complete(&req->base, err); | ||
34 | } | ||
35 | |||
36 | static inline const char *akcipher_alg_name(struct crypto_akcipher *tfm) | ||
37 | { | ||
38 | return crypto_akcipher_tfm(tfm)->__crt_alg->cra_name; | ||
39 | } | ||
40 | |||
41 | /** | ||
42 | * crypto_register_akcipher() -- Register public key algorithm | ||
43 | * | ||
44 | * Function registers an implementation of a public key verify algorithm | ||
45 | * | ||
46 | * @alg: algorithm definition | ||
47 | * | ||
48 | * Return: zero on success; error code in case of error | ||
49 | */ | ||
50 | int crypto_register_akcipher(struct akcipher_alg *alg); | ||
51 | |||
52 | /** | ||
53 | * crypto_unregister_akcipher() -- Unregister public key algorithm | ||
54 | * | ||
55 | * Function unregisters an implementation of a public key verify algorithm | ||
56 | * | ||
57 | * @alg: algorithm definition | ||
58 | */ | ||
59 | void crypto_unregister_akcipher(struct akcipher_alg *alg); | ||
60 | #endif | ||
diff --git a/include/linux/crypto.h b/include/linux/crypto.h index 25a4b71d6d1f..0e3f71a73e3b 100644 --- a/include/linux/crypto.h +++ b/include/linux/crypto.h | |||
@@ -53,6 +53,7 @@ | |||
53 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 | 53 | #define CRYPTO_ALG_TYPE_SHASH 0x00000009 |
54 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a | 54 | #define CRYPTO_ALG_TYPE_AHASH 0x0000000a |
55 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c | 55 | #define CRYPTO_ALG_TYPE_RNG 0x0000000c |
56 | #define CRYPTO_ALG_TYPE_AKCIPHER 0x0000000d | ||
56 | #define CRYPTO_ALG_TYPE_PCOMPRESS 0x0000000f | 57 | #define CRYPTO_ALG_TYPE_PCOMPRESS 0x0000000f |
57 | 58 | ||
58 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e | 59 | #define CRYPTO_ALG_TYPE_HASH_MASK 0x0000000e |
diff --git a/include/linux/cryptouser.h b/include/linux/cryptouser.h index 4abf2ea6a887..36efbbbf2f83 100644 --- a/include/linux/cryptouser.h +++ b/include/linux/cryptouser.h | |||
@@ -43,6 +43,7 @@ enum crypto_attr_type_t { | |||
43 | CRYPTOCFGA_REPORT_COMPRESS, /* struct crypto_report_comp */ | 43 | CRYPTOCFGA_REPORT_COMPRESS, /* struct crypto_report_comp */ |
44 | CRYPTOCFGA_REPORT_RNG, /* struct crypto_report_rng */ | 44 | CRYPTOCFGA_REPORT_RNG, /* struct crypto_report_rng */ |
45 | CRYPTOCFGA_REPORT_CIPHER, /* struct crypto_report_cipher */ | 45 | CRYPTOCFGA_REPORT_CIPHER, /* struct crypto_report_cipher */ |
46 | CRYPTOCFGA_REPORT_AKCIPHER, /* struct crypto_report_akcipher */ | ||
46 | __CRYPTOCFGA_MAX | 47 | __CRYPTOCFGA_MAX |
47 | 48 | ||
48 | #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1) | 49 | #define CRYPTOCFGA_MAX (__CRYPTOCFGA_MAX - 1) |
@@ -101,5 +102,9 @@ struct crypto_report_rng { | |||
101 | unsigned int seedsize; | 102 | unsigned int seedsize; |
102 | }; | 103 | }; |
103 | 104 | ||
105 | struct crypto_report_akcipher { | ||
106 | char type[CRYPTO_MAX_NAME]; | ||
107 | }; | ||
108 | |||
104 | #define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \ | 109 | #define CRYPTO_REPORT_MAXSIZE (sizeof(struct crypto_user_alg) + \ |
105 | sizeof(struct crypto_report_blkcipher)) | 110 | sizeof(struct crypto_report_blkcipher)) |