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