Remove some gcc extra warnings (signed/unsigned problems etc).

This commit is contained in:
Milan Broz
2012-12-02 22:27:19 +01:00
parent 5aef0809d4
commit a4585423fd
4 changed files with 27 additions and 24 deletions

View File

@@ -117,7 +117,7 @@ static int crypt_cipher_crypt(struct crypt_cipher *ctx,
.iov_len = length, .iov_len = length,
}; };
int iv_msg_size = iv ? CMSG_SPACE(sizeof(*alg_iv) + iv_length) : 0; int iv_msg_size = iv ? CMSG_SPACE(sizeof(*alg_iv) + iv_length) : 0;
char buffer[CMSG_SPACE(sizeof(type)) + iv_msg_size]; char buffer[CMSG_SPACE(sizeof(*type)) + iv_msg_size];
struct msghdr msg = { struct msghdr msg = {
.msg_control = buffer, .msg_control = buffer,
.msg_controllen = sizeof(buffer), .msg_controllen = sizeof(buffer),
@@ -137,7 +137,7 @@ static int crypt_cipher_crypt(struct crypt_cipher *ctx,
header = CMSG_FIRSTHDR(&msg); header = CMSG_FIRSTHDR(&msg);
header->cmsg_level = SOL_ALG; header->cmsg_level = SOL_ALG;
header->cmsg_type = ALG_SET_OP; header->cmsg_type = ALG_SET_OP;
header->cmsg_len = CMSG_LEN(sizeof(type)); header->cmsg_len = CMSG_LEN(sizeof(*type));
type = (void*)CMSG_DATA(header); type = (void*)CMSG_DATA(header);
*type = direction; *type = direction;

View File

@@ -2087,7 +2087,7 @@ int crypt_deactivate(struct crypt_device *cd, const char *name)
switch (crypt_status(cd, name)) { switch (crypt_status(cd, name)) {
case CRYPT_ACTIVE: case CRYPT_ACTIVE:
case CRYPT_BUSY: case CRYPT_BUSY:
if (isTCRYPT(cd->type)) if (cd && isTCRYPT(cd->type))
r = TCRYPT_deactivate(cd, name); r = TCRYPT_deactivate(cd, name);
else else
r = dm_remove_device(cd, name, 0, 0); r = dm_remove_device(cd, name, 0, 0);

View File

@@ -32,8 +32,8 @@
/* TCRYPT PBKDF variants */ /* TCRYPT PBKDF variants */
static struct { static struct {
unsigned int legacy:1; unsigned int legacy:1;
char *name; const char *name;
char *hash; const char *hash;
unsigned int iterations; unsigned int iterations;
} tcrypt_kdf[] = { } tcrypt_kdf[] = {
{ 0, "pbkdf2", "ripemd160", 2000 }, { 0, "pbkdf2", "ripemd160", 2000 },
@@ -335,9 +335,10 @@ static int decrypt_hdr_cbci(struct tcrypt_algs *ciphers,
const char *key, struct tcrypt_phdr *hdr) const char *key, struct tcrypt_phdr *hdr)
{ {
struct crypt_cipher *cipher[ciphers->chain_count]; struct crypt_cipher *cipher[ciphers->chain_count];
int bs = ciphers->cipher[0].iv_size; unsigned int bs = ciphers->cipher[0].iv_size;
char *buf = (char*)&hdr->e, iv[bs], iv_old[bs]; char *buf = (char*)&hdr->e, iv[bs], iv_old[bs];
int i, j, r = -EINVAL; unsigned int i, j;
int r = -EINVAL;
remove_whitening(buf, &key[8]); remove_whitening(buf, &key[8]);
@@ -357,8 +358,8 @@ static int decrypt_hdr_cbci(struct tcrypt_algs *ciphers,
/* Implements CBC with chained ciphers in loop inside */ /* Implements CBC with chained ciphers in loop inside */
for (i = 0; i < TCRYPT_HDR_LEN; i += bs) { for (i = 0; i < TCRYPT_HDR_LEN; i += bs) {
memcpy(iv_old, &buf[i], bs); memcpy(iv_old, &buf[i], bs);
for (j = ciphers->chain_count - 1; j >= 0; j--) { for (j = ciphers->chain_count; j > 0; j--) {
r = crypt_cipher_decrypt(cipher[j], &buf[i], &buf[i], r = crypt_cipher_decrypt(cipher[j - 1], &buf[i], &buf[i],
bs, NULL, 0); bs, NULL, 0);
if (r < 0) if (r < 0)
goto out; goto out;
@@ -454,7 +455,7 @@ static int pool_keyfile(struct crypt_device *cd,
j %= TCRYPT_KEY_POOL_LEN; j %= TCRYPT_KEY_POOL_LEN;
} }
crc = 0; memset(&crc, 0, sizeof(crc));
memset(data, 0, TCRYPT_KEYFILE_LEN); memset(data, 0, TCRYPT_KEYFILE_LEN);
return 0; return 0;
@@ -467,7 +468,8 @@ static int TCRYPT_init_hdr(struct crypt_device *cd,
unsigned char pwd[TCRYPT_KEY_POOL_LEN] = {}; unsigned char pwd[TCRYPT_KEY_POOL_LEN] = {};
size_t passphrase_size; size_t passphrase_size;
char *key; char *key;
int r = -EINVAL, i, legacy_modes, skipped = 0; unsigned int i, skipped = 0;
int r = -EINVAL, legacy_modes;
if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN)) if (posix_memalign((void*)&key, crypt_getpagesize(), TCRYPT_HDR_KEY_LEN))
return -ENOMEM; return -ENOMEM;
@@ -609,7 +611,8 @@ int TCRYPT_activate(struct crypt_device *cd,
{ {
char cipher[MAX_CIPHER_LEN], dm_name[PATH_MAX], dm_dev_name[PATH_MAX]; char cipher[MAX_CIPHER_LEN], dm_name[PATH_MAX], dm_dev_name[PATH_MAX];
struct device *device = NULL; struct device *device = NULL;
int i, r; unsigned int i;
int r;
struct tcrypt_algs *algs; struct tcrypt_algs *algs;
struct crypt_dm_active_device dmd = { struct crypt_dm_active_device dmd = {
.target = DM_CRYPT, .target = DM_CRYPT,
@@ -657,23 +660,23 @@ int TCRYPT_activate(struct crypt_device *cd,
if (!dmd.u.crypt.vk) if (!dmd.u.crypt.vk)
return -ENOMEM; return -ENOMEM;
for (i = algs->chain_count - 1; i >= 0; i--) { for (i = algs->chain_count; i > 0; i--) {
if (i == 0) { if (i == 1) {
strncpy(dm_name, name, sizeof(dm_name)); strncpy(dm_name, name, sizeof(dm_name));
dmd.flags = flags; dmd.flags = flags;
} else { } else {
snprintf(dm_name, sizeof(dm_name), "%s_%d", name, i); snprintf(dm_name, sizeof(dm_name), "%s_%d", name, i-1);
dmd.flags = flags | CRYPT_ACTIVATE_PRIVATE; dmd.flags = flags | CRYPT_ACTIVATE_PRIVATE;
} }
snprintf(cipher, sizeof(cipher), "%s-%s", snprintf(cipher, sizeof(cipher), "%s-%s",
algs->cipher[i].name, algs->mode); algs->cipher[i-1].name, algs->mode);
copy_key(&algs->cipher[i], algs->mode, dmd.u.crypt.vk->key, hdr->d.keys); copy_key(&algs->cipher[i-1], algs->mode, dmd.u.crypt.vk->key, hdr->d.keys);
if ((algs->chain_count - 1) != i) { if (algs->chain_count != i) {
snprintf(dm_dev_name, sizeof(dm_dev_name), "%s/%s_%d", snprintf(dm_dev_name, sizeof(dm_dev_name), "%s/%s_%d",
dm_get_dir(), name, i + 1); dm_get_dir(), name, i);
r = device_alloc(&device, dm_dev_name); r = device_alloc(&device, dm_dev_name);
if (r) if (r)
break; break;
@@ -877,7 +880,7 @@ int TCRYPT_get_volume_key(struct crypt_device *cd,
struct volume_key **vk) struct volume_key **vk)
{ {
struct tcrypt_algs *algs; struct tcrypt_algs *algs;
int i, key_index; unsigned int i, key_index;
if (!hdr->d.version) { if (!hdr->d.version) {
log_err(cd, _("This function is not supported without TCRYPT header load.")); log_err(cd, _("This function is not supported without TCRYPT header load."));

View File

@@ -425,8 +425,8 @@ out:
static int action_benchmark(void) static int action_benchmark(void)
{ {
static struct { static struct {
char *cipher; const char *cipher;
char *mode; const char *mode;
size_t key_size; size_t key_size;
size_t iv_size; size_t iv_size;
} bciphers[] = { } bciphers[] = {
@@ -444,8 +444,8 @@ static int action_benchmark(void)
{ "twofish", "xts", 64, 16 }, { "twofish", "xts", 64, 16 },
{ NULL, NULL, 0, 0 } { NULL, NULL, 0, 0 }
}; };
char *header = "# Tests are approximate using memory only (no storage IO).\n" const char *header = "# Tests are approximate using memory only (no storage IO).\n"
"# Algorithm | Key | Encryption | Decryption\n"; "# Algorithm | Key | Encryption | Decryption\n";
char cipher[MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN]; char cipher[MAX_CIPHER_LEN], cipher_mode[MAX_CIPHER_LEN];
double enc_mbr = 0, dec_mbr = 0; double enc_mbr = 0, dec_mbr = 0;
int key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS); int key_size = (opt_key_size ?: DEFAULT_PLAIN_KEYBITS);