37a5ac67d98545a1bfda6f37ff9ecc244d84fc71
[platform/upstream/cryptsetup.git] / lib / utils_keyring.h
1 /*
2  * kernel keyring syscall wrappers
3  *
4  * Copyright (C) 2016-2020 Red Hat, Inc. All rights reserved.
5  * Copyright (C) 2016-2020 Ondrej Kozina
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #ifndef _UTILS_KEYRING
23 #define _UTILS_KEYRING
24
25 #include <stddef.h>
26
27 typedef enum { LOGON_KEY = 0, USER_KEY } key_type_t;
28
29 const char *key_type_name(key_type_t ktype);
30
31 int keyring_check(void);
32
33 int keyring_get_key(const char *key_desc,
34                     char **key,
35                     size_t *key_size);
36
37 int keyring_get_passphrase(const char *key_desc,
38                       char **passphrase,
39                       size_t *passphrase_len);
40
41 int keyring_add_key_in_thread_keyring(
42         key_type_t ktype,
43         const char *key_desc,
44         const void *key,
45         size_t key_size);
46
47 int keyring_add_key_in_user_keyring(
48         key_type_t ktype,
49         const char *key_desc,
50         const void *key,
51         size_t key_size);
52
53 int keyring_revoke_and_unlink_key(key_type_t ktype, const char *key_desc);
54
55 #endif