12874c5fdSThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
24e5f2c40SSalvatore Benedetto /*
34e5f2c40SSalvatore Benedetto * Key-agreement Protocol Primitives (KPP)
44e5f2c40SSalvatore Benedetto *
54e5f2c40SSalvatore Benedetto * Copyright (c) 2016, Intel Corporation
64e5f2c40SSalvatore Benedetto * Authors: Salvatore Benedetto <salvatore.benedetto@intel.com>
74e5f2c40SSalvatore Benedetto */
84e5f2c40SSalvatore Benedetto
94e5f2c40SSalvatore Benedetto #ifndef _CRYPTO_KPP_
104e5f2c40SSalvatore Benedetto #define _CRYPTO_KPP_
11e2950bf1SHerbert Xu
12e2950bf1SHerbert Xu #include <linux/atomic.h>
13e2950bf1SHerbert Xu #include <linux/container_of.h>
144e5f2c40SSalvatore Benedetto #include <linux/crypto.h>
15e2950bf1SHerbert Xu #include <linux/slab.h>
164e5f2c40SSalvatore Benedetto
174e5f2c40SSalvatore Benedetto /**
184e5f2c40SSalvatore Benedetto * struct kpp_request
194e5f2c40SSalvatore Benedetto *
204e5f2c40SSalvatore Benedetto * @base: Common attributes for async crypto requests
214e5f2c40SSalvatore Benedetto * @src: Source data
224e5f2c40SSalvatore Benedetto * @dst: Destination data
234e5f2c40SSalvatore Benedetto * @src_len: Size of the input buffer
244e5f2c40SSalvatore Benedetto * @dst_len: Size of the output buffer. It needs to be at least
254e5f2c40SSalvatore Benedetto * as big as the expected result depending on the operation
264e5f2c40SSalvatore Benedetto * After operation it will be updated with the actual size of the
274e5f2c40SSalvatore Benedetto * result. In case of error where the dst sgl size was insufficient,
284e5f2c40SSalvatore Benedetto * it will be updated to the size required for the operation.
294e5f2c40SSalvatore Benedetto * @__ctx: Start of private context data
304e5f2c40SSalvatore Benedetto */
314e5f2c40SSalvatore Benedetto struct kpp_request {
324e5f2c40SSalvatore Benedetto struct crypto_async_request base;
334e5f2c40SSalvatore Benedetto struct scatterlist *src;
344e5f2c40SSalvatore Benedetto struct scatterlist *dst;
354e5f2c40SSalvatore Benedetto unsigned int src_len;
364e5f2c40SSalvatore Benedetto unsigned int dst_len;
374e5f2c40SSalvatore Benedetto void *__ctx[] CRYPTO_MINALIGN_ATTR;
384e5f2c40SSalvatore Benedetto };
394e5f2c40SSalvatore Benedetto
404e5f2c40SSalvatore Benedetto /**
414e5f2c40SSalvatore Benedetto * struct crypto_kpp - user-instantiated object which encapsulate
424e5f2c40SSalvatore Benedetto * algorithms and core processing logic
434e5f2c40SSalvatore Benedetto *
444d2b225aSHerbert Xu * @reqsize: Request context size required by algorithm
454d2b225aSHerbert Xu * implementation
464e5f2c40SSalvatore Benedetto * @base: Common crypto API algorithm data structure
474e5f2c40SSalvatore Benedetto */
484e5f2c40SSalvatore Benedetto struct crypto_kpp {
494d2b225aSHerbert Xu unsigned int reqsize;
504d2b225aSHerbert Xu
514e5f2c40SSalvatore Benedetto struct crypto_tfm base;
524e5f2c40SSalvatore Benedetto };
534e5f2c40SSalvatore Benedetto
544e5f2c40SSalvatore Benedetto /**
554e5f2c40SSalvatore Benedetto * struct kpp_alg - generic key-agreement protocol primitives
564e5f2c40SSalvatore Benedetto *
574e5f2c40SSalvatore Benedetto * @set_secret: Function invokes the protocol specific function to
584e5f2c40SSalvatore Benedetto * store the secret private key along with parameters.
59c0ca1215STudor-Dan Ambarus * The implementation knows how to decode the buffer
604e5f2c40SSalvatore Benedetto * @generate_public_key: Function generate the public key to be sent to the
614e5f2c40SSalvatore Benedetto * counterpart. In case of error, where output is not big
624e5f2c40SSalvatore Benedetto * enough req->dst_len will be updated to the size
634e5f2c40SSalvatore Benedetto * required
644e5f2c40SSalvatore Benedetto * @compute_shared_secret: Function compute the shared secret as defined by
654e5f2c40SSalvatore Benedetto * the algorithm. The result is given back to the user.
664e5f2c40SSalvatore Benedetto * In case of error, where output is not big enough,
674e5f2c40SSalvatore Benedetto * req->dst_len will be updated to the size required
684e5f2c40SSalvatore Benedetto * @max_size: Function returns the size of the output buffer
694e5f2c40SSalvatore Benedetto * @init: Initialize the object. This is called only once at
704e5f2c40SSalvatore Benedetto * instantiation time. In case the cryptographic hardware
714e5f2c40SSalvatore Benedetto * needs to be initialized. Software fallback should be
724e5f2c40SSalvatore Benedetto * put in place here.
734e5f2c40SSalvatore Benedetto * @exit: Undo everything @init did.
744e5f2c40SSalvatore Benedetto *
758d23da22SStephan Mueller * @base: Common crypto API algorithm data structure
764e5f2c40SSalvatore Benedetto */
774e5f2c40SSalvatore Benedetto struct kpp_alg {
785527dfb6SEric Biggers int (*set_secret)(struct crypto_kpp *tfm, const void *buffer,
794e5f2c40SSalvatore Benedetto unsigned int len);
804e5f2c40SSalvatore Benedetto int (*generate_public_key)(struct kpp_request *req);
814e5f2c40SSalvatore Benedetto int (*compute_shared_secret)(struct kpp_request *req);
824e5f2c40SSalvatore Benedetto
83c444b8daSTudor-Dan Ambarus unsigned int (*max_size)(struct crypto_kpp *tfm);
844e5f2c40SSalvatore Benedetto
854e5f2c40SSalvatore Benedetto int (*init)(struct crypto_kpp *tfm);
864e5f2c40SSalvatore Benedetto void (*exit)(struct crypto_kpp *tfm);
874e5f2c40SSalvatore Benedetto
884e5f2c40SSalvatore Benedetto struct crypto_alg base;
894e5f2c40SSalvatore Benedetto };
904e5f2c40SSalvatore Benedetto
914e5f2c40SSalvatore Benedetto /**
928d23da22SStephan Mueller * DOC: Generic Key-agreement Protocol Primitives API
934e5f2c40SSalvatore Benedetto *
944e5f2c40SSalvatore Benedetto * The KPP API is used with the algorithm type
954e5f2c40SSalvatore Benedetto * CRYPTO_ALG_TYPE_KPP (listed as type "kpp" in /proc/crypto)
964e5f2c40SSalvatore Benedetto */
974e5f2c40SSalvatore Benedetto
984e5f2c40SSalvatore Benedetto /**
994e5f2c40SSalvatore Benedetto * crypto_alloc_kpp() - allocate KPP tfm handle
1004e5f2c40SSalvatore Benedetto * @alg_name: is the name of the kpp algorithm (e.g. "dh", "ecdh")
1014e5f2c40SSalvatore Benedetto * @type: specifies the type of the algorithm
1024e5f2c40SSalvatore Benedetto * @mask: specifies the mask for the algorithm
1034e5f2c40SSalvatore Benedetto *
1044e5f2c40SSalvatore Benedetto * Allocate a handle for kpp algorithm. The returned struct crypto_kpp
105c0ca1215STudor-Dan Ambarus * is required for any following API invocation
1064e5f2c40SSalvatore Benedetto *
1074e5f2c40SSalvatore Benedetto * Return: allocated handle in case of success; IS_ERR() is true in case of
1084e5f2c40SSalvatore Benedetto * an error, PTR_ERR() returns the error code.
1094e5f2c40SSalvatore Benedetto */
1104e5f2c40SSalvatore Benedetto struct crypto_kpp *crypto_alloc_kpp(const char *alg_name, u32 type, u32 mask);
1114e5f2c40SSalvatore Benedetto
1129e2f284eSHannes Reinecke int crypto_has_kpp(const char *alg_name, u32 type, u32 mask);
1139e2f284eSHannes Reinecke
crypto_kpp_tfm(struct crypto_kpp * tfm)1144e5f2c40SSalvatore Benedetto static inline struct crypto_tfm *crypto_kpp_tfm(struct crypto_kpp *tfm)
1154e5f2c40SSalvatore Benedetto {
1164e5f2c40SSalvatore Benedetto return &tfm->base;
1174e5f2c40SSalvatore Benedetto }
1184e5f2c40SSalvatore Benedetto
__crypto_kpp_alg(struct crypto_alg * alg)1194e5f2c40SSalvatore Benedetto static inline struct kpp_alg *__crypto_kpp_alg(struct crypto_alg *alg)
1204e5f2c40SSalvatore Benedetto {
1214e5f2c40SSalvatore Benedetto return container_of(alg, struct kpp_alg, base);
1224e5f2c40SSalvatore Benedetto }
1234e5f2c40SSalvatore Benedetto
__crypto_kpp_tfm(struct crypto_tfm * tfm)1244e5f2c40SSalvatore Benedetto static inline struct crypto_kpp *__crypto_kpp_tfm(struct crypto_tfm *tfm)
1254e5f2c40SSalvatore Benedetto {
1264e5f2c40SSalvatore Benedetto return container_of(tfm, struct crypto_kpp, base);
1274e5f2c40SSalvatore Benedetto }
1284e5f2c40SSalvatore Benedetto
crypto_kpp_alg(struct crypto_kpp * tfm)1294e5f2c40SSalvatore Benedetto static inline struct kpp_alg *crypto_kpp_alg(struct crypto_kpp *tfm)
1304e5f2c40SSalvatore Benedetto {
1314e5f2c40SSalvatore Benedetto return __crypto_kpp_alg(crypto_kpp_tfm(tfm)->__crt_alg);
1324e5f2c40SSalvatore Benedetto }
1334e5f2c40SSalvatore Benedetto
crypto_kpp_reqsize(struct crypto_kpp * tfm)1344e5f2c40SSalvatore Benedetto static inline unsigned int crypto_kpp_reqsize(struct crypto_kpp *tfm)
1354e5f2c40SSalvatore Benedetto {
1364d2b225aSHerbert Xu return tfm->reqsize;
1374e5f2c40SSalvatore Benedetto }
1384e5f2c40SSalvatore Benedetto
kpp_request_set_tfm(struct kpp_request * req,struct crypto_kpp * tfm)1394e5f2c40SSalvatore Benedetto static inline void kpp_request_set_tfm(struct kpp_request *req,
1404e5f2c40SSalvatore Benedetto struct crypto_kpp *tfm)
1414e5f2c40SSalvatore Benedetto {
1424e5f2c40SSalvatore Benedetto req->base.tfm = crypto_kpp_tfm(tfm);
1434e5f2c40SSalvatore Benedetto }
1444e5f2c40SSalvatore Benedetto
crypto_kpp_reqtfm(struct kpp_request * req)1454e5f2c40SSalvatore Benedetto static inline struct crypto_kpp *crypto_kpp_reqtfm(struct kpp_request *req)
1464e5f2c40SSalvatore Benedetto {
1474e5f2c40SSalvatore Benedetto return __crypto_kpp_tfm(req->base.tfm);
1484e5f2c40SSalvatore Benedetto }
1494e5f2c40SSalvatore Benedetto
crypto_kpp_get_flags(struct crypto_kpp * tfm)15066d3994cSTudor-Dan Ambarus static inline u32 crypto_kpp_get_flags(struct crypto_kpp *tfm)
15166d3994cSTudor-Dan Ambarus {
15266d3994cSTudor-Dan Ambarus return crypto_tfm_get_flags(crypto_kpp_tfm(tfm));
15366d3994cSTudor-Dan Ambarus }
15466d3994cSTudor-Dan Ambarus
crypto_kpp_set_flags(struct crypto_kpp * tfm,u32 flags)15566d3994cSTudor-Dan Ambarus static inline void crypto_kpp_set_flags(struct crypto_kpp *tfm, u32 flags)
15666d3994cSTudor-Dan Ambarus {
15766d3994cSTudor-Dan Ambarus crypto_tfm_set_flags(crypto_kpp_tfm(tfm), flags);
15866d3994cSTudor-Dan Ambarus }
15966d3994cSTudor-Dan Ambarus
1604e5f2c40SSalvatore Benedetto /**
1614e5f2c40SSalvatore Benedetto * crypto_free_kpp() - free KPP tfm handle
1624e5f2c40SSalvatore Benedetto *
1634e5f2c40SSalvatore Benedetto * @tfm: KPP tfm handle allocated with crypto_alloc_kpp()
16483681f2bSArd Biesheuvel *
16583681f2bSArd Biesheuvel * If @tfm is a NULL or error pointer, this function does nothing.
1664e5f2c40SSalvatore Benedetto */
crypto_free_kpp(struct crypto_kpp * tfm)1674e5f2c40SSalvatore Benedetto static inline void crypto_free_kpp(struct crypto_kpp *tfm)
1684e5f2c40SSalvatore Benedetto {
1694e5f2c40SSalvatore Benedetto crypto_destroy_tfm(tfm, crypto_kpp_tfm(tfm));
1704e5f2c40SSalvatore Benedetto }
1714e5f2c40SSalvatore Benedetto
1724e5f2c40SSalvatore Benedetto /**
1734e5f2c40SSalvatore Benedetto * kpp_request_alloc() - allocates kpp request
1744e5f2c40SSalvatore Benedetto *
1754e5f2c40SSalvatore Benedetto * @tfm: KPP tfm handle allocated with crypto_alloc_kpp()
1764e5f2c40SSalvatore Benedetto * @gfp: allocation flags
1774e5f2c40SSalvatore Benedetto *
1784e5f2c40SSalvatore Benedetto * Return: allocated handle in case of success or NULL in case of an error.
1794e5f2c40SSalvatore Benedetto */
kpp_request_alloc(struct crypto_kpp * tfm,gfp_t gfp)1804e5f2c40SSalvatore Benedetto static inline struct kpp_request *kpp_request_alloc(struct crypto_kpp *tfm,
1814e5f2c40SSalvatore Benedetto gfp_t gfp)
1824e5f2c40SSalvatore Benedetto {
1834e5f2c40SSalvatore Benedetto struct kpp_request *req;
1844e5f2c40SSalvatore Benedetto
1854e5f2c40SSalvatore Benedetto req = kmalloc(sizeof(*req) + crypto_kpp_reqsize(tfm), gfp);
1864e5f2c40SSalvatore Benedetto if (likely(req))
1874e5f2c40SSalvatore Benedetto kpp_request_set_tfm(req, tfm);
1884e5f2c40SSalvatore Benedetto
1894e5f2c40SSalvatore Benedetto return req;
1904e5f2c40SSalvatore Benedetto }
1914e5f2c40SSalvatore Benedetto
1924e5f2c40SSalvatore Benedetto /**
1934e5f2c40SSalvatore Benedetto * kpp_request_free() - zeroize and free kpp request
1944e5f2c40SSalvatore Benedetto *
1954e5f2c40SSalvatore Benedetto * @req: request to free
1964e5f2c40SSalvatore Benedetto */
kpp_request_free(struct kpp_request * req)1974e5f2c40SSalvatore Benedetto static inline void kpp_request_free(struct kpp_request *req)
1984e5f2c40SSalvatore Benedetto {
199453431a5SWaiman Long kfree_sensitive(req);
2004e5f2c40SSalvatore Benedetto }
2014e5f2c40SSalvatore Benedetto
2024e5f2c40SSalvatore Benedetto /**
2034e5f2c40SSalvatore Benedetto * kpp_request_set_callback() - Sets an asynchronous callback.
2044e5f2c40SSalvatore Benedetto *
2054e5f2c40SSalvatore Benedetto * Callback will be called when an asynchronous operation on a given
2064e5f2c40SSalvatore Benedetto * request is finished.
2074e5f2c40SSalvatore Benedetto *
2084e5f2c40SSalvatore Benedetto * @req: request that the callback will be set for
2094e5f2c40SSalvatore Benedetto * @flgs: specify for instance if the operation may backlog
2104e5f2c40SSalvatore Benedetto * @cmpl: callback which will be called
2114e5f2c40SSalvatore Benedetto * @data: private data used by the caller
2124e5f2c40SSalvatore Benedetto */
kpp_request_set_callback(struct kpp_request * req,u32 flgs,crypto_completion_t cmpl,void * data)2134e5f2c40SSalvatore Benedetto static inline void kpp_request_set_callback(struct kpp_request *req,
2144e5f2c40SSalvatore Benedetto u32 flgs,
2154e5f2c40SSalvatore Benedetto crypto_completion_t cmpl,
2164e5f2c40SSalvatore Benedetto void *data)
2174e5f2c40SSalvatore Benedetto {
2184e5f2c40SSalvatore Benedetto req->base.complete = cmpl;
2194e5f2c40SSalvatore Benedetto req->base.data = data;
2204e5f2c40SSalvatore Benedetto req->base.flags = flgs;
2214e5f2c40SSalvatore Benedetto }
2224e5f2c40SSalvatore Benedetto
2234e5f2c40SSalvatore Benedetto /**
2244e5f2c40SSalvatore Benedetto * kpp_request_set_input() - Sets input buffer
2254e5f2c40SSalvatore Benedetto *
2264e5f2c40SSalvatore Benedetto * Sets parameters required by generate_public_key
2274e5f2c40SSalvatore Benedetto *
2284e5f2c40SSalvatore Benedetto * @req: kpp request
2294e5f2c40SSalvatore Benedetto * @input: ptr to input scatter list
2304e5f2c40SSalvatore Benedetto * @input_len: size of the input scatter list
2314e5f2c40SSalvatore Benedetto */
kpp_request_set_input(struct kpp_request * req,struct scatterlist * input,unsigned int input_len)2324e5f2c40SSalvatore Benedetto static inline void kpp_request_set_input(struct kpp_request *req,
2334e5f2c40SSalvatore Benedetto struct scatterlist *input,
2344e5f2c40SSalvatore Benedetto unsigned int input_len)
2354e5f2c40SSalvatore Benedetto {
2364e5f2c40SSalvatore Benedetto req->src = input;
2374e5f2c40SSalvatore Benedetto req->src_len = input_len;
2384e5f2c40SSalvatore Benedetto }
2394e5f2c40SSalvatore Benedetto
2404e5f2c40SSalvatore Benedetto /**
2414e5f2c40SSalvatore Benedetto * kpp_request_set_output() - Sets output buffer
2424e5f2c40SSalvatore Benedetto *
2434e5f2c40SSalvatore Benedetto * Sets parameters required by kpp operation
2444e5f2c40SSalvatore Benedetto *
2454e5f2c40SSalvatore Benedetto * @req: kpp request
2464e5f2c40SSalvatore Benedetto * @output: ptr to output scatter list
2474e5f2c40SSalvatore Benedetto * @output_len: size of the output scatter list
2484e5f2c40SSalvatore Benedetto */
kpp_request_set_output(struct kpp_request * req,struct scatterlist * output,unsigned int output_len)2494e5f2c40SSalvatore Benedetto static inline void kpp_request_set_output(struct kpp_request *req,
2504e5f2c40SSalvatore Benedetto struct scatterlist *output,
2514e5f2c40SSalvatore Benedetto unsigned int output_len)
2524e5f2c40SSalvatore Benedetto {
2534e5f2c40SSalvatore Benedetto req->dst = output;
2544e5f2c40SSalvatore Benedetto req->dst_len = output_len;
2554e5f2c40SSalvatore Benedetto }
2564e5f2c40SSalvatore Benedetto
2574e5f2c40SSalvatore Benedetto enum {
2584e5f2c40SSalvatore Benedetto CRYPTO_KPP_SECRET_TYPE_UNKNOWN,
259802c7f1cSSalvatore Benedetto CRYPTO_KPP_SECRET_TYPE_DH,
2603c4b2390SSalvatore Benedetto CRYPTO_KPP_SECRET_TYPE_ECDH,
2614e5f2c40SSalvatore Benedetto };
2624e5f2c40SSalvatore Benedetto
2634e5f2c40SSalvatore Benedetto /**
2644e5f2c40SSalvatore Benedetto * struct kpp_secret - small header for packing secret buffer
2654e5f2c40SSalvatore Benedetto *
2664e5f2c40SSalvatore Benedetto * @type: define type of secret. Each kpp type will define its own
2674e5f2c40SSalvatore Benedetto * @len: specify the len of the secret, include the header, that
2684e5f2c40SSalvatore Benedetto * follows the struct
2694e5f2c40SSalvatore Benedetto */
2704e5f2c40SSalvatore Benedetto struct kpp_secret {
2714e5f2c40SSalvatore Benedetto unsigned short type;
2724e5f2c40SSalvatore Benedetto unsigned short len;
2734e5f2c40SSalvatore Benedetto };
2744e5f2c40SSalvatore Benedetto
2754e5f2c40SSalvatore Benedetto /**
2764e5f2c40SSalvatore Benedetto * crypto_kpp_set_secret() - Invoke kpp operation
2774e5f2c40SSalvatore Benedetto *
2784e5f2c40SSalvatore Benedetto * Function invokes the specific kpp operation for a given alg.
2794e5f2c40SSalvatore Benedetto *
2804e5f2c40SSalvatore Benedetto * @tfm: tfm handle
2818d23da22SStephan Mueller * @buffer: Buffer holding the packet representation of the private
2828d23da22SStephan Mueller * key. The structure of the packet key depends on the particular
2838d23da22SStephan Mueller * KPP implementation. Packing and unpacking helpers are provided
2848d23da22SStephan Mueller * for ECDH and DH (see the respective header files for those
2858d23da22SStephan Mueller * implementations).
2868d23da22SStephan Mueller * @len: Length of the packet private key buffer.
2874e5f2c40SSalvatore Benedetto *
2884e5f2c40SSalvatore Benedetto * Return: zero on success; error code in case of error
2894e5f2c40SSalvatore Benedetto */
crypto_kpp_set_secret(struct crypto_kpp * tfm,const void * buffer,unsigned int len)2905527dfb6SEric Biggers static inline int crypto_kpp_set_secret(struct crypto_kpp *tfm,
2915527dfb6SEric Biggers const void *buffer, unsigned int len)
2924e5f2c40SSalvatore Benedetto {
293*29ce50e0SEric Biggers return crypto_kpp_alg(tfm)->set_secret(tfm, buffer, len);
2944e5f2c40SSalvatore Benedetto }
2954e5f2c40SSalvatore Benedetto
2964e5f2c40SSalvatore Benedetto /**
2974e5f2c40SSalvatore Benedetto * crypto_kpp_generate_public_key() - Invoke kpp operation
2984e5f2c40SSalvatore Benedetto *
2994e5f2c40SSalvatore Benedetto * Function invokes the specific kpp operation for generating the public part
3008d23da22SStephan Mueller * for a given kpp algorithm.
3018d23da22SStephan Mueller *
3028d23da22SStephan Mueller * To generate a private key, the caller should use a random number generator.
3038d23da22SStephan Mueller * The output of the requested length serves as the private key.
3044e5f2c40SSalvatore Benedetto *
3054e5f2c40SSalvatore Benedetto * @req: kpp key request
3064e5f2c40SSalvatore Benedetto *
3074e5f2c40SSalvatore Benedetto * Return: zero on success; error code in case of error
3084e5f2c40SSalvatore Benedetto */
crypto_kpp_generate_public_key(struct kpp_request * req)3094e5f2c40SSalvatore Benedetto static inline int crypto_kpp_generate_public_key(struct kpp_request *req)
3104e5f2c40SSalvatore Benedetto {
3114e5f2c40SSalvatore Benedetto struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
3124e5f2c40SSalvatore Benedetto
313*29ce50e0SEric Biggers return crypto_kpp_alg(tfm)->generate_public_key(req);
3144e5f2c40SSalvatore Benedetto }
3154e5f2c40SSalvatore Benedetto
3164e5f2c40SSalvatore Benedetto /**
3174e5f2c40SSalvatore Benedetto * crypto_kpp_compute_shared_secret() - Invoke kpp operation
3184e5f2c40SSalvatore Benedetto *
3194e5f2c40SSalvatore Benedetto * Function invokes the specific kpp operation for computing the shared secret
3204e5f2c40SSalvatore Benedetto * for a given kpp algorithm.
3214e5f2c40SSalvatore Benedetto *
3224e5f2c40SSalvatore Benedetto * @req: kpp key request
3234e5f2c40SSalvatore Benedetto *
3244e5f2c40SSalvatore Benedetto * Return: zero on success; error code in case of error
3254e5f2c40SSalvatore Benedetto */
crypto_kpp_compute_shared_secret(struct kpp_request * req)3264e5f2c40SSalvatore Benedetto static inline int crypto_kpp_compute_shared_secret(struct kpp_request *req)
3274e5f2c40SSalvatore Benedetto {
3284e5f2c40SSalvatore Benedetto struct crypto_kpp *tfm = crypto_kpp_reqtfm(req);
3294e5f2c40SSalvatore Benedetto
330*29ce50e0SEric Biggers return crypto_kpp_alg(tfm)->compute_shared_secret(req);
3314e5f2c40SSalvatore Benedetto }
3324e5f2c40SSalvatore Benedetto
3334e5f2c40SSalvatore Benedetto /**
3344e5f2c40SSalvatore Benedetto * crypto_kpp_maxsize() - Get len for output buffer
3354e5f2c40SSalvatore Benedetto *
336c444b8daSTudor-Dan Ambarus * Function returns the output buffer size required for a given key.
337c444b8daSTudor-Dan Ambarus * Function assumes that the key is already set in the transformation. If this
338c444b8daSTudor-Dan Ambarus * function is called without a setkey or with a failed setkey, you will end up
339c444b8daSTudor-Dan Ambarus * in a NULL dereference.
3404e5f2c40SSalvatore Benedetto *
3414e5f2c40SSalvatore Benedetto * @tfm: KPP tfm handle allocated with crypto_alloc_kpp()
3424e5f2c40SSalvatore Benedetto */
crypto_kpp_maxsize(struct crypto_kpp * tfm)343c444b8daSTudor-Dan Ambarus static inline unsigned int crypto_kpp_maxsize(struct crypto_kpp *tfm)
3444e5f2c40SSalvatore Benedetto {
3454e5f2c40SSalvatore Benedetto struct kpp_alg *alg = crypto_kpp_alg(tfm);
3464e5f2c40SSalvatore Benedetto
3474e5f2c40SSalvatore Benedetto return alg->max_size(tfm);
3484e5f2c40SSalvatore Benedetto }
3494e5f2c40SSalvatore Benedetto
3504e5f2c40SSalvatore Benedetto #endif
351