Add crypt_get_iv_offset() function to API.
authorMilan Broz <gmazyland@gmail.com>
Mon, 18 Jul 2011 13:03:15 +0000 (13:03 +0000)
committerMilan Broz <gmazyland@gmail.com>
Mon, 18 Jul 2011 13:03:15 +0000 (13:03 +0000)
git-svn-id: https://cryptsetup.googlecode.com/svn/trunk@573 36d66b0a-2a48-0410-832c-cd162a569da5

ChangeLog
lib/internal.h
lib/libcryptsetup.h
lib/libcryptsetup.sym
lib/loopaes/loopaes.c
lib/loopaes/loopaes.h
lib/setup.c

index dcc199b..68ead07 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2011-07-07  Milan Broz  <mbroz@redhat.com>
        * 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  <mbroz@redhat.com>
        * Add --shared option for creating non-overlapping crypt segments.
index 606c234..0a29569 100644 (file)
@@ -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 */
index 33fe72b..9258826 100644 (file)
@@ -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);
 
 /**
index da521ca..10718b5 100644 (file)
@@ -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;
 
index 3fe10ea..b14243a 100644 (file)
@@ -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
        };
index 67a2d72..5dd0a71 100644 (file)
@@ -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
index 0755caa..916e388 100644 (file)
@@ -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)) {