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_H
9#define _CRYPTO_AKCIPHER_H
10
11#include <linux/atomic.h>
12#include <linux/crypto.h>
13
14/**
15 * struct akcipher_request - public key cipher request
16 *
17 * @base: Common attributes for async crypto requests
18 * @src: Source data
19 * @dst: Destination data
20 * @src_len: Size of the input buffer
21 * @dst_len: Size of @dst buffer
22 * It needs to be at least as big as the expected result
23 * depending on the operation.
24 * After operation it will be updated with the actual size of the
25 * result.
26 * In case of error where the dst sgl size was insufficient,
27 * it will be updated to the size required for the operation.
28 * @__ctx: Start of private context data
29 */
30struct akcipher_request {
31 struct crypto_async_request base;
32 struct scatterlist *src;
33 struct scatterlist *dst;
34 unsigned int src_len;
35 unsigned int dst_len;
36 void *__ctx[] CRYPTO_MINALIGN_ATTR;
37};
38
39/**
40 * struct crypto_akcipher - user-instantiated objects which encapsulate
41 * algorithms and core processing logic
42 *
43 * @reqsize: Request context size required by algorithm implementation
44 * @base: Common crypto API algorithm data structure
45 */
46struct crypto_akcipher {
47 unsigned int reqsize;
48
49 struct crypto_tfm base;
50};
51
52/**
53 * struct akcipher_alg - generic public key cipher algorithm
54 *
55 * @encrypt: Function performs an encrypt operation as defined by public key
56 * algorithm. In case of error, where the dst_len was insufficient,
57 * the req->dst_len will be updated to the size required for the
58 * operation
59 * @decrypt: Function performs a decrypt operation as defined by public key
60 * algorithm. In case of error, where the dst_len was insufficient,
61 * the req->dst_len will be updated to the size required for the
62 * operation
63 * @set_pub_key: Function invokes the algorithm specific set public key
64 * function, which knows how to decode and interpret
65 * the BER encoded public key and parameters
66 * @set_priv_key: Function invokes the algorithm specific set private key
67 * function, which knows how to decode and interpret
68 * the BER encoded private key and parameters
69 * @max_size: Function returns dest buffer size required for a given key.
70 * @init: Initialize the cryptographic transformation object.
71 * This function is used to initialize the cryptographic
72 * transformation object. This function is called only once at
73 * the instantiation time, right after the transformation context
74 * was allocated. In case the cryptographic hardware has some
75 * special requirements which need to be handled by software, this
76 * function shall check for the precise requirement of the
77 * transformation and put any software fallbacks in place.
78 * @exit: Deinitialize the cryptographic transformation object. This is a
79 * counterpart to @init, used to remove various changes set in
80 * @init.
81 *
82 * @base: Common crypto API algorithm data structure
83 */
84struct akcipher_alg {
85 int (*encrypt)(struct akcipher_request *req);
86 int (*decrypt)(struct akcipher_request *req);
87 int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key,
88 unsigned int keylen);
89 int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key,
90 unsigned int keylen);
91 unsigned int (*max_size)(struct crypto_akcipher *tfm);
92 int (*init)(struct crypto_akcipher *tfm);
93 void (*exit)(struct crypto_akcipher *tfm);
94
95 struct crypto_alg base;
96};
97
98/**
99 * DOC: Generic Public Key Cipher API
100 *
101 * The Public Key Cipher API is used with the algorithms of type
102 * CRYPTO_ALG_TYPE_AKCIPHER (listed as type "akcipher" in /proc/crypto)
103 */
104
105/**
106 * crypto_alloc_akcipher() - allocate AKCIPHER tfm handle
107 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
108 * public key algorithm e.g. "rsa"
109 * @type: specifies the type of the algorithm
110 * @mask: specifies the mask for the algorithm
111 *
112 * Allocate a handle for public key algorithm. The returned struct
113 * crypto_akcipher is the handle that is required for any subsequent
114 * API invocation for the public key operations.
115 *
116 * Return: allocated handle in case of success; IS_ERR() is true in case
117 * of an error, PTR_ERR() returns the error code.
118 */
119struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type,
120 u32 mask);
121
122static inline struct crypto_tfm *crypto_akcipher_tfm(
123 struct crypto_akcipher *tfm)
124{
125 return &tfm->base;
126}
127
128static inline struct akcipher_alg *__crypto_akcipher_alg(struct crypto_alg *alg)
129{
130 return container_of(alg, struct akcipher_alg, base);
131}
132
133static inline struct crypto_akcipher *__crypto_akcipher_tfm(
134 struct crypto_tfm *tfm)
135{
136 return container_of(tfm, struct crypto_akcipher, base);
137}
138
139static inline struct akcipher_alg *crypto_akcipher_alg(
140 struct crypto_akcipher *tfm)
141{
142 return __crypto_akcipher_alg(crypto_akcipher_tfm(tfm)->__crt_alg);
143}
144
145static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm)
146{
147 return tfm->reqsize;
148}
149
150static inline void akcipher_request_set_tfm(struct akcipher_request *req,
151 struct crypto_akcipher *tfm)
152{
153 req->base.tfm = crypto_akcipher_tfm(tfm);
154}
155
156static inline struct crypto_akcipher *crypto_akcipher_reqtfm(
157 struct akcipher_request *req)
158{
159 return __crypto_akcipher_tfm(req->base.tfm);
160}
161
162/**
163 * crypto_free_akcipher() - free AKCIPHER tfm handle
164 *
165 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
166 *
167 * If @tfm is a NULL or error pointer, this function does nothing.
168 */
169static inline void crypto_free_akcipher(struct crypto_akcipher *tfm)
170{
171 crypto_destroy_tfm(tfm, crypto_akcipher_tfm(tfm));
172}
173
174/**
175 * akcipher_request_alloc() - allocates public key request
176 *
177 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
178 * @gfp: allocation flags
179 *
180 * Return: allocated handle in case of success or NULL in case of an error.
181 */
182static inline struct akcipher_request *akcipher_request_alloc(
183 struct crypto_akcipher *tfm, gfp_t gfp)
184{
185 struct akcipher_request *req;
186
187 req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp);
188 if (likely(req))
189 akcipher_request_set_tfm(req, tfm);
190
191 return req;
192}
193
194/**
195 * akcipher_request_free() - zeroize and free public key request
196 *
197 * @req: request to free
198 */
199static inline void akcipher_request_free(struct akcipher_request *req)
200{
201 kfree_sensitive(req);
202}
203
204/**
205 * akcipher_request_set_callback() - Sets an asynchronous callback.
206 *
207 * Callback will be called when an asynchronous operation on a given
208 * request is finished.
209 *
210 * @req: request that the callback will be set for
211 * @flgs: specify for instance if the operation may backlog
212 * @cmpl: callback which will be called
213 * @data: private data used by the caller
214 */
215static inline void akcipher_request_set_callback(struct akcipher_request *req,
216 u32 flgs,
217 crypto_completion_t cmpl,
218 void *data)
219{
220 req->base.complete = cmpl;
221 req->base.data = data;
222 req->base.flags = flgs;
223}
224
225/**
226 * akcipher_request_set_crypt() - Sets request parameters
227 *
228 * Sets parameters required by crypto operation
229 *
230 * @req: public key request
231 * @src: ptr to input scatter list
232 * @dst: ptr to output scatter list
233 * @src_len: size of the src input scatter list to be processed
234 * @dst_len: size of the dst output scatter list
235 */
236static inline void akcipher_request_set_crypt(struct akcipher_request *req,
237 struct scatterlist *src,
238 struct scatterlist *dst,
239 unsigned int src_len,
240 unsigned int dst_len)
241{
242 req->src = src;
243 req->dst = dst;
244 req->src_len = src_len;
245 req->dst_len = dst_len;
246}
247
248/**
249 * crypto_akcipher_maxsize() - Get len for output buffer
250 *
251 * Function returns the dest buffer size required for a given key.
252 * Function assumes that the key is already set in the transformation. If this
253 * function is called without a setkey or with a failed setkey, you will end up
254 * in a NULL dereference.
255 *
256 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
257 */
258static inline unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)
259{
260 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
261
262 return alg->max_size(tfm);
263}
264
265/**
266 * crypto_akcipher_encrypt() - Invoke public key encrypt operation
267 *
268 * Function invokes the specific public key encrypt operation for a given
269 * public key algorithm
270 *
271 * @req: asymmetric key request
272 *
273 * Return: zero on success; error code in case of error
274 */
275static inline int crypto_akcipher_encrypt(struct akcipher_request *req)
276{
277 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
278
279 return crypto_akcipher_alg(tfm)->encrypt(req);
280}
281
282/**
283 * crypto_akcipher_decrypt() - Invoke public key decrypt operation
284 *
285 * Function invokes the specific public key decrypt operation for a given
286 * public key algorithm
287 *
288 * @req: asymmetric key request
289 *
290 * Return: zero on success; error code in case of error
291 */
292static inline int crypto_akcipher_decrypt(struct akcipher_request *req)
293{
294 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
295
296 return crypto_akcipher_alg(tfm)->decrypt(req);
297}
298
299/**
300 * crypto_akcipher_sync_encrypt() - Invoke public key encrypt operation
301 *
302 * Function invokes the specific public key encrypt operation for a given
303 * public key algorithm
304 *
305 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
306 * @src: source buffer
307 * @slen: source length
308 * @dst: destination obuffer
309 * @dlen: destination length
310 *
311 * Return: zero on success; error code in case of error
312 */
313int crypto_akcipher_sync_encrypt(struct crypto_akcipher *tfm,
314 const void *src, unsigned int slen,
315 void *dst, unsigned int dlen);
316
317/**
318 * crypto_akcipher_sync_decrypt() - Invoke public key decrypt operation
319 *
320 * Function invokes the specific public key decrypt operation for a given
321 * public key algorithm
322 *
323 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
324 * @src: source buffer
325 * @slen: source length
326 * @dst: destination obuffer
327 * @dlen: destination length
328 *
329 * Return: Output length on success; error code in case of error
330 */
331int crypto_akcipher_sync_decrypt(struct crypto_akcipher *tfm,
332 const void *src, unsigned int slen,
333 void *dst, unsigned int dlen);
334
335/**
336 * crypto_akcipher_set_pub_key() - Invoke set public key operation
337 *
338 * Function invokes the algorithm specific set key function, which knows
339 * how to decode and interpret the encoded key and parameters
340 *
341 * @tfm: tfm handle
342 * @key: BER encoded public key, algo OID, paramlen, BER encoded
343 * parameters
344 * @keylen: length of the key (not including other data)
345 *
346 * Return: zero on success; error code in case of error
347 */
348static inline int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm,
349 const void *key,
350 unsigned int keylen)
351{
352 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
353
354 return alg->set_pub_key(tfm, key, keylen);
355}
356
357/**
358 * crypto_akcipher_set_priv_key() - Invoke set private key operation
359 *
360 * Function invokes the algorithm specific set key function, which knows
361 * how to decode and interpret the encoded key and parameters
362 *
363 * @tfm: tfm handle
364 * @key: BER encoded private key, algo OID, paramlen, BER encoded
365 * parameters
366 * @keylen: length of the key (not including other data)
367 *
368 * Return: zero on success; error code in case of error
369 */
370static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
371 const void *key,
372 unsigned int keylen)
373{
374 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
375
376 return alg->set_priv_key(tfm, key, keylen);
377}
378#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_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: Source data
22 * @dst: Destination data
23 * @src_len: Size of the input buffer
24 * @dst_len: Size of the output buffer. It needs to be at least
25 * as big as the expected result depending on the operation
26 * After operation it will be updated with the actual size of the
27 * result.
28 * In case of error where the dst sgl size was insufficient,
29 * it will be updated to the size required for the operation.
30 * @__ctx: Start of private context data
31 */
32struct akcipher_request {
33 struct crypto_async_request base;
34 struct scatterlist *src;
35 struct scatterlist *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 */
47struct 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 encrypt 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 * @set_pub_key: Function invokes the algorithm specific set public key
71 * function, which knows how to decode and interpret
72 * the BER encoded public key
73 * @set_priv_key: Function invokes the algorithm specific set private key
74 * function, which knows how to decode and interpret
75 * the BER encoded private key
76 * @max_size: Function returns dest buffer size required for a given key.
77 * @init: Initialize the cryptographic transformation object.
78 * This function is used to initialize the cryptographic
79 * transformation object. This function is called only once at
80 * the instantiation time, right after the transformation context
81 * was allocated. In case the cryptographic hardware has some
82 * special requirements which need to be handled by software, this
83 * function shall check for the precise requirement of the
84 * transformation and put any software fallbacks in place.
85 * @exit: Deinitialize the cryptographic transformation object. This is a
86 * counterpart to @init, used to remove various changes set in
87 * @init.
88 *
89 * @reqsize: Request context size required by algorithm implementation
90 * @base: Common crypto API algorithm data structure
91 */
92struct akcipher_alg {
93 int (*sign)(struct akcipher_request *req);
94 int (*verify)(struct akcipher_request *req);
95 int (*encrypt)(struct akcipher_request *req);
96 int (*decrypt)(struct akcipher_request *req);
97 int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key,
98 unsigned int keylen);
99 int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key,
100 unsigned int keylen);
101 int (*max_size)(struct crypto_akcipher *tfm);
102 int (*init)(struct crypto_akcipher *tfm);
103 void (*exit)(struct crypto_akcipher *tfm);
104
105 unsigned int reqsize;
106 struct crypto_alg base;
107};
108
109/**
110 * DOC: Generic Public Key API
111 *
112 * The Public Key API is used with the algorithms of type
113 * CRYPTO_ALG_TYPE_AKCIPHER (listed as type "akcipher" in /proc/crypto)
114 */
115
116/**
117 * crypto_alloc_akcipher() - allocate AKCIPHER tfm handle
118 * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
119 * public key algorithm e.g. "rsa"
120 * @type: specifies the type of the algorithm
121 * @mask: specifies the mask for the algorithm
122 *
123 * Allocate a handle for public key algorithm. The returned struct
124 * crypto_akcipher is the handle that is required for any subsequent
125 * API invocation for the public key operations.
126 *
127 * Return: allocated handle in case of success; IS_ERR() is true in case
128 * of an error, PTR_ERR() returns the error code.
129 */
130struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type,
131 u32 mask);
132
133static inline struct crypto_tfm *crypto_akcipher_tfm(
134 struct crypto_akcipher *tfm)
135{
136 return &tfm->base;
137}
138
139static inline struct akcipher_alg *__crypto_akcipher_alg(struct crypto_alg *alg)
140{
141 return container_of(alg, struct akcipher_alg, base);
142}
143
144static inline struct crypto_akcipher *__crypto_akcipher_tfm(
145 struct crypto_tfm *tfm)
146{
147 return container_of(tfm, struct crypto_akcipher, base);
148}
149
150static inline struct akcipher_alg *crypto_akcipher_alg(
151 struct crypto_akcipher *tfm)
152{
153 return __crypto_akcipher_alg(crypto_akcipher_tfm(tfm)->__crt_alg);
154}
155
156static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm)
157{
158 return crypto_akcipher_alg(tfm)->reqsize;
159}
160
161static inline void akcipher_request_set_tfm(struct akcipher_request *req,
162 struct crypto_akcipher *tfm)
163{
164 req->base.tfm = crypto_akcipher_tfm(tfm);
165}
166
167static inline struct crypto_akcipher *crypto_akcipher_reqtfm(
168 struct akcipher_request *req)
169{
170 return __crypto_akcipher_tfm(req->base.tfm);
171}
172
173/**
174 * crypto_free_akcipher() - free AKCIPHER tfm handle
175 *
176 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
177 */
178static inline void crypto_free_akcipher(struct crypto_akcipher *tfm)
179{
180 crypto_destroy_tfm(tfm, crypto_akcipher_tfm(tfm));
181}
182
183/**
184 * akcipher_request_alloc() - allocates public key request
185 *
186 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
187 * @gfp: allocation flags
188 *
189 * Return: allocated handle in case of success or NULL in case of an error.
190 */
191static inline struct akcipher_request *akcipher_request_alloc(
192 struct crypto_akcipher *tfm, gfp_t gfp)
193{
194 struct akcipher_request *req;
195
196 req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp);
197 if (likely(req))
198 akcipher_request_set_tfm(req, tfm);
199
200 return req;
201}
202
203/**
204 * akcipher_request_free() - zeroize and free public key request
205 *
206 * @req: request to free
207 */
208static inline void akcipher_request_free(struct akcipher_request *req)
209{
210 kzfree(req);
211}
212
213/**
214 * akcipher_request_set_callback() - Sets an asynchronous callback.
215 *
216 * Callback will be called when an asynchronous operation on a given
217 * request is finished.
218 *
219 * @req: request that the callback will be set for
220 * @flgs: specify for instance if the operation may backlog
221 * @cmpl: callback which will be called
222 * @data: private data used by the caller
223 */
224static inline void akcipher_request_set_callback(struct akcipher_request *req,
225 u32 flgs,
226 crypto_completion_t cmpl,
227 void *data)
228{
229 req->base.complete = cmpl;
230 req->base.data = data;
231 req->base.flags = flgs;
232}
233
234/**
235 * akcipher_request_set_crypt() - Sets request parameters
236 *
237 * Sets parameters required by crypto operation
238 *
239 * @req: public key request
240 * @src: ptr to input scatter list
241 * @dst: ptr to output scatter list
242 * @src_len: size of the src input scatter list to be processed
243 * @dst_len: size of the dst output scatter list
244 */
245static inline void akcipher_request_set_crypt(struct akcipher_request *req,
246 struct scatterlist *src,
247 struct scatterlist *dst,
248 unsigned int src_len,
249 unsigned int dst_len)
250{
251 req->src = src;
252 req->dst = dst;
253 req->src_len = src_len;
254 req->dst_len = dst_len;
255}
256
257/**
258 * crypto_akcipher_maxsize() - Get len for output buffer
259 *
260 * Function returns the dest buffer size required for a given key
261 *
262 * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
263 *
264 * Return: minimum len for output buffer or error code in key hasn't been set
265 */
266static inline int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)
267{
268 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
269
270 return alg->max_size(tfm);
271}
272
273/**
274 * crypto_akcipher_encrypt() - Invoke public key encrypt operation
275 *
276 * Function invokes the specific public key encrypt operation for a given
277 * public key algorithm
278 *
279 * @req: asymmetric key request
280 *
281 * Return: zero on success; error code in case of error
282 */
283static inline int crypto_akcipher_encrypt(struct akcipher_request *req)
284{
285 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
286 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
287
288 return alg->encrypt(req);
289}
290
291/**
292 * crypto_akcipher_decrypt() - Invoke public key decrypt operation
293 *
294 * Function invokes the specific public key decrypt operation for a given
295 * public key algorithm
296 *
297 * @req: asymmetric key request
298 *
299 * Return: zero on success; error code in case of error
300 */
301static inline int crypto_akcipher_decrypt(struct akcipher_request *req)
302{
303 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
304 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
305
306 return alg->decrypt(req);
307}
308
309/**
310 * crypto_akcipher_sign() - Invoke public key sign operation
311 *
312 * Function invokes the specific public key sign operation for a given
313 * public key algorithm
314 *
315 * @req: asymmetric key request
316 *
317 * Return: zero on success; error code in case of error
318 */
319static inline int crypto_akcipher_sign(struct akcipher_request *req)
320{
321 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
322 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
323
324 return alg->sign(req);
325}
326
327/**
328 * crypto_akcipher_verify() - Invoke public key verify operation
329 *
330 * Function invokes the specific public key verify operation for a given
331 * public key algorithm
332 *
333 * @req: asymmetric key request
334 *
335 * Return: zero on success; error code in case of error
336 */
337static inline int crypto_akcipher_verify(struct akcipher_request *req)
338{
339 struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
340 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
341
342 return alg->verify(req);
343}
344
345/**
346 * crypto_akcipher_set_pub_key() - Invoke set public key operation
347 *
348 * Function invokes the algorithm specific set key function, which knows
349 * how to decode and interpret the encoded key
350 *
351 * @tfm: tfm handle
352 * @key: BER encoded public key
353 * @keylen: length of the key
354 *
355 * Return: zero on success; error code in case of error
356 */
357static inline int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm,
358 const void *key,
359 unsigned int keylen)
360{
361 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
362
363 return alg->set_pub_key(tfm, key, keylen);
364}
365
366/**
367 * crypto_akcipher_set_priv_key() - Invoke set private key operation
368 *
369 * Function invokes the algorithm specific set key function, which knows
370 * how to decode and interpret the encoded key
371 *
372 * @tfm: tfm handle
373 * @key: BER encoded private key
374 * @keylen: length of the key
375 *
376 * Return: zero on success; error code in case of error
377 */
378static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
379 const void *key,
380 unsigned int keylen)
381{
382 struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
383
384 return alg->set_priv_key(tfm, key, keylen);
385}
386#endif