"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "lib/luks2/luks2_digest.c" between
cryptsetup-2.3.6.tar.xz and cryptsetup-2.4.0.tar.xz

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.

luks2_digest.c  (cryptsetup-2.3.6.tar.xz):luks2_digest.c  (cryptsetup-2.4.0.tar.xz)
skipping to change at line 31 skipping to change at line 31
#include "luks2_internal.h" #include "luks2_internal.h"
extern const digest_handler PBKDF2_digest; extern const digest_handler PBKDF2_digest;
static const digest_handler *digest_handlers[LUKS2_DIGEST_MAX] = { static const digest_handler *digest_handlers[LUKS2_DIGEST_MAX] = {
&PBKDF2_digest, &PBKDF2_digest,
NULL NULL
}; };
static const digest_handler *LUKS2_digest_handler_type(struct crypt_device *cd, const char *type) static const digest_handler *LUKS2_digest_handler_type(const char *type)
{ {
int i; int i;
for (i = 0; i < LUKS2_DIGEST_MAX && digest_handlers[i]; i++) { for (i = 0; i < LUKS2_DIGEST_MAX && digest_handlers[i]; i++) {
if (!strcmp(digest_handlers[i]->name, type)) if (!strcmp(digest_handlers[i]->name, type))
return digest_handlers[i]; return digest_handlers[i];
} }
return NULL; return NULL;
} }
skipping to change at line 60 skipping to change at line 60
if (!(hdr = crypt_get_hdr(cd, CRYPT_LUKS2))) if (!(hdr = crypt_get_hdr(cd, CRYPT_LUKS2)))
return NULL; return NULL;
if (!(jobj1 = LUKS2_get_digest_jobj(hdr, digest))) if (!(jobj1 = LUKS2_get_digest_jobj(hdr, digest)))
return NULL; return NULL;
if (!json_object_object_get_ex(jobj1, "type", &jobj2)) if (!json_object_object_get_ex(jobj1, "type", &jobj2))
return NULL; return NULL;
return LUKS2_digest_handler_type(cd, json_object_get_string(jobj2)); return LUKS2_digest_handler_type(json_object_get_string(jobj2));
} }
static int LUKS2_digest_find_free(struct crypt_device *cd, struct luks2_hdr *hdr ) static int LUKS2_digest_find_free(struct luks2_hdr *hdr)
{ {
int digest = 0; int digest = 0;
while (LUKS2_get_digest_jobj(hdr, digest) && digest < LUKS2_DIGEST_MAX) while (LUKS2_get_digest_jobj(hdr, digest) && digest < LUKS2_DIGEST_MAX)
digest++; digest++;
return digest < LUKS2_DIGEST_MAX ? digest : -1; return digest < LUKS2_DIGEST_MAX ? digest : -1;
} }
int LUKS2_digest_create(struct crypt_device *cd, int LUKS2_digest_create(struct crypt_device *cd,
const char *type, const char *type,
struct luks2_hdr *hdr, struct luks2_hdr *hdr,
const struct volume_key *vk) const struct volume_key *vk)
{ {
int digest; int digest;
const digest_handler *dh; const digest_handler *dh;
dh = LUKS2_digest_handler_type(cd, type); dh = LUKS2_digest_handler_type(type);
if (!dh) if (!dh)
return -EINVAL; return -EINVAL;
digest = LUKS2_digest_find_free(cd, hdr); digest = LUKS2_digest_find_free(hdr);
if (digest < 0) if (digest < 0)
return -EINVAL; return -EINVAL;
log_dbg(cd, "Creating new digest %d (%s).", digest, type); log_dbg(cd, "Creating new digest %d (%s).", digest, type);
return dh->store(cd, digest, vk->key, vk->keylength) ?: digest; return dh->store(cd, digest, vk->key, vk->keylength) ?: digest;
} }
int LUKS2_digest_by_keyslot(struct luks2_hdr *hdr, int keyslot) int LUKS2_digest_by_keyslot(struct luks2_hdr *hdr, int keyslot)
{ {
skipping to change at line 114 skipping to change at line 114
json_object_object_foreach(jobj_digests, key, val) { json_object_object_foreach(jobj_digests, key, val) {
json_object_object_get_ex(val, "keyslots", &jobj_digest_keyslots) ; json_object_object_get_ex(val, "keyslots", &jobj_digest_keyslots) ;
if (LUKS2_array_jobj(jobj_digest_keyslots, keyslot_name)) if (LUKS2_array_jobj(jobj_digest_keyslots, keyslot_name))
return atoi(key); return atoi(key);
} }
return -ENOENT; return -ENOENT;
} }
int LUKS2_digest_verify_by_digest(struct crypt_device *cd, int LUKS2_digest_verify_by_digest(struct crypt_device *cd,
struct luks2_hdr *hdr, struct luks2_hdr *hdr __attribute__((unused)),
int digest, int digest,
const struct volume_key *vk) const struct volume_key *vk)
{ {
const digest_handler *h; const digest_handler *h;
int r; int r;
h = LUKS2_digest_handler(cd, digest); h = LUKS2_digest_handler(cd, digest);
if (!h) if (!h)
return -EINVAL; return -EINVAL;
skipping to change at line 259 skipping to change at line 259
r = assign_one_digest(cd, hdr, keyslot, atoi(key), assign ); r = assign_one_digest(cd, hdr, keyslot, atoi(key), assign );
if (r < 0) if (r < 0)
break; break;
} }
} else } else
r = assign_one_digest(cd, hdr, keyslot, digest, assign); r = assign_one_digest(cd, hdr, keyslot, digest, assign);
if (r < 0) if (r < 0)
return r; return r;
// FIXME: do not write header in nothing changed
return commit ? LUKS2_hdr_write(cd, hdr) : 0; return commit ? LUKS2_hdr_write(cd, hdr) : 0;
} }
static int assign_all_segments(struct crypt_device *cd, struct luks2_hdr *hdr, static int assign_all_segments(struct crypt_device *cd __attribute__((unused)),
int digest, int assign) struct luks2_hdr *hdr, int digest, int assign)
{ {
json_object *jobj1, *jobj_digest, *jobj_digest_segments; json_object *jobj1, *jobj_digest, *jobj_digest_segments;
jobj_digest = LUKS2_get_digest_jobj(hdr, digest); jobj_digest = LUKS2_get_digest_jobj(hdr, digest);
if (!jobj_digest) if (!jobj_digest)
return -EINVAL; return -EINVAL;
json_object_object_get_ex(jobj_digest, "segments", &jobj_digest_segments) ; json_object_object_get_ex(jobj_digest, "segments", &jobj_digest_segments) ;
if (!jobj_digest_segments) if (!jobj_digest_segments)
return -EINVAL; return -EINVAL;
skipping to change at line 356 skipping to change at line 355
} else { } else {
if (segment == CRYPT_ANY_SEGMENT) if (segment == CRYPT_ANY_SEGMENT)
r = assign_all_segments(cd, hdr, digest, assign); r = assign_all_segments(cd, hdr, digest, assign);
else else
r = assign_one_segment(cd, hdr, segment, digest, assign); r = assign_one_segment(cd, hdr, segment, digest, assign);
} }
if (r < 0) if (r < 0)
return r; return r;
// FIXME: do not write header in nothing changed
return commit ? LUKS2_hdr_write(cd, hdr) : 0; return commit ? LUKS2_hdr_write(cd, hdr) : 0;
} }
static int digest_unused(json_object *jobj_digest) static int digest_unused(json_object *jobj_digest)
{ {
json_object *jobj; json_object *jobj;
json_object_object_get_ex(jobj_digest, "segments", &jobj); json_object_object_get_ex(jobj_digest, "segments", &jobj);
if (!jobj || !json_object_is_type(jobj, json_type_array) || json_object_a rray_length(jobj) > 0) if (!jobj || !json_object_is_type(jobj, json_type_array) || json_object_a rray_length(jobj) > 0)
return 0; return 0;
skipping to change at line 448 skipping to change at line 446
r = crypt_volume_key_set_description(vk, desc); r = crypt_volume_key_set_description(vk, desc);
if (!r) if (!r)
r = crypt_volume_key_load_in_keyring(cd, vk); r = crypt_volume_key_load_in_keyring(cd, vk);
free(desc); free(desc);
return r; return r;
} }
int LUKS2_volume_key_load_in_keyring_by_digest(struct crypt_device *cd, int LUKS2_volume_key_load_in_keyring_by_digest(struct crypt_device *cd,
struct luks2_hdr *hdr, struct volume_key *vk, int digest) struct luks2_hdr *hdr __attribute__((unused)), struct volume_key *vk, int digest)
{ {
char *desc = get_key_description_by_digest(cd, digest); char *desc = get_key_description_by_digest(cd, digest);
int r; int r;
r = crypt_volume_key_set_description(vk, desc); r = crypt_volume_key_set_description(vk, desc);
if (!r) if (!r)
r = crypt_volume_key_load_in_keyring(cd, vk); r = crypt_volume_key_load_in_keyring(cd, vk);
free(desc); free(desc);
return r; return r;
 End of changes. 10 change blocks. 
11 lines changed or deleted 9 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)