18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Key-agreement Protocol Primitives (KPP)
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2016, Intel Corporation
68c2ecf20Sopenharmony_ci * Authors: Salvatore Benedetto <salvatore.benedetto@intel.com>
78c2ecf20Sopenharmony_ci */
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#ifndef _CRYPTO_KPP_
108c2ecf20Sopenharmony_ci#define _CRYPTO_KPP_
118c2ecf20Sopenharmony_ci#include <linux/crypto.h>
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/**
148c2ecf20Sopenharmony_ci * struct kpp_request
158c2ecf20Sopenharmony_ci *
168c2ecf20Sopenharmony_ci * @base:	Common attributes for async crypto requests
178c2ecf20Sopenharmony_ci * @src:	Source data
188c2ecf20Sopenharmony_ci * @dst:	Destination data
198c2ecf20Sopenharmony_ci * @src_len:	Size of the input buffer
208c2ecf20Sopenharmony_ci * @dst_len:	Size of the output buffer. It needs to be at least
218c2ecf20Sopenharmony_ci *		as big as the expected result depending	on the operation
228c2ecf20Sopenharmony_ci *		After operation it will be updated with the actual size of the
238c2ecf20Sopenharmony_ci *		result. In case of error where the dst sgl size was insufficient,
248c2ecf20Sopenharmony_ci *		it will be updated to the size required for the operation.
258c2ecf20Sopenharmony_ci * @__ctx:	Start of private context data
268c2ecf20Sopenharmony_ci */
278c2ecf20Sopenharmony_cistruct kpp_request {
288c2ecf20Sopenharmony_ci	struct crypto_async_request base;
298c2ecf20Sopenharmony_ci	struct scatterlist *src;
308c2ecf20Sopenharmony_ci	struct scatterlist *dst;
318c2ecf20Sopenharmony_ci	unsigned int src_len;
328c2ecf20Sopenharmony_ci	unsigned int dst_len;
338c2ecf20Sopenharmony_ci	void *__ctx[] CRYPTO_MINALIGN_ATTR;
348c2ecf20Sopenharmony_ci};
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci/**
378c2ecf20Sopenharmony_ci * struct crypto_kpp - user-instantiated object which encapsulate
388c2ecf20Sopenharmony_ci * algorithms and core processing logic
398c2ecf20Sopenharmony_ci *
408c2ecf20Sopenharmony_ci * @base:	Common crypto API algorithm data structure
418c2ecf20Sopenharmony_ci */
428c2ecf20Sopenharmony_cistruct crypto_kpp {
438c2ecf20Sopenharmony_ci	struct crypto_tfm base;
448c2ecf20Sopenharmony_ci};
458c2ecf20Sopenharmony_ci
468c2ecf20Sopenharmony_ci/**
478c2ecf20Sopenharmony_ci * struct kpp_alg - generic key-agreement protocol primitives
488c2ecf20Sopenharmony_ci *
498c2ecf20Sopenharmony_ci * @set_secret:		Function invokes the protocol specific function to
508c2ecf20Sopenharmony_ci *			store the secret private key along with parameters.
518c2ecf20Sopenharmony_ci *			The implementation knows how to decode the buffer
528c2ecf20Sopenharmony_ci * @generate_public_key: Function generate the public key to be sent to the
538c2ecf20Sopenharmony_ci *			counterpart. In case of error, where output is not big
548c2ecf20Sopenharmony_ci *			enough req->dst_len will be updated to the size
558c2ecf20Sopenharmony_ci *			required
568c2ecf20Sopenharmony_ci * @compute_shared_secret: Function compute the shared secret as defined by
578c2ecf20Sopenharmony_ci *			the algorithm. The result is given back to the user.
588c2ecf20Sopenharmony_ci *			In case of error, where output is not big enough,
598c2ecf20Sopenharmony_ci *			req->dst_len will be updated to the size required
608c2ecf20Sopenharmony_ci * @max_size:		Function returns the size of the output buffer
618c2ecf20Sopenharmony_ci * @init:		Initialize the object. This is called only once at
628c2ecf20Sopenharmony_ci *			instantiation time. In case the cryptographic hardware
638c2ecf20Sopenharmony_ci *			needs to be initialized. Software fallback should be
648c2ecf20Sopenharmony_ci *			put in place here.
658c2ecf20Sopenharmony_ci * @exit:		Undo everything @init did.
668c2ecf20Sopenharmony_ci *
678c2ecf20Sopenharmony_ci * @reqsize:		Request context size required by algorithm
688c2ecf20Sopenharmony_ci *			implementation
698c2ecf20Sopenharmony_ci * @base:		Common crypto API algorithm data structure
708c2ecf20Sopenharmony_ci */
718c2ecf20Sopenharmony_cistruct kpp_alg {
728c2ecf20Sopenharmony_ci	int (*set_secret)(struct crypto_kpp *tfm, const void *buffer,
738c2ecf20Sopenharmony_ci			  unsigned int len);
748c2ecf20Sopenharmony_ci	int (*generate_public_key)(struct kpp_request *req);
758c2ecf20Sopenharmony_ci	int (*compute_shared_secret)(struct kpp_request *req);
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci	unsigned int (*max_size)(struct crypto_kpp *tfm);
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_ci	int (*init)(struct crypto_kpp *tfm);
808c2ecf20Sopenharmony_ci	void (*exit)(struct crypto_kpp *tfm);
818c2ecf20Sopenharmony_ci
828c2ecf20Sopenharmony_ci	unsigned int reqsize;
838c2ecf20Sopenharmony_ci	struct crypto_alg base;
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci/**
878c2ecf20Sopenharmony_ci * DOC: Generic Key-agreement Protocol Primitives API
888c2ecf20Sopenharmony_ci *
898c2ecf20Sopenharmony_ci * The KPP API is used with the algorithm type
908c2ecf20Sopenharmony_ci * CRYPTO_ALG_TYPE_KPP (listed as type "kpp" in /proc/crypto)
918c2ecf20Sopenharmony_ci */
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/**
948c2ecf20Sopenharmony_ci * crypto_alloc_kpp() - allocate KPP tfm handle
958c2ecf20Sopenharmony_ci * @alg_name: is the name of the kpp algorithm (e.g. "dh", "ecdh")
968c2ecf20Sopenharmony_ci * @type: specifies the type of the algorithm
978c2ecf20Sopenharmony_ci * @mask: specifies the mask for the algorithm
988c2ecf20Sopenharmony_ci *
998c2ecf20Sopenharmony_ci * Allocate a handle for kpp algorithm. The returned struct crypto_kpp
1008c2ecf20Sopenharmony_ci * is required for any following API invocation
1018c2ecf20Sopenharmony_ci *
1028c2ecf20Sopenharmony_ci * Return: allocated handle in case of success; IS_ERR() is true in case of
1038c2ecf20Sopenharmony_ci *	   an error, PTR_ERR() returns the error code.
1048c2ecf20Sopenharmony_ci */
1058c2ecf20Sopenharmony_cistruct crypto_kpp *crypto_alloc_kpp(const char *alg_name, u32 type, u32 mask);
1068c2ecf20Sopenharmony_ci
1078c2ecf20Sopenharmony_cistatic inline struct crypto_tfm *crypto_kpp_tfm(struct crypto_kpp *tfm)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	return &tfm->base;
1108c2ecf20Sopenharmony_ci}
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic inline struct kpp_alg *__crypto_kpp_alg(struct crypto_alg *alg)
1138c2ecf20Sopenharmony_ci{
1148c2ecf20Sopenharmony_ci	return container_of(alg, struct kpp_alg, base);
1158c2ecf20Sopenharmony_ci}
1168c2ecf20Sopenharmony_ci
1178c2ecf20Sopenharmony_cistatic inline struct crypto_kpp *__crypto_kpp_tfm(struct crypto_tfm *tfm)
1188c2ecf20Sopenharmony_ci{
1198c2ecf20Sopenharmony_ci	return container_of(tfm, struct crypto_kpp, base);
1208c2ecf20Sopenharmony_ci}
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_cistatic inline struct kpp_alg *crypto_kpp_alg(struct crypto_kpp *tfm)
1238c2ecf20Sopenharmony_ci{
1248c2ecf20Sopenharmony_ci	return __crypto_kpp_alg(crypto_kpp_tfm(tfm)->__crt_alg);
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic inline unsigned int crypto_kpp_reqsize(struct crypto_kpp *tfm)
1288c2ecf20Sopenharmony_ci{
1298c2ecf20Sopenharmony_ci	return crypto_kpp_alg(tfm)->reqsize;
1308c2ecf20Sopenharmony_ci}
1318c2ecf20Sopenharmony_ci
1328c2ecf20Sopenharmony_cistatic inline void kpp_request_set_tfm(struct kpp_request *req,
1338c2ecf20Sopenharmony_ci				       struct crypto_kpp *tfm)
1348c2ecf20Sopenharmony_ci{
1358c2ecf20Sopenharmony_ci	req->base.tfm = crypto_kpp_tfm(tfm);
1368c2ecf20Sopenharmony_ci}
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic inline struct crypto_kpp *crypto_kpp_reqtfm(struct kpp_request *req)
1398c2ecf20Sopenharmony_ci{
1408c2ecf20Sopenharmony_ci	return __crypto_kpp_tfm(req->base.tfm);
1418c2ecf20Sopenharmony_ci}
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_cistatic inline u32 crypto_kpp_get_flags(struct crypto_kpp *tfm)
1448c2ecf20Sopenharmony_ci{
1458c2ecf20Sopenharmony_ci	return crypto_tfm_get_flags(crypto_kpp_tfm(tfm));
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_cistatic inline void crypto_kpp_set_flags(struct crypto_kpp *tfm, u32 flags)
1498c2ecf20Sopenharmony_ci{
1508c2ecf20Sopenharmony_ci	crypto_tfm_set_flags(crypto_kpp_tfm(tfm), flags);
1518c2ecf20Sopenharmony_ci}
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/**
1548c2ecf20Sopenharmony_ci * crypto_free_kpp() - free KPP tfm handle
1558c2ecf20Sopenharmony_ci *
1568c2ecf20Sopenharmony_ci * @tfm: KPP tfm handle allocated with crypto_alloc_kpp()
1578c2ecf20Sopenharmony_ci *
1588c2ecf20Sopenharmony_ci * If @tfm is a NULL or error pointer, this function does nothing.
1598c2ecf20Sopenharmony_ci */
1608c2ecf20Sopenharmony_cistatic inline void crypto_free_kpp(struct crypto_kpp *tfm)
1618c2ecf20Sopenharmony_ci{
1628c2ecf20Sopenharmony_ci	crypto_destroy_tfm(tfm, crypto_kpp_tfm(tfm));
1638c2ecf20Sopenharmony_ci}
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci/**
1668c2ecf20Sopenharmony_ci * kpp_request_alloc() - allocates kpp request
1678c2ecf20Sopenharmony_ci *
1688c2ecf20Sopenharmony_ci * @tfm:	KPP tfm handle allocated with crypto_alloc_kpp()
1698c2ecf20Sopenharmony_ci * @gfp:	allocation flags
1708c2ecf20Sopenharmony_ci *
1718c2ecf20Sopenharmony_ci * Return: allocated handle in case of success or NULL in case of an error.
1728c2ecf20Sopenharmony_ci */
1738c2ecf20Sopenharmony_cistatic inline struct kpp_request *kpp_request_alloc(struct crypto_kpp *tfm,
1748c2ecf20Sopenharmony_ci						    gfp_t gfp)
1758c2ecf20Sopenharmony_ci{
1768c2ecf20Sopenharmony_ci	struct kpp_request *req;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci	req = kmalloc(sizeof(*req) + crypto_kpp_reqsize(tfm), gfp);
1798c2ecf20Sopenharmony_ci	if (likely(req))
1808c2ecf20Sopenharmony_ci		kpp_request_set_tfm(req, tfm);
1818c2ecf20Sopenharmony_ci
1828c2ecf20Sopenharmony_ci	return req;
1838c2ecf20Sopenharmony_ci}
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci/**
1868c2ecf20Sopenharmony_ci * kpp_request_free() - zeroize and free kpp request
1878c2ecf20Sopenharmony_ci *
1888c2ecf20Sopenharmony_ci * @req:	request to free
1898c2ecf20Sopenharmony_ci */
1908c2ecf20Sopenharmony_cistatic inline void kpp_request_free(struct kpp_request *req)
1918c2ecf20Sopenharmony_ci{
1928c2ecf20Sopenharmony_ci	kfree_sensitive(req);
1938c2ecf20Sopenharmony_ci}
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci/**
1968c2ecf20Sopenharmony_ci * kpp_request_set_callback() - Sets an asynchronous callback.
1978c2ecf20Sopenharmony_ci *
1988c2ecf20Sopenharmony_ci * Callback will be called when an asynchronous operation on a given
1998c2ecf20Sopenharmony_ci * request is finished.
2008c2ecf20Sopenharmony_ci *
2018c2ecf20Sopenharmony_ci * @req:	request that the callback will be set for
2028c2ecf20Sopenharmony_ci * @flgs:	specify for instance if the operation may backlog
2038c2ecf20Sopenharmony_ci * @cmpl:	callback which will be called
2048c2ecf20Sopenharmony_ci * @data:	private data used by the caller
2058c2ecf20Sopenharmony_ci */
2068c2ecf20Sopenharmony_cistatic inline void kpp_request_set_callback(struct kpp_request *req,
2078c2ecf20Sopenharmony_ci					    u32 flgs,
2088c2ecf20Sopenharmony_ci					    crypto_completion_t cmpl,
2098c2ecf20Sopenharmony_ci					    void *data)
2108c2ecf20Sopenharmony_ci{
2118c2ecf20Sopenharmony_ci	req->base.complete = cmpl;
2128c2ecf20Sopenharmony_ci	req->base.data = data;
2138c2ecf20Sopenharmony_ci	req->base.flags = flgs;
2148c2ecf20Sopenharmony_ci}
2158c2ecf20Sopenharmony_ci
2168c2ecf20Sopenharmony_ci/**
2178c2ecf20Sopenharmony_ci * kpp_request_set_input() - Sets input buffer
2188c2ecf20Sopenharmony_ci *
2198c2ecf20Sopenharmony_ci * Sets parameters required by generate_public_key
2208c2ecf20Sopenharmony_ci *
2218c2ecf20Sopenharmony_ci * @req:	kpp request
2228c2ecf20Sopenharmony_ci * @input:	ptr to input scatter list
2238c2ecf20Sopenharmony_ci * @input_len:	size of the input scatter list
2248c2ecf20Sopenharmony_ci */
2258c2ecf20Sopenharmony_cistatic inline void kpp_request_set_input(struct kpp_request *req,
2268c2ecf20Sopenharmony_ci					 struct scatterlist *input,
2278c2ecf20Sopenharmony_ci					 unsigned int input_len)
2288c2ecf20Sopenharmony_ci{
2298c2ecf20Sopenharmony_ci	req->src = input;
2308c2ecf20Sopenharmony_ci	req->src_len = input_len;
2318c2ecf20Sopenharmony_ci}
2328c2ecf20Sopenharmony_ci
2338c2ecf20Sopenharmony_ci/**
2348c2ecf20Sopenharmony_ci * kpp_request_set_output() - Sets output buffer
2358c2ecf20Sopenharmony_ci *
2368c2ecf20Sopenharmony_ci * Sets parameters required by kpp operation
2378c2ecf20Sopenharmony_ci *
2388c2ecf20Sopenharmony_ci * @req:	kpp request
2398c2ecf20Sopenharmony_ci * @output:	ptr to output scatter list
2408c2ecf20Sopenharmony_ci * @output_len:	size of the output scatter list
2418c2ecf20Sopenharmony_ci */
2428c2ecf20Sopenharmony_cistatic inline void kpp_request_set_output(struct kpp_request *req,
2438c2ecf20Sopenharmony_ci					  struct scatterlist *output,
2448c2ecf20Sopenharmony_ci					  unsigned int output_len)
2458c2ecf20Sopenharmony_ci{
2468c2ecf20Sopenharmony_ci	req->dst = output;
2478c2ecf20Sopenharmony_ci	req->dst_len = output_len;
2488c2ecf20Sopenharmony_ci}
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_cienum {
2518c2ecf20Sopenharmony_ci	CRYPTO_KPP_SECRET_TYPE_UNKNOWN,
2528c2ecf20Sopenharmony_ci	CRYPTO_KPP_SECRET_TYPE_DH,
2538c2ecf20Sopenharmony_ci	CRYPTO_KPP_SECRET_TYPE_ECDH,
2548c2ecf20Sopenharmony_ci};
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci/**
2578c2ecf20Sopenharmony_ci * struct kpp_secret - small header for packing secret buffer
2588c2ecf20Sopenharmony_ci *
2598c2ecf20Sopenharmony_ci * @type:	define type of secret. Each kpp type will define its own
2608c2ecf20Sopenharmony_ci * @len:	specify the len of the secret, include the header, that
2618c2ecf20Sopenharmony_ci *		follows the struct
2628c2ecf20Sopenharmony_ci */
2638c2ecf20Sopenharmony_cistruct kpp_secret {
2648c2ecf20Sopenharmony_ci	unsigned short type;
2658c2ecf20Sopenharmony_ci	unsigned short len;
2668c2ecf20Sopenharmony_ci};
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_ci/**
2698c2ecf20Sopenharmony_ci * crypto_kpp_set_secret() - Invoke kpp operation
2708c2ecf20Sopenharmony_ci *
2718c2ecf20Sopenharmony_ci * Function invokes the specific kpp operation for a given alg.
2728c2ecf20Sopenharmony_ci *
2738c2ecf20Sopenharmony_ci * @tfm:	tfm handle
2748c2ecf20Sopenharmony_ci * @buffer:	Buffer holding the packet representation of the private
2758c2ecf20Sopenharmony_ci *		key. The structure of the packet key depends on the particular
2768c2ecf20Sopenharmony_ci *		KPP implementation. Packing and unpacking helpers are provided
2778c2ecf20Sopenharmony_ci *		for ECDH and DH (see the respective header files for those
2788c2ecf20Sopenharmony_ci *		implementations).
2798c2ecf20Sopenharmony_ci * @len:	Length of the packet private key buffer.
2808c2ecf20Sopenharmony_ci *
2818c2ecf20Sopenharmony_ci * Return: zero on success; error code in case of error
2828c2ecf20Sopenharmony_ci */
2838c2ecf20Sopenharmony_cistatic inline int crypto_kpp_set_secret(struct crypto_kpp *tfm,
2848c2ecf20Sopenharmony_ci					const void *buffer, unsigned int len)
2858c2ecf20Sopenharmony_ci{
2868c2ecf20Sopenharmony_ci	struct kpp_alg *alg = crypto_kpp_alg(tfm);
2878c2ecf20Sopenharmony_ci	struct crypto_alg *calg = tfm->base.__crt_alg;
2888c2ecf20Sopenharmony_ci	int ret;
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci	crypto_stats_get(calg);
2918c2ecf20Sopenharmony_ci	ret = alg->set_secret(tfm, buffer, len);
2928c2ecf20Sopenharmony_ci	crypto_stats_kpp_set_secret(calg, ret);
2938c2ecf20Sopenharmony_ci	return ret;
2948c2ecf20Sopenharmony_ci}
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci/**
2978c2ecf20Sopenharmony_ci * crypto_kpp_generate_public_key() - Invoke kpp operation
2988c2ecf20Sopenharmony_ci *
2998c2ecf20Sopenharmony_ci * Function invokes the specific kpp operation for generating the public part
3008c2ecf20Sopenharmony_ci * for a given kpp algorithm.
3018c2ecf20Sopenharmony_ci *
3028c2ecf20Sopenharmony_ci * To generate a private key, the caller should use a random number generator.
3038c2ecf20Sopenharmony_ci * The output of the requested length serves as the private key.
3048c2ecf20Sopenharmony_ci *
3058c2ecf20Sopenharmony_ci * @req:	kpp key request
3068c2ecf20Sopenharmony_ci *
3078c2ecf20Sopenharmony_ci * Return: zero on success; error code in case of error
3088c2ecf20Sopenharmony_ci */
3098c2ecf20Sopenharmony_cistatic inline int crypto_kpp_generate_public_key(struct kpp_request *req)
3108c2ecf20Sopenharmony_ci{
3118c2ecf20Sopenharmony_ci	struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
3128c2ecf20Sopenharmony_ci	struct kpp_alg *alg = crypto_kpp_alg(tfm);
3138c2ecf20Sopenharmony_ci	struct crypto_alg *calg = tfm->base.__crt_alg;
3148c2ecf20Sopenharmony_ci	int ret;
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_ci	crypto_stats_get(calg);
3178c2ecf20Sopenharmony_ci	ret = alg->generate_public_key(req);
3188c2ecf20Sopenharmony_ci	crypto_stats_kpp_generate_public_key(calg, ret);
3198c2ecf20Sopenharmony_ci	return ret;
3208c2ecf20Sopenharmony_ci}
3218c2ecf20Sopenharmony_ci
3228c2ecf20Sopenharmony_ci/**
3238c2ecf20Sopenharmony_ci * crypto_kpp_compute_shared_secret() - Invoke kpp operation
3248c2ecf20Sopenharmony_ci *
3258c2ecf20Sopenharmony_ci * Function invokes the specific kpp operation for computing the shared secret
3268c2ecf20Sopenharmony_ci * for a given kpp algorithm.
3278c2ecf20Sopenharmony_ci *
3288c2ecf20Sopenharmony_ci * @req:	kpp key request
3298c2ecf20Sopenharmony_ci *
3308c2ecf20Sopenharmony_ci * Return: zero on success; error code in case of error
3318c2ecf20Sopenharmony_ci */
3328c2ecf20Sopenharmony_cistatic inline int crypto_kpp_compute_shared_secret(struct kpp_request *req)
3338c2ecf20Sopenharmony_ci{
3348c2ecf20Sopenharmony_ci	struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
3358c2ecf20Sopenharmony_ci	struct kpp_alg *alg = crypto_kpp_alg(tfm);
3368c2ecf20Sopenharmony_ci	struct crypto_alg *calg = tfm->base.__crt_alg;
3378c2ecf20Sopenharmony_ci	int ret;
3388c2ecf20Sopenharmony_ci
3398c2ecf20Sopenharmony_ci	crypto_stats_get(calg);
3408c2ecf20Sopenharmony_ci	ret = alg->compute_shared_secret(req);
3418c2ecf20Sopenharmony_ci	crypto_stats_kpp_compute_shared_secret(calg, ret);
3428c2ecf20Sopenharmony_ci	return ret;
3438c2ecf20Sopenharmony_ci}
3448c2ecf20Sopenharmony_ci
3458c2ecf20Sopenharmony_ci/**
3468c2ecf20Sopenharmony_ci * crypto_kpp_maxsize() - Get len for output buffer
3478c2ecf20Sopenharmony_ci *
3488c2ecf20Sopenharmony_ci * Function returns the output buffer size required for a given key.
3498c2ecf20Sopenharmony_ci * Function assumes that the key is already set in the transformation. If this
3508c2ecf20Sopenharmony_ci * function is called without a setkey or with a failed setkey, you will end up
3518c2ecf20Sopenharmony_ci * in a NULL dereference.
3528c2ecf20Sopenharmony_ci *
3538c2ecf20Sopenharmony_ci * @tfm:	KPP tfm handle allocated with crypto_alloc_kpp()
3548c2ecf20Sopenharmony_ci */
3558c2ecf20Sopenharmony_cistatic inline unsigned int crypto_kpp_maxsize(struct crypto_kpp *tfm)
3568c2ecf20Sopenharmony_ci{
3578c2ecf20Sopenharmony_ci	struct kpp_alg *alg = crypto_kpp_alg(tfm);
3588c2ecf20Sopenharmony_ci
3598c2ecf20Sopenharmony_ci	return alg->max_size(tfm);
3608c2ecf20Sopenharmony_ci}
3618c2ecf20Sopenharmony_ci
3628c2ecf20Sopenharmony_ci#endif
363