xref: /aosp_15_r20/external/ltp/include/tst_crypto.h (revision 49cdfc7efb34551c7342be41a7384b9c40d7cab7)
1 /* SPDX-License-Identifier: GPL-2.0-or-later
2  * Copyright (c) 2018 Richard Palethorpe <[email protected]>
3  */
4 
5 /**
6  * @file tst_crypto.h
7  *
8  * Library for interacting with kernel's crypto layer using the netlink
9  * interface.
10  */
11 
12 #ifndef TST_CRYPTO_H
13 #define TST_CRYPTO_H
14 
15 #include "lapi/cryptouser.h"
16 #include "tst_netlink.h"
17 
18 /**
19  * Add a crypto algorithm to a session.
20  *
21  * @param ctx Initialized netlink context
22  * @param alg The crypto algorithm or module to add.
23  *
24  * This requests a new crypto algorithm/engine/module to be initialized by the
25  * kernel. It sends the request contained in alg and then waits for a
26  * response. If sending the message or receiving the ack fails at the netlink
27  * level then tst_brk() with TBROK will be called.
28  *
29  * @return On success it will return 0 otherwise it will return an inverted
30  *         error code from the crypto layer.
31  */
32 int tst_crypto_add_alg(struct tst_netlink_context *ctx,
33 		       const struct crypto_user_alg *alg);
34 
35 /**
36  * Delete a crypto algorithm from a session.
37  *
38  * @param ctx Initialized netlink context
39  * @param alg The crypto algorithm to delete.
40  * @param retries Number of retries before giving up. Recommended value: 1000
41  *
42  * Request that the kernel remove an existing crypto algorithm. This behaves
43  * in a similar way to tst_crypto_add_alg() except that it is the inverse
44  * operation and that it is not unusual for the crypto layer to return
45  * EBUSY. If EBUSY is returned then the function will internally retry the
46  * operation tst_crypto_session::retries times before giving up and returning
47  * EBUSY.
48  *
49  * Return: Either 0 or an inverted error code from the crypto layer. If called
50  *         during cleanup it may return a positive ENODATA value from the LTP
51  *         library, you don't need to log this error as it will already have
52  *         been printed by tst_brk().
53  */
54 int tst_crypto_del_alg(struct tst_netlink_context *ctx,
55 	const struct crypto_user_alg *alg, unsigned int retries);
56 
57 #endif	/* TST_CRYPTO_H */
58