*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <string.h>
static int setup_mapping(const char *cipher, const char *name,
const char *device,
- const char *key, size_t keyLength,
+ struct volume_key *vk,
unsigned int sector, size_t srcLength,
int mode, struct crypt_device *ctx)
{
int device_sector_size = sector_size_for_device(device);
- uint64_t size;
+ struct crypt_dm_active_device dmd = {
+ .device = device,
+ .cipher = cipher,
+ .uuid = NULL,
+ .vk = vk,
+ .offset = sector,
+ .iv_offset = 0,
+ .size = 0,
+ .flags = (mode == O_RDONLY) ? CRYPT_ACTIVATE_READONLY : 0
+ };
/*
* we need to round this to nearest multiple of the underlying
log_err(ctx, _("Unable to obtain sector size for %s"), device);
return -EINVAL;
}
- size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
- cleaner_size = size;
- return dm_create_device(name, device, cipher, "TEMP", NULL, size, 0, sector,
- keyLength, key, (mode == O_RDONLY), 0);
+ dmd.size = round_up_modulo(srcLength,device_sector_size)/SECTOR_SIZE;
+ cleaner_size = dmd.size;
+
+ return dm_create_device(name, "TEMP", &dmd, 0);
}
static void sigint_handler(int sig __attribute__((unused)))
static const char *_error_hint(char *cipherMode, size_t keyLength)
{
const char *hint= "";
-#ifdef __linux__
- char c, tmp[4] = {0};
- struct utsname uts;
- int i = 0, kernel_minor;
-
- /* Nothing to suggest here */
- if (uname(&uts) || strncmp(uts.release, "2.6.", 4))
- return hint;
-
- /* Get kernel minor without suffixes */
- while (i < 3 && (c = uts.release[i + 4]))
- tmp[i++] = isdigit(c) ? c : '\0';
- kernel_minor = atoi(tmp);
if (!strncmp(cipherMode, "xts", 3) && (keyLength != 256 && keyLength != 512))
hint = _("Key size in XTS mode must be 256 or 512 bits.\n");
- else if (!strncmp(cipherMode, "xts", 3) && kernel_minor < 24)
- hint = _("Block mode XTS is available since kernel 2.6.24.\n");
- if (!strncmp(cipherMode, "lrw", 3) && (keyLength != 256 && keyLength != 512))
- hint = _("Key size in LRW mode must be 256 or 512 bits.\n");
- else if (!strncmp(cipherMode, "lrw", 3) && kernel_minor < 20)
- hint = _("Block mode LRW is available since kernel 2.6.20.\n");
-#endif
+
return hint;
}
handler and global vars for cleaning */
static int LUKS_endec_template(char *src, size_t srcLength,
struct luks_phdr *hdr,
- char *key, size_t keyLength,
+ struct volume_key *vk,
const char *device,
unsigned int sector,
ssize_t (*func)(int, void *, size_t),
cleaner_name = name;
r = setup_mapping(dmCipherSpec, name, device,
- key, keyLength, sector, srcLength, mode, ctx);
+ vk, sector, srcLength, mode, ctx);
if(r < 0) {
log_err(ctx, _("Failed to setup dm-crypt key mapping for device %s.\n"
"Check that kernel supports %s cipher (check syslog for more info).\n%s"),
device, dmCipherSpec,
- _error_hint(hdr->cipherMode, keyLength * 8));
+ _error_hint(hdr->cipherMode, vk->keylength * 8));
r = -EIO;
goto out1;
}
int LUKS_encrypt_to_storage(char *src, size_t srcLength,
struct luks_phdr *hdr,
- char *key, size_t keyLength,
+ struct volume_key *vk,
const char *device,
unsigned int sector,
struct crypt_device *ctx)
{
- return LUKS_endec_template(src,srcLength,hdr,key,keyLength, device,
+ return LUKS_endec_template(src,srcLength,hdr,vk, device,
sector, write_blockwise, O_RDWR, ctx);
}
int LUKS_decrypt_from_storage(char *dst, size_t dstLength,
struct luks_phdr *hdr,
- char *key, size_t keyLength,
+ struct volume_key *vk,
const char *device,
unsigned int sector,
struct crypt_device *ctx)
{
- return LUKS_endec_template(dst,dstLength,hdr,key,keyLength, device,
+ return LUKS_endec_template(dst,dstLength,hdr,vk, device,
sector, read_blockwise, O_RDONLY, ctx);
}