diff --git a/ChangeLog b/ChangeLog index dcc199b4..68ead079 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,7 @@ 2011-07-07 Milan Broz * Remove old API functions (all functions using crypt_options). * Add --enable-discards option to allow discards/TRIM requests. + * Add crypt_get_iv_offset() function to API. 2011-07-01 Milan Broz * Add --shared option for creating non-overlapping crypt segments. diff --git a/lib/internal.h b/lib/internal.h index 606c2346..0a29569c 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -98,7 +98,6 @@ int PLAIN_activate(struct crypt_device *cd, const char *name, struct volume_key *vk, uint64_t size, - uint64_t iv_offset, uint32_t flags); #endif /* INTERNAL_H */ diff --git a/lib/libcryptsetup.h b/lib/libcryptsetup.h index 33fe72b4..92588267 100644 --- a/lib/libcryptsetup.h +++ b/lib/libcryptsetup.h @@ -160,7 +160,7 @@ const char *crypt_get_type(struct crypt_device *cd); struct crypt_params_plain { const char *hash; /* password hash function */ uint64_t offset; /* offset in sectors */ - uint64_t skip; /* IV initilisation sector */ + uint64_t skip; /* IV offset / initialisation sector */ uint64_t size; /* size of mapped device or 0 for autodetection */ }; @@ -172,7 +172,7 @@ struct crypt_params_luks1 { struct crypt_params_loopaes { const char *hash; /* key hash function */ uint64_t offset; /* offset in sectors */ - uint64_t skip; /* IV initilisation sector */ + uint64_t skip; /* IV offset / initialisation sector */ }; /** * Create (format) new crypt device (and possible header on-disk) but not activates it. @@ -540,6 +540,7 @@ int crypt_dump(struct crypt_device *cd); * uuid - device UUID or NULL if not set * device_name - underlying device name or NULL if not yet set * data_offset - device offset in sectors where real data starts on underlying device) + * iv_offset - IV offset in sectors (skip) * volume_key_size - size (in bytes) of volume key for crypt device */ const char *crypt_get_cipher(struct crypt_device *cd); @@ -547,6 +548,7 @@ const char *crypt_get_cipher_mode(struct crypt_device *cd); const char *crypt_get_uuid(struct crypt_device *cd); const char *crypt_get_device_name(struct crypt_device *cd); uint64_t crypt_get_data_offset(struct crypt_device *cd); +uint64_t crypt_get_iv_offset(struct crypt_device *cd); int crypt_get_volume_key_size(struct crypt_device *cd); /** diff --git a/lib/libcryptsetup.sym b/lib/libcryptsetup.sym index da521ca0..10718b5b 100644 --- a/lib/libcryptsetup.sym +++ b/lib/libcryptsetup.sym @@ -36,6 +36,7 @@ CRYPTSETUP_1.0 { crypt_get_cipher_mode; crypt_get_uuid; crypt_get_data_offset; + crypt_get_iv_offset; crypt_get_volume_key_size; crypt_get_device_name; diff --git a/lib/loopaes/loopaes.c b/lib/loopaes/loopaes.c index 3fe10eaf..b14243a2 100644 --- a/lib/loopaes/loopaes.c +++ b/lib/loopaes/loopaes.c @@ -185,7 +185,6 @@ int LOOPAES_activate(struct crypt_device *cd, const char *base_cipher, unsigned int keys_count, struct volume_key *vk, - uint64_t skip, uint32_t flags) { char *cipher = NULL; @@ -197,7 +196,7 @@ int LOOPAES_activate(struct crypt_device *cd, .uuid = crypt_get_uuid(cd), .vk = vk, .offset = crypt_get_data_offset(cd), - .iv_offset = skip, + .iv_offset = crypt_get_iv_offset(cd), .size = 0, .flags = flags }; diff --git a/lib/loopaes/loopaes.h b/lib/loopaes/loopaes.h index 67a2d725..5dd0a71b 100644 --- a/lib/loopaes/loopaes.h +++ b/lib/loopaes/loopaes.h @@ -21,6 +21,5 @@ int LOOPAES_activate(struct crypt_device *cd, const char *base_cipher, unsigned int keys_count, struct volume_key *vk, - uint64_t skip, uint32_t flags); #endif diff --git a/lib/setup.c b/lib/setup.c index 0755caa2..916e388a 100644 --- a/lib/setup.c +++ b/lib/setup.c @@ -216,7 +216,6 @@ int PLAIN_activate(struct crypt_device *cd, const char *name, struct volume_key *vk, uint64_t size, - uint64_t iv_offset, uint32_t flags) { int r; @@ -227,7 +226,7 @@ int PLAIN_activate(struct crypt_device *cd, .uuid = crypt_get_uuid(cd), .vk = vk, .offset = crypt_get_data_offset(cd), - .iv_offset = iv_offset, + .iv_offset = crypt_get_iv_offset(cd), .size = size, .flags = flags }; @@ -1328,9 +1327,7 @@ int crypt_activate_by_passphrase(struct crypt_device *cd, if (r < 0) goto out; - r = PLAIN_activate(cd, name, vk, - cd->plain_hdr.size, - cd->plain_hdr.skip, flags); + r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags); keyslot = 0; } else if (isLUKS(cd->type)) { /* provided passphrase, do not retry */ @@ -1400,9 +1397,7 @@ int crypt_activate_by_keyfile(struct crypt_device *cd, if (r < 0) goto out; - r = PLAIN_activate(cd, name, vk, - cd->plain_hdr.size, - cd->plain_hdr.skip, flags); + r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags); } else if (isLUKS(cd->type)) { r = key_from_file(cd, _("Enter passphrase: "), &passphrase_read, &passphrase_size_read, keyfile, keyfile_size); @@ -1431,9 +1426,7 @@ int crypt_activate_by_keyfile(struct crypt_device *cd, goto out; if (name) r = LOOPAES_activate(cd, name, cd->loopaes_cipher, - key_count, vk, - cd->loopaes_hdr.skip, - flags); + key_count, vk, flags); } else r = -EINVAL; @@ -1481,9 +1474,7 @@ int crypt_activate_by_volume_key(struct crypt_device *cd, if (!vk) return -ENOMEM; - r = PLAIN_activate(cd, name, vk, - cd->plain_hdr.size, - cd->plain_hdr.skip, flags); + r = PLAIN_activate(cd, name, vk, cd->plain_hdr.size, flags); } else if (isLUKS(cd->type)) { /* If key is not provided, try to use internal key */ if (!volume_key) { @@ -1816,6 +1807,20 @@ uint64_t crypt_get_data_offset(struct crypt_device *cd) return 0; } +uint64_t crypt_get_iv_offset(struct crypt_device *cd) +{ + if (isPLAIN(cd->type)) + return cd->plain_hdr.skip; + + if (isLUKS(cd->type)) + return 0; + + if (isLOOPAES(cd->type)) + return cd->loopaes_hdr.skip; + + return 0; +} + crypt_keyslot_info crypt_keyslot_status(struct crypt_device *cd, int keyslot) { if (!isLUKS(cd->type)) {