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