"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/src/cryptsetup.h" (13 Jan 2022, 5105 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. For more information about "cryptsetup.h" see the Fossies "Dox" file reference documentation and the last Fossies "Diffs" side-by-side code changes report: 2.3.6_vs_2.4.0.

    1 /*
    2  * cryptsetup - setup cryptographic volumes for dm-crypt
    3  *
    4  * Copyright (C) 2004 Jana Saout <jana@saout.de>
    5  * Copyright (C) 2004-2007 Clemens Fruhwirth <clemens@endorphin.org>
    6  * Copyright (C) 2009-2021 Red Hat, Inc. All rights reserved.
    7  * Copyright (C) 2009-2021 Milan Broz
    8  *
    9  * This program is free software; you can redistribute it and/or
   10  * modify it under the terms of the GNU General Public License
   11  * as published by the Free Software Foundation; either version 2
   12  * of the License, or (at your option) any later version.
   13  *
   14  * This program is distributed in the hope that it will be useful,
   15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
   16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17  * GNU General Public License for more details.
   18  *
   19  * You should have received a copy of the GNU General Public License
   20  * along with this program; if not, write to the Free Software
   21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
   22  */
   23 
   24 #ifndef CRYPTSETUP_H
   25 #define CRYPTSETUP_H
   26 
   27 #include <stdbool.h>
   28 #include <string.h>
   29 #include <stdlib.h>
   30 #include <stdarg.h>
   31 #include <stdio.h>
   32 #include <stdint.h>
   33 #include <errno.h>
   34 #include <unistd.h>
   35 #include <inttypes.h>
   36 #include <limits.h>
   37 #include <ctype.h>
   38 #include <fcntl.h>
   39 #include <popt.h>
   40 #include <sys/stat.h>
   41 #include <sys/time.h>
   42 
   43 #include "lib/nls.h"
   44 #include "lib/bitops.h"
   45 #include "lib/utils_crypt.h"
   46 #include "lib/utils_loop.h"
   47 #include "lib/utils_fips.h"
   48 #include "lib/utils_io.h"
   49 #include "lib/utils_blkid.h"
   50 #include "lib/libcryptsetup_macros.h"
   51 
   52 #include "libcryptsetup.h"
   53 
   54 #define DEFAULT_CIPHER(type)    (DEFAULT_##type##_CIPHER "-" DEFAULT_##type##_MODE)
   55 
   56 #define DEFAULT_WIPE_BLOCK  1048576 /* 1 MiB */
   57 #define MAX_ACTIONS 16
   58 
   59 /* Common tools */
   60 void tool_log(int level, const char *msg, void *usrptr __attribute__((unused)));
   61 void quiet_log(int level, const char *msg, void *usrptr);
   62 
   63 int yesDialog(const char *msg, void *usrptr);
   64 int noDialog(const char *msg, void *usrptr);
   65 void show_status(int errcode);
   66 const char *uuid_or_device(const char *spec);
   67 __attribute__ ((noreturn)) \
   68 void usage(poptContext popt_context, int exitcode, const char *error, const char *more);
   69 void dbg_version_and_cmd(int argc, const char **argv);
   70 int translate_errno(int r);
   71 
   72 typedef enum { CREATED, UNLOCKED, REMOVED  } crypt_object_op;
   73 void tools_keyslot_msg(int keyslot, crypt_object_op op);
   74 void tools_token_msg(int token, crypt_object_op op);
   75 void tools_token_error_msg(int error, const char *type, int token, bool pin_provided);
   76 
   77 extern volatile int quit;
   78 void set_int_block(int block);
   79 void set_int_handler(int block);
   80 void check_signal(int *r);
   81 int tools_signals_blocked(void);
   82 
   83 int tools_get_key(const char *prompt,
   84           char **key, size_t *key_size,
   85           uint64_t keyfile_offset, size_t keyfile_size_max,
   86           const char *key_file,
   87           int timeout, int verify, int pwquality,
   88           struct crypt_device *cd);
   89 void tools_passphrase_msg(int r);
   90 int tools_is_stdin(const char *key_file);
   91 int tools_string_to_size(const char *s, uint64_t *size);
   92 
   93 struct tools_progress_params {
   94     uint32_t frequency;
   95     struct timeval start_time;
   96     struct timeval end_time;
   97     uint64_t start_offset;
   98     bool batch_mode;
   99 };
  100 
  101 int tools_wipe_progress(uint64_t size, uint64_t offset, void *usrptr);
  102 int tools_reencrypt_progress(uint64_t size, uint64_t offset, void *usrptr);
  103 
  104 int tools_read_mk(const char *file, char **key, int keysize);
  105 int tools_write_mk(const char *file, const char *key, int keysize);
  106 
  107 int tools_read_json_file(const char *file, char **json, size_t *json_size, bool batch_mode);
  108 int tools_write_json_file(const char *file, const char *json);
  109 
  110 int tools_detect_signatures(const char *device, int ignore_luks, size_t *count, bool batch_mode);
  111 int tools_wipe_all_signatures(const char *path);
  112 
  113 int tools_lookup_crypt_device(struct crypt_device *cd, const char *type,
  114         const char *data_device_path, char *name, size_t name_length);
  115 
  116 
  117 /* each utility is required to implement it */
  118 void tools_cleanup(void);
  119 
  120 /* Log */
  121 #define log_dbg(x...) crypt_logf(NULL, CRYPT_LOG_DEBUG, x)
  122 #define log_std(x...) crypt_logf(NULL, CRYPT_LOG_NORMAL, x)
  123 #define log_verbose(x...) crypt_logf(NULL, CRYPT_LOG_VERBOSE, x)
  124 #define log_err(x...) crypt_logf(NULL, CRYPT_LOG_ERROR, x)
  125 
  126 typedef enum {
  127     CRYPT_ARG_BOOL = 0,
  128     CRYPT_ARG_STRING,
  129     CRYPT_ARG_INT32,
  130     CRYPT_ARG_UINT32,
  131     CRYPT_ARG_INT64,
  132     CRYPT_ARG_UINT64
  133 } crypt_arg_type_info;
  134 
  135 struct tools_arg {
  136     const char *name;
  137     bool set;
  138     crypt_arg_type_info type;
  139     union {
  140         char *str_value;
  141         uint64_t u64_value;
  142         uint32_t u32_value;
  143         int32_t i32_value;
  144         int64_t i64_value;
  145     } u;
  146     const char *actions_array[MAX_ACTIONS];
  147 };
  148 
  149 void tools_parse_arg_value(poptContext popt_context, crypt_arg_type_info type, struct tools_arg *arg, const char *popt_arg, int popt_val, bool(*needs_size_conv_fn)(unsigned arg_id));
  150 
  151 void tools_args_free(struct tools_arg *args, size_t args_count);
  152 
  153 void tools_check_args(const char *action, const struct tools_arg *args, size_t args_size, poptContext popt_context);
  154 
  155 struct tools_log_params {
  156     bool verbose;
  157     bool debug;
  158 };
  159 
  160 #endif /* CRYPTSETUP_H */