"Fossies" - the Fresh Open Source Software Archive 
Member "cryptsetup-2.4.3/tests/api_test.h" (13 Jan 2022, 5402 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:
As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style:
standard) with prefixed line numbers and
code folding option.
Alternatively you can here
view or
download the uninterpreted source code file.
See also the last
Fossies "Diffs" side-by-side code changes report for "api_test.h":
2.4.0_vs_2.4.1.
1 /*
2 * cryptsetup library API check functions
3 *
4 * Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
5 * Copyright (C) 2009-2021 Milan Broz
6 * Copyright (C) 2016-2021 Ondrej Kozina
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #ifndef API_TEST_H
24 #define API_TEST_H
25
26 #include <stdio.h>
27 #include <stdint.h>
28
29 extern char *THE_LOOP_DEV;
30 extern int _debug;
31 extern int global_lines;
32 extern int _quit;
33 extern int _verbose;
34 extern uint64_t t_dev_offset;
35
36 int t_device_size(const char *device, uint64_t *size);
37 int t_dm_check_versions(void);
38 int t_dm_crypt_keyring_support(void);
39 int t_dm_crypt_cpu_switch_support(void);
40 int t_dm_crypt_discard_support(void);
41
42 int fips_mode(void);
43
44 int create_dmdevice_over_loop(const char *dm_name, const uint64_t size);
45
46 int get_key_dm(const char *name, char *buffer, unsigned int buffer_size);
47
48 int prepare_keyfile(const char *name, const char *passphrase, int size);
49
50 int crypt_decode_key(char *key, const char *hex, unsigned int size);
51
52 void global_log_callback(int level, const char *msg, void *usrptr);
53
54 void reset_log(void);
55
56 int _system(const char *command, int warn);
57
58 void register_cleanup(void (*cleanup)(void));
59
60 void check_ok(int status, int line, const char *func);
61 void check_ok_return(int status, int line, const char *func);
62 void check_ko(int status, int line, const char *func);
63 void check_equal(int line, const char *func, int64_t x, int64_t y);
64 void check_ge_equal(int line, const char *func, int64_t x, int64_t y);
65 void check_null(int line, const char *func, const void *x);
66 void check_notnull(int line, const char *func, const void *x);
67 void xlog(const char *msg, const char *tst, const char *func, int line, const char *txt);
68
69 /* crypt_device context must be "cd" to parse error properly here */
70 #define OK_(x) do { xlog("(success)", #x, __FUNCTION__, __LINE__, NULL); \
71 check_ok((x), __LINE__, __FUNCTION__); \
72 } while(0)
73 #define NOTFAIL_(x, y) do { xlog("(notfail)", #x, __FUNCTION__, __LINE__, y); \
74 check_ok_return((x), __LINE__, __FUNCTION__); \
75 } while(0)
76 #define FAIL_(x, y) do { xlog("(fail) ", #x, __FUNCTION__, __LINE__, y); \
77 check_ko((x), __LINE__, __FUNCTION__); \
78 } while(0)
79 #define EQ_(x, y) do { int64_t _x = (x), _y = (y); \
80 xlog("(equal) ", #x " == " #y, __FUNCTION__, __LINE__, NULL); \
81 if (_x != _y) check_equal(__LINE__, __FUNCTION__, _x, _y); \
82 } while(0)
83 #define GE_(x, y) do { int64_t _x = (x), _y = (y); \
84 xlog("(g_equal)", #x " == " #y, __FUNCTION__, __LINE__, NULL); \
85 if (_x < _y) check_ge_equal(__LINE__, __FUNCTION__, _x, _y); \
86 } while(0)
87 #define NULL_(x) do { xlog("(null) ", #x, __FUNCTION__, __LINE__, NULL); \
88 check_null(__LINE__, __FUNCTION__, (x)); \
89 } while(0)
90 #define NOTNULL_(x) do { xlog("(notnull)", #x, __FUNCTION__, __LINE__, NULL); \
91 check_notnull(__LINE__, __FUNCTION__, (x)); \
92 } while(0)
93 #define RUN_(x, y) do { reset_log(); \
94 printf("%s: %s\n", #x, (y)); x(); \
95 } while (0)
96
97 #define CRYPT_FREE(x) do { crypt_free(x); x = NULL; } while (0)
98
99 #define DMDIR "/dev/mapper/"
100
101 #define TST_SECTOR_SHIFT 9L
102 #define TST_SECTOR_SIZE 512
103 #define TST_LOOP_FILE_SIZE (((1 << 20) * 100) >> TST_SECTOR_SHIFT)
104 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
105 #define DIV_ROUND_UP_MODULO(n,d) (DIV_ROUND_UP(n,d)*(d))
106
107 /* Device mapper backend - kernel support flags */
108 #define T_DM_KEY_WIPE_SUPPORTED (1 << 0) /* key wipe message */
109 #define T_DM_LMK_SUPPORTED (1 << 1) /* lmk mode */
110 #define T_DM_SECURE_SUPPORTED (1 << 2) /* wipe (secure) buffer flag */
111 #define T_DM_PLAIN64_SUPPORTED (1 << 3) /* plain64 IV */
112 #define T_DM_DISCARDS_SUPPORTED (1 << 4) /* discards/TRIM option is supported */
113 #define T_DM_VERITY_SUPPORTED (1 << 5) /* dm-verity target supported */
114 #define T_DM_TCW_SUPPORTED (1 << 6) /* tcw (TCRYPT CBC with whitening) */
115 #define T_DM_SAME_CPU_CRYPT_SUPPORTED (1 << 7) /* same_cpu_crypt */
116 #define T_DM_SUBMIT_FROM_CRYPT_CPUS_SUPPORTED (1 << 8) /* submit_from_crypt_cpus */
117 #define T_DM_VERITY_ON_CORRUPTION_SUPPORTED (1 << 9) /* ignore/restart_on_corruption, ignore_zero_block */
118 #define T_DM_VERITY_FEC_SUPPORTED (1 << 10) /* Forward Error Correction (FEC) */
119 #define T_DM_KERNEL_KEYRING_SUPPORTED (1 << 11) /* dm-crypt allows loading kernel keyring keys */
120 #define T_DM_INTEGRITY_SUPPORTED (1 << 12) /* dm-integrity target supported */
121 //FIXME add T_DM_SECTOR_SIZE once we have version
122
123 /* loop helpers */
124 int loop_device(const char *loop);
125 int loop_attach(char **loop, const char *file, int offset,
126 int autoclear, int *readonly);
127 int loop_detach(const char *loop);
128
129 int t_device_size_by_devno(dev_t devno, uint64_t *retval);
130 int t_get_devno(const char *dev, dev_t *devno);
131
132 #endif