cryptsetup  2.4.3
About: cryptsetup is a utility used to conveniently setup disk encryption based on the dm-crypt kernel module. These include plain dm-crypt volumes, LUKS volumes, loop-AES and TrueCrypt compatible format.
  Fossies Dox: cryptsetup-2.4.3.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

cryptsetup_reencrypt.c File Reference
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <uuid/uuid.h>
#include "cryptsetup.h"
#include "cryptsetup_reencrypt_args.h"
#include "cryptsetup_reencrypt_arg_list.h"
Include dependency graph for cryptsetup_reencrypt.c:

Go to the source code of this file.

Data Structures

struct  reenc_ctx
 

Macros

#define PACKAGE_REENC   "cryptsetup-reencrypt"
 
#define NO_UUID   "cafecafe-cafe-cafe-cafe-cafecafeeeee"
 
#define MAX_SLOT   32
 
#define MAX_TOKEN   32
 
#define ARG(A, B, C, D, E, F, G)   { A, B, C, NULL, A ## _ID, D, E },
 

Enumerations

enum  header_magic { MAKE_UNUSABLE , MAKE_USABLE , CHECK_UNUSABLE , CHECK_OPEN }
 

Functions

void tools_cleanup (void)
 
static void _quiet_log (int level, const char *msg, void *usrptr)
 
static int alignment (int fd)
 
static size_t pagesize (void)
 
static const char * luksType (const char *type)
 
static const char * hdr_device (const struct reenc_ctx *rc)
 
static int set_reencrypt_requirement (const struct reenc_ctx *rc)
 
static int device_check (struct reenc_ctx *rc, const char *device, header_magic set_magic)
 
static int create_empty_header (const char *new_file)
 
static int write_log (struct reenc_ctx *rc)
 
static int parse_line_log (struct reenc_ctx *rc, const char *line)
 
static int parse_log (struct reenc_ctx *rc)
 
static void close_log (struct reenc_ctx *rc)
 
static int open_log (struct reenc_ctx *rc)
 
static int activate_luks_headers (struct reenc_ctx *rc)
 
static int set_pbkdf_params (struct crypt_device *cd, const char *dev_type)
 
static int create_new_keyslot (struct reenc_ctx *rc, int keyslot, struct crypt_device *cd_old, struct crypt_device *cd_new)
 
static int create_new_header (struct reenc_ctx *rc, struct crypt_device *cd_old, const char *cipher, const char *cipher_mode, const char *uuid, const char *key, int key_size, const char *type, uint64_t metadata_size, uint64_t keyslots_size, void *params)
 
static int isLUKS2 (const char *type)
 
static int luks2_metadata_copy (struct reenc_ctx *rc)
 
static int backup_luks_headers (struct reenc_ctx *rc)
 
static int backup_fake_header (struct reenc_ctx *rc)
 
static void remove_headers (struct reenc_ctx *rc)
 
static int restore_luks_header (struct reenc_ctx *rc)
 
static ssize_t read_buf (int fd, void *buf, size_t count)
 
static int copy_data_forward (struct reenc_ctx *rc, int fd_old, int fd_new, size_t block_size, void *buf, uint64_t *bytes)
 
static int copy_data_backward (struct reenc_ctx *rc, int fd_old, int fd_new, size_t block_size, void *buf, uint64_t *bytes)
 
static void zero_rest_of_device (int fd, size_t block_size, void *buf, uint64_t *bytes, uint64_t offset)
 
static int copy_data (struct reenc_ctx *rc)
 
static int initialize_uuid (struct reenc_ctx *rc)
 
static int init_passphrase1 (struct reenc_ctx *rc, struct crypt_device *cd, const char *msg, int slot_to_check, int check, int verify)
 
static int init_keyfile (struct reenc_ctx *rc, struct crypt_device *cd, int slot_check)
 
static int initialize_passphrase (struct reenc_ctx *rc, const char *device)
 
static int initialize_context (struct reenc_ctx *rc, const char *device)
 
static void destroy_context (struct reenc_ctx *rc)
 
static int luks2_change_pbkdf_params (struct reenc_ctx *rc)
 
static int run_reencrypt (const char *device)
 
static void help (poptContext popt_context, enum poptCallbackReason reason, struct poptOption *key, const char *arg, void *data)
 
static bool needs_size_conversion (unsigned arg_id)
 
static void basic_options_cb (poptContext popt_context, enum poptCallbackReason reason, struct poptOption *key, const char *arg, void *data)
 
int main (int argc, const char **argv)
 

Variables

static const char ** action_argv
 
static const char * set_pbkdf = NULL
 
static struct tools_log_params log_parms
 
char MAGIC [] = {'L','U','K','S', 0xba, 0xbe}
 
char NOMAGIC [] = {'L','U','K','S', 0xde, 0xad}
 
int MAGIC_L = 6
 

Macro Definition Documentation

◆ ARG

#define ARG (   A,
  B,
  C,
  D,
  E,
  F,
  G 
)    { A, B, C, NULL, A ## _ID, D, E },

◆ MAX_SLOT

#define MAX_SLOT   32

Definition at line 39 of file cryptsetup_reencrypt.c.

◆ MAX_TOKEN

#define MAX_TOKEN   32

Definition at line 40 of file cryptsetup_reencrypt.c.

◆ NO_UUID

#define NO_UUID   "cafecafe-cafe-cafe-cafe-cafecafeeeee"

Definition at line 31 of file cryptsetup_reencrypt.c.

◆ PACKAGE_REENC

#define PACKAGE_REENC   "cryptsetup-reencrypt"

Definition at line 29 of file cryptsetup_reencrypt.c.

Enumeration Type Documentation

◆ header_magic

Enumerator
MAKE_UNUSABLE 
MAKE_USABLE 
CHECK_UNUSABLE 
CHECK_OPEN 

Definition at line 81 of file cryptsetup_reencrypt.c.

Function Documentation

◆ _quiet_log()

static void _quiet_log ( int  level,
const char *  msg,
void *  usrptr 
)
static

Definition at line 93 of file cryptsetup_reencrypt.c.

References ARG_SET, and tool_log().

Referenced by initialize_uuid(), and remove_headers().

◆ activate_luks_headers()

◆ alignment()

◆ backup_fake_header()

◆ backup_luks_headers()

◆ basic_options_cb()

static void basic_options_cb ( poptContext  popt_context,
enum poptCallbackReason  reason,
struct poptOption *  key,
const char *  arg,
void *  data 
)
static

◆ close_log()

static void close_log ( struct reenc_ctx rc)
static

Definition at line 364 of file cryptsetup_reencrypt.c.

References log_dbg, reenc_ctx::log_fd, and reenc_ctx::log_file.

Referenced by destroy_context(), and open_log().

◆ copy_data()

◆ copy_data_backward()

static int copy_data_backward ( struct reenc_ctx rc,
int  fd_old,
int  fd_new,
size_t  block_size,
void *  buf,
uint64_t *  bytes 
)
static

◆ copy_data_forward()

static int copy_data_forward ( struct reenc_ctx rc,
int  fd_old,
int  fd_new,
size_t  block_size,
void *  buf,
uint64_t *  bytes 
)
static

◆ create_empty_header()

static int create_empty_header ( const char *  new_file)
static

Definition at line 254 of file cryptsetup_reencrypt.c.

References log_dbg.

Referenced by backup_fake_header(), and backup_luks_headers().

◆ create_new_header()

◆ create_new_keyslot()

◆ destroy_context()

◆ device_check()

◆ hdr_device()

static const char * hdr_device ( const struct reenc_ctx rc)
static

◆ help()

static void help ( poptContext  popt_context,
enum poptCallbackReason  reason,
struct poptOption *  key,
const char *  arg,
void *  data 
)
static

Definition at line 1569 of file cryptsetup_reencrypt.c.

References log_std, NULL, PACKAGE_REENC, tools_cleanup(), and usage().

Referenced by main().

◆ init_keyfile()

◆ init_passphrase1()

◆ initialize_context()

◆ initialize_passphrase()

◆ initialize_uuid()

◆ isLUKS2()

static int isLUKS2 ( const char *  type)
static

◆ luks2_change_pbkdf_params()

◆ luks2_metadata_copy()

◆ luksType()

static const char * luksType ( const char *  type)
static

Definition at line 116 of file cryptsetup_reencrypt.c.

References crypt_get_default_type(), CRYPT_LUKS1, CRYPT_LUKS2, and NULL.

Referenced by initialize_uuid(), and main().

◆ main()

◆ needs_size_conversion()

static bool needs_size_conversion ( unsigned  arg_id)
static

Definition at line 1590 of file cryptsetup_reencrypt.c.

Referenced by basic_options_cb().

◆ open_log()

static int open_log ( struct reenc_ctx rc)
static

◆ pagesize()

static size_t pagesize ( void  )
static

Definition at line 110 of file cryptsetup_reencrypt.c.

Referenced by crypt_getphysmemory_kb(), and device_check().

◆ parse_line_log()

static int parse_line_log ( struct reenc_ctx rc,
const char *  line 
)
static

◆ parse_log()

static int parse_log ( struct reenc_ctx rc)
static

Definition at line 335 of file cryptsetup_reencrypt.c.

References _, reenc_ctx::log_buf, log_err, reenc_ctx::log_fd, parse_line_log(), and SECTOR_SIZE.

Referenced by open_log().

◆ read_buf()

static ssize_t read_buf ( int  fd,
void *  buf,
size_t  count 
)
static

Definition at line 886 of file cryptsetup_reencrypt.c.

References log_dbg.

Referenced by copy_data_backward(), and copy_data_forward().

◆ remove_headers()

◆ restore_luks_header()

◆ run_reencrypt()

◆ set_pbkdf_params()

◆ set_reencrypt_requirement()

◆ tools_cleanup()

void tools_cleanup ( void  )

Definition at line 88 of file cryptsetup_reencrypt.c.

References ARRAY_SIZE, tool_core_args, and tools_args_free().

Referenced by help(), and main().

◆ write_log()

◆ zero_rest_of_device()

static void zero_rest_of_device ( int  fd,
size_t  block_size,
void *  buf,
uint64_t *  bytes,
uint64_t  offset 
)
static

Definition at line 1045 of file cryptsetup_reencrypt.c.

References ARG_SET, log_dbg, and quit.

Referenced by copy_data().

Variable Documentation

◆ action_argv

const char** action_argv
static

Definition at line 33 of file cryptsetup_reencrypt.c.

Referenced by main().

◆ log_parms

struct tools_log_params log_parms
static

Definition at line 37 of file cryptsetup_reencrypt.c.

Referenced by basic_options_cb(), and main().

◆ MAGIC

char MAGIC[] = {'L','U','K','S', 0xba, 0xbe}

Definition at line 77 of file cryptsetup_reencrypt.c.

Referenced by device_check().

◆ MAGIC_L

int MAGIC_L = 6

Definition at line 79 of file cryptsetup_reencrypt.c.

Referenced by device_check().

◆ NOMAGIC

char NOMAGIC[] = {'L','U','K','S', 0xde, 0xad}

Definition at line 78 of file cryptsetup_reencrypt.c.

Referenced by device_check().

◆ set_pbkdf

const char* set_pbkdf = NULL
static

Definition at line 35 of file cryptsetup_reencrypt.c.

Referenced by main(), and set_pbkdf_params().