xref: /linux/include/crypto/akcipher.h (revision 621cde16e49b3ecf7d59a8106a20aaebfb4a59a9)
12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
23c339ab8STadeusz Struk /*
33c339ab8STadeusz Struk  * Public Key Encryption
43c339ab8STadeusz Struk  *
53c339ab8STadeusz Struk  * Copyright (c) 2015, Intel Corporation
63c339ab8STadeusz Struk  * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
73c339ab8STadeusz Struk  */
83c339ab8STadeusz Struk #ifndef _CRYPTO_AKCIPHER_H
93c339ab8STadeusz Struk #define _CRYPTO_AKCIPHER_H
10035d78a1SHerbert Xu 
11035d78a1SHerbert Xu #include <linux/atomic.h>
123c339ab8STadeusz Struk #include <linux/crypto.h>
133c339ab8STadeusz Struk 
143c339ab8STadeusz Struk /**
153c339ab8STadeusz Struk  * struct akcipher_request - public key request
163c339ab8STadeusz Struk  *
173c339ab8STadeusz Struk  * @base:	Common attributes for async crypto requests
1822287b0bSTadeusz Struk  * @src:	Source data
19c7381b01SVitaly Chikunov  *		For verify op this is signature + digest, in that case
20c7381b01SVitaly Chikunov  *		total size of @src is @src_len + @dst_len.
21c7381b01SVitaly Chikunov  * @dst:	Destination data (Should be NULL for verify op)
2222287b0bSTadeusz Struk  * @src_len:	Size of the input buffer
23c7381b01SVitaly Chikunov  *		For verify op it's size of signature part of @src, this part
24c7381b01SVitaly Chikunov  *		is supposed to be operated by cipher.
25c7381b01SVitaly Chikunov  * @dst_len:	Size of @dst buffer (for all ops except verify).
26c7381b01SVitaly Chikunov  *		It needs to be at least	as big as the expected result
27c7381b01SVitaly Chikunov  *		depending on the operation.
28e14a1f1eSLABBE Corentin  *		After operation it will be updated with the actual size of the
2922287b0bSTadeusz Struk  *		result.
3022287b0bSTadeusz Struk  *		In case of error where the dst sgl size was insufficient,
313c339ab8STadeusz Struk  *		it will be updated to the size required for the operation.
32c7381b01SVitaly Chikunov  *		For verify op this is size of digest part in @src.
333c339ab8STadeusz Struk  * @__ctx:	Start of private context data
343c339ab8STadeusz Struk  */
353c339ab8STadeusz Struk struct akcipher_request {
363c339ab8STadeusz Struk 	struct crypto_async_request base;
3722287b0bSTadeusz Struk 	struct scatterlist *src;
3822287b0bSTadeusz Struk 	struct scatterlist *dst;
393c339ab8STadeusz Struk 	unsigned int src_len;
403c339ab8STadeusz Struk 	unsigned int dst_len;
413c339ab8STadeusz Struk 	void *__ctx[] CRYPTO_MINALIGN_ATTR;
423c339ab8STadeusz Struk };
433c339ab8STadeusz Struk 
443c339ab8STadeusz Struk /**
453c339ab8STadeusz Struk  * struct crypto_akcipher - user-instantiated objects which encapsulate
463c339ab8STadeusz Struk  * algorithms and core processing logic
473c339ab8STadeusz Struk  *
483e71e5b0SHerbert Xu  * @reqsize:	Request context size required by algorithm implementation
493c339ab8STadeusz Struk  * @base:	Common crypto API algorithm data structure
503c339ab8STadeusz Struk  */
513c339ab8STadeusz Struk struct crypto_akcipher {
523e71e5b0SHerbert Xu 	unsigned int reqsize;
533e71e5b0SHerbert Xu 
543c339ab8STadeusz Struk 	struct crypto_tfm base;
553c339ab8STadeusz Struk };
563c339ab8STadeusz Struk 
573c339ab8STadeusz Struk /**
583c339ab8STadeusz Struk  * struct akcipher_alg - generic public key algorithm
593c339ab8STadeusz Struk  *
603c339ab8STadeusz Struk  * @sign:	Function performs a sign operation as defined by public key
613c339ab8STadeusz Struk  *		algorithm. In case of error, where the dst_len was insufficient,
623c339ab8STadeusz Struk  *		the req->dst_len will be updated to the size required for the
633c339ab8STadeusz Struk  *		operation
64c7381b01SVitaly Chikunov  * @verify:	Function performs a complete verify operation as defined by
65c7381b01SVitaly Chikunov  *		public key algorithm, returning verification status. Requires
66c7381b01SVitaly Chikunov  *		digest value as input parameter.
67e14a1f1eSLABBE Corentin  * @encrypt:	Function performs an encrypt operation as defined by public key
683c339ab8STadeusz Struk  *		algorithm. In case of error, where the dst_len was insufficient,
693c339ab8STadeusz Struk  *		the req->dst_len will be updated to the size required for the
703c339ab8STadeusz Struk  *		operation
713c339ab8STadeusz Struk  * @decrypt:	Function performs a decrypt operation as defined by public key
723c339ab8STadeusz Struk  *		algorithm. In case of error, where the dst_len was insufficient,
733c339ab8STadeusz Struk  *		the req->dst_len will be updated to the size required for the
743c339ab8STadeusz Struk  *		operation
7522287b0bSTadeusz Struk  * @set_pub_key: Function invokes the algorithm specific set public key
7622287b0bSTadeusz Struk  *		function, which knows how to decode and interpret
77f1774cb8SVitaly Chikunov  *		the BER encoded public key and parameters
7822287b0bSTadeusz Struk  * @set_priv_key: Function invokes the algorithm specific set private key
7922287b0bSTadeusz Struk  *		function, which knows how to decode and interpret
80f1774cb8SVitaly Chikunov  *		the BER encoded private key and parameters
81e14a1f1eSLABBE Corentin  * @max_size:	Function returns dest buffer size required for a given key.
823c339ab8STadeusz Struk  * @init:	Initialize the cryptographic transformation object.
833c339ab8STadeusz Struk  *		This function is used to initialize the cryptographic
843c339ab8STadeusz Struk  *		transformation object. This function is called only once at
853c339ab8STadeusz Struk  *		the instantiation time, right after the transformation context
863c339ab8STadeusz Struk  *		was allocated. In case the cryptographic hardware has some
873c339ab8STadeusz Struk  *		special requirements which need to be handled by software, this
883c339ab8STadeusz Struk  *		function shall check for the precise requirement of the
893c339ab8STadeusz Struk  *		transformation and put any software fallbacks in place.
903c339ab8STadeusz Struk  * @exit:	Deinitialize the cryptographic transformation object. This is a
913c339ab8STadeusz Struk  *		counterpart to @init, used to remove various changes set in
923c339ab8STadeusz Struk  *		@init.
933c339ab8STadeusz Struk  *
943c339ab8STadeusz Struk  * @base:	Common crypto API algorithm data structure
953c339ab8STadeusz Struk  */
963c339ab8STadeusz Struk struct akcipher_alg {
973c339ab8STadeusz Struk 	int (*sign)(struct akcipher_request *req);
983c339ab8STadeusz Struk 	int (*verify)(struct akcipher_request *req);
993c339ab8STadeusz Struk 	int (*encrypt)(struct akcipher_request *req);
1003c339ab8STadeusz Struk 	int (*decrypt)(struct akcipher_request *req);
10122287b0bSTadeusz Struk 	int (*set_pub_key)(struct crypto_akcipher *tfm, const void *key,
1023c339ab8STadeusz Struk 			   unsigned int keylen);
10322287b0bSTadeusz Struk 	int (*set_priv_key)(struct crypto_akcipher *tfm, const void *key,
10422287b0bSTadeusz Struk 			    unsigned int keylen);
105561f8e2dSTudor-Dan Ambarus 	unsigned int (*max_size)(struct crypto_akcipher *tfm);
1063c339ab8STadeusz Struk 	int (*init)(struct crypto_akcipher *tfm);
1073c339ab8STadeusz Struk 	void (*exit)(struct crypto_akcipher *tfm);
1083c339ab8STadeusz Struk 
1093c339ab8STadeusz Struk 	struct crypto_alg base;
1103c339ab8STadeusz Struk };
1113c339ab8STadeusz Struk 
1123c339ab8STadeusz Struk /**
1133c339ab8STadeusz Struk  * DOC: Generic Public Key API
1143c339ab8STadeusz Struk  *
1153c339ab8STadeusz Struk  * The Public Key API is used with the algorithms of type
1163c339ab8STadeusz Struk  * CRYPTO_ALG_TYPE_AKCIPHER (listed as type "akcipher" in /proc/crypto)
1173c339ab8STadeusz Struk  */
1183c339ab8STadeusz Struk 
1193c339ab8STadeusz Struk /**
120e1eabc05SStephan Mueller  * crypto_alloc_akcipher() - allocate AKCIPHER tfm handle
1213c339ab8STadeusz Struk  * @alg_name: is the cra_name / name or cra_driver_name / driver name of the
1223c339ab8STadeusz Struk  *	      public key algorithm e.g. "rsa"
1233c339ab8STadeusz Struk  * @type: specifies the type of the algorithm
1243c339ab8STadeusz Struk  * @mask: specifies the mask for the algorithm
1253c339ab8STadeusz Struk  *
1263c339ab8STadeusz Struk  * Allocate a handle for public key algorithm. The returned struct
1273c339ab8STadeusz Struk  * crypto_akcipher is the handle that is required for any subsequent
1283c339ab8STadeusz Struk  * API invocation for the public key operations.
1293c339ab8STadeusz Struk  *
1303c339ab8STadeusz Struk  * Return: allocated handle in case of success; IS_ERR() is true in case
1313c339ab8STadeusz Struk  *	   of an error, PTR_ERR() returns the error code.
1323c339ab8STadeusz Struk  */
1333c339ab8STadeusz Struk struct crypto_akcipher *crypto_alloc_akcipher(const char *alg_name, u32 type,
1343c339ab8STadeusz Struk 					      u32 mask);
1353c339ab8STadeusz Struk 
crypto_akcipher_tfm(struct crypto_akcipher * tfm)1363c339ab8STadeusz Struk static inline struct crypto_tfm *crypto_akcipher_tfm(
1373c339ab8STadeusz Struk 	struct crypto_akcipher *tfm)
1383c339ab8STadeusz Struk {
1393c339ab8STadeusz Struk 	return &tfm->base;
1403c339ab8STadeusz Struk }
1413c339ab8STadeusz Struk 
__crypto_akcipher_alg(struct crypto_alg * alg)1423c339ab8STadeusz Struk static inline struct akcipher_alg *__crypto_akcipher_alg(struct crypto_alg *alg)
1433c339ab8STadeusz Struk {
1443c339ab8STadeusz Struk 	return container_of(alg, struct akcipher_alg, base);
1453c339ab8STadeusz Struk }
1463c339ab8STadeusz Struk 
__crypto_akcipher_tfm(struct crypto_tfm * tfm)1473c339ab8STadeusz Struk static inline struct crypto_akcipher *__crypto_akcipher_tfm(
1483c339ab8STadeusz Struk 	struct crypto_tfm *tfm)
1493c339ab8STadeusz Struk {
1503c339ab8STadeusz Struk 	return container_of(tfm, struct crypto_akcipher, base);
1513c339ab8STadeusz Struk }
1523c339ab8STadeusz Struk 
crypto_akcipher_alg(struct crypto_akcipher * tfm)1533c339ab8STadeusz Struk static inline struct akcipher_alg *crypto_akcipher_alg(
1543c339ab8STadeusz Struk 	struct crypto_akcipher *tfm)
1553c339ab8STadeusz Struk {
1563c339ab8STadeusz Struk 	return __crypto_akcipher_alg(crypto_akcipher_tfm(tfm)->__crt_alg);
1573c339ab8STadeusz Struk }
1583c339ab8STadeusz Struk 
crypto_akcipher_reqsize(struct crypto_akcipher * tfm)1593c339ab8STadeusz Struk static inline unsigned int crypto_akcipher_reqsize(struct crypto_akcipher *tfm)
1603c339ab8STadeusz Struk {
1613e71e5b0SHerbert Xu 	return tfm->reqsize;
1623c339ab8STadeusz Struk }
1633c339ab8STadeusz Struk 
akcipher_request_set_tfm(struct akcipher_request * req,struct crypto_akcipher * tfm)1643c339ab8STadeusz Struk static inline void akcipher_request_set_tfm(struct akcipher_request *req,
1653c339ab8STadeusz Struk 					    struct crypto_akcipher *tfm)
1663c339ab8STadeusz Struk {
1673c339ab8STadeusz Struk 	req->base.tfm = crypto_akcipher_tfm(tfm);
1683c339ab8STadeusz Struk }
1693c339ab8STadeusz Struk 
crypto_akcipher_reqtfm(struct akcipher_request * req)1703c339ab8STadeusz Struk static inline struct crypto_akcipher *crypto_akcipher_reqtfm(
1713c339ab8STadeusz Struk 	struct akcipher_request *req)
1723c339ab8STadeusz Struk {
1733c339ab8STadeusz Struk 	return __crypto_akcipher_tfm(req->base.tfm);
1743c339ab8STadeusz Struk }
1753c339ab8STadeusz Struk 
1763c339ab8STadeusz Struk /**
177e1eabc05SStephan Mueller  * crypto_free_akcipher() - free AKCIPHER tfm handle
1783c339ab8STadeusz Struk  *
1793c339ab8STadeusz Struk  * @tfm: AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
18083681f2bSArd Biesheuvel  *
18183681f2bSArd Biesheuvel  * If @tfm is a NULL or error pointer, this function does nothing.
1823c339ab8STadeusz Struk  */
crypto_free_akcipher(struct crypto_akcipher * tfm)1833c339ab8STadeusz Struk static inline void crypto_free_akcipher(struct crypto_akcipher *tfm)
1843c339ab8STadeusz Struk {
1853c339ab8STadeusz Struk 	crypto_destroy_tfm(tfm, crypto_akcipher_tfm(tfm));
1863c339ab8STadeusz Struk }
1873c339ab8STadeusz Struk 
1883c339ab8STadeusz Struk /**
189e1eabc05SStephan Mueller  * akcipher_request_alloc() - allocates public key request
1903c339ab8STadeusz Struk  *
1913c339ab8STadeusz Struk  * @tfm:	AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
1923c339ab8STadeusz Struk  * @gfp:	allocation flags
1933c339ab8STadeusz Struk  *
1943c339ab8STadeusz Struk  * Return: allocated handle in case of success or NULL in case of an error.
1953c339ab8STadeusz Struk  */
akcipher_request_alloc(struct crypto_akcipher * tfm,gfp_t gfp)1963c339ab8STadeusz Struk static inline struct akcipher_request *akcipher_request_alloc(
1973c339ab8STadeusz Struk 	struct crypto_akcipher *tfm, gfp_t gfp)
1983c339ab8STadeusz Struk {
1993c339ab8STadeusz Struk 	struct akcipher_request *req;
2003c339ab8STadeusz Struk 
2013c339ab8STadeusz Struk 	req = kmalloc(sizeof(*req) + crypto_akcipher_reqsize(tfm), gfp);
2023c339ab8STadeusz Struk 	if (likely(req))
2033c339ab8STadeusz Struk 		akcipher_request_set_tfm(req, tfm);
2043c339ab8STadeusz Struk 
2053c339ab8STadeusz Struk 	return req;
2063c339ab8STadeusz Struk }
2073c339ab8STadeusz Struk 
2083c339ab8STadeusz Struk /**
209e1eabc05SStephan Mueller  * akcipher_request_free() - zeroize and free public key request
2103c339ab8STadeusz Struk  *
2113c339ab8STadeusz Struk  * @req:	request to free
2123c339ab8STadeusz Struk  */
akcipher_request_free(struct akcipher_request * req)2133c339ab8STadeusz Struk static inline void akcipher_request_free(struct akcipher_request *req)
2143c339ab8STadeusz Struk {
215453431a5SWaiman Long 	kfree_sensitive(req);
2163c339ab8STadeusz Struk }
2173c339ab8STadeusz Struk 
2183c339ab8STadeusz Struk /**
219e1eabc05SStephan Mueller  * akcipher_request_set_callback() - Sets an asynchronous callback.
2203c339ab8STadeusz Struk  *
2213c339ab8STadeusz Struk  * Callback will be called when an asynchronous operation on a given
2223c339ab8STadeusz Struk  * request is finished.
2233c339ab8STadeusz Struk  *
2243c339ab8STadeusz Struk  * @req:	request that the callback will be set for
2253c339ab8STadeusz Struk  * @flgs:	specify for instance if the operation may backlog
226e1eabc05SStephan Mueller  * @cmpl:	callback which will be called
2273c339ab8STadeusz Struk  * @data:	private data used by the caller
2283c339ab8STadeusz Struk  */
akcipher_request_set_callback(struct akcipher_request * req,u32 flgs,crypto_completion_t cmpl,void * data)2293c339ab8STadeusz Struk static inline void akcipher_request_set_callback(struct akcipher_request *req,
2303c339ab8STadeusz Struk 						 u32 flgs,
2313c339ab8STadeusz Struk 						 crypto_completion_t cmpl,
2323c339ab8STadeusz Struk 						 void *data)
2333c339ab8STadeusz Struk {
2343c339ab8STadeusz Struk 	req->base.complete = cmpl;
2353c339ab8STadeusz Struk 	req->base.data = data;
2363c339ab8STadeusz Struk 	req->base.flags = flgs;
2373c339ab8STadeusz Struk }
2383c339ab8STadeusz Struk 
2393c339ab8STadeusz Struk /**
240e1eabc05SStephan Mueller  * akcipher_request_set_crypt() - Sets request parameters
2413c339ab8STadeusz Struk  *
2423c339ab8STadeusz Struk  * Sets parameters required by crypto operation
2433c339ab8STadeusz Struk  *
2443c339ab8STadeusz Struk  * @req:	public key request
24522287b0bSTadeusz Struk  * @src:	ptr to input scatter list
246c7381b01SVitaly Chikunov  * @dst:	ptr to output scatter list or NULL for verify op
24722287b0bSTadeusz Struk  * @src_len:	size of the src input scatter list to be processed
248c7381b01SVitaly Chikunov  * @dst_len:	size of the dst output scatter list or size of signature
249c7381b01SVitaly Chikunov  *		portion in @src for verify op
2503c339ab8STadeusz Struk  */
akcipher_request_set_crypt(struct akcipher_request * req,struct scatterlist * src,struct scatterlist * dst,unsigned int src_len,unsigned int dst_len)2513c339ab8STadeusz Struk static inline void akcipher_request_set_crypt(struct akcipher_request *req,
25222287b0bSTadeusz Struk 					      struct scatterlist *src,
25322287b0bSTadeusz Struk 					      struct scatterlist *dst,
2543c339ab8STadeusz Struk 					      unsigned int src_len,
2553c339ab8STadeusz Struk 					      unsigned int dst_len)
2563c339ab8STadeusz Struk {
2573c339ab8STadeusz Struk 	req->src = src;
2583c339ab8STadeusz Struk 	req->dst = dst;
2593c339ab8STadeusz Struk 	req->src_len = src_len;
2603c339ab8STadeusz Struk 	req->dst_len = dst_len;
2613c339ab8STadeusz Struk }
2623c339ab8STadeusz Struk 
2633c339ab8STadeusz Struk /**
264e1eabc05SStephan Mueller  * crypto_akcipher_maxsize() - Get len for output buffer
26522287b0bSTadeusz Struk  *
266561f8e2dSTudor-Dan Ambarus  * Function returns the dest buffer size required for a given key.
267561f8e2dSTudor-Dan Ambarus  * Function assumes that the key is already set in the transformation. If this
268561f8e2dSTudor-Dan Ambarus  * function is called without a setkey or with a failed setkey, you will end up
269561f8e2dSTudor-Dan Ambarus  * in a NULL dereference.
27022287b0bSTadeusz Struk  *
27122287b0bSTadeusz Struk  * @tfm:	AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
27222287b0bSTadeusz Struk  */
crypto_akcipher_maxsize(struct crypto_akcipher * tfm)273561f8e2dSTudor-Dan Ambarus static inline unsigned int crypto_akcipher_maxsize(struct crypto_akcipher *tfm)
27422287b0bSTadeusz Struk {
27522287b0bSTadeusz Struk 	struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
27622287b0bSTadeusz Struk 
27722287b0bSTadeusz Struk 	return alg->max_size(tfm);
27822287b0bSTadeusz Struk }
27922287b0bSTadeusz Struk 
28022287b0bSTadeusz Struk /**
281e1eabc05SStephan Mueller  * crypto_akcipher_encrypt() - Invoke public key encrypt operation
2823c339ab8STadeusz Struk  *
2833c339ab8STadeusz Struk  * Function invokes the specific public key encrypt operation for a given
2843c339ab8STadeusz Struk  * public key algorithm
2853c339ab8STadeusz Struk  *
2863c339ab8STadeusz Struk  * @req:	asymmetric key request
2873c339ab8STadeusz Struk  *
2883c339ab8STadeusz Struk  * Return: zero on success; error code in case of error
2893c339ab8STadeusz Struk  */
crypto_akcipher_encrypt(struct akcipher_request * req)2903c339ab8STadeusz Struk static inline int crypto_akcipher_encrypt(struct akcipher_request *req)
2913c339ab8STadeusz Struk {
2923c339ab8STadeusz Struk 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
2933c339ab8STadeusz Struk 
294*29ce50e0SEric Biggers 	return crypto_akcipher_alg(tfm)->encrypt(req);
2953c339ab8STadeusz Struk }
2963c339ab8STadeusz Struk 
2973c339ab8STadeusz Struk /**
298e1eabc05SStephan Mueller  * crypto_akcipher_decrypt() - Invoke public key decrypt operation
2993c339ab8STadeusz Struk  *
3003c339ab8STadeusz Struk  * Function invokes the specific public key decrypt operation for a given
3013c339ab8STadeusz Struk  * public key algorithm
3023c339ab8STadeusz Struk  *
3033c339ab8STadeusz Struk  * @req:	asymmetric key request
3043c339ab8STadeusz Struk  *
3053c339ab8STadeusz Struk  * Return: zero on success; error code in case of error
3063c339ab8STadeusz Struk  */
crypto_akcipher_decrypt(struct akcipher_request * req)3073c339ab8STadeusz Struk static inline int crypto_akcipher_decrypt(struct akcipher_request *req)
3083c339ab8STadeusz Struk {
3093c339ab8STadeusz Struk 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
3103c339ab8STadeusz Struk 
311*29ce50e0SEric Biggers 	return crypto_akcipher_alg(tfm)->decrypt(req);
3123c339ab8STadeusz Struk }
3133c339ab8STadeusz Struk 
3143c339ab8STadeusz Struk /**
315addde1f2SHerbert Xu  * crypto_akcipher_sync_encrypt() - Invoke public key encrypt operation
316addde1f2SHerbert Xu  *
317addde1f2SHerbert Xu  * Function invokes the specific public key encrypt operation for a given
318addde1f2SHerbert Xu  * public key algorithm
319addde1f2SHerbert Xu  *
320addde1f2SHerbert Xu  * @tfm:	AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
321addde1f2SHerbert Xu  * @src:	source buffer
322addde1f2SHerbert Xu  * @slen:	source length
323595729b6SRandy Dunlap  * @dst:	destination obuffer
324addde1f2SHerbert Xu  * @dlen:	destination length
325addde1f2SHerbert Xu  *
326addde1f2SHerbert Xu  * Return: zero on success; error code in case of error
327addde1f2SHerbert Xu  */
328addde1f2SHerbert Xu int crypto_akcipher_sync_encrypt(struct crypto_akcipher *tfm,
329addde1f2SHerbert Xu 				 const void *src, unsigned int slen,
330addde1f2SHerbert Xu 				 void *dst, unsigned int dlen);
331addde1f2SHerbert Xu 
332addde1f2SHerbert Xu /**
333addde1f2SHerbert Xu  * crypto_akcipher_sync_decrypt() - Invoke public key decrypt operation
334addde1f2SHerbert Xu  *
335addde1f2SHerbert Xu  * Function invokes the specific public key decrypt operation for a given
336addde1f2SHerbert Xu  * public key algorithm
337addde1f2SHerbert Xu  *
338addde1f2SHerbert Xu  * @tfm:	AKCIPHER tfm handle allocated with crypto_alloc_akcipher()
339addde1f2SHerbert Xu  * @src:	source buffer
340addde1f2SHerbert Xu  * @slen:	source length
341595729b6SRandy Dunlap  * @dst:	destination obuffer
342addde1f2SHerbert Xu  * @dlen:	destination length
343addde1f2SHerbert Xu  *
344addde1f2SHerbert Xu  * Return: Output length on success; error code in case of error
345addde1f2SHerbert Xu  */
346addde1f2SHerbert Xu int crypto_akcipher_sync_decrypt(struct crypto_akcipher *tfm,
347addde1f2SHerbert Xu 				 const void *src, unsigned int slen,
348addde1f2SHerbert Xu 				 void *dst, unsigned int dlen);
349addde1f2SHerbert Xu 
350addde1f2SHerbert Xu /**
351e1eabc05SStephan Mueller  * crypto_akcipher_sign() - Invoke public key sign operation
3523c339ab8STadeusz Struk  *
3533c339ab8STadeusz Struk  * Function invokes the specific public key sign operation for a given
3543c339ab8STadeusz Struk  * public key algorithm
3553c339ab8STadeusz Struk  *
3563c339ab8STadeusz Struk  * @req:	asymmetric key request
3573c339ab8STadeusz Struk  *
3583c339ab8STadeusz Struk  * Return: zero on success; error code in case of error
3593c339ab8STadeusz Struk  */
crypto_akcipher_sign(struct akcipher_request * req)3603c339ab8STadeusz Struk static inline int crypto_akcipher_sign(struct akcipher_request *req)
3613c339ab8STadeusz Struk {
3623c339ab8STadeusz Struk 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
3633c339ab8STadeusz Struk 
364*29ce50e0SEric Biggers 	return crypto_akcipher_alg(tfm)->sign(req);
3653c339ab8STadeusz Struk }
3663c339ab8STadeusz Struk 
3673c339ab8STadeusz Struk /**
368c7381b01SVitaly Chikunov  * crypto_akcipher_verify() - Invoke public key signature verification
3693c339ab8STadeusz Struk  *
370c7381b01SVitaly Chikunov  * Function invokes the specific public key signature verification operation
371c7381b01SVitaly Chikunov  * for a given public key algorithm.
3723c339ab8STadeusz Struk  *
3733c339ab8STadeusz Struk  * @req:	asymmetric key request
3743c339ab8STadeusz Struk  *
375c7381b01SVitaly Chikunov  * Note: req->dst should be NULL, req->src should point to SG of size
376c7381b01SVitaly Chikunov  * (req->src_size + req->dst_size), containing signature (of req->src_size
377c7381b01SVitaly Chikunov  * length) with appended digest (of req->dst_size length).
378c7381b01SVitaly Chikunov  *
379c7381b01SVitaly Chikunov  * Return: zero on verification success; error code in case of error.
3803c339ab8STadeusz Struk  */
crypto_akcipher_verify(struct akcipher_request * req)3813c339ab8STadeusz Struk static inline int crypto_akcipher_verify(struct akcipher_request *req)
3823c339ab8STadeusz Struk {
3833c339ab8STadeusz Struk 	struct crypto_akcipher *tfm = crypto_akcipher_reqtfm(req);
3843c339ab8STadeusz Struk 
385*29ce50e0SEric Biggers 	return crypto_akcipher_alg(tfm)->verify(req);
3863c339ab8STadeusz Struk }
3873c339ab8STadeusz Struk 
3883c339ab8STadeusz Struk /**
389e1eabc05SStephan Mueller  * crypto_akcipher_set_pub_key() - Invoke set public key operation
3903c339ab8STadeusz Struk  *
3913c339ab8STadeusz Struk  * Function invokes the algorithm specific set key function, which knows
392f1774cb8SVitaly Chikunov  * how to decode and interpret the encoded key and parameters
3933c339ab8STadeusz Struk  *
3943c339ab8STadeusz Struk  * @tfm:	tfm handle
395f1774cb8SVitaly Chikunov  * @key:	BER encoded public key, algo OID, paramlen, BER encoded
396f1774cb8SVitaly Chikunov  *		parameters
397f1774cb8SVitaly Chikunov  * @keylen:	length of the key (not including other data)
3983c339ab8STadeusz Struk  *
3993c339ab8STadeusz Struk  * Return: zero on success; error code in case of error
4003c339ab8STadeusz Struk  */
crypto_akcipher_set_pub_key(struct crypto_akcipher * tfm,const void * key,unsigned int keylen)40122287b0bSTadeusz Struk static inline int crypto_akcipher_set_pub_key(struct crypto_akcipher *tfm,
40222287b0bSTadeusz Struk 					      const void *key,
4033c339ab8STadeusz Struk 					      unsigned int keylen)
4043c339ab8STadeusz Struk {
4053c339ab8STadeusz Struk 	struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
4063c339ab8STadeusz Struk 
40722287b0bSTadeusz Struk 	return alg->set_pub_key(tfm, key, keylen);
40822287b0bSTadeusz Struk }
40922287b0bSTadeusz Struk 
41022287b0bSTadeusz Struk /**
411e1eabc05SStephan Mueller  * crypto_akcipher_set_priv_key() - Invoke set private key operation
41222287b0bSTadeusz Struk  *
41322287b0bSTadeusz Struk  * Function invokes the algorithm specific set key function, which knows
414f1774cb8SVitaly Chikunov  * how to decode and interpret the encoded key and parameters
41522287b0bSTadeusz Struk  *
41622287b0bSTadeusz Struk  * @tfm:	tfm handle
417f1774cb8SVitaly Chikunov  * @key:	BER encoded private key, algo OID, paramlen, BER encoded
418f1774cb8SVitaly Chikunov  *		parameters
419f1774cb8SVitaly Chikunov  * @keylen:	length of the key (not including other data)
42022287b0bSTadeusz Struk  *
42122287b0bSTadeusz Struk  * Return: zero on success; error code in case of error
42222287b0bSTadeusz Struk  */
crypto_akcipher_set_priv_key(struct crypto_akcipher * tfm,const void * key,unsigned int keylen)42322287b0bSTadeusz Struk static inline int crypto_akcipher_set_priv_key(struct crypto_akcipher *tfm,
42422287b0bSTadeusz Struk 					       const void *key,
42522287b0bSTadeusz Struk 					       unsigned int keylen)
42622287b0bSTadeusz Struk {
42722287b0bSTadeusz Struk 	struct akcipher_alg *alg = crypto_akcipher_alg(tfm);
42822287b0bSTadeusz Struk 
42922287b0bSTadeusz Struk 	return alg->set_priv_key(tfm, key, keylen);
4303c339ab8STadeusz Struk }
4313c339ab8STadeusz Struk #endif
432