1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2018 Richard Palethorpe <[email protected]>
4 * Nicolai Stange <[email protected]>
5 */
6
7 #include <errno.h>
8 #include <stdio.h>
9
10 #define TST_NO_DEFAULT_MAIN
11 #include "tst_test.h"
12 #include "tst_crypto.h"
13
tst_crypto_add_alg(struct tst_netlink_context * ctx,const struct crypto_user_alg * alg)14 int tst_crypto_add_alg(struct tst_netlink_context *ctx,
15 const struct crypto_user_alg *alg)
16 {
17 struct nlmsghdr nh = {
18 .nlmsg_type = CRYPTO_MSG_NEWALG,
19 .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
20 };
21
22 NETLINK_ADD_MESSAGE(ctx, &nh, alg, sizeof(struct crypto_user_alg));
23 return NETLINK_SEND_VALIDATE(ctx) ? 0 : -tst_netlink_errno;
24 }
25
tst_crypto_del_alg(struct tst_netlink_context * ctx,const struct crypto_user_alg * alg,unsigned int retries)26 int tst_crypto_del_alg(struct tst_netlink_context *ctx,
27 const struct crypto_user_alg *alg, unsigned int retries)
28 {
29 int ret;
30 unsigned int i = 0;
31 struct nlmsghdr nh = {
32 .nlmsg_type = CRYPTO_MSG_DELALG,
33 .nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK,
34 };
35
36 for (i = 0; i < retries; i++) {
37 NETLINK_ADD_MESSAGE(ctx, &nh, alg,
38 sizeof(struct crypto_user_alg));
39
40 if (NETLINK_SEND_VALIDATE(ctx))
41 return 0;
42
43 ret = -tst_netlink_errno;
44
45 if (ret != -EBUSY)
46 break;
47
48 usleep(1);
49 }
50
51 return ret;
52 }
53