int device_ready(struct crypt_device *cd, const char *device, int mode);
int device_size(const char *device, uint64_t *size);
-int crypt_getpagesize(void);
+unsigned crypt_getpagesize(void);
enum devcheck { DEV_OK = 0, DEV_EXCL = 1, DEV_SHARED = 2 };
int device_check_and_adjust(struct crypt_device *cd,
sprintf(&hexkey[i * 2], "%02x", (unsigned char)key[i]);
}
-static int hex_to_bytes(const char *hex, char *result)
+static size_t hex_to_bytes(const char *hex, char *result)
{
char buf[3] = "xx\0", *endp;
- int i, len;
+ size_t i, len;
len = strlen(hex) / 2;
for (i = 0; i < len; i++) {
return -EINVAL;
}
+ if (!(cd->type = strdup(CRYPT_PLAIN)))
+ return -ENOMEM;
+
cd->plain_key_size = volume_key_size;
cd->volume_key = crypt_alloc_volume_key(volume_key_size, NULL);
if (!cd->volume_key)
return -EINVAL;
}
+ if (!(cd->type = strdup(CRYPT_LUKS1)))
+ return -ENOMEM;
+
if (volume_key)
cd->volume_key = crypt_alloc_volume_key(volume_key_size,
volume_key);
return -EINVAL;
}
+ if (!(cd->type = strdup(CRYPT_LOOPAES)))
+ return -ENOMEM;
+
cd->loopaes_key_size = volume_key_size;
cd->loopaes_cipher = strdup(cipher ?: DEFAULT_LOOPAES_CIPHER);
if (!params || !params->data_device)
return -EINVAL;
- /* set data device */
- cd->type = CRYPT_VERITY;
+ if (!(cd->type = strdup(CRYPT_VERITY)))
+ return -ENOMEM;
+
r = crypt_set_data_device(cd, params->data_device);
- cd->type = NULL;
if (r)
return r;
if (!params->data_size) {
r = -EINVAL;
}
- if (!r && !(cd->type = strdup(type)))
- r = -ENOMEM;
-
if (r < 0) {
+ free(cd->type);
+ cd->type = NULL;
crypt_free_volume_key(cd->volume_key);
cd->volume_key = NULL;
}
#include "libcryptsetup.h"
#include "internal.h"
-int crypt_getpagesize(void)
+unsigned crypt_getpagesize(void)
{
- return (int)sysconf(_SC_PAGESIZE);
+ return (unsigned)sysconf(_SC_PAGESIZE);
}
static int get_alignment(int fd)
static unsigned get_bits_up(size_t u)
{
unsigned i = 0;
- while ((1 << i) < u)
+ while ((1U << i) < u)
i++;
return i;
}
static unsigned get_bits_down(size_t u)
{
unsigned i = 0;
- while ((u >> i) > 1)
+ while ((u >> i) > 1U)
i++;
return i;
}
size_t digest_size_full = 1 << get_bits_up(digest_size);
off_t blocks_to_write = (blocks + hash_per_block - 1) / hash_per_block;
size_t left_bytes;
- int i, r;
+ unsigned i;
+ int r;
if (fseeko(rd, data_block * data_block_size, SEEK_SET)) {
log_dbg("Cannot seek to requested position in data device.");
char *root_hash,
size_t root_hash_size)
{
- int pgsize = crypt_getpagesize();
+ unsigned pgsize = crypt_getpagesize();
if (verity_hdr->salt_size > 256)
return -EINVAL;
static const char **action_argv;
static int action_argc;
-static int hex_to_bytes(const char *hex, char *result)
+static size_t hex_to_bytes(const char *hex, char *result)
{
char buf[3] = "xx\0", *endp;
- int i, len;
+ size_t i, len;
len = strlen(hex) / 2;
for (i = 0; i < len; i++) {
struct crypt_params_verity params = {};
uint32_t activate_flags = CRYPT_ACTIVATE_READONLY;
char root_hash_bytes[128];
+ size_t hash_size;
int r;
if ((r = crypt_init(&cd, hash_device)))
if (r < 0)
goto out;
- if (hex_to_bytes(root_hash, root_hash_bytes) !=
- crypt_get_volume_key_size(cd)) {
+ hash_size = crypt_get_volume_key_size(cd);
+ if (hex_to_bytes(root_hash, root_hash_bytes) != hash_size) {
r = -EINVAL;
goto out;
}
r = crypt_activate_by_volume_key(cd, dm_device,
root_hash_bytes,
- crypt_get_volume_key_size(cd),
+ hash_size,
activate_flags);
out:
crypt_free(cd);
struct crypt_device *cd = NULL;
struct stat st;
char *backing_file;
- int i, path = 0, r = 0;
+ unsigned i, path = 0;
+ int r = 0;
/* perhaps a path, not a dm device name */
if (strchr(action_argv[0], '/') && !stat(action_argv[0], &st))